Skip to content

Instantly share code, notes, and snippets.

View jamiesun's full-sized avatar
🍇
On vacation

Jett Wang jamiesun

🍇
On vacation
View GitHub Profile
@jamiesun
jamiesun / tun-ping-linux.py
Created October 6, 2015 15:56 — forked from glacjay/tun-ping-linux.py
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2

Talkincode.org @codeid:44def9aa87254bd7836abdfff3c06825 "@tags:vim set nocompatible
set backspace=2
source $VIMRUNTIME/vimrc_example.vim
if has('win32')
source $VIMRUNTIME/mswin.vim
behave mswin
endif
set encoding=utf-8

@jamiesun
jamiesun / batch2utf8.py
Created July 19, 2012 10:36
批量转换一个目录下的文件到utf8
#!/usr/bin/python
#codeing:utf-8
import os
from optparse import OptionParser
if __name__ == "__main__":
usage = "usage: %prog [options] arg"
parser = OptionParser(usage)
@jamiesun
jamiesun / proxyserver
Created September 9, 2012 12:50
gevent实现基于端口转发的http代理服务器
import sys
import signal
import urlparse
import gevent
from gevent.server import StreamServer
from gevent.socket import create_connection, gethostbyname
class ProxyServer(StreamServer):
def __init__(self, listener, **kwargs):
#####################################################################
# COPY FROM http://www.gnome.org/~jdub/bzr/planet/2.0/planet/htmltmpl.py
# and inspired from http://www.python.org/pypi/zc.lockfile
# LICENSE: BSD
# Modified by: Limodou(limodou@gmail.com)
#####################################################################
__all__ = ['LOCK_EX', 'LOCK_SH', 'LOCK_UN', 'lock_file', 'unlock_file',
'LockFile', 'LockError']
@jamiesun
jamiesun / fock
Created September 9, 2012 15:02
python fork os.pipe()
#!/usr/bin/env python
import os, sys
print "I'm going to fork now - the child will write something to a pipe, and the parent will read it back"
r, w = os.pipe() # r,w是文件描述符, 不是文件对象
pid = os.fork()
if pid:
# 父进程
os.close(w) # 关闭一个文件描述符
r = os.fdopen(r) # 将r转化为文件对象
print "parent: reading"
@jamiesun
jamiesun / socks.py
Created September 10, 2012 09:53
SocksiPy - Python SOCKS module.
SocksiPy - Python SOCKS module.
@jamiesun
jamiesun / __init__.py
Created September 15, 2012 03:51 — forked from ipconfiger/__init__.py
OAuth包,实现了sina,QQ,网易,搜狐的OAuth认证
# -*- Encoding: utf-8 -*-
import base64
import binascii
import cgi
import hashlib
import hmac
import logging
import time
import urllib
import urlparse
@jamiesun
jamiesun / gist:3741546
Created September 18, 2012 06:21
pyqt and gevent
# -*- coding: utf-8 -*-
"""The user interface for our app"""
import os,sys
import gevent
# Import Qt modules
from PyQt4 import QtCore,QtGui
@jamiesun
jamiesun / export.py
Created September 21, 2012 10:21
oracle export data
#coding:utf-8
import sys
import cx_Oracle
import csv
print '请输入要导出的数据库地址,格式:user/passwd@host:port/sid :'.decode('utf-8')
db = len(sys.argv)>=2 and sys.argv[1] or raw_input('Enter db(user/passwd@host:port/sid):')
connection = cx_Oracle.Connection(db)