Skip to content

Instantly share code, notes, and snippets.

@thegrandpoobah
thegrandpoobah / _.retry.js
Created May 5, 2011 14:34
Retry mixin for Underscore.js
_.mixin({
// Polls condition indefinitely every N milliseconds and executes
// a function once the condition has passed.
retry: function(func, cond, wait) {
var args = slice.call(arguments, 3);
if (cond()) {
func.apply(this, args);
} else {
_.delay.apply(this, [_.retry, wait, func, cond, wait].concat(args));
}
@rmcafee
rmcafee / hash_extend.rb
Created May 19, 2009 18:18
Extend Ruby Hash with Useful Methods
class Hash
def except(*blacklist)
{}.tap do |h|
(keys - blacklist).each { |k| h[k] = self[k] }
end
end
def only(*whitelist)
{}.tap do |h|
(keys & whitelist).each { |k| h[k] = self[k] }