Host a TextMate Bundle on GitHub
Create a repository on GitHub
Go into the Bundle Editor and drag your bundle to your desktop and cd into it in the terminal. This is the key to the whole thing. If you just go into the bundle where it lives in TextMate, you might not get everything it needs. Dragging the file to the desktop makes it a nice, happy package ready to help other people.
Follow GitHub’s instructions to set up and push to the remote repository. Don’t forget to git add . to get everything in there.
Delete your original bundle and then clone from GitHub like so:
cd ~/"Library/Application Support/TextMate/Bundles/"
git clone git://github.com/trey/trey-tmbundle.git "Trey.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
When you make changes to your Git-ified bundle in the Bundle Editor, you’ll need to Reload Bundles for the changes to show up in your repository. Then you’ll need to git add . and commit / push as you would a normal repository.
Source
Flagging a Post as Outdated Using Wordpress Custom Fields
If you write a blog whose primary purpose is to help people find and remember information (mostly myself in this case), then it’s probably a good idea to flag certain posts as out-of-date so as not to mislead people who are on a quest for knowledge. That is, of course, if you know it’s outdated. Maybe someone will tell you.
In any case, here’s how you can do it using Custom Fields in WordPress.
Find a post that’s out of date and edit it. Down towards the bottom of the page, there’s a section labeled Custom Fields, click it to open it, and enter something like this:

Use whatever name you want for the key and value, but be sure to change the related fields in the other places I’m about to mention.
I want the notice to show up on the post’s permalink page, so in single.php, I put this right after the start of ‘the loop’:
$status = get_post_meta($post->ID, 'status', true);
As you can probably guess, that just grabs the content for the ’status’ key for the current post and stores it in the variable $status. Easy. If the post doesn’t have the value, the get_post_meta tag is nice enough to fail quietly (as far as I can tell).
Now that you have this very valuable information, you can change CSS, add a warning message, or whatever your little heart desires.
For example:
if ($status == 'outdated') include (TEMPLATEPATH . '/outdated.php');
Sources
- I got the idea from Bryan Veloso’s Avalonstar
- WordPress Codex / get_post_meta
- WordPress Codex / Using Custom Fields
Using Something Other Than the Site Root for a Wordpress Posts Page
This is so you can use something like /blog/ for a list of your blog entries, and the home page for a static page (or something fancier).
Under Settings > Reading > Posts page, pick the page template you want to use.

If you’re using a static page template for the home page, be sure not to name it home.php. Name it something like homepage.php and choose that template for the home page (you can still call it “Home” inside the template).
The “Posts page” will use index.php whether you like it or not. I couldn’t find a way to override that inside of Post management in WordPress.
Installing WordPress The Right Way
svn co http://svn.automattic.com/wordpress/tags/[current_tag_number] [name_of_site]
cd [name_of_site]
touch .htaccess
chmod 666 .htaccess
cp wp-config-sample.php wp-config.php
cd wp-content/themes/
cp -R default [name_of_theme]
cd [name_of_theme]
rm -rf `find . -type d -name .svn`
Now import the content of wp-content/themes/[name_of_theme] into your choice of source code management systems and get to it.
Updating
cd [name_of_site]
svn sw http://svn.automattic.com/wordpress/tags/[new_tag_number]
Sources
Starting a Magento Theme
Duplicate these folders:
app/design/frontend/default/default
skin/frontend/default/default
(Don’t get me started about how awkward the folder structure is.)
Rename the duplicated folders to whatever you want (make them both the same).
FYI, the theme files under the app/ folder are for generated templates (things the system has to build when the site is viewed) and the theme files under the skin/ folder are for publicly viewable files (images, CSS, JavaScript).
Now go to your the admin area of your site and then System > Configuration. Then click Design in the sidebar and under Themes type the name of your theme folders (the ones you duplicated). Just once. One name.
Now the fun really begins. Time to dig into a bluemillion .phtml and .xml files. I’m still not too far along here, but I have determined that to change the media that you load in most pages, you need to edit:
app/design/frontend/default/your_theme_name/layout/page.xml
There you’ll se a bunch of crap like this:
<action method="addCss"><stylesheet>css/reset.css</stylesheet></action>
Have fun.
Using Someone Else’s SVN Repository with Git
If you have a repository URL that looks like this:
http://code.yourmom.com/project/trunk/
Issue this command (note that you leave off trunk/):
git svn clone -s http://code.yourmom.com/project/ project
After it’s done, see how big it is:
du -hs project
And you’ll see something like this:
20M project/
If it’s particularly big, go into the folder and garbage collect:
cd project
git gc
From within the project folder, set your local repository to the trunk (it’s set to whatever branch had the last commit otherwise):
git reset --hard trunk
Create your own branch and get to work:
git co -b treys_changes
When you want to pull in the changes from the original author to stay up to date:
git svn rebase
If you’ve cloned this repo (after posting it to GitHub or elsewhere) and want to use it on another computer, you’ll have to use do more step in order to track the original SVN repo again:
git update-ref refs/remotes/trunk origin/master
git svn init -T trunk http://code.yourmom.com/project/
Sources
- Brian Rosner’s Using git with Django Screencast
- Pieter on #github
- WebKit wiki (via Pieter)
Use Django’s Permalink Decorator with Generic Views
The permalink decorator is the way to keep your URLs DRY. The only place you need to define where something lives is in your urls.py. In your templates, just point to {{ object.get_absolute.url }}. The problem with how they tell you to do it in the book, the documentation, and elsewhere is that it doesn’t work right if you’re using the same view function more than once in all your urls.py files (which is bound to happen if you’re using a bunch of generic views). That’s because Django has no way of telling which one you mean.
Named URL patterns to the rescue.
If you have a URLpattern that looks like this:
(r'^(?P<slug>[-\w]+)/$’, list_detail.object_detail, log_detail),
Change it to this:
url(r'^(?P<slug>[-\w]+)/$’, list_detail.object_detail, log_detail, name=’log-detail’),
Note the addition of “url” to the start of the line and the “name=” bit at the end.
Now, in your model file(s), do the following:
Add this line to the top of the file:
from django.db.models import permalink
At the bottom of the model class do something similar to this:
@permalink
def get_absolute_url(self):
return ('log-detail', (), { 'slug': self.slug })
Any other question you have about this stuff is probably in the other sources.
Sources:
- Magus- on the #django IRC channel
- Django Book (print edition pages 324-325)
- Django documentation (permalink decorator)
- Django documentation (named URL patterns)
- cam macrae
Python Datatypes
dictionary = {'a':'apple', 'b':'banana', 'c':'cat'}
# Associative array / hash / array with non-numeric indices.
list = ['a', 'b', 'c']
# Normal array with 0-based indices.
tuple = (’a', ‘b’, ‘c’)
# Read-only array.
Django Template System Basics
The long way
- Load a template
- Fill a
Context - Return a
HttpResponseobject
Like so:
from django.template import Template, Context
from django.http import HttpResponse
...
t = get_template('current_datetime.html')
html = t.render(Context({'current_date': now}))
return HttpResponse(html)
The short way: render_to_response
Like so:
from django.shortcuts import render_to_response
...
return render_to_response('current_datetime.html', {'current_date': now})
Source:
- The Django Book (pages 51, 52 of the print edition)
Things you probably want to install to get the most out of Django
Open and run:
sudo python setup.py install
Open and run:
sudo python setup.py install