Skip to content

Instantly share code, notes, and snippets.

View edmore's full-sized avatar

Edmore Moyo edmore

  • Philadelphia, USA
  • 05:51 (UTC -04:00)
View GitHub Profile
@edmore
edmore / git-svn
Created February 15, 2012 19:18
Git-svn
git svn clone <repo_url> [name]
git svn rebase
git svn dcommit
@edmore
edmore / console_wrapper2.js
Created January 24, 2012 11:41
Paul Irish 2
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( arguments );
}
};
@edmore
edmore / console_wrapper1.js
Created January 24, 2012 11:40
Paul Irish
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
@edmore
edmore / block_refactoring01.rb
Created January 13, 2012 06:58
Before rafactoring
def last_commit_message
output = parsed_json(list_commits)
output["commits"] ? output["commits"][0]["message"] : output
end
def last_commit_date
output = parsed_json(list_commits)
output["commits"] ? DateTime.parse(output["commits"][0]["committed_date"]).strftime("%d %B %Y %I:%M%p") : output
end
@edmore
edmore / block_refactoring02.rb
Created January 13, 2012 06:57
After refactoring
def last_commit_message
with_commits_list { |o| o["commits"] ? o["commits"][0]["message"] : o }
end
def last_commit_date
with_commits_list do |o|
o["commits"] ? DateTime.parse(o["commits"][0]["committed_date"]).strftime("%d %B %Y %I:%M%p") : o
end
end
@edmore
edmore / functional.js
Created October 24, 2011 11:30
Functional Inheritance
var person = function(spec){
var that = {};
that.getName = function(){
return spec.name;
};
that.getSex = function(){
return spec.sex;
};
@edmore
edmore / patterns.js
Created October 21, 2011 09:16
Understanding the differences between Private, Public and Privileged
//Based on Crockford's Private Members in JavaScript post..
var myObject = {
name : "Edmore",
age : 28,
next_year : function(){ // method
return this.age += 1;
}
};
@edmore
edmore / duck_typing.rb
Created September 28, 2011 20:31
Duck Typing
def make_a_sound(obj)
obj.sound!
end
def catch_make_a_sound(obj)
return obj.sound! if obj.respond_to? sound!
"#{obj.name} does not make a sound!!"
end
class Mouse
@edmore
edmore / closure.js
Created September 28, 2011 19:55
JavaScript closure
// usage : mult2 = multiplier(2) ; mult2(3) gives you 6
// usage : mult3 = multiplier(3)
var multiplier = function(x){
return function(y){
return x * y;
}
};
@edmore
edmore / closure.rb
Created September 28, 2011 19:53
Ruby closure
def multiplier(x)
lambda { |n| x * n }
end
# mult2 = multiplier(2) # returns Proc object
# mult2.call(3) # 6