How to text search in terminal

There’re times when I need to quickly search through occurrences of certain phrases in my PHP source files. Here is when I have to search for ‘giraffes’.

This is an example finding the word ‘giraffes’ in all PHP source files from the current directory recursively.

[code lang=”bash”]find . -name “*.php” -exec grep -i -H -n “giraffes” {} ;[/code]

This works for Ubuntu, CentOS and Mac OS X.

Bangkok, and now Taipei

I just returned from Bangkok not long ago. It was a good trip.

And now I’m going to Taipei. It’s okay to be envious, even I am envious of myself. I know however that it’s probably the only time I can go for two holidays in one month. My excuse is I didn’t take much leave from work last year.

The two holidays make up I guess. I want to try doing a lot more in Taiwan though. Perhaps pack my itinerary with so much activities just to experience the place more. My holidays are always extremely laid back which I suspect has something to do with my inability to reconcile with failures to commit.

Anyway, I’ll bring my laptop over to Taipei. Maybe do some writing and research there on where to travel to. I will love suggestions. My hotel will be at the Ximen MRT Station area, in Taipei city. First stop is likely Ximending.

Stereotyped as a web developer

During casual introductions, it perhaps isn’t particularly good to tell others what you do. I find that introducing myself as a web developer to friends of friends just kind of kills it all. Not because web developers are such nasty people — quite the opposite, most are nice — but that there’s a deep stereotype as to what a software engineer is like. I feel my identity is determined by my work — meticulous, overly logical, robotic and geeky. Furthermore web developer is an increasingly meaningless label since everyone knows a cousin could do what I do. Web programming is just one of the things that I can do. I could do more but in a one sentence introduction I can’t mention all. Now I just say my name and how I first met my friends. Not useful maybe, but rids the stereotype.

The battle over the way we should speak

On the increasing usage of improper English, Joan Acocella of The New Yorker notes:

English is a melding of the languages of the many different peoples who have lived in Britain; it has also changed through commerce and conquest. English has always been a ragbag, and that encouraged further permissiveness. In the past half century or so, however, this situation has produced a serious quarrel, political as well as linguistic, with two combatant parties: the prescriptivists, who were bent on instructing us in how to write and speak; and the descriptivists, who felt that all we could legitimately do in discussing language was to say what the current practice was.

But the most curious flaw in the descriptivists’ reasoning is their failure to notice that it is now they who are doing the prescribing. By the eighties, the goal of objectivity had been replaced, at least in the universities, by the postmodern view that there is no such thing as objectivity: every statement is subjective, partial, full of biases and secret messages. And so the descriptivists, with what they regarded as their trump card—that they were being accurate—came to look naïve, and the prescriptivists, with their admission that they held a specific point of view, became the realists, the wised-up.

Source: New Yorker

I guess that will make me closer to a descriptivist since I think there’s nothing wrong with Singlish.

Lion takes long to connect to local server

Does your /etc/hosts file look like this?

[code lang=”bash”] gladlycode.local gladlycast.local babyessentials.local localhost[/code]

Every request I made to gladlyCode.local takes 5 seconds to resolve to my local Apache server. Something was wrong!

If it does and you’re on Mac OS X Lion, you should change your VirtualHost names to something else. It turns out that Mac OS X Lion no longer looks up /etc/hosts first when you try to lookup a .local domain since are technically reserved for Multicast DNS (MDNS), or Bonjour. Starting Lion, it will lookup through MDNS first, and after the 5 second timeout, it checks with /etc/hosts.

This is at a cost of developer productivity and I have to change all my .local domains to which is a domain name I own. I figured that if it is a domain name I own, it will never clash unknowingly. I changed ‘gladlycode.local’ into ‘’ and point it to now. Now testing gladlyCode no longer takes 5 seconds per request (ridiculous!).

Alternatively you can use another top level domain (TLD) instead of .local and the common ones such as .com.

Never type origin master again

The reality with most projects is I typically work with origin master only. Only 10% of my projects is doing actual branching. (Yea, there probably should be an improvement on that figure.)

Here’s how to merge origin master by default.

[code lang=”bash”]git config branch.master.remote origin
git config branch.master.merge refs/heads/master[/code]

You never have to see the following message again:

[code lang=”bash”] kahwee$ git pull
You asked me to pull without telling me which branch you
want to merge with, and ‘branch.master.merge’ in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. ‘git pull ‘).
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch “master”]
remote =
merge =

See git-config(1) for details.[/code]

How to be happier

Excerpts from paper by Elizabeth W. Dunn, Daniel T. Gilbert and Timothy D. Wilson

If money doesn’t make you happy, then you probably aren’t spending it right

The relationship between money and happiness is surprisingly weak, which may stem in part from the way people spend it.

We suggest that consumers should

  1. buy more experiences and fewer material goods;
  2. use their money to benefit others rather than themselves;
  3. buy many small pleasures rather than fewer large ones;
  4. eschew extended warranties and other forms of overpriced insurance;
  5. delay consumption;
  6. consider how peripheral features of their purchases may affect their day-to-day lives;
  7. beware of comparison shopping; and
  8. pay close attention to the happiness of others.

On point 2, use their money to benefit others rather than themselves:

Choosing to give money away—or even being forced to do so—led to activation in brain areas typically associated with receiving rewards (Harbaugh, Mayr, & Burghart, 2007).

On point 5, delay consumption:

…there is a second reason why “consume now, pay later” is a bad idea: it eliminates anticipation, and anticipation is a source of “free” happiness. The person who buys a cookie and eats it right away may get X units of pleasure from it, but the person who saves the cookie until later gets X units of pleasure when it is eventually eaten plus all the additional pleasure of looking forward to the event.