Archive for July, 2009

Using Mac OS X 10.5’s keychain for ssh

The version of ssh that comes with Mac OS X 10.5.6 has a -K option that stores your passphrases in your system’s keychain.

Run this:

ssh-add -K [path to private keyfile]

Provide your passphrase once when asked, and keychain will provide the passphrase for you automatically. You should probably enable “Require password to wake this computer from sleep or screen saver” in the Security pane of the System Preferences if you decide to do this.

If you see

$ ssh-add -K
ssh-add: illegal option -- K

it’s because you’re using the macports (or fink) version of ssh. (run ‘which ssh’ to find out). With macports, uninstall the “openssh” package:

sudo port uninstall openssh

The ‘-K’ option was discovered courtesy of http://www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html.

http://kimmo.suominen.com/docs/ssh/ has some excellent ssh documentation.

How to add a version number to your hudson-built maven jar

Maven’s jar plugin will automatically add a “pom.properties” in your jar’s META-INF/maven/$groupId/$artifactId directory. If you build with hudson, there are a number of other values that you might want to include automatically, though, like the SVN revision number that the artifact was built from, and when it was built.

Here’s the configuration for the maven-jar-plugin that adds a couple of the more-interesting hudson variables to your module’s jar’s META-INF/MANIFEST.MF:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Svn-Revision>${SVN_REVISION}</Svn-Revision>
              <Build-Tag>${BUILD_TAG}</Build-Tag>
              <Build-Number>${BUILD_NUMBER}</Build-Number>
              <Build-Id>${BUILD_ID}</Build-Id>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>

The Maven Guide to Working with Manifests and Maven Archiver pages, along with the other hudson variables may prove helpful.

Update December 14, 2009:

Note that Hudson’s SVN_REVISION macro is empty if you build your project as a maven multi-module.

Simple PHP image rotation script

This blog has a rotating header — if you visit /header/ and bounce on reload, you’ll see a series of random images. Here’s how it works:

The header is added to a div with the following CSS:

#headerimage{
  background: url("/header/") center center no-repeat;
}

/header/ is a directory in ~/public_html/. It contains a bunch of similar-sized images, along with the following index.php file:

<?php
$pattern = '/\.(png|gif|jpg|jpeg|svg)$/i';
$dh  = opendir('.');
while (false !== ($filename = readdir($dh))) {
  if (!is_dir($filename) && $filename[0] != '.' && preg_match($pattern, $filename)) {
    $files[] = $filename;
  }
}
closedir($dh);
$file = $files[rand(0, count($files) - 1)];
header('content-type: '. mime_content_type($file));
readfile($file);
?>

It’s pretty simple. It

  1. looks for image files in the same directory (lines 2-9)
  2. chooses one at random (line 10)
  3. sets the mimetype of the response based on the image’s filename suffix (line 11)
  4. sends out the file’s contents (line 12)

What’s nifty is you can turn this into an ultra-lightweight slideshow by adding one line:

header('refresh: 5');

after line 11 (the mime_content_type header). There isn’t any transition between the image changes, but we’ll leave that for next time.

How to add a version number to your maven webapp

I couldn’t find a simple recipe to add a version number to a maven-built webapp. The maven-war-plugin talks about how to filter, but no simple example is given.

More >

Create new junit tests in Eclipse with a keystroke

The Galileo version of Eclipse doesn’t ship with a default keybinding for creating a unit test for the current class, but you can add one easily enough. Navigate to Preferences > General > Keys, and search for “junit test case”:

eclipse-create-junit-keystroke

Click the “Binding” field, hit the keystroke (I used shift-control-option-command-t), and click Apply.

I haven’t found a way to jump to the referring test for a given class, though. IDEA’s JUnit plugin had that and I miss it. :-\

WordPress upgrade with svn sw

Most likely, it’s time to upgrade your instance of wordpress (given their releases are every couple weeks).

Backup the db and code:

mkdir -p ~/.archive
mysqldump blog | gzip &amp;gt; ~/.archive/blog-$(date '+%Y%m%d').sql.gz
cd ~/public_html ; tar czf ~/.archive/blog-$(date '+%Y%m%d').tgz blog

Then upgrade. Note that switching from 2.7.1 to 2.8 isn’t just a “svn switch” — you must svn update first.

cd ~/public_html/blog
svn update
svn sw http://svn.automattic.com/wordpress/tags/2.8.3/

The next time you hit the wp-admin page, it will upgrade the db and you’ll be done.


  • Update November 15, 2008: 2.6.5 is out. See installing wordpress using subversion.
  • Update December 14, 2008: 2.7 with new admin UI hotness
  • Update June 15, 2009: 2.8 requires an `svn update`
  • Update July 9th, 2009: 2.8.1
  • Update July 22nd, 2009: oye, 2.8.2
  • Update Aug 4th, 2009: oye, 2.8.3