Django hostname middleware

Recently I wanted to enforce the hostname in a couple Django-based projects. By default, Django really only allows you to enforce that a “www” is present in the URL. To me this seems rather one-sided as several sites may need:

  • To enforce that the “www” is not present
  • Or that an alternate domain name resolves to the primary domain

So I created the following middleware to enforce hostnames and submitted it to be added to the core (which was rejected). But in case you need to enforce the domain that visitors to your projects use, you may find this to be handy!

Textmate command for copying last selector in CSS

I recently was crafting some CSS, but I kept running into places where I would have this situation:

#someDiv li a:hover { color: #fff; }

But I would want to also add an a:active and an a:focus. Unfortunately that means I would have to copy #someDiv li and paste it. This is why Textmate commands were created.

So I created a command for copying the last selector on the line and guessing what you want to change. Now I can press ctrl-c and presto, the last selector is inserted as a snippet.

New PHP functions command for Textmate

After using some commands in the Python and Ruby bundles in TextMate, I felt it was time to work on a new command for PHP functions. Assign the following to shift + enter and then you can enter a single word on a line and pressed key equivalent to generate a function. It tries to do something things “smartly”: if the function starts with “get” or “is” it will behave a bit differently or if you enter a name and parameters, it will document those for you (or stub out the documentation, anyway).

New function command

Styleswitcher becomes social

PHP Styleswitcher on GitHub

The PHP Styleswitcher has always been open source, but in a move which will hopefully help me and users of the scripts, the code now has a home on GitHub:

PHP Styleswitcher at GitHub

So now developers can take advantage of the being able to check out the latest source there. Recently it went under some changes to make it more PHP 5 friendly (getting rid of old PHP 4 habits) and some code restructuring. It’s not documented to my standards yet, but I have begun working on the updates to the switcher web site.