Saturday, October 29, 2005

Reconstructing Absinthe

I only became aware of Absinthe fairly recently (~2001) and was struck by the incongruity of a beverage which is readily available in my local supermarket being surrounded by an air of mystique. What I did not know was that, for most of the 20th century, it's been banned in much of the world; bans were only lifted in the EU in 1988 and are still in force in the USA. Wired has an interesting article on microbiologist Ted Breaux's obsessive recreation of authentic absinthe.

Wednesday, October 26, 2005

The sandwich predates Sandwich?

According to this History of Sandwiches, people have been stuffing food between bits of bread and eating it that way for almost two millenia prior to the hard-core gambler John Montague (Fourth Earl of Sandwich) making a habit of having his valet provide his meals in an easy-to-eat-while-gambling form.

Ah, trivia.

(via kottke)

Tuesday, October 25, 2005

Google Maps Pedometer

Cool, want to work out how long your jogging circuit is? Google Maps Pedometer allows you to trace out a line on a map and measure exactly that.

Mine is a mere 2.4km at present.

Saturday, October 22, 2005

FPS Level Name Generator

Dig those Doom/Quake level names? Here is a tool for rapidly generating your own. As Clive Thompson points out, this could also be used for naming blogs or corporate projects.

Would this worsen or improve Furman's software naming?

Sunday, October 09, 2005

Joe, the Amazing Coding Monkey

While reading J's Crick, I encountered a link to Bruce Tate's (of Bitter Java) brilliant allegory about Joe, the Amazing Coding Monkey. It describes beautifully the evolution of something that I fell in love with a decade ago into something that I now find a little indigestable. (It's all just detail, which is tolerable, but there's so much of it now.) Interestingly Bruce has also selected the same language that's on top of my "to learn" list.

(via a crick in the net)

Saturday, October 08, 2005

PostgreSQL, Perl and DBI

I recently had need to write a short script to take care of renaming a column during a PostgreSQL 7.2 (ala Debian Woody) to 7.4 (ala Debian Sarge) upgrade. Here are some gotchas that I overcame.

The underlying need for this change is PostgreSQL's "helpful" autotruncation of overlength symbol names. In 7.2 the limit was about 31 characters, in 7.4 it's about 63. The database in question had a column with a 36 character name which was being helpfully autotruncated, both during schema creation and use. After upgrading an existing database to 7.4, the column names in use were no longer being translated, but the column carried through during the upgrade had had its name truncated upon creation and, therefore, now appeared to be a different column name. At this point, the application stopped working. The script's job was to make the change, but to be graceful about it; to only attempt the change if it had not already been made. i.e. to remain idempotent.
#! /usr/bin/perl

use strict;
use DBI;
Pretty obvious.
my $dbh = DBI->connect ( "dbi:Pg:dbname=databasname;host=hostname", "usename", "password", { AutoCommit => 0, RaiseError => 1 }) or die "failed to connect to db";
Fairly straightforward, but note the RaiseError which obviates the need to put "or die" after every subsequent statement. This is ideal for a "do one thing or exit with error" script. More complex activties may require Perl's less-than-entirely-elegant exception catching mechanism (eval {statements}).
my $sth = $dbh->column_info(undef, undef, "tablename", "oldcolumnname");
Neat! DBI includes some standard methods for reflecting over the schema. Note, however, that what this really does is to set up a query, which then needs executing.

if ($sth->fetchrow_hashref() != undef)
$dbh->do("ALTER TABLE...
Yes, you read that correctly; a commit after a DDL (Data Definition Language) statment. Has 7.4 made DDL transactional? I didn't chase this down, but merely note that, without it, it didn't work. Thinking about it, setting AutoCommit on at the outset would presumably have had the same effect. I'm still astonished at the consequences of this though: "DROP TABLE foo; ROLLBACK;". Wow.
Just housekeeping. It is unlikely that you'd ever have multiple matches, but I did have some hiccups without this in place. The DBI docs say that you shold never need to do this.


Thursday, October 06, 2005

Presentation styles

Like plenty of other people, I've long disliked the typical corporate Powerpoint presentations. The first time that I actually saw a computer+bigscreen presentation that actually impressed me was when I went to see Dave Gorman's Googlewhack Adventure; his presentation style actually included, well, style. I've now seen another that, while not quite so well done as Dave's (Dave made plenty of use of the screen, but much of the performance involved him addressing the audience without support from the computer), it is nonetheless a quantum leap over the typical corporate Powerpoint. Interesingly, like Dave Gorman, Dick Hardt also appears to be a Mac user...

(Thanks to Jon Mann for the link.)