Slaptijack Title

Archive for the ‘Programming’ Category

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

Django + jQueryUI Tabs: Open a Specific Tab on Page Load

I recently created a page that had different tabs using the jQueryUI Tabs widget. For whatever reason, I would occasionally want to show a specific tab on page load rather than the default initial tab. One way to do this is to set a variable in your view context and then use jQuery to open the right tab.

Categories: Programming