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
#!/bin/bash | |
# | |
# pylink.sh - Link a Python module to your site packages directory. | |
# | |
# See http://gist.github.com/21649 for updates. | |
# Check that an argument has been given. If not, print usage string. | |
if [ -z $1 ] | |
then | |
echo "Usage: `basename $0` <path_to_module> [<link_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
class LazyChoiceField(forms.ChoiceField): | |
''' | |
A Lazy ChoiceField. | |
This ChoiceField does not unwind choices until a deepcopy is called on it. | |
This allows for dynamic choices generation every time an instance of a Form is created. | |
''' | |
def __init__(self, *args, **kwargs): | |
# remove choices from kwargs. | |
# choices should be an iterable | |
self._lazy_choices = kwargs.pop('choices',()) |
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 os | |
def rmgeneric(path, __func__): | |
try: | |
__func__(path) | |
#print 'Removed ', path | |
return 1 | |
except OSError, (errno, strerror): | |
print 'Could not remove %s, %s' % (path,strerror) | |
return 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
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: redis-server | |
# Required-Start: $syslog | |
# Required-Stop: $syslog | |
# Should-Start: $local_fs | |
# Should-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: redis-server - Persistent key-value db |
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,()) |
OlderNewer