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 -*- | |
# | |
# author: mayli <[email protected]> | |
# | |
# Modified from Pinhole, and the original code is found here: | |
# {{{ http://code.activestate.com/recipes/114642/ (r1) | |
# | |
""" | |
usage: pinhole |
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 -*- | |
# | |
# zipdb.py | |
# Use a zipfile store a dict like k-v database. | |
# Known bug: duplicate key(filenames) allowed | |
# | |
# Copyright 2012 mayli <[email protected]> | |
# |
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
""" | |
My little cache demo | |
without cache | |
$ time python PythonPlay.py | |
14930352 | |
real 0m9.392s | |
user 0m9.266s | |
sys 0m0.077s |
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 cgi, os | |
import cgitb; cgitb.enable() | |
form = cgi.FieldStorage() | |
if form.has_key("file"): | |
fileitem = form['file'] | |
if fileitem.filename: | |
fn = os.path.basename(fileitem.filename) | |
fn = fn.replace(' ','_') |
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 -*- | |
# | |
def longest_common_substring(s1, s2): | |
m = [[0] * (1 + len(s2)) for i in xrange(1 + len(s1))] | |
longest, x_longest = 0, 0 | |
for x in xrange(1, 1 + len(s1)): | |
for y in xrange(1, 1 + len(s2)): | |
if s1[x - 1] == s2[y - 1]: | |
m[x][y] = m[x - 1][y - 1] + 1 |
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 Queue | |
import xmlrpclib | |
from SimpleXMLRPCServer import SimpleXMLRPCServer | |
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler | |
import threading | |
from SocketServer import ThreadingMixIn | |
class ThreadingXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer): | |
pass |
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
#include <stdio.h> | |
#include <errno.h> | |
#include <sched.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
void print_sched(){ | |
printf("PID=%d, SCHED=%d\n", getpid(), sched_getscheduler(getpid())); | |
} |
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 threading | |
import collections | |
import logging | |
class CacheManager(object): | |
_lock = threading.RLock() | |
_cache = dict() | |
_cache_lock = collections.defaultdict(threading.Lock) | |
@staticmethod |
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 urllib | |
import re | |
import os | |
import shutil | |
URL = "http://tv.byr.cn/mobile/" | |
TV_STR = '"col-md-12"' | |
RE_TV = re.compile('<a>(.+)<\/a>') |
OlderNewer