Chorn Sokun’s Weblog

try { divide and conquer; } catch { keep it simple!; } finally { nothing is impossible; }

Archive for the ‘Website Development’ Category

Storm the Castle in Action

without 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: http://storm-the-castle.googlecode.com/svn/tags/barcamppp

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

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

  // 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()}
<%
end
%>

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

bugfree

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 (http://code.google.com/p/fbug/issues/detail?id=1473) 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 firebug@software.joehewitt.com 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

[ExtensionDirs]
Extension0=path_to_extension_folder

Written by Chorn Sokun

February 11, 2009 at 9:37 am

ASP.NET Fileupload

with one comment

Call me lazy cuz I am deserved it. It shocked me a bit when a production code crash on my face. As part of my job today I have to train a few admin staffs on how to operate our newly invented site www.ncdd.gov.kh/jobs it works out quiet well on my machine cuz I dev, test & teach on Mozill Firefox. But it turn out that I don’t perform enough exercise cuz I haven’t test the site with IE yeah, cuz I haven’t use IE for almost 3 years enough to forgot about it :)) anyway here is the story.

Do you know this guy System.Web.HttpPostedFile? yeah, he is my best friend when it comes to uploading file in ASP.NET. However you should know that he acted bit strange with browse in used.

Let say file1 is an instance of HttpPostedFile and if we ask him file1.FileName

Firefox return :
Hello My Friend.doc
Nice , isn’t it?

IE return :
“C:\Document & Setting ….\user_name\desktop\Hello My Friend.doc
WWOWO WHAT?! it slap me so hard to make me laugh out loud :))
Not Nice !

Anyway quick fix would be add a small detection on the file1.FileName

int lastDirSeparatorChar = file1.FileName.LastIndexOf(Path.DirectorySeparatorChar);

if (lastDirSeparatorChar > 0) {
  filename = file1.FileName.Substring(lastDirSeparatorChar + 1);
} else {
  filename = file1.FileName
}

Lesson learn – test dev. site with IE as much as I hate “IE”

Written by Chorn Sokun

February 1, 2008 at 5:40 pm

Freedom Mission "Reclaim my Port"

without comments

Being a geek, I do not want to fall in out of control situation while still standing on the cutting edge.
What you say running multiple web server on a single machine? Can I run multiple web server simultaneously? Yeah, why not? no big deal … okay

But hey! Do I really need all web servers to run concurrently? for me I do not opt for that.
My ego is to load service as minimum as necessary to perform a certain task.

Anyway now look at what I got?

  1. IIS 5 – for ASP.NET development
  2. XAMPP – for PHP4 or 5 development + some other scripting
  3. Tomcat 5.5 – well since my favorite IDE(s) love it so much why can’t I do it a favor?

Am I nut? why not configure all the development with single web server let say IIS.
Because I do not want to waste my time tracing out problem where it shouldn’t occur… let children stay with their parents.

What the problem anyway?
Well simple, each web server will fighting for their seat “port(s)”. IIS & XAMPP will try to take over ports 80, 443 etc where in case Tomcat 5.5.x is more polite by asking for a safe seat.

So what I do?
Okay, I pretend to be a traffic police officer by simply say …

  1. IIS – listen at port 8080 (http) & 443 (https)
  2. XAMPP, Apache – listen port 80 (http) & 8443(https)
  3. Tomcat 5.5.x – this guy know that he always come last so he ask for higher port but I simply give it 8181 (http)

To spare my laptop batter non of these guy will ever load without my permission.
Even now it safe to load all web server simultaneously, I prefer not to do so.

I am a happy man?!
Yeah, I do until today I need to work on my PHP project suddenly XAMPP, Apache just ignore my command and complaint I giving it ports to another guy???? what the heck?
Anyway, checking Event log confirm that port is already in use. Who dare use the ports without asking me? by invoke portcheck tool ship with XAMPP I found that Skype 3.2.0.145 had take over port 80 and 443 aha…

Now it time to fight for freedom, I simple reclaim the ports back by disable listening port in the Skype: Tools > Options > Advanced > Connections…

Lucky that Skype only take these port as an alternative otherwise trouble.

Written by Chorn Sokun

May 19, 2007 at 10:58 am

Posted in Tips & Tricks, Tools, Website Development

Tagged with

Introduce to www.a-kdam.com

without comments

The project is started, I am proud to present to you a free computer programming language turotial in Khmer language online.

Lady & Gentlement: អាក្តាម (beta)

Written by Chorn Sokun

April 19, 2007 at 11:55 am

When Open Source Culture got into my brain…

with one comment

From day to day I got new knowledge from the open source project as well as the open mind of the guru out there “Cyberspace”. I don’t even have a chance to see them in personal, but I do appreciate their brilliant contribution to the people knowledge all over the world.

In line with this I would like to extend the culture of sharing knowledge to my citizenship, but I will do it a little bit different. Instead of giving them a Hello World kind of thing tutorial I will try to bring concept to into their brain and let them growth the way I do.

I will bring my imagination to live through a project call “a-Kdam“, which is currently under-development.

I will announce the URL one the website is up and running.
Until then …

Written by Chorn Sokun

April 9, 2007 at 4:45 pm

It just another day for celebration

without comments

It’ve been quiet a while since my previous blog. I haven’t got much time to blog since. The reason is that Seila Programme/PLG is ended and most of the staff is carry on with the new program known as NCDD/PSDD believe me you don’t want to read it full word :D

So in the new home I have to design website development proposal for my organization it kind of :( when I have to deal with government high ranking staffs.

Anyway, after work time I still have to enjoy working on my private business.
Well you guess it nothing more than software development. As of right now I am waiting for WS_FTP transferring my 80% work in progress into the Internet. I know it a mess but I have no choice I got 3 days deadline to stadesign/coding the entire site.

So how I did it?
1. Fire up Adobe Photoshop & Draw a few thing up
2. Get my client feedback & finalize
3. Convert .PSD file into HTML format
4. Restructure HTML code generated by Photoshop wire up CSS :D
5. Stick it to my lovely PHP Framework
6. Plug-in additional features requested by my client
8. Loading their spreedsheet into MySQL table ;) my expertise
7. BOoM !

Can I impress my client their annual meeting + website launching is tomorrow 30-March-2007
Geez, I forgot to tell you I got some task tonight that mean I can’t sleep well until the 30th past.

Written by Chorn Sokun

March 29, 2007 at 6:12 pm