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 lookup_url(ident); "http://favstar.fm/users/#{ident}"; end | |
def save_result(ident, result); puts Hpricot(result).at(:title).inner_text; end | |
def logger; Rails.logger; end | |
def name; 'console'; end | |
include Point::SiteLookup | |
perform_lookup! 'samstokes' | |
# console is querying http://favstar.fm/users/samstokes | |
# @samstokes' (Sam Stokes) most faved tweets |
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
hey |
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
hello |
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
require 'em-http' | |
require 'hpricot' | |
class EM::HttpRequest | |
synchronous_shim! :get | |
end | |
Hpricot(EM::HttpRequest.new('http://www.samstokes.co.uk/').get.response).at(:title).inner_text | |
# => "Sam Stokes" |
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
module Existing | |
def twinge | |
"Existing#twinge" | |
end | |
def prunge | |
"Existing#prunge" | |
end | |
end | |
# module included in another module |
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 do_funky_stuff | |
d = EM::DefaultDeferrable.new | |
# do some long-running thing synchronously | |
d.succeed | |
return d | |
end | |
do_funky_stuff.callback { sleep 5; puts 'Done!' } # blocks for 5 seconds | |
# prints "Done!" |
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
require 'blankslate' | |
# Instead of writing | |
# | |
# > (1..3).map(&:even?).map(&:to_s).map(&:upcase).map(&:reverse) | |
# => ["ESLAF", "EURT", "ESLAF"] | |
# | |
# write the more concise | |
# | |
# > (1..3).map_chain.even?.to_s.upcase.reverse.result |
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 ip2int(dotted) | |
dotted.split('.').map(&:to_i). | |
zip([24, 16, 8, 0]). | |
inject(0) do |s, (segment, shift)| | |
s + (segment << shift) | |
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
module Enumerable; def chunked(n); i=0; inject([]) {|chunks, item| if i % n == 0; chunks << [item]; else; chunks.last << item; end; i += 1; chunks }; 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
def gemver(gem); Gem.loaded_specs[gem.to_s].version; end |