Saturday, December 17, 2011

How to see your responses in xml - a shortcut

Once you try viewing your server loaded view files,

Use the Ctrl + U command to get the equivalent view files.

I have currently done this for api related tokamak view file. Tried viewing this in a json and xml format.

Multiple rake gem conflict workaround

The workaround is:

Consider using bundle exec.


mohnish@mohnish-laptop:~/mohnish/home$ bundle exec rake routes | grep profiles



It will make use of the rake gem installed as part of your gem file.

Monday, November 21, 2011

Use a particular rails version along with ur choice of ruby version using rvm

mohnish@mohnish-laptop:~/shop_cart/depot$ rvm gemset create 'rails305'
'rails305' gemset created (/home/mohnish/.rvm/gems/ruby-1.9.2-p180@rails305).
mohnish@mohnish-laptop:~/shop_cart/depot$ rvm 1.9.2-p180@rails305
mohnish@mohnish-laptop:~/shop_cart/depot$ rails -v
getopt: invalid option -- 'v'
Terminating...
mohnish@mohnish-laptop:~/shop_cart/depot$ gem list

*** LOCAL GEMS ***

rake (0.9.2)

To use this particular gemset we need to use the below command now:-

rvm use 1.9.2-p180@rails305

Monday, October 17, 2011

Experiences with Git and Github

To check your current branch

git branch

Adding a new branch name

git branch branch_name


To do a fetch and merge at one go:-

Do a git pull


Committing code with others comitting at the same time:

Scenario 1: others have also modified the same file that you have modified..

git fetch

Caution:

Now before doing a git merge origin/branch_name --> (Keeping in mind you are modifiying a file in the same branch)

Take a backup of your file(s) into another folder/location; wherever there is a conflict

Do a git checkout path(for the file name say app/views/folder_name/file_name)

then do the git merge origin/branch_name

Committing your code on git:-

To commit your code on git you need to use:-

git commit -a -m "Appropriate Message wrt the commit"

here, the -a command mostly implies for all.

To commit only certain files:-

To commit multiple files at one time you need to separate each file with a whitespace.

git commit -m "Appropriate Message" filename(s)

One can also push all code using:-

git push origin branch_name


You can't push your commits when:

When others have made a commit and you haven't updated your code upto the latest commit; it would give an error saying non fast forward updates are not allowed.

To do a (fetch + merge for a specific branch):


Do a git pull origin branch_name

To switch to another branch

git checkout branch_name

Monday, October 10, 2011

Use of before_filter in Rails and the application controller

We make use of before_filter in Rails to call certain methods like user authentication or login; or perform a customized action before we gain access to the controller.

The application controller is used to define common set of methods which would be accessible for use/call by methods belonging to a specific controller.

Tuesday, September 20, 2011

Learn ruby and ruby on rails from scratch

Hi to start off with Ruby on Rails,

You need to firstly learn ruby, a scripting language. Then you can start learning Rails.

You should first ask yourself why should I want to learn Ruby? Will Ruby Fail Me?

Try Googling for various links on why you should learn Ruby or why you should not. Then Decide for yourself.

Few Sample links are below:-



Once you have decided you want to learn Ruby; i.e. if you want to learn Ruby,

Lets start with what is Ruby?


Now to start coding/developing in rails:-

To learn Ruby, one of the really good sites is:

 http://www.rubylearning.org/ (It is by an Indian )

You can find video tutorials to learn Ruby here:-


http://marakana.com/ (you can use this for learning other languages also...:) )

Spend some time getting a hang of the basics, you will have to install the Ruby Software , which you would find here:-


To Kick start with learning Rails

Firstly, why should I learn Rails:-

I would recommend you to google and choose links as they take you.

Few Sample Links:-




some really useful online sites include:-


http://www.tutorialspoint.com/(you can use this for learning other languages also...:) )


Video tutorials:-


Learn Rails on the move:-

http://www.codeschool.com/courses/rails-for-zombies.



Coming to Books:-


For Ruby:
The Ruby Programming Language by Yukhirio Matsumoto aka “Matz”(the creator of Ruby) and David Flanagan is good.
The Ultimage Guide to Ruby Programming by Satish Talim also is a good book for beginners.


For Rails:
Agile Development with Rails by Sam Ruby, Dave Thomas is like a must read

