Skip to content

Instantly share code, notes, and snippets.

View kaizhu256's full-sized avatar

kai zhu kaizhu256

View GitHub Profile
@kaizhu256
kaizhu256 / travis-encrypt.sh
Last active August 29, 2015 14:02
travis encrypt secrets using shell commands
#!/bin/sh
function shTravisEncrypt () {
## this shell function travis encrypts the secret $2 for github repo $1
## tested to work on linux and osx (mountain lion)
local GITHUB_REPO="$1"
local SECRET="$2"
printf "fetching public rsa key from https://api.travis-ci.org/repos/$GITHUB_REPO/key ...\n"
curl -3Ls https://api.travis-ci.org/repos/$GITHUB_REPO/key\
| perl -ne 's/[^-]*//; s/"[^"]*$//; s/\\n/\n/g; s/ RSA / /g; print'\
@kaizhu256
kaizhu256 / phantomjs-capture.js
Last active August 29, 2015 14:04
screen capture using phantomjs
/*
phantomjs-capture.js from https://gist.github.com/kaizhu256/6637fa028d526b2c236d
usage example:
$ phantomjs phantomjs-capture https://www.google.com gooogle.png 5000
*/
/*jslint browser: true, indent:2, node: true, nomen: true*/
/*global phantom*/
(function submoduleCapturePhantomjs() {
/*
this phantomjs submodule captures a webpage
@kaizhu256
kaizhu256 / crawler.js
Created April 16, 2015 03:23
phantomjs web crawler
/*jslint
bitwise: true,
browser: true,
maxerr: 8,
maxlen: 96,
node: true,
nomen: true,
stupid: true
*/
(function (self) {
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
generalized-bucket-solution [2015.5.22-a]
</title>
<link rel="stylesheet" href="http://kaizhu256.github.io/assets/utility2.css">
<style>
@kaizhu256
kaizhu256 / curl.txt
Created June 9, 2015 02:22
china stock api
curl 'http://hq.sinajs.cn/list=rt_hk01816,hk01816_i,HKDCNY,rt_hkCSCSHQ,s_' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Referer: http://stock.finance.sina.com.cn/hkstock/view/stock.php?code=01816&level2=1' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36' --compressed
var hq_str_rt_hk01816="CGN POWER,�й�˵��,5.280,5.250,5.410,5.230,5.350,0.100,1.905,5.340,5.350,190496400.000,35700000,34.320,1.907,5.530,3.000,2015/06/09,09:54:54";
var hq_str_hk01816_i="EQTY,EQTY,5.530,3.000,0.126,0.102,0,11163625000,0,45448750000,1.878453038674,20793287000.00,5712568000.00,0.17,1";
var hq_str_HKDCNY="09:41:00,0.8000,0.8010,0.8000,6,0.8006,0.8006,0.8000,0.8000,��Ԫ�����";
var hq_str_rt_hkCSCSHQ=",,0.000,0.000,0.000,0.000,13398.271,0.000,0.000,0.000,0.000,0.000,13398270787,0.000,0.000,0.000,0.000,2015/06/09,09:54:49";
var hq_str_s_="";
@kaizhu256
kaizhu256 / curl.txt
Created June 9, 2015 02:23
china stock api
http://stock.finance.sina.com.cn/hkstock/view/stock.php?code=01816&level2=1
curl 'http://hq.sinajs.cn/list=rt_hk01816,hk01816_i,HKDCNY,rt_hkCSCSHQ,s_' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Referer: http://stock.finance.sina.com.cn/hkstock/view/stock.php?code=01816&level2=1' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36' --compressed
var hq_str_rt_hk01816="CGN POWER,�й�˵��,5.280,5.250,5.410,5.230,5.350,0.100,1.905,5.340,5.350,190496400.000,35700000,34.320,1.907,5.530,3.000,2015/06/09,09:54:54";
var hq_str_hk01816_i="EQTY,EQTY,5.530,3.000,0.126,0.102,0,11163625000,0,45448750000,1.878453038674,20793287000.00,5712568000.00,0.17,1";
var hq_str_HKDCNY="09:41:00,0.8000,0.8010,0.8000,6,0.8006,0.8006,0.8000,0.8000,��Ԫ�����";
var hq_str_rt_hkCSCSHQ=",,0.000,0.000,0.000,0.000,13398.271,0.000,0.000,0.000,0.000,0.000,13398270787,0.000,0.000,0.0
@kaizhu256
kaizhu256 / socks5.js
Created March 25, 2012 06:41
nodejs socks5 client handshake snippet
## socks5 handshake with existing connection
my.socks5Connect = function(kwargs) {};:
var addr;
my.ooUpdateUndefined(kwargs, my.urlParse(kwargs.href));
my.ooUpdateUndefined();:
kwargs, {}:
'bff': new Buffer(512),
'bffLen': 0,
'fncData': function(chunk) {},:
var bff;
@kaizhu256
kaizhu256 / gist:2191915
Created March 25, 2012 06:44
nodejs - key/value cache with efficient lru flush algorithm
my.Cache = function(ll) {
this.l1 = {}; this.l2 = {}; this.ii = 0; this.ll = ll || 256;
};
my.Cache.prototype = {
'flush': function() {this.l1 = {}; this.l2 = {}; this.ii = 0;},
'get': function(kk, vv0) {
this.ii += 1;
return this.l1[kk] === undefined ? this.l1[kk] = vv0 : this.l2[kk] = this.l1[kk];
},
'set': function(kk, vv) {
@kaizhu256
kaizhu256 / gist:2853690
Created June 1, 2012 17:10
javscript naive discrete fourier transform
//// naive O(n^2) algorithm for verifying fft algorithm
my.Complex2.prototype.dft = function(mode) {
var ee, ii2, ll2, tmp;
ll2 = this[0].ll2; ee = my.Complex2(1, ll2); tmp = ee.copy();
ee[1].set(my.Array2.range(ll2)).mul(-2 * Math.PI / ll2); if(mode === 'reverse') {ee.neg();}
if(mode === 'reverse') {this.mul(1 / ll2);}
this.each1(
function(slice) {
tmp.set([0, 0]);
for(ii2 = 0; ii2 < ll2; ii2 += 1) {
@kaizhu256
kaizhu256 / gist:2857043
Created June 2, 2012 06:56
javascript my.Complex2 - 2d complex array class
//// Complex2 - core
my.Complex2 = my.Complex2 || function(xxyy, ll2) {
var self; self = this;
if(!(self instanceof my.Complex2)) {return new my.Complex2(xxyy, ll2);}
if(ll2) {
if(typeof ll2 === 'number') {xxyy = [my.Array2(xxyy, ll2), my.Array2(xxyy, ll2)];}
}
self[0] = xxyy[0]; self[1] = xxyy[1];
my.ooEach(
2,