Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Archive for the ‘Website Development’ 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


with one comment

Out of my boredom I usually tune in some random Khmer Oldies Songs just to remind myself the glorious era where sound of the music would flew into the deepest of my heart and cheer me up. What I did in the pass was collect all my favorite songs and classified it manually and sometime after clean up my station I let iTune screw up my collection a big pain in the a^^ and as my habit of trying out new os release like Ubuntu every 6 months I got to remind myself backup the music collection before I do something silly. That works out quiet well until I am get lazy and decided not to waste my time move back and force I truth the Internet to play me my favorite songs :) which mean I optimize my money Internet expend when I am not using it for some secrecy works ;)

How it works out for me? YouTube! Yeah, what can’t be find on YouTube right? Except that streaming video on my connection is damn slow and like chopping my head every time the buffer loading. So I tried something lighter pure sound and that tons of site offer free mp3 and I do enjoy using those site which some of you may already know and love. But I am just too demand I want some control over what I want to listen, I want to be able to easily share my playlist with my close friends so they can rejoice in hearing the songs. It turn out that a few site does offer these ability, why am I still not happy? Because the site need to know about me want me to become a member and I kind of like what the f???ck. It like I have to tell my radio who I am before it play me the song kind of thing.

So enough is enough, I thought to myself “look geek if it doesn’t work out, do it yourself” ah huh, that was what I use to talk with my dest friend (sad he’d gone) why don’t we do something about it, It’d be fun. Now that I am bored it justified enough that I block sometime to deliver our plan and so I start prototype the project #sidekick and show it to a few friends get their feedback some -/+ and finally I got it out of the door “JolJET Hits” or should I call it “JolJET Hits Online Music Player” still have an issue of naming it properly but here how it looks:

JolJET Player v2

JolJET Player v2

A typic music player portable as it should be since it developed using HTML 5 and Sencha ExtJS technology blah blah blah not so interesting for an engineer to talk about tools. But hey it’s not bad for the cost of home stay during Khmer New Year instead of enjoying myself sight seeing Thansur Bokor Resort and weeks after to stabilize. But as the passion fill up I glad I spend my time develop this little product so that what I can do now:

  • On first visit to the site the app will load up default playlist fill with about 250 songs enough  if you want to just hear some noise the whole day
  • If you so obsess about what you want to hear then Clear all and start adding your favorite songs from: a) Library b) Artist Collection or c) Blind search
  • when you found it select it (multiple select is supported) and click on Add to playlist to append selected song to your current playlist
  • or if you so want to hear the song immediately just double click it and you got it
  • Not just that if your like to listen to the music during your work hours (I usually did :D) close your browser as soon as your boss walk to your desk, and revisit the site after he/she gone nice trick yeah ;) who never cheat. But I had implemented is the app will remember not only your selected song but it remember your last play song and resume it for you (Thanks Sothy Chanty for  his suggestion)
  • But how about I want my friend to listen to a song. NO NOT 1 songs my collection, well we got you covered from Now Playing tab you find a menu call Sharing just select your favorite sharing technical twitter/facebook and you done

Now that more like an ado why don’t you jump to the site and experience it yourself? Here the link as always I love to hear your comments/suggestions you can do it here or post on facebook page

Hope you enjoy the sound LIKE if you LIKED for sharing is caring and have a great weekend ;)

Written by Chorn Sokun

May 5, 2012 at 12:05 am

.NET developer survive on linux

leave a comment »

I’ve been joking with my friends “the open source fan boyz” that I am a Microsoft slave for the fact that I am a dedicated .NET developer. But for all the joke I found some competitive disadvantage for me moving forward. If customer is looking for a low cost solution .NET is not the way to go. Base on what I do for a living, I build desktop and web application in .NET. But I tend to focus more on Web Application which dragged me to ASP.NET MVC.

Let taking ASP.NET MVC to build solution for me it yield a great ROI for me

  1. I got to learn more about .NET library
  2. it still .NET so I can use all the skill I got
  3. got great IDE support => productivity is high so and so …

