Skip to content

Instantly share code, notes, and snippets.

View carljm's full-sized avatar

Carl Meyer carljm

View GitHub Profile
@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 / 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)
--- 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 @@
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)
@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