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
''' | |
Script for setting up python-django environment in ubuntu | |
''' | |
import os | |
packages = lambda name: 'apt-get install %s' % name | |
sysinstall = 'apache2 libapache2-mod-wsgi postgresql python-psycopg2 python-setuptools python-imaging' |
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
template<typename K, typename V> | |
struct key2value { | |
typedef K argument_type; | |
typedef V mapped_type; | |
typedef boost::unordered_map<K,V> hash_type; | |
typedef typename hash_type::value_type result_type; | |
typedef boost::shared_ptr<hash_type> hash_ptr; | |
key2value(const hash_ptr& h):hash_(h) { | |
} |
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 sortlist(views, func): | |
def comp(a,b): | |
if func(a) > func(b): | |
return 1 | |
else: | |
return -1 | |
views.sort(comp) | |
return views |
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 | |
from itertools import izip, islice | |
data = range(0,100000) | |
def loop1(): | |
return zip(data[::2],data[1::2]) | |
def loop2(): | |
return izip(data[::2],data[1::2]) |
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 time | |
from datetime import date, datetime | |
from decimal import Decimal | |
import json | |
def totimestamp(dte): | |
return time.mktime(dte.timetuple()) | |
def totimestamp2(dte): |
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 _getnone(): | |
return None | |
class NonePickler(object): | |
def __reduce__(self): | |
return (_getnone,()) |
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 | |