Firefox Iframe Caching Bug

One of the most frustrating parts of web programming is dealing with browser quirks.  Javascript that works in one browser might not work in a different browser on the same OS; better yet, that same Javascript might not even work in the same browser and on different OS. Great, welcome to cross-browser/OS testing hell.

One particularly nasty browser quirk that I recently had to deal with was a Firefox iframe caching bug.  You can check out the full 5-year old bug report in all its glory here.

To summarize the problem, if you have an iframe whose content is set dynamically on page load, Firefox will cache the content of the iframe so that on the next page load, it will serve the cached content rather than the new dynamically generated content.  Traditional cache-breaking techniques like modifying the HTTP headers or adding a random string to the URL don’t work here.

After wrestling around for a while, I found a few posts here and here that helped me figure out a solution that worked for my case.  Here’s the gist of it:

var iframe = document.createElement("iframe");
iframe.src = "http://calvinyoung.org";
document.body.appendChild(iframe);

// And then set the src AGAIN after the iframe's been added
iframe.contentWindow.location.replace(iframe.src);

Why can’t browsers just agree on a uniform standard. It really would make everybody’s life so much easier.

Blocking Child Subprocesses in Python

As somewhat of a proof-of-concept for Minno, I put together a little web service called TorrentTraveler, which is a simple anonymous Bit Torrent proxy that lets users purchase single downloads with Minno.  The backend is in Python uses the subprocess module to execute a series of bash scripts that interact with transmission-daemon.

Everything seemed to work fine most of the time, but every now and then, I’d run into this strange problem where it’d look like the server action would block on a child process spawned with subprocess.Popen.  This didn’t make much sense to me since the subprocess module actually spawns completely separate subprocesses.  I had a hard time understanding exactly what was going on until hacker guru Mahmoud jumped in and helped me figure it out.

While the subprocess module does in fact spawn separate processes, all child processes inherit file descriptors from their parents.  After a parent spawns a child process, the child process holds open some of these file descriptors, thus causing parent to block until the child process finishes executing.  In order to fix this behavior, I had to pass closed_fds=True as an argument to subprocess.Popen.

In Python 2.7, the subprocess module sets closed_fds=False by default.  I’m sure I’m not the only one who’s been bitten by this problem.  Luckily, in Python 3.0, the default has been changed to closed_fds=True, which seems like a much more sensible setting to me–hoorah!

Gone Fishin’

Call me Ishmael.  Five months after starting at Google, I’ve decided to go fishing.  And by fishing, I really mean dream-chasing.

Google was pretty much the amusement park of every nerd child’s dream, filled with the most incredible technology, really smart people, colorful ball pits, and the best free food money can’t buy.  I learned a lot and had a great time, but I always knew I’d end up leaving at some point to start a company; I just didn’t realize it’d happen so soon.  Then on one fortuitous day, I met my future roommate and partner-in-crime Noah.

Noah and I have both dreamt of building startups, and being young and indestructible, we thought we’d give it a whack.  As fresh college grads with little to lose, we both quit our jobs at Google to work work full-time on Minno, which is a new spin on micropayments.  More details as they develop, but stay on the lookout for updates!  Eric has–we’re expecting him to call any minute :)

And with that, we set sail!  This will surely be a long and most epic adventure. Heck, maybe we’ll even find Moby Dick.

My New Favorite Linux Command: at

I never have much to do in terms of regularly scheduled appointments during the summer, but I do have a lot of very quick one-off tasks that I need to do every now and then (ie water my mom’s plants, buy some milk, etc.). I’d normally be fine remember these things, but the summer always seems to make me particularly absent-minded when it comes to business concerning the real world.

I could make a Google Calendar event for each of these tasks, but a lot of these tasks would literally take about 2 minutes and I’m not glued to my GCalendar right now anyways.  I could have also written a reminder on a sheet of paper, but I would’ve really liked to use some sort of simple command-line reminder tool. After Googling around for a bit, I couldn’t seem to find anything that fit what I was looking for. But just as the disappointment was settling in, I found the command that would become my new best friend: at.

The Linux man page description for this command reads at executes commands at a specified time.  So it’s kind of like cron, except whereas cron schedules a task to be repeated at a certain time, at schedules a task to be executed just once.  Perfect!  Now I just need to bundle this together with a zenity dialog box and I’m in business.

The syntax for the command is simple:

at [time]

There are several other options that you can use with this but that’s about as complicated as we need to get.  The time format is flexible and can be something like “14:00,” “2:00pm,” or even simply “2pm.”  After we execute this command, at waits for the user to type in the commands to be executed at the specified time.  Alternatively, we could also just pipe a command into at from the command line like this:

command | at 2pm

I put this together with zenity in this shell script:

#!/bin/bash

if [ $# -ne 2 ]; then
    echo -e "Usage: `basename $0` '[text]' [time]"
else
    echo "DISPLAY=$DISPLAY zenity --info --text='$1'" | at $2 > /dev/null 2>&1
fi

To use it, simply execute something like this:

./remind.sh 'Freaking go to sleep!' 4am

And at 4am, when I’ll likely still be hacking away on my computer, I’ll get this lovely pop up on desktop to remind me to go to sleep:

That’s it! Now I have an awesome simple command line utility to help me remember those little one-off tasks that we tend to forget when we get sucked into our work.

New Look

If you’ve been checking this site regularly, you might have noticed that I’ve been switching between themes pretty frequently.  I’ve looked through a lot of themes but couldn’t seem to find one that I really liked, so I decided to design my own!  This is the debut of my first WordPress theme which I’ve called “So Fresh.”  I was going for a very minimalist design inspired by a lot of the themes here.  If you like it, you can download it at in the “Portfolio” section of this site.

I am the co-founder of a micropayments startup called Minno. I live and hack out of a little house in Palo Alto, CA. I like building things, photography, traveling, and beer.