This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# | |
#author: rex | |
#blog: http://iregex.org | |
#filename tr.py | |
#created: 2010-08-01 20:24 | |
#source uri: http://iregex.org/blog/trie-in-python.html | |
# escape bug fix by fcicq @ 2012.8.19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for revert instructions please see http://digitaldj.net/2011/07/21/trim-enabler-for-lion/ | |
# \x51 is changed to \x4d in the script | |
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original | |
# this is for 10.8.1-10.8.2(?) | |
# sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4d)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage | |
# this is for 10.8.3 | |
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage | |
sudo touch /System/Library/Extensions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IPv6 | |
domain ip6 table filter { | |
chain INPUT { | |
proto ipv6-icmp ACCEPT; | |
} | |
} | |
domain (ip ip6) table filter { | |
# fcicq: temporary disable log... | |
chain logdrop { | |
# LOG log-level warning log-prefix "dropped "; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
有一存有整数的数组 A[n] (n <= 2^31 - 1, 但需要的话可以再扩大), 其中 0 <= i, A[i] <= n-1 且 i!=j 时 A[i]!=A[j] (即一个排列). 用你认为*最高效*的方法求 B=A^(-1) (即对范围内满足 A[B[i]]=i 的 B) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import traceback | |
def dump_threads(): | |
for thread_id, frame in sys._current_frames().iteritems(): | |
print 'Thread #%d' % thread_id | |
print ''.join(traceback.format_stack(frame)) | |
# Usage: print_frame_info(sys._getframe()) | |
def print_frame_info(frame): | |
print 'module: %s' % frame.f_globals.get('__name__') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Cipher import AES | |
from Crypto.Random import _UserFriendlyRNG | |
from Crypto.Util import Counter | |
import base64 | |
AES_NBITS = 256 | |
key = _UserFriendlyRNG.get_random_bytes(AES_NBITS / 8) | |
iv = _UserFriendlyRNG.get_random_bytes(AES.block_size / 2) | |
# we use the 8 bytes as iv, 8 bytes as counter, max file size is 2^64 * 16 = 2^68 bytes. | |
ctr_counter = Counter.new(AES.block_size * 8 / 2, prefix=iv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before using: rename your exported json as read.json | |
a = json.load(file('read.json')) | |
print '''<!DOCTYPE NETSCAPE-Bookmark-file-1> | |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> | |
<!-- This is an automatically generated file. | |
It will be read and overwritten. | |
Do Not Edit! --> | |
<TITLE>Bookmarks</TITLE> | |
<H1>Bookmarks</H1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
nsamples=1 | |
sleeptime=0 | |
pid=$(pidof mysqld) | |
for x in $(seq 1 $nsamples) | |
do | |
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid | |
sleep $sleeptime | |
done | \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
code: https://groups.google.com/d/msg/openresty/u-puKWWONMk/bxsyQdWMkJIJ by agentzh | |
Require SystemTap 2.0 and linux kernel 3.5+ | |
Example usage: | |
stap --ldd -d /path/to/nginx/sbin/nginx \ | |
-d /path/to/luajit/lib/libluajit-5.1.so.2.0.0 \ | |
--all-modules -D MAXMAPENTRIES=20240 \ | |
-D MAXACTION=20000 \ | |
-D MAXTRACE=100 \ | |
-D MAXSTRINGLEN=4096 \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def midreduce_iter(func, d, init=None): | |
it = iter(d) | |
if init is None: | |
i = it.next() | |
yield i | |
else: | |
i = init | |
while True: | |
i = func(i, it.next()) # as it will raise StopIteration exception... | |
yield i |