Archive for the ‘Uncategorized’ Category

Rails Single Table Inheiritance and class loading

Sunday, October 26th, 2008

I might have mentioned this before but you should be very aware of how your development environment loads and caches STI classes.

Update: yeah, I did mention this before.

Say I have:


class Partner
end

class DrivingSchool < Partner
end

class Library < Partner
end

and I want to query

Partner.find_by_partner_code("abcde")

unless the system has previously loaded DrivingSchool and Library it will not query those subtypes.

You’ll get

SELECT * from Partner WHERE type = "Partner" AND partner_code = 'abcde'

rather than

SELECT * from Partner WHERE type = "Partner" OR type = 'DrivingSchool' OR type = 'Library' AND partner_code = 'abcde'

and so those subtypes you want to include don’t come through.

The solution is to add the following to your ApplicationController.


# We're using STI here and it doesn't do a great job of loading up subtypes
# so if the system hasn't yet seen a subtype of Partner and you then query
# on Partner, it won't find subtypes.
require_dependency 'partner'
require_dependency 'library'
require_dependency 'driving_school'

I like the new Macbook

Tuesday, October 14th, 2008

But it isn’t so great that I’m not going to be able to hold off until June when my current Macbook turns 3 years old.

Now I need to send my Macbook back to get the wifi fixed again.

There, I just had to get that off my chest.

Thank you for your understanding.

Add ERB to your ActionMailer fixtures

Friday, October 10th, 2008

Easy:

def read_fixture(action)
  template = ERB.new(
    IO.readlines(
      "#{FIXTURES_PATH}/sms_registrations_mailer/#{action}"
    ).join
  )
  template.result(binding)
end

Now you can <%= %> in your fixture to your heart’s content.

Understanding this credit crunch thing

Wednesday, October 8th, 2008

I’ve been ignoring the news for a bit but wanted to learn more about what’s going on with the “economic crisis”.

Here are a few audio programmes that I’ve found very useful.

The Giant Pool of Money - explains the mortgage backed securities that kicked off this thing

Another Frightening Show About the Economy - explains what’s happened since

Planet Money Podcast - the same reporters have a podcast.

Why are these programmes good? They’re mostly jargon free. They give good, concrete examples of how these mechanisms work at a street level and individual company and bank level.

Oh, and listen to them in that order.

Creaky bottom brackets

Tuesday, October 7th, 2008

Today I visited the Hackney Bike Workshop for the second time. The first time I came away with a slightly improved bike and a promise that they’d have a special tool that I needed when I returned.

The workshop is a help-yourself type place with some very knowledgeable people who wander around giving tips and lending a hand.

I had some help from Paul, thanks Paul, who helped me track down and treat my bike’s particular creak and pop to the bottom bracket.

The process was incremental. First taking off the pedals, cleaning the thread, applying fresh copper grease, and re-installing. No change in the creak/pop.

Then out with the crank bolts. Application of a special crank pulling tool that works with the Shimano octa-link crank/axel combo.

Once the cranks are off you need another pair of special tools (splined?) for unscrewing the bottom bracket cartridge and the matching plug on the other side. Oh, and a fucking massive crescent wrench. 2 feet long! Lots of torque.

Pull out the cartridge / clean and grease the threads with copper grease.

Reinstall everything.

Tighten thoroughly.

Sorted, no more creak/pop. It is very satisfying to be able to fix something like that myself.

So, why bother with the workshop? Why not just go it alone?

Tools: they have lots of them and that saves cash.

Work stands: expensive to own in terms of space and cash, they have lots.

Know how and experience: when you’re applying ludicrous force to a rather expensive and soft aluminium bolt it is very nice to have someone there to reassure you that you’re doing the right thing. They’re as hands-off as possible too, letting you get the feel of things yourself.

They take small donations. Isn’t that nice of them?

Hackney Cyclist’s maintenance workshop

