This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uuid generator, 通过闭包在当前页面状态产生全局唯一的序列 | |
var uuid = (function(){ | |
var id = 0; | |
return function () { | |
return id++; | |
}; | |
}()); | |
uuid(); // 0 | |
uuid(); // 1 | |
uuid(); // 2 ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.uncurryThis = function() { | |
var f = this; | |
return function() { | |
var a = arguments, b = [].slice.call(a, 1); | |
return f.apply(a[0], b); | |
}; | |
}; | |
Function.prototype.curry = function() { | |
var fn = this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Introduces a typal object to make classical/prototypal patterns easier | |
* Plus some AOP sugar | |
* | |
* By Zachary Carter <[email protected]> | |
* MIT Licensed | |
* */ | |
var typal = (function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 如果你需要用短链表示github上的路径,可以使用git.io | |
curl -i http://git.io -F "url=https://github.com/..." | |
# HTTP/1.1 201 Created | |
# Location: http://git.io/abc123 | |
curl -i http://git.io/abc123 | |
# HTTP/1.1 302 Found | |
# Location: https://github.com/... | |
# 你也可以设置你自己定义的url地址 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cp_p() | |
{ | |
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \ | |
| awk '{ | |
count += $NF | |
if (count % 10 == 0) { | |
percent = count / total_size * 100 | |
printf "%3d%% [", percent | |
for (i=0;i<=percent;i++) | |
printf "=" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var module = {}; | |
// global on the server, window in the browser | |
var root, previous_module; | |
root = this; | |
if (root != null) { | |
previous_module = root.module; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var root = this; | |
// AMD / RequireJS | |
if (typeof define !== 'undefined' && define.amd) { | |
define('modulename', [], function () { | |
return global; | |
}); | |
} | |
// Node.js | |
else if (typeof module !== 'undefined' && module.exports) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Platform [email protected] Arch Linux | |
* Date 2013-07-12 09:43:15 | |
* @author [email protected] (cattail) | |
* | |
* @fileoverview Javascript code explain closure by movie inception. | |
* dream - function | |
* everything in dream including secret - scope | |
* people inside dream - executable code | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.curry = function () { | |
var fn = this; | |
var args = [].slice.call(arguments, 0); | |
return function () { | |
return fn.apply(this, args.concat([].slice.call(arguments, 0))); | |
}; | |
}; | |
var bind = function (func, thisArg) { | |
return function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Code example from <professional javascript for web developers v3 p733> | |
*/ | |
// problem | |
function Person(name, age, job){ | |
this.name = name; | |
this.age = age; | |
this.job = job; | |
} |