Skip to content

Instantly share code, notes, and snippets.

Avatar

Carl Meyer carljm

View GitHub Profile
@carljm
carljm / deploy.wsgi
Created Jan 27, 2011
A mod_wsgi deployment file for Django that handles a virtualenv, putting its paths in front
View deploy.wsgi
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
View Exception wrapping is dumb
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)
View virtualenv activate.csh
--- 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 Mar 27, 2011
An example of a decorator for a view that returns a TemplateResponse, modifying the template context before it is rendered.
View decorators.py
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
ghetto gem-installer that reads something similar to a pip requirements file
View install-gems.sh
#!/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 Jul 12, 2011
Yo dawg, I heard you like Ruby...
View postactivate
#!/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 Aug 23, 2011 — forked from mirisuzanne/tutorial.mkdn
A new Susy tutorial
View tutorial.mkdn

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 Dec 9, 2011
Unittest2 test discovery and real dotted-path named test selection for Django
View runner.py
"""
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).
View gist:2561976
[core]
excludesfile = ~/.gitignore
@carljm
carljm / conftest.py
Created Jun 15, 2012
Using py.test with Django
View conftest.py
import os
def pytest_sessionstart(session):
"""
Set up the test environment.
Sets DJANGO_SETTINGS_MODULE and sets up a test database.
You can’t perform that action at this time.