Skip to content

Instantly share code, notes, and snippets.

@chrisjpowers
chrisjpowers / mock_console.js
Created April 13, 2010 21:49
Never have your javascript die from forgetting to take out console.log statements again!
// If console is not defined (ie the browser isn't
// using developer extensions), this will keep console
// statements accidentally left in the code from
// causing errors for the end user.
//
if(console == null) {
var console = {
log: function() {
// do nothing
}
@chrisjpowers
chrisjpowers / delayed_method_chain.rb
Created July 14, 2009 21:30
Allows you to declare alias_method_chain before either method has been defined.
# Allows you to declare an alias_method_chain before the original
# method has been defined.
#
# class A
# delayed_method_chain :name, :hello
#
# def name_with_hello
# "Hello #{name_without_hello}"
# end
#
class Hash
def map_values
h = {}; self.each_pair { |k,v| h[k] = yield(v) }; h
end
end
[ 'asdf', 'qwer' ].map{ |val| val * 2 }
# => [ 'asdfasdf', 'qwerqwer' ]
{ :one => 'asdf', :two => 'qwer' }.map{ |val| val * 2 }