Author Archives: Andrews Ang

About Andrews Ang

A techie who loves to share.

To the teachers who inspired me

I was a quiet boy in school when I was little. I never had any close friends before secondary school because I had very low self-esteem.

I think my self-confidence was more or less damaged by the comments I got from my relatives and friends. My dad was in debt, my mum was an alcohol sales girl, my sisters were dropped out from school, I never did well in school and I was a sissy. Yes, I got a lot of that “sissy” comments. It got so deep into me that I was troubled by it for the longest time in my youth.

I tried to stay away from the boys in primary school because they would make fun of me. I always thought being sissy was a wrong thing, so I didn’t want the other boys to hear me talking. I pretended to be like them: talking loudly, mocking at others, cheating during tests, playing truant and pulling girls’ pony tails. But to me, they were not my friends. The girls hated me too.

Actually, playing truant wasn’t exactly just for show. I didn’t like school, didn’t like the teachers and classmates. It didn’t make any sense to go there at all. Although, I loved drawing. I scored well in my art and craft. My art teacher even praised me during meet-the-parent session. But my dad would say drawing was for girls. So I dropped it.

My elder sister was very good in sports. She was one of the top badminton players in school and she always participated in track and fields. I admired her a lot, still do. I took part in drama and I drew very well, but I was never good in sports. My dad and relatives would laugh at me for doing the “girls stuff”. I tried soccer. It was a disaster… I could only chase the ball and mocked by the other boys.

I ever thought I had made a good friend when I was in primary 4. He would ask me to go over to his house and we would make our own toy cars. I thought finally I was doing what other boys would do. And then one day my good friend offered to help me make my toy car look better. The model I bought was one of the most expensive ones available at that time. I had saved up all my breakfast money to buy it. So naturally I was very particular about all the parts in my toy car. The next day my good friend played truant. The following day he didn’t show up. So I went to his house to ask if I could get my toy car back. He gave me back, reluctantly. I was beginning to feel suspicious. So I checked every part of my toy car… The engine was different… I remembered I made a mark on it. So I questioned him, and of course he denied and blamed me for being so sissy. What?!

Then, I never trusted anyone. And I stopped talking. I had even stopped going to school. Every morning, I would dress up nicely, pretending to go to school. Then I would wait on the upper floor for my dad to leave for work. I would go back to my house and hid under the bed or in the cupboard for the next couple of hours. I hated school. In fact, I hated people.

There was this social studies teacher who was always concerned about my attendance. If I didn’t turn up in class, she would talk to me the next day when she saw me. I was so petrified whenever she called me out in class, and then questioned me about my medical certificate. Many years later, I read in a news that she had won some awards for the most caring teachers in Singapore. Now that I think of it, she really deserves that award. Her name was (something like) Ms Synnathambhi. I can’t spell her name now. :P

I failed primary 5, really badly. During that time, for students who failed primary 5 or 6, they would either go to extended classes or mono classes. Primary school would usually end at primary 6. So the extended classes would continue to primary 7 and 8. While the mono classes would continue to primary 7 and 8, but they could never go to the main stream in secondary school.

I ended up in an extended class, jumping from primary 5 to primary 7 extended.

As usual, in the first few weeks, I always turned up late. Then one day, my maths teacher, Ms Gwee, saw me coming into the class, late, and said in front of the class: “Oh wow, you’re early!”

I was terribly embarrassed like never before. But she didn’t continue to humiliate me in front of the class. She waited for me to settle down and then continue with her lesson. This was the most important lesson in my life! The first sarcastic remark I had gotten. Yet, it helped me to realize how selfish I was to let the others wait for me to begin class. She didn’t look at me like other teachers. What I saw from her was the same look she gave to every other student in the class. That was the first time I felt at ease in class. I didn’t have to behave like others, because I was “others”. From that day onwards, Mathematics became my favourite subject. I had even scored an A star in PSLE, our national Primary School Leaving Examination, almost on par with the normal stream primary 6 students. I’m sure Ms Gwee was very proud of me.

