This file contains hidden or 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 next() for Python pre-2.6 | |
class Throw(object): pass | |
throw = Throw() # easy sentinel hack | |
def next(iterator, default=throw): | |
"""next(iterator[, default]) | |
Return the next item from the iterator. If default is given | |
and the iterator is exhausted, it is returned instead of | |
raising StopIteration. |
This file contains hidden or 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/env python | |
# -*- coding: utf-8 -*- | |
# unzip-gbk.py | |
import os | |
import sys | |
import zipfile | |
print "Processing File " + sys.argv[1] |
This file contains hidden or 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
>>> class AAA(object): | |
... def go(self): | |
... self.one = 'hello' | |
... | |
>>> class BBB(object): | |
... def go(self): | |
... one = 'hello' | |
... | |
>>> a1 = AAA() | |
>>> a1.go() |
This file contains hidden or 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 multiprocessing import Pool, cpu_count | |
from time import sleep | |
def f(x): | |
for i in range(10): | |
print 'counting %d --- Process:%d ' % (i, x) | |
sleep(1.0+float(x % cpu_count())/5) | |
def main(): |
This file contains hidden or 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 itertools import count, imap | |
import time | |
import sys | |
def stream(lo, hi, f): | |
def approx((a,b,c), n): return (a * n + b) // c | |
def mul((a,b,c), (d,e,f)): return a * d, a * e + b * f, c * f | |
xs = ((n, a*d, d) for n, d, a in imap(f, count(1))) | |
z = 1, 0, 1 | |
while True: |
This file contains hidden or 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
#coding:utf-8 | |
from random import choice | |
paper = [{'E': "天才", 'S': "笨蛋", 'W': "猪八戒", 'N': "大师兄"}, {'E': "Hentai", 'S': "绅士", 'W': "高富帅", 'N': "矮穷挫"}] | |
command = raw_input("Please input Direction and count, like: W25\n>>> ") | |
direction = command[0] | |
count = choice([0, 1]) + int(command[1:]) | |
print paper[count % 2][direction] |
This file contains hidden or 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 PyQt4 import QtCore | |
import glob | |
import os | |
import time | |
def all_files(pattern, search_path, pathsep=os.pathsep): | |
for path in search_path.split(pathsep): | |
for match in glob.glob(os.path.join(path, pattern)): | |
yield match |
This file contains hidden or 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 PyQt4 import QtCore, QtGui | |
class TextEdit(QtGui.QTextEdit): | |
""" | |
A TextEdit editor that sends editingFinished events | |
when the text was changed and focus is lost. | |
""" | |
editingFinished = QtCore.pyqtSignal() | |
receivedFocus = QtCore.pyqtSignal() |
This file contains hidden or 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/env python | |
import dpkt, socket | |
f = open('t.cap', 'rb') | |
pcap = dpkt.pcap.Reader(f) | |
c = 0 | |
ptr_c = 0 | |
log = open('4-seg-ip-dns-filter','w') |
This file contains hidden or 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 dpkt, socket | |
f = open('t.cap', 'rb') | |
pcap = dpkt.pcap.Reader(f) | |
c = 0 | |
for ts, buf in pcap: | |
# make sure we are dealing with IP traffic | |
# ref: http://www.iana.org/assignments/ethernet-numbers |