Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for September 2008

Screencast TortoiseSVN Intro

with 2 comments

This is my first screencast uploaded on YouTube don’t know why the video quality was reduced check this out

Anyway this is just a preview see how it works if you happen to know a better way to publish the video “to get high quality, which exclude solution to host file on my own server :)” and where still open for me to embed the file in my blog please knock me up.

Ah huh! want to try high quality video? get it here To view the downloaded version you must first download and install the Techsmith Video Codec (160 K)

Written by Chorn Sokun

September 28, 2008 at 9:35 pm

Posted in Geek, Tips & Tricks

Tagged with ,

Raising the Dark Army

with 5 comments

I never regret to step my feet into programming world back in 1997. My first experience using notepad to script out (HTML) website. I don’t remember how many times I skew up my brother’s computer just to figure out a thing no matter how hard he try to avoid me. 

Rewind for the last 10 years I keep pushing myself up step by step no matter how hard, stressful I got I never give up. 10 years? Yeah I know my brain deserved a major upgrade perhap replacement of RAM, CPU Squad Core or something :) But see it took me so long to get to this stage where I legendary programmers abroad take much shorter time to advance their skills.

You may compare my learning experience to a single pig raising in a big farm, the lack of physical interaction, challenge and guiding is the main source preventing it from fast growth. But that are all history today I am so happy, because I am no fall into those mind set and I am not alone, ladies & gentlemen the dark army is rising. 

Dark Army

Dark Army, taking on TDD & DDD

This is the 5th session that they all come together and learn .NET programming C# and I glad to become their instructor as much as I enjoy walking them through the learning curve. Although it is a programming course we don’t talk much about syntax sugar or debate about how it was designed because it doesn’t give much value in real world once it’s time to get down to business so what they need to learn are concepts and tool set for rapid application development.

I want to see some new face as well but it doesn’t seem to work out just yet :) but again we please to invite you to join our journey anytime just keep you eyes on our public calendar.

Let the spirit of sharing growth among Cambodian, let us all create an opportunity for our young generation to extend what we had discovered.

Written by Chorn Sokun

September 27, 2008 at 10:34 pm

Castle Routing Module

with 5 comments

In previous post I was talking about the beauty of MR Controller which I also mention about Routing feature of Castle MonoRail Framework. Today I am going to walk you through basic steps to configure environement, define and register MR Routing.

Step 1: Start with web.config by adding the following line into system.web\httpModules section

<add name="routing"
  type="Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework" />

Step 2: Define routing rules, base on Hammett suggestion I am going to create a static class for handling this task

// filename: RoutingRules.cs
using Castle.MonoRail.Framework.Routing;

public static class RoutingRules
    public static void Register(IRoutingRuleContainer rules)
	  rules.Add(new PatternRoute("<controller>/[action]")
	// you can add as many rules as you want

Step 3: Register rules, this have to be done once and the best place for that is in Global.asax using its’ Application_Startup event

public class Global : HttpApplication
    public override void Application_Start(object sender, System.EventArgs e)
        base.Application_Start(sender, e);

And that about it. Oh by the way if you are like me. I am a big fan of UrlHelper class and I’m addicted to this macro:

// generate url /product/list<.extension>
${Url.For({@controller: 'product', @action: 'list'})}

And if you do not want to gernerate url with extension /product/list then you have to take another step by adding the following line to monorail configuration section in the web.config

Step 4: Remove extension from generated url

<monorail defaultUrlExtension="">
    <!-- other configuration removed -->
    <url useExtensions="false"/>
    <!-- other configuration removed -->

Now do you have any specific routing rules wanted to discuss? It’s time to dig in ;)

Ken Egozi also had an interesting post related to this topic.

Written by Chorn Sokun

September 24, 2008 at 11:09 pm

jQuery ajaxform generate on the fly

with 2 comments

What scripting language would come to your mind first when you begin to talk about client-side scripting (web)? Don’t tell me it is VBScript or I’ll LOL, and so your answer would be? “JavaScript” alright +1 from me :). I believe most of the programmer who is reading this post knowing/aware of jQuery.

I can extend the talk about jQuery into a series of posts but I am not gonna do that because google would give you millions of result about jQuery and it usage.

Today what I am interested to talk about is using jQuery ajax functionality in conjunction with Castle.MonoRail to generate HTML Form on the fly and the form will also has ajax functionality. What does it mean? well let us all get into application context of adding new customer. In general we are going to have a customer page /customers which list all existing customers in a table format. Additional customer can be added by clicking on Add New Customer link wired up with a javascript function.

