Archive for

December 2006

Mephisto Flickr Update

Thank’s to Nathaniel Brown for pointing this out.

A few days ago Flickr seemed to change their URL scheme for images served inside their RSS feed. The Mephisto plugin I wrote included the Flickr aggregation library from Typo. This does some regular expression parsing to determine the URL for other image sizes, but, because Flickr had changed their URL scheme, it broke.

Fortunately, the fix is pretty straightforward. Of course, first the test to show the new behaviour of Flickr:




12345678
def test_should_generate_correct_address_for_each_image_size  pic = FlickrAggregation::Picture.new(    :title => 'test',    :description => 'http://farm1.static.flickr.com/my_image_m.jpg'  )  assert_equal 'http://farm1.static.flickr.com/my_image_m.jpg', pic.image  assert_equal 'http://farm1.static.flickr.com/my_image_d.jpg', pic.medium

Running the test shows that we get an error - the regular expression fails to pick up the URL correctly:

NoMethodError: You have a nil object when you didn’t expect it!You might have expected an instance of Array.The error occurred while evaluating nil.first

So, we change our aggregation library to fix it as:




123
def image  description.scan( /(http:\/\/.*(static|photos).*?\.jpg)/ ).first.firstend

Run the test again and we’re green.

I’ve committed the changes into the Subversion repository. So feel free to get the update!

Incidentally, I wonder whether this is related to Ezra Zygmuntowicz’s post about speeding up page loads by serving images from cnames. Maybe it’s just coincidence.

Posted

Double Christmas Bonus

I noticed the other day that Flickr are now offering unlimited uploads for Pro accounts - previously it was set to 2 gigabytes. Not sure when that happened, but I only just noticed.

Not only that, but I’ve got a lovely shiny new Nikon D200 to fill it with! So far I’m pretty darn thrilled - from the couple of photos I’ve taken so far with it they seem to have a real, natural quality to them.

And since I’ve now got unlimited uploads, I can upload away to my heart’s content! Just need to start taking more pictures.

Incidentally, I also purchased a license for FlickrExport (for Aperture) too - I can now export to Flickr directly from Aperture! Oh, and I had a few problems initially because the full-resolution photos I were uploading were each over 10MB - Flickr’s limit per-file. Reducing the JPEG quality one stop for my export settings did the trick.

Posted

Parsing Parameters for Liquid Blocks

One of the first things I noted when I posted (some would say borderline complaining) about my first encounters with Liquid - the templating engine used in Mephisto and a few other apps - was the way it didn’t seem to abstract how parameters were set on the block.

Well, turns out it’s not quite so nasty as I first expected - you indeed don’t have to write all the regular expressions yourself. Inside liquid.rb a number of constants are defined, a lot of these are to do with capturing aspects of the tag.

One such regular expression is for TagAttributes, so we can write a test that:




12345678
def test_should_use_parameterised_url_for_feed  template = Liquid::Template.parse(    "{% flickrphotostream feed: http://blah/test.xml %}    {% endflickrphotostream %}")  first_block = template.root.nodelist.first      assert_equal 'http://blah/test.xml', first_block.feed_urlend

first_block is the first block that we encounter in our template - the Flickr photostream one. Inside our class, we can then build up an attributes hash from these items using the TagAttributes regular expression as follows:




123
markup.scan(Liquid::TagAttributes) do |key, value|  @attributes[key.to_sym] = valueend

Hey presto, we’re done.

Now, I’m not so sure I like this too much, it doesn’t feel very Rails-like. Too much dealing with regular expressions for my liking.

So, I’m going to continue refactoring my solution (please don’t read too much into the tests or code I’ve written so far, it’s very much a first stab over the course of a little hacking). As part of that, I’d definitely like to see if I can Rails-ActiveRecord-it-up a tad, a la:




12
class FlickrPhotoStream < Liquid::Block  attr :feed_url, :count

Maybe I’ll give that a go tomorrow.

Posted

Using, Not Just Trying Something (and Recruitment)

Jason Fried of 37signals just published the startings of a post he was writing about the difference between using and trying something.

It’s why agile lovers (such as myself) are so keen on the process. Not just because its a nicer way to work, everything is focused on feedback - from writing code test-first and using that feedback cycle to hone how you develop and design your code, to delivering early and often to customers to tune what you’re building.