Looking forward to your comments on this blog. Please do let me know your views one the above blog. Kindly add on good suggestions based on your experience of using Ruby & Rails for the benefit of all....:)

Wednesday, August 17, 2011

Chat Application Using Ruby


Implementing a Chat application was never made so easy as it is now. Once done with the Chat application, I realized it was not that difficult to implement it in Ruby. It was just the need of using the right classes and methods with apt timing which gives one the end product Chat Application. You can clone the entire code of the chat application from the github repo link.

The below chat application is implemented using User Datagram Protocol( UDP ). Here we make use of the UDP Socket class in Ruby. UDP allows computers to send individual packets of data to other computers, without the overhead of establishing a persistent connection.

The Chat application given below is based on a Client Server model wherein the client sends a datagram containing a string of text to a specified host and port. The server, which is also running on the same host and listening on that port, receives the text and posts it on the terminal. Multiple clients can connect to the server and post their messages.

Every client is recognized with a unique client port number for every instance of it run on the terminal. Given below is the server script and the client script which have to be run one after the other. Here we have a 1:N relationship, thus for one server script run we can have multiple client scripts running alongside.

Here the server represents the chat room and the clients represents the users who are making use of the chat application for their purpose.

The server side script takes a command line argument which is basically the port number on which you are running the Chat application.

To run the server script, you need to enter the following command in the terminal:

ruby filename.rb 12345
Server side running script:

Client side running script:
The client side script takes two command line arguments which are basically the host name and the port number on which you are running the Chat application.
To run the client script, you need to enter the following command in the terminal: ruby filename.rb hostname 12345

--> Here
- localhost is your hostname
- 12345 stands for the port number


A client exits the chat application and leaves the chat room only on the entry of the string “quit”. When there are no clients, the server will prompt whether or not do you want to close the chat room. One chooses appropriately.

Output:
The output is basically a running chat application . You will the output resembling something similar to a chatroom with respect to the terminal where you run the server side script. Given below is a screen shot of a sample output with three clients running alongside one server.


A day out with an inmate of Anatha Shishu Sevashrama

   
Hello,

This blog is mainly a volunteering activity as part of CSR for the company I am currently a part of.

Experiences are in a way a blessing upon each one of our lives where we get an opportunity to learn anything and even at times even everything!. This is one manifestation of God’s grace upon us.

