Howdy!

Welcome to my blog where I write about software development, cycling, and other random nonsense. This is not the only place I write, you can find more words I typed on the Buoyant Data blog, Scribd tech blog, and GitHub.

Yes, that is hair on my chin

And it's taken an eternity to graduate from "adorable peach fuzz" to "smudge of dirt" status, so leave me alone.

I figure by the time it grows long enough to where I stop getting carded for alcohol, my hair will be gray, thus defeating the purpose.
Read more →

President's Day in Photos

While I don’t carry a decent camera around with me, I’ve found that the camera in my Samsung Jack is usually decent enough if I can hold my hands still (rare). Ended up snapping a few photos today and wanted to post them with a little bit of story behind them.

That's new

My bike route to the office takes me up and down Page St. which runs into Market St. just on the other side of Van Ness Ave. I never saw the accident or another car, I just saw a couple of cops and tow-truck guys standing around this flipped car on the turn from inbound Market St. onto Franklin St. I didn’t see any damage on the vehicle so I’m still quite puzzled how it was flipped and which direction it could have possibly been heading.

Leela and Zoidberg (Kid Robot figures)

I picked these two figures up from Kid Robot for Apture’s Christmas Secret Santa, they ended up going to Josh who didn’t take them with him for whatever reason. I’ve since moved them to a more visible location (right below the Hudson dashboard).

Twin Peaks shrouded in cloudery

Given the cloud cover that I normally ride home through I was quite surprised to see clear skies over Twin Peaks on my ride home. Of course, it is still February, so the clouds were still there, creeping along the ground.

Read more →

Building a game for ET. Day 1 with Pygame

Earlier this week I was checking out Pygame, pondering what I could possibly build with it that could keep me motivated enough to finish it. Motivation would like be the primary problem for me with any amount of game programming; I’m not a gamer, I don’t harbor a dislike of games, they’re just not something I typically spend time playing (I do like to play “haggard late night open-source hacker” though, that’s a fun one). Friday night I stumbled across an idea, ET likes to play (casual) games, perhaps we could write a game together; ask any engineer at EA or Ubisoft, there’s nothing more romantic than working on a game.

Talking over the idea with ET on the ride home from the office, we talked about creating a typing-oriented game and started to brainstorm. The tricky aspect of a typing-oriented game is you have to walk the fine line of “educational gaming”, that is to say, the game’s goal is not to teach the player how to type. That sucks. Contrasted to some other games where the means of progressing in some games is by solving a puzzle, killing noobs in others, in this game we wanted the player to progress through levels/situations with their typing ability (ET finds this fun, we do not have this in common).

Over pizza we discussed more about how the levels would work, I decided that I wanted to use stories/articles instead of random words for the “content” of the game. We settled on a couple fundamental concepts: the player would earn coins by correctly completing a words as the scrolled from right to left (similar to a ticker tape), they would lose coins if they made a mistake or could not keep up. After a player completed a level (i.e. a “story”) they would find themselves in a “store” of sorts, where they could purchase “tools” for future levels with their coins. The tools we decided would be a very important, as the player reached their upper bound of typing speed the utility of these various tools would necessary as a means of strategically conquering the level. One of the few things we didn’t particularly cover was the “end game”, whether the player would simply play increasingly more difficult levels (a la Tetris) or if they could actually “beat” the game. With at least the basics of the concept sketched out, it was time to start writing some code.

Starting with Pygame

It’s incredibly important to mention that I’ve never programmed a game before. Never-ever. From my work with network programming I was already familiar with the concept of the run-loop that’s pretty core to Pygame, but I had never really made use of any to animate objects on the screen or deal with handling any kind of events from mouse movements to key presses, etc. Fortunately I’m already a professional Python developer, so writing code wasn’t the difficult part so much as laying it out. Orienting things into classes to handle separate components such as animating text (which is a painful in Pygame, in my opinion) to keeping track of user-input.

