Brad Lucas

Programming, Clojure and other interests

Programming Competitions

July 14, 2017

The other week I saw this post about programming competitions and how they supposedly correlate negatively to job performance. This was according to Peter Norvig.

I found this interesting because as most will know the typical work of a programmer is very different from a programming competition.

After looking around a bit I found a Hacker News post for the same blog page with some interesting comments.

Continue reading →

Replace

July 13, 2017

An old Perl script for replacing a string within multiple files.

replace.pl

#!/usr/bin/perl
#
# Replaces a string within multiple files
# specified on the command line
#

$mv = '/bin/mv';

$op = shift || die("Usage: $0 perlexpr [filenames]\n");
print "$op\n";
print "@ARGV\n";

if (!@ARGV) {
  @ARGV = <STDIN>;
  chop(@ARGV);
}

foreach $file (@ARGV) {
  if (!-f $file) { print "Skipping non-regular file: $file\n"; next; }
  if (-B $file) { print "Skipping binary file: $file\n"; next; }

  $outfile = "/tmp/$file.$$";

  open(FILE, $file) || die("Couldn't open $file: $!\n&quot;");
  undef $/;
  $_ = <FILE>;
  close(FILE);

  if (eval $op) {
    open(OFILE, "> $outfile") || die("Couldn't open $outfile: $!\n");
    print OFILE;
    close(OFILE);

    system($mv, '-f', $file, "$file.bak");
    system($mv, '-f', $outfile, $file);

    print "File changed: $file\n";
  }
  else {
    print "No change to file: $file\n";
  }
}

exit(0);

Continue reading →

Diskspace

July 12, 2017

Show the amount of disk space the larger directories under your home directory are taking.

diskspace.sh

#!/bin/sh

pushd $HOME

du -sk * | sort -nr | head

popd

Continue reading →

Travel Day

July 11, 2017

Travelling today. Looks like 13 hours door to door.

Continue reading →

Update Last Git Commit Comment

July 10, 2017

You just committed to your Git repo and realized you have a typo in your commit message. Here is how you can edit the last commit's comment.

$ git commit --amend
Continue reading →