Thursday, November 16, 2006

An old man lived alone in Idaho, with his only son, Bubba

An old man lived alone in Idaho. He wanted to
spade his potato garden, but it was very hard
work. His only son, Bubba, who used to help him,
was in prison. The old man wrote a letter to his
son and described his predicament.

----------------
Dear Bubba:
----------------
I am feeling pretty bad because it looks like I
won't be able to plant my potato garden this year.
I'm just getting too old to be digging up a garden
plot. If you were here, all my troubles would be
over. I know you would dig the plot for me.

Love, Dad

A few days later, he received a letter from his son.

----------------
Dear Dad:
----------------
For heaven's sake, Dad, don't dig up that garden.
That's where I buried the BODIES.
Love, Bubba

At 4 a.m. the next morning, FBI agents and local
Police showed up and dug up the entire area
without finding any bodies. They apologized to the
old man and left.
That same day, the old man received another letter
from his son.

----------------
Dear Dad:
----------------
Go ahead and plant the potatoes now. It's the best
I could do under the circumstances.

Love, Bubba

Wednesday, October 25, 2006

Specialised Function Template Linking Problem (Multiple Definition)

Imagine a scenario where you have this specialised template implementation, where it converts the first argument to string and place it on second argument. It also indicates the conversion is successful or not.

template< typename T >
bool convertToString(T x, std::string& result)
{
...
}

// As there's no point of converting a string to another string
template<>
bool convertToString(std::string x, std::string& result)
{
...
}

There're perfectly nothing wrong with that when you're using this function template within your class, i.e.
string a_string, out;
f< std::string >(a_string, out));
f(a_string, out); // this will also trigger the specialised template function

However, in most cases, you'll be using these templates on other classes by #include-ing it. All of a sudden, it gives you an error message "Linked error in function XXX: multiple definition of `bool convertToString ... at line YYY". (this error message has been polished for your readability)

Now you're scratching your head, and ask what've gone wrong here? Fret not, take a step back, all the reasoning behind it is that the compiler linker can't decide on which one to choose as both functions DO support std::string. From outside word, this so-called smart tempate functions library just have two SAME functions with the same number argument and the same return type. We need to tell this picky compiler on which one he should be using.

Enough the description, all we need to do is just inlining the specialised template, which essentially tell the compiler that this should be the one you should looked at if it there's multiple definition for it, i.e.

template<>
inline bool convertToString(std::string x, std::string& out)
{
...
}

Problems gone!

Friday, August 25, 2006

For Lexophiles (Lovers of Words)

1. A bicycle can't stand alone; it is two tired.

2. A will is a dead giveaway.

3. Time flies like an arrow; fruit flies like a banana.

4. A backward poet writes inverse.

5. In a democracy it's your vote that counts; in feudalism, it's your Count that votes.

6. A chicken crossing the road: poultry in motion.

7. If you don't pay your exorcist you can get repossessed.

8. With her marriage she got a new name and a dress.

9. Show me a piano falling down a mine shaft and I'll show you A-flat Miner.

10. When a clock is hungry it goes back four seconds.

11. The guy who fell onto an upholstery machine was fully recovered.

12. A grenade fell onto a kitchen floor in France resulted in Linoleum Blownapart.

13. You are stuck with your debt if you can't budge it.

14. Local Area Network in Australia: The LAN down under.

15. He broke into song because he couldn't find the key.

16. A calendar's days are numbered.

17. A lot of money is tainted: 'Taint yours, and 'taint mine.

18. A boiled egg is hard to beat.

19. He had a photographic memory which was never developed.

20. A plateau is a high form of flattery.

21. The short fortune teller who escaped from prison: a small medium at Large.

22. Those who get too big for their britches will be exposed in the End.

23. When you've seen one shopping center you've seen a mall.

24. If you jump off a Paris bridge, you are in Seine.

25. When she saw her first strands of gray hair, she thought she'd dye.

26. Bakers trade bread recipes on a knead to know basis.

27. Santa's helpers are subordinate clauses.

28. Acupuncture: a jab well done.

29. Marathon runners with bad shoes suffer the agony of de feet.

Note: No trees were killed in the sending of this message, but a large number of electrons were terribly inconvenienced


Wednesday, August 23, 2006

MacBook Pro - Eject Button Troubleshooting

Ever have a problem with a CD/DVD stuck in your offline MacBook Pro and it doesn't allow you to boot up OS X? Apple mentioned the solution is to press and hold the trackpad button when booting your MBP. You tried that, but still fails? Another possible fix is the credit card/knife trick that sometimes works, but it just sounds not right?

OK, now there is an easy way to do it: Just power up your MBP and leave it alone for about 10 minutes. It will eventually boot up and the CD/DVD will automatically eject. Make sure your power cable is plugged in, though!

I have posted this solution at MacOSXHints.com, here is the direct link: Eject a stuck CD/DVD from a MacBook Pro SuperDrive