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.addMethod = function(name, method) { | |
var existingMethod = this.prototype[name]; | |
this.prototype[name] = function() { | |
if (method.length == arguments.length) { | |
return method.apply(this, arguments); | |
} else if (typeof existingMethod == "function") { | |
return existingMethod.apply(this, arguments); | |
} |
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 debounce(fn, time) { | |
var time = time || 300, | |
scope = this, | |
delay; | |
return function() { | |
var args = arguments; | |
if (delay) clearTimeout(delay); | |
delay = setTimeout(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
angular.module("autoscroll", []) | |
.service("scroller", function() { | |
this.defaultTime = 500; | |
this.scroll = function(element, height, time) { | |
element.animate({ | |
scrollTop: height | |
}, time || this.defaultTime); | |
} | |
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 fs = require("fs"), | |
readline = require("readline"); | |
var reader = readline.createInterface({ | |
input: fs.createReadStream("large-file.txt"), | |
output: fs.createWriteStream("/dev/null"), | |
terminal: false | |
}); | |
reader.on("line", function(line) { |
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 es = require("event-stream"); | |
module.exports = function() { | |
return es.map(function(file, callback) { | |
file.contents = new Buffer("(function() {\n" + String(file.contents) + "\n})();"); | |
callback(null, file); | |
}); | |
}; |
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
# This class implements async evaluation by transparently executing the block on a different thread. | |
class Future < Lazy | |
def initialize(&block) | |
@attribute = ::Lazy.new(&block) | |
@thread = ::Thread.new { @attribute.__send__(:__call__) } | |
end | |
private | |
def __call__ |
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
Array.prototype.unique = function() { | |
return this.filter(function(value, index, array) { | |
return array.indexOf(value) === index; | |
}); | |
} |
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 curry(fn) { | |
var arity = fn.length, | |
args = Array.prototype.slice.call(arguments, 1); | |
function accumulator() { | |
var leftArgs = args.concat(Array.prototype.slice.call(arguments, 0)); | |
if (leftArgs.length >= arity) { | |
return fn.apply(this, leftArgs); | |
} else { |
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
#!/usr/bin/env ruby | |
require "webrick" | |
unless ARGV[0] | |
STDERR.puts "Usage: cgiup [PATH TO CGI SCRIPT]" | |
exit 1 | |
end | |
cgi_script = File.expand_path(ARGV[0]) |
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
def luminance(color = "FFFFFF") | |
r, g, b = color.chars.each_slice(2).map(&:join).map(&:hex) | |
r * 0.299 + g * 0.587 + b * 0.114 | |
end |