Skip to content

Instantly share code, notes, and snippets.

View andymccurdy's full-sized avatar

Andy McCurdy andymccurdy

  • San Francisco, CA
View GitHub Profile
import threading
import Queue
q = Queue.Queue()
def worker():
while True:
msg = q.get(block=True)
# do stuff with the message
t = threading.Thread(target=worker)
import time
import threading
import redis
def worker():
print "starting thread..."
r = redis.Redis(db=9)
for i in xrange(2000):
r.incr('foo')
<script type="text/javascript">
   pageTracker._trackEvent('Ads', 'Quest Shown', '{{quest.name|slugify}}');
</script>
@andymccurdy
andymccurdy / crier.py
Created December 11, 2010 01:09
Crier: simple introspection for long-running Python processes
import pprint
import os
import sys
import threading
import time
import traceback
_crier = None
def init_crier(temp_dir='/tmp'):
"Initialzies Crier, ensuring it's only created once in the process"
@andymccurdy
andymccurdy / gist:891956
Created March 29, 2011 07:43
FU Django ORM
#good
Foo.objects.get(fk=45)
#not good
Foo.objects.get(fk_id=45)
#good
Foo.objects.create(fk_id=45)
#not good
Foo.objects.create(fk=45)
events {
worker_connections 1024;
}
http {
# Set cache dir
proxy_cache_path /var/nginx-cache levels=1:2 keys_zone=microcache:5m;
class Redis(...):
def __init__(self):
# dictionary of "installed" scripts to sha's
self.loaded_scripts = {}
def load_script(self, name, code):
"Install a script, giving it a friendly name"
sha = self.execute_command('SCRIPT', 'LOAD', code)
# save the friendly name => sha
self.loaded_scripts[name] = sha
####################################################
# WARNING: This is very hacky! Use at your own risk.
#
# This assumes you have all keys in a single DB and
# want to move them all to DB 0. If you have keys
# in more than one DB, the first DB found will be
# rewritten to 0, with all others left alone.
####################################################
import shutil
cd ~
rm -rf redis
git clone https://github.com/antirez/redis.git
cd redis
make
cp src/redis-server /usr/local/bin/
cp src/redis-cli /usr/local/bin/
======================================================================
ERROR: Failure: ImportError (cannot import name SkipTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/.virtualenvs/tested/lib/python2.6/site-packages/nose/loader.py", line 390, in loadTestsFromName
addr.filename, addr.module)
File "/Users/andy/.virtualenvs/tested/lib/python2.6/site-packages/nose/importer.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/andy/.virtualenvs/tested/lib/python2.6/site-packages/nose/importer.py", line 86, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)