Friday, March 25, 2011

Firefox4 on 64 bit Ubuntu

Now that Firefox 4 final is out, I wanted to switch to using it rather than version 3.x on my Ubuntu 10.10 systems. You can download a Linux version of Firefox 4.0 from the Mozilla site, but it's 32-bit only. While it will run, the problem I found is that all of my plugins (libflashplayer, etc) stopped working. The solution is to install the 64-bit build of Firefox 4, which is available on a launchpad PPA. Thus:

sudo apt-add-repository ppa:mozillateam/firefox-stable 
sudo apt-get update
sudo apt-get upgrade

That gave me a new, working FireFox 4.0. Most of my extensions worked OK, with the exception of (fix here), and All-in-one sidebar (now uninstalled). And, weirdly, the language packs aren't compatible between 3.x and 4.0, but I assume that will get sorted in time.

Thursday, March 24, 2011

Quick tip: SHA1 or MD5 checksum strings in Java

In a recent project (OK, I was processing FOAF data), I needed to be able to generate the hex-encoded string of a SHA1 checksum. The built-in Java security classes can do the heavy-lifting, of generating the checksum itself, but they deliver the resulting checksum as a byte-array. I needed the string encoding of that array. There are various code-snippets around on the web to do that, by iterating over the byte array and incrementally building up the string in a buffer, but they look low-level and inelegant. The following is much neater (written for SHA1, but the method works for the other digest formats):

public String getEncodedSha1Sum( String key ) {
    try {
        MessageDigest md = MessageDigest.getInstance( "SHA1" );
        md.update( key.getBytes() );
        return new BigInteger( 1, md.digest() ).toString(16);
    catch (NoSuchAlgorithmException e) {
        // handle error case to taste

Kudos to Brian Gianforcaro on StackOverflow for the tip

Thursday, January 27, 2011

Ruby, rvm and Eclipse

I've switched to using rvm for all of my ruby development. Rvm makes it trivial to have multiple copies of ruby installed side-by-side, while trying to do that using apt-get was proving a big headache. It has brought one minor gotcha though: rvm runs a script from the .bashrc or .bash_profile to set up the environment so that a current – default – version of ruby is always selected. If the .bashrc isn't run, no rvm and hence no ruby. I have my Linux desktop set up so that I have a quick-lauch button for Eclipse on the toolbar docked to the edge of my screen. Launching Eclipse from there doesn't invoke .bashrc for the containing shell, hence Eclipse wasn't seeing my installed rubies. I could point to the actual location of the ruby interpreters, but my applications weren't able to load any gems.

My solution was to force Eclipse to run in a shell which does load .bashrc. This is simply achieved by the -i and -c flags for /bin/bash: i to force an interactive shell (which loads .bashrc) and c to run a specific command (Eclipse in this case).