Skip to content

Instantly share code, notes, and snippets.

View carljm's full-sized avatar

Carl Meyer carljm

View GitHub Profile
@carljm
carljm / deploy.wsgi
Created January 27, 2011 19:24
A mod_wsgi deployment file for Django that handles a virtualenv, putting its paths in front
import os, sys, site
base = os.path.dirname(os.path.dirname(__file__))
project = os.path.join(base, 'project')
virtenv = os.path.join(base, 'env')
### virtual environment, with precedence over global env ###
# from http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
def unwrap_template_syntax_error(function, *unwrap_exceptions):
"""
A decorator to catch TemplateSyntaxError and unwrap it, reraising the
wrapped exception.
If unwrap_exceptions are passed, the unwrapping will only occur if the
wrapped exception is one of those exception types.
"""
@wraps(function)
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -867,5 +867,5 @@
files['activate'] = ACTIVATE_SH
else:
- files = {'activate': ACTIVATE_SH}
+ files = {'activate': ACTIVATE_SH, 'activate.csh': ACTIVATE_CSH}
files['activate_this.py'] = ACTIVATE_THIS
for name, content in files.items():
@@ -1426,4 +1426,29 @@
@carljm
carljm / decorators.py
Created March 27, 2011 18:28
An example of a decorator for a view that returns a TemplateResponse, modifying the template context before it is rendered.
def paginate(ctx_name):
"""
View decorator that handles pagination of a ListObject. Expects to find it
in the TemplateResponse context under the name ``ctx_name``.
This needs to not force delivery of the ListObject.
"""
def decorator(view_func):
@wraps(view_func)
@carljm
carljm / install-gems.sh
Created May 18, 2011 19:29
ghetto gem-installer that reads something similar to a pip requirements file
#!/bin/bash
vfile=$1
for line in `cat ${vfile}`; do
gem=${line%%=*}
version=${line##*=}
if gem list | grep ${gem} | grep "(${version})"; then
echo "${gem} (${version}) is already installed"
else
gem install ${gem} -v ${version} --no-rdoc --no-ri
fi
@carljm
carljm / postactivate
Created July 12, 2011 18:21
Yo dawg, I heard you like Ruby...
#!/bin/bash
# This hook is run after every virtualenv is activated.
export OLD_GEM_HOME=$GEM_HOME
export GEM_HOME=$VIRTUAL_ENV/gems/
export GEM_PATH=
export PATH=$VIRTUAL_ENV/gems/bin:$PATH
@carljm
carljm / tutorial.mkdn
Created August 23, 2011 19:31 — forked from mirisuzanne/tutorial.mkdn
A new Susy tutorial

Susy Tutorial

For this tutorial I'm assuming you are already comfortable with CSS, Sass (I'll use the SCSS syntax) and Compass. Please get set up with each one of those before attempting to use Susy. Sass and Compass both have their own setup instructions and tutorials that you can use.

There is also reference documentation in the works.

What Susy Does

CSS Systems

@carljm
carljm / runner.py
Created December 9, 2011 04:07
Unittest2 test discovery and real dotted-path named test selection for Django
"""
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).
[core]
excludesfile = ~/.gitignore
@carljm
carljm / conftest.py
Created June 15, 2012 15:11
Using py.test with Django
import os
def pytest_sessionstart(session):
"""
Set up the test environment.
Sets DJANGO_SETTINGS_MODULE and sets up a test database.