Skip to main content

One Hundred Push Up Challenge

I'm a bit of a sucker for silly physical challenges. For example, I'm hoping to complete the Canadian Death Race one of these days. So when I learned about the 100 Push Up Challenge, it immediately appealed to me. The gist of the challenge is to progress along a 6 week program, at the end of which you should be able to do 100 push ups in a row. I did the initial test tonight, and managed 23 push ups. Pretty pathetic, I know :P I thought I could manage at least 25! I intend to post updates semi-regularly on how I'm doing. Haven't decided whether I should start tomorrow, or wait until Monday. Stay tuned.

Life at Mozilla

Well, I've survived my first two weeks at Mozilla. It's been rough, what with the mandatory Rock Band, and the always excellent and plentiful coffee. Thanks to John and the rest of the Release Engineering team for their very warm welcome. The whole team got together in Toronto last week, so it was great to get to meet everybody. We're a pretty geographically diverse group, Toronto actually has the highest concentration of RelEng people...with 2 people. I'm slowly getting up to speed on how all Mozilla's systems work, but something tells me that I haven't felt the full strength of the Mozilla firehose just yet!

Upgrading Wordpress with Mercurial

Since Mozilla has started using Mercurial for source control, I thought I shoud get some hands on experience with it. My Wordpress dashboard has been nagging me to upgrade to the latest version for quite a while now. I was running 2.5.1 up until today, which was released back in April. I've been putting off upgrading because it's always such a pain if you follow the recommended instructions, and I inevitably end up forgetting to migrate some customization I made to the old version. So, to kill two birds with one stone, I decided to try my hand at upgrading Wordpress by using Mercurial to track my changes to the default install, as well as the changes between versions of Wordpress. Preparation: First, start off with a copy of my blog's code in a directory called 'blog'. Download Wordpress 2.5.1 and 2.6.3 (the version I want to upgrade to). Import initial Wordpress code:

tar zxf wordpress-2.5.1.tar.gz # NB: unpacks into wordpress/

mv wordpress wordpress-2.5.1

cd wordpress-2.5.1

hg init

hg commit -A -m 'wordpress 2.5.1'

cd ..

Apply my changes:

hg clone wordpress-2.5.1 wordpress-mine

cd wordpress-mine

hg qnew -m 'my blog' my-blog.patch

hg locate -0 | xargs -0 rm

