Making sure South migrations get run when using Django’s create_test_db()

I’ve been experimenting with using Lettuce for a project.  When not using Django’s test runner, you can use the framework’s test database hooks by calling create_test_db() (see the Django docs for create_test_db()) from a method in your terrain.  Django Full Stack Testing and BDD with Lettuce and Splinter is a great resource for seeing how to get up and running.  But, I was having a terrible time because create_test_db() was throwing an exception because it was trying to run the flush management command to flush data on a table that hadn’t yet been created.  According to South’s documentation, “South’s syncdb command will also apply migrations if it’s run in non-interactive mode, which includes when you’re running tests.”

While South’s syncdb command was getting executed by create_test_db(), the option that tells the command to run the migrations after running syncdb, wasn’t getting properly set.  It turns out there is a (not very well documented) workaround, you have to call before your call to create_test_db().

So, your might look something like this:

from lettuce import before, after, world
from django.db import connection
from django.test.utils import setup_test_environment, teardown_test_environment
from import patch_for_test_db_setup
from splinter.browser import Browser

def setup(server):
# Force running migrations after syncdb.
# syncdb gets run automatically by create_test_db(), and
# South's syncdb (that runs migrations after the default
# syncdb) normally gets called in a test environment, but
# apparently not when calling create_test_db().
# So, we have to use this monkey patched version.
world.browser = Browser('webdriver.firefox')

# ...

A Heads-Up About Head-Down Coding

This was originally posted on the Local Fourth blog as part of my participation in a community media innovation project at the Medill School of Journalism.

I first became acquainted with the term hackathon in college. A computer science student group organized an all-night event in one of the computer labs and ordered in pizza and a seemingly limitless supply of caffeinated soda. I remember the event as fun, but I mostly worked on classwork. I didn’t yet have a backlog of personal hacking projects that could really benefit from hours of uninterrupted coding.

At the start of this project, Shane, Steve and I participated in a mobile hackathon sponsored by The Media Consortium. It was a fun way to familiarize ourselves with our chosen software tools, get used to coding as a team and anticipate some of the hurdles we’d encounter during the innovation project. Though I spend a lot of most days in front of the computer, there’s something pleasurable about having an entire day, or weekend, of frenetic, uninterrupted programming. This might sound like hell to a lot of people, but it’s fundamentally satisfying to building something from scratch and to be able to be fully immersed in a project, really feeling every aspect of the process and design.

Most of my coding time doesn’t feel this way. Within the innovation project, there are countless meetings, e-mail threads to read, documents to share. While there is a certain amount of coordination required between developers working on the same code base, the time overhead required to connect with other teams feels like it increases exponentially. While communicating about the project often feels like an interruption, finding uninterrupted time to program is even more difficult when I have to factor in childcare responsibilities.

On a typical Wednesday, I try to leave the workspace before 3:30 to pick the kids up from their after school program. Then we head home where I have to help with homework, cook dinner, do the dishes, go to the park if we have time and then remind them when it’s time for bed. It’s around 9 before I can even think clearly about code again. Thursdays, I leave even earlier to pick them up from school, drop Florence at home and drive Oona to the West Loop for her dance class (though this has made me really good at doing long division in my head while navigating traffic). If the traffic’s bad, I’m in the car for around two hours total. I sometimes try to squeeze in a little work while they’re doing homework, or reading after dinner, but it usually feels like a kind of attention purgatory where I’m neither able to focus on the infuriating bug that I’m trying to fix or the needs of the kids. On the days when I have to leave early, it feels like I never end my work day at a coherent stopping point, where I’ve at least discovered the cause of a bug and have a plan for a fix or where I’ve sketched out enough of the implementation of a feature where I can come back to it and everything will make sense.

I’ve lived with and helped take care of my friend’s twin daughters, now 10 years old, for a few years.  But, my responsibilities, and their impact on my time, really ramped up since we all moved to Chicago. I’m somewhere between a babysitter and a parental figure and this ambiguity mirrors the range of likely responses to talking about trying to work on a software project and share in childcare responsibilities. For a lot of my peers, who are childless, the response is “I can’t imagine what that’s like.” For older folks who are parents, it’s more like “duh, that’s how it is.” It’s a tough topic to talk about, made tougher because, from week to week, I either feel overwhelmed by all the juggling or like the responsibilities that I have are a cakewalk compared with those of a full-time single parent.

As a recent thread about parenting and start-ups on the excellent Geek Feminism Blog points out, its not a very productive conversation to generalize about how parenting or any other real-life experience affects technology projects and the people behind them. Still, the experience of someone struggling to balance the needs of a project and the needs of others is different than those who aren’t struggling with such ambivalence. I’ve read accounts of developers who are fathers feeling alienated when they leave at the end of the workday, just as their childless colleagues are ordering pizza for a late-night coding session. During this past year’s Ada Lovelace Day, a campaign to forefront women in technology, a blogger voiced criticism that some men used it as an opportunity to acknowledge how their female partners gave them time to work on technical projects rather than celebrating the direct technical contributions of women. In the context of childcare responsibilities, it’s easy to see how this underscores a trade-off between one person’s ability to participate in demanding technology projects and another’s. But I want to go beyond pointing out that there might be some disparities and prejudices around different people’s availability for technology work or projects. Instead, I try to question whether the amount of time someone spends hacking on a project, or in the office necessarily represents the only value of their labor.

