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 | |
import timeit | |
if sys.version_info < (3,0): | |
range = xrange | |
GSTR = 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' | |
def string_global(): | |
for x in range(0,10000): |
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
memory_symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') | |
memory_size = dict(((s,1 << (i+1)*10) for i,s in enumerate(memory_symbols))) | |
def convert_bytes(b): | |
'''Convert a number of bytes into a human readable memory usage''' | |
if b is None: | |
return '#NA' | |
for s in reversed(memory_symbols): | |
if b >= memory_size[s]: | |
value = float(b) / memory_size[s] |
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 socket | |
solist = [x for x in dir(socket) if x.startswith('SO_')] | |
solist.sort() | |
for x in solist: | |
print(x) |
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 random import random | |
from math import log | |
ispy3k = int(sys.version[0]) >= 3 | |
if not ispy3k: | |
range = xrange | |
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
KEY, PREV, NEXT = range(3) | |
class OrderedSet(object): | |
'''Equivalent to OrderedDict, this is a set class which remembers the | |
insertion order. | |
From http://code.activestate.com/recipes/576694-orderedset/''' | |
def __init__(self, iterable=None): | |
self.end = end = [] | |
end += [None, end, end] # sentinel node for doubly linked list | |
self.map = {} # key --> [key, prev, next] |
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 | |
if sys.version_info >= (2,7): | |
from unittest import * | |
else: | |
try: | |
from unittest2 import * | |
except ImportError: | |
print('To run tests in python 2.6 you need to install\ | |
the unitest2 package') |
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
'''Jinja2 template binding for djpcms. | |
''' | |
import os | |
import jinja2 | |
from djpcms.utils.importer import import_module | |
from djpcms import html, ImproperlyConfigured | |
####################################### JINJA2 Settings |
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
'''Stand alone compact module for managing python paths.''' | |
import os | |
import sys | |
if sys.version_info > (3,0): | |
string_type = str | |
else: | |
string_type = unicode | |
range = xrange |
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
'''A micro-asyncronous script derived from twisted.''' | |
import sys | |
import traceback | |
from collections import deque | |
__all__ = ['Deferred', 'MultiDeferred'] | |
def iterdata(stream): |
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 timeit | |
>>> timeit.Timer('str(n)','n=100000').timeit() | |
0.31551924882785443 | |
>>> timeit.Timer('"%s"%n','n=100000').timeit() | |
0.27519383648404983 | |
>>> timeit.Timer('"{0}".format(n)','n=100000').timeit() | |
0.5812355446599895 |