Tuesday, May 30, 2017

Bhujia Barons: The Untold Story of How Haldiram Built a Rs 5000-crore EmpireBhujia Barons: The Untold Story of How Haldiram Built a Rs 5000-crore Empire by Pavitra Kumar
My rating: 3 of 5 stars

Does a good job at describing the start of the Haldiram Empire. The struggle of Haldiram is insightful. But then the book looses its way and becomes a commentary on the legal fights between the various branches of Haldiram family. Dis-coherent at times, the book started of well and ended up in a heap of mess.

View all my reviews

Monday, July 9, 2012

Tip: traversing arrays in C-Shell

Below I have described two methods to traverse arrays in C-Shell - one uses the foreach loop and other while loop.
In both cases, the important thing to note is that array index in C-shell starts with '1' instead of '0' as in most programming languages, like C, C++, Java, Perl.


set a = (1 2 3 4)
set b = (5 6 7 8)
 

Method 1 - using the foreach loop, iterating on one array as the foreach index, and the accessing the other array inside the loop body using the index operator "[]"
set i = 1
foreach x ( `echo $a` )
  echo "x = $x b = $b[$i]"
  @ i = $i + 1
end
 

Output: 
x = 1 b = 5
x = 2 b = 6
x = 3 b = 7
x = 4 b = 8

Method 2 - using the while loop. Iterating on the size of array and accessing both the arrays inside the loop body using the index operator "[]"


set i = 1
while ($i <= 4)
  echo "a = $a[$i] b = $b[$i]"
  @ i = $i + 1
end
 

Output:
a = 1 b = 5
a = 2 b = 6
a = 3 b = 7
a = 4 b = 8




Wednesday, February 15, 2012

gdb stops at SIGPIPE



By default, gdb captures SIGPIPE of a process and pauses it. However, some program ignores SIGPIPE. So, the default behavour of gdb is not desired when debugging those program. To avoid gdb stopping in SIGPIPE, use the folloing command in gdb:

handle SIGPIPE nostop noprint pass

Wednesday, November 2, 2011

Parenting

Interesting insight on this blog entry in Freakonimics - http://freakonomics.blogs.nytimes.com/2010/07/07/the-paradox-of-parenting/
The crux is that parent's don't seem to enjoy parenting is a strange conclusion made by almost all studies in this field. I am not sure I fully subscribe to this theory as I oscillate between happiness and despair when parenting. Maybe its more despair than happiness, but one thing I am sure about it is that happiness definitely has a longer lasting effect than despair.

Accomplishment is important

Not losing focus is the key. It’s about switching your focus from quantity to quality, and making sure that you use your productivity for a greater good: reaching your goals. Wonderful insights at http://workawesome.com/productivity/being-productive/

Tips for remembering and organizing ideas

Use a pocket recorder and record the thoughts. Musicians do it all the time.

Saturday, September 10, 2011

Crux for HBase

new reporting application for BigData based on HBase - Crux

Who are you?

someone who follows rules and also believes in the them is Ram. Some who follows rules but does not believe them is Duryodhana.
one who believes in rules but breaks them is Krishna, one who neither believes in rules nor follows them is Ravan. Who are you?

Monday, February 14, 2011

gdb: script

Recently I discovered the easy way of debugging in gdb - GDB scripting. Often while debugging I got stuck wondering what the value of an item in a complex data structure was. Till a few days ago, I used to modify the code to add debug messages and then recompile and then rerun. This wasted a lot of time.
Then one day after having wasted a lot of time, in recompile and rerun, I decided to use GDB scripts (which I had known since long, but had never used). And it is really fun now. I save a lot of time in debugging.
A sample script that I used to count the number of elements in a linked list (which we use a lot in our code) is below:

define cntList
set $l = $arg0
set $i = 0
if ($l == 0)
printf "NULL list found\n"
else
set $n = $l
while ($n != 0)
set $i = $i+1
set $n = $n->next
end
end
printf "list size %d\n", $i
end
document cntList
count the number of elements in the list
Usage: cntList ptr
end

Tuesday, December 14, 2010

Nube Technologies in news

