Skip to content

Instantly share code, notes, and snippets.

View j4mie's full-sized avatar

Jamie Matthews j4mie

View GitHub Profile
@j4mie
j4mie / index.html
Created July 31, 2011 09:02
Conway's Life in CoffeeScript and Processing.js
<!DOCTYPE html>
<title>CoffeeScript/Processing</title>
<script src="https://raw.github.com/jeresig/processing-js/master/processing.js"></script>
<script src="https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"></script>
<script src="https://raw.github.com/gist/1114064/professing.js"></script>
<script type="text/coffeescript">
sketch ->
@j4mie
j4mie / example.html
Created July 29, 2011 15:40
A tiny shim for Processing/Coffeescript prototyping
<!DOCTYPE html>
<title>CoffeeScript/Processing</title>
<script src="https://raw.github.com/jeresig/processing-js/master/processing.js"></script>
<script src="https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"></script>
<script src="https://raw.github.com/gist/1114064/professing.js"></script>
<script type="text/coffeescript">
sketch ->
@j4mie
j4mie / gunicorn-projectname.conf
Created May 13, 2011 08:07
upstart configuration for gunicorn
description "upstart configuration for gunicorn"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /home/jamie/.virtualenvs/projectname/bin/gunicorn_django -c /home/jamie/code/projectname/gunicorn.py /home/jamie/code/projectname/settings/production.py
@j4mie
j4mie / middleware.py
Created May 5, 2011 10:32
Django middleware to log the total number of queries run and query time for every request
from django.db import connection
from django.utils.log import getLogger
logger = getLogger(__name__)
class QueryCountDebugMiddleware(object):
"""
This middleware will log the number of queries run
and the total time taken for each request (with a
status code of 200). It does not currently support
@j4mie
j4mie / dynamicsubdomainreverseproxy.py
Created April 15, 2011 13:22
A reverse proxy that sends requests to "mysubdomain.mysite.com" to a machine with a DNS entry for "mysubdomain" (untested)
from twisted.internet import reactor
from twisted.web.proxy import ReverseProxyResource
from twisted.web.server import Site
from twisted.web.resource import Resource
class DynamicSubdomainReverseProxy(Resource):
isLeaf = False
allowedMethods = ("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")
def getChild(self, path, request):
@j4mie
j4mie / rundjangotests.sh
Created December 31, 2010 15:14
run the django test suite
# clone django from github and run its test suite
git clone https://github.com/django/django.git
cd django/tests
PYTHONPATH=`pwd`/../ ./runtests.py --settings=test_sqlite
@j4mie
j4mie / pushhandler.py
Created December 7, 2010 00:31
Send push notifications from GAE with Flask and Notifo
from flask import Flask, request
from google.appengine.api.mail import InboundEmailMessage
import notifo
from config import NOTIFO_USER, NOTIFO_KEY
app = Flask(__name__)
@app.route("/_ah/mail/<address>", methods=['POST'])
def receive_mail(address):
message = InboundEmailMessage(request.data)
@j4mie
j4mie / runserver.py
Created November 20, 2010 18:57
Run the Django development server programmatically
from django.core.management import setup_environ, call_command
import settings
setup_environ(settings)
call_command('runserver')
# This doesn't work from a Python REPL shell because the auto reloader is multithreaded
@j4mie
j4mie / chains.php
Created September 21, 2010 02:22
PHP __get weirdness
<?php
// You can do some very odd things with PHP's __get method
class Chain {
private $chain = array();
public static function it() {
return new self;
# autocomplete.py - Redis autocomplete example
# download female-names.txt from http://antirez.com/misc/female-names.txt
# Ruby original: http://gist.github.com/574044
# Requires http://github.com/andymccurdy/redis-py/
from redis import Redis
r = Redis()
KEY = 'compl'