Skip to content

Instantly share code, notes, and snippets.

View wilsoncook's full-sized avatar

Wilson Zeng wilsoncook

  • Alibaba Inc.
  • China
View GitHub Profile
@wilsoncook
wilsoncook / post-update
Created July 1, 2014 05:08
GIT部署钩子post-update,放置于.git/hooks目录下
#!/bin/sh
#
# This hook does two things:
#
# 1. update the "info" files that allow the list of references to be
# queries over dumb transports such as http
#
# 2. if this repository looks like it is a non-bare repository, and
# the checked-out branch is pushed to, then update the working copy.
# This makes "push" function somewhat similarly to darcs and bzr.
@wilsoncook
wilsoncook / linux启动network
Created July 3, 2014 09:57
安装CentOS mininal版本后,如何启动network
Looks like your eth0 is not set up. Here is what I did to fix mine on CentOS 6.4.
sudo su -
cat /etc/sysconfig/network |grep -i network
This should return: NETWORKING=yes - If it does not, then change it to yes.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
This should look like:
@wilsoncook
wilsoncook / gist:18c28ea76f1eac5c4c41
Created August 9, 2014 04:27
a test script for Nodejs's issue #8118
//TEST issue #8118
//Nodejs is attempting to re-create a http request if the request-handler may exec more time #8118
//See: https://github.com/joyent/node/issues/8118
console.log('/******* Current Node *******/');
console.log(process.versions);
console.log(process.platform);
console.log('/****************************/');
var test_timeout_visited = false;
var test_timeout_count = 0;
@wilsoncook
wilsoncook / gist:10750f9aba03c76b6f98
Created August 30, 2014 03:47
C++常用函数集锦
//强制置顶窗口
void ForceForegroundWindow(HWND hWnd) {
DWORD thread1, thread2, pid;
thread1 = ::GetWindowThreadProcessId(::GetForegroundWindow(), &pid);
thread2 = ::GetCurrentThreadId();
::AttachThreadInput(thread2, thread1, TRUE);
::SetForegroundWindow(hWnd);
::AttachThreadInput(thread2, thread1, FALSE);
::BringWindowToTop(hWnd);
}
@wilsoncook
wilsoncook / lib.less
Created February 3, 2015 09:21
LESS工具库
//---精灵图操作
@spritePic: '../images/sprites.png'; //精灵图地址
.fn-setSprite (@width, @height, @x, @y) {
width: @width + 0px;
height: @height + 0px;
background: url(@spritePic) 0px - @x 0px - @y;
}
.fn-setSpriteXY (@x, @y) {
background-position: 0px - @x 0px - @y;
}
@wilsoncook
wilsoncook / SignAuther.js
Last active November 3, 2016 03:36
极简的服务器HTTP通信加密---PHP/JS端
/**
* 通用通信加密验证库【注:传递的参数名仅支持:数字、大小写字母】
* @author Wilson Zeng jackzcs@gmail.com
* @version 0.0.1
*/
(function () {
// Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
//依赖自由的md5
@wilsoncook
wilsoncook / gist:24049a6662aad23807342f244d02aa6d
Last active September 9, 2016 06:19
对象多级获取/设置值
/**
* 设置或获取某对象的多级属性
* @param {[type]} obj [可选]要设置或获取的对象,默认为空对象
* @param {[type]} key 获取或设置的键名
* @param {[type]} value 若为undefined则表示获取值,!undefined表示设置值
* @param {[type]} defaultValue 默认值,当获取值时,若值不存在则返回defaultValue
* @return {[type]} 当为设置时,返回obj本身,为获取时,返回对应属性值
*/
function getsetObject (obj, key, value, defaultValue) {
obj = obj || {};
@wilsoncook
wilsoncook / gzip_chunked.js
Last active November 15, 2016 03:38
模拟HTTP响应中,动态生成的内容流,然后经过gzip+chunked返回(测试学习用)
var zlib = require('zlib');
var Readable = require('stream').Readable;
var Transform = require('stream').Transform;
var count = 0, data = ['t007', '是', '个', 'idiot!'];
function MyReader (opts) {
Readable.call(this, opts);
};
MyReader.prototype = Object.create(Readable.prototype);
MyReader.prototype._read = function (size) {
@wilsoncook
wilsoncook / cross-origin-nginx.conf
Created November 16, 2016 09:43
利用nginx动态转发实现ajax跨域
server {
listen 80;
listen 443;
server_name zx250local.com;
# 测试,转发实现跨域
# 后面就可以这样在zx250local.com域名下发起其他域名的AJAX请求了,比如:
# $.getJSON('/cross/http%3a%2f%2fmobile.minmetals.com.cn%3a8050%2fwkjt%2fversion.html%3f1479282583007', function(result){console.log(result)})
location ~ /cross/(?<target>.+) { # 请求时,<target>中最好全部urlencode一遍
# rewrite /cross/(.+)$ /$1 break;