Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for the ‘Tips & Tricks’ Category

Use jQuery select an option from dropdown

leave a comment »

Self note

<select id="target">
<option selected>--- blank</option>
<option value="21">test1</option>
<option value="12">test2</option>
<option value="30">test3</option>

Using index:

  $('#target>option:eq(1)').attr('selected', true);
  // test1 will be select

Or select by value:

  $(#target>option[value=30]').attr('selected', true);
  // test3 will be select


Written by Chorn Sokun

November 11, 2012 at 12:02 pm

Yii overwrite accessRules in base class

leave a comment »

Suppose you defined a base class Controller with basic accessRules

class Controller extends CController
  public function filters()
    return array(
      'postOnly + delete',

  public function accessRules() {
    return array(
      // allow authenticated user to perform 'create' and 'update' actions
      array('allow', 'actions'=>; array('index', 'view'), 'users' => '@'),

      // deny all users
      array('deny', 'users'=>'*'),

and you want to add (overwrite) rules in derived class, using array_merge here how you do it:

class Site extends Controller
  public function accessRules()
    return array_merge(
      // allow all user to perform 'help' actions
      array( array('allow', 'actions'=> array('help'), 'users' => '*') ),

      // parent go last

As best practice your base class default access rule is deny all by default.

Written by Chorn Sokun

October 22, 2012 at 3:34 pm

[mac os x lion] Reset a user’s password in single user mode

leave a comment »

Lesson learn for mac newbie, always show input method in login screen otherwise here how you going to get back into your machine.
  1. Boot into single user mode (press Command-S at power on)
  2. Type fsck -fy
  3. Type mount -uw /
  4. Type launchctl load /System/Library/LaunchDaemons/
  5. Type dscl . -passwd /Users/username password, replacing username with the targeted user and password with the desired password. Ignore the error message!
  6. Reboot

Written by Chorn Sokun

March 2, 2012 at 11:42 am

Posted in Tips & Tricks

Tagged with

Build monodevelop on ubuntu 11.10

with 11 comments

Again? yes but this time I don’t have to built mono runtine Ubuntu 11.10 packed with mono 2.10.5 which good enough since what I am after is dynamic.
However monodevelop I got from Ubuntu Software Center (USC) is 2.6 and the official release is 2.8.x so I take my on my gut to try and built me an IDE ;)

This time it much easier what I have to do is get latest copy of the source code from

> git clone git://

Then install build dependent by issuing this command

> sudo apt-get build-dep monodevelop

I don’t know why mono-gmcs was not install as part of the previous command (if you know why please comment) for now I have to install another package

> sudo apt-get install mono-gmcs

and then I’m ready to

> ./configure
> sudo make && make run

> monodevelop


MonoDevelop 2.8.2
Installation UUID: b220bfc2-57c6-4b94-840e-ff6c6477632d
	Mono 2.10.5 (Debian 2.10.5-1) (64-bit)
	GTK 2.24.6
	GTK# (
Build information:
	Git revision: e047f99f6df7b5c801102c03f903d4dd722b2989-dirty
	Build date: 2011-11-11 15:03:47+0000

Thanks to mono packaging team, you guy rock!

Written by Chorn Sokun

November 11, 2011 at 11:12 pm

LINQ 101 .NET Reflection

leave a comment »

In this post I am going over three points listed bellow:

What is .NET Reflection? Cut short it refer to a set of API built-in .NET Framework, which give you a greate power to load and manipulate type within assembly (.dll) one of the most favor use is to support late binding. There a whole lot of explaination available through google! but that all I care for now.

How about LINQ? stand for .NET Language-Integrated Query,

 a set of general purpose standard query operators that allow traversal, filter, and projection operations to be expressed in a direct yet declarative way in any .NET-based programming language. The standard query operators allow queries to be applied to any IEnumerable<T>-based information source.

What it mean to me?
Assume that I had ITrap interface and a bunch of Trap implementation as show in the code bellow:

interface ITrap{
  void Setup();
  int OrderNr { get; };

class LevelOneTrap: ITrap{
  public void Setup(){
    Console.WriteLine("LevelOne Setup First");
  public int OrderNr {
    get { return 1; }

class LevelTwoTrap: ITrap{
  public void Setup(){
    Console.WriteLine("LevelTwo Setup Next");
  public int OrderNr {
    get { return 2; }

Now I want to Setup all trap by respecting it OrderNr which mean LevelOneTrap.Setup() must execute before LevelTwoTrap.Setup() so far so good? Let see how many lines of code needed:

var trapInterface = typeof(ITrap);

var trapImplementations = ( from t in trapInterface.Assembly.GetTypes()
                      where t.IsClass && t.GetInterfaces().Any(x => x == trapInterface)
                      select (ITrap)Activator.CreateInstance(t)

// time to play ;)
foreach( var trap in trapImplementations ) {

//   LevelOne Setup First
//   LevelTwo Setup Next

Cool isn’t it? Life is short so our code!

Written by Chorn Sokun

May 7, 2011 at 12:39 pm

Posted in Programming, Tips & Tricks

Tagged with , ,

How to changing default Khmer Unicode Font in Ubuntu

with 2 comments

In Ubuntu 10.10 release cycle ttf-khmeros version 5.0.3 was included. However the only problem I had with Chrome.  Later on I was told that the fix is by trying various font until we find the one that work properly.

So the idea is to change default Khmer Unicode font so let see how we do it:

sudo gedit /etc/fonts/conf.d/65-khmer.conf

you can replace <family>Khmer OS</family> with <family>Khmer_Unicode_Font_Of_Your_Choice</family> or if you do not want to touch the line you can just add another line on top like this:

<family>Khmer OS</family>

next step issue the following command to update font package:

sudo dpkg-reconfigure ttf-khmeros

logout and log back in again.

Thanks @rithy for sharing this technique.

Written by Chorn Sokun

December 10, 2010 at 8:27 am

Posted in OSS, Tips & Tricks, Ubuntu

.NET Database Application Development (C#)

leave a comment »

If you are interested in .NET and want to jump start with Database Application Development in no time here is your chance

Lady & Gentlemen, boy & girl I present you a .NET Database Application Development (C#) fast track with the following content:

  1. C# Programming Introduction
  2. Introduction to NHibernate .NET Object Relational Mapping (ORM)
  3. Advance Data Processing with NHibernate Criteria API
  4. Hand-on practice

At the end of the course your will learn tools & technique to develop database application which could talk various Database Management System (DBMS) from Microsoft Access, Microsoft SQL Server, MySQL you name it.

Now the truth about doing this in no time :D I lie :-P I need minimum 10 hours before I can transform a newbie into a .NET Database Application Development (C#)


  • Basic Programming Concept
  • Know basic C# Programming
  • Be able to read and understand this blog post – otherwise get yourself English tutor

If you, your friend interested or your employer got budget to develop your capacity drop me a line I would love to hear about it ;)

Written by Chorn Sokun

December 5, 2010 at 4:36 pm