I just wanted to share the experience of spending a day as part of this activity with an inmate of Anatha Shishu Sevashrama(http://anathashishusevashram.com/), an orphanage. This orphanage has around 40 – 50 children( I am sorry, I am not sure about the exact number of children residing in the ashram), most of them being school going kids, and few of them going to PU(Pre University) colleges.

The main purpose of this day’s activity was to hand pick books for a library that is coming up for the children of the ashram. The book store that we had visited was: Sapna Book House, a very well known book store with a really good variety of books to choose form, having at least two to three outlets located within Bangalore city limits.

This activity was part of an ongoing development (including construction) of a library in the ashram which is completely funded by the company's foundation. Apart from this, the company's foundation is also funding the development (with basic infrastructure facilities in addition to the construction) of a dispensary in this ashram.

This ashram is located in Wilson Garden, Bangalore.

This was a second time I was given an opportunity to do something for this orphanage thanks to Deepak Prabhu Matti, who is a lead volunteer for this noble initiative and senior person in the company I work for.

Every opportunity to do the very little I can as part of this activity has been a unique journey, lighting up a series of thoughts within myself, which I just wanted to share.

This volunteering activity was mainly to select books and educational cd’s which could play a vital role in shaping the future of many children in the ashram, acting as a medium to whatever extent they can to fulfill the aspirations of these young minds. Upon selection, a quotation of these items was finally to be made and forwarded to the concerned officials of the company for their approval. An initial budget of Rs 10,000 and Rs 2000 was allocated to the books and the educational cd’s respectively.

Upon discussing with Deepak on the allocated budget and the feasibility of it being increased, I was glad to get Deepak’s positive response for this. A final budget allocation was made wrt the procurement of books and cd’s together. Deepak was mainly following up with the concerned officials wrt the total amount initially proposed as part of funding the entire project from the very scratch and he had to make sure that if the budget allocated to books and cd’s is increased from what was initially discussed, making appropriate adjustments to still meet the overall limit would be a challenge in itself. I really appreciate Deepak for tackling this really well and approving from his end an increased budget dedicated to books and educational cd’s. It was a note worthy investment into future of the children of this ashram. The final budget had to range anywhere between Rs 12,000 to Rs 20,000. It was my job to keep this in mind and go about selecting the books and educational cd’s from a good book store.

Since most of the ashram inmates where young school going children (boys and girls), the main focus was to procure children’s books. These children are mostly going to government schools/government aided institutions and studying as per the SSLC board(State Board). On looking back into my past, I realize now, how lucky we were and also was thinking that did I actually ever thank my parents and the almighty for giving me the best of education? Better late than never, I felt its time, I should surely do it as the call was coming genuinely from within to express a heartfelt golden word “Thank You” to Mom, Dad and our Dear God.
I am sure by now, one must have realized the importance of choosing the right books for these children, as it would play a vital initial role in giving them a light of hope and the courage to believe in their dreams inspite of their current circumstances.

Before this activity was actually carried out, I had spoken to Deepak, Saraswathy aunty(a dedicated soul who is leading the ashram related activities(she is the care taker of the ashram) and who is unfortunately unable to see( I personally have my hats off to the commitment of aunty and I really feel that I have a lot to learn from the sacrifices that she has made in her life and from the e.g. that she sets forth for most of us ) and I even got a chance to speak to the little ones in the ashram about what kind of books they were actually looking for.
Deepak had mainly stressed upon the importance of books like the Panchatantra series, where each book as part of this series covers a small story in itself with an inspiring moral that accompanies it towards the end. Apart from this Deepak had also mentioned that children would need coloring and drawing books.
Based on what I could gather from aunty who as actually playing a “mother” for the children in the ashram , her focus was on autobiographies/short stories on the life of great people like Mahatma Gandhi, Swami Vivekananda, Albert Einstein etc. apart from coloring and drawing books for children. She also mentioned that she would like the children in the ashram to read up on the great epics which are invaluable assets to the history of Mother India like the Mahabharata and Ramayana. Finally aunty had also mentioned that since most of the children in the ashram are fluent with the Kannada language(the main language of communication used by the people of Karnataka of which Bangalore is the capital), she would like to have even these books as an add on to the collection of books being procured for the library.

Saraswathy Aunty





The children of the ashram who really haven’t been so lucky to see much of the outside world like us and who really wouldn’t have the best of childhood like the ones we had , didn’t have too much idea on what exactly they would want as books for them to read. But still their inputs, I must say were really handy, they were looking for something artistic, books which they could use to draw, not exactly from scratch but using the dotted lines which serve as a guided outline for many real world entities like the elephant, fruits like apple etc. They also mentioned that they wanted books on learning mathematical tables.

This actually reminds me of my childhood days, how lucky we were, we never had to think about what books we wanted, what appropriate books had to be read at what age as we always had our parents with us who get us anything for our happiness, whenever we demand/asked for anything. It also reminds me that if we look down in life , we will realize how much we have been blessed to get such facilities, having merry go rounds, slides, jhulas(swings) and many such small things to play with during our early days. It reminds me that we should always remain grateful to the Almighty and do our bit as God’s instruments in whatever way we can to add a smile, a ray of hope in the lives of the less fortunate.

Based on hints from Deepak, aunty and children, I was able to infer that any book which is small, colorful, attractive with loads of pictures in it would surely get hold of a child’s attention.

Oh by the way, I have to mention this( I am happy that nobody’s questioning me on this.. yet..:) ) my Kannada has been pretty weak in terms of reading and writing and I thus, felt that I would not be the right person when it comes to selecting Kannada books for the children. I thus had requested aunty to kindly send someone along with me who could help in selecting Kannada books for the children residing in the ashram.
For procuring the Kannada books I had initially requested aunty to send her son Chetan( he is a BCA(Bachelor of Computer Applications) graduate! ) who his helping her mother in taking care of the ashram, to accompany me for the visit to the book store. On the day of the visit due to some reason, Chetan couldn’t accompany me to the ashram. Aunty made sure she had someone instead who would in place of Chetan.

Chetan


I had arrived at 2 pm to the ashram on 26/02/11. Deepu an inmate of the ashram had joined me to the bookstore in place of Chetan. He was currently in his 10th standard and his Kannada was anytime better than mine. We left from the ashram for the book store at 2 30pm. I told aunty that by the time we would be back it could be around 5 30 pm. She was leaving the responsibility of Deepu, who was like her own child upon someone like me whom she had hardly known. I understood and respect her mother like feelings for Deepu and keeping the same in mind, I had given her my mobile number before I left. It would have at least made her a little more relaxed and comfortable I thought. She also mentioned that she had known the owner of this books store and on mentioning the name of this ashrama, she said we would surely get a good discount on the total purchase. She bid adieu to both of us smilingly..

On the way to the book store, I was to an extent getting to know Deepu better(although I could make out that he wouldn’t talk too much, knowing that good kids don’t talk to strangers(I had never met him before/known him), so it was pretty much understandable on why would he be doing so) ). I casually had enquired from Deepu on what does he, his friends eventually dream to become. He replied that some of his friends wanted to be doctors, some wanted to serve in the military/police. He wanted to become a Computer Programmer:). I also asked him about whether he knows about the route I was taking or where the book store was located. He said he wasn’t aware of the route, he only knew places close by to Wilson Garden(the area where the ashram was located) like Double road and so on. This again makes many of us actually reflect on how lucky we are that we having seen so much of things around us, we have been to so many places like water parks, different restaurants, to movies to exhibitions and the list just goes on.. ..but they haven’t.. . Their life seems to be only confined currently to their education, their life goals/dreams and their ashram.. We really can pick up something from this huge contrast of their lives to ours..

