Slaptijack Title

Archive for the ‘Programming’ Category

Python urllib2 with gzip or deflate encoding

The other night I was working on some Python code that interacts with the zKillboard API. The API call returns kill information via JSON for EVE Online. While making the request, I was getting an error that I was using "non-acceptable encoding." It turns out that the zKillboard guys require you to accept gzip or […]

Categories: Programming

MySQL Multiple-Column Indexes: Order Matters

This will just be a short reminder. If you're planning to create multiple-column indexes in MySQL, remember that the order of the columns matters. As the MySQL documentation points out, any "leftmost prefix of the index can be used." This means that the index can be used for any number of columns in a where clause as long as those columns are at the beginning of the index column list and in the same order.

Categories: Programming

If Your Post Doesn't Start With An Image, Display an Ad Instead

I usually start my posts off with an image that is relevant to the post. I think it adds a bit of drama to what I'm writing about, and it also gives me a nice place to anchor a link to a WordPress tag about the subject. I had this idea the other day that if I didn't include an image at the beginning of a post, I should put a Google AdSense ad there instead.

Categories: Programming

Python: Convert String Date to Date Object

Occasionally, you may run across a date in a format that can't be easily loaded into a Python date object. For example, I recently had a situation where a file I was parsing was full of dates in this format: 7/7/2008.

Categories: Programming

Combining Multiple Models Into One Context Variable

I'm not sure if the title of this post accurately describes the problem. I have a situation where I have very similar models that I want to display in one table. As you know, querysets are limited to a single model, so it isn't possible to have a single context variable use a single queryset. In my case, I could have created a new context variable for each model, but that results in a situation where adding a new model means changing both the view and the template.

Categories: Programming