Skip to content

Instantly share code, notes, and snippets.

@jbalogh
jbalogh / proxyproxy.js
Created November 9, 2010 18:27
node.js duplex proxy for load testing with production traffic
/* A node.js proxy that forwards requests to two upstream servers, but only
* returns the response from one. Might be useful for load testing with
* production traffic.
*/
var http = require('http');
/* The request is forwarded to both proxies, but only the response from proxy1
* is returned.
*/
var proxy1 = [8001, 'localhost'],
# pip install growl-py
try:
import Growl
i = Growl.Image.imageFromPath('media/img/amo2009/logo-mozilla.gif')
g = Growl.GrowlNotifier(applicationName='z', applicationIcon=i,
notifications=['Info'])
g.register()
g.notify('Info', 'ZAMBONI', None)
except Exception, e:
@jbalogh
jbalogh / urlconf_decorator.py
Created September 23, 2010 17:32
Apply a decorator to a whole urlconf instead of a single view function.
"""
Apply a decorator to a whole urlconf instead of a single view function.
Usage::
>>> from urlconf_decorator import decorate
>>>
>>> def dec(f):
... def wrapper(*args, **kw):
... print 'inside the decorator'
@jbalogh
jbalogh / async_signals.py
Created September 23, 2010 04:24
A monkeypatch for ``django.dispatch`` to send signals asynchronously.
"""
A monkeypatch for ``django.dispatch`` to send signals asynchronously.
Usage::
>>> import async_signals
>>> async_signals.start_the_machine()
``django.dispatch.Signal.send`` is replaced with an asynchronous version that
adds the signal to a queue processed on a background thread. The synchronous
@jbalogh
jbalogh / crush.py
Created September 15, 2010 20:39
crush.py generates a lot of load for redis
#!/usr/bin/env python
"""
./crush.py [host:port]
Runs a bunch of SADD and DELETE commands against Redis to see how it handles
high load. Do `./crush.py &` a bunch of times to generate a lot of
connections.
"""
import hashlib
import random
@jbalogh
jbalogh / hangserver.py
Created August 16, 2010 18:11
A server that accepts a connection and then hangs.
"""
A server that accepts a connection and then hangs. Pass a number to bind to a
specific port.
You need socket.settimeout.
"""
import socket
import sys
@jbalogh
jbalogh / gist:483424
Created July 20, 2010 19:29
An echo server so I remember how to use sockets.
import socket
def main():
server = socket.socket()
server.bind(('localhost', 9999))
server.listen(1)
print 'listening on :9999'
client = server.accept()[0]
while 1:
"""SMTP email backend class."""
from django.core.mail.backends import smtp
class EmailBackend(smtp.EmailBackend):
"""
A wrapper that manages the SMTP network connection.
"""
import re
import sys
logs = {}
regex = re.compile('z.timer:INFO (?P<method>\w+) "(?P<url>[^"]+)" '
'\((?P<code>\d+)\) (?P<time>[\d.]+) :')
@jbalogh
jbalogh / gist:423381
Created June 3, 2010 03:09
Generate tables of browser stats from webtrends json output
import collections
import json
import locale
import sys
import jingo
from babel.support import Format
KEY = 'Views'