Entries for April 2006

Project Club Barbecue

Case Project Club is having a barbecue today in front of Olin at 12:30 PM.

Everyone is invited.

Even if you hate projects.

Post-mortem: Success! Everyone ate everything! Adventurous attendees even ate hot dogs and hamburgers—get this—on the opposite type of bun! Or even no bun at all! I did my best at speedy wiener-cooking the whole time with Slow Chris on burgers. Jon says the keg was emptied within an hour and made $45 back in donations. Afterwards there was some concrete basking followed by playing with the friendliest bunny/ferret duo you'll ever meet. I love days like today.

Summer 2006 Plans

I've been really unorganized for the past couple months. I'm amazed that I didn't miss any major deadlines or just completely forget I was enrolled in a particular class or something (note: that has happened to me before). I started using Google Calendar this week, not in an attempt to solve any problems, but just because I was bored. Now I'm part of this shared calendar network thing with my buddies so I guess that's neat.

Despite being unorganized, I can just barely make out my summer plans through the haze. They look something like this:

  • Definitely living with Jon Ward et al. in a house on South Overlook
  • Maybe working at American Greetings with Clepy buddies, maybe even on Python stuff (sending resume any day now...)
  • Possibly doing Google Summer of Code again assuming the Python or Django people find Merquery interesting enough
  • Probably helping out with a software startup company run by some Case graduates
  • Probably not taking any classes (is registration open still/yet?)

This Week in Brian

I haven't done anything Python-related in a week (except read newsgroups), but here's what I have done:

Thursday 4/20: Walked a quarter-mile on stilts in the dark.

Friday 4/21: Saw some students with water guns on the quad, used the huge stash of armaments I just happen to keep in Thunder Labs to stage an ambush with some upperclassmen. Sat in Starbucks soaked and dirty. Saw Silent Hill with Steve, Chris, Franz; funniest movie of the year?

Saturday 4/22: Ran to Cutler to eat some cookies baked by a random girl on the hub, sat in her lobby watching Jackie Chan and drinking some milk I brought for the occasion. Extended her generosity by delivering a snack to a random Village resident.

Sunday 4/23: Lost $9 in poker, licked some dirty pennies for money to stay in the game. (Note: will not make habit of this)

Monday 4/24: Attended a lecture at the Cleveland Botanical Garden, where I also ate some bugs, pet some cockroaches, was terrorized by butterflies. Was a dinner guest at the McMyler/ODE ceremony.

Tuesday 4/25: Failed a quiz, broke my glasses, epoxied them back together.


Potential employers, I'm sorry you had to read this.

Brian's TurboGears Tutorial

This weekend I decided to write my own TurboGears tutorial instead of working on Merquery. If you're interested, check out Brian's TurboGears Tutorial. The application demonstrated in the tutorial can be played with on my server and downloaded*.

Why my own tutorial?

First off, last week I gave a talk on Web Programming with Python, and I never made the demonstration code available to the attendees. Hopefully this will make up for that. The application is the same as the one I made from scratch during the talk, except not crappy.

Secondly, I've made a dozen or more TurboGears apps now and I know how the routine goes. I've also walked a couple beginners through the basics in person. I generally do things in a specific order and this tutorial reflects that.

This tutorial's goal is to give beginners a good understanding of how every basic component of TurboGears works. That means SQLObject, CherryPy, Kid, and MochiKit.

For one thing, it slightly annoys me that the Identity login stuff is plastered all over the default code (okay, just in two places) in 0.9. If it were two lines of code to add that stuff, I'd be okay with it. But as it is, it just looks confusing to newbies. When absolute beginners encounter that stuff in controllers.py and master.kid, I just tell them "Aw, wipe that crap offa there!"

And as soon as you start throwing around any remotely abstract-sounding terms like SecureResource, WidgetValidator, IdentityManagement, DataController... what pops into my head is this thing you may have heard of, starts with a Z.

So yeah. This tutorial starts the reader off with a clean slate, trying to explain all the little things TurboGears does for them along the way. Here's that link again.

* Note: setup.py sdist needs to grab everything in templates/ and static/ by default for TurboGears projects. I just made the archive myself because it was easier than figuring out how to do it with setup.py.

reducipes: Use reduce in Python For Real

If you're like me, you enjoy browsing through the list of Python's built-ins to find better ways to do high-level things more concisely.

If you're even more like me, you stop to scratch your chin every time you come across reduce, a nice way to do some functional programming in Python. If you're unfamiliar with reduce, it goes a little something like this:

Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5).

"Hmmm," you think, "I bet I could use this for something. But what?!" Well, today I submitted this recipe to the ActiveState Python Cookbook. It provides a few ideas for real-life situations where using reduce is both helpful and concise.

Here's an example:

import operator
def factorial(n):
    """Calculate n factorial"""
    return reduce(operator.mul, range(2, n+1), 1)

Usage:

>>> factorial(10)
3628800

Another one:

def intersection(*sets):
    """Get the intersection of all input sets"""
    return reduce(set.intersection, sets)

Usage:

>>> a = set([1, 2, 3, 4, 5])
>>> b = set([5, 6, 3, 7])
>>> c = set([8, 7, 5])
>>> intersection(a, b, c)
set([5])

If you have any of your own reduce recipes, post them here or to the Cookbook recipe. Happy reducing!