This file contains 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
This is just a gist. |
This file contains 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
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/zeromq/gyre" | |
"os" | |
"time" | |
) |
This file contains 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 delay = setTimeout.partial(undefined, 10); | |
delay(function () { | |
console.log('A call to this function will be temporarily delayed.'); | |
}); | |
// logs 'A call to this function will be temporarily delayed.' | |
delay(function () {console.log('Some other message.');}); | |
// logs 'Some other message.' | |
})(); |
This file contains 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 delay = setTimeout.partial(undefined, 10); | |
delay(function () { | |
console.log('A call to this function will be temporarily delayed.'); | |
}); | |
// logs 'A call to this function will be temporarily delayed.' | |
delay(function () {console.log('Some other message.');}); | |
// logs 'A call to this function will be temporarily delayed.' | |
})(); |
This file contains 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 delay = setTimeout.partial(undefined, 10); | |
delay(function () { | |
console.log('A call to this function will be temporarily delayed.'); | |
}); | |
// logs 'A call to this function will be temporarily delayed.' | |
})(); |
This file contains 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.partial = function () { | |
var fn = this, args = Array.prototype.slice.call(arguments); | |
return function () { | |
var arg = 0; | |
for (var i = 0; i < args.length && arg < arguments.length; i++) | |
if (args[i] === undefined) | |
args[i] = arguments[arg++]; | |
return fn.apply(this, args); | |
}; | |
}; |
This file contains 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 has = 'hasOwnProperty', slice = Array.prototype.slice; | |
Function.prototype.partial = function () { | |
var method = this, orig = arguments, orig_len = orig.length, key, | |
new_method = function () { | |
var arguments_len = arguments.length, args = [], i = 0, j = 0; | |
if (!arguments_len) return method.apply(this, slice.call(orig)); | |
for (; i < orig_len; i++) | |
args.push(orig[i] === void 0 ? arguments[j++] : orig[i]); | |
return method.apply(this, args.concat(slice.call(arguments, j, arguments_len))); |
NewerOlder