Skip to content

Instantly share code, notes, and snippets.

@maliubiao
maliubiao / itoa.py
Created October 1, 2014 06:20
转换整型到某base的字符串
hex_table = {
0: "0",
1: "1",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",
7: "7",
@maliubiao
maliubiao / daemon.py
Last active August 29, 2015 14:06
替代难用的nohup
#! /usr/bin/env python
#chmod +x daemon.py
#complete -cf daemon.py
import sys
import os
if len(sys.argv) < 2:
print "daemon.py cmdline..."
exit(0)
@maliubiao
maliubiao / tcp_info.py
Created September 25, 2014 11:41
获取一个socket的相关信息。
import socket
import cStringIO
import struct
def parse_struct(b, fmt):
d = {}
fmts = "".join([x[1] for x in fmt])
raw = b.read(struct.calcsize(fmts))
raw = struct.unpack(fmts, raw)
for i, item in enumerate(fmt):
@maliubiao
maliubiao / mysql_backtrace.py
Last active August 29, 2015 14:06
mysql thread backtrace
import gdb
import os
log = "/tmp/gdb.out"
pid = int(open("/tmp/gdb.in", "r").read())
gdb.execute("attach %d" % pid)
logfile = open(log, "w+", buffering=0)
p = gdb.selected_inferior()
of = "{:<5}{:<10}{:<5}\n"
#include <fcntl.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
char *lock_path = NULL;
@maliubiao
maliubiao / ifeng.py
Created September 24, 2014 03:15
检查凤凰网节目更新
#-*-encoding=utf-8-*-
import sys
import pdb
#https://github.com/maliubiao/simple_http
import simple_http
from lxml import etree
xpath = "/html/body/div[3]/div[2]/div[4]/div[2]/ul/li/h6/a"
#锵锵三人行
@maliubiao
maliubiao / travfs.py
Last active August 29, 2015 14:06
find the top n biggest file in a path
#! /usr/bin/env python
import os
import os.path
import stat
import sys
def new_queue():
#the dummy head
h = {
"item": None,
@maliubiao
maliubiao / changelog.py
Created September 6, 2014 14:21
replace the log file on the fly
#-*-encoding=utf-8-*-
import gdb
import os
import pdb
import os.path
S_IRUSR = 0400
S_IWUSR = 0200
S_IXUSR = 0100
@maliubiao
maliubiao / flatten.py
Last active August 29, 2015 14:06
flatten.py
def flatten1(l):
s = [(l, 0)]
x = []
while s:
d, i = s.pop()
dlen = len(d)
while i < dlen:
if isinstance(d[i], list):
s.append((d, i+1))
s.append((d[i], 0))
@maliubiao
maliubiao / randpass.py
Created September 5, 2014 03:07
random password generator
import os
import string
letters = string.letters
lowercase = string.lowercase
uppercase = string.uppercase
digits = string.digits
punctuation = string.punctuation
all_nospace = digits + letters + punctuation