Hackers don't write programs? Wtf?
Nailed it! Lets steal and do it faster:
require ‘peach’
(1…10).to_a.peach { |x|
sleep(Random.rand(2))
puts “job #{x} completed”
}
Done. Notice I didn’t join it (ie waited for thread completion), just let it rain.
MOAR?
Lets learn nokogiri… A gem that I can’t pronounce.
I just want the title of a website.
require 'nokogiri’
link = yourwebsitehtml
Nokogiri::HTML(open(link)).title
That’s not enough, I want to grab the titles off an array of websites:
require 'peach’
links = [“http://ti.me/ilD1iu”, “http://rg.tl/AdOwqW”…<<links>>…“http://nyti.ms/xlPl8V”]
links.pmap { |link| Nokogiri::HTML(open(link)).title }
Peach - Hackers choice.
Benchmark.bm do |x|
x.report { links[0…5].map { |link| Nokogiri::HTML(open(link)).title rescue link} }
x.report { links[5…10].pmap { |link| Nokogiri::HTML(open(link)).title rescue link} }
end