Animating text across the screen wasn’t particularly difficult, with Pygame you first create your primary “surface” (i.e. the window) and then you can render things onto that surface. With text, you end up rendering a surface which contains your text, “hello world” which you then place onto the primary surface. Easy peasy thus far: import pygame surface = pygame.display.set_mode((640, 680), pygame.HWSURFACE | pygame.DOUBLEBUF) font = pygame.font.SysFont('Courier', 42) ### render(text, antialias, rgb color tuple font_surface = font.render('hello world', 0, (0, 0, 0)) ### draw `font_surface` onto `surface` at (x=0, y=0) start_x, start_y = 0, 0 surface.blit(font_surface, (start_x, start_y)) while True: ### Holy runloop batman pygame.display.update()

That was fun, I now have “hello world” rendered onto my screen, now to animate I suppose I’ll just render font_surface a little further right every iteration of the runloop, i.e. while True: ### Holy runloop batman surface.blit(font_surface, (start_x, start_y)) start_x += 0.5 pygame.display.update() This blurs the text however, so I then changed to: while True: ### Holy runloop batman surface.blit(font_surface, (start_x, start_y)) surface.fill((0, 0, 0)) start_x += 0.5 pygame.display.update() This will cause the (primary) surface to be repainted (washed over) every iteration of the runloop ensuring that the text will properly animate, drawing the text in one spot, wiping the surface then drawing it slightly further to the left, resulting in the scrolling animation. All’s fine and good until you determine that you want to have other elements on the screen and you also don’t want to redraw them every time around the carousel. I then discovered how to “fill” just one particular rectangle on the surface, i.e. the rectangle behind the text: text_w, text_h = font.size('hello world') while True: ### Holy runloop batman surface.blit(font_surface, (start_x, start_y)) surface.fill((0, 0, 0), rect=pygame.Rect(start_x, start_y, text_w, text_h)) start_x += 0.5 pygame.display.update()

Once I was able to get text properly scrolling across the screen, the rest of the afternoon of hacking was far easier. My confidence in my ability to grok Pygame in order to do what I wanted. I then set forth organizing my code into some logical classes, for example I created a LetterSpool class which would record the user’s progress through the current word, rendering it at the bottom-center of the screen and firing an event when the user hit the space bar (denoting the word “complete”), additionally I wrapped my text animation code into AnimatedWord so I could easily string words together to scroll across the screen in conjunction similar to a textual screensaver.

Not a whole lot more to write about with regards to my progress today, hooked up some music and basic sound effects which was trivial after looking at some sample code. Next I need to start addressing some more fundamentals for user-interaction: scoring and level-changing.

You can track the progress of the game “Typy” (pronounced: typey) on GitHub

Read more →

Writing for multiple blogs

My New Year’s resolution this year was incredibly generic insofar that I merely wanted to “write more.” No qualifications for what kind of writing that entailed, I simply want to become a better writer (or blogger), with technical subjects in particular I’d like to get better at writing in a fashion that is interesting, parse-able by novices and has sufficient “depth” to interest more technical readers. I’m not sure if I can define what being a “better writer” will entail or how I’ll know when I’m there, so for now I’m just trying to write good content. Considering my last post didn’t even pretend to ride the fence between opinionated-article and full-on rant, I think it’s safe to say that in order to accomplish my goal I need more venues for writing and more topics to write about.

One of those venues, which I’ve linked to before is the Apture Blog; I have written for the company blog already this year and chances are I will have another few posts go up as we tackle some of the technical challenges we’re currently facing (you can view my posts here). Unfortunately there’s only so many articles I can write for the Apture Blog without giving away any confidential information or turning it completely into a technical blog (hint: it’s not).

Looking around at a few of the open source communities that I’m involved in, two groups stick out: Eventlet and Hudson. Eventlet already has a blog and I’m certain my usage of Eventlet is not steady enough to warrant any kind of authoritative posts on the subject. The other, Hudson, is something I’ve used on a daily basis for almost a year and a half. Not only that, I run the @hudsonci twitter account and founded the #Hudson channel on Freenode, I’ve also tried my hand at developing some plugins for Hudson (which is written in Java). Suffice to say, I’m quite the little Hudson cheerleader.

When I floated the idea of an “official” blog for Hudson, which I would help drive, to Kohsuke and some other “core” developers of Hudson, the idea was well received and I set off getting Drupal configured, writing some preliminary content and getting ready for a launch of Continuous Blog. While my writing contributions thus far to Continuous Blog have been sparse, I’ve gotten to play the delightful role of Editor which is an entirely different experience unto itself.

