Skip to content

Instantly share code, notes, and snippets.

@mayli
mayli / malloc_hook.c
Created May 21, 2016 00:37
malloc wrapper
/* 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 *);
@mayli
mayli / candycrush.py
Created May 21, 2016 00:30
Candy Crush Mitm Hack (maybe no longer working)
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:
@mayli
mayli / promise.py
Created March 19, 2016 01:30
Promise in Python?
#!/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
@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>')
@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 / 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 / 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 / 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 / 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 / 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