Little Programs

Web Page Downloader

 #!ruby
 url = ask("Enter a URL:")
 save_as = ask("Save the URL as:")
 Web.download(url, save_as)

Web Page Viewer

 #!ruby
 url = ask("Enter a URL:")
 Web.page {
    iframe '', :src => url, :width => '100%', :height => '600px'
 }

Hello, Bob

name = ask("What's your name?")
print("Hi, ",name,"! Your name has ",name.length," letters in it.")

Hello, Bob II

name = ask("What is your name?")
age = ask("And how old are you ",name,"?")
days = age.to_i * 365 - 1
print("Hi ",name.capitalize,"! I bet it feels great to have seen at least ",days," days.")

Blinkard Blinker

 #!ruby
 6.times do
   say "O_o"
   sleep rand
   say "-_-"
   sleep 0.2
 end

HTML Helper

html = Web.page {
     h1 'A BIG Heading'
     p 'A paragraph'
}
puts html.string

Words

# Learn new words. (knowledge is power)
the_feed = Web.fetch "http://www.m-w.com/word/index.xml"
puts the_feed.items.first

Twitter reader (Not so little...)

#Twitter reader

#Grab info on who we're after and what we want to see
username = ask("Who is it I'm looking for?")
items = ask("How many tweets do you want to see?")

#Grab the JSON data off the net
json_data = Web.fetch("http://www.twitter.com/statuses/user_timeline/#{username}.json?count=#{items}")
#Parse the data
result = JSON.parse(json_data)

#Output the tweets
Web.page {
	#Give it a title
	h1 {a "#{username.capitalize}'s Twitter feed", :href => "http://twitter.com/#{username}"}
	#Show the users profile image
	center {img :src => result[0]['user']['profile_image_url']}

	#Echo the list of tweets with times and links
	ul {
		1.upto(items.to_i) do |item|
			li result[item.to_i - 1]['text']
			ul {
				li result[(item.to_i - 1)]['created_at'].sub!(/\+0000/, '')
				li {a "Permalink", :href => "http://twitter.com/#{username}/statuses/" + result[item.to_i - 1]['id'].to_s}
			}
		end
	}
}