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 eventlet, settings, datetime | |
from crimes.models import Crime | |
from django.db.models import Min,Max | |
pool = eventlet.greenpool.GreenPool(settings.DB_CONNECTIONS) | |
min_max_id = Crime.objects.all().aggregate(Min('id'),Max('id')) | |
min_id = min_max_id['id__min'] | |
max_id = min_max_id['id__max'] |
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
# only show the fields specified in the json properties list of the model | |
if hasattr(item, 'json_properties'): | |
json_properties = getattr(item, 'json_properties') | |
properties = {} | |
for k,v in item.__dict__.iteritems(): | |
if k in json_properties: | |
properties[k] = v | |
# the json properties list is not available, so copy all the properites | |
else: |
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
# Set postgis-1.5 path. | |
POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-1.5 | |
# Creating the template spatial database | |
createdb -E UTF8 -T template0 template_postgis | |
# and add PLPGSQL language support. | |
createlang -d template_postgis plpgsql | |
# Loading the PostGIS SQL routines. | |
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql |
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
# The root directory of this project; also the directory where this file lives | |
import os | |
SETTINGS_DIR = os.path.abspath(os.path.dirname(__file__)) | |
# A list of locations of additional static files | |
STATICFILES_DIRS = [os.path.join(SETTINGS_DIR, 'static')] | |
# List of finder classes that know how to find static files in | |
# various locations. | |
STATICFILES_FINDERS = ( |
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 contextlib import contextmanager | |
import os | |
import shutil | |
@contextmanager | |
def mktempdir(folder): | |
os.mkdir(folder) | |
yield | |
shutil.rmtree(folder) |
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 xrange_decimal(start, stop, step): | |
i = start | |
while i < stop: | |
yield i | |
i += step |
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 PIL import Image | |
def get_white_noise_image(width, height): | |
pil_map = Image.new("RGBA", (width, height), 255) | |
random_grid = map(lambda x: ( | |
int(random.random() * 256), | |
int(random.random() * 256), | |
int(random.random() * 256) | |
), [0] * width * height) | |
pil_map.putdata(random_grid) |
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 fancy_open(filename, mode='r'): | |
if args.file.endswith('.bz2'): | |
from bz2 import BZ2File | |
input_file = BZ2File(filename, mode) | |
elif args.file.endswith('.zip'): | |
from zipfile import ZipFile | |
input_file = ZipFile(filename, mode) | |
elif args.file.endswith('.tar'): | |
from tarfile import TarFile |
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 | |
# Supervisord auto-start | |
# | |
# description: Auto-starts supervisord | |
# processname: supervisord | |
# pidfile: /var/run/supervisord.pid | |
SUPERVISORD=/usr/local/bin/supervisord | |
SUPERVISORCTL=/usr/local/bin/supervisorctl |
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 | |
# run with path to postgis share dir | |
# e.g. ./postgis_template.sh /usr/local/Cellar/postgis/2.0.1/share/postgis | |
POSTGIS_TEMPLATE_PATH=$1; | |
# Creating the template spatial database | |
createdb -E UTF8 -T template0 template_postgis | |
# Loading the PostGIS SQL routines. |
OlderNewer