for clients :/ intranet deploy

  1. invest on the server hardware (normal)
  2. software license just take Microsoft Windows Server + SQL Server hmm

and for Internet deploy ASP.NET hosting generally more expensive than LAMP stack. If I am about to help client cutting down expenditure cost I got to get rid of the underline infrastructure need to run the application. Possible with Mono but I am keep hearing incompatible issues on ASP.NET + Mono.

Anyway let me (us) forget all about ASP.NET glorious day. Recently, I start caught up with a movement in two different communities. Both of them trying to escape from ASP.NET sandbox and they both  gave birth to two unrelated open source projects manos and Nancy that the cool part.

These two project promised to free its user from underline infrastructure (no more IIS is required!) and it work x-platform.

Up to this point I can only make manos serve page, I am keep watching and follow-up with Nancy development. I hope to be able to compare advantage and disadvantage between the two projects in the future.

“Nancy start with a full range of view template to choice from, and I do not think it hard for manos to do the same thing”.

Which one is the best? is not really important at this point, what important is when these projects are matured we can use it to build low cost solution for my clients while still enjoy writing C# “YES, it pronounced C-Sharp” :D, but how? Here the spec

  • Web Application power by [manos | Nancy] + a few open source libraries
  • Mono 2.8.x or higher
  • Server OS OpenSuse 11.13
  • Back-end database name a few open source DBMS

Why OpenSuse? it is mono home’s os, and if you want to get hot-fix on time that the way to go. So let me end this blah blah post with a teasing screenshot!

Hello World from manos running on OpenSuse 11.13 inside VirtualBox, client access from Ubuntu 10.10 if you care about the environment :D

There you go it’s how a .NET developer survive on linux nice hacking weekend everyone!

Written by Chorn Sokun

January 22, 2011 at 10:36 pm

Mocking ASP.NET MVC 2 Context & Session using RhinoMock

leave a comment »

Watching video record from #mvcconf about “Making ASP.NET Apps Testable” by Eric B. Sowell. He showing how to test ASP.NET MVC Session make me wonder how difficult it is for RhinoMock so I load sample app and here how I test it. Since

public void TestSession()
   // Arrange
   // HttpContextBase, HttpSessionStateBase are abstract classes
   // I can ask RhinoMock to generate stubs for those classes
   var httpContext = MockRepository.GenerateStub<HttpContextBase>();
   var session = MockRepository.GenerateStub<HttpSessionStateBase>();

   session["Name"] = "Sokun";
   httpContext.Stub(c => c.Session)

   // act
   controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller);
   var result = controller.TestSession() as ViewResult;

   // assert

and the action:

public ActionResult TestSession()
   ViewData["Name"] = Session["Name"];
   return View();

So, what you think? it just fine to love ASP.NET MVC 2

Written by Chorn Sokun

July 26, 2010 at 10:45 am

Storm the Castle in Action

with 2 comments

felt bore today and decided to tune into studio and record some stuff :D hope you enjoy it.

I know, I know the quality is bad but I don’t know I am not do much with youtube so it the luck I get :) BUT as always orginal video can be download here.

Source code:

Written by Chorn Sokun

October 23, 2009 at 5:50 pm

PHP date diff

with 2 comments

I call out for an excuse for not practicing PHP enough recent year; with just a simple date_diff could knock me out :) not to open my complain of having different version of PHP to check before using a function(s) I got a request from a friend to help workout how many days from two given date.

Now if I have two date string (it is what we get from form post right?)

// fixed format as I don't want to deal with complicate of different world format :(
$day1 = "26/03/2009";
$day2 = "28/03/2009";
// now I need to know how many days does it take from day1 to day2
// PHP 4.x; ignore my out of date PHP skill this is how I did it
$break_day1_apart = explode('/', $day1);
$break_day2_apart = explode('/', $day2);
$day1_number_form = $break_day1_apart[2].$break_day1_apart[1].$break_day1_apart[0];
$day2_number_form = $break_day2_apart[2].$break_day2_apart[1].$break_day2_apart[0];