During the same time, I had also met another important teacher in my life. She was my Chinese language teacher. I must admit, I forgot her last name. But I remembered I was very bad in Mandarin. At home, my parents and relatives would communicate in Hokkien (Min Nan), a dialect passed down from my grandparents who were from the south China. English and Mandarin were foreign to me at that time. I had even written my assignment in Hokkien without knowing. She read it out in class (in Hokkien) to humiliate me. It was so embarrassing, yet funny because she did the Hokkien slang the right way! But the most important thing was, she pointed out to me what was wrong, and corrected me. I felt so blessed. And comforted. Because she understood my background. She didn’t blame me, but praised me for what she could never do! Yes, you guessed it. Mandarin became my next favourite subject and I got A in PSLE.

I then became “teachers’ pet”, and was hated by many classmates. I didn’t want that. I only wanted to be kind to people who treated me kindly. Unfortunately, those people were my teachers.

While I was quiet in school during my time in primary 7 and 8, there was this guy who was in my class and had been mocked by many students as a sissy. He was always alone and quiet. During recess time, you would see him hiding in a corner, eating his breakfast. One day, during physical exercise lesson, under the impression that all the other boys didn’t like him, I mocked at him loudly across the parade square, shouting “sissy”. He merely looked away, hurt. And then a boy whom I admired for a long time, spoke out for him and scolded me for being rude. It shocked me… because I always thought people didn’t like sissy. And then I realised that I was wrong to judge people. I was in no position to judge people, especially when I was in the same position… a “sissy”. That “sissy” became my first good friend in school.

I didn’t do well in English, but squeezed my way through the express course in secondary school, it was the same couse that the normal primary 6 students would go. My teachers were thrilled, but my dad didn’t know the difference. He only wanted to know if I had “passed”. I just told him I did. My mum, on the other hand, knew that I was “first in class”, and insisted that we celebrate at the coffee shop she worked in. She began telling her colleagues how smart I was. You can imagine how embarrassed I was at that time. I was just an “extended student”, which was deemed as no future at that time.

In my first year in secondary school, I had tried to keep away from other students. I hardly spoke to anyone, even my good friend from primary school. During recess time, I would buy my breakfast and do my homework in a corner. It felt safe…. because I didn’t have to face human beings. Until we were forced to join an ECA (Extra Curriculum Activity).

I loved arts and music. So the first ECA that I thought would be either the band or the choir. But then I was pressured by my relatives to do something more “manly”, which I thought could be the boys scout or NPCC.

My form teacher, Ms Chang, was the teacher-in-charge of the band. We were the pioneer batch of the school, so all ECAs were only just starting. Eventually, I had decided to give the band a try, thinking that I could learn the violin. Ms Chang very kindly explained to me that the band wasn’t an orchestra, so there wasn’t any violin available. I was quite disappointed at that time. She then encouraged me to try other instruments later on in that year (it was a new school, so there wasn’t any instrument to practice for many months). I don’t know what came to me, but I stayed in the band eventually. Trombone was my first musical instrument.

I knew Ms Chang took care of me. I didn’t know why. But in my second semester of the first year, she made me the chairman of the class, and then she made me stand in front of the class to make announcements. Initially, I was very shy and afraid… but after a few rounds, I gained some confidence and spoke better with people. Later on, she even made me the drum major of the band. I knew she was trying to help me regain my self-esteem, but I had also heard rumours about people not happy with my position. It was difficult to deal with rumours at that young age. The discipline master even tried to make me the Head Prefect, but I rejected… because I couldn’t deal with so much pressure at the same time.

We did well in our band competition, although not ideal, but I had enjoyed every day with the band members. It was then that I felt ease and comfort with people of the same mindset and without prejudice. Yes, we were only maybe 12 to 16 years old. But the amount of pressure from our peers was no lesser than the adults.

Along the years, I had met many other great teachers who had guided me to a clearer path. I may not be successful now. But I’m more human, more self-esteem, and more open to people who care about me. To those teachers who had changed my life, if not for you, I won’t be writing this blog in front of a 27 inch iMac comfortably, and I won’t be having so many good friends in my life. Thank you so much! Oh, and I may still be a sissy, but I have come to accept it as part of my life! :)

Fix file association error in Windows 7