Sonal's company Nube Technologies (earlier known as Meghsoft) found mention in this post about companies and start ups working in Cloud Computing from Jeff Hammerbacher.
Way to go Sonal!!

Monday, July 26, 2010

Unable to move windows in KDE

Many times I have faced a problem where I am not able to move or resize windows in a KDE session. So must have you and wondered how to fix it.

Now there is help available to fix this issue:
kwin -replace

will replace the window manager and voila you can now resize and/or move the windows in KDE

Wednesday, July 14, 2010

using sed in alias in C shell

Using sed commands in your .alias file in C shell is always tricky. One example of the same is:

alias grf 'set fileNline = `echo "\!*" | sed -e "s/\([^ ]*\):\([0-9]*\):.*/+\2 \1/"`;gvim $fileNline'

This alias is called as:

grf file:line_num:

and then it open the file "file" in gvim with cursor at line "line_num".

Friday, July 9, 2010

Accomplishment is important

Not losing focus is the key. It’s about switching your focus from quantity to quality, and making sure that you use your productivity for a greater good: reaching your goals. Wonderful insights at http://workawesome.com/productivity/being-productive/

in reference to: iGoogle (view on Google Sidewiki)

Thursday, July 8, 2010

Parenting

Interesting insight on this blog entry in Freakonimics - http://freakonomics.blogs.nytimes.com/2010/07/07/the-paradox-of-parenting/
The crux is that parent's don't seem to enjoy parenting is a strange conclusion made by almost all studies in this field. I am not sure I fully subscribe to this theory as I oscillate between happiness and despair when parenting. Maybe its more despair than happiness, but one thing I am sure about it is that happiness definitely has a longer lasting effect than despair.

in reference to: iGoogle (view on Google Sidewiki)

Tuesday, May 18, 2010

How organizations are scared of talent

Recently got the following mail which uses a story from Hindu mythology to analyze corporate behavior.

Rishi Ashtavakra was called Ashtavakra because his body was deformed and twisted in eight areas. He was cursed by his own father, Kahoda. While he was in his mother's womb, he had overheard his father converse with his mother on the nature of Vedic truths as expressed in various Vedic hymns.
Even before he was born, he had understood the secrets of Vedic hymns so well that one day, from his mother's womb, he spoke and corrected his father. "Perhaps," he said, "the same hymn can be interpreted in this way, father." Rather than being appreciative of his son, the father was annoyed. "May this over-smart child of mine be born deformed with eight twists in his body," said the father.

Kahoda went to the court of king Janaka to participate in a public debate. The condition of the debate was that the loser had to die. Kahoda, who thought greatly of his wisdom, participated in the competition but he lost the debate to a sage called Bandi and was forced to kill himself. When Ashtavakra grew up and learnt about the
fate of his father, he decided to participate in the same public debate in Janaka's court.
He won the competition and Bandi was forced to bring Ashtavakra's father back to life. Thus Ashtavakra not only avenged his father's humiliation, he also brought his father back to life. Janaka commented that Kahoda was lucky to have a son as brilliant as Ashtavakra. To this Ashtavakra said, "While you, Janaka, appreciate my wisdom, that very same wisdom had made my father insecure."

This ancient story draws attention to the envy of the father for his son, or the envy of a teacher for his student. Kahoda is the boss, the coach, the mentor, who nurtures talent under him. Ashtavakra represents that unusually bright student one sometimes gets to coach or mentor. It takes a lot of self-assurance for a mentor to admit that the student is better than him. By the law of averages, such brilliant students are few and far between and when they make themselves known they usually face great hostility from those around them and especially the mentor. Few mentors like Janak can handle a student who is better than them.

The best minds come to his court and thrive. In a world of corporations, when a junior can overtake his senior, coaches and mentors are often threatened by team members. The result is an organization which is full of many more Kahodas than Janakas, to the detriment of Ashtavakra. Organizations have to constantly ensure that leaders are more like Janakas and less like Kahoda because the future fate of the organization depends on the brilliance of Ashtavakras

Saturday, January 16, 2010

Fuel subsidy in India

