Skip to content

Instantly share code, notes, and snippets.

View allanlei's full-sized avatar
:shipit:
What's that I'm playing?

Allan Lei allanlei

:shipit:
What's that I'm playing?
View GitHub Profile
@allanlei
allanlei / jquery.django.js
Created July 18, 2011 21:49
Django Serialization for Jquery
(function($){
$.getDjangoJSON = function(url, data, success){
return $.ajax({
url: url,
dataType: "django-json",
data: data,
success: success
});
};
@allanlei
allanlei / README
Created July 18, 2011 23:57
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
allanlei / db_backup_to_s3.sh
Created December 30, 2011 02:21
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
allanlei / s3_db_backup.py
Created December 30, 2011 02:23
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
allanlei / dnsimple.py
Created January 13, 2012 00:04
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='rhinoaccounting.com', help='Domain to update')
@allanlei
allanlei / crontab
Created January 14, 2012 01:37
Cron job for cleaning PostgreSQL
@daily vacuumdb -U postgres --all --analyze -q
@monthly vacuumdb -U postgres --all --analyze --full -q
@allanlei
allanlei / .env
Created January 16, 2012 21:14
Sample local Heroku/Django development environment using foreman
DATABASE_URL=postgres://USERNAME:PASSWORD@127.0.0.1/DATABASE
MEMCACHE_SERVERS=127.0.0.1:11211
DJANGO_SETTINGS_MODULE=settings.development.local
@allanlei
allanlei / staticfile-server.py
Created January 17, 2012 18:08
Simple staticfile server for development using fapws
#!/usr/bin/env python
'''
pip install fapws3
python staticfile-server.py
'''
import fapws._evwsgi as evwsgi
from fapws import base
from fapws.contrib import views
from fapws.contrib import zip, log
@allanlei
allanlei / findFileWithExtension.js
Created January 18, 2012 21:34
Coffeescript that finds files with extensions using the async library
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
allanlei / gunicorn.py
Created February 6, 2012 20:07
Sample Gunicorn config for Django on Heroku. Usage: "gunicorn -b 0.0.0.0:$PORT --settings $DJANGO_SETTINGS_MODULE -c gunicorn.py"
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
loglevel = 'error'
secure_scheme_headers = {
'HTTP_X_FORWARDED_PROTO': 'https'
}