This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo -e "tell application \"Quicksilver\"\nshow large type \"$1\"\nend tell" | osascript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import time | |
import threading | |
import sys | |
import uuid | |
from mongrel2 import handler | |
import simplejson as json | |
import zmq | |
import zookeeper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import uuid | |
import zmq | |
from zmq import devices | |
ctx = zmq.Context(10) | |
datastore = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import uuid | |
from time import time | |
import zmq | |
from zmq import devices | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |