Skip to content

Instantly share code, notes, and snippets.

@sebastibe
sebastibe / runner.py
Created March 22, 2012 02:50 — forked from carljm/runner.py
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).
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
@sebastibe
sebastibe / runinenv.sh
Created October 9, 2012 02:24 — forked from parente/runinenv.sh
run a command in virtualenv, useful for supervisord
#!/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 "$@"
// 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)
pb-kill-line () {
zle kill-line
echo -n $CUTBUFFER | pbcopy
}
pb-kill-whole-line () {
zle kill-whole-line
echo -n $CUTBUFFER | pbcopy
}
User = Backbone.Model.extend({
url: function() {
var origUrl = Backbone.Model.prototype.url.call(this);
return origUrl += origUrl.endsWith('/') ? '' : '/';
}
});
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
class _Missing(object):
def __repr__(self):
return 'no value'
def __reduce__(self):
return '_missing'
_missing = _Missing()
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});