Skip to content

Instantly share code, notes, and snippets.

@ls0f
ls0f / proxy.go
Created February 26, 2016 02:54 — forked from wallrat/proxy.go
Simple GO TCP proxy
package main
import (
"net"
"fmt"
"io"
"os"
)
func main() {
if len(os.Args) != 3 {
fatal("usage: netfwd local remote")
@ls0f
ls0f / arp.py
Created February 23, 2016 05:27
arp hack
#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)
@ls0f
ls0f / img2txt.js
Created January 28, 2016 08:43 — forked from justjavac/img2txt.js
img2txt:基于canvas的图片转字符画工具
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;
// 根据灰度生成相应字符
@ls0f
ls0f / int2bin.py
Last active January 28, 2016 02:49
int2bin
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:]
@ls0f
ls0f / .tmux.conf
Created January 20, 2016 07:39
tmux config
#此类配置可以在命令行模式中输入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查询
@ls0f
ls0f / phone.go
Last active December 6, 2015 03:42
phone 的go解析
package main
import (
"bytes"
"encoding/binary"
"fmt"
"io/ioutil"
"strconv"
)
@ls0f
ls0f / analysis.py
Last active November 30, 2015 07:20
词频统计&DFA关键词匹配
# 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:
@ls0f
ls0f / python_daemon.py
Last active November 26, 2015 09:20
sime python daemon
#!/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.
@ls0f
ls0f / notify.py
Last active November 23, 2015 09:01
daemon notify
import functools
import sys
import pyinotify
import datetime
def restart():
pass
class MyEventHandler(pyinotify.ProcessEvent):
def my_init(self, file_object=sys.stdout):
@ls0f
ls0f / pysheme.py
Last active November 14, 2015 14:32
python scheme interpreters http://norvig.com/lispy.html
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."