I yearn for days where I can work, uninterrupted and on my own schedule, on a juicy programming problem. But I, and hacker culture in general, may also overly romanticize this kind of heads-down coding. Interruptions are frustrating, but they can also mean that our work and lives as programmers are grounded in the world and not just in code. Good software exists to meet needs, not for its own sake, and a life without significant demands outside of a software project can make it much more difficult for a developer to design software that is both elegant and useful. Furthermore, more code, or time coding, doesn’t necessarily mean better code. I’ve definitely spent hours of intense coding, only to find that I’ve hacked my way into a corner, leaving behind a series of commits more convoluted than when I started.

Now I just need to remember this when I’m stuck in traffic rushing to make that after-school pickup.

Bookmarklet to generate Flickr image attribution text and link

This is a jQuery bookmarklet to extract an attribution string and link from a Flickr photo page.

To use the bookmarklet bookmark this link or drag it to your browser’s bookmarks bar: Flickr Attribution

The code is available at github.

At the time that I wrote this bookmarklet, I was using the the Monochrome Author theme (similar to the Monochrome Pro theme) by Graph Paper Press. It requires that you have an image associated with each post, so I frequently grab Creative Commons licensed photos for posts where I didn’t take a photo. I got tired of building the photo attribution string and link back to the photo by hand, so I made the bookmarklet to generate it with one click.

This is my first attempt at writing a bookmarklet and using jQuery.

I make use of the very helpful jQuery Bookmarklet by Brett Barros with modifications by Paul Irish as well as the zeroclipboard library for copying the text to the system clipboard.

There are probably some bugs with this code as well as lots of room for improvement. In particular, it would be nice to have the z-index of the bar displayed by the widget set so it covers all the FLickr page elements, but I couldn’t set a high z-index without messing up the zeroclipboard functionality.

String mangling in Excel/VBA

Often, I find myself needing to do string mangling in spreadsheets. For instance, in an Excel dump of an MS Access database, the names of institutions were sometimes written as “Foo, University of” or “Foo U”. I wanted these to be formatted as “University of Foo” and “Foo University” respectively. I may be misinformed but there doesn’t seem to be regexp style substitution in VBA. I could do this directly in the spreadsheet, but conditional use of functions gets to be hard to understand and difficult to edit. So, I wrote the following custom function in VBA.

Function FormatInstitutionName(institutionName As Variant) As String
'Formats an institution name for import into CiviCRM:
'"Foo, University of" => "University of Foo"
'"Foo U" => "Foo University"
    Dim newInstitutionName As String

    newInstitutionName = institutionName

    If InStr(newInstitutionName, ", University of") Then
        newInstitutionName = "University of " & Replace(newInstitutionName, ", University of", "")
    End If

    If InStr(Len(newInstitutionName) - 1, newInstitutionName, "U") Then
        newInstitutionName = Left(newInstitutionName, Len(newInstitutionName) - 2) & " University"
    End If

    FormatInstitutionName = newInstitutionName
End Function

Add this to your workbook by following the instructions at

Then call it in your spreadsheet cells like like:


PHP cheatsheet

This post is for PHP stuff that I needed to use, but couldn’t easily find on the web

‘pass’ in PHP

Maybe it’s bad to start using conventions from other languages, but I find that sometimes the code is more readable if you write an if statement so that nothing happens if the conditon is true and then put the code that will get run often in the else block.  In python, if you don’t want anything to happen in a block, you use the pass statement.  In PHP, you can just leave the block empty:

if ( $condition == true) {
// do nothing. note that other than the comment
// there are no statements in this block
else {
// do stuff


Domain-Driven Design

Thomas said this book is paradigm shifting.

What little I know about Domain-Driven design makes me think about using Domain-Driven Design to teach computer science+social justice in the same way that the Algebra Project is trying to develop a math curriculum based on real-world stories that include social justice themes.

Link to info on the book.
Link to entry on google books.

my first firefox extension! a NATO phonetics converter

My paid job is doing tech-support work and I often have to convey information to users over the phone.  To make sure we’re on the same page with spellings, I use the NATO phonetic alphabet.  But, I can never remember certain letters.  One solution would be to just remember the NATO alphabet.  Or, I could just write a Firefox extension that lets you select text, click on “Show NATO Phonetics” in the context menu, and get a popup of the phonetics for the selected text.

Install the plugin

Boxcar Inventory Development Update

The top seller queries weren’t working properly so I re-wrote them.  The update implementation is contained in the ‘book top sellers’, ‘books sold in last 2 months’, ‘comic/zine top sellers’, and ‘comics/zines sold in last 2 months’ queries.

community blog hacking

Spent a good amount of time fruitlessly looking for how to get future posts to show up in RSS feed (to allow syndication of events). The place to start looking is in the main method of the WP class (wp-inst/wp-includes/classes.php). Just follow the sub-methods and the relevent code is in there somewhere.

Update: look for the ‘//BOOKMARK’ comment to see where I was looking last.