Posts tagged: TIPS

Notes on my new Django setup

My personal record of using revision control for source code has been pretty spotty. Today I took steps toward fixing that by working out a system for managing my Django projects. I wanted revision control (Subversion), I wanted Django’s “runserver” for development and mod_python for deployment, and I didn’t want it to be a pain.

Some highlights of the process:

  • I used my pastebin site as the test mule. I checked in the current live site’s source code, created “trunk”, “tags”, and “branches” directories per the Subversion manual, and checked out a copy of the trunk into a staging directory.

Python MySQL junk pointer not making sense

(There’s got to be a name for blog posts that you make just so you’ll be able to remember something later – or so somebody who is banging their head against a problem you just solved can find your solution via Google magic. This is one of those posts.)

A while back I started getting bizarre errors when using Python with MySQL. They looked like this:

python in free(): warning: junk pointer, too high to make sense

It didn’t make sense to me either! Tech support for my VPS and copious Google searching didn’t turn up anything I could use.

Handling legacy URLs with Django

One of the great things about Django is its simple and flexible URL handling. If your Django work, like mine, includes converting existing sites, you’ll probably be doing some URL cleanup along the way. Django’s “generic views” system includes a view called “redirect_to” that handles cases like this. A rule might look like this:

urlpatterns = patterns('django.views.generic.simple',
    ('^foo/oldsite/BadOldUrl33247.blech$', 'redirect_to', {'url': '/bar/nice-new-url/'}),
    )

But because the URL pattern building happens in Python, if you have many of these you can do better than filling your urls.py with variants of that line. Here’s the root urlconf for one of my sites:

Think twice before you let those domains lapse

In an effort to shed time-sucking side projects in the past couple years I’ve let a number of sites go dark and domain names lapse. Some of these were ideas that never got off the ground, but one or two were sites with real traffic and Google pagerank (PR 5 in one case, not stellar but not achievable overnight either).

Sadly, some of these domains have now been taken over by those useless squatter pages that manufacture lists of “related links” and “popular searches” and so on to trick people into clicking on ads. This only makes sense – if you were a domain squatter, you’d certainly prioritize grabbing expired domains with high pagerank and many existing inbound links. If you set up your server never to return a 404, some of those linking sites might never even notice the change.

A MAC address regex

Today I worked on a form and script used for registering users on a restricted-access wireless network. Here’s a nice compact regex for checking that MAC addresses have been entered in the correct format. (If you’re using this in a double-quoted PHP string, escape the “$” with a backslash.)

/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/i

Bjoern commented on Mon Jun 4 09:09:14 2007:

Hi,

great regex! exactly what I was looking for.

It only does not match lower case also the windows output of ipconfig/all (using a dash as delimiter) is not covered