I also recommend Zinn and the Art of Road Bike Maintenance (2nd Edition) - it is damn fine for telling you things like “the right hand side of the bottom bracket has a left hand thread so you turn it the other way to loosen it.

Bottom line, never get reamed by a bike repair workshop again. This stuff is easy and having someone to show you the ropes is a great confidence builder.

Other random notes: they have a barrier cream. If you use that before you start working on stuff then all the grease washes off pretty well at the end. Bring your own band-aids if you have a habit of skinning your knuckles on bike bits when working on them. They seem really good at helping people learn basic preventative maintenance too.

I’ll probably go along most of the time now as I ride enough that my bike is always in need of some sort of servicing. When I leave London and move somewhere that owning your own bike stand is feasible I’ll have the experience and know-how to be a self sufficient cyclist.

Next year I might use the workshop to build a cool-kid single speed / fixie from salvaged parts… if I can find any.

Rails Flash.now

Tuesday, October 7th, 2008

flash[:notice] when redirecting

flash.now[:notice] when rendering

well… learn something new every day.

this will stop your flash lasting one action too long

great write up here:

http://www.rubysavedmylife.com/2007/12/15/flashnotice-vs-flashnownotice/

thanks guy. that’s rad.

Nick Hornby interview with David Simon, creator of The Wire

Thursday, September 25th, 2008

The Wire is the best TV show I’ve ever seen. We’ve just started watching the fifth and final season/series.

Here’s a great interview with the creator.

Beginning with Homicide, the book, I decided to write for the people living the event, the people in that very world. I would reserve some of the exposition, assuming the reader/viewer knew more than he did, or could, with a sensible amount of effort, hang around long enough to figure it out. I also realized—and this was more important to me—that I would consider the book or film a failure if people in these worlds took in my story and felt that I did not get their existence, that I had not captured their world in any way that they would respect.

http://www.believermag.com/issues/200708/?read=interview_simon [via 43folders.com - I like Mr. Mann's new direction]

This space…

Sunday, September 14th, 2008

Quiet around here of late.

I’m working on:

http://writersresidence.com

http://theorytestpro.co.uk

and I just pushed out http://whenshouldwe.com with a fresh coat of paint courtesy of the wonderful folks at With Associates (http://withassociates.com) who you should really use for all your web design, development and hosting needs.

Um, what else? Well, I’m sure you’ll be thrilled to hear that it was sunny in London today and that we went to a barbecue at Henry’s. I highly recommend Henry and Erwan for all your barbecue hosting and cooking needs.

That’s it for now.

Rails: Don’t create a controller namespace with the same name as one of your models

Thursday, July 31st, 2008

For example:

I have a model Partner and I have a parter section of the site I’m building so I created a namespace Partner.

That results in lots of these:

inflector.rb:298: warning: toplevel constant SignupsController referenced by Partner::SignupsController

and that results in lots of these:
:( :( :(

Jeremy Voorhis Says:
June 30, 2006 at 10:04 am
In Ruby, you cannot have a class and a module with the same name.

More here.

Writing Portfolios

Monday, June 9th, 2008

Monica built her own website when she became a freelance writer. She hosted it on WordPress and that was fine. Except it kinda sucked that she had to spend her time doing that instead of pitching to editors. Along with that it was really lucky that she had the skills necessary to wrangle WordPress and I had a server and the knowledge to install it.

We decided to fix that problem for other writers and we created Writer’s Residence. The site is a tool that we hope does one thing well, help writer’s create and host their own writing portfolio is 30 minutes or less.

When you sign up you get an address like http://monicashaw.writersresidence.com so you’re ready to get your site out to editors with no further expense. If you want to bring your own domain you can hook that up to so you can have a Writer’s Residence portfolio with an address like http://monicashaw.com

Anyway, it was fun to build and I learned a lot in the process.

We’re now learning how to market the site and I think that that is going to be a very steep learning curve.

Writer’s Residence