Read an interesting comment from the Minister of State for Oil & Gas Mr. Jitin Prasada in today's Economic Times (Delhi -
"Those who can afford it should pay the full fuel price"
Noble thought. Difficult or maybe impossible to implement across the country. But how about implementing it for just the Government (including State Govts) and its organizations. The Govt organizations raises tenders for fuel supply for its vehicles and whosoever is the lowest bidder, gets the contract for fuel supply. So the total requirement is always known. Instead of paying the bidder by the prevailing (subsidized) market rate, why not pay the bidder by the unsubsidized market rate.
Lets see if it makes sense or not.
This news article says that the first three quarters of FY 09-10, the petroleum ministry demanded a subsidy of Rs 20,872 crore to take care for the losses of three Oil & Gas PSUs. Extrapolating the annual subsidy could be assumed to be around Rs 28,000 crore.
Govt of India have more than 50 lakh employees assuming an average of 1 car per 10 employees, the Govt will have around 5,00,000 cars. A typical govt official's car will run for around 40,000 kms per year (including transit from office to home and tours). Assuming a mileage of a 6kms (ambassadors won't give more than that). Diesel cost would be
500000 * 6700 * 36 = Rs 12060 Crores.

Difference between actual and subsidized price of diesel varies depending on the global crude price. At the price of $75 the loss for Oil companies on Diesel was around Rs 9/litre.
So if the Govt were to buy the fuel at market rate the loss of Oil companises will be reduced by around Rs 3000 Crores which is more than 10% of the annual loss.

To me this seems a good way to reduce the subsidy bill.

Tuesday, December 15, 2009

Using Outlook's After Sending rules

Found this interesting post to configure Outlook to complete the thread view. By default the thread does not show your mails. So in effect it has a lot of information missing.

Using Outlook's After Sending rules

Friday, May 8, 2009

Improve Microsoft Outlook Performance

I have been facing a big slowdown in performing any actions in MS Outlook - be it reading mails, trying to reply. Then I found that my personal mail folder was around 3.5GB and I have only 512MB of RAM on my laptop (I know its primitive) so most of time Windows was doing paging.
Then I found this brilliant article Improve Microsoft Outlook Performance on how to have more than one personal mail folders. Ever since I created a new data file, using Outlook is much less painful.

Saturday, April 25, 2009

Ways to extract data from a space delimited string

Ways to tokenize a string if you cannot use the space character as a field delimiter in an input where the fields can have spaces:

1. create the input with the delimiter as some other character as the delimiter. The delimiter character should be non-printable. This would reduce its chances of occuring in the input and thus reduce handling of special cases.

2. If the input was generated with space as the delimiter then we have a problem at hand. For such cases there are two approaches and both require the knowledge of the format of the input.

If the format of the input is known then one can use regular expressions to search for the tokens in the string. (Typical scripting languages, like Perl, TCL support regular expressions. C++ user can use the Boost library for regular expression support).

However using regular expressions can be expensive if the number of searches during the program execution are large. So these can be used only when the number of searches are small.

For programs that do such search more often, let us understand the other approach using an example:

// input format:

char* inputStr = "12 abc def 14";
char* firstSpaceChar = strchr(inputStr, ' ');
int firstInt = 0;
int lastInt = 0;
string midStr = "";
if (firstSpaceChar != NULL) {
*firstSpaceChar = '\0';
firstInt = atoi(inputStr);
char* lastSpaceChar = strrchr(firstSpaceChar+1, ' ');
if (lastSpaceChar != NULL) {
lastInt = atoi(lastSpaceChar+1);
*lastSpaceChar = '\0';
}
midStr = firstSpaceChar+1;
} else {
midStr = inputStr;
}



Friday, October 31, 2008

Tech: How to find the existence of a thread

To find if a thread created using pthread_create exists or not use phread_kill with signal number 0
on the thread that needs to be tested. If the return value is 0, then the thread is alive.
If the return value is ESRCH, then the thread is not alive in the system.

Sample code may look like:

bool is_thread_alive(pthread_t thread_id)
{
int status = pthread_kill(thread_id, 0);
if (status == ESRCH)
return true;
else
return false;
}