# Number System Solution

Yesterday I used a programming challenge to illustrate a use of generators. The solution to the problem given in that post was far from ideal – just a brute force hack, really. Today, let’s look at a respectable solution to the problem. Again, the problem: Imagine you are given a set of weights, each weight…

# When Generators Are Brute Force Enablers

An interesting (if mysterious) programming challenge popped up in my business partner’s browser the other day. You’re given an odd set of weights which represents the series of powers of three. So, the first one is 1lb, the second 3lbs, the third 9lbs, the fourth 27lbs, etc. You also have a scale. If someone puts…

# Duped by the Birthday Paradox

A well-known counterintuitive fact about probability is the birthday problem – the idea that the odds of two people in a group sharing a birthday increases much more rapidly with the size of the group than most people expect. Most people’s intuition seems to be roughly linear: odds increase more or less uniformly with each…

# Clever Grouping in Python

Sometimes when you run across clever code, you just wanna tell someone about it. I spent about 5min. today trying to figure out the grouper function from the Python itertools recipes – because I needed to do something where I split a string, group the resulting list into pairs, and then build a dict from…

# Stop the Madness – DateTime without the Silly Microseconds in SQLAlchemy

If you’ve done much relational database programming in Python, you’ve almost certainly used Michael Bayer’s excellent SQLAlchemy module. I mean, like most people I’ve moved on to NoSQL (CouchDB being my weapon of choice these days). But back in the days when I did a lot of SQL programming, it wouldn’t really be an exaggeration…

# Making pyenv play with PySide on Mac OS X

So, I’ve been working a bit on my password manager (now called Stempel), and it’s working pretty well with CouchDB and a commandline interface, and it’s about time to make a GUI for certain purposes. I’d mentioned before wanting to use PySide for this purpose, and naturally PySide turns out to be one of those…

# Pythonbrew can’t find pkg_resources inside a venv

I ran into some frustrations using pythonbrew to create a virtualenv today on my laptop (a MacBook Pro running Lion). Everything is fine when I just set them up using virtualenv, the way God Intended, but I’m working on something that needs to go on a remote server that has pythonbrew set up already, and…

# PySide Up and Running in OS X Lion

At the moment, I store all my passwords in text files which I manage with Vim. This is, of course, a horrible idea. It’s true that I name the files cryptically, so anyone who stole my laptop would probably take a long time figuring out what they were, but there’s still really no excuse. It’s…

# Making an API where there isn’t one with Requests

The Python Requests module has made my life easier on countless occasions. This is the story of one of those times. One of the projects I work on at work involves interacting with a mildly shady VDN. Without getting into my litany of complaints, what’s relevant here is that they make it somewhat difficult to…

# Getting Regular Feedback from a Remote Server with Growl and Python

Recently, the iCalendar feed of one of the applications I work on caused it to crash – at the worst possible time (of course!). We have to pull iCalendar data from Google every so often so that customers can block out periods of time on their appointment schedules by using their Google Calendar feed. The…