tag:blogger.com,1999:blog-76776929504994008312024-03-05T12:52:52.681+05:30Musings on life, work and other thingsLife's like a road that you travel on,
Sometimes you bend and sometimes you stand,
Sometimes you turn your head to the windRuchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.comBlogger78125tag:blogger.com,1999:blog-7677692950499400831.post-14104026780103992502017-05-30T10:04:00.002+05:302017-05-30T10:04:58.709+05:30<a href="https://www.goodreads.com/book/show/31416028-bhujia-barons" style="float: left; padding-right: 20px"><img border="0" alt="Bhujia Barons: The Untold Story of How Haldiram Built a Rs 5000-crore Empire" src="https://images.gr-assets.com/books/1470838686m/31416028.jpg" /></a><a href="https://www.goodreads.com/book/show/31416028-bhujia-barons">Bhujia Barons: The Untold Story of How Haldiram Built a Rs 5000-crore Empire</a> by <a href="https://www.goodreads.com/author/show/15596430.Pavitra_Kumar">Pavitra Kumar</a><br/>
My rating: <a href="https://www.goodreads.com/review/show/2014183226">3 of 5 stars</a><br /><br />
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.
<br/><br/>
<a href="https://www.goodreads.com/review/list/7554289-ruchir">View all my reviews</a>
Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-40539275722875164022012-07-09T13:00:00.001+05:302012-07-09T13:00:58.080+05:30Tip: traversing arrays in C-Shell<div dir="ltr" style="text-align: left;" trbidi="on">
Below I have described two methods to traverse arrays in C-Shell - one uses the foreach loop and other while loop.<br />
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.<br />
<br />
<br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">set a = (1 2 3 4)</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">set b = (5 6 7 8)</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><b>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 "[]"</b> </span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">set i = 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">foreach x ( `echo $a` )</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> echo "x = $x b = $b[$i]"</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @ i = $i + 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">end</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">Output: </span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">x = 1 b = 5</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">x = 2 b = 6</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">x = 3 b = 7</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">x = 4 b = 8</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><b style="font-family: "Courier New",Courier,monospace;">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 "[]"</b></span><br />
<span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">set i = 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">while ($i <= 4)</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> echo "a = $a[$i] b = $b[$i]"</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @ i = $i + 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">end</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">Output: </span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">a = 1 b = 5</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">a = 2 b = 6</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">a = 3 b = 7</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">a = 4 b = 8</span></span><br />
<br />
<br />
<br /></div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-9403811100179301002012-02-15T21:41:00.002+05:302012-02-15T21:42:50.760+05:30gdb stops at SIGPIPE<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h3 class="post-title entry-title" style="background-color: #f6f6f6; color: #9e5205; font: normal normal bold 142%/normal Verdana, sans-serif; letter-spacing: -1px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: -webkit-auto;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: small;"><br /></span></h3>
<div class="post-header" style="background-color: #f6f6f6; text-align: -webkit-auto;">
<div class="post-header-line-1">
</div>
</div>
<div class="post-body entry-content" id="post-body-1010450472006788082" style="background-color: #f6f6f6; text-align: -webkit-auto;">
<span style="font-family: Arial, Helvetica, sans-serif;">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:</span><br />
<br />
<blockquote>
<span style="font-family: Arial, Helvetica, sans-serif;">handle SIGPIPE nostop noprint pass</span></blockquote>
<span style="font-family: 'courier new'; font-size: 15px;">
</span><div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 15px;">
</div>
</div>
</div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-21465967017553187872011-11-02T15:52:00.002+05:302011-11-02T15:53:22.038+05:30Parenting<span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px; line-height: 16px; ">Interesting insight on this blog entry in Freakonimics - http://freakonomics.blogs.nytimes.com/2010/07/07/the-paradox-of-parenting/ </span><div><span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px; line-height: 16px; ">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.</span></div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-78618759707320940002011-11-02T15:52:00.001+05:302011-11-02T15:52:47.962+05:30Accomplishment is important<span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px; line-height: 16px; ">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/</span>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-2432155415111597862011-11-02T15:51:00.000+05:302011-11-02T15:52:12.122+05:30Tips for remembering and organizing ideas<span class="Apple-style-span" style="font-family: Arial, sans-serif; font-size: 13px; line-height: 16px; "> Use a pocket recorder and record the thoughts. Musicians do it all the time.</span>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-62682326021853811952011-09-10T21:44:00.001+05:302011-09-10T21:45:58.290+05:30Crux for HBasenew reporting application for BigData based on HBase - Crux<div><a href="http://nubetech.co/crux-hbase">http://nubetech.co/crux-hbase</a></div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-79981124011941420942011-09-10T21:29:00.000+05:302011-09-10T21:34:09.063+05:30Who are you?<span class="Apple-style-span" style="font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); ">someone who follows rules and also believes in the them is Ram. Some who follows rules but does not believe them is Duryodhana. </span><div><span class="Apple-style-span" style="font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px; background-color: rgb(255, 255, 255); ">one who believes in rules but breaks them is Krishna, one who neither believes in rules nor follows them is Ravan. Who are you?</span></div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com1tag:blogger.com,1999:blog-7677692950499400831.post-75127015652357594952011-02-14T11:55:00.003+05:302011-02-14T12:05:04.148+05:30gdb: scriptRecently 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.<br />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.<br />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:<br /><br /><span style="font-size:100%;"><span style="font-family:courier new;">define cntList</span><br /><span style="font-family:courier new;"> set $l = $arg0</span><br /><span style="font-family:courier new;"> set $i = 0</span><br /><span style="font-family:courier new;"> if ($l == 0)</span><br /><span style="font-family:courier new;"> printf "NULL list found\n"</span><br /><span style="font-family:courier new;"> else</span><br /><span style="font-family:courier new;"> set $n = $l</span><br /><span style="font-family:courier new;"> while ($n != 0)</span><br /><span style="font-family:courier new;"> set $i = $i+1</span><br /><span style="font-family:courier new;"> set $n = $n->next</span><br /><span style="font-family:courier new;"> end</span><br /><span style="font-family:courier new;"> end</span><br /><span style="font-family:courier new;"> printf "list size %d\n", $i</span><br /><span style="font-family:courier new;">end</span><br /><span style="font-family:courier new;">document cntList</span><br /><span style="font-family:courier new;">count the number of elements in the list</span><br /><span style="font-family:courier new;">Usage: cntList <dbslist></dbslist></span>ptr<br /><span style="font-family:courier new;">end</span></span>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-74018802306719560152010-12-14T23:11:00.003+05:302010-12-14T23:19:27.382+05:30Nube Technologies in news<a href="http://in.linkedin.com/in/sonalgoyal">Sonal's</a> company <a href="http://www.nubetech.co">Nube Technologies</a> (earlier known as Meghsoft) found mention in <a href="http://www.quora.com/What-companies-other-than-Cloudera-are-betting-on-Hadoop/answer/Jeff-Hammerbacher">this post</a> about companies and start ups working in Cloud Computing from <a href="http://www.linkedin.com/in/jhammerb">Jeff Hammerbacher</a>.<br />Way to go Sonal!!Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-52006352565949194142010-07-26T10:47:00.002+05:302010-07-26T10:49:37.991+05:30Unable to move windows in KDEMany 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.<br /><br />Now there is help available to fix this issue:<br /><span style="font-family: courier new;"> kwin -replace</span><br /><br />will replace the window manager and voila you can now resize and/or move the windows in KDERuchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-31461417060247964292010-07-14T11:22:00.004+05:302010-07-14T11:27:14.877+05:30using sed in alias in C shellUsing sed commands in your .alias file in C shell is always tricky. One example of the same is:<br /><br /><span style=";font-family:trebuchet ms;font-size:85%;" >alias grf 'set fileNline = `echo "\!*" | sed -e "s/\([^ ]*\):\([0-9]*\):.*/+\2 \1/"`;gvim $fileNline'</span><br /><br />This alias is called as:<br /><br /><span style="font-family:courier new;"><span style=";font-family:trebuchet ms;font-size:85%;" >grf file:line_num:</span></span><br /><br />and then it open the file "file" in gvim with cursor at line "line_num".Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-10305967283321379852010-07-09T10:28:00.001+05:302010-07-09T10:28:28.461+05:30Accomplishment is important<div xmlns='http://www.w3.org/1999/xhtml'><p>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 <a href='http://workawesome.com/productivity/being-productive/'>http://workawesome.com/<wbr/>productivity/being-productive/</a></p>in reference to: <a href='http://www.google.com/ig?hl=en&source=iglk'>iGoogle</a> (<a href='http://www.google.com/sidewiki/entry/101572090631977474386/id/rsict0xaRCIx_ulJ-Z8USg-MGuE'>view on Google Sidewiki</a>)</div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-17792590792331050182010-07-08T00:04:00.001+05:302010-07-08T00:04:23.893+05:30Parenting<div xmlns='http://www.w3.org/1999/xhtml'><p>Interesting insight on this blog entry in Freakonimics - <a href='http://freakonomics.blogs.nytimes.com/2010/07/07/the-paradox-of-parenting/'>http://freakonomics.blogs.<wbr/>nytimes.com/2010/07/07/the-<wbr/>paradox-of-parenting/</a><br/>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.</p>in reference to: <a href='http://www.google.com/ig?hl=en&source=iglk#max98'>iGoogle</a> (<a href='http://www.google.com/sidewiki/entry/101572090631977474386/id/ACGxcCBw3zTY-hUJ1tER3lZQuNM'>view on Google Sidewiki</a>)</div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-19058372886444860442010-05-18T15:49:00.003+05:302010-05-18T15:53:54.620+05:30How organizations are scared of talentRecently got the following mail which uses a story from Hindu mythology to analyze corporate behavior.<br /><br /><div style="text-align: justify;"><span style="font-family: courier new;">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. </span><br /><span style="font-family: courier new;">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. </span><br /><br /><span style="font-family: courier new;"> 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</span><br /><span style="font-family: courier new;"> fate of his father, he decided to participate in the same public debate in Janaka's court. </span><br /> <span style="font-family: courier new;">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." </span><br /> <br /><span style="font-family: courier new;"> 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</span><span style="font-family: courier new;"> 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.</span><br /> <br /><span style="font-family: courier new;"> 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</span></div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-45525984646621471872010-01-16T09:11:00.003+05:302010-01-16T10:22:49.613+05:30Fuel subsidy in IndiaRead an interesting comment from the Minister of State for Oil & Gas Mr. Jitin Prasada in today's Economic Times (Delhi -<br /><blockquote style="font-style: italic;">"Those who can afford it should pay the full fuel price"</blockquote>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.<br />Lets see if it makes sense or not.<br /><a href="http://in.news.yahoo.com/32/20100115/1059/tbs-govt-picks-only-half-of-home-fuel-su.html"> This news article</a> 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.<br />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<br />500000 * 6700 * 36 = Rs 12060 Crores.<br /><br />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.<br />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.<br /><br />To me this seems a good way to reduce the subsidy bill.Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-87628779689271484832009-12-15T21:49:00.004+05:302009-12-15T21:52:23.142+05:30Using Outlook's After Sending rules<span class="headline">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.<br /><br /><a href="http://www.outlookpower.com/issues/issue200503/00001512001.html">Using Outlook's After Sending rules</a><br /><br /></span>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-69309998451265488672009-05-08T12:26:00.005+05:302009-05-08T12:38:05.951+05:30Improve Microsoft Outlook PerformanceI 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.<br />Then I found this brilliant article <a href="http://www.webgrrls.com/blog/2008/03/11/improve-microsoft-outlook-performance/">Improve Microsoft Outlook Performance</a> on how to have more than one personal mail folders. Ever since I created a new data file, using Outlook is much less painful.Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-51785392083376424292009-04-25T12:39:00.008+05:302009-04-27T13:11:50.227+05:30Ways to extract data from a space delimited stringWays to tokenize a string if you cannot use the space character as a field delimiter in an input where the fields can have spaces:<div><br /></div><div>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.</div><div><br /></div><div>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. </div><div><br /></div><div>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 <a href="http://www.perl.org/">Perl</a>, <a href="http://www.tcl.tk/">TCL</a> support <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions</a>. C++ user can use the <a href="http://www.blogger.com/www.boost.org">Boost</a> library for regular expression support). </div><div><br /></div><div>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.</div><div><br /></div><div>For programs that do such search more often, let us understand the other approach using an example:</div><div><span class="Apple-style-span" style="white-space: pre;"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"> // input format: <int> <string> <int><br /></int></string></int></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>char* inputStr = "12 abc def 14";<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"> char* firstSpaceChar = strchr(inputStr, ' ');<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>int firstInt = 0;</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>int lastInt = 0;<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>string midStr = "";<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>if (firstSpaceChar != NULL) {</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>*firstSpaceChar = '\0';<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>firstInt = atoi(inputStr);<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>char* lastSpaceChar = strrchr(firstSpaceChar+1, ' ');</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>if (lastSpaceChar != NULL) {<br /></span></div><div><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family:'courier new';"> </span></span><span class="Apple-style-span" style="font-family:'courier new';">lastInt = atoi(lastSpaceChar+1);<br /></span></div><div><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family:'courier new';"> *</span></span><span class="Apple-style-span" style="font-family:'courier new';">lastSpaceChar = '\0';<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>}<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>midStr = firstSpaceChar+1;<br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="white-space: pre;"> </span>} else {</span><br /></div><div><span class="Apple-style-span" style="font-family:'courier new';"> midStr = inputStr;</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"> }</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-78255646354248701642008-10-31T19:13:00.004+05:302008-10-31T19:21:38.444+05:30Tech: How to find the existence of a thread<span style="font-family:arial;">To find if a thread created using pthread_create exists or not use phread_kill with signal number 0</span><br /><span style="font-family:arial;">on the thread that needs to be tested. If the return value is 0, then the thread is alive.</span><br /><span style="font-family:arial;">If the return value is ESRCH, then the thread is not alive in the system.</span><br /><br /><span style="font-family:arial;">Sample code may look like:</span><br /><pre><br />bool is_thread_alive(pthread_t thread_id)<br />{<br /> int status = pthread_kill(thread_id, 0);<br /> if (status == ESRCH)<br /> return true;<br /> else<br /> return false;<br />}<br /></pre>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-5274982979218241772008-03-25T16:07:00.006+05:302008-03-25T16:25:55.188+05:30STL: find in a list of pointersMost STL tutorials will not help you solve this problem:<br />How to search in a list of pointers?<br /><span style="font-family:courier new;">e.g vector<'obj*'>myList;</span><br /><span style="font-family:georgia;">The <em>find</em> alogrithm on this will match only the pointer address and if you do not share your objects between classes then your find will always fail as <em>it matches only the pointer addresses and not the value to which it points</em>.<br />To fix this problem, the solutions that can be considered are:<br />1. store objects instead of pointers in the list. (huge memory overhead!!)<br />2. use <em>find_if</em> instead of <em>find</em> and write a <em>functor</em> which compares value instead of pointer address<br />3. Overload <em>find</em> and implement your own comparator in it. This comparator again compares the value instead of pointer address.<br /></span>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-11020643782749963022008-03-08T17:01:00.002+05:302008-04-08T17:49:57.720+05:30The basics of Technology Mapping in Digital Circuits1. Generate the truth table of a given boolean expression<br />2. Represent the expression in terms of minterms<br />3. Convert each component into one of the cells of technology map.<br /><br />Example 1:<br />a 8x1 multiplexer using a 2x1 mux:<br />8x1 --> a'b'c'I0 + a'b'cI1 +a'bc'I2 + a'bcI3 + ab'c'I4 + ab'cI5 + abc'I6 + abcI7<br /> ==> a'(b'c'I0 + b'cI1 + bc'I2 + bcI3) + a(b'c'I4 + b'cI5 + bc'I6 + bcI7)<br /> ==> a'(b'(c'I0 + cI1) + b(c'I2 + cI3)) + a(b'(c'I4 + cI5) + b(c'I6 + cI7))<br /> ==> a'(b'M1 + bM2) + a(b'M3 + bM4)<br /> ==> a'M5 + aM6<br /> ==> M7<br /><br />Example 2:<br />AND gate using a 2x1 mux:<br />AB --> AB + A'0<br />So the mux will have A as the select line and B on select 1 and tie 0 on select 0<br /><br />Example 3:<br />OR gate using a 2x1 mux:<br />A + B ==> 1(A + B)<br /> ==> (A + A')(A + B)<br /> ==> AA + AB + A'A + A'B<br /> ==> A + AB + A'B<br /> ==> A(1 + B) + A'B<br /> ==> A1 + A'B<br />So the mux will have A as the select line and tie 1 on select 1 and B on select 0Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-41640986434558937612008-03-05T17:39:00.001+05:302008-03-05T17:58:50.583+05:30the awesome GoogleLookUp functionGot this from a <a href="http://www.readwriteweb.com/archives/googlelookup_wow.php">ReadWriteWeb</a>:<br />Try the following on a google spreadsheet<br />1. Create a Google Spreadsheet<br />2. Tape "bmw" in A2, "mercedes" in A3 and "nissan" in A4<br />3. Select A2:A4 and, while holdind the Ctrl key, expand your selection until A50.<br />4. Say "wow"<br />5. Tape "employees" from B2 to B50.<br />6. Enter "=googlelookup(A2; B2)" in C2 and expand the formula until C50<br />7. "wow", again<br />8. Take a look at other Google functions in the "Google" tab of this page: http://documents.google.com/support/spreadsheets/bin/answer.py?answer=82712&ctx=<br />10. "wow", again and againRuchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0tag:blogger.com,1999:blog-7677692950499400831.post-91236742028202528582008-02-27T14:57:00.002+05:302008-02-27T15:00:43.587+05:30Eldeco never seizes to amaze - updateUpdate on my earlier blog entry <a href="http://ruchir75.blogspot.com/2008/01/eldeco-never-seizes-to-amaze.html">Eldeco never seizes to amaze</a><br />The suffering reader says again:<br /><br /><em>They are constantly trying to exploit the situation. I am trying to post my experience with them, in the internet which would help others to take right decisions choosing the property. Even after 4 years, they have not given me offer of possession and saying that I have to pay holding charges for 1.5 years to process the handover.</em><br /><br />May God bring some sanity in Eldeco.Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com3tag:blogger.com,1999:blog-7677692950499400831.post-88744508872736671542008-02-02T22:36:00.001+05:302008-02-02T22:40:42.691+05:30You know you are driving in IndiaRecently got a mail about driving habits in India.<br /><br />You know you are driving in India if ...<br /><br /><ol><li>People in cars think they are conserving their battery by not using the turn signals.</li><li>The side-view mirrors always remain folded in, lest they come in the way of the car's aerodynamics.</li><li>The cellophane/plastic covers on seats and headrests remain in place even after the car is a year old.</li><li>The right of way belongs to the bigger vehicle.</li><li>Pedestrians are unnecessary objects on the roads that need to be honked out of existence, if possible.</li><li>The slowest moving tractor is invariably be on the fast lane.</li><li>The truck in front of you has both the driver and the cleaner waving their hands out of the right and left window at the same time.</li><li>The "L" sign adorns vehicles that are speeding past you.</li><li>The traffic light at a junction is showing red, amber and green at the same time.</li><li>The bus driver wanting to take a right turn at a traffic junction moves to the extreme left lane, picks up a passenger and cuts directly in front of all the right lanes to take his right turn.</li><li>Your first new car scratch "happens" within 30 minutes or 100 metres of driving out of the showroom, whichever is less; first new car dent within 10 days or 1000 km, whichever is less.</li><li>You have an accident while driving at less than 20 km/hour or less (you are lucky if you can get up to triple that speed these days!)</li><li>Every fifth car you pass has a saree pallu or dupatta peeking out the bottom of the passenger side door.</li><li>The number of milk cans on any given Royal Enfield motorcycle is an even number greater than 5.</li><li>You have an accident and ask the truck driver to produce his license and he tells you casually that it was confiscated by the police some 20 years back near Jhumri talaiya.</li><li>For every bull you see standing on the road right in front of you, there are five cows approaching you from either left or right. And the cow dung under your car is really bull shit!</li><li>The five trucks you overtake on a given road have the following five messages on their backside - "HORUN PLASE", "HURN PLEESE", "HOUR PLISS", "HARN PLECE" and "HORNY PLACE".</li><li>The bus in front of you is listing heavily to the left (the door side) and a whole family is hanging on to the door by one hand.</li><li>The number of passengers in a car is indirectly proportional to the size of the car - a Merc or a BMW will have a lone occupant, a Maruti 800 a family of 10 plus the neighbours.</li><li>The lane divider is seen as something you use to guide yourself while driving on the wrong side of the road.</li><li>The speed breaker height is universally one and a half times the ground clearance of your vehicle. The only exception is if you are behind the wheel of a Tata truck.</li><li>The road on either side of a railway crossing is fully occupied by vehicles of 17 types, with each one pointed directly at another one on the other side of the railway crossing.</li><li>The average distance between vehicles going one way is a safe 2.345 cm and the same statistic for vehicles going in opposite directions is a highly conservative 3.987 cm.</li><li>The headlights of every vehicle are defaulted to the high beam mode, since this is a clear sign of manliness and machismo. If a vehicle is not able to drive with its high beams on, it has no rights to unhindered driving on the road.</li><li>The road may have a length, but no fixed width. Every road is a many-shouldered thing - you drive on the road, but when you can't, you drive on the shoulder; when you can't on the shoulder, there is the shoulder's shoulder, and so on. It is only after you have scraped the wall of the house on the edge of the road that you start considering the remote possibility of slowing down and nosing your way back towards the centre. Of course, real men don't do this - they just take the wall along with them.</li></ol>Ruchirhttp://www.blogger.com/profile/14732294144858357420noreply@blogger.com0