Skip to content

Instantly share code, notes, and snippets.

View objcode's full-sized avatar

Sean McQuillan objcode

  • Mountain View, CA
View GitHub Profile
class CachingInterface (object):
def __init__(self):
"To be overridden by the sub-class."
raise Exception("not implemented")
def store(key, value, type='post'):
"""
Store a key/value pair in the cache. Returns a Deferred.
@objcode
objcode / sadgenerators.py
Created August 9, 2011 08:00
Python generators sadface
import functools
class generatorfunction(object):
"""
Apparently you can't monkeypatch generator objects for some reason.
Lets go ahead and proxy them instead to add __call__.
"""
def __init__(self, generator):
self.delegate = generator
import signal
class TimerException(Exception): pass
def timeout(signum, frame):
print "signal handler exception", signum
print frame
raise TimerException(frame)
signal.signal(signal.SIGALRM, timeout)
@objcode
objcode / signal_timer.py
Created August 9, 2011 09:44
signal_timer context manager
import signal
import time
class TimerException(Exception): pass
from contextlib import contextmanager
@contextmanager
def signal_timer(mili):
@objcode
objcode / fail.py
Created September 18, 2011 02:34
python fail
def shell(cmdline):
start = time.time()
outbuffer = StringIO.StringIO()
print "asked to shell", cmdline
subcommands = cmdline.split('|')
subcommands = [command.strip() for command in subcommands]
first, last, subcommands = subcommands[0], subcommands[-1], subcommands[1:-1]
@objcode
objcode / thread.py
Created November 14, 2011 20:25
defer to thread in gevent
import gevent, gevent.event
import threading, Queue, collections, time, functools
def _threads_poller_f():
while _OsThread._threads_count:
try:
t, rv, isexc = _OsThread._threads_results.get_nowait()
except Queue.Empty:
gevent.sleep()
else:

Keybase proof

I hereby claim:

  • I am objcode on github.
  • I am objcode (https://keybase.io/objcode) on keybase.
  • I have a public key whose fingerprint is 3BF6 CC06 3DE3 4DE7 9DA8 2213 7F4D BEDF 4134 143B

To claim this, I am signing this object:

#!/usr/bin/env python
import csv
import sys
def process(fname, ofname):
with open(fname, 'rb') as csvfile:
with open(ofname, 'wb') as writefile:
out_lines = 0;
reader = csv.reader(csvfile)
id,nces_id,state,school_name,school_website,prefix,firstname,lastname,title,email,source,worker
,370002502096,CA,Quality Education Academy,,Mr.,Joe,Alpha,Teacher,[email protected],,
@objcode
objcode / Factorio indicator for tanks
Created September 16, 2017 19:24
How to make a tiered light indicator.
# A tiered light indicator is pretty easy to build and this will show you how to build scalable indicators using (2n + 1) decoders
# and one arithmetic. I made mine with three lights, which is enough to understand at a glance what's going on.
#
# You can also put the logic on the lights and use fewer deciders but I prefer this setup because it's easier to modify.
#
# Inputs:
# - R is a constant "ratio". It should be set to the integer value of (tank size - 1 / # of lights).
# - resource types
#
# Variables: