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
from djredis.models import DredisMixin | |
import djredis.fields | |
class Blog(models.Model, DredisMixin): # inherit from the mixin class | |
author = models.ForeignKey('Author') | |
title = models.CharField(max_length=200) | |
viewcount = djredis.fields.Counter() | |
# optionally add a unique keyspace for the instance - default is shown below | |
def redis_key(self): |
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
def switchProtocol(currProto, newProto): | |
currentData = currProto.recvd | |
currProto.recvd = '' | |
newProto.makeConnection(currProto.transport) | |
if currentData: | |
newProto.dataReceived(currentData) |
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
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. |
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
# 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': |
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
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) |
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
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: |
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
@inlineCallbacks | |
def parallelSearch(keywords): | |
out = [] | |
for key in keywords: | |
out.append((yield search(k))) | |
returnValue(out) |
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
#!/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 |
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
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 |
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 | |
from time import time | |
from collections import deque | |
from itertools import permutations | |
from pprint import pprint | |
# xxT = xx Top | |
# xxB = xx Bottom | |
# Chocolate Brown |
OlderNewer