Blog Posts

Tips for data smugglers

While I was working on the acts_as_resource plugin trying to fix things up so that the resource finding side of things works neatly, I realised that I needed some way to get at the ordered list of parameter keys that were matched by the routing system. One way to do it would have been to parse the path again, but that smacked a little too much of repetition, after all, the routing system knows this stuff already, but how to get at it?

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

My first 'acts_as' plugin

So, you’ve upgraded to Rails 1.2.1 and you’re working on a tool to maintain a database of all the tunes you have in your various songbooks and (eventually) your record collection. You start with: $ ./script/generate rspec_resource MusicBook title:string author_id:integer \ abstract:text $ ./script/generate rspec_resource Tune title:string composer_id:integer \ abc:text book_id:integer You decide to come back to composers and authors later, so you set up your models[1]: MusicBook.has_many :tunes Tune.belongs_to :music_book

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Continuing Sudoku

Your mission, should you choose to accept it, is to explain what the following code does: class Amb def initialize @error = Exception.new("Ran out of possibilities") @failure_continuation = lambda {|v| @error} end def assert(assertion) if !assertion self.fail end end def deny(assertion) assert !assertion end def fail @failure_continuation.call(nil) end def maybe one_of [true, false] end def one_of(collection = []) k_prev = @failure_continuation callcc do |k_entry| collection.each do |item| callcc do |k_next| @failure_continuation = lambda do |v| @failure_continuation = k_prev k_next.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Five things you probably don't know about me...

I’ve been watching this five things meme coursing round the blogs I read for a while now, and chromatic just tagged me to share five little-known personal facts. In a perfect world I would be making a living as a folk singer. In the real world, the market for an unaccompanied singer of mostly traditional songs is somewhat limited. There are very few things in life enjoy more than singing in good company.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Word of the day: Musicking

A friend of mine, David Morton, just pointed me at a transcript of a lecture given by one Christopher Small. In it Small nails something I’ve been trying to articulate for ages. I don’t know whether to applaud madly or seethe with silent resentment that someone said it so much better, and in 1995 at that. On balance, I’m applauding. Read it, it’s worth it for Opera story alone.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

What I've been up to recently

Cast an eye over my new venture. It’s pretty much a place holder site at the time being, but I’m beavering away at the bits that need beavering away at.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Blessed are the toolmakers

My dad drives a vintage Fraser Nash. I say drives, but that’s only half the battle, a large part of his Nash time is spent fettling it. It’s an old car; bits wear out, break or drop off. And because it’s an old car, you can’t just nip round to Halfords and pic up a replacement; nor can you head down to the breaker’s yard and cannibalize something else. So he has a lathe and a milling machine and a bewildering collection of tools.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Getting the Rspec religion

I’ve been eyeing the rspec and rspec on rails packages and thinking I should give them a go. To my eye at least, something like: context ‘Given a published article’ do fixtures :contents setup { @article = contents(:published_article) } specify ‘changing content invalidates the cache’ do article.body = 'new body' article.invalidates_cache?.should_be true end end context ‘Given an unpublished article’ do fixtures :contents setup { @article = contents(:unpublished_article) } specify ‘changing content keeps the cache’ do `article.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Everyone is human...

Why do people have to be human with my new computer? You would think that arriving home and opening up a brown cardboard box and pulling out a shiny new 15" MacBook Pro 2.16GHz would be a fine thing wouldn’t you? It’s rather less than fine when what you’d paid for was a 17" MacBook Pro 2.33GHz. Annoyingly, it turns out that this wasn’t a case of someone in the local store pulling the wrong box from the stockroom.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

A sketch of declarative ActiveRecord Migrations

Writing migrations can get pretty tedious when you’re being scrupulous about writing both the up and the down side of the migration. Okay, so the Textmate ninjas amongst you can use scarily clever snippets to populate the down migration while you write the up method, but I can’t be the only Mac user who still prefers Emacs. And not everyone gets to run on Macs either. So, inspired by something Jamis Buck wrote about designing a DSL, I’ve been sketching out a DSL for describing the easy parts of a migration in declarative style.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Typo on Rails 1.2

Typo users with longish memories will recall the absolute disaster we had when Rails 1.1 shipped and Typo wasn’t even remotely compatible with it. Even edge Typo didn’t work with 1.1. Chaos and confusion, strong words from DHH, all manner of unfun things. So, this time, we’re not going to let it happen. We hope. For starters, the current Typo release, 4.0.3 is locked to Rails 1.1.6 - if you install it from the gem it will insist that you have an appropriate Rails gem installed too.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Dear LazyWeb

I would love to be able to run a slideshow on a second screen based on a ’live’ album in Aperture. So, when I drop an image into an Aperture album on my primary screen, it shows up when appropriate in the secondary screen slideshow. I can live with having to take an explicit ‘publish changes’ type step from within Aperture, but I’d rather not, and I certainly don’t want the secondary slideshow to stop.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Why fly when you can drive to Berlin?

Gill needs to go to Berlin next week to do some research at the university and the Ethnological Museum, and it’s no fun flying with a CPAP machine and an insulin pen in these paranoid times. So I shall don my chauffeur’s hat and we’re taking the ferry from Hull to Rotterdam on Monday night and driving to Berlin. So, if anyone reading this has tips for places to see, restaurants to eat at and all that good stuff, I’d be delighted to hear from you.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

How do you find me again?

Hmm… it’s been 3 months since I last did this. Time for another look at the incoming queries log.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Precalculating in Typo

You may or may not know that Typo is multiblog capable under its hood. There is a blogs table in the database and every single request ends up fetching the blog object by doing a Blog.find_by_base_url query. We don’t have UI support for multiblogging though, and the vast majority of Typo installations have exactly one blog object. Even when multiblogging comes along, there won’t be that many blogs in any given installation.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Getting back to Typo

I’ve been taking an accidental sabbatical from Typo. It started during conference season, then there was a bunch of housekeeping and general home type stuff that needed doing, so I’ve been away from the codeface for a while (and I still haven’t turned my EuroFOO talk into a podcast, or finished scanning and uploading all the EuroOSCON photos…) However, I am back and coding, and a new typo feature just made it to the top of my todo list: This morning, in a fit of over enthusiasm, I managed to zap the 36 most recent comments on this blog.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Second thoughts...

I just pulled the the entry entitled It’s not just open source that has a problem with sexism. Here’s why: My intention was to point up the kind of unthinking, ingrained sexism that is all too common in our field. My friends’ email exchanges with a conference organizer were textbook examples of the sort of thing I mean, so I used them and posted them pretty much verbatim without a thought.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Perspective

I stand by what I said in my last post. The fight against that kind of ingrained, unconscious sexism is one that is well worth fighting. But this morning I read about a woman who is fighting to have her claim of asylum recognized so that she will never have to return to her home country where she will be obliged have her clitoris cut off. What’s really depressing about the story is that she’s had to take her appeal all the way to the House of Lords - apparently the Geneva Convention doesn’t require signatories to grant asylum to people who fear persecution on the grounds of their gender.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…

Rolling back the enlightenment

Whatever your opinion the the Iraq war, whatever you think of Our Glorious Grinning Leader, it is still possible to point to at least one unqualified Good Law brought in by our current government. <typo:lightbox img=“188231238” thumbsize=“small” displaysize=“large”/> In July this year, my uncles, after being together for 36 years, got married. The law calls it a civil partnership, but it’s marriage in all but (official) name. Yay! One Good Thing.

  • 0 likes
  • 0 reposts
  • 0 replies
  • 0 mentions

Written by Piers Cawley on , updated

Read more…