Archive for August, 2007

Aug 29

How can our code take a screenshot of a webpage, and save it to an image file ?

It turns out it’s easy. First, we need to

gem install win32screenshot

Then, write code something like this:

require ‘win32screenshot’
width, height, bmp = Win32::Screenshot.foreground
img = Magick::Image.from_blog(bmp)[0]
img.write(RAILS_ROOT + “/public/images/screenshot.png”)

Voila, and you get the screenshot!

Aug 24

I was a PHP programmer before, I got used to ‘echo’ when trying to debug PHP application.
That’s why when migrating to Ruby from PHP, I used pp a lot. Although it just prints to console, it helps a lot.

But I’ve been wondering all this while, sometimes I got an application error, undefined method ‘pp’, while trying to pretty-print an object on Rails.

I never bothered to find out why, until today where I just happen to.

It turns out we have to require ‘PP’ on our code to make it works. Duh!