Skip to content

Instantly share code, notes, and snippets.

@rswofxd
rswofxd / GetKey.py
Created May 25, 2012 10:21
Python:获取键盘输入映射
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
class _Getch:
"""Gets a single character from standard input. Does not echo to the screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
@rswofxd
rswofxd / OnePicture.py
Created May 25, 2012 10:20
Python:国家地理每日一图
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import urllib2
import re
# get page html
page = urllib2.urlopen("http://photography.nationalgeographic.com/ngs_pod_ext/searchPOD.jsp?month=06&day=10&year=2009&page=")
@rswofxd
rswofxd / Loging.py
Created May 25, 2012 10:19
Python:log日志记录实现
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import os
import sys
import errno
import logging
import logging.handlers
@rswofxd
rswofxd / SVM.py
Created May 25, 2012 10:18
Python:神经网络SVM向量机模型
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import matplotlib
from pylab import plot
import sys,math
# get current tolerance level
@rswofxd
rswofxd / Netflow.py
Created May 25, 2012 09:58
Python:网卡流量统计实现
#coding:utf-8
import re,time
def get_net_info():
flow1 = open('/proc/net/dev')
lines = flow1.read()
flow1.close()
e = re.compile('(eth.)')
r_re = re.compile('eth..(.*?\s)')
@rswofxd
rswofxd / dirlist.py
Created May 25, 2012 09:57
Python:目录树遍历和生成
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from os.path import basename, isdir
from os import listdir
def traverse(path, depth=0):
print depth* '| ' + '|_', basename(path)
@rswofxd
rswofxd / weiboCN.py
Created May 25, 2012 09:56
Python:新浪微博刷粉工具
# -*- coding: utf-8 -*-
import urllib, urllib2, cookielib, hashlib,threading
import re, os, time, random
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def log(s):
@rswofxd
rswofxd / RE.py
Created May 25, 2012 09:54
Python:RE模块学习与实例
# -*- coding:UTF8 -*-
#1.概念:
# 正则表达式(或 RE)是一种小型的、高度专业化的编程语言,
# (在Python中)它内嵌在Python中,并通过 re 模块实现。使用这个小型语言,
# 你可以为想要匹配的相应字符串集指定规则;该字符串集可能包含英文语句、email
# 地址、TeX命令或任何你想搞定的东西。然后你可以问诸如“这个字符串匹配
# 该模式吗?”或“在这个字符串中是否有部分匹配该模式呢?”。你也可以使用 RE
# 以各种方式来修改或分割字符串。
#
# 正则表达式语言相对小型和受限(功能有限),因此并非所有字符串处理都能用
@rswofxd
rswofxd / pyfunstatitics.py
Created May 25, 2012 09:53
Python:获取模块中类与函数定义
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import os
import sys
def Show_file():
print "lines filename"
@rswofxd
rswofxd / webTCP.py
Created May 25, 2012 09:51
Python:网络TCP传输服务端和客户端
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
'''
Created on 2012-3-13
@author: 小马过河
'''