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
#! /usr/bin/env python | |
import cmd | |
class MyShell(cmd.Cmd): | |
def precmd(self, line): | |
lines = line.split(';') | |
self.cmdqueue.extend(lines[1:]) | |
return lines[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
#! -*- coding: utf-8 -*- | |
from multiprocessing import Pool | |
class Worker(object): | |
def __init__(self, func, *args): | |
self.func = func | |
self.args = args | |
def __call__(self, *args, **kw): |
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
#! /usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# This program works with both 1.8.7 and 1.9.3 | |
# | |
# usage: | |
# ruby cal.rb [month] [year] | |
# month and year are optional | |
require "date" |
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import lxml.html | |
from collections import Counter | |
doc = lxml.html.parse(open("cache.html")) | |
users = [x.text.upper() for x in doc.xpath("//div[@class='side_sec_box side_article_area']/div/p[@class='user']/a")[:400]] | |
print "".join(map(lambda x: x[0], Counter("".join(users)).most_common(5))) |
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
import os | |
import sys | |
import lxml.html | |
import twitter | |
api = twitter.Api( |
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
# http://lukasrieder.com/2009/07/14/extend-your-bash-ps1.html | |
function parse_git_dirty_and_branch() { | |
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
[[ $branch != '' ]] && echo "($(parse_git_dirty)$branch)" | |
} | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" |
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
# -*- coding: utf-8 -*- | |
import operator | |
def guard(*guardArgs, **guardKw): | |
def _argGuard(f): | |
def _inner(*args, **kw): | |
argTypes = map(lambda x: type(x), args) | |
if not all(map(operator.eq, guardArgs, argTypes)): | |
raise Exception("Type Error: not match type {0}, {1}".format(guardArgs, argTypes)) |
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
Python2.7.1 | |
================== | |
In [1]: import sys | |
In [2]: sys.version | |
Out[2]: '2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) \n[GCC 4.5.2]' | |
In [3]: import p002, p002_functional | |
In [4]: timeit p002.sumevenfibo(4000000) |
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
""" libpcre wrapping""" | |
from pypy.rpython.tool import rffi_platform | |
from pypy.rpython.lltypesystem import lltype, rffi | |
from pypy.translator.tool.cbuild import ExternalCompilationInfo | |
from pypy.translator.platform import platform | |
from pypy.tool.ansi_print import ansi_log | |
import py | |
import os |
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
def main(maxnum): | |
for idx in xrange(1, maxnum+1): | |
val = idx | |
if idx % 3 == 0: |