Friday, June 26, 2009

Playing with Prawnto - Ruby PDF generator plugin

I recently watched Ryan's railscast PDFs with Prawn and tried it on tool version tracker application's index page (Please see my previous blog - Tool Version Tracker )

It was a good experience of writing text, image, table to pdf document with clean and neat code. I was able to generate the pdf document I intended to display in less than 20-25 minutes. (installing prawn gem, prawnto plugin, understanding some API and making code changes :-)

Prawnto is a rails plugin leveraging the Prawn library to produce compiled pdf views. The plugin adds a new template handler class that will process any views with a .prawn extension. These .prawn views are evaluated as ruby code and are provided an instantiated Prawn::Document object as 'pdf'. The pdf object gives you complete access to all of prawn's capabilities.

I added the following line to my index.rhtml page :-

link_to 'PDF Format', tools_url(:pdf)

Then I created index.pdf.prawn file :-



Clicking 'PDF Format' link on index page generated inline pdf for tools as below :-



There are many things that you can do with prawnto. (http://www.cracklabs.com/prawnto/demos) I plan to try these different options.

Have a nice pdf ! :-)

Thursday, June 18, 2009

Code Reading – The Open Source Perspective

The book 'Code Reading' has been written by Diomidis Spinellis.

This book is the first one to exclusively deal with code reading as a distinct activity. It primarily emphasizes on developing and improvising the Code Reading or comprehending skills of a programmer. The simplest way to learn to write great code is by reading good code. For that, one needs to make a distinction between a good and bad code.

The level of abstraction the programmer can hit upon given a section of code to analyze, depends on his/her code reading skills and perception about the problem. This book helps to enhance these skills.

At the beginning, it briefly introduces the commonly used programming structures and explains how to extract semantic meaning out of them. It talks about different nifty code reading techniques that may be used in the following scenarios –

- Analyzing large bodies of code
- Adding new functionality
- Fixing bugs
- Integrating into new environments
- Code Reuse

It further talks about understanding project build process, following coding standards and conventions, effectively using software documentation to supplement code reading efforts and getting architecture overview from a code in terms of design patterns.

It also describes some of the code reading and browsing tools which can enhance the code reading efficiency. (e.g. Regular expressions, grep for search, diff for difference in files, source navigator for browsing, code beautifiers, runtime tools like profiler – gprof in unix, etc.)

Reading this book will definitely spur interest into the programmers to learn a lot from the existing open source code and make valuable contributions to the open source world in future.

Wednesday, June 17, 2009

RailRoad - RoR diagram generator

Thanks to Javier Smaldone for developing this gem!

http://railroad.rubyforge.org/

This gem generates model and controller diagrams in RoR application. Javier has built on top of the original idea by Matt Biddulph. I mentioned Matt's idea in one of my earlier posts - Shaping models in RoR.

We should play with RailRoad in all our RoR applications to understand the complexity of the relationships that we have developed.

Tuesday, June 9, 2009

Making a difference !

This is a very nice story which I liked the most !

A man was walking along a beach when he saw a woman picking up starfish off the sand and tossing them into the waves. Curious, he asked her what she was doing. The woman replied "When the tide goes out it leaves these starfish stranded on the beach. They will dry up and die before the tide comes back in, so I am throwing them back into the sea where they can live."

The man then asked her "But this beach is miles long and there are hundreds of stranded starfish, many will die before you reach them - do you really think throwing back a few starfish is really going to make a difference?"

The woman just smiled. She picked up a starfish and threw it into the waves. "It certainly makes a difference to this one" she said.

In our day to day life, we come across many things that we consider very difficult to tackle with. There are many poor people, many mentally and physically retarded people, very old people, really needy people, etc. How can we make a difference in their lives ? Is it practical ? Certainly not. There are definitely some limitations.

But can we take inspiration from the above starfish story and step into making difference to at least one really needy person? Don't you think that will certaily make a difference in his/her life ?

Can we donate our valuable eyes to blind person after our death ?
Can we donate our blood ?
Can we adopt one orphan child for his/her education ?
Can we adopt a child completely ?
Can we help someone to start with small business ?


Actually there are many things that we can do .... we need to start with at least one though !

Tuesday, June 2, 2009

The big fire and the little water

Long time ago there was a great fire in the forests that covered our Earth. People and animals started to run, trying to escape from the fire. One of the eagles, was flying away also when he noticed a small bird hurrying back and forth between the nearest river and the fire. He headed towards this small bird.

He noticed that it was a small sparrow, flyinging to the river, picking up small drops of water in his beak, then returning to the fire to throw that tiny bit of water on the flame. The eagle approached the sparrow and yelled at him: "What are you doing brother? Are you stupid? You are not going to achieve anything by doing this. What are you trying to do? You must run for your life!"

The sparrow stopped for a moment and looked at the big eagle, and then answered:
"I am doing the best I can with what I have."