xkcd and ruby
is Yesterday I noticed that
yes ruby is really cool actually. One can very elegent and very easy to program with it. For the demonstration I've written a small program that displays the current
xkcd comic in a window. It has only 20 lines of code!
# / usr / bin / env ruby
require 'net / http'
require 'tk'
require 'tkextlib / tkimg'
str = Net:: HTTP.get (URI.parse ('http:/ / xkcd.com '))
img_url = URI.parse (str.match (' http \\: \\ / \\ / imgs \\ \\ xkcd com \\ / comics \\ / \\ w + \\ png ') to_s)
File.... . open ('img.png', 'w') { =
TkLabel.new label = (root)
label.image = image
root.height Image.Height = '/ img.png.';
root.width = image.Width;
label.place ('height' Image.Height =>, 'width' => image.Width)
Tk.mainloop
0 comments:
Post a Comment