I’m looking forward to seeing how this develops, I might end up writing for a few other blogs depending on interest and time, but for now my shenanigans can be found on:

Read more →

I hope you bump your head

There are few things I truly enjoy in life, things that warm my heart and make me smile from ear to ear, things like hot oatmeal and coffee, cell coverage in San Francisco, back scratches and not dying. If I didn’t commute every single day on my bicycle, I’d likely put “bike riding” on the list too but it’s hard to be ecstatic about something you start and finish every workday with (except for maybe some recreational yelling). For about 25 minutes every morning and 25 minutes every night, I’m a cyclist in San Francisco, nothing terribly unique, I am one of many cyclists in the city during rush hour and I have been noticing some things lately.

First of all, let me address my fellow cyclists. Some of you (you hopefully know who you are) are unadulterated, complete fucking-assholes. I understand that you don’t need a license to ride a bicycle but you still have to obey the rules of the road. Among other things this means you should be courteous to those you’re sharing the road with which includes:

  • Using hand signals
  • Yielding (you can use the dictionary on the iPhone that you’re pulling out at intersections to look up what that word means). Despite the ironic t-shirt you’re wearing underneath your hoodie, you are not “King of the World”.
  • Riding on streets safe for bicycle use. I know you love to ride down Oak St. and Van Ness in rush hour but it does nothing but piss drivers off. There are typically less trafficked streets adjacent to busy streets which are preferred for cyclist use (such as Page and Market St.).
  • Stopping at stop lights. I’m sure Gavin and the SFPD have given you an exemption from basic traffic laws but the drivers coming into the intersection don’t know that. You are making things dangerous for everybody around you on the road; stop it.

Given the hours I work, I’m typically riding home in the dark, where I’ve noticed a group of people who don’t share the same love of “not dying” as I do. I’m going to call them the “Suicide Cyclists.” This group of morons never cease to disappoint, without fail you’ll see one or two of them riding down a busy street (like Market St.) with no lights and no helmet. Some vindictive part of me really would like to see a car accidentally hit one of them. I don’t want them to seriously injure or kill anybody, just a light enough tap to send them to the ground and bump their head just hard enough to knock some god-damn sense into it.

There are parts of my bike ride where I might even crash into one of these Suicide Cyclists, places where I’m riding on a two-way bike path (through a poorly lit park) or where I’m turning at an intersection. If through some unfortunate turn of events we crash into each other, the cyclist wearing a dark sweatshirt with no helmet or lights on their bicycle, and me, with my plethora of lights and hand signals, you can be certain that the next thing that’s going to happen is assault with a U-Lock against some poor schmuck who’s too stupid to ride on the right side of the bike path in the dark.

To be honest, I can deal with the immense number of drivers not paying enough attention to the bike lanes, red lights or speed limits, the majority of the time cars do not cut through intersections, sidewalks, parks and everywhere else. Their trajectories are far more predictable than some jerk riding his fixie with his corduroy bike cap where ever he damn well pleases.

Grumble.

Read more →

Mourning Sun

Some users of Hudson have already started to notice a subtle addition to the latest release, 1.343, a new background watermark image.

The commit message (r26728) from Kohsuke, the incredibly talented founder and maintainer of the Hudson project, adds a bit of sadness to the whole affair:<blockquote>In tribute to Sun Microsystems and all my colleagues who had to go today. I hope the community would forgive me for doing this. </blockquote>

Given the incredible speed at which the tech industry grows and moves, it’s easy to forget that there are a number of talented engineers that have spent their careers at Sun building technologies that have helped change the face of modern computing, regardless of whether or not Sun could figure out how to sell them: SunOS/Solaris, Java, DTrace, SPARC 64-bit chips, Sun Grid Engine, JRuby, the W3C XML specification, ZFS, OpenOffice (acquisition), MySQL (acquisition), and VirtualBox (acquisition).

As a corporation, I personally think Sun was a failure, as a foundation of engineering in Silicon Valley, I think Sun has been quite successful.

To those that are being pushed out as part of the merger with Oracle, I want to sincerely thank you for your contributions to computing and wish you the best of luck. Here’s the “full” version of the image, which I found via @jtnl’s TwitPic stream:

