This file contains 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
class Dingo | |
def self.bark | |
"woof" | |
end | |
def self.eat | |
"A dingo ate my baby!" | |
end |
This file contains 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
class Array | |
# split array into groups up to n items, randomly choosing the size. | |
def split_random(n) | |
size == 0 ? self : (size == 1 ? [self] : self[1..-1].reduce([[self[0]]]){|ll, elt| (rand(n)==(n-1) || ll[-1].size==n) ? ll + [[elt]] : ll[0..-2] + [ll[-1] +[elt]]}) | |
end | |
end |
This file contains 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
class Array | |
def split_random(n) | |
def td(n) | |
[take(n),drop(n)] | |
end | |
def split_random_acc(n,l, acc) | |
head,tail = l.td(rand(n)+1) | |
return (acc + [head]) if tail==[] | |
split_random_acc(n, tail, acc + [head]) |
This file contains 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
# There is more than one way to skin a cat, different coders prefer different methods. | |
include ActionView::Helpers | |
class Link < Struct.new(:title, :url); end | |
a = Link.new("Google", "http://www.google.com") | |
b = Link.new("Hacker News", "http://news.ycombinator.com") | |
array_of_links = [a, b] |
This file contains 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() { | |
if(typeof(console) == 'undefined') { | |
(function() { | |
/* Shim for window.console */ | |
var methods = ['log', 'info', 'warn', 'error']; | |
window.console = {}; | |
for(var i = 0; i < methods.length; i++){ | |
window.console[ methods[i] ] = function() {}; | |
} | |
})(); |
This file contains 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
@mixin ie6 { * html & { @content } } | |
#logo { | |
background-image: url("/images/logo.png"); | |
@include ie6 { background-image: url("/images/logo.gif"); } | |
} |
This file contains 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
/ | |
.7 | |
\ , // | |
|\.--._/|// | |
/\ ) ) ).'/ | |
/( \ // / | |
/( J`((_/ \ | |
/ ) | _\ / |
This file contains 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
// once the google maps is loaded, put a Raphael canvas on top of it | |
// be sure to apply margin:0 to the body in this case | |
var point = new GLatLng(46.065375, 5.448974); | |
var pixel = map.fromLatLngToContainerPixel(point); | |
var paper = Raphael(0, 0, 400, 300); | |
var circle = paper.circle(pixel.x, pixel.y, 10); | |
circle.attr("fill", "#f00"); | |
circle.attr("stroke", "#fff"); |
This file contains 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
protected function sendToHoptoad (msg:String):void { | |
var yamlData:String = 'notice: \n' | |
+ ' api_key: YOUR_API_KEY\n' | |
+ ' error_message: "' + msg + '"\n' | |
+ ' backtrace: \n' | |
+ ' request: {}\n' | |
+ ' session: {}\n' | |
+ ' environment: \n' | |
+ ' RAILS_ENV: [YOUR_ENV_HERE]\n'; | |