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.
Thursday, June 24, 2010
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 !
Subscribe to:
Posts (Atom)
