Skip to content

Instantly share code, notes, and snippets.

View fuzzysteve's full-sized avatar
💭
Building shit

Steve Anderson / Steve Ronuken fuzzysteve

💭
Building shit
View GitHub Profile
@scragg0x
scragg0x / gist:3894835
Created October 15, 2012 19:47
Unserialize PHP Session in Python
def unserialize_session(val):
if not val:
return
session = {}
groups = re.split("([a-zA-Z0-9_]+)\|", val)
if len(groups) > 2:
groups = groups[1:]
groups = map(None, *([iter(groups)] * 2))
for i in range(len(groups)):
@gregburek
gregburek / rateLimitDecorator.py
Created December 7, 2011 01:51
Rate limiting function calls with Python Decorators
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0: