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 | |
def accepts(*a, **kw): | |
""" | |
Decorates a function to add type checking to calls. | |
Raises TypeError if the decorated function is called with parameters that violate the type constraints. | |
@accepts can be called in the same way as the function it wraps, with positional and keyword arguments replaced by types. | |
Any arguments of the decorated function whose type are not specified will not be type checked. | |
Any arguments of the decorated function with default values will have those default values checked immediately. | |
""" |
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
''' | |
The idea is to create a SuperTree with jQuery like functionality on arbitrary | |
data. | |
The key is, chain and accept a selector function in place of css. | |
Here are some jQuery methods that could be implemented: | |
add() -- adds to the set of matched elements | |
Nodes should only be in one place -- one parent; |
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
table = {} | |
def f(n, k): | |
if (n, k) not in table: #compute if not yet visited | |
if n == 1: | |
table[n,k] = k-1 | |
if n == 2: | |
table[n,k] = k*(k-1) | |
if n >= 3: | |
table[n,k] = (k-1)*f(n-1, k) + (k-1)*f(n-2, k) |
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 ctypes | |
import time | |
import datetime | |
#a bunch of win32 constants; unfortunately must be hardcoded here | |
GENERIC_READ = 0x80000000 | |
SHARE_NONE = 0 | |
OPEN_EXISTING = 3 | |
FILE_ATTRIBUTE_NONE = 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
>>> class A(object): | |
... def __getattribute__(self, k): return "AAA" | |
... | |
>>> class B(A): pass | |
... | |
>>> b = B() | |
>>> b.a | |
'AAA' | |
>>> b.b = 2 | |
>>> b.b |
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 struct | |
import hashlib | |
import zlib | |
LONG = struct.Struct('>L') | |
def exec_secure(secure_file): | |
with open(secure_file, "rb") as f: | |
sec_data = f.read() | |
sec_data = zlib.decompress(sec_data) |
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
class updict(dict): | |
def __new__(cls, up=None, *a, **kw): | |
return dict.__new__(cls, *a, **kw) | |
def __init__(self, up=None, *a, **kw): | |
dict.__init__(self, *a, **kw) | |
self.up = up | |
def mro(self): | |
def mro_gen(): |
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
BINARY PARSING TEST..... | |
without instrumentation: | |
1.2692489624 seconds | |
Wed Jun 27 17:01:13 2012 profile.tmp | |
1431592 function calls (1343306 primitive calls) in 2.614 CPU seconds | |
Ordered by: internal time | |
List reduced from 99 to 30 due to restriction <30> |
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
maybe a way to squeeze a bit more out of these short string appends | |
>>> def list_method(): | |
... l = list() | |
... for i in range(10000): | |
... l.append(b'\x01') | |
... return "".join(l) | |
... | |
>>> a = list_method() | |
>>> def byte_array_method(): |
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
1/0 | |
Infinity | |
parseInt(1/0, 5) | |
NaN | |
parseInt(1/0, 19) | |
18 | |
parseInt(1/0, 20) | |
18 | |
parseInt(1/0, 45) | |
NaN |
OlderNewer