Brad's Blog

web dev, django, running, food, or whatever

Published: 2010-06-09

Vim Syntax highlighting for Apache Config Files

apache django vim

I use Django with Apache and mod_wsgi. Each project that I work on has different apache config files, so I like to keep those in the same mercurial repo that contains my django project's code.For some time now, it's been bugging me that vim doesn't do syntax highlighting for those apache configs (nor the wsgi files). I finally decided to do something about it, and I'm glad I did, because it's a fairly simple ...


Published: 2010-05-28

Convert Tables to Unordered Lists

BeautifulSoup Programming Python web

If you've ever had the pleasure of working with old HTML content, you've surely seen some <table>'s where they don't belong. Lately, that's the sort of thing I've been dealing with on a regular basis, and for some reason, I often see a list of information in a table.Wouldn't it be nice if there were an easy way to turn these tables into unordered lists? Thanks to BeautifulSoup, this is really not ...


Published: 2010-04-22

Pretty options for Django's auth.User

Python django web

Several of my Django Apps have Foreign Key relationships to django.contrib.auth.model.User. In Django's admin app, these show up a select elements displaying the username attribute. For some people, that may be OK, but for most of the people with which I work, it's not. We want to see prettier options, i.e. each User's full name as the options in that select element.So, here's how it works. We override the ModelChoiceField ...


Published: 2010-03-25

Dealing with Unicode and ASCII using Python

ascii python unicode

Dealing with Character Encodings is (sometimes) hard. It's especially confusing for those who've never done it before. Converting text from unicode to ascii can be tricky. A lot of times, I'll import some data from a text file, and I just want to convert everything to ASCII and ignore anything that's not ascii (like MS Word's smart quotes). Luckily, this is fairly easy:mystring = mystring.decode('ascii', 'ignore')There's tons of great Python resources ...


Published: 2010-03-23

On select_related()

Python awesome django web

If you use Django, and your models have relationships that span across multiple tables, you need to read this: http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4select_related() is awesome.That is all.


Published: 2010-02-25

Building PIL on OS X: Snow Leopard

Mac OS PIL Python X homebrew virtualenv

There are several places online that discuss problems installing PIL on Mac OS X Snow LeopardThis is how I got it to work.Install lib jpeg using homebrew (which is super-aweseome!) brew intall jpeg.This installs the library into /usr/local/Cellar/jpeg/7Install libfreetype the old-fashioned way (./configure, make, sudo make install). I used freetype-2.1.10.pre-20050511.Download, unpack PIL (I used Imaging-1.1.6). I had to make the following changes to setup.pyFREETYPE_ROOT = "/usr/local"JPEG_ROOT ...


Published: 2010-02-24

Specialization

Fun humanity

Thanks to @mxcl for tweeting a link to this: http://gist.github.com/313640Things I've done (or similar)change a diaperplan an invasion (warcraft counts, right?)butcher a hog squirreldesign a building (with legos!)write a sonnet songbalance accountsbuild a wall fencecomfort the dyingtake ordersgive orderscooperateact alonesolve equationsanalyze a new problempitch manureprogram a computercook a tasty meal (yum!)fight efficiently (yay for taekwondo!)...not quite there yet:conn a shipset a bonedie gallantly (here's hoping!)Hooray for Humanity!


Published: 2010-01-23

Adventures in Bread-Baking: Part 1

Food bread

Last weekend I attempted to make Mark Bittman's Speedy No-Knead Bread... sort of. Being the adventurous experimenter that I am, I altered the ingredients:2 cups whole-grain flour + 1 cup all purpose flour2 cups of really warm water (instead of the 1.5 cups)I followed the rest of the recipe perfectly. However, the results were really unsatisfactory. The center was super dense and gooey, and the bread had a really really hard crust (ok, I also cooked it ...


Published: 2010-01-15

Add JSON syntax highlighting in Vim on OS X

This is how I got Vim to do syntax highlighting for JSON files (Max OS X - Snow Leopard)Download the syntax file from http://www.vim.org/scripts/script.php?script_id=1945. (I got json.vim version 0.4)If it doesn't already exist, create a .vim/ftplugin in your home directory.Put json.vim into .vim/ftpluginAdd the following lines in your .vimrc file (mine is located at ~/.vimrc)au BufRead,BufNewFile *.json set filetype=jsonau! Syntax json ...


Published: 2010-01-14

Resize the iTunes Window

Mac Programming applescript iTunes

My Macbook Pro is my main machine. At the office, I connect it to a 20" Cinema display. At home, I connect it to a 24" Samsung Monitory (Model 2494SW Glossy Black, which I really like, btw.)There's a down-side to all this, though. I mostly just notice it with iTunes. When I'm working on the laptop without an external monitor, my iTunes window is larger than my screen :( Unfortunately, clicking the Maximize button doesn't do what ...