Skip to content

Instantly share code, notes, and snippets.

View upbit's full-sized avatar

Zhou Hao upbit

  • China
View GitHub Profile
@upbit
upbit / pexpect_ssh.py
Last active August 29, 2015 13:57
python-pexpect demo
import pexpect # download from https://github.com/pexpect/pexpect
def remote_ssh_cmd(ip, cmd, user="root", passwd=""):
ssh = pexpect.spawn('ssh %s@%s "%s"' % (user, ip, cmd))
r = ''
try:
i = ssh.expect(['password: ', 'continue connecting (yes/no)?'])
if i == 0 :
ssh.sendline(passwd)
elif i == 1:
@upbit
upbit / hosts_to_dnsmasq.py
Created August 28, 2014 13:16
将hosts中的网站,转为dnsmasq的conf规则
# -*- coding: utf-8 -*-
HOSTS = """
# 将gfw hosts内容粘贴到这里
"""
BLACK_LIST = """com.co.jp
akamaihd.net
angrybirds.com
@upbit
upbit / update_imouto.host.sh
Last active August 29, 2015 14:05
MacOS用的imouto.host自动更新脚本
#!/bin/bash
IMOUTO_HOST="https://www.dropbox.com/sh/lw0ljk3sllmimpz/AAC-n6LmtWbdlKQRbdEa0QUoa/imouto.host.7z?dl=1"
# download hosts file
curl -L -o imouto.host.7z ${IMOUTO_HOST}
# unzip
./7za x imouto.host.7z imouto.host.txt
awk '{ if (NR==1) sub(/^\xef\xbb\xbf/,""); print }' imouto.host.txt > imouto.host.txt
# -*- coding: utf-8 -*-
##
## dump object to string
##
# XXX - ''.join([(len(`chr(x)`)==3) and chr(x) or '.' for x in range(256)])
__vis_filter = """................................ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................."""
def hexdump(buf, length=16):
"""form dpkt: Return a hexdump output string of the given buffer."""
@upbit
upbit / Makefile
Created November 21, 2014 03:03
Makefile for libCocoaHTTPServer.a
######################################
# Common Static library Makefile
######################################
TARGET := libCocoaHTTPServer.a
SRC_DIR := Core Core/Categories Core/Mime Core/Responses Extensions/WebDAV \
Vendor/CocoaAsyncSocket Vendor/CocoaLumberjack Vendor/CocoaLumberjack/Extensions
HEADER_DIR := include/
# > make clean && make && make headers
GET /?qt=cen&b=12376380.95%2C3574010.31%3B12376380.95%2C3574010.31&l=12&ie=utf-8&oue=1&res=api&callback=BMap._rd._cbk50813 HTTP/1.1
Host: api.map.baidu.com
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36
Referer: http://api.map.baidu.com/lbsapi/getpoint/index.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
Cookie: BAIDUPSID=B43CC9CA4D0E53EA8F712095BDAE5BB3; BDUSS=zl6MHBXYlZEZFRwSGlkallzeExVbENGQi1PcXFxbXdhNW05Yng2a01IcTlFLU5VQVFBQUFBJCQAAAAAAAAAAAEAAACK0zQHdXBiaXQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL2Gu1S9hrtUV; BAIDUID=DE16C72A2F375E80190C332AC83BF0E0:SL=0:NR=10:FG=1; cflag=65279%3A2
@upbit
upbit / itnl_idev.sh
Last active August 29, 2015 14:16
expect and connect with itnl 2022 port
#/bin/bash
killall itnl 2>&1 > /dev/null
itnl --tunnel &
expect -c "
set timeout 30
spawn ssh -p2022 root@127.0.0.1
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
@upbit
upbit / .gitconfig
Created March 18, 2015 15:26
GitHub config for China
[url "git@github.com:"]
# Always use GitHub SSH protocol to push.
# Allows use of git:// for public repositories with push access
#pushInsteadOf = git://github.com/
pushInsteadOf = https://github.com/
[url "https://github.com/"]
# Use HTTP for GitHub instead of git:// or git@
# Enable this in networks where git:// or git@ are blocked.
#insteadOf = git://github.com/
#insteadOf = git@github.com:
@upbit
upbit / SLNovel2Txt.md
Created March 30, 2015 15:56
转换空之文库(轻国阅读Android)sln文档格式为txt

SLNovel2Txt

转换空之文库(轻国阅读Android)sln文档格式为txt Script to convert Sora.SLNovel to txt

  • 使用方法
  1. 安装Python并下载 slnovel_to_txt.py 到任意文件夹中
@upbit
upbit / cmd.erl
Created June 18, 2015 10:59
erlang cmd.erl
-module(cmd).
%% https://kisao.wordpress.com/2013/12/16/how-to-run-a-system-command-in-erlang/
-export([run/1, run/2, test/0]).
run(Cmd) ->
run(Cmd, 5000).
run(Cmd, Timeout) ->
Port = erlang:open_port({spawn, Cmd},[exit_status]),