Pickling Complex Classes

If you’ve got a particularly complicated python class that you need to pickle, you might find that it’s a little unusual when it comes out the other side. This could be because by default init and new aren’t called on objects when they’re unpickled. If you need your init/new behaviour to be called at unpickle time, you can define getinitargs or getnewargs to request the methods you want to be run. These methods should return tuples containing the variables you’d like to call the method of your choice with. They’re called at pickle time and the tuple that they generate is stored with the object. ...

June 23, 2009

Checking out files from branches in Git

If you just need one file from a branch in git, you can grab it with checkout: It never occurred to me that this would work, because, frankly, it’s far too easy. Good work, Git.

May 28, 2009

Git Diff in a text editor

If you want to have a look through your git diffs in a more useful editor than the default, you can just pipe it in on the command line: Or, you can set your GIT_PAGER environment variable to your editor of choice. Thanks to the good people at Stack Overflow.

May 14, 2009

Converting Prices to 15% VAT

If you’re in the UK and you muck about with prices a lot, you might have to convert them to the new (new-ish, anyway) VAT value of 15%. I made this TextMate command to make life a little easier for you.

May 11, 2009

AutoLoading (or, table reflection) using Elixir

I spent a while knocking this together once before, then deleted it, so when I set out to find it again, I found this rather handy Guide to Elixir Autoloading. Thank you, whoever wrote that! I really don’t get why this can’t be as simple as ActiveRecord, but sure, whatever, Python does like to be complicated.

May 9, 2009

Building PIL with JPEG support under MacOS X

Getting the Python Imaging Library (v1.1.6) working in MacOS (Leopard) took a bit too much reading for my liking, so here’s how I did it. First off you’ll need to get yourself the libjpeg source. Basically, Follow this guide to get libjpeg installed. It’s not quite that simple though: when you run .configure, you’ll need to get it to actually give you your libraries: ...

May 9, 2009

Rails 2.1.0 scaffolding

I feel the need to post this because it’s not very clear to new rails users and if someone had posted it before my life would have been easier. Most Ruby on Rails tutorials are, for a start, incorrect, because they’re old (Thanks to David Lynch for helping me on that front), but even those that feature the slightly more up to date information aren’t clear on one point. This is the point. ...

May 9, 2009