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;
return false;

Tuesday, March 25, 2008

STL: find in a list of pointers

Most STL tutorials will not help you solve this problem:
How to search in a list of pointers?
e.g vector<'obj*'>myList;
The find 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 it matches only the pointer addresses and not the value to which it points.
To fix this problem, the solutions that can be considered are:
1. store objects instead of pointers in the list. (huge memory overhead!!)
2. use find_if instead of find and write a functor which compares value instead of pointer address
3. Overload find and implement your own comparator in it. This comparator again compares the value instead of pointer address.

Saturday, March 8, 2008

The basics of Technology Mapping in Digital Circuits

1. Generate the truth table of a given boolean expression
2. Represent the expression in terms of minterms
3. Convert each component into one of the cells of technology map.

Example 1:
a 8x1 multiplexer using a 2x1 mux:
8x1 --> a'b'c'I0 + a'b'cI1 +a'bc'I2 + a'bcI3 + ab'c'I4 + ab'cI5 + abc'I6 + abcI7
==> a'(b'c'I0 + b'cI1 + bc'I2 + bcI3) + a(b'c'I4 + b'cI5 + bc'I6 + bcI7)
==> a'(b'(c'I0 + cI1) + b(c'I2 + cI3)) + a(b'(c'I4 + cI5) + b(c'I6 + cI7))
==> a'(b'M1 + bM2) + a(b'M3 + bM4)
==> a'M5 + aM6
==> M7

Example 2:
AND gate using a 2x1 mux:
AB --> AB + A'0
So the mux will have A as the select line and B on select 1 and tie 0 on select 0

Example 3:
OR gate using a 2x1 mux:
A + B ==> 1(A + B)
==> (A + A')(A + B)
==> AA + AB + A'A + A'B
==> A + AB + A'B
==> A(1 + B) + A'B
==> A1 + A'B
So the mux will have A as the select line and tie 1 on select 1 and B on select 0

Wednesday, March 5, 2008

the awesome GoogleLookUp function

Got this from a ReadWriteWeb:
Try the following on a google spreadsheet
1. Create a Google Spreadsheet
2. Tape "bmw" in A2, "mercedes" in A3 and "nissan" in A4
3. Select A2:A4 and, while holdind the Ctrl key, expand your selection until A50.
4. Say "wow"
5. Tape "employees" from B2 to B50.
6. Enter "=googlelookup(A2; B2)" in C2 and expand the formula until C50
7. "wow", again
8. Take a look at other Google functions in the "Google" tab of this page:
10. "wow", again and again

Wednesday, February 27, 2008

Eldeco never seizes to amaze - update

Update on my earlier blog entry Eldeco never seizes to amaze
The suffering reader says again:

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.

May God bring some sanity in Eldeco.

Saturday, February 2, 2008

You know you are driving in India

Recently got a mail about driving habits in India.

You know you are driving in India if ...

  1. People in cars think they are conserving their battery by not using the turn signals.
  2. The side-view mirrors always remain folded in, lest they come in the way of the car's aerodynamics.
  3. The cellophane/plastic covers on seats and headrests remain in place even after the car is a year old.
  4. The right of way belongs to the bigger vehicle.
  5. Pedestrians are unnecessary objects on the roads that need to be honked out of existence, if possible.
  6. The slowest moving tractor is invariably be on the fast lane.
  7. 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.
  8. The "L" sign adorns vehicles that are speeding past you.
  9. The traffic light at a junction is showing red, amber and green at the same time.
  10. 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.
  11. 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.
  12. 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!)
  13. Every fifth car you pass has a saree pallu or dupatta peeking out the bottom of the passenger side door.
  14. The number of milk cans on any given Royal Enfield motorcycle is an even number greater than 5.
  15. 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.
  16. 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!
  17. 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".
  18. 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.
  19. 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.
  20. The lane divider is seen as something you use to guide yourself while driving on the wrong side of the road.
  21. 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.
  22. 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.
  23. 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.
  24. 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.
  25. 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.

Friday, February 1, 2008

Comment: Microsoft offer to buy Yahoo - Microsoft offers to buy Yahoo for $44.6B -- Very interesting.
Is it part of Microsoft's strategy to counter Google? But Yahoo is no competition to Google in search and Gmail is much better and faster than Yahoo mail.

Peter Clarke in his comment on the above news makes an interesting observation - It really marks Microsoft handing over the torch of succession: because Google is the big dog now - and I totally agree with him on this. To me Microsoft today seems like Sun of the browser war. Sun was wiped out by Microsoft then, is it Microsoft's turn now? Microsoft is trying hard to save itself from getting commoditized by Google's killer web applications.

Wednesday, January 30, 2008

Power politics

The manner of disposal of complaint against Indian cricketer Harbhajan Singh for alleged racist remarks to Australian cricketer Andrew Symonds has incensed a lot of Australians. The main grouse being the way Indian cricket board (BCCI) was able to arm twist the world governing body ICC and Cricket Australia (CA) into following its lead.
With some explicit and some implicit threats of withdrawing from the tour from BCCI and its resultant financial loss to CA and ICC and not to forget Television companies, from the very outset, it was not tough to figure out that the final decision would be as per the liking of Indian team and cricket board. So I wonder why the comments now. Maybe the reality dawns on some people later than others.

I tend to sympathize and agree with the Australians who feel that the financial clout of BCCI in cricket led to the unwanted semi-withdrawal of complaint from the Australian cricket team.
But isn't it the norm in every society that the rich and powerful always have there way? Whatever space the weak get is not taken but given by the strong.
Few examples:
This article on how the rich nations which contribute most to the UN kitty are arm twisting the UN to spend in the manner in which they tell it to.
The bombing of Hiroshima and Nagasaki in WWII. Who says that the US is a bad country?

Australians, welcome to the real world!!

Eldeco never seizes to amaze

One of the readers has sent this about his experiences with Eldeco at Utopia:

It is 4 years, I have paid them in full for a flat in their Utopia project. FDN is partially pending. I am trying to sell my apartment. The prospective buyers go there and see the situation and return with lot of resentment. ..... they [Eldeco] are misusing my flat as their store room by them and their contractors and not made the flat ready for possession and it is in shabby state.

Eldeco never seizes to amaze me!!

Tuesday, January 29, 2008

Eldeco hasn't changed its ways

It seems that the residents at Ananda are not the only ones who are suffering due to apathy of Eldeco. Almost once in a week I get a mail from a sufferer of Eldeco. Be it Utopia on expressway or Amantran in Sector 119, Noida.
I wonder what happiness Eldeco gets by treating its customer with such apathy. They charge a bag full of money and they give back a bag full of woes.

The comment in this post makes an interesting read:

And the latest at Ananda:

Last night (20th Jan 08), there was an event in the passage of 7th Floor. Whole row of the tiles above the Lift door, collapsed en mass with a very loud noise. It happened last night, luckily no one was using life at that moment, otherwise it would have caused a grave injury, including head injury with a possibility of fatality. I think this is a serious concern, showing extremely poor quality of construction done by ELDECO(an ISO certified organisation)

Thursday, January 24, 2008

Techy: Questions - hints

Hints to questions asked in my earlier post Techy: Questions

  1. The random function in Unix gives a number between 0 and RAND_MAX (which is fairly large). So starting with the 1st index as seed, call random function K-1 times with the seed for each call being the output of the previous call of the random function. Once these K numbers are available, sort them and iterate on the list using these numbers.
  2. Try using a modification of the quicksort alogrithm, with the pivot at the kth item. Pivots in subsequent iterations will also be the kth item of the original list. The actual location of the pivot in the sublist will depend on the size of the sublist and of any sub lists which have smaller entries than the sublist under consideration.

Wednesday, January 23, 2008

Techy: Questions - 2

1. Given two linked lists. Find whether they converge or not.
2. If the lists converge then find the point of convergence
3. How to find if a rectilinear polygon is clockwise or anticlockwise, given the coordinates of all the points in order.

Monday, January 21, 2008

Umberto Eco’s Anti-Library

Interesting quote from Taleb's Black Swan

“The writer Umberto Eco belongs to that small class of scholars who are encylopedic, insightful, and nondull. He is the owner of a large personal library (containing thirty thousand books), and separates visitors into two categories: those who react with “Wow! Signore professore dottore Eco, what a library you have! How many of these books have you read?” and the others - a very small minority - who get the point that a private library is not an ego-boosting appendage but a research tool. Read books are far less valuable than unread ones. The library should contain as much of what you do not know as your financial means, mortgage rates, and the currently tight read-estate market allows you to put there. You will accumulate more knowledge and more books as you grow older, and the growing number of unread books on the shelves will look at you menacingly. Indeed, the more you know, the larger the rows of unread books. Let us call this collection of unread books an antilibrary.
We tend to treat our knowledge as personal property to be protected and defended. It is an ornament that allows us to rise in the pecking order. So this tendency to offend Eco’s library sensibility by focusing on the known is a human bias that extends to our mental operations. People don’t walk around with anti-resumes telling you what they have not studied or experienced (it’s the job of their competitors to do that), but it would be nice if they did. Just as we need to stand library logic on its head, we will work on standing knowledge itself on its head. Note that the Black Swan comes from our misunderstanding of the likelihood of surprises, those unread books, because we take what we know a little too seriously.
Let us call this an antischolar - someone who focuses on the unread books, and makes an attempt not to treat his knowledge as a treasure, or even a possession, or even a self-esteem enhancement device - a skeptical empiricist.”

After reading this piece, I don't fear the growing number of unread books in my collection. And it inspires me to buy more books and not wait till I have read all of the present unread set which I was doing till now.

Sunday, January 20, 2008

India Tour of Austrailia 07-08: 3rd Test review

Siddhartha Vaidyanathan's pre-match article on the 3rd test match between India and Australia had an interesting comment:

"Despite all the portents India can take heart from one fact: they've recently pulled off surprises in bowler-friendly conditions abroad. Like in Headingley in 2002, Kingston or even Wanderers in 2006 and Nottingham last year, they have stood up and taken on the challenge."

When I had read this I I had hoped if there could be a repeat at Perth.
Post match it appears that India are on there way to win the pace battles in near future. And given the unpredictable nature of Indian team, I am now beginning to doubt there capabilities to win on pitches which are expected to help them. Look at what happened at Sydney and Melbourne earlier. Both places where India had a chance. But post Perth, one thing that I am confident about is that Indian pace battery is there to stay and has the potential to become world beaters in future.

Tuesday, January 15, 2008

Raise your sights

The article Cricinfo - Raise your sights, India by Peter Roebuck on the state of Cricket in India and what it should do next in Cricket is an interesting one. The arguments raised in it can easily be applied to personal life as well:

  1. In the long run it was not the result that mattered but the response -- rise like a phoniex from the ashes is what they say
  2. A newly formed nation relishes every achievement because they instil confidence and create identity. A mature country is not so easily pleased. Certainly, it does not live in the past. -- but it does remember it so as move forward in a better manner
  3. Defeats have led not to rational introspection but to loud protest -- do not blame someone else but see what more you could have to done to win
  4. Goals help to define actions -- no better truth than this one
  5. extract every last drop of ability .... keep working, keep improving. -- the only thing constant is change

Friday, January 11, 2008


Interesting article on offshoring from Sramana -- Trend Radar 2008: Offshoring - Sramana Mitra on Strategy
A year back I would have disagreed with her, but with the learnings in the past one year, I think she is right on the count that in 5 years time the cost of living in Indian Metros would be comparable to that in the US.
However, if India has to stay on top then we have to develop ourselves into a product development industry rathar than a service industry. That would help India to maintain its niche in the IT industry.

And with lots of activities going on in Indian IT industry I have little doubt that India wont be able to make it.