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
package main | |
import ( | |
"net" | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { | |
if len(os.Args) != 3 { | |
fatal("usage: netfwd local remote") |
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
#coding:utf-8 | |
import socket | |
import time | |
import os | |
import sys | |
from struct import pack | |
ARPOP_REQUEST = pack('!H', 0x0001) | |
ARPOP_REPLY = pack('!H', 0x0002) |
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
var cv = document.getElementById('cv'); | |
var c = cv.getContext('2d'); | |
var txtDiv = document.getElementById('txt'); | |
var fileBtn = document.getElementById("up-button"); | |
var img = new Image(); | |
img.src = 'a.jpg'; | |
img.onload = init; // 图片加载完开始转换 | |
fileBtn.onchange = getImg; | |
// 根据灰度生成相应字符 |
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 int2bin(num): | |
s = '' | |
while num > 0: | |
s = ('1' if num & 1 else '0') + s | |
num >>= 1 | |
return s if s else '0' | |
if __name__ == "__main__": | |
assert int2bin(12345) == bin(12345)[2:] |
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
#此类配置可以在命令行模式中输入show-options -g查询 | |
set-option -g base-index 1 #窗口的初始序号;默认为0,这里设置为1 | |
set-option -g display-time 5000 #提示信息的持续时间;设置足够的时间以避免看不清提示,单位为毫秒 | |
set-option -g repeat-time 1000 #控制台激活后的持续时间;设置合适的时间以避免每次操作都要先激活控制台,单位为毫秒 | |
set-option -g status-keys vi #操作状态栏时的默认键盘布局;可以设置为vi或emacs | |
set-option -g status-right "#(date +%H:%M' ')" #状态栏右方的内容;这里的设置将得到类似23:59的显示 | |
set-option -g status-right-length 10 #状态栏右方的内容长度;建议把更多的空间留给状态栏左方(用于列出当前窗口) | |
#set-option -g status-utf8 on 开启状态栏的UTF-8支持 | |
#此类设置可以在命令行模式中输入show-window-options -g查询 |
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
package main | |
import ( | |
"bytes" | |
"encoding/binary" | |
"fmt" | |
"io/ioutil" | |
"strconv" | |
) |
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
# http://vdisk.weibo.com/s/azYuqTtsWXaEc | |
def analysis(fn): | |
with open(fn, 'rb') as f: | |
content = f.read() | |
word_dict = {} | |
cur_word = '' | |
total_word = 0 | |
for c in content: |
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/env python | |
# http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ | |
import sys, os, time, atexit | |
from signal import SIGTERM | |
class Daemon: | |
""" | |
A generic daemon class. | |
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 functools | |
import sys | |
import pyinotify | |
import datetime | |
def restart(): | |
pass | |
class MyEventHandler(pyinotify.ProcessEvent): | |
def my_init(self, file_object=sys.stdout): |
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 math,operator as op | |
Number = (int, float) | |
Symbol = str | |
class Env(dict): | |
"An environment: a dict of {'var':val} pairs, with an outer Env." | |