$day_diff = abs((int)$day2_number_form - (int)$day1_number_form);

// and it should work by theory
echo $day_diff; 

Suck ! what would you do instead?

Written by Chorn Sokun

July 4, 2009 at 11:37 am

Rhino-Tools a smarter Guard

with 4 comments

When Ayende typed Guard.Against(condition, error_message) it clicked in my brain. I thought wow that was nice and easy to use what it does was check if the condition is true it will throw and exception with error message specify. I had an idea using this litle beast for business validation, since it doesn’t required any special configuration all you have to do is adding reference to Rhino.Common.Clr.dll.

However the original Guard API only has only two static method Guard.Against() it was limited for web application. In web application we might want to report back all problems so user can make the correction before they re-submit the form again, but using Guard.Against() we only catch one problem at a time, if we have multiple codition to check you can imagine how annoy for web experience.

Ayende is kindly enough accepting my patch for two additional method for the Guard bellow:

  • Guard.Check(condition, error_message) – same behavior as Guard.Against() but it won’t throw and exception instead keeping records of problems
  • Guard.Report() – until .Report() get call and exception known as GuardSpotException will be throw.

Let see how I can improve my usage experience with these methods

  new Guard()
    .Check(pay.Date.Equals(DateTime.MinValue), "Invalid payment date.")
    .Check(pay.Amount == 0, "Invalid amount, should it be something other than zero?")

  // persist pay instance to the database
catch(GuardSpotException ex)
  // list of errors message
  PropertyBag["errors"] = ex.GetErrorSummary();

First I instantiate a new Guard object and start checking conditions (business rules) finally I call Guard.Report() if there is any true condition (= business rule voilated) and exception known as GuardSpotException will be throw you then can catch and examin all problems.

Isn’t that cool?

Written by Chorn Sokun

April 10, 2009 at 10:37 am

Brail Daily Use Macros #2

with 2 comments

Imagine you had to associate multiple skill to your “Profile”

Multiple skill

Suppose we have the following Profile & Skill class

class Profile {
  public virtual int Id { get; set; }
  public virtual string Name { get; set; }
  //.... other properties as necessary
  public virtual IList<Skill> Skills { get;set; }

// a lookup class per say
class Skill {
  public virtual int Id { get;set; }
  public virtual Profile { get; set; }
  public virtual string Title { get; set; }

Assume that we know how to apply AR attribute on these two class make it persist able to a database. The important thing is Profile has many Skills that all you have to concentrate on right now.

Ok ! today recipe is to generate UI with checkbox which allow user to tick and save the choices without any hassle. With the help of FormHelper method YES, WE CAN

list = Form.CreateCheckboxFieldList("p.Skills", skills, {@text:'Title', @value:'Id'})
// we need a loop
for item in list:
  ${list.Item()}  ${item.ToString()}

Don’t panic let me explain a bit ${list.Item()} will generate individual html checkbox where ${item.ToString()} will generate a label for each one.

Written by Chorn Sokun

March 16, 2009 at 5:00 pm

Life without Firefug

with 3 comments


I shouldn’t complain about this since I accept the fact to run on Windows 7 beta build. I wouldn’t get support from third party software just as fast as I want.

But I believe eventually thing will get back on track. However I am suck at the movement I wonder if it was just me who rant into this problem ( or it just “the bug to be”?

Anyone know any other Firefox extension with similar functionality of Firebug? where I can use temporary to debug ajax request?

UPDATE:  2009.03.03

I had manually install Firebug by copy extracted file from my colleage computer located in
C:\Users\<user>\AppData\Roaming\Mozilla\Firefox\Profiles\<profile>\extensions\ usually Firebug file stored in a folder, so just copy the folder and paste it into your Firefox profile.

Hmm, next is to modify extensions.ini located in C:\Users\<user>\AppData\Roaming\Mozilla\Firefox\Profiles\<profile>\ to something like this


Written by Chorn Sokun

February 11, 2009 at 9:37 am