It’s all very well just looking at screenshots, but its not until you try using it you see things. It’s why I’m loving seeing lo-fi prototypes in how we work - stickies on acetates that let you walk through the UI. Ultra-simplistic but uber-effective. In Jason’s words:

You don’t notice the quirks and shortcuts when you try something. Those revelations only come from real use. Eye candy shines during trial, but fades fast during use. Cool wears off quick, usefulness never does.

The last couple of weeks I was happy to be back in the ThoughtWorks office in London, working on various little utilities (and the Mephisto plugin). I was also fortunate enough to help out with some of our UK graduate recruitment.

As with Jason’s point above - it’s only when you sit and work with someone you get an idea about what they’re like. Both interviewee, but also interviewer - as the person being invited to an interview it gives a real insight into the types of people you work with.

After all, it’s all very well giving tests and asking difficult questions (which we also do), but actually working with something is a very different (and revealing) thing. But, just as importantly, it’s very refreshing.

Posted

Trying Out MediaTemple

At present, I primarily use a Virtual Private Server from RimuHosting.com. They are very affordable, and have a great reputation for support. I’ve been with them for well over a year and have had a brilliant experience with them so far. But, a couple of things sprung up that interested me so I couldn’t resist.

Firstly, MediaTemple announced their GridServer. Now, ignoring the academic definition of what constitutes grid computing or not, it’s a reasonably interesting offering - at least from a Rails point-of-view. Ben Rockwood (of Joyent/TextDrive fame) posted about their setup a while ago. But to paraphrase, it’s essentially lots of nodes fronting onto NFS, load balanced.

And it’s pretty easy to use, with their own commands for creating ‘containers’ which configures a Mongrel cluster and the Apache rewriting rules, as well as then starting/stopping containers etc.

But, going back to what Ben mentioned about it - while multiple nodes backed by NFS is fine for static content and PHP, and even works quite well, for Rails apps its a little less-so. Because these must be up-and-running in memory, these must exist inside a long-running Ruby on Rails container, and so are at least bound to a logical node. How they actually map onto Grid nodes is where I have no idea how it actually works, it would be interesting to see how it is distributed across the ‘Grid’.

Now, take this a step further (specifically with regard to the software I’m using - Mephisto) this kind of configuration is interesting because needing an up-and-running Rails container isn’t essential - since most of the time the content stays mostly static (I know - I’m a bad poster) and Rails’ caching generates HTML that is served directly by Apache (that sits in front of Mongrel, in the case of MT). Consequently, any node on the grid that receives a request will be able to serve the content direct from disk.

Theoretically, therefore, assuming traffic is predominantly skewed towards reading largely static content via. Mephisto, MediaTemple’s Grid is a good offering. Or, have I misunderstood something?

Of course, for different types of usage it’s potentially not so great - depending on how well the containers are spread and can take advantage of available resources. And, without knowing precisely how the grid routes requests to Rails containers I’m wary. Coupled with the fact that MySQL server problems have been rife as well as more serious problems with the whole grid disappearing it’s perhaps a little too early to be sure. But, updates are on the way next week so we’ll see.

Even more interesting is that I also read that TextDrive are updating their Shared Hosting sometime in the future to move along similar lines as their Accelerator product - a little closer to a more isolated system but with some shared resources (like database and email). Sounds very interesting, can’t wait to take a look when it launches and see how deploying Rails apps on it looks!

Posted

Flickr Plugin for Mephisto

I spent some time the other day putting together a plugin for Mephisto that would let me display a small selection of photos from my Flickr feed - you’ll see the results on the right side if you’re looking at this through my site.

Well, the first cut is done and seems to be working fine with a good response inside the Mephisto Google Group.

To install, you’ll need to change to your mephisto install’s directory and run

$ script/install plugin http://www.engross.org/svn/mephisto_plugins/mephisto_flickr_photo_stream/trunk/

then inside your template you’ll be able to use the following:

{% flickrphotostream feed: http://api.flickr.com/services/feeds/photos_public.gne?id=57966634@N00&format=rss_200 count: 6 %}  {{pic.title}}{% endflickrphotostream %}

I’m working on writing up some of the things I came across whilst I was working on it. I wasn’t happy with a few things (most importantly, the tests), and I’ve already started tinkering with the code again to improve it a little.

But, if you’re running Mephisto and want some Flickr goodness feel free to give it a try!

Posted
Fork me on GitHub