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
# Define a method named add_one that accepts | |
# a block and returns the return value of the | |
# block + 1, as follows. | |
# (Hint: yield gives you the return value of | |
# the block) | |
add_one do | |
2 | |
end | |
# => 3 |
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
$ irb | |
1.9.3-p374-perf :001 > Time | |
=> Time | |
1.9.3-p374-perf :002 > Time.now | |
=> 2013-07-23 10:04:42 +0100 | |
1.9.3-p374-perf :003 > Time.now.iso8601 | |
NoMethodError: undefined method `iso8601' for 2013-07-23 10:04:47 +0100:Time | |
from (irb):3 | |
from /Users/joecorcoran/.rvm/rubies/ruby-1.9.3-p374-perf/bin/irb:16:in `<main>' | |
1.9.3-p374-perf :004 > require 'time' |
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
beforeEach(function() { | |
this.addMatchers({ | |
toBeNear: function(expected, within) { | |
within = within || 1; | |
return (this.actual >= (expected - within)) && (this.actual <= (expected + within)); | |
} | |
}); | |
}); |
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
10.times { City.cities_in_country("RU") } | |
Benchmark.bm | |
------------ | |
user system total real | |
JSON 33.210000 0.630000 33.840000 ( 33.872267) | |
YAML 78.530000 3.230000 81.760000 ( 81.758585) | |
Benchmark.bmbm | |
-------------- |
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
toHaveEvent: function(eventType){ | |
return (this.actual.data('events')) && (typeof this.actual.data('events')[eventType] == 'object'); | |
} |
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
Name | Department | Manager | Salary | |
---|---|---|---|---|
Robin Hood | 200 | |||
Arsene Wenger | Bar | Friar Tuck | 50 | |
Friar Tuck | Foo | Robin Hood | 100 | |
Little John | Foo | Robin Hood | 100 | |
Sam Allardyce | 250 | |||
Dimi Berbatov | Foo | Little John | 50 |
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
def smallest_temperature_spread | |
# store all munged values in a hash | |
map = {} | |
File.open("weather.dat", "r") do |file| | |
# iterate each line | |
while line = file.gets | |
# only use relevant lines | |
if line.match(/^\s+\d+\s+[\d\*]+\s+/) | |
# seems appropriate to convert keys to integers here for possible future use |
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 DoTooMuchStuff(num) { | |
$('p#mypar_'+num).slideUp(400).remove(); | |
$('h3#myheading_'+num).html('No records found'); | |
context.trigger('updateStoredRecords', { remove: num }); | |
var delimiter = ($('ul#removed > li').size() > 0) ? ', ' : ''; | |
$('ul#removed').append($('<li/>').html(delimiter+GetName(num))); | |
}; |
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
var app = $.sammy(function() { | |
var context = this; | |
this.get('#/', function() { | |
this.trigger('myEvent', { h1: 'My app', text: 'world' }); | |
}); | |
this.bind('myEvent', function(e, opts) { | |
$('h1').html(opts.h1); |
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
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){su=$("link[rev=canonical]").attr("href");su===undefined?alert("No%20short%20url!%20Try%20viewing%20the%20image%20directly,%20outside%20of%20any%20set."):alert(su);}); |