Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

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

 

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

Code Reading Skills for ExtJS newbie

leave a comment »

@samnangchhun wrote a blog post talking about this particular subject, I just want to share my experience exploring a new tool especially the ExtJS library from sencha.com

Now there is something special about sencha.com which I love, they put alot of effort in documenting their library API as well as sample projects in every release.

But like any other developers out there the only page in the document that I would read slowly is getting start, once I could say hello I would try to solve my problem with this new library/framework. That the only way that keep me focus and dig deeper into the document, source code, sample project, testing unit whatever available. At the end of the day I would know that this is the right tool or not.

How do i get this quick in adapting with new environment? I walk the same path as what @samnangchhun described in his blog and I did it enough that I can quick capture the convention and pattern of the thing I want to know. So if you haven’t read enough code do it now ;)

Great weekend everyone.

Written by Chorn Sokun

May 5, 2012 at 4:23 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

[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/com.apple.opendirectoryd.plist
  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 github.com

> git clone git://github.com/mono/monodevelop.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

BOOM !

MonoDevelop 2.8.2
Installation UUID: b220bfc2-57c6-4b94-840e-ff6c6477632d
Runtime:
	Mono 2.10.5 (Debian 2.10.5-1) (64-bit)
	GTK 2.24.6
	GTK# (2.12.0.0)
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)
                  ).OrderBy(k=>k.OrderNr);

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

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

Follow

Get every new post delivered to your Inbox.