Skip to content

Instantly share code, notes, and snippets.

@maliubiao
maliubiao / locate-files.py
Created September 2, 2013 02:14
locate opened files
#! /usr/bin/env python
import os
import sys
import os.path
proc = '/proc'
fullpath = ''
query = sys.argv[1]
got = ''
for path in os.listdir(proc):
@maliubiao
maliubiao / daemonize.py
Last active December 22, 2015 03:09
create a daemon process, run program in the background.
#! /usr/bin/env python
import os
import sys
if __name__ == "__main__":
if len(sys.argv) < 2:
print("usage: daemon.py cmdline")
exit()
@maliubiao
maliubiao / break.py
Last active December 22, 2015 03:19
break a c function in python, usage: source break.py, see: help pycbreak in gdb.
#! /usr/bin/env python
try:
import gdb
except:
print("gdb only")
exit(0)
def version_error():
print("python 2.7.3 only")
exit(0)
@maliubiao
maliubiao / timer.c
Last active December 22, 2015 13:09
a little timer. "usage: timer [-f s] [-r s] -c shell-command\n\ -f s , timer expires once in s microseconds\n\ -r s, timer expires every s microseconds\n\ -c shell-command, execute this command via sh -c\n";
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#define CMDLEN 1024
@maliubiao
maliubiao / rmdup.py
Created September 14, 2013 02:50
remove dumplicates
#! /usr/bin/env python
if __name__ == "__main__":
import os
import sys
import os.path
path = sys.argv[1]
if not os.path.exists(path):
print("Error: file doesn't exists")
exit(0)
@maliubiao
maliubiao / readpyc.py
Last active December 23, 2015 01:19
pyc disassembler
#! /usr/bin/env python
"""globals"""
source = [""]
"""dis.py"""
"""Disassembler of Python byte code into mnemonics."""
import sys
@maliubiao
maliubiao / topyc.py
Last active December 23, 2015 03:09
topyc , compile python source code.
#! /usr/bin/env python
import os.path
import sys
import py_compile
if __name__ == "__main__":
if len(sys.argv) < 2:
print("usage: topyc.py yourfile.py")
exit(0)
path = sys.argv[1]
@maliubiao
maliubiao / stap-stack.py
Last active December 24, 2015 01:29
a dia plugin that draws the stack data generated by systemtap, you will find it useful when you want to read the source code of a large C project.
#! /usr/bin/env python
#-*-encoding=utf-8-*-
import pygtk
pygtk.require('2.0')
import gtk
import dia
import re
import os.path
import datetime
@maliubiao
maliubiao / ngx-stacks.py
Last active December 24, 2015 01:29
a sample script to capture stack data of nginx.
#! /usr/bin/env python
import os
import sys
import time
import signal
import subprocess
stap_script = """
global s;
@maliubiao
maliubiao / stacktrace.py
Last active December 25, 2015 03:48
stacktrace.py , usage: import trace, trace.starttrace("logfile") your cdoe to trace, trace.stoptrace()
import sys
import os
from cStringIO import StringIO
from traceback import extract_stack
"""
stack sample:
default_headers /usr/lib/python2.7/site-packages/requests/utils.py 452
__init__ /usr/lib/python2.7/site-packages/requests/sessions.py 176
request /usr/lib/python2.7/site-packages/requests/api.py 43