A couple of weeks ago, while I was talking to my colleague Gourav in his team room, a book lying on his desk caught my eye. The front cover image of a crumpled paper and the title of the book - REWORK - sounded interesting to me. I asked my friend whether I could borrow that book for some days from him and as expected, he happily agreed :-)
Thanks Gourav for this beautiful book !
The book has been written by Jason Fried and David Hansson, the founders of 37signals. (the authors say the book is a by-product :-)
You can read through any chapter of this book and you will feel like - yes, this is how it should be ... The authors speak the truth as it emerges from their practical and sound business experience. As the book review says, you do not need to be a workaholic, you do not need to staff up, you do not need to waste time on paperwork or meetings, etc. ... Those are all just excuses. What you really need to do is stop talking and start working.
The authors touch various aspects in running a successful business such as productivity, progress, competitors, promotion, hiring, damage control, culture, etc. They conclude the book with a chapter - 'Inspiration is perishable.' I am tempted to share some part of this chapter as I liked it the most.
"We all have ideas. Ideas are immortal. They last forever.
What doesn't last forever is inspiration. Inspiration is like fresh fruit or milk. It has an expiration date.
If you want to do something, you've got to do it now. You can't put it on a shelf and wait two months to get around to it. You can't just say you'll do it later. Later, you won't be pumped up about it anymore.
Inspiration is a magical thing, a productivity multiplier, a motivator. But it won't wait for you. Inspiration is a now thing. If it grabs you, grab it right back and put it to work."
Hmm ... worth reading this book my friends !
Ohh ... have you already started googling around this book name ? ... That's what I anticipate from whoever has not read this book before :-)
Enjoy reading ...
Wednesday, December 22, 2010
Tuesday, December 21, 2010
My first Android app with Rhodes
Few days back, I attended a free online course on 'Develop Mobile apps on Android phones with Rhodes'. The course was made available on RubyLearning.org by Ruby mentor and evangelist Satish Talim. Though it was a very basic course, I got a good hands on the Rhodes framework. Good learning for me ! :-)
I am not going to list down the steps for building this sample app as these are very well explained in the online course by Satish Talim. Similar steps are also available at Rhohub and Rhodes sites under documentation. So I would request everyone who is interested to learn Rhodes to attend this course. It is definitely a good beginning.
The app that I created was a simple Contact app where you can enter Contact's name, email, phone and country and can perform CRUD operations on the Contact model. I pushed my app to Rhohub via Git. This is snapshot of my app on Android emulator :-
Looks good and simple ! Isn't it? Planning to try some advance things with Rhodes now!
I am not going to list down the steps for building this sample app as these are very well explained in the online course by Satish Talim. Similar steps are also available at Rhohub and Rhodes sites under documentation. So I would request everyone who is interested to learn Rhodes to attend this course. It is definitely a good beginning.
The app that I created was a simple Contact app where you can enter Contact's name, email, phone and country and can perform CRUD operations on the Contact model. I pushed my app to Rhohub via Git. This is snapshot of my app on Android emulator :-
Looks good and simple ! Isn't it? Planning to try some advance things with Rhodes now!
Tuesday, December 7, 2010
The Secret book by Rhonda Byrne
Another good book that I read few days ago! Thanks to my friend Swati Desai for gifting me this wonderful book which talks about spreading only positive thoughts and energy into the Universe. The book reminded me of the famous Alchemist quote :- "When a person really desires something, all the universe conspires to help that person to realize his dream."
As the book says, the negative thought gets only multiplied in your mind. It is true. When you have a negative thought about a person or his behavior, you will notice it really gets multiplied. You tend to think more negative things about the person which never existed before in your mind about that person. It is of no use to your state of mind and also to the person who you are thinking about. You start to attract your dominant thoughts. You spoil your own life.
Instead why not try to inculcate positive thoughts into our mind? The thoughts full of positive energy, positive attitude and positive beliefs ! As the book says, happy and positive feelings will attract more happy and positive circumstances. It costs zero money from your pocket.
Hmm... it's time to act on it now!
This is the official website of The Secret :- http://www.thesecret.tv/
I have signed up for the the Secret Scrolls on this site. Have you ?
Enjoy reading ...
As the book says, the negative thought gets only multiplied in your mind. It is true. When you have a negative thought about a person or his behavior, you will notice it really gets multiplied. You tend to think more negative things about the person which never existed before in your mind about that person. It is of no use to your state of mind and also to the person who you are thinking about. You start to attract your dominant thoughts. You spoil your own life.
Instead why not try to inculcate positive thoughts into our mind? The thoughts full of positive energy, positive attitude and positive beliefs ! As the book says, happy and positive feelings will attract more happy and positive circumstances. It costs zero money from your pocket.
Hmm... it's time to act on it now!
This is the official website of The Secret :- http://www.thesecret.tv/
I have signed up for the the Secret Scrolls on this site. Have you ?
Enjoy reading ...
Wednesday, December 1, 2010
The Passionate Programmer by Chad Fowler
At the outset I would like to thank my colleague Amit Kumar who gave me 'The Passionate Programmer' book to read. When he handed over the book to me, he said - "Do not only read, but try to implement as well !" That's really true Amit.
While I was going through the chapters, I found that there are many small things that we can begin to implement to make a remarkable career in software development as the book title says. I liked the way Chad has correlated his musical experience with the software development career smoothly. You really enjoy and learn a lot while reading this book. It is a sort of introspection for yourself.
Please also read :-
http://pragdave.blogs.pragprog.com/pragdave/2009/05/the-passionate-programmer.html
I plan to implement some concepts/thoughts from this great book ! :-)
Enjoy reading !
While I was going through the chapters, I found that there are many small things that we can begin to implement to make a remarkable career in software development as the book title says. I liked the way Chad has correlated his musical experience with the software development career smoothly. You really enjoy and learn a lot while reading this book. It is a sort of introspection for yourself.
Please also read :-
http://pragdave.blogs.pragprog.com/pragdave/2009/05/the-passionate-programmer.html
I plan to implement some concepts/thoughts from this great book ! :-)
Enjoy reading !
Monday, November 29, 2010
jQuery UI Multiselect
There was one requirement of selecting multiple values for an attribute in my project and I was searching for some fancy but simple to use multiselect UI widget which will allow the user to select/drag drop multiple values from the panel of available items to the panel of selected items.
I found jQuery UI Multiselect and was able to use that in my project within a very short time. It is really easy to use and provides some good features like :-
- Search within available options
- Displaying count of selected and available items
- Select All / Deselect All links
- Dragging items from the available list to the selected list directly
You can configure the multiselect widget with options like sortable, searchable, dividerLocation for the panel width division, etc.
I personally liked the look and feel and the functionality of this ui widget !
I found jQuery UI Multiselect and was able to use that in my project within a very short time. It is really easy to use and provides some good features like :-
- Search within available options
- Displaying count of selected and available items
- Select All / Deselect All links
- Dragging items from the available list to the selected list directly
You can configure the multiselect widget with options like sortable, searchable, dividerLocation for the panel width division, etc.
I personally liked the look and feel and the functionality of this ui widget !
Wednesday, November 3, 2010
The Oscar Wilde Collection
Here is a link to the collection of Oscar Wilde's stories, poems and plays.
http://www.oscarwildecollection.com/
'The Picture of Dorian Gray' is the best I think.
Enjoy reading !
http://www.oscarwildecollection.com/
'The Picture of Dorian Gray' is the best I think.
Enjoy reading !
Saturday, October 23, 2010
Who will cry when you die by Robin Sharma
I recently read 'Who will cry when you die?' book written by Robin Sharma - the author of the best seller 'The Monk who sold his Ferrari'. The book is a collection of 101 life lessons explained in a very short but succinct manner. Even if we practice only some of these lessons in our day to day life, it will certainly enrich the quality of our personal and professional life. Listing some of the lessons that I liked the most:-
- Start Your Day Well
- Talk to Yourself
- Remember, Genius Is 99 Percent Inspiration
- Get Up Early
- Laugh More
- Spend a Day Without Your Watch
- Take More Risks
- Live a Life
- Always Carry a Book with You
- Enjoy the Path, Not Just the Reward
- Get Good at Asking
- Connect with Nature
- Use Your Commute Time
- Get Serious About Setting Goals
- Walk in the Woods
- Listen to Music Daily
- Learn to Meditate
- Stop Complaining and Start Living
- See Your Day as Your Life
- Be Humble
- Don’t Finish Every Book You Start
- Sleep Less
- Learn How to Walk
- Plant a Tree
- Be an Adventurer
- Respect Your Instincts
- Love Your Work
Enjoy reading !
- Start Your Day Well
- Talk to Yourself
- Remember, Genius Is 99 Percent Inspiration
- Get Up Early
- Laugh More
- Spend a Day Without Your Watch
- Take More Risks
- Live a Life
- Always Carry a Book with You
- Enjoy the Path, Not Just the Reward
- Get Good at Asking
- Connect with Nature
- Use Your Commute Time
- Get Serious About Setting Goals
- Walk in the Woods
- Listen to Music Daily
- Learn to Meditate
- Stop Complaining and Start Living
- See Your Day as Your Life
- Be Humble
- Don’t Finish Every Book You Start
- Sleep Less
- Learn How to Walk
- Plant a Tree
- Be an Adventurer
- Respect Your Instincts
- Love Your Work
Enjoy reading !
Tuesday, October 19, 2010
The right perspective
I must thank my friend Sudhir Bangera for sending this very nice story to begin with my day of work. It's actually a food of thought for all ... Sharing the same.
Two brothers grew up in an orphanage. The warden of the institution was a pesky fellow, who would often say terrible things to the children.
Years passed. The little boys grew up to become fine young men, and in time got married and had families of their own.
The elder brother grew up to become bad tempered and gave his family lot of grief. The younger brother, however, turned out to be a good parent and husband. He was successful both in his professional and personal life. People who knew them would express surprise over how the two brothers were so different from each other, in spite of facing the same circumstances while growing up.
The elder brother would say, “The warden, whom we all looked upon as almost a father, set us a bad example. I had no one to guide me, so I couldn’t help but turn out the way he was. It’s not my fault, I have become like him because of my circumstances.”
And, the younger brother would say, “The warden never taught me good values or behavior. But growing up, I made a promise to myself, to hold him as an example of what not to be and to make sure that I don’t to do the things he did.”
How many times have we blamed our failures over bad circumstances or rotten luck? True success and happiness comes from making the best out of a bad situation and looking at things with the right perspective. Look at the brighter side of situations ...
Have a thoughtful day ahead ! :-)
Two brothers grew up in an orphanage. The warden of the institution was a pesky fellow, who would often say terrible things to the children.
Years passed. The little boys grew up to become fine young men, and in time got married and had families of their own.
The elder brother grew up to become bad tempered and gave his family lot of grief. The younger brother, however, turned out to be a good parent and husband. He was successful both in his professional and personal life. People who knew them would express surprise over how the two brothers were so different from each other, in spite of facing the same circumstances while growing up.
The elder brother would say, “The warden, whom we all looked upon as almost a father, set us a bad example. I had no one to guide me, so I couldn’t help but turn out the way he was. It’s not my fault, I have become like him because of my circumstances.”
And, the younger brother would say, “The warden never taught me good values or behavior. But growing up, I made a promise to myself, to hold him as an example of what not to be and to make sure that I don’t to do the things he did.”
How many times have we blamed our failures over bad circumstances or rotten luck? True success and happiness comes from making the best out of a bad situation and looking at things with the right perspective. Look at the brighter side of situations ...
Have a thoughtful day ahead ! :-)
Sunday, October 17, 2010
Panoramic view of Naigara falls
Saturday, October 16, 2010
Mount Washington photos
On October 2, 2010, my wife and I visited Mount Washington (New Hampshire) along with my friends. Mt. Washington is the highest peak in the Northeastern United States. (6288 ft). It was a wonderful experience that can not be expressed in the words. I have tried to capture the nature's beauty in my camera! Sharing some photos...
Friday, October 15, 2010
We do not have enough time to improve ?
I was reading a book - 'Who will cry when you die?' by Robin Sharma and came across a very nice and thought provoking quote by him :-
"Saying that you don't have time to improve your thoughts and your life is like saying you don't have time to stop for gas because you are too busy driving. Eventually it will catch up with you."
I am sure reading this quote must have started a thought cycle in your mind !
"Saying that you don't have time to improve your thoughts and your life is like saying you don't have time to stop for gas because you are too busy driving. Eventually it will catch up with you."
I am sure reading this quote must have started a thought cycle in your mind !
Monday, October 11, 2010
Analyze your app performance with newrelic_rpm
I used newrelic_rpm(2.13.1) (http://www.newrelic.com/) - Ruby performance management system in my rails application to find out the performance bottlenecks and it helped me a lot.
First, it took me only 2 minutes to set up newrelic into my application. Second, the detailed level of information that it provided helped me to debug at granular level starting from sql query execution time to individual template load time. I also liked the Pie chart representation of the analysis.
Here are the installation steps :-
http://support.newrelic.com/faqs/docs/ruby-agent-installation
Readme doc :-
http://github.com/newrelic/rpm/blob/master/README.rdoc
First, it took me only 2 minutes to set up newrelic into my application. Second, the detailed level of information that it provided helped me to debug at granular level starting from sql query execution time to individual template load time. I also liked the Pie chart representation of the analysis.
Here are the installation steps :-
http://support.newrelic.com/faqs/docs/ruby-agent-installation
Readme doc :-
http://github.com/newrelic/rpm/blob/master/README.rdoc
Thursday, September 30, 2010
Moving rails app from 2.3.5 to 2.3.9
In my last post, at the end, I mentioned about migrating my rails app from version 2.3.5 to 2.3.9 for making it more closer to rails 3.0. I worked on the same and it went well. I localized rack-1.1.0 version as rails 2.3.9 has this dependency. Most of the steps that I followed were similar to my earlier post except the change in version number.
Listing the deprecation warnings that need to be fixed that I received during the migration :-
(1) DEPRECATION WARNING: Giving :session_key to SessionStore is deprecated, please
use :key instead. (called from new at app_root/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:72)
Change :session_key to :key in environment.rb file :-
config.action_controller.session = {
:key => '_radar_session',
:secret => '271c2f352da72.....'
}
(2) DEPRECATION WARNING: config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead
Change in the environment.rb file :-
From config.load_paths to config.autoload_paths
(3) DEPRECATION WARNING: Date#last_month is deprecated and has been removed in Rails 3, please use Date#prev_month instead. (called from ./spec/models/my_model_name_spec.rb:10)
(4) DEPRECATION WARNING: Time#last_month is deprecated and has been removed in Rails 3, please use Time#prev_month instead. (called from ./spec/models/my_model_name_spec.rb:41)
Here are the actual changes in rails 2.3.9 :-
app_root\vendor\rails\activesupport\lib\active_support\core_ext\date\calculations.rb
(5) DEPRECATION WARNING: Rake tasks in vendor/plugins/xss_terminate/tasks are deprecated. Use lib/tasks instead. (called from app_root/vendor/rails/railties/lib/tasks/rails.rb:10)
Move the tasks folder inside the lib folder of the plugin directory and the deprecation warning should go away. But you may need to change some require file paths according to new placement of tasks folder.
(6) DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from helper at app_root/vendor/gems/rspec-rails-1.3.0/lib/spec/rails/example/helper_example_group.rb:59)
I googled around for this deprecation warning and found some useful articles. Sharing one of those articles :-
Upgrading to Rails 3: Beware of the Object#tap pattern
http://feeds.simonecarletti.com/simonecarletti/en
I also tried with rspec-rails-1.3.2 gem, but it also threw same deprecation warning. So I just opened the corresponding class and extended the implementation as :-
From
@helper_object ||= returning HelperObject.new do |helper_object|
To
@helper_object ||= HelperObject.new.tap do |helper_object|
I made similar change for app_root\vendor\gems\rspec-rails-1.3.0\lib\spec\rails\mocks.rb :-
From
returning model_class.new do |model|
To
model_class.new.tap do |model|
Now, I am much closer to moving my app to Rails 3.0 version :-)
Listing the deprecation warnings that need to be fixed that I received during the migration :-
(1) DEPRECATION WARNING: Giving :session_key to SessionStore is deprecated, please
use :key instead. (called from new at app_root/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:72)
Change :session_key to :key in environment.rb file :-
config.action_controller.session = {
:key => '_radar_session',
:secret => '271c2f352da72.....'
}
(2) DEPRECATION WARNING: config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead
Change in the environment.rb file :-
From config.load_paths to config.autoload_paths
(3) DEPRECATION WARNING: Date#last_month is deprecated and has been removed in Rails 3, please use Date#prev_month instead. (called from ./spec/models/my_model_name_spec.rb:10)
(4) DEPRECATION WARNING: Time#last_month is deprecated and has been removed in Rails 3, please use Time#prev_month instead. (called from ./spec/models/my_model_name_spec.rb:41)
Here are the actual changes in rails 2.3.9 :-
app_root\vendor\rails\activesupport\lib\active_support\core_ext\date\calculations.rb
(5) DEPRECATION WARNING: Rake tasks in vendor/plugins/xss_terminate/tasks are deprecated. Use lib/tasks instead. (called from app_root/vendor/rails/railties/lib/tasks/rails.rb:10)
Move the tasks folder inside the lib folder of the plugin directory and the deprecation warning should go away. But you may need to change some require file paths according to new placement of tasks folder.
(6) DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from helper at app_root/vendor/gems/rspec-rails-1.3.0/lib/spec/rails/example/helper_example_group.rb:59)
I googled around for this deprecation warning and found some useful articles. Sharing one of those articles :-
Upgrading to Rails 3: Beware of the Object#tap pattern
http://feeds.simonecarletti.com/simonecarletti/en
I also tried with rspec-rails-1.3.2 gem, but it also threw same deprecation warning. So I just opened the corresponding class and extended the implementation as :-
From
@helper_object ||= returning HelperObject.new do |helper_object|
To
@helper_object ||= HelperObject.new.tap do |helper_object|
I made similar change for app_root\vendor\gems\rspec-rails-1.3.0\lib\spec\rails\mocks.rb :-
From
returning model_class.new do |model|
To
model_class.new.tap do |model|
Now, I am much closer to moving my app to Rails 3.0 version :-)
Tuesday, September 28, 2010
Migrating rails app from 2.2.2 to 2.3.5
I recently migrated my rails app from rails version 2.2.2 to 2.3.5. I enjoyed the work as it was a good learning for me. Listing the steps that I followed and some issues that I faced during the migration.
Gems installed on my windows machine :-
mongrel (1.1.5 x86-mingw32)
rake (0.8.7)
rack (1.0.1)
rubygems-update (1.3.7)
(1) I installed rails :-
gem install rails -v=2.3.5
(2) Deleted rails folder (2.2.2) from app/vendor.
environment.rb file -
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
Go to the project root and execute :-
rake rails:update --trace
It will update some js files and also renames application.rb to application_controller.rb
** Invoke rails:update (first_time)
** Invoke rails:update:scripts (first_time)
** Execute rails:update:scripts
** Invoke rails:update:javascripts (first_time)
** Execute rails:update:javascripts
** Invoke rails:update:configs (first_time)
** Execute rails:update:configs
** Invoke rails:update:application_controller (first_time)
** Execute rails:update:application_controller
app_root/app/controllers/application.rb has been renamed to app_root/app/controllers/application_controller.rb, update your SCM as necessary
** Execute rails:update
(3) Rename application_spec.rb to application_controller_spec.rb
(4) Localize rails version into the app.
rake rails:freeze:gems
(5) I was having rspec(1.2.3) and rspec-rails(1.2.3) plugins which I removed and installed rspec(1.3.0) and rspec-rails(1.3.0) gems instead and then localized in the app/vendor.
gem install rspec -v 1.3.0
gem install rspec-rails -v 1.3.0
environment.rb file :-
config.gem "rack", :version => "1.0.1"
config.gem "rspec-rails", :lib => false, :version => ">= 1.3.0"
config.gem "rspec", :lib => false, :version => ">= 1.3.0"
Go to the project root and execute :-
rake gems:unpack
(6) I kept a copy of my customized spec/spec_helper.rb file because I wanted to run "ruby script/generate rspec" for upgrading rspec-rails in the app which overwrites these three files :-
* spec/spec.opts
* spec/rcov.opts
* spec/spec_helper.rb
(7) While running the specs, I got flash.now[:message] specs failing.
I added following in the spec/spec_helper.rb file to fix the issue with that spec.
module DisableFlashSweeping
def sweep
end
end
module EnableFlashSweeping
def sweep
keys.each do |k|
unless @used[k]
use(k)
else
delete(k)
@used.delete(k)
end
end
# clean up after keys that could have been left over by calling reject! or shift on the flash
(@used.keys - keys).each{ |k| @used.delete(k) }
end
end
And I used the calls in the spec before the action as :-
it 'should retain the flash message only for the current request' do
controller.instance_eval { flash.extend(DisableFlashSweeping) }
post :create, :work_loc => {:country => "India", :state => "Maharashtra"}
response.should be_success
flash[:message].should == "Error in Loc mapping!"
end
(8) I changed in rspec from
response.should render_template(:states) '
TO
controller.should_receive(:render).with(:partial => 'states')
(9) Changed response.headers["Status"] to response.status in some of the controller specs.
(10) I got one deprecation warning about formatted_url :-
DEPRECATION WARNING: formatted_action_name_controller_name_url() has been deprecated. Please pass format to the standard action_name_controller_name_url method instead..
So changed :action from
:action => formatted_action_name_controller_name_url('js')
to
:action => action_name_controller_name_url(:format => 'js')
Now, along with the rspecs, my app is looking good with rails 2.3.5
Planning to go ahead with migrating to 2.3.9 to make the app more closer to Rails 3.0.
Gems installed on my windows machine :-
mongrel (1.1.5 x86-mingw32)
rake (0.8.7)
rack (1.0.1)
rubygems-update (1.3.7)
(1) I installed rails :-
gem install rails -v=2.3.5
(2) Deleted rails folder (2.2.2) from app/vendor.
environment.rb file -
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
Go to the project root and execute :-
rake rails:update --trace
It will update some js files and also renames application.rb to application_controller.rb
** Invoke rails:update (first_time)
** Invoke rails:update:scripts (first_time)
** Execute rails:update:scripts
** Invoke rails:update:javascripts (first_time)
** Execute rails:update:javascripts
** Invoke rails:update:configs (first_time)
** Execute rails:update:configs
** Invoke rails:update:application_controller (first_time)
** Execute rails:update:application_controller
app_root/app/controllers/application.rb has been renamed to app_root/app/controllers/application_controller.rb, update your SCM as necessary
** Execute rails:update
(3) Rename application_spec.rb to application_controller_spec.rb
(4) Localize rails version into the app.
rake rails:freeze:gems
(5) I was having rspec(1.2.3) and rspec-rails(1.2.3) plugins which I removed and installed rspec(1.3.0) and rspec-rails(1.3.0) gems instead and then localized in the app/vendor.
gem install rspec -v 1.3.0
gem install rspec-rails -v 1.3.0
environment.rb file :-
config.gem "rack", :version => "1.0.1"
config.gem "rspec-rails", :lib => false, :version => ">= 1.3.0"
config.gem "rspec", :lib => false, :version => ">= 1.3.0"
Go to the project root and execute :-
rake gems:unpack
(6) I kept a copy of my customized spec/spec_helper.rb file because I wanted to run "ruby script/generate rspec" for upgrading rspec-rails in the app which overwrites these three files :-
* spec/spec.opts
* spec/rcov.opts
* spec/spec_helper.rb
(7) While running the specs, I got flash.now[:message] specs failing.
I added following in the spec/spec_helper.rb file to fix the issue with that spec.
module DisableFlashSweeping
def sweep
end
end
module EnableFlashSweeping
def sweep
keys.each do |k|
unless @used[k]
use(k)
else
delete(k)
@used.delete(k)
end
end
# clean up after keys that could have been left over by calling reject! or shift on the flash
(@used.keys - keys).each{ |k| @used.delete(k) }
end
end
And I used the calls in the spec before the action as :-
it 'should retain the flash message only for the current request' do
controller.instance_eval { flash.extend(DisableFlashSweeping) }
post :create, :work_loc => {:country => "India", :state => "Maharashtra"}
response.should be_success
flash[:message].should == "Error in Loc mapping!"
end
(8) I changed in rspec from
response.should render_template(:states) '
TO
controller.should_receive(:render).with(:partial => 'states')
(9) Changed response.headers["Status"] to response.status in some of the controller specs.
(10) I got one deprecation warning about formatted_url :-
DEPRECATION WARNING: formatted_action_name_controller_name_url() has been deprecated. Please pass format to the standard action_name_controller_name_url method instead..
So changed :action from
:action => formatted_action_name_controller_name_url('js')
to
:action => action_name_controller_name_url(:format => 'js')
Now, along with the rspecs, my app is looking good with rails 2.3.5
Planning to go ahead with migrating to 2.3.9 to make the app more closer to Rails 3.0.
Tuesday, September 21, 2010
The Last Lecture by Randy Pausch
Today I received an email from my uncle about The Last Lecture by Randy Pausch. I was wondering why I did not get this email from anyone else before as it seems a quite old email. It's ok ! The important thing is I got a chance to read Randy's simple but succinct view points about life. I can not resist myself to share those with all.
----
On September 18, 2007, Carnegie Mellon professor and alumnus Randy Pausch delivered a one-of-a-kind last lecture that made the world stop and pay attention. It became an Internet sensation viewed by millions, an international media story, and a best-selling book "The Last Lecture" that has been published in 35 languages. To this day, people everywhere continue to talk about Randy, share his message and put his life lessons into action in their own lives.
In a letter to his wife Jai and his children, Dylan, Logan , and Chloe, he wrote this beautiful "guide to a better life" for his wife and children to follow. May you be blessed by his insight.
POINTS ON HOW TO IMPROVE YOUR LIFE
Personality:
1. Don't compare your life to others'. You have no idea what their journey is all about.
2. Don't have negative thoughts of things you cannot control. Instead invest your energy in the positive present moment
3. Don't over do; keep your limits
4. Don't take yourself so seriously; no one else does
5. Don't waste your precious energy on gossip
6. Dream more while you are awake
7. Envy is a waste of time. You already have all you need..
8. Forget issues of the past. Don't remind your partner of his/her mistakes of the past. That will ruin your present happiness.
9. Life is too short to waste time hating anyone. Don't hate others.
10. Make peace with your past so it won't spoil the present
11. No one is in charge of your happiness except you
12. Realize that life is a school and you are here to learn.
Problems are simply part of the curriculum that appear and fade away like algebra class but the lessons you learn will last a lifetime.
13. Smile and laugh more
14. You don't have to win every argument. Agree to disagree.
Community:
15. Call your family often
16. Each day give something good to others
17. Forgive everyone for everything
18. Spend time with people over the age of 70 & under the age of 6
19. Try to make at least three people smile each day
20. What other people think of you is none of your business
21. Your job will not take care of you when you are sick. Your family and friends will. Stay in touch.
Life:
22. Put GOD first in anything and everything that you think, say and do.
23. GOD heals everything
24. Do the right things
25. However good or bad a situation is, it will change
26. No matter how you feel, get up, dress up and show up
27. The best is yet to come
28. Get rid of anything that isn't useful, beautiful or joyful
29. When you’re awake alive in the morning, thank GOD for it
30. If you know GOD you will always be happy. So, be happy.
Here is the video link as well :-
http://video.google.com/videoplay?docid=-5700431505846055184#
----
On September 18, 2007, Carnegie Mellon professor and alumnus Randy Pausch delivered a one-of-a-kind last lecture that made the world stop and pay attention. It became an Internet sensation viewed by millions, an international media story, and a best-selling book "The Last Lecture" that has been published in 35 languages. To this day, people everywhere continue to talk about Randy, share his message and put his life lessons into action in their own lives.
In a letter to his wife Jai and his children, Dylan, Logan , and Chloe, he wrote this beautiful "guide to a better life" for his wife and children to follow. May you be blessed by his insight.
POINTS ON HOW TO IMPROVE YOUR LIFE
Personality:
1. Don't compare your life to others'. You have no idea what their journey is all about.
2. Don't have negative thoughts of things you cannot control. Instead invest your energy in the positive present moment
3. Don't over do; keep your limits
4. Don't take yourself so seriously; no one else does
5. Don't waste your precious energy on gossip
6. Dream more while you are awake
7. Envy is a waste of time. You already have all you need..
8. Forget issues of the past. Don't remind your partner of his/her mistakes of the past. That will ruin your present happiness.
9. Life is too short to waste time hating anyone. Don't hate others.
10. Make peace with your past so it won't spoil the present
11. No one is in charge of your happiness except you
12. Realize that life is a school and you are here to learn.
Problems are simply part of the curriculum that appear and fade away like algebra class but the lessons you learn will last a lifetime.
13. Smile and laugh more
14. You don't have to win every argument. Agree to disagree.
Community:
15. Call your family often
16. Each day give something good to others
17. Forgive everyone for everything
18. Spend time with people over the age of 70 & under the age of 6
19. Try to make at least three people smile each day
20. What other people think of you is none of your business
21. Your job will not take care of you when you are sick. Your family and friends will. Stay in touch.
Life:
22. Put GOD first in anything and everything that you think, say and do.
23. GOD heals everything
24. Do the right things
25. However good or bad a situation is, it will change
26. No matter how you feel, get up, dress up and show up
27. The best is yet to come
28. Get rid of anything that isn't useful, beautiful or joyful
29. When you’re awake alive in the morning, thank GOD for it
30. If you know GOD you will always be happy. So, be happy.
Here is the video link as well :-
http://video.google.com/videoplay?docid=-5700431505846055184#
Sunday, August 1, 2010
Beautiful nature snaps...
Thursday, July 22, 2010
Hasgat - A book by Dilip Prabhawalkar
Yesterday, my father gave a marathi book - 'Hasgat' to me. It is written by a well known and my favorite marathi actor Dilip Prabhawalkar. I could not resist myself to read his book. The book made my travel to office and back to home journey jovial.
The book is a collection of short stories which can be enjoyed any time. The common thread that binds these stories is the element of situational humour and the naive characters in each of these, reminiscent of the P.G. Wodehousian style, which has admittedly been one of Prabhawalkar's literary influences.
Dilip Prabhawalkar has done a great work in theatre, cinema, television and as a writer as well. Please take a look at his website :- http://dilipprabhavalkar.com/v1/indexHtml.htm
I have watched his drama - 'Hasvaphasvi' at least 8 to 10 times. You can see the pictures of six different character roles that he played in that drama at : http://dilipprabhavalkar.com/v1/hasvaphasvi.htm
Isn't it awesome ? :-)
Enjoy reading ...
The book is a collection of short stories which can be enjoyed any time. The common thread that binds these stories is the element of situational humour and the naive characters in each of these, reminiscent of the P.G. Wodehousian style, which has admittedly been one of Prabhawalkar's literary influences.
Dilip Prabhawalkar has done a great work in theatre, cinema, television and as a writer as well. Please take a look at his website :- http://dilipprabhavalkar.com/v1/indexHtml.htm
I have watched his drama - 'Hasvaphasvi' at least 8 to 10 times. You can see the pictures of six different character roles that he played in that drama at : http://dilipprabhavalkar.com/v1/hasvaphasvi.htm
Isn't it awesome ? :-)
Enjoy reading ...
Tuesday, July 6, 2010
Augmented Array in Ruby
Few days ago, I was randomly going through the Ruby Array class API and the method '*' caught my attention.
array * int -> an_array : Returns a new array built by concatenating the int copies of self.
[ 1, 2, 3 ] * 3 #=> [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
I just had a thought can I have a method named '/' which will return a new array by splitting the array into arrays of int divisor elements each ?
The functionality that I was looking for :-
[1,2,3,4,5,6]/1 # => [[1], [2], [3], [4], [5], [6]]
[1,2,3,4,5,6]/2 # => [[1, 2], [3, 4], [5, 6]]
[1,2,3,4,5,6]/3 # => [[1, 2, 3], [4, 5, 6]]
I gave it a try, my fingers typed the code as per my brain's instructions and it worked the way I expected.
Then I saw the methods at(index) and fetch(index) and thought can I fetch or even set the elements of the array with the index as if index acting as array's attributes ?
Like this :-
ary = [1,2,3]
ary._0 = 25
ary._0 # => 25
ary._1 = 10
ary._1 # => 10
ary # => [25, 10,3]
For the above to work, I played with the method_missing method.
Few things that I noticed in the Array class were it has 'first' and 'last' methods but not 'first=' and 'last=' methods. It has 'nitems' method which returns the number of non-nil elements, but no 'nilitems' method which will return nil elements in the array.
My mind started to think whether I can build some other useful methods as well and it came to a sufficiently big list which I finally moved into a gem. I named the gem as 'augmented_array' and pushed it to gemcutter.
Install:
====
gem install augmented_array
Uninstall:
====
gem uninstall augmented_array
Source Code is available at my Github repository.
array * int -> an_array : Returns a new array built by concatenating the int copies of self.
[ 1, 2, 3 ] * 3 #=> [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
I just had a thought can I have a method named '/' which will return a new array by splitting the array into arrays of int divisor elements each ?
The functionality that I was looking for :-
[1,2,3,4,5,6]/1 # => [[1], [2], [3], [4], [5], [6]]
[1,2,3,4,5,6]/2 # => [[1, 2], [3, 4], [5, 6]]
[1,2,3,4,5,6]/3 # => [[1, 2, 3], [4, 5, 6]]
I gave it a try, my fingers typed the code as per my brain's instructions and it worked the way I expected.
Then I saw the methods at(index) and fetch(index) and thought can I fetch or even set the elements of the array with the index as if index acting as array's attributes ?
Like this :-
ary = [1,2,3]
ary._0 = 25
ary._0 # => 25
ary._1 = 10
ary._1 # => 10
ary # => [25, 10,3]
For the above to work, I played with the method_missing method.
Few things that I noticed in the Array class were it has 'first' and 'last' methods but not 'first=' and 'last=' methods. It has 'nitems' method which returns the number of non-nil elements, but no 'nilitems' method which will return nil elements in the array.
My mind started to think whether I can build some other useful methods as well and it came to a sufficiently big list which I finally moved into a gem. I named the gem as 'augmented_array' and pushed it to gemcutter.
Install:
====
gem install augmented_array
Uninstall:
====
gem uninstall augmented_array
Source Code is available at my Github repository.
Thursday, July 1, 2010
The One Minute Manager
Yesterday I read a management book - 'The One Minute Manager' written by Ken Blanchard and Spencer Johnson. I liked that book very much. It's practical. It includes some examples demonstrating how you can effectively handle the people under you. By the book definition, effective managers manage themselves and the people they work with so that both the organization and the people profit from their presence.
The metaphor, The One Minute Manager means it takes very little time for that manager to get big results from people and behind this success lie just three secrets :-
- One minute goals
- One minute praisings
- One minute reprimands
One should read this little book to know more about these secrets.
It is really good to know that the leaders of American and Japanese industry have made this book compulsory reading for all their managers.
Enjoy reading ...
The metaphor, The One Minute Manager means it takes very little time for that manager to get big results from people and behind this success lie just three secrets :-
- One minute goals
- One minute praisings
- One minute reprimands
One should read this little book to know more about these secrets.
It is really good to know that the leaders of American and Japanese industry have made this book compulsory reading for all their managers.
Enjoy reading ...
Thursday, June 24, 2010
Some good food of thoughts
I started my day today with reading my colleague's beautiful post what mindfood are we eating and it really made me think.
This is such a wonderful thought... what do we feed our mind with ? How many of us make conscious efforts to nurture our mind ? Hmm ... need to prepare healthy diet plan for our minds as well :-)
Sharing some good food of thoughts that I got from googling :-
1. Success is not the key to happiness. But happiness is the key to success.
2. You can tell whether a man is intelligent by his answers. But you can tell a man is wise by his questions.
3. Morning means one more inning given by the god to play.
4. Success is not a matter of being the best and winning the race, it is a matter of handling the worst and finishing the race. Be positive.
5. A honey bee visits 2 million flowers to collect 500 mg of honey. So our workload is nothing as compared to them. Be cheerful and keep working.
6. It is not that some people have will power and some do not. It is that some people are ready to change and others are not. Believe in yourself and change for betterment.
7. The world suffers a lot, not because of the violence of bad people, but because of the silence of good people.
This is such a wonderful thought... what do we feed our mind with ? How many of us make conscious efforts to nurture our mind ? Hmm ... need to prepare healthy diet plan for our minds as well :-)
Sharing some good food of thoughts that I got from googling :-
1. Success is not the key to happiness. But happiness is the key to success.
2. You can tell whether a man is intelligent by his answers. But you can tell a man is wise by his questions.
3. Morning means one more inning given by the god to play.
4. Success is not a matter of being the best and winning the race, it is a matter of handling the worst and finishing the race. Be positive.
5. A honey bee visits 2 million flowers to collect 500 mg of honey. So our workload is nothing as compared to them. Be cheerful and keep working.
6. It is not that some people have will power and some do not. It is that some people are ready to change and others are not. Believe in yourself and change for betterment.
7. The world suffers a lot, not because of the violence of bad people, but because of the silence of good people.
Wednesday, June 23, 2010
Tips for Managers
I have worked with a couple of good companies. The managerial behavioral pattern that I have observed across these companies remains more or less the same. Yes... there are certainly few exceptions. I have many friends across different organizations, but to be frank, I have rarely seen people talking good about their managers. Why is this so ? Are the managers lacking the skills to effectively handle the people under them ? Or some other reason ? There is no straightforward answer to these questions, but can we improve this better ? I am not at manager level yet, but certainly I can suggest few tips which would improve this situation.
Tips for Managers :-
1. Consider people under you as people rather than only billable resources.
2. Do not let people under you to lose trust in you. It is very difficult to build back the trust again.
3. Give more importance to career progression of the people under you than billing.
4. Have faith in your people.
5. You do not have any right to play with or spoil the career of the people under you. Freshers are the best example of this. They are rarely asked about their career aspiration, rather they are asked to do things what the current situation demands.
6. Do not take people under you for granted.
7. Interact with your people regularly about their aspirations and make loyal efforts to fulfill those.
8. A little smile on your face makes a huge difference in the professional and personal lives of the people under you. The most important thing here is that it's absolutely free of cost.
9. Try to be a role model of the people under you.
10. Billing/Revenue is important. But people are more important as they sustain business with the client by their good work.
11. Micromanagement kills.
12. Try to be a thought leader than just to be a manager.
13. Do not lose your core values while dealing with the client.
Tips for Managers :-
1. Consider people under you as people rather than only billable resources.
2. Do not let people under you to lose trust in you. It is very difficult to build back the trust again.
3. Give more importance to career progression of the people under you than billing.
4. Have faith in your people.
5. You do not have any right to play with or spoil the career of the people under you. Freshers are the best example of this. They are rarely asked about their career aspiration, rather they are asked to do things what the current situation demands.
6. Do not take people under you for granted.
7. Interact with your people regularly about their aspirations and make loyal efforts to fulfill those.
8. A little smile on your face makes a huge difference in the professional and personal lives of the people under you. The most important thing here is that it's absolutely free of cost.
9. Try to be a role model of the people under you.
10. Billing/Revenue is important. But people are more important as they sustain business with the client by their good work.
11. Micromanagement kills.
12. Try to be a thought leader than just to be a manager.
13. Do not lose your core values while dealing with the client.
Friday, June 18, 2010
Welcome Monsoon !
The monsoon has started in Mumbai - Maharashtra with full force and one of my friends forwarded some great nature pictures especially from Konkan region to me. I can not resist myself to share some of those beautiful photos with you all.
Marleshwar waterfall near Sangameshwar in Ratnagiri district:
Jog waterfall:
A typical home in Konkan:
River bank:
Happy monsoon ! :-)
It's real time to go for a trek / nature trail !
Marleshwar waterfall near Sangameshwar in Ratnagiri district:
Jog waterfall:
A typical home in Konkan:
River bank:
Happy monsoon ! :-)
It's real time to go for a trek / nature trail !
Monday, June 7, 2010
hash_key_as_attribute gem published
Following my earlier post, I pushed hash_key_as_attribute gem to rubygems.org
Install
====
gem install hash_key_as_attribute
OR
Download the gem file from http://github.com/NiranjanSarade/hash_key_as_attribute/
gem install hash_key_as_attribute-0.0.1.gem
Install
====
gem install hash_key_as_attribute
OR
Download the gem file from http://github.com/NiranjanSarade/hash_key_as_attribute/
gem install hash_key_as_attribute-0.0.1.gem
Thursday, June 3, 2010
Allowing hash values to be set and retrieved as if they were attributes
In ruby, we have OpenStruct which allows the creation of data objects with arbitrary attributes. With ruby's metaprogramming capability, we can also allow hash values to be set and retrieved as if they were its attributes. If the key does not correspond to any hash entry, it should return “The key does not correspond to any hash entry” message. The hook that we are going to use is Kernel's method_missing.
Here we are opening the class Hash :-
And this is the sample output :-
h = Hash.new("The key does not correspond to any hash entry")
h.one = 1
puts h.one #=> 1
h.two= [1,2,3,4]
puts h.two.inspect #=> [1,2,3,4]
puts h.three #=> "The key does not correspond to any hash entry"
puts h.inspect #=> {:one=>1, :two=>[1, 2, 3, 4]}
h2 = {}
h2.four = 4
h.three = h2
puts h.three.inspect #=> {:four=>4}
puts h.three.four #=> 4
Here we are opening the class Hash :-
And this is the sample output :-
h = Hash.new("The key does not correspond to any hash entry")
h.one = 1
puts h.one #=> 1
h.two= [1,2,3,4]
puts h.two.inspect #=> [1,2,3,4]
puts h.three #=> "The key does not correspond to any hash entry"
puts h.inspect #=> {:one=>1, :two=>[1, 2, 3, 4]}
h2 = {}
h2.four = 4
h.three = h2
puts h.three.inspect #=> {:four=>4}
puts h.three.four #=> 4
Wednesday, June 2, 2010
Instance and class variable get set methods
In ruby, instance variables have prefix '@' and class variables have prefix '@@'.
We have instance_variable_get and instance_variable_set methods from Object class and class_variable_get and class_variable_set methods from Module class in Ruby. Here is the typical usage of these methods from the ruby docs :-
----
class Fred
@@foo = 99
end
def Fred.foo
class_variable_get(:@@foo) #=> 99
end
----
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_get(:@a) #=> "cat"
fred.instance_variable_get("@b") #=> 99
----
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_set(:@a, 'dog') #=> "dog"
fred.instance_variable_set(:@c, 'cat') #=> "cat"
fred.inspect #=> #Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\"
----
However, why do we need to specify the @ and @@ when the method names are smart enough to distinguish between whether the variable is an instance or a class variable. Why does a call to instance_variable_set require the "@" symbol in the first argument? Any idea ? Or has it been done with some purpose ?
We have instance_variable_get and instance_variable_set methods from Object class and class_variable_get and class_variable_set methods from Module class in Ruby. Here is the typical usage of these methods from the ruby docs :-
----
class Fred
@@foo = 99
end
def Fred.foo
class_variable_get(:@@foo) #=> 99
end
----
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_get(:@a) #=> "cat"
fred.instance_variable_get("@b") #=> 99
----
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_set(:@a, 'dog') #=> "dog"
fred.instance_variable_set(:@c, 'cat') #=> "cat"
fred.inspect #=> #Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\"
----
However, why do we need to specify the @ and @@ when the method names are smart enough to distinguish between whether the variable is an instance or a class variable. Why does a call to instance_variable_set require the "@" symbol in the first argument? Any idea ? Or has it been done with some purpose ?
Friday, May 21, 2010
Do you want to touch real Tigers ?
Last week my wife and I visited Thailand. In the tour, we got a chance to visit Tiger Temple near Bangkok. Yes ... the thrill was patting real tigers. Tiger Temple, or Wat Pha Luang Ta Bua, is a Buddhist temple in Western Thailand where tourists can actually touch/pat the tigers in open area. It was a great experience in watching the real tigers staying with men and how the people take care of them. The tigers are handled by Thai monks, volunteers and the local staff.
Sharing few photos ...
Sharing few photos ...
Thursday, April 22, 2010
Ruby metaprogramming
This is an excellent video about ruby metaprogramming concept:-
http://www.infoq.com/presentations/metaprogramming-ruby
This was presented by Dave Thomas, a well known author of The Pragmatic Programmer book.
http://www.infoq.com/presentations/metaprogramming-ruby
This was presented by Dave Thomas, a well known author of The Pragmatic Programmer book.
Tuesday, April 20, 2010
Passing hash from javascript
I was working on one functionality where I needed to build hash like structure in javascript and make an ajax call to perform that particular action by passing that hash as params to process further. The functionality was to delete a numbered row from the form and after deletion the form should rearrange the rows in sequence while maintaining the order. I used javascript 2 dimensional array to treat it as hash.
e.g. On the form :-
No. | EmpID | Date | Location | Action |
1. | 123 |12-Mar-10 | Mumbai |Delete |
2. | 233 |10-Jan-10 | Mumbai |Delete |
3. | 444 |15-Mar-10 | Mumbai |Delete |
4. | 555 |18-Mar-10 | Mumbai |Delete |
So. If you delete the 3rd row, then after deletion the new form should render as :-
No. | EmpID | Date | Location | Action |
1. | 123 |12-Mar-10 | Mumbai |Delete |
2. | 233 |10-Jan-10 | Mumbai |Delete |
3. | 555 |18-Mar-10 | Mumbai |Delete |
The elements were written in table format. Each row is assigned unique id, so first row will have id = 1, 2nd row with id = 2 and so on. Each td has unique class.
<%=row_id%>
<%= text_field_tag "emp_#{row_id}", "", :id => emp_#{row_id}" %>
<%=text_field_tag "dt_#{row_id}", "", :id => "dt_#{row_id}" %>
<%= text_field_tag "loc_#{row_id}", "", :id => "loc_#{row_id}", %>
<%=link_to(image_tag("delete_img.jpg", :alt => "Delete Row", :id => "del_#{row_id}"),"#")%>
This is the jquery code :-
jQuery(document).ready(function() {
jQuery('#del_<%=i%>').click(function() {
var row_to_be_deleted = jQuery(this).parent().parent().parent();
var row_id = parseInt(row_to_be_deleted.attr("id"));
var data_ary = [];
jQuery('#emp_table tbody > tr').each(function() {
if (jQuery(this).attr("id") != row_id) {
var myArray = [];
var empid_val = "";
var dt_val = "";
var loc_val = "";
jQuery(this).find("td").each(function(){
if (jQuery(this).attr("class")== "empid"){
empid_val = jQuery(this).find("input").val();
myArray.push(empid_val);
}
if (jQuery(this).attr("class")== "dt"){
dt_val = jQuery(this).find("input").val();
myArray.push(dt_val);
}
if (jQuery(this).attr("class")== "loc"){
loc_val = jQuery(this).find("input").val();
myArray.push(loc_val);
}
});
data_ary.push(myArray);
}
});
ajax_call_for_remove_row( data_ary, '<%= remove_row_controllername_url%>');
});
});
----
function ajax_call_for_remove_row(data_ary, remove_row_url) {
var inputs = new Object;
inputs["data_ary"] = data_ary;
jQuery.ajax({
url: remove_row_url,
data: inputs,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("We are sorry something went wrong, please try again");
},
success: function(data){
},
type: "post"
});
}
----
The corresponding controller actions :-
def remove_row
@data = []
logger.debug(params['data_ary'].inspect)
build_data_from_hash(params['data_ary'])
logger.debug(@data.inspect)
end
private
def build_data_from_hash data_hash
if data_hash
data_ary = sort_hash_to_array data_hash
data_ary.each { |value|
@data << {"Empid" => value[1][0], "Date" => value[1][1], "Location" => value[1][2] }
}
else
@data << {"Empid" => "", "Date" => "", "Location" => "" }
end
end
def sort_hash_to_array data_hash
data_hash.sort { |a,b| a[0].to_i <=> b[0].to_i }
end
----
params['data_ary'].inspect =>
====================================
{"0"=>["123", "12-Mar-10", "Mumbai"], "1"=>["233", "10-Jan-10", "Mumbai"], "2"=>["555", "18-Mar-10", "Mumbai"]}
====================================
@data.inspect =>
====================================
[["0", ["123", "12-Mar-10", "Mumbai"]], ["1", ["233", "10-Jan-10", "Mumbai"]], ["2", ["555", "18-Mar-10", "Mumbai"]] ]
====================================
We can pass this @data as local while rendering the table body partial in corresponding js.erb template. This works great for me!
e.g. On the form :-
No. | EmpID | Date | Location | Action |
1. | 123 |12-Mar-10 | Mumbai |Delete |
2. | 233 |10-Jan-10 | Mumbai |Delete |
3. | 444 |15-Mar-10 | Mumbai |Delete |
4. | 555 |18-Mar-10 | Mumbai |Delete |
So. If you delete the 3rd row, then after deletion the new form should render as :-
No. | EmpID | Date | Location | Action |
1. | 123 |12-Mar-10 | Mumbai |Delete |
2. | 233 |10-Jan-10 | Mumbai |Delete |
3. | 555 |18-Mar-10 | Mumbai |Delete |
The elements were written in table format. Each row is assigned unique id, so first row will have id = 1, 2nd row with id = 2 and so on. Each td has unique class.
This is the jquery code :-
jQuery(document).ready(function() {
jQuery('#del_<%=i%>').click(function() {
var row_to_be_deleted = jQuery(this).parent().parent().parent();
var row_id = parseInt(row_to_be_deleted.attr("id"));
var data_ary = [];
jQuery('#emp_table tbody > tr').each(function() {
if (jQuery(this).attr("id") != row_id) {
var myArray = [];
var empid_val = "";
var dt_val = "";
var loc_val = "";
jQuery(this).find("td").each(function(){
if (jQuery(this).attr("class")== "empid"){
empid_val = jQuery(this).find("input").val();
myArray.push(empid_val);
}
if (jQuery(this).attr("class")== "dt"){
dt_val = jQuery(this).find("input").val();
myArray.push(dt_val);
}
if (jQuery(this).attr("class")== "loc"){
loc_val = jQuery(this).find("input").val();
myArray.push(loc_val);
}
});
data_ary.push(myArray);
}
});
ajax_call_for_remove_row( data_ary, '<%= remove_row_controllername_url%>');
});
});
----
function ajax_call_for_remove_row(data_ary, remove_row_url) {
var inputs = new Object;
inputs["data_ary"] = data_ary;
jQuery.ajax({
url: remove_row_url,
data: inputs,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("We are sorry something went wrong, please try again");
},
success: function(data){
},
type: "post"
});
}
----
The corresponding controller actions :-
def remove_row
@data = []
logger.debug(params['data_ary'].inspect)
build_data_from_hash(params['data_ary'])
logger.debug(@data.inspect)
end
private
def build_data_from_hash data_hash
if data_hash
data_ary = sort_hash_to_array data_hash
data_ary.each { |value|
@data << {"Empid" => value[1][0], "Date" => value[1][1], "Location" => value[1][2] }
}
else
@data << {"Empid" => "", "Date" => "", "Location" => "" }
end
end
def sort_hash_to_array data_hash
data_hash.sort { |a,b| a[0].to_i <=> b[0].to_i }
end
----
params['data_ary'].inspect =>
====================================
{"0"=>["123", "12-Mar-10", "Mumbai"], "1"=>["233", "10-Jan-10", "Mumbai"], "2"=>["555", "18-Mar-10", "Mumbai"]}
====================================
@data.inspect =>
====================================
[["0", ["123", "12-Mar-10", "Mumbai"]], ["1", ["233", "10-Jan-10", "Mumbai"]], ["2", ["555", "18-Mar-10", "Mumbai"]] ]
====================================
We can pass this @data as local while rendering the table body partial in corresponding js.erb template. This works great for me!
Tuesday, April 13, 2010
RubyConf 2010 - Bangalore, India
In the last month, I got an opportunity to attend the very first Ruby conference held in Bangalore, India(20-21 March) organized by ThoughtWorks. The response was very huge (around 400 people ranging from beginners to CEOs from more than 100 companies) and people really enjoyed the event.
It was really great to hear some good speakers/industry leaders like Matz, Obie Fernandez, Ola Bini, etc. Many technical topics were presented like future of Ruby, Rails 3.0, Glassfish and WebRoar app servers, building cross platform mobile application with Rhodes framework, etc. You can find more details about these topics at http://rubyconfindia.org/
I felt a lot of enthusiasm and energy amongst the people w.r.t. Ruby and Rails. There are many small companies being set up especially in Pune and Bangalore for doing only rails projects. I really liked that !
Indian market is really catching up on Rails very fast !
It was really great to hear some good speakers/industry leaders like Matz, Obie Fernandez, Ola Bini, etc. Many technical topics were presented like future of Ruby, Rails 3.0, Glassfish and WebRoar app servers, building cross platform mobile application with Rhodes framework, etc. You can find more details about these topics at http://rubyconfindia.org/
I felt a lot of enthusiasm and energy amongst the people w.r.t. Ruby and Rails. There are many small companies being set up especially in Pune and Bangalore for doing only rails projects. I really liked that !
Indian market is really catching up on Rails very fast !
Rendering partial with jquery
Below is the way by which you can render partial with jQuery in your view.js.erb file :-
jQuery("#mydiv").html("<%= escape_javascript(render(:partial => 'my_partial', :locals => {:my_instance_var => @my_instance_var} ))%>");
jQuery("#mydiv").html("<%= escape_javascript(render(:partial => 'my_partial', :locals => {:my_instance_var => @my_instance_var} ))%>");
Friday, March 19, 2010
A mechanic and a surgeon
A mechanic was removing a cylinder head from the motor of a Harley motorcycle when he spotted a well-known heart surgeon in his shop. The surgeon was there, waiting for the service manager to come and take a look at his bike. The mechanic shouted across the garage, "Hey, Doc, can I ask you a question?"
The surgeon a bit surprised, walked over to the mechanic working on the motorcycle. The mechanic straightened up, wiped his hands on a rag and asked, "So Doc, look at this engine. I open its heart, take valves out, fix 'em, put 'em back in, and when I finish, it works just like new. So how come I get such a small salary and you get the really big bucks, when you and I are doing basically the same work?"
The surgeon paused, smiled and leaned over, and whispered to the mechanic...
"Try doing it with the engine running."
The surgeon a bit surprised, walked over to the mechanic working on the motorcycle. The mechanic straightened up, wiped his hands on a rag and asked, "So Doc, look at this engine. I open its heart, take valves out, fix 'em, put 'em back in, and when I finish, it works just like new. So how come I get such a small salary and you get the really big bucks, when you and I are doing basically the same work?"
The surgeon paused, smiled and leaned over, and whispered to the mechanic...
"Try doing it with the engine running."
Friday, February 12, 2010
WebROaR - Ruby Application Server
I got a chance to visit http://webroar.in/ and it seems interesting.
http://webroar.in/blog/2009/11/25/introducing-webroar-v0-2-3-ruby-application-server
WebROaR is an application server that makes deployments of ruby web applications extremely simple. It provides an integrated solution to view the run time performance numbers and email notifications in case any exceptions occur in any of the deployed applications. It is 5 to 55% faster than all other comparable deployment stacks for RoR apps.
Comparison :-
http://webroar.in/blog/2009/11/25/comparison-of-rails-deployment-stacks-2
Some screenshots :-
http://webroar.in/screenshots
Source :-
http://github.com/webroar/webroar/
http://webroar.in/blog/2009/11/25/introducing-webroar-v0-2-3-ruby-application-server
WebROaR is an application server that makes deployments of ruby web applications extremely simple. It provides an integrated solution to view the run time performance numbers and email notifications in case any exceptions occur in any of the deployed applications. It is 5 to 55% faster than all other comparable deployment stacks for RoR apps.
Comparison :-
http://webroar.in/blog/2009/11/25/comparison-of-rails-deployment-stacks-2
Some screenshots :-
http://webroar.in/screenshots
Source :-
http://github.com/webroar/webroar/
Wednesday, February 10, 2010
Scientific explanation of Bhagwad Geeta
I recently read a very good book written by Dr. P.V.Vartak - "Geeta - Vidnyananishtha Nirupan" (Scientific explanation)
As we know, Geeta is a conversation between Lord Krishna and Arjuna which took place on the battlefield of Kurukshetra just prior to the start of Mahabharata war. Responding to Arjuna's confusion and moral dilemma, Krishna explained to Arjuna his duties as a warrior and real path of truth and elaborated on a number of different Yogic and Vedantic philosophies, with examples and analogies. Geeta is often being described as a concise guide to Hindu philosophy and also as a practical, self-contained guide to live life especially with Karma yog. Karma Yog is a science that frees us from the bonds of actions and attachment with the attributes. According to the Bhagawad Geeta, it consists of mentally renouncing the sense of doership in favour of God while performing all actions.
Dr. Vartak has explained all the 18 chapters (addhyay) of Geeta in a very simple but superior language. Many thanks to him !
He has also pointed out some mistakes that Mahaatma Gandhi (M.K.Gandhi) did which ultimately led to a lot of violence during Indian independence. Mahaatma Gandhi used to daily worship/read Geeta, but unfortunately could not grab the real meaning of non-violence, Karma yog described in Geeta. The Geeta was actually told to Arjuna to take away his confusion and encourage him to perform his duties as a warrior. But Mahaatma Gandhi never understood the crux of Geeta and repeatedly made mistakes in terms of following non-violence, forgiving real enemies at National level and unfortunately the Nation also followed wrong leadership during that time.
I would request everyone to read this book and think in solitude on the thoughts explained in the book ... We have yet a lot to improve ...
As we know, Geeta is a conversation between Lord Krishna and Arjuna which took place on the battlefield of Kurukshetra just prior to the start of Mahabharata war. Responding to Arjuna's confusion and moral dilemma, Krishna explained to Arjuna his duties as a warrior and real path of truth and elaborated on a number of different Yogic and Vedantic philosophies, with examples and analogies. Geeta is often being described as a concise guide to Hindu philosophy and also as a practical, self-contained guide to live life especially with Karma yog. Karma Yog is a science that frees us from the bonds of actions and attachment with the attributes. According to the Bhagawad Geeta, it consists of mentally renouncing the sense of doership in favour of God while performing all actions.
Dr. Vartak has explained all the 18 chapters (addhyay) of Geeta in a very simple but superior language. Many thanks to him !
He has also pointed out some mistakes that Mahaatma Gandhi (M.K.Gandhi) did which ultimately led to a lot of violence during Indian independence. Mahaatma Gandhi used to daily worship/read Geeta, but unfortunately could not grab the real meaning of non-violence, Karma yog described in Geeta. The Geeta was actually told to Arjuna to take away his confusion and encourage him to perform his duties as a warrior. But Mahaatma Gandhi never understood the crux of Geeta and repeatedly made mistakes in terms of following non-violence, forgiving real enemies at National level and unfortunately the Nation also followed wrong leadership during that time.
I would request everyone to read this book and think in solitude on the thoughts explained in the book ... We have yet a lot to improve ...
Saturday, February 6, 2010
A rumour takes wings
A pandit crossing a field felt that there was something in his mouth and spat it out. It turned out to be a heron's feather. He could not understand how it had got into his mouth and it perplexed him a great deal. When he reached home he told his wife about it but asked her not to tell anyone lest somebody put a bad interpretation on it. His wife was even more intrigued by the strange occurrence and felt the need to confide in someone. So she swore her neighbour to secrecy and told her what had happened.
Perhaps it was the way she told it, but her neighbour got the impression that several feathers had come out of the pandit's mouth. She was shocked. However, she assured the woman that such things could happen and advised her not to worry about it.
"Please don't tell anyone," said the pandit's wife.
"My lips are sealed," said the woman. But she was longing to tell someone and when she saw the dhobi's wife going past, called her in and told her the whole story. Only, she made it sound as if a whole heron had come out of the pandit's mouth.
"Never have I heard of such a thing," said the dhobi's wife, her eyes popping with excitement, "and he being a vegetarian and all that, but one can never tell..."
She went away promising not to tell anyone but on the way she met her friend and the whole story sort of tumbled out of her mouth. Perhaps in her excitement she said 'herons' instead of 'heron' or perhaps her friend just imagined she had said herons but when she told her husband the story sometime later, she was emphatic that a whole flock of herons had come out of the pandit's mouth.
And as the story spread "herons" became "herons and other birds" and then "hundreds of birds of all shapes and sizes".
By evening the whole village and several other neighbouring villages had heard the story and people began to arrive in droves at the pandit's house to witness the miraculous happenings there.
The pandit steadfastly denied that any bird had come out of his mouth but nobody would believe him and everybody begged him to demonstrate his wonderful power of producing birds from his mouth.
Finally in exasperation, he asked them all to sit in front of his house and when they had done so ran out of the back and hid in the jungle where he remained several days till the excitement had died down and the people had realised that the news was false...
Perhaps it was the way she told it, but her neighbour got the impression that several feathers had come out of the pandit's mouth. She was shocked. However, she assured the woman that such things could happen and advised her not to worry about it.
"Please don't tell anyone," said the pandit's wife.
"My lips are sealed," said the woman. But she was longing to tell someone and when she saw the dhobi's wife going past, called her in and told her the whole story. Only, she made it sound as if a whole heron had come out of the pandit's mouth.
"Never have I heard of such a thing," said the dhobi's wife, her eyes popping with excitement, "and he being a vegetarian and all that, but one can never tell..."
She went away promising not to tell anyone but on the way she met her friend and the whole story sort of tumbled out of her mouth. Perhaps in her excitement she said 'herons' instead of 'heron' or perhaps her friend just imagined she had said herons but when she told her husband the story sometime later, she was emphatic that a whole flock of herons had come out of the pandit's mouth.
And as the story spread "herons" became "herons and other birds" and then "hundreds of birds of all shapes and sizes".
By evening the whole village and several other neighbouring villages had heard the story and people began to arrive in droves at the pandit's house to witness the miraculous happenings there.
The pandit steadfastly denied that any bird had come out of his mouth but nobody would believe him and everybody begged him to demonstrate his wonderful power of producing birds from his mouth.
Finally in exasperation, he asked them all to sit in front of his house and when they had done so ran out of the back and hid in the jungle where he remained several days till the excitement had died down and the people had realised that the news was false...
Monday, February 1, 2010
email_pop_reader gem pushed to gemcutter
In one of my previous projects, I worked on ruby script to read the emails from mail-in database and process the emails as per the business requirement. In ruby, we have a libray called Net::POP3 which provides functionality for retrieving email via POP3. I went ahead with a thought of converting this to a gem.
The emails retrieved from mail-in database are stored in some sort of data structure to process further. The utility makes use of Net::POP3 and TMail libraries and provides with some handy methods such as 'retrieve emails' as array of hashes. The hash has email's from,to,cc,bcc,subject,body fields. Email body with attachment has not been considered for simplicity.
It also provides 'delete_emails(unique_email_ids=[])' method which takes array of unique email ids (retrieved with pop email unique_id) as parameter and deletes those.
Install :-
gem install email_pop_reader
(It has been pushed to http://gemcutter.org) - http://gemcutter.org/gems/email_pop_reader
OR
Download the gem file from http://github.com/NiranjanSarade/email-pop-reader.git/
gem install email_pop_reader-0.0.1.gem
The emails retrieved from mail-in database are stored in some sort of data structure to process further. The utility makes use of Net::POP3 and TMail libraries and provides with some handy methods such as 'retrieve emails' as array of hashes. The hash has email's from,to,cc,bcc,subject,body fields. Email body with attachment has not been considered for simplicity.
It also provides 'delete_emails(unique_email_ids=[])' method which takes array of unique email ids (retrieved with pop email unique_id) as parameter and deletes those.
Install :-
gem install email_pop_reader
(It has been pushed to http://gemcutter.org) - http://gemcutter.org/gems/email_pop_reader
OR
Download the gem file from http://github.com/NiranjanSarade/email-pop-reader.git/
gem install email_pop_reader-0.0.1.gem
Wednesday, January 20, 2010
Ruby's block_proc_lamda_method
I went through a couple of articles on ruby's blocks, procs, lambda & method and found those really good and interesting. Sharing those articles :
http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
http://www.neeraj.name/blog/articles/589-block-vs-lambda-vs-proc
http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
http://www.neeraj.name/blog/articles/589-block-vs-lambda-vs-proc
Monday, January 18, 2010
Company
Finding that cranes were destroying his newly sown corn, a farmer one evening set a net in his field to catch the destructive birds. When he went to examine the net next morning he found a number of cranes and also a stork.
"Release me, I beseech you," cried the stork, "for I have eaten none of your corn, nor have I done you any harm. I am a poor innocent stork, as you may see - a most dutiful bird, I honor my father and mother, I..."
But the farmer cut him short. "All this may be true enough, I dare say, but I have caught you with those were destroying my crops, and you must suffer with the company in which you are found."
Moral: People are judged by the company they keep.
"Release me, I beseech you," cried the stork, "for I have eaten none of your corn, nor have I done you any harm. I am a poor innocent stork, as you may see - a most dutiful bird, I honor my father and mother, I..."
But the farmer cut him short. "All this may be true enough, I dare say, but I have caught you with those were destroying my crops, and you must suffer with the company in which you are found."
Moral: People are judged by the company they keep.
Saturday, January 16, 2010
The Right Speech
There is a Chinese saying which carries the meaning that "A speech will either prosper or ruin a nation." Many relationships break off because of wrong speech. When a couple is too close with each other,we always forget mutual respect and courtesy. We may say anything without considering if it would hurt the other party.
A friend and her millionaire husband visited their construction site. A worker who wore a helmet saw her and shouted,"Hi, Emily! Remember me? We used to date in the secondary school." On the way home, her millionaire husband teased her, "Luckily you married me.Otherwise you would have been the wife of a construction worker." She answered ,"You should appreciate that you married me. Otherwise, he would have been the millionaire and not you."
A friend and her millionaire husband visited their construction site. A worker who wore a helmet saw her and shouted,"Hi, Emily! Remember me? We used to date in the secondary school." On the way home, her millionaire husband teased her, "Luckily you married me.Otherwise you would have been the wife of a construction worker." She answered ,"You should appreciate that you married me. Otherwise, he would have been the millionaire and not you."
Thursday, January 14, 2010
Model diagram generator plugin
After my one of the last posts Shaping models in Rails, I got a chance to convert that piece of code into a Rails plugin.
It has been rolled out to Github.
Github Repository :- http://github.com/NiranjanSarade/model-diagram-generator
Installation :-
ruby script/plugin install http://github.com/NiranjanSarade/model-diagram-generator.git/
Usage :-
rake model_diagram:generate
It will generate diagramatic representation of the model relationship present in your rails app. The model_relationship.dot and model_relationship.png files will be generated at the application root folder.
It was a nice feeling with contributing something to the open source community !
It has been rolled out to Github.
Github Repository :- http://github.com/NiranjanSarade/model-diagram-generator
Installation :-
ruby script/plugin install http://github.com/NiranjanSarade/model-diagram-generator.git/
Usage :-
rake model_diagram:generate
It will generate diagramatic representation of the model relationship present in your rails app. The model_relationship.dot and model_relationship.png files will be generated at the application root folder.
It was a nice feeling with contributing something to the open source community !
Wednesday, January 13, 2010
Formatting rules of UseModWiki ...
In continuation of my previous post Formatting Rules, you will find this link very useful :- http://www.usemod.com/cgi-bin/wiki.pl?TextFormattingRules
Tuesday, January 5, 2010
Ryan's_Video_Railscasts.to_s
ASCIIcasts are text versions of each Railscast developed by Ryan Bate, each with a link to the original video. So if we want to refer the text version of the railscasts, just refer this link :-
http://asciicasts.com/
http://asciicasts.com/
Monday, January 4, 2010
Ruby/Rails Tool Box
Here is a good link for Ruby/Rails tool box which has collection of many utilities/tools to address different development life cycle concerns like deployment, testing, code metrics, continuous integration, project management and many more ...
http://www.ruby-toolbox.com/
http://www.ruby-toolbox.com/
Subscribe to:
Posts (Atom)