Skip to content

Instantly share code, notes, and snippets.

server {
listen 80;
server_name XXXX;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_pass https://spreadsheets.google.com;
proxy_set_header x-real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#coding=utf-8
import re
from scrapy import log
from scrapy.http import Request, FormRequest
from scrapy.spider import BaseSpider
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
def print_red(s):print '\033[0;31;48m%s\033[0m'%s
@xiaojay
xiaojay / gist:4965827
Created February 16, 2013 06:33
simple proxy server for debug
#coding=utf-8
import BaseHTTPServer, SocketServer, urllib, urllib2, urlparse, zlib, socket, os, sys, errno, base64, re, time, datetime
HopHeaders = ['connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'te', 'trailers', 'transfer-encoding', 'upgrade']
def print_red(s):
print '\033[0;31;48m%s\033[0m'%s
class ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
@xiaojay
xiaojay / gist:5675738
Created May 30, 2013 04:35
python script for masquerading squid log
#coding=utf-8
import sys, json
users = {}
uid = 0
fn = open(sys.argv[1])
while True:
line = fn.readline()
if not line:break
data = line.split()
@xiaojay
xiaojay / gist:5873816
Created June 27, 2013 03:54
test for observe num of goroutine running http://v2ex.com/t/73772#reply1
package main
import (
"fmt"
"time"
"math/rand"
"runtime"
)
func get_rand_int(max int) int {
rand.Seed( time.Now().UTC().UnixNano())
@xiaojay
xiaojay / gist:5873821
Created June 27, 2013 03:56
test2 for observe num of goroutine running http://v2ex.com/t/73772
ackage main
import (
"fmt"
"time"
"math/rand"
)
func get_rand_int(max int) int {
rand.Seed( time.Now().UTC().UnixNano())
return rand.Intn(max)
@xiaojay
xiaojay / gist:5935331
Created July 5, 2013 15:33
go for redis
package main
import(
"fmt"
"github.com/vmihailenco/redis"
)
func main(){
password := ""
db := int64(-1)
client := redis.NewTCPClient("localhost:6379", password, db)
@xiaojay
xiaojay / gist:6027022
Created July 18, 2013 06:04
unix epoch time convert to humbleable format
def c(t):
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
@xiaojay
xiaojay / addsrt.py
Created October 22, 2013 03:55
自动给coursera课程添加字幕加班
#coding=utf-8
import sys, os, subprocess
dir_ = sys.argv[1]
command = 'mencoder -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4 -sub "%s" -subfont-text-scale 1.8 -subpos 95 -sub-bg-alpha 240 -utf8 -o "%s" "%s"'
for fn in os.listdir(dir_):
name, ext = os.path.splitext(fn)
mp4_file = os.path.join(dir_, fn)
srt_file = os.path.join(dir_, '%s.srt'%name)
if ext == '.mp4' and os.path.exists(srt_file):
print fn
@xiaojay
xiaojay / gist:0073aa2c6a48700cd06d
Created August 28, 2014 14:17
squid basic auth
#auth_param basic program /usr/lib/squid3/ncsa_auth /home/jay/jayproxy/auth-password
#auth_param basic children 5
#auth_param basic realm PLEASE LOGIN IN
#auth_param basic credentialsttl 4 hours
#auth_param basic casesensitive off
#authenticate_ip_ttl 5 minutes
#acl nosingleip max_user_ip -s 1
#acl ncsa_users proxy_auth REQUIRED
#http_access deny nosingleip