A responsibility that was on me was to choose books/cd’s based on the various inputs I received and also select some books and cd’s based on my knowledge. Before leaving for this activity, I made a humble silent prayer to God, to bless me to choose wisely and not otherwisely.

It’s very important in life to look at things from somebody else’s perspective, to understand what another person is feeling and what condition he/she is going through. This really is of primary importance in building relationships and also it really helps in strengthening them.

I am always greatful to God for instilling this in me. Keeping this in mind I prayed to the almighty to bless in such a way that when I am going to select books for the children , let me not go there as myself, let me go there as a mother, as if Saraswathy aunty is herself selecting the books for the children. This would give me a different perspective in itself apart from keeping in mind various things that I was aware of wrt what would be perhaps right to choose for these children, as a books.

The bookstore branch that we had visited was located in Gandhinagar area, having a building of their own with three floors. We had no particular floor/section to actually start off with once we reached the bookstore. It really had a lot to offer especially for voracious book readers. Once inside the store, I only carried a paper in which I had jotted down few details/guidelines from what I could gather, using the above discussed criteria to go about selecting the books. We soon gathered momentum and started selecting books based on the guidelines that we could make use of from the sheet of paper.

As we went about selecting books sometimes Deepu used to get some books and show me asking me an opinion on whether this would be one among what we are looking for or not.. sometimes I would go about asking him the same as he would surely know his other friends in the ashram more better than I did. The basic thing that we both had to keep in mind while selecting books was that they should be illustrative, informative and not too bulky as to serve our basic purpose..

The variety that this store had to display was really worth appreciating, I never thought I would be selecting books on General Knowledge, books talking about the Universe, books on India and other such books which one would ideally like to have as a collection to their personal library, but I am happy to have added those so that children would be more aware of things happening around them and would also appreciate the rich cultural heritage of our country. Out of the books that we selected apart from the ones on which we were already given an idea of included a book on Global Warming, books talking about going Green, improving children’s handwriting, writing skills, famous books on increasing vocabulary like Normal Lewis’ Word Power Made Easy, Oxford pocket dictionary, English-Kannada Oxford Dictionary, inspiring riddles, small useful puzzles to sharpen children’s quantitative ability to name a few.

I would like to make a special mention to certain Computer books that we had also added to the list. These books cover basics of Computers including concepts like MS Word, MS Excel, MS Power Point, Paint, Internet, Email. Once the library and dispensary would be set up along with the procurement of these books some time form June onwards when the schools of children start, there is a plan to teach these children through these books the above syllabus and Deepak was asking me to spread the word among friends/colleagues (within the company) that I knew, people who would be interested in taking classes for these children on weekends.

