Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
What's happening?

Allan Lei allanlei

:shipit:
What's happening?
View GitHub Profile
@allanlei
allanlei / jquery.django.js
Created Jul 18, 2011
Django Serialization for Jquery
View jquery.django.js
(function($){
$.getDjangoJSON = function(url, data, success){
return $.ajax({
url: url,
dataType: "django-json",
data: data,
success: success
});
};
@allanlei
allanlei / README
Created Jul 18, 2011
Django Custom Queryset Mixin and manager
View README
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 Dec 30, 2011
pg_dump and upload to S3 using s3cmd
View db_backup_to_s3.sh
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 Dec 30, 2011
pg_dump and upload to S3 using s3cmd
View s3_db_backup.py
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 Jan 13, 2012
Script to use DNSimple's API
View dnsimple.py
#!/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 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
allanlei / .env
Created Jan 16, 2012
Sample local Heroku/Django development environment using foreman
View .env
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 Jan 17, 2012
Simple staticfile server for development using fapws
View staticfile-server.py
#!/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 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
allanlei / gunicorn.py
Created Feb 6, 2012
Sample Gunicorn config for Django on Heroku. Usage: "gunicorn -b 0.0.0.0:$PORT --settings $DJANGO_SETTINGS_MODULE -c gunicorn.py"
View gunicorn.py
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
loglevel = 'error'
secure_scheme_headers = {
'HTTP_X_FORWARDED_PROTO': 'https'
}
You can’t perform that action at this time.