Skip to content

Instantly share code, notes, and snippets.

@mayli
mayli / pinhole.py
Created March 11, 2012 16:03
A simple port multiplexer
#!/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
@mayli
mayli / zipdb.py
Created April 5, 2012 13:58
Use a zipfile store a dict like k-v database
#!/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]>
#
@mayli
mayli / authorized_keys
Created July 31, 2012 05:28
My public keys of ssh
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDByOEhRdY5ezKZmcZCbmJrFN8ot9jV3E8uvYzRgqcs13cvfNOl4s9YXHuZ/sjcEWPREIlfdQM27f2ZHy63F1dF3yUW1Msu+luNs+nrLnMlUzLRA2nauHR6/oK0VwiWcNfA0BGcW35gvyAy40iAZJYKfxO2OW1k/QpKMMraAR++P++azS6fdI8FsL0kIS4MXPq+oCdvJRoUPhZ2AA0XVOFYRPZ+aLic31KZfcRJLRJO1QQoH1esBgingfhMMs3a91FOaX8iqpVTbm2EMdVVY3SKrhifUWPcacJR5qT5eaJK40M2Pz3ou4H1rjt5tSjKheaoZXZmvDNk4jQzxOITfE7P mayli@Matrix7
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDt9wlh7DBoDW3JTmBCVLWPxzUWsZAWLMThq0TRbpgtQ5rZ224Bm0l+g5cB8/eVWDhwVQFidOneyfWziq5QKqmwhZ9Zq+8vYMw8fAWPfplUOyqBsPigDuvoNP6ZRVp2b07b0waaesd8tzyJ+7pDfqj/YixOanHXZ4DHyKhnpuXRSnioOpbNZrunRhtrAfh+fuZbi6xI4jwc102AKMixyhdv7borgNcw+sUww2h2NiY2VGW7F+FgjO0EKDK0wsaBTKwdK55yuJRIE5PrM8cM/gOKPYzgo7bER+dmACmSHSRNu8qV0pmOH49YC9qPt/usZdW5R1Y/Frcn73eWLssMhN0Z mayli@matrix
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsJL9n89aMBmv3uCm5CebwJnD/Gytd81FHFA4CPKKwwZPS7A2fVVzlUbig9gntn42O78JNlxUZu7VvQXjbdDW0kOI2tZojQG05rfEA8oYS9YD0FCs84rZhpgvCUacjgNvBsMycLG6bc+b2GfzL0+6qVfr7rPZ2PeGNXbbST/dku2wXfa0+2mfE4TK75/ay017BY17
@mayli
mayli / cacheplay.py
Created August 11, 2013 05:04
My little cache demo
"""
My little cache demo
without cache
$ time python PythonPlay.py
14930352
real 0m9.392s
user 0m9.266s
sys 0m0.077s
@mayli
mayli / save_file.py
Created October 2, 2013 04:38
Python CGI program to convert a pdf to swf, just a POC
#!/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(' ','_')
@mayli
mayli / lcstring
Created November 23, 2013 22:30
longest common substring
#!/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
@mayli
mayli / RPCQueue.py
Created April 24, 2015 20:59
RPCQueue
import Queue
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import threading
from SocketServer import ThreadingMixIn
class ThreadingXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
pass
@mayli
mayli / sched_play.c
Created July 19, 2015 21:54
play with SCHED_RR
#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()));
}
@mayli
mayli / cache.py
Created October 10, 2015 00:38
Cache Manager
import threading
import collections
import logging
class CacheManager(object):
_lock = threading.RLock()
_cache = dict()
_cache_lock = collections.defaultdict(threading.Lock)
@staticmethod
@mayli
mayli / brytv_gen.py
Last active December 24, 2015 22:16
Generate rtmp.strm file for tv.byr.cn
#!/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>')