Skip to content

Instantly share code, notes, and snippets.

View bremac's full-sized avatar

Brendan MacDonell bremac

  • Sight Machine
  • San Francisco, California
View GitHub Profile
@bremac
bremac / workerqueue.py
Created March 12, 2012 06:52
Handling client requests with workers using gevent
import gevent
from gevent.event import AsyncResult
import gevent.pool
import gevent.queue
class WorkerQueue(object):
def __init__(self):
self.group = gevent.pool.Group()
self.q = gevent.queue.Queue()
@bremac
bremac / handlers.py
Created January 20, 2012 00:23
Django Piston Example
from piston.handler import BaseHandler
from models import Apple
class AppleHandler(BaseHandler):
exclude = () # Ensure that the ID is shown.
allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')
model = Apple
@bremac
bremac / tpl.js
Created July 8, 2011 14:35
Minimal template processor in JS.
var template = function(ctx, tpl) {
var accum = [], idx = 0;
while (true) {
var start = tpl.indexOf('{{', idx);
if (start < 0) break;
var end = tpl.indexOf('}}', start);
if (end < 0) break;
var str = tpl.slice(start+2, end);
@bremac
bremac / ideas.coffee
Created May 30, 2011 13:47
Hal-baked ideas on Injectors. All legal but unusual coffee-script
inspect = (o) ->
alert(JSON.stringify(o))
# GWT-style module injection
class Module
constructor: (m) ->
@extend(m)
extend: (m) ->
for k, v of m