Skip to content

Instantly share code, notes, and snippets.

View supersheep's full-sized avatar

Spud Hsu supersheep

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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");
}