Tuesday, December 8, 2009

Less is More

My professor used to say "Less is more" especially when answer questions in exams. We interpret that he does not want to read through long answers. i.e. He's just lazy. :)

But there are some quotes that talks about this as well.
It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away. - Antoine de Saint-Exupéry, Wind, sand and stars, 1939
Everything should be made as simple as possible, but not simpler. - Albert Einstein

So...I'm reading "Getting Real" written by the guys are 37signals. And the same concept of "less is more" is highlighted again. Of course, being the people who brought us Ruby On Rails. This concept should be the center of what they do everyday.

Interestingly, I received a phishing email asking me to login to 37signals to change my account password. I immediately realized that it was a phishing email and went to the real website to warn them about it. I guess the success of your web application depends on whether hackers are trying to phish your users data.

Friday, December 4, 2009

Singapore NRIC check

There are various nric check information pages, but most of them are giving you the algo. Here is one implemented in PHP.


<?php
function check_nric($nric) {
  if ( preg_match('/^[ST][0-9]{7}[JZIHGFEDCBA]$/', $nric) ) 
  { // NRIC
    $check = "JZIHGFEDCBA";
  } else if ( preg_match('/^[FG][0-9]{7}[XWUTRQPNMLK]$/', $nric) ) 
  { // FIN
    $check = "XWUTRQPNMLK";
  } else 
  {
    return false;
  }

  $total = $nric[1]*2
    + $nric[2]*7
    + $nric[3]*6
    + $nric[4]*5
    + $nric[5]*4
    + $nric[6]*3
    + $nric[7]*2;

  if ( $nric[0] == "T" OR $nric[0] == "G" ) 
  {
    // shift 4 places for after year 2000
    $total = $total + 4; 
  }

  if ( $nric[8] == $check[$total % 11] ) {
    return TRUE;
  } else {
    return FALSE;
  }
}
?>