I’m having this very strange Perl scripts association issue in Windows 7 that is causing my automation to fail with strange warnings. Perl script launches correctly but doesn’t detect any parameters passed into it.

To fix this, I had to remove some keys in RegEdit.exe to reset the association.

Go to “Start button” -> search for -> “regedit”, and delete the following:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pl
HKEY_CLASSES_ROOT\.pl
HKEY_CLASSES_ROOT\pl_auto_file

Hope this helps people with the same problem.

References to good BYO PHP MVC Framework tutorials

When I first came across the term MVC (Model-View-Controller) few years back, the whole concept sounded so complex, especially for people with (old) ASP and PHP background. In those days, we were so used to mixing business logics inside the presentation layer. It was so logical and convenient, until the code got big and things got out of hand. We forgot where the codes were, and we risked stability even for small changes to the UI, because they were all intertwined with business logics.

Typical PHP-HTML mixed code:

<?php
  include "someFileContainsFunction.php";
  public function someLocalFunction( $param )
  {
    return "Business logic in <b>$param</b>!";
  }
?>
<html> 
  <title>HTML with PHP</title>
  <body>
    <h1>My Example</h1>
    <?php
      print someLocalFunction( "Inside body" );
    ?>
    <b>Here is some more HTML</b>
    <?php
      print functionFromExternalPHP();
    ?>
  </body>
 </html>

Then I was introduced to MVC during a Microsoft .NET bootcamp in Singapore. I was quite fascinated with the idea. Separating the 3 components enable us to distribute the work to programmers and designers, allowable them to do their work without touching the fields they’re not familiar with. It is also an ideal solution to multinational collaboration.

Although the .NET MVC framework was great as a development tool, I couldn’t understand the fundamentals of building an MVC. We merely followed the coding style requirements by the framework, and work our way through to make the application work.

So I went in search of other languages, and found many other frameworks such as Ruby on Rails (for Ruby) and CakePHP (for PHP). They are also great MVC frameworks, but then again, they’re very established with quite stringent coding style requirements that I always got lost halfway down the development.

http://www.netmagazine.com/features/choose-right-php-framework

I thought the best way to learn about something is to start from the beginning, and keep on testing and failing until I understand it. The following 2 tutorials are great starting points. I managed to write my own MVC framework within a day (or maybe a few hours) by following the tutorial from Domagoj Salopek. I would recommend going through this tutorial first before going to the next one, which is slightly more complex but covers a little more for MVC.

http://www.domagojsalopek.com/Details/Create-a-simple-PHP-MVC-Framework/28

http://johnsquibb.com/tutorials

Of course, there’re people who think that using MVC on a small project is an overkill. Trust me, it’ll help you in the long run. By writing a core MVC framework, you’ll be able to use it in all other projects in the future, regardless how big or small it is. Unless the client only wanted a “simple” website. I know clients always think their requirements are simple because they don’t understand the simpler it seems, the more work it takes. I’m referring to those instances where the project can be done just with HTML and JavaScript. In those cases, MVC is really too much.

Now, going back to fiddling the simple MVC framework that I have written.

Edited: After writing my own simple MVC framework, I went on to study other major PHP framework such as Symfony, CakePHP and CodeIgniter. I noticed that CodeIgniter uses a very similar approach to the simple framework introduced by Domagoj. So if you’re advancing to a more complex framework, take a look at CodeIgniter. You’ll be glad he had written something so fundamental to get us started.

MD5 Hashing password or text using Perl

Just a small tip I learned from work.

Obtain the MD5 hash of the password using Perl:

$ perl -MDigest::MD5=md5_hex -e"print uc(md5_hex(@ARGV[0]))" hellother3

Result:

BB4505B8BC6051AF4A6FEB31A2ECE1E7

The uc() means returning the upper case of the result.

print uc(md5_hex(@ARGV[0]))

To return the lower case of the result, use lc() instead:

print lc(md5_hex(@ARGV[0]))

Setting Aptana to read another file type as PHP

So recently I’ve been following this simple tutorial to learn about creating a simple MVC PHP framework: http://www.domagojsalopek.com/Details/Create-a-simple-PHP-MVC-Framework/28