Read more →

Using a browser to piss off IRC users, or, spamming #redditdowntime

One of my most favorite sites on the internet, reddit, took some downtime this evening while doing some infrastructure (both hardware and software) upgrades. On their down-page, the reddit team invited everybody to join the #redditdowntime channel on the Freenode network, ostensibly to help users pass the time waiting for their pics and IAMAs to come back online.

Shortly after reddit started their scheduled outage, I joined the channel to pass the time while I debated what I should do with my evening. Within minutes the channel was flooded with a number of users, varying between spouting reddit memes in caps. link-spamming or engaging in casual chit-chat. I complained to one of the ops and fairly well-known-to-redditors employee: jedberg about the lack of moderation and he nearly instantly gave me +o (ops) in the channel. Not one to take my ops duty lightly, I started kicking spammers, warning habitual caps-lock users and tried to keep things generally civil through the deluge of messages consuming the channel.

Towards the end of the scheduled outage, some automated link-spamming started to appear and once it started it triggered more and more link-spamming. Clearly whatever was behind the bit.ly link was responsible for the self-propagating nature of the spamming. While the other moderators and myself tried to keep up with banning people I used wget to fetch the destination of the clearly malicious bit.ly URL to determine what we were dealing with. What I found is one of the more clever bits of JavaScript I think I’ve seen in recent months.

After bringing the site back up for a few minutes, reddit had to take it back down after noticing some problems with the upgrade, so another flood of users filled into the #redditdowntime channel and the link-spamming got worse. The most interesting aspect of the JavaScript in the code snippet below is how simple it is, I’ve commented it up a bit to help explain what’s actually going on:

DIGG ROOLZ! REDDIT DROOLZ!

</code>

Read more →

Unsubstantiated Rumors about Apture and Facebook

Yesterday I was pointed to this post on ReadWriteWeb, suggesting that Facebook should acquire Apture next. Being an Apture employee, I would like to take some time to fuel the rumormill with these COMPLETELY TRUE (read: false) rumors:

Unsubstantiated Rumor #1:

A shadowy figure in a black Northface jacket has been spotted lingering around 539 Bryant St in San Francisco

Unsubstantiated Rumor #2:

Apture's CTO is seen regularly in Palo Alto

Unsubstantiated Rumor #3:

Apture employees were issued company Adidas sandals last December

Unsubstantiated Rumor #4:

Mark Zuckerberg and Tristan Harris talk regularly at meetings of the Bay Area Strip-Parcheesi Club in Redwood City

Unsubstantiated Rumor #5:

Apture is hiring aggressively in order to bump up their acquisition price
Read more →

Thread-safety assumptions in Django

These days, the majority of my day job revolves around working with Apture’s Django-based code which, depending on the situation, can be a blessing or a curse. In some of my recent work to help improve our ability to scale effectively, I started swapping out Apache for Spawning web servers which can more efficiently handle large numbers of concurrent requests. One of the mechanisms by which Spawning accomplishes this task, is by using eventlet’s tpool (thread pool) module in addition to some other clever tricks. With Apache, we used pre-forked workers to accomplish the work needed to be done and while still using forked child processes with Spawning, threading was also thrown into the mix, that’s when “shit got real” (so to speak).

We started seeing sporadic, difficult to reproduce errors. Not a lot, a trickle of exception emails throughout the day. Digging deeper into some of the exceptions, careful stepping through Apture code, into Django code and back again, I started to realize I had thread-safety problems. Shock! Panic! Despair! Lunch! Disappointment! Shock! I felt all these things and more. I’ve long lamented the number of globals used in Django’s code base but this is the icing on the cake.

Apparently Django’s threading problems are sufficiently documented in a few places. Using a slightly older version of the Django framework certainly doesn’t help but it doesn’t appear that recent releases (1.1.1) can guarantee thread-safety anyways. I think it’s safe to assume the majority of Django framework users are not using threaded web servers in any capacity, else this would have become a far larger issue (and hopefully of been fixed) by now. From NoReverseMatch exceptions, to curious middleware problems to thread-safety issues in the WSGI support layer, Django has potholes lying all along the road to multithreadedness.

Beware.

Read more →