Classes for around one-two hours duration is what is being planned for to help enhance the basic computer skills of these children.

Of the various educational cd’s the ones that we selected included Britannica Encyclopedia 2011( I am really thankful for Deepak to allow me to especially select this), cd’s on communications skills, business etiquette and body language and also movie cd’s on how to learn English through Kannada( with animated cartoons ), English-Kannada talking dictionary. We as part of the corporate world really have the Internet especially our close buddy “Google” coming to our rescue whenever we have to search for something we really don’t have much idea on. These children wouldn’t be having internet facilities on each of the computers like us. If I am not mistaken the entire ashrama has as of now only a single Internet connection. In today’s world realizing the positive influence what the Internet can make in one’s life, the lack of such vital facilities for the children of the ashrama was a matter of concern. As a substitute I thought, an Encyclopedia would at least come to some use when they would try to gather information on something that they could use as part of their school projects, education etc. Thus this was a very important thing that was added to the collection of educational cd’s.
By the time we finished selecting all this and getting the final quotations for the same it was around 7 30 pm. In a five hour span of time Saraswathy aunty had herself called up atleast 3-4 times asking for Deepu and how was he..She especially once called up in order to guide Deepu in selecting the Kannada books. I am sorry, I won’t be able to highlight the important books she had taken as I am unaware of the actual contents, but to name a few: SWATANTRA BHARATHADA VEERARA KATHEGALU, SIR M VISHWESHWARIAH-JEEVANA CHARITRE MALE VASAN etc where few of the books that aunty had asked Deepu to surely add to the list of books for the library.

You would happy to know that although, the owner of this store wasn’t present there at that time but we got a good discount for these books and educational cd’s from the owner’s sons. I am grateful to them also for their contribution to this noble cause.

Before leaving for the ashram since it was a quite a gap from our last meal, we just had some refreshments. I dropped Deepu to the ashram at 8 30pm and bid adieu to aunty and him for the day.
It was an eventful day for me and a day very close to my heart as, as I believe this was my first chance to really contribute in a more meaningful way to support CSR activities of the compant in general and the ongoing development of a library in particular of Anatha Shishu Sevashrama.

I am sure you would be happy to learn that apart from the books and educational cd’s, through the company, two brand new computers are going to be procured for the ashram. Five other computers are going to be procured, courtesy NASSCOM. Various other things that are going to be a part of the library and dispensary include cupboards, book shelves, computer tables and chairs, first aid kits, a wash basin, cots, blankets lighting and other related equipment which would go in as part of basic requirements for a library and a dispensary.

Deepak is really playing the anchor role in following up most of the above requirements. Procuring and forwarding the quotations in appropriate formats for approval to the company. The credit for initiating this Outreach activity goes to Deepak and Ajay with contributions from Santosh also(I am sorry I am not currently fully aware of contributions of others, kindly excuse me if I have missed somebody’s name).
Currently the status wrt the development activities in the ashram are like this:- The construction activities have been completed wrt the library and dispensary, NASSCOM computers have been procured into the ashram and have been setup thanks to help from another volunteer by the name Sridhar C.R..All this, giving way to a new beginning for these children as they enter into a new academic year of their life ..:)

I am once again really grateful to Deepak for this opportunity to do the least I could do from my end.
I know this has been quite a long blog by now, I completely appreciate your patient reading so far.
Before closing in, I would just like to share something that really touched me in a different way. We all have responsibilities/duties towards our families, parents and to those whom we feel we are indebted in some way or the other. Apart from this we do have some responsibility towards the society too. Many of us might think why/how..etc. the list wrt these questions might know no end. It’s just that people like Mahatma Gandhi, Swami Vivekananda etc. in the past had realized this and in the current scenario people like Anna Hazare are setting the same e.g.’s . It just a matter of time when we would eventually realize our role in this and do our part for a religion above all religions..Humanity..:)

I would like to just close with the following beautiful lines that I was fortunate enough to read. They go like this:-
“There is a happiness above happiness. It belongs to him who, forgetting himself, gives happiness to others.”

On reflecting on this, I just thought.. that the impact of these lines on one’s life is beyond words.. it’s just something you need to really experience to realize its true worth..:)
Thank you….