Skip to content

Instantly share code, notes, and snippets.

@maliubiao
maliubiao / socket-stacks.py
Created November 29, 2013 04:22
network activity monitor.
#! /usr/bin/env python
import os
import sys
import time
import signal
import subprocess
stap_script = """
global counter = 0
global SOCK_STREAM = 1
@maliubiao
maliubiao / debugme.py
Last active December 31, 2015 07:59
debugme.py
#! /data/project/py/Python-2.7.3/python
import signal
import os
import time
path = "/data/project/py/Python-2.7.3/python"
masterpid = os.getpid()
breakonce = False
def sigint_handler(signum, frame):
@maliubiao
maliubiao / profile2csv.py
Created December 16, 2013 08:30
profile2csv.py file -> profile.csv, cProfile->pstats->csv.
import sys
import marshal
def main():
if len(sys.argv) < 2:
print "usage: profile2csv file -> profile.csv"
f = open(sys.argv[1], "r")
k = marshal.loads(f.read())
f.close()
f = open("profile.csv", "w")
@maliubiao
maliubiao / simple_gzip.py
Last active December 31, 2015 17:19
simple_gzip.py
from time import time
from struct import pack
from zlib import compressobj
from zlib import crc32
import zlib
compresslevel = 9
_crc = crc32("") & 0xffffffffL
compresser = compressobj(compresslevel,
zlib.DEFLATED,
@maliubiao
maliubiao / lz4.c
Created December 18, 2013 13:50
lz4 library
/*
LZ4 - Fast LZ compression algorithm
Copyright (C) 2011-2013, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
@maliubiao
maliubiao / main.css
Last active January 1, 2016 01:19
mysql manager demo
body {
background-color: whiteSmoke;
}
#navPanel {
margin-top: 3%;
}
#queryResult {
top: 10px; left: 10px;
display: block;
width: 500px;
@maliubiao
maliubiao / cache_area.py
Last active January 1, 2016 07:29
git internel , read git sha1 file.
import os.path
import pdb
import sys
import io
from struct import unpack
from time import ctime
#flags
CE_STAGEMASK = 0x3000
CE_EXTENDED = 0x4000
@maliubiao
maliubiao / weibo.py
Last active January 1, 2016 07:49
a stupid weibo sdk demo
#a very stupid weibo sdk
#-*-encoding=utf-8-*-
import io
import os
import pdb
import urllib
import json
import time
from simple_http import get
from simple_http import post
@maliubiao
maliubiao / ngx_modules.py
Last active January 1, 2016 14:39
ngx_modules
#! /usr/bin/env python
import os
import sys
import signal
stap_script = """
global i = 0;
global j = 0;
global k = 0;
probe process("/data/project/c/nginx-build/sbin/nginx").function("ngx_worker_process_cycle") {
@maliubiao
maliubiao / stacktools.py
Last active January 1, 2016 21:49
stacktools.py -> stacks.folded ; flamegraph.pl stacks.folded > graph.svg
import sys
import os
import signal
from traceback import extract_stack
from collections import OrderedDict
"""
MODE_SYSTRACE, ncalls
MODE_TIMER, capture stack every SAMPLE_INTERVAL
trace pure python code only, don't use syscall
"""