Archive for January, 2009

Selected Saturday links

For quite a while I used del.icio.us to post summaries of interesting links here on an almost daily basis. After a while I got a little tired of the aesthetics of that: the clunky titles, the way it inserted tags, the fact that sometimes there was just one link and sometimes many. And I realised that for the quick/transient linking twitter works better.

So for now I’m going to try and post a digest every week or so, selecting the highlights. If you really want regular updates on what I’m keeping from what I’m reading, you can always follow me on delicious.

Tracking Heathrow with twitter

It's 11.23 on Thursday

A few months back—while we were discussing the number of talking objects appearing on twitter—Jenny pointed out to me that all Heathrow airport arrivals and departures data is online. That set my mind racing, as if you know all the flights leaving that currently controversial airport, there are all manner of things you could begin to do. Working out miles travelled and carbon emitted, spotting delays, and so on. But at the time it all came down to a quick note in Things to some day set aside time to explore.

That day arrived this week. The data turned out to be pretty simple to scrape, with a quick wrapper around hpricot, and to throw into an SQLite database using datamapper to give me a little abstraction and a place to throw a variety of methods to make my code simpler. And then it was a small matter of employing John Nunemaker’s twitter gem to set up regular tweets letting followers in on how many flights in and out of Heathrow there have been lately.

The result is a rather pleasing hourly summary, that adds a little rhythm and background awareness into my day. You can follow it at http://twitter.com/heathrowtower.

Perhaps the biggest frustration with the data is that all destinations/origins are given as city names. Given that city names are hardly unique, and even if they were a given city may have several airports connecting with Heathrow, that makes it a bit trickier to do some of the more sophisticated calculations. My hope is that the flight codes (which are given) can soon be transformed into a list of airport codes, which can then open up a route to more useful and interesting data. (if anyone knows of an existing database that does that mapping, please let me know!)

I’m looking forward to that, but I’m also anticipating the ambient awareness that having the bot running will create. Will the hourly ritual of seeing a sentence or two about Heathrow activity reveal any patterns? If they do, maybe I’ll update the code to make more of those. We’ll see.

For now, please do follow the tower on twitter, tell people about it, send it messages if you spot anything interesting, and feel free to take a look at the code over on github.

Migrating from attachment_fu to paperclip

Thoughtbot have released a suite of plugins over the past few months that are enlivening the fields of Ruby on Rails file attachments (paperclip) and authentication (clearance), long dominated by Rick Olson’s attachment_fu and restful_authentication. You can see some previous posts about attachment_fu here and here.

I’ve been playing with paperclip on a couple of projects, including one which was previously using attachment_fu. That necessitated some work migrating the previous attachments. Opinions are divided on whether data should be transformed in migrations or in separate libraries, and I’d rather remain agnostic on that, but I whipped together some code that can be used either in migrations or an external library to make the transfer.

You can find it as a gist.

To use it, do something like:

class ConvertAvatar < ActiveRecord::Migration
  include PaperclipMigrations
 
  def self.up
    add_paperclip_fields :users, :photo
    User.reset_column_information
    User.all.each do |user|
      populate_paperclip_from_attachment_fu(user, user.avatar, 'photo') if user.avatar
    end
  end
end

It’s quick and a little dirty, but it’s done the job for me. If you’re using S3 for storage, you might prefer to check out Andrew Timberlake’s writeup.