Posts Tagged ‘ruby’

I encountered an interesting issue with this couple of months ago.

Using mechanize you can select or click form dom elements, submit forms and automate
interaction with websites. But let’s say there’s a case when you select an element
or click on a button – and it’s calling a Javascript function to get the result.

In such cases, you can’t directly get the result by mechanizing the element. Rather
you could just follow two simple steps to get the result,

1 – View the page source or inspect the element using firebug.

2 – Do the exact thing in your ruby script that the javascript function is doing.

for example: If the javascript function is trying to load the data by opening another
Url then open that url in your Ruby script. Here, you can by pass the mechanizing step
and get the result directly!

10 cool tips to code in Java

Posted: September 25, 2008 in Quick Tips
Tags: , ,

* 1st and Most Important tip: Code in Ruby … don’t code in Java.

* Next 9 Tips : Follow the 1st Tip. :)

I spent a good amount of time in digging about another ruby gem.
RMagick is the magic gem I am talking about.In ruby, magic means
something amazing, something wow.You don’t have to scratch your
head to know about much of the background details. Just know how
to use it, and it’s all done!

RMagick is a binding from Ruby to the ImageMagick library. You can
use it to resize images, create thumbnails of images in a directory,
crop images, create watermarks for images and much more.

+ “rmagick” is the gems you need to include.

+ Magick::Image.read is a method returns an array if you will try to open gif
animation with multiple frames. In our case, we will get a single frame as it’s
a png image. And “.first” gives us the 1st frame which is the image itself.

+ change_gemometry method takes a new size as an argument and passes
the value to the associated blocks.

+ resize! method resizes the image and write saves the files with a new name.

You may like to try out other features of RMagick. Like conversation of image
formats. (PNG to JPG or others!)