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). |
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
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
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
$('.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
#!/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
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
# 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
import sys | |
from os.path import abspath, join, dirname | |
DOC_ROOT = abspath(dirname(dirname(__file__))) | |
BASE_PATH = dirname(DOC_ROOT) | |
PROJECT_PATH = join(BASE_PATH, 'api') | |
sys.path.append(BASE_PATH) | |
sys.path.append(PROJECT_PATH) |
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
// Assuming we are working with the ASCII character set. 256 unique values. | |
// | |
// First, check that the length of the string is under the number of unique values. | |
// If it is greater, the string does not have all unique characters | |
// | |
// Second, create an array of boolean values of size of unique characters. | |
// Traverse the string and flag the array value from false to true when a character is hit. | |
// When the character is hit a second time, return false. | |
bool hasUniqueChars(char * string) |
OlderNewer