This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531. | |
class Borg(object): | |
__shared_state = {} | |
def __init__(self): | |
self.__dict__ = self.__shared_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
# http://stackoverflow.com/questions/3915024/dynamically-creating-classes-python | |
OnTheFlyForm = type("OnTheFlyForm", (forms.Form,), fields) | |
# ModelForm | |
def get_on_the_fly_form(model): | |
class OnTheFlyModelForm(forms.ModelForm): | |
class Meta: | |
model = model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VENV=$1 | |
if [ -z $VENV ]; then | |
echo "usage: runinenv [virtualenv_path] CMDS" | |
exit 1 | |
fi | |
. ${VENV}/bin/activate | |
shift 1 | |
echo "Executing $@ in ${VENV}" | |
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.dropdown form').on('click', function (e) { | |
e.stopPropagation() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
app = Flask(__name__) | |
if app.config['DEBUG']: | |
from werkzeug.wsgi import SharedDataMiddleware | |
import os.path | |
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, { | |
'/static': os.path.join(os.path.dirname(__file__), 'static') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-get install zlib1g-dev | |
apt-get install g++ | |
export VENV=$VIRTUAL_ENV | |
mkdir $VENV/packages && cd $VENV/packages | |
curl -O http://oligarchy.co.uk/xapian/1.2.12/xapian-core-1.2.12.tar.gz | |
curl -O http://oligarchy.co.uk/xapian/1.2.12/xapian-bindings-1.2.12.tar.gz | |
tar xzvf xapian-core-1.2.12.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iter_islast(iterable): | |
""" iter_islast(iterable) -> generates (item, islast) pairs | |
Generates pairs where the first element is an item from the iterable | |
source and the second element is a boolean flag indicating if it is the | |
last item in the sequence. | |
""" | |
it = iter(iterable) | |
prev = it.next() | |
for item in it: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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). |
NewerOlder