Skip to content

Instantly share code, notes, and snippets.

def sanitizeArgs(func):
if func.func_code.co_flags & 8: # Has **var
return func # Can't know what arguments it takes
accepts = func.func_code.co_varnames[:func.func_code.co_argcount]
def sub(*args, **kwargs):
return func(*args, **dict((key, val) for key, val in kwargs.items() if key in accepts))
return sub
require 'pp'
require 'stringio'
class Architecture
class << self
def opcodes(&block)
@@opcodes = {}
@@operandCount = {}
@@disassembly = {}
@@semantics = {}
import urllib, urllib2
class Url(object):
def __init__(self, url):
self.url = url
def get(self, **kwargs):
url = self.url
if len(kwargs):
url += '?' + urllib.urlencode(kwargs)
from pylons import request
class FormException(Exception):
def __init__(self, name, description, value):
self.name, self.description, self.value = name, description, value
class FormEmptyException(FormException):
def __str__(self):
return 'Field %r (%s) is mandatory but empty.' % (self.name, self.description)
def select(name, cur=None, options=()):
options = ((v, v) if isinstance(v, str) else v for v in options)
return '<select name="%s">%s</select>' % (
name,
''.join('<option%s%s>%s</option>' % (
' selected' if cur == value else '',
(' value="%s"' % value) if value != name else '',
name
) for value, name in options)
import imp, marshal
def moduleFromData(name, data):
"""
Loads a module from a pyc string in memory.
`name` -- Name of the module
`data` -- Contains the contents of a pyc file in a string
Returns a module object
"""
code = marshal.loads(data[8:])
{
v18 = 0;
v19 = 0;
v20 = 0;
v21 = 0;
v22 = 0;
v23 = 0;
v24 = 0;
v25 = 0;
v26 = 0;
@daeken
daeken / regvex.py
Created October 23, 2010 02:31
Regex timing attack
# Copyright 2010 Cody Brocious (Daeken / [email protected])
# Distribution under the terms of the GPLv2 is a-ok.
import math, re, time, timeit
def mean(*vals):
return sum(vals) / float(len(vals))
def stddev(*vals):
_mean = mean(*vals)
import inspect
class MetaVar(object):
def __init__(self, name):
self.name = name
self.value = None
def __repr__(self):
return '_.%r' % self.name
from pypattern import *
if _((_.a, _.b)).match(('foo', 'bar')):
print a, b
if _(hax=_.bar).match({'hax' : 'zomg'}):
print bar