Skip to content

Instantly share code, notes, and snippets.

@oldcai
oldcai / install_pytho27.sh
Last active October 12, 2015 16:17 — forked from ftao/install_pytho27.sh
install python 2.7.3 on debian 6
#!/bin/sh
mkdir ~/down/
cd ~/down/
sudo apt-get install build-essential
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xzf Python-2.7.3.tgz
cd Python-2.7.3
sudo apt-get install libsqlite3-dev zlib1g-dev libncurses5-dev
sudo apt-get install libgdbm-dev libbz2-dev libreadline5-dev
sudo apt-get install libssl-dev libdb-dev
# 1. Make sure you have nginx sub module compiled in
# nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module'
# 2. add two directives below at HTTP level
# nginx.conf
http {
# ......
sub_filter '</head>' '<style type="text/css">html{ filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@oldcai
oldcai / compression_benchmark.py
Last active March 30, 2024 13:11
zlib vs lz4 vs lzma vs zstd compression
import time
import requests
import zlib
#!pip install lz4 pylzma zstd
import lz4.block
import pylzma as lzma
import zstd
def measure_time_and_compress_decompress(compress_func, decompress_func, data, *args):
# Measure compression time
@oldcai
oldcai / get_max_repeat.py
Last active January 1, 2016 12:19
题目是这样: 有一个队列,比方说是:2,2,2,2,2,2,3,3,3,3,3,1,1,1,5,5,5,5 然后让你找出数字中重复最多的一个数字。
#coding: utf-8
def get_max_repeat(*arr):
length = len(arr)
if length == 0:
return 0, 0
last_index = -1
current_index = 0
max_repeat_number = arr[0]
@oldcai
oldcai / dropbox_getfile.py
Created December 30, 2013 10:55
A dropbox read only client
#coding:utf-8
import os
import dropbox
app_key = 'app_key'
app_secret = 'app_secret'
def load_access_token():
if os.path.isfile("access_token"):
@oldcai
oldcai / result
Last active January 3, 2016 11:09
test put switch case in do...while loop
test case 1:
case on the top
case in do while
case in 2 loop for
case in 2 loop for
case in default
test case 2:
case in do while
case in 2 loop for
case in 2 loop for
@oldcai
oldcai / linear_regression.py
Created March 17, 2014 09:57
linear regression using python scipy
import numpy
import pylab
from scipy import stats
xi = numpy.arange(0, 9)
A = numpy.array([xi, numpy.ones(9)])
# linearly generated sequence
y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24]
slope, intercept, r_value, p_value, std_err = stats.linregress(xi, y)
@oldcai
oldcai / shadowspdyclient
Last active August 29, 2015 13:59
ShadowSPDY init scripts
#!/bin/sh
# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh
set -e
# Must be a valid filename
NAME=shadowspdy_client
PIDFILE=/var/run/$NAME.pid
#This is the command to be run, give the full pathname
DAEMON=/opt/ShadowSPDY/bin/splocal
@oldcai
oldcai / mkpack.sh
Last active August 29, 2015 14:10
Generate gfwlist pac file
#!/usr/bin/env bash
# To use this script, you need to install gfwlist2pac, curl first
# install command: pip install gfwlist2pac
# For more information: https://github.com/clowwindy/gfwlist2pac
rm gfwlist.txt
rm gfwlist.js
curl --socks5-hostname 127.0.0.1:1080 http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt > gfwlist.txt
gfwlist2pac -i gfwlist.txt -f gfwlist.js -p "SOCKS local.shadowsocks.com:1080; SOCKS5 local.shadowsocks.com:1080; DIRECT;" --user-rule user_rules.txt