Sunday, May 24, 2009

Learning from mistakes

Thomas Edison tried two thousand different materials in search of a filament for the light bulb. When none worked satisfactorily, his assistant complained, "All our work is in vain. We have learned nothing."

Edison replied very confidently, "Oh, we have come a long way and we have learned a lot. We know that there are two thousand elements which we cannot use to make a good light bulb!"

Moral: Always take things positively. You can learn a lot from the mistakes you commit. Actually by commiting mistakes, you are laying a strong foundation before the world. So even if you think you have wasted a big time for that, you have actually saved a huge time of others in future...

Saturday, May 23, 2009

Obedient Disciples

One day while they were on their way to a distant town, Guru Gampar fell asleep in the bullock cart they were travelling in. His head rolled from side to side and suddenly his turban slipped from his head and fell on to the road. But as their guru had told them never to do anything without his permission, none of the disciples made a move to get down and pick it up.

When the guru woke up and was told about the loss of his turban he was furious. "Next time anything falls off pick it up at once!" he thundered.

Some time later the bullock dropped its dung and the four foolish disciples leaped down and picked it up. Guru Gampar was horrified. He made a list of the things that could fall off from a moving cart. "Pick up any of these things if they fall," he told them, handing them the list. "Don't pick up anything that is not mentioned here."

Just then the cart lurched violently and Guru Gampar was thrown headlong into a ditch. Guru Gampar yelled to his disciples to pull him out.

"We can't, guruji," said his disciples, sadly. "Your name is not on the list you gave us." Guru Gampar pleaded with them to pull him out, but in vain.

"We know you are testing us, guruji," they told him. "But you can rest assured that we will never disobey you. You told us not pick up anything that was not mentioned in your list and we will not do so."

"Give me the list!" yelled Guru Gampar. They threw him the list and the pen and the guru hastily scrawled his name on it.

Then and then only did the obedient disciples pull their beloved guru out of the ditch and put him back into the cart !

Moral : Obedience has to be backed with Conscience and Prudence, otherwise it becomes just a silly act.

Friday, May 22, 2009

What is Unobtrusive javascript ?

In simple words, it is separation of behaviour from the html structure.

Consider the following example :-



The style of this button element, to include the font of its caption, is provided by CSS rules loaded via a stylesheet. But while this declaration does not mix style with structure, it does mix behavior with structure, by including the JavaScript
that is to be executed when the button is clicked as part of the markup of the button element (which in this case, turns something named xyz red upon a click of the button).

For all the same reasons that it is desirable to segregate style and structure within an HTML document, it is also becoming recognized that separation of behavior from structure has just as many, if not more, benefits.

This movement is known as Unobtrusive Javascript.

jQuery is a javascript library which supports this movement. It aims to change the way that web developers fundamentally think about creating rich functionality in their pages. jQuery is generally useful for any page that needs to perform anything but the most trivial of JavaScript operations, but is also strongly focused on enabling page authors to employ the concept of Unobtrusive JavaScript within their pages. With this approach, behavior is separated from structure in the same way that CSS separates style from structure, achieving better page organization and increased code versatility.

Thursday, May 21, 2009

Who moved my cheese ?

The book 'Who moved my cheese?' has been written by Spencer Johnson. It's an amazing way to deal with change in our work and in our life. Many people have reported that what they discovered in the story has improved their careers, businesses, health and marriages.

I found this book very interesting as it correctly identifies human thinking patterns.

Cheese is a metaphor for what you want to have in life - whether it is a good job, a loving relationship, etc.

Maze is where you look for what you want - the organisation you work in, or the family or community you live in.

There are four imaginary characters depicted in the story. They intend to represent the simple and complex parts of ourselves, regardless of our age, gender, race or nationality.

Sniff :- who sniffs out change early
Scurry :- who scurries into action
Hem :- who denies and resists change as he fears it will lead to something worse
Haw :- who learns to adapt in time when he sees changing can lead to something better !


Here are the simple but very important notes/principles mentioned in this book :-

(1) Having cheese makes you happy
(2) The more important your cheese is to you, the more you want to hold on to it
(3) If you do not change, you can become extinct
(4) What would you do if you weren't afraid ?
(5) Smell the cheese often so you know when it is getting old
(6) Movement in a new direction helps you find new cheese
(7) When you stop being afraid, you feel good !
(8) Imagining yourself enjoying your new cheese leads you to it
(9) The quicker you let go of old cheese, the sooner you find new cheese
(10)It is safer to search in the maze, than remain in a cheeseless situation
(11)Old beliefs do not lead you to new cheese
(12)When you see that you can find and enjoy new cheese, you change course
(13)Noticing small changes early helps you adapt to the bigger changes that are to come


Enjoy reading ! :-)

Tuesday, May 19, 2009

Astronomical Dating of the Ramayan and South America was known in Ramayan era - by Dr. P V Vartak

I recently read a book "Vastav Ramayan" (Real Ramayan) written by Dr. P.V.Vartak.
He has done scientific research and calculated dates of the important events during Ramayan era. It is a very interesting and scientific book that everyone should read.

Here is a link for Astronomical Dating of the Ramayan :-

Astronomical dating of Ramayan events

Also, his research shows that South America was known at the Ramayan era. Indians migrated to South America which is called "Patal Lok" in sanskrit. There are some places in South America which denote the Indian culture, like Surya Mandir (Sun Temple), Elephants, Lord Ganesha and snakes carved on ancient monuments, etc.

