Skip to content

Instantly share code, notes, and snippets.

View easierbycode's full-sized avatar

▓▒░ ♔ Daniel ♔ ░▒▓ easierbycode

View GitHub Profile
@easierbycode
easierbycode / Word Capitalize.js
Created February 14, 2012 16:21
Word Capitalize
// http://coderbyte.com/CodingArea/Results.php?ct=Letter%20Capitalize
function LetterCapitalize(str) {
return str.replace(/_/g, " ").toLowerCase().replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
@easierbycode
easierbycode / share_trip.coffee
Last active December 13, 2019 22:47
share google map trip (bit.ly, jst)
(($) ->
defaults =
version: "3.0"
login: "evogiadmin"
apiKey: "R_026ef971c6878e251cb7a2d395e88a6d"
history: "0"
format: "json"
$.bitly = (url, params) ->
params = $.extend(defaults, params)
@easierbycode
easierbycode / extend classes using prototype.js
Created February 24, 2012 23:02
extend Object/String/Number/Array using prototype
// all objects inherit methods and properties from Object.prototype, although they may be overridden
Object.prototype.toSource()
// "({})"
str = 'hello';
arr = new Array(20);
num = 99;
Object.prototype.boom = function() {
@easierbycode
easierbycode / binary_heap.js
Created February 26, 2012 22:02
JS binary heap
function identity(x) {
return x;
}
var heap = new BinaryHeap(identity);
forEach([2, 4, 5, 1, 6, 3], function(number) {
heap.push(number);
});
while (heap.size() > 0)
show(heap.pop());
@easierbycode
easierbycode / class vs instance methods.rb
Created February 29, 2012 03:22
Class vs Instance methods - when to use self.some_method
# http://bagwanpankaj.com/metaprogramming-in-rails
class Testt
end
Testt.class_eval do
def foo
"I'll be available as instance method"
end
@easierbycode
easierbycode / monkey_patching.rb
Created February 29, 2012 04:25 — forked from bagwanpankaj/monkey_patching.rb
Monkey Patching done right
#first we create a subclass of class string
class MyString < String
end
MyString.new
# => ""
#now we are going to override this method by some Ruby magic
MyString.class_eval do
def empty?
@easierbycode
easierbycode / object to primitive coersion.js
Created March 1, 2012 22:03
object to primitive coersion
var foo = {
toString: function () {
return 5;
},
valueOf: function () {
return "foo";
}
};
alert(foo.toString() + 1); // 6 (bad!)
alert(foo + 1); // "foo1" (no good!)
@easierbycode
easierbycode / array comparison.js
Created March 1, 2012 22:06
array comparison
[[]][0] === []
++[[]][0] === 1
++[[]][+[]] === 1 // yay! wtf!
@easierbycode
easierbycode / declaration vs initialization.js
Created March 1, 2012 22:11
declaration vs initialization
// Of course, the variable is undefined because its being declared but not initialized until after the document.write in the function context which itself runs before the first declaration of a.
var a = 8;
var someFunc = function(){
document.write(a);
var a = 8;
};
someFunc(); // writes undefined
@easierbycode
easierbycode / expression evaluation.js
Created March 1, 2012 22:16
(true) in expression evaluation
// Remember how true sometimes has a value so in the above 3 > 2 evaluates to true making the second part of the expression evaluate true > 1 which is false.
3 > 2 > 1 // false