Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
# Hacky script for downloading videos from PyVideo and converting them to m4v | |
# format so they can be synced onto your apple device. Useful if you | |
# want to see everything that happened at PyCon while commuting. | |
# | |
# Requirements: | |
# * pip install requests BeautifulSoup | |
# * youtube-dl (from https://github.com/rg3/youtube-dl/) - add this to the | |
# directory where this script runs and ensure its execute bit is set. | |
# This was the only YouTube downloader I found that worked. It doesn't | |
# really have a good Python API so I call it through os.system. |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
#target photoshop | |
var sizes = { | |
'xlarge': [1490, 730], | |
'large': [1160, 568], | |
'medium': [890, 436], | |
'small': [760, 372] | |
}; |
""" | |
An alternative Django ``TEST_RUNNER`` which uses unittest2 test discovery from | |
a base path specified in settings, rather than requiring all tests to be in | |
``tests`` module of an app. | |
If you just run ``./manage.py test``, it'll discover and run all tests | |
underneath the ``TEST_DISCOVERY_ROOT`` setting (a path). If you run | |
``./manage.py test full.dotted.path.to.test_module``, it'll run the tests in | |
that module (you can also pass multiple modules). |
""" | |
Generate a http://yuml.me definition of Django's class-based views to get a | |
nice class diagram of those views. | |
""" | |
# This runs as a script, but in my Django project root, so import the settings | |
import settings | |
import inspect | |
import django.views.generic.list as list_views |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
1. Two space soft indents (fake tabs) OR tabs... BUT NEVER BOTH - DO NOT MIX | |
2. Whitespace, Parens, Braces, Linebreaks | |
if/else/for/while/try always have spaces, braces and multiple lines. | |
-------------------------------------------------------------------- | |
#! /bin/sh | |
echo "Purging pyc files and empty directories..." | |
# Start from the repository root. | |
cd ./$(git rev-parse --show-cdup) | |
# Delete .pyc files and empty directories. | |
find . -name "*.pyc" -delete 2>&1 > /dev/null & | |
find . -type d -empty -delete 2>&1 > /dev/null & |
""" | |
jQuery templates use constructs like: | |
{{if condition}} print something{{/if}} | |
This, of course, completely screws up Django templates, | |
because Django thinks {{ and }} mean something. | |
Wrap {% verbatim %} and {% endverbatim %} around those | |
blocks of jQuery templates and this will try its best |