Skip to content

Instantly share code, notes, and snippets.

Avatar

Drew Smathers djfroofy

  • Pro Solutions Llc.
  • Seattle, WA
View GitHub Profile
View horsepuzzle_start.py
import sys
from time import time
from collections import deque
from itertools import permutations
from pprint import pprint
# xxT = xx Top
# xxB = xx Bottom
# Chocolate Brown
@djfroofy
djfroofy / ipython-pypy-1.9.out
Created Aug 12, 2012
Tupling a generator vs. list comping
View ipython-pypy-1.9.out
pypy-1.9 Python 2.7.2
In [1]: g = xrange(10000)
In [2]: %timeit tuple(i for i in g)
1000 loops, best of 3: 659 us per loop
In [3]: %timeit [i for i in g]
10000 loops, best of 3: 77.9 us per loop
@djfroofy
djfroofy / performance_results.txt
Created Aug 4, 2012
Lists vs. StringIO vs. Regular String Concat for building strings in Python
View performance_results.txt
IPython 0.10.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [2]: from string_building_perf import *
In [3]: %timeit build_ul_list(100000)
10 loops, best of 3: 77.9 ms per loop
@djfroofy
djfroofy / amortize.lua
Created May 28, 2012
LUA Mortgage payment calculator
View amortize.lua
#!/usr/bin/env lua
function monthly_payment(principal, apr, years)
local i = apr / 12
local n = years * 12
return principal * (i + (i / ((1 + i)^n - 1)))
end
local principal = tonumber(arg[1])
local apr = tonumber(arg[2]) / 100
@djfroofy
djfroofy / txparallalsearch.py
Created Feb 16, 2012
parallelSearch with inlineCallbacks
View txparallalsearch.py
@inlineCallbacks
def parallelSearch(keywords):
out = []
for key in keywords:
out.append((yield search(k)))
returnValue(out)
@djfroofy
djfroofy / pylog_service.py
Created Nov 25, 2011
A Twisted Multiservice that sets ILogObserver
View pylog_service.py
from twisted.python.log import ILogObserver, PythonLoggingObserver
from twisted.application import service
class PythonLoggingMultiService(service.MultiService):
usePythonLogging = True
def setServiceParent(self, parent):
service.MultiService.setServiceParent(self, parent)
if self.usePythonLogging:
@djfroofy
djfroofy / quantumhealing.py
Created Aug 3, 2011
BL comp - Quantum Healing
View quantumhealing.py
from comps.core import *
player_rw = rw([0,0,0,0,R(5,0),5,0,5,0,0,0,5,17,5,0,0,12,24,29,24,5,5,0,0,0,0,0,5,17,5,5,0,0])
def mod_player():
next = player_rw.next()
player.noteFactory.amount = next
blakmaparada = Instrument('sf2/string/blakmaparada.sf2')
player = Player(blakmaparada, Adder(OrderedArp([53,55,60,57])), OrderedArp([127,100,120,90]), interval=0.5)
@djfroofy
djfroofy / noway.py
Created Jul 15, 2011
Making an iterable from __getitem__
View noway.py
# http://lucumr.pocoo.org/2011/7/9/python-and-pola/
class NoWay(object):
def __getitem__(self, key):
if key == 0:
return 'a'
if key == 1:
return 'b'
if key == 'apple':
@djfroofy
djfroofy / gist:988833
Created May 24, 2011
Traceback after trying PUT in txyoga
View gist:988833
web.Server Traceback (most recent call last):
<type 'exceptions.AttributeError'>: Request instance has no attribute 'body'
/Users/dsmathers/Envs/scrubbed/lib/python2.6/site-packages/Twisted-11.0.0_r31757-py2.6-macosx-10.6-universal.egg/twisted/web/server.py, line 126 in process
124 self.postpath = map(unquote, string.split(self.path[1:], '/'))
125 try:
126 resrc = self.site.getResourceFor(self)
127 self.render(resrc)
/Users/dsmathers/Envs/scrubbed/lib/python2.6/site-packages/Twisted-11.0.0_r31757-py2.6-macosx-10.6-universal.egg/twisted/web/server.py, line 542 in getResourceFor
540 # servers and disconnected sites.
View switch.py
def switchProtocol(currProto, newProto):
currentData = currProto.recvd
currProto.recvd = ''
newProto.makeConnection(currProto.transport)
if currentData:
newProto.dataReceived(currentData)
You can’t perform that action at this time.