Announcements


28
Mar 09

Rails 2.3 final and theme_support updates

Somewhere between Ruby on Rails versions 2.3.0 (RC1) and 2.3.2 (final) a change was made to the arguments required for one of the methods the theme_support plugin requires. I must confess I hadn’t spotted it, but github user knapo kindly sent me a message with a patch. That patch is now applied in the main repository, as are a few tweaks to the ActionMailer integration to better handle multipart emails. You can get the new version from github.

Perhaps more significant than those small patches is that I’ve now pushed up a new rails app for use in testing theme_support. The tests are a series of cucumber stories, and the app is very barebones designed entirely to test the various features. I could do with tightening up the way the test app and the main plugin repository are connected, but it’s a start and has been very helpful with the aforementioned patches. Any improvements to the test suite would be much appreciated. You can, of course, find it on github.


23
Feb 09

Hacking wordpress to support per-post banner images

post-bannersI seem to be spending a lot of time with wordpress at the moment. It’s become so ubiquitous that it often makes far more sense to set it up and integrate with an existing app than to set up some other blogging system and re-train users. As a result I’ve been writing a few wordpress plugins. Most of them are too specialised to be worth sharing, but one seemed worth opening up…

Implementing a (not quite public yet) design recently I had need of a way to specify a banner image for each post. While wp has pretty good support for adding various media into the body of posts, this needed to sit outside the post body.

I whipped together a quick plugin to handle uploading a banner and storing its details in the metadata for the post. It was a simple process, nicely self-contained, except that the post edit form doesn’t have the appropriate enctype=”multipart/form-data”. I looked around for any hooks that would allow me to cleanly add attributes to the form tag, but in the end resorted to editing wp-admin/edit-form-advanced.php to add it.

I’d hoped that there’d be time to find a cleaner way to do all this before telling people about it—perhaps some javascript that hooks into the existing media selector but allows it to populate a custom data field?—but it hasn’t, so I’m throwing it out there to the wider world as-is. The code is at github. Feel free to take it and use it as-is, to fork it and update it to be a better wordpress citizen, to email me patches to apply to my copy, or even to employ me to spend more time cleaning it up! Either way, it deserves to be out in the open and hopefully it’ll be of us to somebody besides me.


13
Feb 09

Quick update on Heathrow Tower

While there haven’t been any visible changes to my Heathrow Tower project in the past couple of weeks beyond my throwing in a few greetings in other languages to break things up a bit. Having put some of the statistical plans on hold as the snow last week prevented any data gathered from being anywhere close to representative, I’ve gradually been building up the database behind the scenes so I can start to do some of the more intricate things I’d like to do.

The key data I wanted was the airport codes for the various flights, and geographic data for those airports.

Firstly I found FlightAware.com who will provide all sorts of data from a flight code, but unfortunately the first time I tried making a request to their site using HTTP Client I spotted a comment in the HTML referring visitors to http://flightaware.com/about/termsofuse.rvt which states:

You will only access the FlightAware web site with an interactive web browser and not with any program, collection agent, or “robot” for the purpose of automated retrieval of content.

So I started looking at airline sites. United have a relatively straightforward URL scheme that responds to a GET and returns data that can be scraped. eg:

http://www.ua2go.com/flifo/FlightSummary.do?date=20090201&fltNbr=959

BA and Virgin, on the other hand, both require cookies to be enabled in order to get results from their flight trackers and don’t advertise any other URLs for flight data. Once I’d realised that only one of those three carriers was going to be helpful, I decided not to keep checking airlines.

So, a little frustrated, I tried just typing flight codes into google. And lo and behold… most of them give useful results. It doesn’t get them all, of course, but it’s enough that out of the 838 flight codes in the database, 695 are fully identified. Of those not identified, a number seem to be flights that were diverted to Heathrow but don’t normally go there.

So with some sense of the airports served, I also want to know about the airports themselves. Wikipedia’s pretty good there, with geo data for them all in an easy to capture form. Some, like Heathrow itself, are very easy to find:

http://en.wikipedia.org/wiki/LHR

while others are a bit trickier. But with some manual intervention I was able to get all of that data. The manually produced mappings and the code for pulling in the data can both be found on github.

More updates as time allows…


2
Feb 09

Rails 2.3 and Grand Rapids WiFi

I like to always have at least one project on the go that works as a testbed for a variety of new Rails techniques, tools and releases. For a long time that project was Grand Rapids WiFi, a site that lapsed into some neglect after I moved (a long way) away from the town it focussed on, but which I still officially maintain. It was where I first tried Rails 1.1 and 1.2, where I got to grips with various geo tools, and where I first generated RDF and Atom from a Rails app.

With this morning’s announcement that there’s a release candidate of Rails 2.3 out, I decided the time was ripe to dust off the GR WiFi code and move it from Rails 1.2.x to 2.3.0. It turned out to be a nice quick process, even allowing for the time it took to move it all onto github.

  • Tidy up environment.rb to remove some deprecated features, and specify the new gem version
  • Run rake rails:update to rename application.rb to application_controller.rb
  • Remove quite a few defunct plugins that we didn’t need anyway
  • Replace a couple of plugins with relevant calls to config.gem
  • Rip out the use of components (what was I thinking?) and add a new model to help with sidebars
  • Tidy up a few old paths
  • Update my deploy script to get the code from git rather than svn

This site was where I really learned my way around rails’ test/unit-based testing framework and I’m sad to say that the tests now lie rather neglected. If time allows, I’ll kick them back into shape so they can be used to uncover any dark corners of the code that haven’t survived the transition, but for now I just wanted to get the site upgraded quickly and hopefully running a bit more efficiently.

For those who’d like to play with the code, it’s all public now over on github. I make no promises as to the quality of the code, but feel free to take it, use it, path it, etc. If you do end up using it for anything, please do let me know.


29
Jan 09

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.


12
Dec 08

For Sale: Canon Digital Rebel XTi/400D

UPDATE: The camera has now been sold

rebel_xti_586x225

Having recently upgraded to the wonderful Canon EOS 50D I’m looking for a new home for my old 400D (actually the US version: the Digital Rebel XTi). I’ve taken about 15,000 photos with it and it was a great introduction to the world of digital SLRs. Despite all that use, it’s in really good shape and will come complete with a 2GB memory card, a spare (non-Canon, but perfectly fine) battery, strap, 18-55mm kit lens, and US and UK chargers, all in the original box.

I’m planning to list the camera on ebay on Monday or Tuesday next week, but wanted to throw the option out there if anyone wants to make me offers in the region of £275 including postage (within the UK). Email me at james@jystewart.net if you’re interested.


8
Dec 08

XML_Feed_Parser: Handing over the reins

For the past few years I’ve been maintaining a PHP package called XML_Feed_Parser. It’s part of PEAR and attempts to offer a unified API for handling RSS and Atom feeds in your PHP code, a little inspired by projects like the universal feed parser. Its parsing and API are pretty comprehensive, but lately I’ve been falling a bit behind in managing it and there are aspects that could definitely do with some attention.

So I’m looking to hand it all over to someone with more time and energy for it than I. Preferably someone who uses it in an active project (being primarily a ruby developer these days, I spend a lot more time with feedtools than with my own package). I’m going to mark the package as ‘unmaintained’ and if you want to take it on, take a look at the appropriate page in the manual.

And if you want the full story of why I’ve chosen now to make this move, it’s made fairly clear on flickr and my other blog.


22
Oct 08

New home for Rails 'geo plugin comparison'

About eighteen months ago I compiled a series of reviews of Ruby on Rails plugins concerned with geography. I put together a comparison chart and posted it on this blog. It subsequently found a new home on a wiki, but lately that wiki has rarely been accessible so I decided it was time to move it all back into this site.

You can now find the comparison chart at: http://jystewart.net/process/resources/rails-geo-plugins/

A few updates have been lost along the way as they were solely made on the wiki, but hopefully it’s still of use. Since I published the original reviews and chart my attention has wandered a little from the geo plugin scene, so please do flag up any new plugins, changes in features or fixes that I may have missed. I’m going to be trying to check through all the existing listings to update them but that may take a while, so comments here may well encourage me to focus more quickly.


15
Oct 08

acts_as_amazon_product

A couple of years ago I wrote and released a Ruby on Rails plugin called loads_from_amazon. It made it relatively simple to populate a model with data based on an amazon search, and was very helpful in the project I was then working on.

That project ended and I’ve not had time to maintain the plugin since. It was based on a clunky amazon ECS library and I kept meaning to rewrite it to sit on something more up to date, like amazon-ecs, but the time never materialised.

Today I stumbled upon acts_as_amazon_product which looks like it does everything my plugin did, and more. If you’re looking for that functionality, it seems like that’s the place to go.


20
Aug 08

Announcing image_associations

Discussions of multi-model forms and nested models in Rails has been revived recently, with various changes appearing in Edge Rails, plugins like attribute_fu getting a lot of attention, and the release of ActivePresenter. It looks like when the dust settles we’ll have a nice new set of ways to simplify our code.

One thing I frequently find myself doing is associating multiple images with a given model. My news story might have a banner image, and a series of other attachments, which I could specify with:

class Story < ActiveRecord::Base
  belongs_to :banner_image
  has_many :story_attachments
end

class BannerImage < ActiveRecord::Base
  has_attachment # I'm using attachment_fu
end

class StoryAttachment < ActiveRecord::Base
  has_attachment # I'm using attachment_fu
end

(or I could use has_one in place of belongs_to there, your tastes/requirements may vary)

What quickly becomes a pain is assigning the images to the models, and having rejected fat controllers I often end up writing accessors on my models to manage that for me:

class Story  data)
    end
  end

  def valid_file?
    # etc.
  end
end

That quickly gets dull, so I've wrapped it up in a plugin I'm calling image_associations. With that I can write:

class Story < ActiveRecord::Base
  belongs_to_image :banner_image
  has_many_images :story_attachments
end

and get the accessors for free.

It may only be of use to me, and it's pretty crude (there's no support for deleting attachments, for example) but it's been working nicely and has DRYed up my code in a satisfying way, so I thought I'd throw it out there. You can find it over on github.

(I'm not promising to keep supporting it, but it is used in an active project so chances are bug fixes will make it in. And of course, anyone is welcome to branch the project and twist it in their own ways)