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 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 |
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
require 'pp' | |
require 'stringio' | |
class Architecture | |
class << self | |
def opcodes(&block) | |
@@opcodes = {} | |
@@operandCount = {} | |
@@disassembly = {} | |
@@semantics = {} |
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 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) |
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 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) |
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 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) |
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 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:]) |
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
{ | |
v18 = 0; | |
v19 = 0; | |
v20 = 0; | |
v21 = 0; | |
v22 = 0; | |
v23 = 0; | |
v24 = 0; | |
v25 = 0; | |
v26 = 0; |
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
# 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) |
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 inspect | |
class MetaVar(object): | |
def __init__(self, name): | |
self.name = name | |
self.value = None | |
def __repr__(self): | |
return '_.%r' % self.name |
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 pypattern import * | |
if _((_.a, _.b)).match(('foo', 'bar')): | |
print a, b | |
if _(hax=_.bar).match({'hax' : 'zomg'}): | |
print bar |
OlderNewer