Skip to content

Instantly share code, notes, and snippets.

View supersheep's full-sized avatar

Spud Hsu supersheep

View GitHub Profile
@supersheep
supersheep / simeple async queue
Created August 25, 2012 15:19
A simple javascript async queue
var list = [{
time:1000,
proc:function(){
console.log("after 1 second");
}
},{
time:5000,
proc:function(){
console.log("after 5 seconds");
}
@supersheep
supersheep / js-php-hooks
Created August 26, 2012 08:14
git pre-commit hook with php lint and closure compiler
#from https://github.com/genintho/Git-Pre-Commit
#!/bin/sh
GOOGLE_CLOSURE_PATH='/svn/staging/jsCompiler.jar'
echo "$(tput bold)SUMMARY$(tput sgr0)"
git diff --cached --name-status
echo ''
echo "$(tput bold)STAT$(tput sgr0)"
git diff --cached --stat
@supersheep
supersheep / image_proxy.php
Created November 23, 2012 13:48
crawl image , get content-length and log to file
$url = "http://ditu.google.cn/staticmap?hl=zh-cn&center=31.226659999958,121.48024000013&zoom=16&size=238x240&markers=31.226659999958,121.48024000013,red&client=free-dianping&signature=fN8tyLxLQ33hLYtFASuB2Wery7Q=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
$contentLength = 'unknown';
@supersheep
supersheep / queue
Created January 4, 2013 01:43
async.js like series queue
function Queue(tasks,alldone){
var currentTask = tasks[0];
Queue.result = Queue.result || [];
function done(result){
Queue.result.push(result);
tasks.shift();
Queue(tasks,alldone);
}
if(tasks.length){
currentTask(done);
@supersheep
supersheep / cheatmap
Last active December 11, 2015 07:08
上上下下左左右右ABAB
function cheatKeyMap(str,cb){
var cheat_train = str.split("");
var match_offset;
var keymap = {
38:"上",
40:"下",
37:"左",
39:"右"
};
@supersheep
supersheep / parseQuery
Created January 18, 2013 10:32
?a=1&b=2 => {a:1,b:2}
function parseQuery(){
return location.search ? (function(query){
var ret = {};
query.split("&").forEach(function(kv){
var pair = kv.split("=");
ret[pair[0]] = pair[1]
});
return ret;
})(location.search.slice(1)) : {};
}
@supersheep
supersheep / clipString
Created January 20, 2013 12:51
截字
// 非常偷懒的假设中文字符集为两个字符长度,别的都是一个
function clipString(str,length){
var strArr = str.split("");
var result = [];
for(var i=0;chr=strArr[i];i++){
if(/[\u0391-\uFFE5]/.test(chr)){
length -= 2;
}else{
length -= 1;
}
@supersheep
supersheep / iframeMap
Created January 26, 2013 13:13
iframeMapAccessor
(function(win,DP){
// 适配mootools与neuron框架创建元素方法
function create(tag){
if(DP.DOM){
return DP.DOM.create(tag).el(0)
}else{
return new Element(tag);
}
}
function (req, res, next) {
var url,reqdata;
if(!req.xhr){next();}
url = urlmod.parse(req.url).pathname;
reqdata = {
get : req.query,
post : req.body,
header: req.headers
};
function(resschema,body,type){
var result,schema;
if(!resschema){
return {ok:false,msg:"no response schema"};
}
if(!body){
return {ok:false,msg:"no body"};
}