In Ramyan, when King Sugriv directs his men in all directions in search of Sita, he instructs people going to east direction to check out for a TRIDENT engraved on a mountain. He describes the Trident as "A long Golden flagstick with three limbs stuck on top. It always glitters in when seen from sky". (This trident is on west coast of peru - Lima and is visible clearly from the sky)

In Valmiki Ramayan - Kishkindha Kaand - The sanskrit shlok is as below: (Kishkindha-39/47-48)




The entire Valkimi Ramayan can be found at :-

Complete Valkimi Ramayan in Sanskrit

The description given is so clear that Sugriv or Sage Valmiki must have seen this trident from sky proving they might have aeroplanes to travel.



Around 100 miles from this trident, there is a place called Nazca or Nasca, where gigantic geometric shapes are drawn on land (Spread in miles across). These are visible from sky only. Looks like big airport at that time.

Pls visit these links so that you can get a picture.
Trident at Lima-Peru
Nazca lines

According to Dr. P. V. Vartak, the trident is a sign of east ( as we have 180 degrees today to decide from where west starts ). This was created by Lord Vishnu around 15000 - 17000 years ago. And the lines on the Nazca are the signs of Ancient Airport of King Bali, around 15000 years ago.

If you get a chance, please read this book - Vastav Ramayan! It is awesome !

Also the book 'PataalYatra' by Anil Patil is good to read. It is a fiction inspired by South America and Pataal invention by Dr. P V Vartak.

Michael Crichton's fictions

I have read few fictions of Michael Crichton and very impressed with his writing skills. He keeps one totally engrossed with the story.

Jurassic Park, The Lost World, The Terminal Man, Eaters of the Dead, Timeline, State of Fear, The Andromeda Strain are some of his fictions that I have read and liked all of these.

I have also seen some movies that are based on his novels, but truely speaking the thrill that I experienced while reading the novels was much greater than watching the movie :-)

Thursday, May 14, 2009

Shaping Models in ruby on rails

Whenever a new team member enters to any enhancement project, from technical perspective, he tries to understand the already developed code. Code comprehension may become difficult if there is no proper documentation. There can be many models with different relationships defined amongst themselves. Won't it be good to have some sort of diagrammatic representation of the Model relationships ? It will certainly be very helpful for the development and support teams to understand the application in technical perspective.

Let's develop small and simple ruby code to construct a diagrammatic representation
of the Model (Active Record) relationships (Model in M-V-C architecture) in any Ruby on Rails application. (We will follow KISS principle - Keep it simple and Succinct ! :-)

Active Record is an implementation of the object-relational mapping (ORM) pattern by the same name as described by Martin Fowler:

"An object that wraps a row in a database table or view, encapsulates
the database access, and adds domain logic on that data."



Active Record supports three types of relationship between tables:
(1) one-to-one
(2) one-to-many
(3) many-to-many.
You indicate these relationships by adding declarations to your models: has_one, has_many, belongs_to, and has_and_belongs_to_many.

There is a tool called 'Gvedit' (graphviz-2.20.2.exe) (http://www.graphviz.org/) which generates Directed and Undirected graphs. It accepts a dot file in specific format and it generates directed graphs free of cost ! :-) Why not use this tool ?

We can use the reflections for findling all associations of a Model.
http://api.rubyonrails.com/classes/ActiveRecord/Reflection/ClassMethods.html

Here is the utility which can be run from the rails application root and generates simple text file with the represention that the dot file requires for creating graphs. It looks for all the model classes under app/models directory.



It generates a simple text file as below :-

digraph model_relationship {
Asset -> DbFile [label=belongs_to]
Asset -> Thumbnail [label=has_many]
Category -> Child [label=has_many]
Category -> Content [label=has_and_belongs_to_many]
Category -> Parent [label=belongs_to]
Content -> Category [label=has_and_belongs_to_many]
Content -> Asset [label=belongs_to]
}


Save this as a .dot file. Open this file in Gvedit and run to generate the graph.

Here is a sample graph generated out of Gvedit :-



We can thus get a picture of all the model relationships in a typical ruby on rails application !

Tool Version Tracker rails application for sourceforge tools

There are many sourceforge open source tools and it is sometimes difficult to track the latest vesions of all tools and keep us updated. We should atleast try to track the latest versions of the open source tools that we daily use in our projects.

So why not develop a very simple rails application which will allow you to add, edit and destroy tool information, the sourceforge url, version information, etc. Let's develop tool version tracker app with CRUD operations and some logic to track the tool versions :-) The logic may not be great but definitely useful for core developers who are always looking for new things/tools/versions ! Find the updated versions of the sourceforge tools and send an email with the updated versions to all team members :-) We can either run this periodically through web application or we can do some modifications to run this as a scheduled cron job :-)

We will use hpricot for parsing html.
Let's take an example of checkstyle. If we go to this link :- http://sourceforge.net/project/showfiles.php?group_id=29721

We will find the version information as :-


So in our code we will just compare the release number by parsing the html with hpricot and find out any change in version of the tool.

Here is the code in html_parser.rb under lib :-



In the environment.rb file, add the following line :-

SOURCEFORGE_URL = "http://sourceforge.net/project/showfiles.php?group_id="

For each tool, we have a unique group id.

The migration for Tool model is as below :-



You can view all the tools on index as below :-


You can find the updated version of individual tool or all tools by clicking on the links. So after clicking on the Update versions of all tools, you will get :-



And an email is also sent with the latest information (Simple Rails ActionMailer):-




You can edit/add the tool information from your application as :-


So how do you find it ? It is simple and easy to develop through Rails and definitely useful for all the Automated Tool Lovers :-)
It certainly solves our purpose :-)