Skip to content

Instantly share code, notes, and snippets.

What's happening?

Allan Lei allanlei

What's happening?
Block or report user

Report or block allanlei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
allanlei / jquery.django.js
Created Jul 18, 2011
Django Serialization for Jquery
View jquery.django.js
$.getDjangoJSON = function(url, data, success){
return $.ajax({
url: url,
dataType: "django-json",
data: data,
success: success
allanlei / README
Created Jul 18, 2011
Django Custom Queryset Mixin and manager
Based of custom chainable querysets that others have posted + the usage of mixins like the ones found in Django's class based views
Example Queryset:
from django.db import models
class ExchangeQuerySet(models.query.QuerySet):
def my_test(self):
return self.filter()
allanlei /
Created Dec 30, 2011
pg_dump and upload to S3 using s3cmd
FILENAME="DATABASE.backup" && pg_dump -Fc -O -x -f "$FILENAME" DATABASE && s3cmd --acl-private put "$FILENAME" s3://S3_BUCKET && rm "$FILENAME"
allanlei /
Created Dec 30, 2011
pg_dump and upload to S3 using s3cmd
import argparse
import subprocess
import shlex
import datetime
import os
parser = argparse.ArgumentParser(description='pg_dump and upload to S3')
parser.add_argument('database', nargs=1)
parser.add_argument('-U', '--user')
allanlei /
Created Jan 13, 2012
Script to use DNSimple's API
#!/usr/bin/env python
import argparse
import simplejson as json
import urllib2, urllib
import httplib
import base64
parser = argparse.ArgumentParser(description='Updates DNSimple with EC2\'s hostname')
parser.add_argument('cname', type=str, nargs=1, help='Name of the CNAME')
parser.add_argument('--domain', default='', help='Domain to update')
allanlei / crontab
Created Jan 14, 2012
Cron job for cleaning PostgreSQL
View crontab
@daily vacuumdb -U postgres --all --analyze -q
@monthly vacuumdb -U postgres --all --analyze --full -q
allanlei / .env
Created Jan 16, 2012
Sample local Heroku/Django development environment using foreman
View .env
allanlei /
Created Jan 17, 2012
Simple staticfile server for development using fapws
#!/usr/bin/env python
pip install fapws3
import fapws._evwsgi as evwsgi
from fapws import base
from fapws.contrib import views
from fapws.contrib import zip, log
allanlei / findFileWithExtension.js
Created Jan 18, 2012
Coffeescript that finds files with extensions using the async library
View findFileWithExtension.js
var findFilesWithExtension,
_this = this;
findFilesWithExtension = function(dir, extensions, callback) {
var directories, files;
files = [];
directories = [dir];
return async.whilst(function() {
return directories.length > 0;
}, function(whilstCallback) {
allanlei /
Created Feb 6, 2012
Sample Gunicorn config for Django on Heroku. Usage: "gunicorn -b$PORT --settings $DJANGO_SETTINGS_MODULE -c"
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
loglevel = 'error'
secure_scheme_headers = {
You can’t perform that action at this time.