Skip to content

Instantly share code, notes, and snippets.

View progrium's full-sized avatar

Jeff Lindsay progrium

View GitHub Profile
// This is a design doc for adding two methods to node via monkey patching
// that I find useful in all the little bits of HTTP glue I make. The point
// is to create a useful abstraction for forwarding requests and linking
// responses. In the most trivial case for building a reverse proxy, but
// see below for other use cases.
// API
http.ServerRequest.prototype.forward(port, host, dataFilter=null)
http.ServerResponse.prototype.attach(requestOrResponse, responseFilter=null, dataFilter=null)
#!/bin/bash
echo -e "tell application \"Quicksilver\"\nshow large type \"$1\"\nend tell" | osascript
import time
import operator
import collections
class SampledRate(object):
"""Tool for pushing rate over time data"""
def __init__(self, frequency=1, resolution=1, callback=None):
""" frequency: Rate update frequency in seconds
resolution: Interval to average data over in seconds
class CleanupHandler(webapp.RequestHandler):
def get(self):
posts = Post.all().filter('created <', datetime.datetime.now() - datetime.timedelta(days=90))
assert posts.count()
try:
while True:
db.delete(posts.fetch(500))
time.sleep(0.1)
except DeadlineExceededError:
self.response.clear()
import collections
import time
import simplejson as json
from mongrel2 import handler
sender_id = "82209006-86FF-4982-B5EA-D1E29E55D482"
conn = handler.Connection(sender_id, "ipc://run/requests", "ipc://run/responses")
import collections
import time
import threading
import sys
import uuid
from mongrel2 import handler
import simplejson as json
import zmq
import zookeeper
import sys
import os
import uuid
import zmq
from zmq import devices
ctx = zmq.Context(10)
datastore = {}
import sys
import os
import uuid
from time import time
import zmq
from zmq import devices
require 'rubygems'
require 'sinatra'
require 'ruby2ruby'
require 'pony'
require 'uri'
def base64_url_decode(str)
str += '=' * (4 - str.length.modulo(4))
Base64.decode64(str.gsub("-", "+").gsub("_", "/"))
end
import threading
from wsgiref.simple_server import make_server
def serve_once(handler, port=4442):
""" Single serving web server
Creates a web server in another thread that will output the result of
handler for a single request. Returns a URL to hit the web server.
"""
def app(e, start):