Monday, May 30, 2011
Exit from rufus-scheduler ruby
you can use "scheduler.stop" to stop the rufus/scheduler execution. require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.start_new
scheduler.in '1m' do
puts "hhhhhhhhhhhaaaaaaaaaaaaiiiiiiiiiiiiiiii"
if (some condition)
scheduler.stop
end
end
scheduler.joinParse media:content tag using Nokogiri
I need to extract the URL from this tag:
doc = Nokogiri::XML(open("http://www.ted.com/talks/rss"))
doc.css('item').each do |item|
puts item.at_xpath('media:content')['url']
end
"media:content url="http://video.ted.com/talk/podcast/2011/None/MikeMatas_2011.mp4" fileSize="15533795" type="video/mp4" />"
doc = Nokogiri::XML(open("http://www.ted.com/talks/rss"))
doc.css('item').each do |item|
puts item.at_xpath('media:content')['url']
end
Thursday, May 26, 2011
Grouping array ruby
Create arrays inside an array.
require 'enumerator'
>> a = (0..12).to_a
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>> b = a.enum_for(:each_slice,4).to_a
=> [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12]]
below is how to iteration
>> b.each do |c|
?> c.each do |value|
?> puts value
>> end
>> end
Subscribe to:
Posts (Atom)