This file contains hidden or 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
/* Prototypes for __malloc_hook, __free_hook */ | |
#include <malloc.h> | |
static void *old_malloc_hook; | |
static void *old_free_hook; | |
/* Prototypes for our hooks. */ | |
static void my_init_hook (void); | |
static void *my_malloc_hook (size_t, const void *); | |
static void my_free_hook (void*, const void *); |
This file contains hidden or 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 json | |
def response(context, flow): | |
path = flow.response.request.path | |
if 'lol' in path: | |
flow.response.code = 200 | |
flow.response.msg = 'OK' | |
flow.response.content = 'Good job!'+log | |
elif 'getMessages' in path or 'poll' in path: |
This file contains hidden or 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/evn python2 | |
import json | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
class Promise(object): | |
def __init__(self, function=lambda: None, prev=None): | |
super(Promise, self).__init__() | |
self.function = function | |
self.prev = prev |
This file contains hidden or 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>') |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |