Archive for the ‘Web Development’ Category

Recently I met a lot of startup founders and directors through Singapore Entrepreneur & Developer
community. While many of them are interested to provide both web and mobile solution for their
application, some of them are thinking to get the web version out first and think about mobile
applications later.

In either case, they need to think of an approach that’s more agile and easily extensible. Many
developers would follow the conventional way of building an application and adding components for
more platforms they would support. That not only makes them write the same functional features
multiple times but also make it less scalable as and when more users will start using the
application.

I have jotted down an easier and more scalable approach which encourages in creation and adaptation
of an API based route. While in the first approach the number of controllers or methods are directly
proportional to the number of supported platforms, in the second approach they can leverage on the
single set of APIs. As and when they will support more platforms they can parse the API response
and display it as per the device form factor and designs. As most of the modern platforms like
mobile os, web technologies, internet TV, think-clients support XML or JSON parsing it will be
easier to re-use the same code or set of APIs to enable the solution for a new platform.

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!

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!)