It’s so simple that I got a MVC template in less than an hour. But it definitely took me some time to fully understand the code. Luckily I have some experience with WordPress and CakePHP so somehow it wasn’t too long for me. *Trigger proud-mode* :P

As usual I was using my favorite IDE Aptana but something struck me: I don’t see the PHP color code for the *.tpl files that I have created for the MVC framework. It’s quite annoying and inconvenient.

Turns out it’s actually quite simple to “fix” it.

  1. Just go to Preference (Mac users check the “Aptana Studio 3″ menu at the top panel, WIndows and Linux users should check the File or Tool menu)
  2.  Under General -> Editors -> File Associations
  3. Under File Types -> Choose Add, and enter: *.tpl
  4. After added, click on that file type
  5. At the bottom, click Add and choose “PHP Source Editor”.

Done!

Now when you reopen all the *.tpl files in Aptana, it will be recognized as PHP files.

Hope this is useful to you. :)

Windows 7 Auto Logon in Domain

1. Go to Start>Run (or press the windows key + r)

2. Type regedit and press the enter key or click on OK.

3. In the registry editor go to HKEY_LOCAL_MACHINE>SOFTWARE>Microsoft>Windows NT>CurrentVersion>Winlogon

4. On right side pane look for these values AutoAdminLogon, DefaultPassword and DefaultUsername. If they are there skip on to Step 6.

5. If the above values aren’t there, then right click on empty area in the right pane select New>String Value and enter the value name such as AutoAdminLogon. Repeat this step for each value.

6. Once you’ve created these values double-click each value and enter the following value data for the particular value

Name : AutoAdminLogon Value : 1
Name : DefaultPassword Value : the pasword of the user profile
Name : DefaultUsername Value : the username of the account you want to log in to

7. Now you’re done!

Source
http://www.mockbox.net/windows-7/295-windows-7-auto-logon-with-domain-computer

C# .NET Entity Framework: How to insert record into database table with auto-increment primary ID?

I want to insert some records into the database table but it is giving an error which says “INDENTITY_INSERT is set to OFF”, something like that.

To resolve this, there’re 3 steps:

First, in Visual Studio 2010 and click on the .edmx file.
Look for the relevant and right click on the identity column (ID in most cases) and choose Properties.
In the properties window, look for StoreGeneratedPattern and change the value to “None”.
Save the changes.

In some cases (in my case), changing the value in step one is now enough. We still need to manually edit the .edmx file.
In Visual Studio 2010, right click the .edmx file -> “Open With…” -> Choose “XML (Text) Editor” to open the .edmx file
Look for the relevant table and change StoreGeneratedPattern=”Identity” to StoreGeneratedPattern=”None” for the identity column.
Save the changes.

Once the EF settings are done, we can set the primary key at the EF side.
However, SQL Server does not allow the Identity column to be set unless IDENTITY_INSERT is ON. (http://msdn.microsoft.com/en-us/library/ms188059.aspx).
So we need to manually execute SQL command to turn on the IDENTITY_INSERT first before we insert new records.

using (TestDBEntities1 context = new TestDBEntities1())
{
	using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
	{
		context.Connection.Open();
		int i = context.ExecuteStoreCommand("SET IDENTITY_INSERT TestDB.dbo.Person ON");
		Person p = new Person();
		p.PersonID = 4;
		p.Name = "Michael";
		context.People.AddObject(p);
		context.SaveChanges();
		i = context.ExecuteStoreCommand("SET IDENTITY_INSERT dbo.Person OFF");
		scope.Complete();
	}
}

This is a workaround to let us manually set the identity column.
Warning: when IDENTITY_INSERT is set to ON, we need to manually assign the identity key (ID in most cases). You must ensure that it is unique and not null or empty. If you want to get the next available ID, you may add this:

Person p = context.Person.OrderByDescending( c => c.PersonID).FirstOrDefault();
int newId = (null == p ? 0 : p.Id) + 1;

Resource:
http://social.msdn.microsoft.com/Forums/eu/adodotnetentityframework/thread/48cfa132-8612-4353-b916-b29f32b4070e

http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/84867836-2a52-4c8d-aa3d-e2d5f1845e66