Sunday, August 1, 2010

Beautiful nature snaps...

Last week, I captured some beautiful nature snaps near Kolhapur, Maharashtra. Sharing few of those 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 ...

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.

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 ...

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.

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.

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 !

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

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

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 ?