Some python (and Django) utilities for working with pgcrypto. Includes a fun pure python implementation of ASCII Armor format — http://www.ietf.org/rfc/rfc2440.txt
It’s been stuck here for 15 minutes. There is no close box or cancel button, and obviously no timeout checking. I realize it’s a beta, but this does not bode well.
My Bar
I finally put the finishing touches on the bar I’ve been building for the better part of 3 years. I still need to finish behind the bar, and get some shelves, but I’m not ashamed to have people in my basement anymore. To celebrate, Alexa went out and picked up a new dartboard and cabinet. No bar is complete without darts.



I whittled that corner piece myself.
iPhone Web App Links
I was working on an iPhone web app recently (my first, actually) and came across an annoyance: any links in a web app with apple-mobile-web-app-capable set to “yes” will open in Safari, not the app itself. I wanted to keep things as simple as possible, and not have to change my code to support AJAX loading. Some research turned up this article which did almost exactly what I wanted, except I didn’t want to load a page into a container. I wanted all links to Just Work how you’d expect links to work. So I dropped this bit of jQuery code into my base template, and everything seems to work great:
$(document).ready( function() {
$('a').each( function(idx,elem) {
var url = $(elem).attr('href');
var js = "javascript:window.location.href='"
+ url + "';";
$(elem).attr('href', js);
} );
} );
This could probably be done just as easily without jQuery using getElementsByTagName, but I’ll leave that as an exercise for the reader.
A Django file storage backend that transparently compresses files using the gzip python module. Nothing fancy, but it gets the job done, with a few caveats:
- Since the data returned by
GzipFile.readis not necessarily of the length you requested,File.chunkswould sometimes leave off the last bits. I wroteDjangoGzipFileto return just a single decompressed chunk to get around this, but a better approach would check to see if any data remains and yield it at the end. - For compressed files, the path has
.gzappended to it, so the path you request via the storage system may not exist on the filesystem. Just something to note if you access the files without using the storage system.
Writing this also gave me a few ideas for some small refactorings to make FileSystemStorage more easily subclass-able:
- Overriding the
pathmethod made it easy to append.gztransparently, but I had to write my ownlistdirsince I didn’t want to add.gzwhen resolving a directory path. It might be nice to have a path transformation helper method thatFileSystemStorage.pathcalls. - It would be nice to move the directory creation and permission “post-processing” out of
FileSystemStorage._saveand into helper methods to avoid having to copy/paste the code. Alternatively, there could be another method to actually write the file data that_savecould call by default.
Not that any of this is difficult to deal with, but I’d imagine file system storage backends could almost be considered a class of their own when you start thinking about things like compression, sharding, etc. Making it just a bit cleaner to create them would be a nice touch.
Subclassing SearchableModel and using SearchManager basically lets you do things like this:
SomeModel.objects.search('query', rank_field='rank')
Without having to worry about updating an index.


