Two hours with Sinatra

ruby sinatra thin simplelog blogging scanty twitter last.fm hpricot json

Thu May 21 20:17:46 +0000 2009

Recently I decided to spruce up this site. It had been languishing – as many personal sites do – in the realm of uninspired drivel, amounting to a few pointless paragraphs and a contact form which nobody used. Nice. Last year I had set up simplelog, a Rails-based blogging engine, with the intention of occasionally writing informative articles on my web development exploits. As an application, simplelog was brilliant: easy to use and relatively low on feature bloat. However, soon afterwards my enthusiasm began to wane. Partly because for some reason simplelog is no longer supported, which leaves me to maintain someone else’s out-of-date code, gem dependencies and so on. But mainly because I realised… being a web developer is all about getting your hands dirty, right? A lot of the fun of running a site (for me at least) is starting from a point of my own choosing, maintaining my own code and making feature modifications as and when I see fit.

As I considered my approach, I looked around and found other people discussing the poor Ruby blog options available, which in turn led me to Scanty, a tiny blogging application written in Ruby by Adam Wiggins, utilising the Sinatra microframework. I forked it on GitHub, made some quick modifications (mostly style changes) and deployed it with Thin, thanks to this helpful and succinct post by Garrick van Buren, all in the same afternoon. Result. Scanty is so devoid of unnecessary features it’s bordering on invisible (around 17kB by my count, not including gems, rackup file or docs), so it’s a perfect starting point for those wishing to build their own Ruby blog.

For whatever reason(s), I rarely used to find the time to update the one page that pretty much every visitor to this site sees – the static index page. So, spurred on by my first hassle-free Sinatra experience, I decided to can it and create something a little more dynamic. Thanks to Sinatra and the JSON and Hpricot gems, it took me two lunch breaks to complete. Most of that time wasn’t even spent working with Sinatra but on writing mad regular expressions to pretty up the text received from my Twitter feed. Comically, a few days later I went to a talk by Roland Swingler about Treetop, a parsing expression grammar which is meant to take the pain out of jobs like that. But I digress…

By parsing JSON feeds from places elsewhere on the web which see a little more of my time (Twitter, last.fm), and adding the most recent entries from my new blog’s Atom feed, the site is updated almost every day without me lifting a finger. Far preferable to the static ghetto I’d become accustomed to.

I’ve put my efforts on GitHub under the slightly pompous name of ‘home’ (what?). It’s not intended as proper reusable software in its current state as it only really caters to very specific needs right now, but please fork and amend to your heart’s content if you so wish. Or just grab the useful bits and cook up your own! I do intend to make various improvements / enhancements. I’ll probably add public GitHub repo integration next, possibly even Brightkite if I start using it properly.

I highly recommend Sinatra for small application development. Soon I’ll have so much free time, I can spend afternoons bringing shame upon my friends and family by making geek jokes about eight-year-old hip-hop songs…

  def i_got(hoes)
    different_area_codes = [[404],[718],[202],[901],[305]]
    hoes.each do |ho| {
      different_area_codes[rand(different_area_codes.length)] + ho
    }
  end
blog comments powered by Disqus