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>
</select>

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

 

Advertisements

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(
      'accessControl',
      '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
      parent::accessRules()
    );
  }
}

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

Play!

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 http://play.joljet.net as always I love to hear your comments/suggestions you can do it here or post on facebook page http://www.facebook.com/play.joljet.net

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

[Test]
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)
      .Return(session);

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

   // assert
   Assert.IsNotNull(result);
}

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: 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