<a href='#' onclick='addNewCustomer()'>Add New Customer</a>

and the addNewCustomer() function looks like this:

<script language="javascript"> 

function addNewCustomer(){

      dataType: 'script',
      url: '/customers/addNewCustomer'



From the above script the web browser going to send off a request to /customers/addNewCustomer which is going to handle by an action of CustomersController. If you care to see the action code it look like this:

[Layout("default"), Rescue("generalerror")]
public class CustomerController: SmartDispatcherController
    .... code removed for clarity 

    public void AddNewCustomer(){

        PropertyBag["c"] = new Customer();


    .... code removed for clarity


and the rest of the work will be left over to the view engine to find the view template file and process it. Since I am a big fan of Brail View Engine the template file would be call AddNewCustomer.brail and the code look like this:

<form id='form1' method='post' action='/customer/create'>

   Name: ${Form.TextField("c.Name")}
   Phone: ${Form.TextField("c.Phone")}
   <input type='Submit' value='Create New' />


<script type='text/javascript'>


      $('#form1').ajaxForm( { dataType: 'script' } );



Again it just simple HTML markup mixed with a few Brail’s tagging macro but take a closer look at the javascript code at bottom, what does it do? Well the idea is once the template is processed it going to generate a pure HTML form and send it back to the client side, however the javascript that send along will ensure that the new generated HTML form will perform a post back via jQuery ajax functionality. Hmm, sound cool. But didn’t I just waste a bytes of data with this approach? I tell you what, this application is going to run on a LAN so bandwidth is not a problem.

Up to this point everything works perfect, except for one final click on the Submit button to save new customer and oop! look there is a post without ajax It just work as normal as any other HTML form submission. Hmm, what I had discovered was by generating form id=’something’ or whatever as long as it is not id=’form1′. The submission of the form will route through ajax weir isn’t it? I haven’t investigate into jQuery code just yet jQuery might use form1 for something else internally, do you know what it is?

UPDATE 2008-11-25:

I believe my first assumption about form id attribute which cause ajax not to fire was wrong. What I recently found was if I am not calling $(document).ready(…); in the original page the generated dom pass in even if it contain $(document).ready(…) script block that block just do nothing.

Written by Chorn Sokun

September 21, 2008 at 9:27 pm

Posted in OSS, Programming, Tips & Tricks

Tagged with , ,

StackOverFlow Gentlements, & Ladies

leave a comment »

I hang around in recently and I wanted to wait long enough so that I can describe how the experience like G do I ever told you I hate sleeping? but it seem like Jeff Atwood also doesn’t sleep & blogging; so why don’t we just read what he got to say about his toy shall we?




Written by Chorn Sokun

September 20, 2008 at 6:16 am

Posted in Geek, OSS

Tagged with

REST, Routing & the beauty of MR Controller

with one comment

What is REST?

REST stands for Representational State Trasfer an important concept in REST is the existence of resources (sources of specific information), each of which is referenced with a global identifier (e.g., a URI in HTTP).

How does it work?

REST take advantage of HTTP methods such as POST, GET, PUT and DELETE and translate the request as CREATE, READ, UPDATE, DELETE (CRUD) operation associated with database technologies.

POST Create, Update, Delete
GET Read
PUT Create, Overwrite/Replace

REST application might define resources URI such as:

and client code would look something like this:

Resource userResource = new Resource('');

It is simple enough, right?

RESTful Castle

REST needed URI to begin with; now if you are assigned to design a server side code for that what are you gonna do? Well, you simple need an URL Rewrite tools to save day, don’t you? So what does URL Rewrite tools do? Simply it would intercept incoming HTTP request and route to relevant destination (.php, .cgi, .aspx, .asmx scripts etc). It is pretty trivial to do it on apache web server:

  1. Make sure mod_urlrewrite is enabled
  2. define a few rules in .htaccess (hmm, regex not so funny)
And that all you need. But I am not talking about Apache I am now going to talk about .NET and the IIS to be exact I am talking about Castle.MonoRail. Castle.MonoRail is a MVC framework (MVC stands for Model-View-Controller) and I am going to dive a bit into Controller. According to the document a Controller logically grouped in an Area; and it contains Actions. For instance to produce url like this /admin/users/index.rails we simple define a controller class as:
public class UsersController : Controller
   public void Index()

Notice the use of ControllerDetails attribute which usually allow you to tell MonoRail how a controller can be found. The important part of ControllerDetails above is Area = “admin” which is very flexible and that mean you can burried a controller down as deep as you want it to be.

Is that mean I can have a controller defined and it will generate URI like this?

With controller alone? you basically can’t do, because controller generated URI in the form /area/controller/action.rails?id={id} to do a nice RESTful like URI you need another tool similar to URL Rewrite lucky enough MR got a build-in tool for that it located here Castle.MonoRail.Framework.Routing … going to talk more in the future.

Limitation & Workaround

How are you going to define your controller class to fullfill the required like this?

* Public Access

* Authorization Access

Look at the screenshot bellow:

and you say; hell YEAH that neat right; now compile and run the test site. Navigate to /album/index.rails work unfortunately navigate to /users/albums/index.rails will cause MR to throw an exception say it can’t find Area & Controller specified.

What the hell ??? the truth is MR register a controller using class name as a key I believe it run from the top namespace first which mean Basic.Web.Controllers.AlbumController got register first so when it walk into Basic.Web.Controllers.Users.AlbumController it just skip that controller.

To work around this problem against thank to ControllerDetailsAttribute which allow us to name a controller free from Controller class. How are you going to do that? well rename /users/AlbumController.cs to /users/WhatTheF_CKAlbumController.cs and boom it done.

[ControllerDetails("album", Area="users")]

public class WhatTheF_CKAlbumController{

    ... same code old code


Get lost? probably :) but don’t worry I am going to give a slow version in my C# lecturing session and if you are interested to walkin and listen up just subscribe to my google calendar.

Until then have a good weekend.

Written by Chorn Sokun

September 20, 2008 at 6:01 am

Posted in MonoRail, OSS

Tagged with , ,

Credit where credit is due

leave a comment »

It is the great honor to read a story behind the man behind Cambodian Open Source Software movement. I really appreciate all the hard work that the people at NiDA especially Mr. Noy Shoung had done to put Cambodian inline with the rest of the world.

Father of Cambodian Open Source Software

Father of Cambodian Open Source Software

Noy is the Deputy Secretary General (In Charge of Human Capacity Building and Free/Open Source Software) at National ICT Development Authority (NiDA). Cool title to have. And, one that is hard earned. Noy’s built up a team inside NiDA to localize open source desktop apps into Khmer (a language too small to be interesting to Microsoft), build up open source development skills amongst young people (still early days on this one) and train end users on Linux, Open Office and Firefox (20,000 people and counting). He’s also the major champion behind Khmer OS, a localized OpenSuse distribution.

full article here don’t forget my dear friends cheer him up with your comments.

Written by Chorn Sokun

September 18, 2008 at 9:18 am

Posted in OSS

Tagged with ,

the most exciting second

leave a comment »

Do you hate yourself by letting the second passed and turn into hours? If there was an intellisent or syntax checking exist I may had supressed the hours back down to second.

Oh ! dear …

If it always work; but not here ….
                    beware of your typos

/* the wrong version */
component SmartGrid, {@source: listOfData, @column: [@Id, @Name]}

/* the correct version */
component SmartGrid, {@source: listOfData, @columns: [@Id, @Name]}

Written by Chorn Sokun

September 16, 2008 at 4:44 pm

Posted in MonoRail, Tips & Tricks

Tagged with

Oh! dear MySqlGuid

leave a comment »

If you are a DBA operating SQL Server you know what I am talking about the Guid Data Type; and ever wonder how to port Guid column into MySql? It was such a pain right na not anymore here come the cure … 

MySql connector-net

MySql connector-net

Now I need not worry about porting my legacy data into MySql ;) stay tune.

Written by Chorn Sokun

September 14, 2008 at 11:32 pm

Posted in OSS, Programming

Tagged with , ,

Subversion is not alone, do you?

leave a comment »

I am a big fan of Subversion (SVN) I use it mainly for checking out .NET OSS projects that I am interested in as well as to manage my day to day projects. Although Subversion is not the only file version control solution in the whole wide world but it just works so while border :( ah huh it doesn’t hurt a married man knowing pretty girls right ;) “I hope my wife do read this post, LOL”.

So a quick googling I got 2 links which buy me alot as saying said “Seeing is Believing” right? then just watch the screencasts … oh ! by the way no sheep get hurt during production lolz

Written by Chorn Sokun

September 13, 2008 at 8:59 am

Posted in Tools

Tagged with , , , ,