The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Walking Slide Numbers

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Walking Slide Numbers Posted: Aug 9, 2005 12:01 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Walking Slide Numbers
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

See how Vincent Foley makes a local copy of the slides Matz put up:

 require "open-uri" 

 BASE_URL = "http://www.rubyist.net/~matz/slides/oscon2005/mgp" 
 "00001".upto("00059") do |n|
   puts "Fetching #{n}.html..." 
   File.open(n + ".html", "w") do |f|
     f.write(open(BASE_URL + n + ".html").read)
   end
 end

The part I’m digging is that "00001".upto("00059"). I totally forgot about String.upto, which does a succ behind the scenes.

 >> "r01".succ
 => "r02" 
 >> "r02".succ
 => "r03" 

But if you want Matz’ slides, let’s also grab the JPEGs.

 require "open-uri" 

 BASE_URL = "http://www.rubyist.net/~matz/slides/oscon2005/" 
 "mgp00001".upto("mgp00059") do |n|
   ['jpg', 'html'].each do |ext|
     puts "Fetching #{n}.#{ext}..." 
     File.open("#{n}.#{ext}", "w") do |f|
       f << open("#{BASE_URL}#{n}.#{ext}").read
     end
   end
 end

We’ve liked succ before, haven’t we? (Lifted from ruby-talk:151295.)

Read: Walking Slide Numbers

Topic: Introducing SwitchTower Previous Topic   Next Topic Topic: Typo 2.5 preview

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use