cp -ar ../blog/* .

hg addremove

hg qrefresh

cd ..

The 'hg locate -0' line removes all the files currently tracked by Mercurial. This is needed so that any files I deleted from my copy of Wordpress also are deleted in my Mercurial repository. The result of these two steps is that I have a repository that has the original Wordpress source code as one revision, with my changes applied as a Mercurial Queue patch. Now I need to tell Mercurial what's changed between versions 2.5.1 and 2.6.3. To do this, I'll make a copy (or clone) of the 2.5.1 repository, and then put all the 2.6.3 files into it. Again, I use 'hg locate -0 | xargs -0 rm' to delete all the files from the old version before copying the new files in. Mercurial is smart enough to notice if files haven't changed, and the subsequent commit with the '-A' flag will add any new files or delete any files that were removed between 2.5.1 and 2.6.3. Upgrade the pristine 2.5.1 to 2.6.3:

hg clone wordpress-2.5.1 wordpress-2.6.3

tar zxf wordpress-2.6.3 # NB: Unpacks into wordpress/

cd wordpress-2.6.3

hg locate -0 | xargs -0 rm

cp -ar ../wordpress/* .

hg commit -A -m 'wordpress-2.6.3'

cd ..

Now I need to perform the actual upgrade to my blog. First I save the state of the current modifications, then pull in the 2.5.1 -> 2.6.3 changes from the wordpress-2.6.3 repository. Then I reapply my changes to the new 2.6.3 code. Pull in 2.6.3 to my blog:

cd wordpress-mine

hg qsave -e -c

hg pull ../wordpress-2.6.3

hg update -C

hg qpush -a -m

Voilà! A quick rsync to my website, and the upgrade is complete! I have to admit, I don't fully grok some of these Mercurial commands. It took a few tries to work out this series of steps, so there's probably a better way of doing it. I'm pretty happy overall though; I managed a successful Wordpress upgrade, and learned something about Mercurial in the process! The next upgrade should go much more smoothly now that I've figured things out a bit better.

Moving on

I'm changing jobs. Yup, after nearly five years at Side Effects, I'm moving on. I have somewhat mixed feelings about this...I'm sad to be leaving such a friendly and talented group of people, but I'm very excited about my next job. I'm very happy to say that I will be joining Mozilla Corporation in their Toronto office starting in October. I'll be working in the Release Engineering group, helping to make sure that the world's thirst for new Firefox builds can be satisfied! I can't say how excited I am about this, it's pretty much a dream job: getting paid to work on a great open source project!

Announcing poster 0.1

I've just uploaded the first public release of poster to my website, and to the cheeseshop. I wrote poster to scratch an itch I've had with Python's standard library: it's hard to do HTTP file uploads. There are a few reasons for this, one is that the standard library doesn't provide a way to do multipart/form-data encoding, and the second reason is that there's no way to stream an upload to the remote server, you have to build the entire request in memory first before sending the request. poster addresses both these issues. The poster.encode module provides multipart/form-data encoding, and the poster.streaminghttp module provides streaming http request support. Here's an example of how you might use it:


from poster.encode import multipart_encode

from poster.streaminghttp import register_openers

import urllib2

# Register the streaming http handlers with urllib2


# Start the multipart/form-data encoding of the file "DSC0001.jpg"

# "image1" is the name of the parameter, which is normally set

# via the "name" parameter of the HTML  tag.

# headers contains the necessary Content-Type and Content-Length

# datagen is a generator object that yields the encoded parameters

datagen, headers = multipart_encode({"image1": open("DSC0001.jpg")})

# Create the Request object

request = urllib2.Request("http://localhost:5000/upload_image", datagen, headers)

# Actually do the request, and get the response

print urllib2.urlopen(request).read()

Download it as a tarball or egg for python 2.5, or easy_install it from cheeseshop. Bugs, patches, comments or complaints are welcome!

Validating credit card numbers in python

For various reasons I've needed to validate some credit card numbers in Python. For future reference, here's what I've come up with:

import re

def validate_cc(s):
    Returns True if the credit card number ``s`` is valid,
    False otherwise.

    Returning True doesn't imply that a card with this number has ever been,
    or ever will be issued.

    Currently supports Visa, Mastercard, American Express, Discovery
    and Diners Cards.  

    >>> validate_cc("4111-1111-1111-1111")
    >>> validate_cc("4111 1111 1111 1112")
    >>> validate_cc("5105105105105100")
    >>> validate_cc(5105105105105100)
    # Strip out any non-digits
    # Jeff Lait for Prime Minister!
    s = re.sub("[^0-9]", "", str(s))
    regexps = [

    if not any(re.match(r, s) for r in regexps):
        return False

    chksum = 0
    x = len(s) % 2

    for i, c in enumerate(s):
        j = int(c)
        if i % 2 == x:
            k = j*2
            if k >= 10:
                k -= 9
            chksum += k
            chksum += j

    return chksum % 10 == 0

Father's Day Run 2008

Me at Father's Day Run last year In what is becoming something of an annual tradition, I'm going to be participating in the 2008 Father's Day Run in support of prostate cancer research. Both my father and father-in-law have had prostate cancer, so this is a cause that's very close to my heart. Please consider supporting me in my run by clicking the image above, or this link. BTW, that's me and Thomas in the picture at last year's Father's Day Run - the first time I ran as a new father!

Re: Tolkien didn't like Narnia?

Holly, I've heard this before as well. I came across a much much much longer article earlier this year: Letters to Malcolm and the trouble with Narnia (by way Mark Shea's blog) This hasn't really affected my enjoyment of Lewis' works. Mel and I also love Narnia and we can't wait to see Prince Caspian in the theatres (subject to babysitting too!) It just means that I wouldn't use Narnia as a way to teach concepts about Christianity to somebody. You could still point out ideas in Narnia that draw from Christianity. But I wouldn't use the Narnia stories to draw conclusions about Christianity - I think this could be a natural inclination since in many ways the Narnia stories are very similar to ideas and events from Christianity. So, we enjoy Narnia for what it is, a fantastic set of stories set in a wonderful world with characters that we grow to love.