<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.rudylee.com</title>
	<atom:link href="http://blog.rudylee.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rudylee.com</link>
	<description>keep it humble</description>
	<lastBuildDate>Mon, 27 May 2013 01:16:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Playing with Google Map API</title>
		<link>http://blog.rudylee.com/2013/05/27/playing-with-google-map-api/</link>
		<comments>http://blog.rudylee.com/2013/05/27/playing-with-google-map-api/#comments</comments>
		<pubDate>Mon, 27 May 2013 01:16:02 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=1074</guid>
		<description><![CDATA[The main purpose of this post is only to write about Google Map API for future reference. Here are the code snippets : Get the latitude and longitude based on address : http://maps.googleapis.com/maps/api/geocode/json?address=435A%20Kent%20St&#38;sensor=true The code below set up the Google Map, put the marker and also make it grayscale function initialize() { var map; var location ...<p><a href="http://blog.rudylee.com/2013/05/27/playing-with-google-map-api/">Playing with Google Map API</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>The main purpose of this post is only to write about Google Map API for future reference. Here are the code snippets :</p>
<p>Get the latitude and longitude based on address : <a href="http://maps.googleapis.com/maps/api/geocode/json?address=435A%20Kent%20St&amp;sensor=true">http://maps.googleapis.com/maps/api/geocode/json?address=435A%20Kent%20St&amp;sensor=true</a></p>
<p>The code below set up the Google Map, put the marker and also make it grayscale</p>
<pre class="brush: javascript; gutter: true">                function initialize() {
                    var map;
                    var location = new google.maps.LatLng(-33.87190930, 151.20480740);
                    var styles = [
                        {
                            featureType: &quot;all&quot;,
                            elementType: &quot;all&quot;,
                            stylers: [
                                { saturation: -100 }
                            ]
                        }
                    ];

                    var mapOptions = {
                        center: location,
                        zoom: 17,
                        mapTypeControlOptions: {
                            mapTypeId: [google.maps.MapTypeId.ROADMAP, &#039;theGray&#039;]
                        }
                    };

                    map = new google.maps.Map(document.getElementById(&quot;map-canvas&quot;), mapOptions);
                    var mapType = new google.maps.StyledMapType(styles, { name:&quot;GrayScale&quot; });    
                    map.mapTypes.set(&#039;theGray&#039;, mapType);
                    map.setMapTypeId(&#039;theGray&#039;);

                    marker = new google.maps.Marker({
                        position: location,
                        map: map
                    });
                }
                google.maps.event.addDomListener(window, &#039;load&#039;, initialize);</pre>
<p><a href="http://blog.rudylee.com/2013/05/27/playing-with-google-map-api/">Playing with Google Map API</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/05/27/playing-with-google-map-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Override module config in Zend Framework 2</title>
		<link>http://blog.rudylee.com/2013/05/16/override-module-config-in-zend-framework-2/</link>
		<comments>http://blog.rudylee.com/2013/05/16/override-module-config-in-zend-framework-2/#comments</comments>
		<pubDate>Thu, 16 May 2013 01:12:19 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[Zend Framework 2]]></category>
		<category><![CDATA[access password]]></category>
		<category><![CDATA[alphanumeric]]></category>
		<category><![CDATA[api access]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[heaps]]></category>
		<category><![CDATA[maintenance nightmare]]></category>
		<category><![CDATA[numerical characters]]></category>
		<category><![CDATA[rudy]]></category>
		<category><![CDATA[staging]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=1063</guid>
		<description><![CDATA[There is a time when you want to override module config in your Zend Framework 2 application. In my case, I have different configuration for SMS gateway in staging and live server. You can do this by overwriting the module.config.php file inside the module config&#8217;s folder. However, there are heaps of configuration inside module.config.php file. This ...<p><a href="http://blog.rudylee.com/2013/05/16/override-module-config-in-zend-framework-2/">Override module config in Zend Framework 2</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>There is a time when you want to override module config in your Zend Framework 2 application. In my case, I have different configuration for SMS gateway in staging and live server. You can do this by overwriting the module.config.php file inside the module config&#8217;s folder. However, there are heaps of configuration inside module.config.php file. This approach will lead to maintenance nightmare when you need to change one or more configuration inside the file.</p>
<p>The cleanest approach is to override specific configuration key by creating module-name.local.php file inside config/autoload folder. For example, you have &#8220;Admin&#8221; module and here is the sample module.config.php file :</p>
<pre class="brush: actionscript3; gutter: true">return array(
    &#039;sms&#039; =&gt; array(
        &#039;username&#039; =&gt; &#039;rudy&#039;, //API access username
        &#039;password&#039; =&gt; &#039;rudy&#039;, //API access password
        &#039;sender&#039; =&gt; &#039;Rudy&#039;, // max of 11 alphanumeric or max of 15 numerical characters
    ),
);</pre>
<p>You can override only the username by creating admin.local.php file inside config/autoload folder and put this code inside it :</p>
<pre class="brush: php; gutter: true">return array(
    &#039;sms&#039; =&gt; array(
        &#039;username&#039; =&gt; &#039;override&#039;, //API access username
    ),
);</pre>
<p>Zend Framework 2 will read this file and overwrite the username key inside module.config.php. Now you can create script during your deployment process to create this file automatically.</p>
<p><a href="http://blog.rudylee.com/2013/05/16/override-module-config-in-zend-framework-2/">Override module config in Zend Framework 2</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/05/16/override-module-config-in-zend-framework-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework 2 : The proper way to set application path in Javascript Object</title>
		<link>http://blog.rudylee.com/2013/05/06/zend-framework-2-the-proper-way-to-set-application-path-in-javascript-object/</link>
		<comments>http://blog.rudylee.com/2013/05/06/zend-framework-2-the-proper-way-to-set-application-path-in-javascript-object/#comments</comments>
		<pubDate>Mon, 06 May 2013 04:44:36 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[Zend Framework 2]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[application path]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[basepath]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[cdata]]></category>
		<category><![CDATA[long time]]></category>
		<category><![CDATA[lt]]></category>
		<category><![CDATA[script type]]></category>
		<category><![CDATA[text javascript]]></category>
		<category><![CDATA[website register]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=1058</guid>
		<description><![CDATA[Storing application path inside Javascript object is a way to avoid &#8220;hard coded&#8221; URL inside your Javascript file.  It is pretty common to have like this in your Javascript file : $.ajax({ type: POST, url: &#039;http://localhost/my-website/register&#039;, data: dataJSON }) That approach is completely fine. However, when you need to deploy your application, you need to manually change ...<p><a href="http://blog.rudylee.com/2013/05/06/zend-framework-2-the-proper-way-to-set-application-path-in-javascript-object/">Zend Framework 2 : The proper way to set application path in Javascript Object</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Storing application path inside Javascript object is a way to avoid &#8220;hard coded&#8221; URL inside your Javascript file.  It is pretty common to have like this in your Javascript file :</p>
<pre class="brush: javascript; gutter: true">$.ajax({
    type: POST,
    url: &#039;http://localhost/my-website/register&#039;,
    data: dataJSON
})</pre>
<p>That approach is completely fine. However, when you need to deploy your application, you need to manually change all the URL to match with your server. The solution that I have been using for quite a long time is setting up Javascript object that contains path to my application.</p>
<p>In CakePHP, this can be easily done by using URL method inside Router Class. Here is the sample :</p>
<pre class="brush: javascript; gutter: true">$cbunny = array(
    &#039;APP_PATH&#039; =&gt; Router::url(&#039;/&#039;,true)
);
echo $this-&gt;Html-&gt;scriptBlock(&#039;var CbunnyObj = &#039; . $this-&gt;Javascript-&gt;object($cbunny) . &#039;;&#039;);</pre>
<p>In Zend Framework 2, you have to rely on serverUrl and basePath to achieve the same thing. Here is the proper way to do it in Zend Framework 2 :</p>
<pre class="brush: javascript; gutter: true">        &lt;script type=&quot;text/javascript&quot;&gt;
            //&lt;![CDATA[
                var CMSObj = {
                    &quot;APP_PATH&quot;:&quot;&lt;?php echo $this-&gt;serverUrl() . $this-&gt;basePath() ?&gt;/&quot;
                };
            //]]&gt;
        &lt;/script&gt;</pre>
<p>&nbsp;</p>
<p><a href="http://blog.rudylee.com/2013/05/06/zend-framework-2-the-proper-way-to-set-application-path-in-javascript-object/">Zend Framework 2 : The proper way to set application path in Javascript Object</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/05/06/zend-framework-2-the-proper-way-to-set-application-path-in-javascript-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My review after two months using VIM</title>
		<link>http://blog.rudylee.com/2013/03/30/my-review-after-two-months-using-vim/</link>
		<comments>http://blog.rudylee.com/2013/03/30/my-review-after-two-months-using-vim/#comments</comments>
		<pubDate>Sat, 30 Mar 2013 12:35:41 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[Unix and Linux]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=1039</guid>
		<description><![CDATA[On January ( Two months ago ) , I decided to learn Vim after watching screencast from Destroy All Software. In one of the screencast, the guy shows how fast you can program when using Vim and use plugin to make it even better. I have known Vim for 4 years now but never actually ...<p><a href="http://blog.rudylee.com/2013/03/30/my-review-after-two-months-using-vim/">My review after two months using VIM</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>On January ( Two months ago ) , I decided to learn Vim after watching screencast from <a href="http://www.destroyallsoftware.com">Destroy All Software</a>. In one of the screencast, the guy shows how fast you can program when using Vim and use plugin to make it even better.</p>
<p>I have known Vim for 4 years now but never actually keen to learn all the shortcuts. I remember I been to one of the PHP meetup in my city and one guy was presenting some of his code using Vim. One of the audience commented &#8220;Why you need to use Vim if you have IDE and all of the GUI ?&#8221;. At that time, I couldn&#8217;t agree more with that guy.</p>
<p>I had always thought Vim&#8217;s user are just trying to show off that they are different and superior. Using Vim basically separate them from GUI&#8217;s group and put them one level above. At least, that&#8217;s what I was thinking and apparently I am wrong.</p>
<p>After started using Vim, I can feel that I am more productive and less stressful when programming. All the shortcuts definitively help you to avoid redundancy and remove your reliance on mouse. You can navigate through the source code by only using keyboard.</p>
<p style="text-align: center;"><a href="http://www.amazon.com/Practical-Vim-Thought-Pragmatic-Programmers/dp/1934356980/ref=sr_1_1?ie=UTF8&amp;qid=1364646960&amp;sr=8-1&amp;keywords=vim"><img class="aligncenter size-thumbnail wp-image-1040" alt="Practical Vim" src="http://blog.rudylee.com/wp-content/uploads/2013/03/41LK8SwU4WL._SX225_-150x150.jpg" width="150" height="150" /></a></p>
<p>The book that I am using to learn VIM is<a href="http://www.amazon.com/Practical-Vim-Thought-Pragmatic-Programmers/dp/1934356980/ref=sr_1_1?ie=UTF8&amp;qid=1364646960&amp;sr=8-1&amp;keywords=vim"> &#8220;Practical Vim : Edit Text at the Speed of Thought&#8221; by Drew Neil</a>. If you are new with Vim, I&#8217;ll strongly recommend to start with this book. This book has collection of tips on how to use Vim in real situation and you going to feel you learn Vim faster.</p>
<p>However, before deciding to learn Vim, you need to know that Vim is not for everyone. You know that you are not suitable for Vim when you :</p>
<ul>
<li><span style="line-height: 13px;">Still looking at your keyboard when typing.</span></li>
<li>Have problem or hate remembering shortcuts.</li>
<li>Don&#8217;t have any curiosity to find another way to achieve something.</li>
</ul>
<p>If you are an IDE fan such as Eclipse, Netbeans or Visual Studio. There are some plugins that you can download to unleash the Vim power in your IDE. At the moment, I am using <a href="http://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329" target="_blank">VsVim</a> to use all the Vim shortcuts when programming in C#. If you want to become better programmer, I&#8217;ll say start using Vim and you won&#8217;t regret it.</p>
<p><a href="http://blog.rudylee.com/2013/03/30/my-review-after-two-months-using-vim/">My review after two months using VIM</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/03/30/my-review-after-two-months-using-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework 2 : get server URL in controller without using serverUrl()</title>
		<link>http://blog.rudylee.com/2013/02/15/zend-framework-2-get-server-url-in-controller-without-using-serverurl/</link>
		<comments>http://blog.rudylee.com/2013/02/15/zend-framework-2-get-server-url-in-controller-without-using-serverurl/#comments</comments>
		<pubDate>Fri, 15 Feb 2013 05:22:35 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[Zend Framework 2]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=1014</guid>
		<description><![CDATA[Sometimes you need to be able to get current server URL inside controller in your Zend Framework 2 application. As you might know, you won&#8217;t be able to use $this-&#62;serverUrl() method in the controller as it&#8217;s a part of helper. So, here is the code that I am using to get server URL in controller ...<p><a href="http://blog.rudylee.com/2013/02/15/zend-framework-2-get-server-url-in-controller-without-using-serverurl/">Zend Framework 2 : get server URL in controller without using serverUrl()</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Sometimes you need to be able to get current server URL inside controller in your Zend Framework 2 application. As you might know, you won&#8217;t be able to use $this-&gt;serverUrl() method in the controller as it&#8217;s a part of helper.</p>
<p>So, here is the code that I am using to get server URL in controller :</p>
<pre class="&quot;brush:">$server_url = $this-&gt;getRequest()-&gt;getUri()-&gt;getScheme() . &#039;://&#039; . $this-&gt;getRequest()-&gt;getUri()-&gt;getHost();</pre>
<p>Probably it&#8217;s not the best solution but it works for now <img src='http://blog.rudylee.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://blog.rudylee.com/2013/02/15/zend-framework-2-get-server-url-in-controller-without-using-serverurl/">Zend Framework 2 : get server URL in controller without using serverUrl()</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/02/15/zend-framework-2-get-server-url-in-controller-without-using-serverurl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bootstrap Typeahead CakePHP 2.0</title>
		<link>http://blog.rudylee.com/2013/02/02/bootstrap-typeahead-cakephp-2-0/</link>
		<comments>http://blog.rudylee.com/2013/02/02/bootstrap-typeahead-cakephp-2-0/#comments</comments>
		<pubDate>Sat, 02 Feb 2013 09:13:35 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=1004</guid>
		<description><![CDATA[Demo : http://cbunny2.rudylee.com/users/typeahead Source : https://github.com/rudylee/cbunny In this post, I&#8217;ll explain how to integrate Twitter Bootstrap Typeahead with your CakePHP 2.0 application. We will avoid using helpers or plugins and stick with plain Javascript + jQuery. Make sure you have include jQuery, Bootstrap CSS and Bootstrap Javascript files in your CakePHP application. You can simply do it ...<p><a href="http://blog.rudylee.com/2013/02/02/bootstrap-typeahead-cakephp-2-0/">Bootstrap Typeahead CakePHP 2.0</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<h2>
Demo : <a target="_blank" href="http://cbunny2.rudylee.com/users/typeahead">http://cbunny2.rudylee.com/users/typeahead</a><br />
Source : <a target="_blank" href="https://github.com/rudylee/cbunny">https://github.com/rudylee/cbunny</a><br />
</h2>
<p>In this post, I&#8217;ll explain how to integrate Twitter Bootstrap Typeahead with your CakePHP 2.0 application. We will avoid using helpers or plugins and stick with plain Javascript + jQuery. Make sure you have include jQuery, Bootstrap CSS and Bootstrap Javascript files in your CakePHP application. You can simply do it inside your default.ctp file ( the files are bootstrap.min.js and bootstrap.min.css ).</p>
<p>After that we will create controller, action and view to put our input box. In this tutorial I&#8217;ll use my Cbunny application and Users controller. I&#8217;ll start by creating typeahead action, here is the code :</p>
<pre class="brush: php; gutter: true">    public function typeahead() {
        $this-&gt;User-&gt;recursive = 0;
        $this-&gt;set(&#039;users&#039;, $this-&gt;paginate());       
    }</pre>
<p>Nothing special happening rather than get current users from the table and paginate them. And here is the view :</p>
<pre class="brush: php; gutter: true">&lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;span12&quot;&gt;

    &lt;!-- Typeahead Auto Complete --&gt;
    &lt;div class=&quot;pull-right&quot;&gt;
        &lt;input type=&quot;text&quot; data-provide=&quot;typeahead&quot; id=&quot;user-typeahead&quot;&gt;
    &lt;/div&gt;

    &lt;h2&gt;&lt;?php echo __(&#039;Users&#039;);?&gt;&lt;/h2&gt;
    &lt;table class=&quot;table&quot;cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;id&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;username&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;password&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;created&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;modified&#039;);?&gt;&lt;/th&gt;
                &lt;th class=&quot;actions&quot;&gt;&lt;?php echo __(&#039;Actions&#039;);?&gt;&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;?php foreach ($users as $user): ?&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;id&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;username&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;password&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;created&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;modified&#039;]); ?&gt; &lt;/td&gt;
                &lt;td class=&quot;actions&quot;&gt;
                    &lt;?php echo $this-&gt;Html-&gt;link(__(&#039;View&#039;), array(&#039;action&#039; =&gt; &#039;view&#039;, $user[&#039;User&#039;][&#039;id&#039;])); ?&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;?php endforeach; ?&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
&lt;/div&gt;</pre>
<p>On line 5-7, I am defining input text with typeahead attribute and ID that we will use in Javascript code. The next step is to create Javascript object in your layout file. So add this code snippet in your default.ctp file :</p>
<pre class="brush: php; gutter: true">        $cbunny = array(
            &#039;APP_PATH&#039; =&gt; Router::url(&#039;/&#039;,true)
        );
        echo $this-&gt;Html-&gt;scriptBlock(&#039;var CbunnyObj = &#039; . $this-&gt;Javascript-&gt;object($cbunny) . &#039;;&#039;);</pre>
<p>You can change the $cbunny and CBunnyObj variable name to resemble your app name. However, the rest of the code has to be same as above. This snippet of code will create Javascript object which contains the root URL path of CakePHP.</p>
<p>After we have the Javascript object variable, let&#8217;s continue by creating the Javascript code. Inside your application Javascript file add these code :</p>
<pre class="brush: javascript; gutter: true">  $(&#039;#user-typeahead&#039;).typeahead({
    source: function (query, process) {
      return $.ajax({
        url: CbunnyObj.APP_PATH + &#039;users/typeahead_search&#039;,
        type: &#039;get&#039;,
        data: {q: query},
        dataType: &#039;json&#039;,
        success: function (json) {
          return process(json);
        }
      });
    }
  });</pre>
<p>In this code, we initialize the typeahead library and create AJAX request to the typeahead_search action. In the next step, we will create typeahead_search action that will handle AJAX request and return JSON result. Back to our users controller, create the typeahead action which will contain this code :</p>
<pre class="brush: php; gutter: true">    public function typeahead_search() {
        $this-&gt;autoRender = false;
        $this-&gt;RequestHandler-&gt;respondAs(&#039;json&#039;);

        // get the search term from URL
        $term = $this-&gt;request-&gt;query[&#039;q&#039;];
        $users = $this-&gt;User-&gt;find(&#039;all&#039;,array(
            &#039;conditions&#039; =&gt; array(
                &#039;User.username LIKE&#039; =&gt; &#039;%&#039;.$term.&#039;%&#039;
            )
        ));

        // Format the result for select2
        $result = array();
        foreach($users as $key =&gt; $user) {
            array_push($result, $user[&#039;User&#039;][&#039;username&#039;]);
        }
        $users = $result;

        echo json_encode($users);
    }</pre>
<p>This action will receive the request, search the database for relevant result and return it on JSON format.</p>
<p><a href="http://blog.rudylee.com/2013/02/02/bootstrap-typeahead-cakephp-2-0/">Bootstrap Typeahead CakePHP 2.0</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/02/02/bootstrap-typeahead-cakephp-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select2 AJAX Auto Complete with CakePHP 2.0</title>
		<link>http://blog.rudylee.com/2013/02/02/select2-ajax-auto-complete-with-cakephp-2-0/</link>
		<comments>http://blog.rudylee.com/2013/02/02/select2-ajax-auto-complete-with-cakephp-2-0/#comments</comments>
		<pubDate>Sat, 02 Feb 2013 08:09:26 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=968</guid>
		<description><![CDATA[Demo : http://cbunny2.rudylee.com/users/select2 Source : https://github.com/rudylee/cbunny In this post, I&#8217;ll explain how to use Select2 inside CakePHP. We will avoid using any helpers and rely on jQuery + Javascript. Before we start, I presume you have downloaded Select2 and included the Javascript and CSS files inside your layout. Thus, I won&#8217;t explain how to import Select2 library ...<p><a href="http://blog.rudylee.com/2013/02/02/select2-ajax-auto-complete-with-cakephp-2-0/">Select2 AJAX Auto Complete with CakePHP 2.0</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<h2>Demo : <a href="http://cbunny2.rudylee.com/users/select2">http://cbunny2.rudylee.com/users/select2</a><br />
Source : <a href="https://github.com/rudylee/cbunny">https://github.com/rudylee/cbunny</a></h2>
<p>In this post, I&#8217;ll explain how to use <a title="Select2" href="http://ivaynberg.github.com/select2/" target="_blank">Select2</a> inside CakePHP. We will avoid using any helpers and rely on jQuery + Javascript. Before we start, I presume you have downloaded Select2 and included the Javascript and CSS files inside your layout. Thus, I won&#8217;t explain how to import Select2 library into your CakePHP app ( you can download my cbunny app from Github if you are lost ).</p>
<p>So the first step is to create controller that will contain our Select2 search box. In this tutorial, I&#8217;ll create users controller and one action to put the select2 search box. Here is the snippet of my code :</p>
<pre class="brush: php; gutter: true">    public function select2() {
        $this-&gt;User-&gt;recursive = 0;
        $this-&gt;set(&#039;users&#039;, $this-&gt;paginate());
    }</pre>
<p>After this you can create the view ( View/Users/select2.ctp ). Here is my view code :</p>
<pre class="brush: php; gutter: true">&lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;span12&quot;&gt;

    &lt;!-- Select2 Auto Complete --&gt;
    &lt;div class=&quot;pull-right&quot;&gt;
        &lt;input type=&quot;text&quot; id=&quot;user-select2&quot;&gt;
    &lt;/div&gt;

    &lt;h2&gt;&lt;?php echo __(&#039;Users&#039;);?&gt;&lt;/h2&gt;
    &lt;table class=&quot;table&quot;cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;id&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;username&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;password&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;created&#039;);?&gt;&lt;/th&gt;
                &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort(&#039;modified&#039;);?&gt;&lt;/th&gt;
                &lt;th class=&quot;actions&quot;&gt;&lt;?php echo __(&#039;Actions&#039;);?&gt;&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;?php foreach ($users as $user): ?&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;id&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;username&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;password&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;created&#039;]); ?&gt; &lt;/td&gt;
                &lt;td&gt;&lt;?php echo h($user[&#039;User&#039;][&#039;modified&#039;]); ?&gt; &lt;/td&gt;
                &lt;td class=&quot;actions&quot;&gt;
                    &lt;?php echo $this-&gt;Html-&gt;link(__(&#039;View&#039;), array(&#039;action&#039; =&gt; &#039;view&#039;, $user[&#039;User&#039;][&#039;id&#039;])); ?&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;?php endforeach; ?&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
&lt;/div&gt;</pre>
<p>If you look at 5-7 you&#8217;ll notice that I have input element with id element user-select2. We will use the ID inside our jQuery to initiate the Select2. The next step after this is to create a Javascript object to store the dynamic app path. Add this snippet of code into your layout file ( default.ctp ).</p>
<pre class="brush: php; gutter: true">        $cbunny = array(
            &#039;APP_PATH&#039; =&gt; Router::url(&#039;/&#039;,true)
        );
        echo $this-&gt;Html-&gt;scriptBlock(&#039;var CbunnyObj = &#039; . $this-&gt;Javascript-&gt;object($cbunny) . &#039;;&#039;);</pre>
<p>You can change the $cbunny and CBunnyObj variable name to resemble your app name. However, the rest of the code has to be same as above. This snippet of code will create Javascript object which contains the root URL path of CakePHP.</p>
<p>After we have the Javascript object, we will create jQuery code to create Select2 search box, process AJAX request and handle the respond. I&#8217;ll start with creating cbunny.js file inside my webroot folder and add the file in my layout file. Here is the code :</p>
<pre class="brush: javascript; gutter: true">/*global $, document, CbunnyObj */
$(document).ready(function () {

  $(&#039;#user-select2&#039;).select2({
    placeholder: &quot;Search user auto complete&quot;,
    minimumInputLength: 1,
    ajax: {
      url: CbunnyObj.APP_PATH + &#039;users/search&#039;,
      dataType: &#039;json&#039;,
      data: function (term, page) {
        return {
          q: term
        };
      },
      results: function (data, page) {
        return { results: data };
      }
    }
  });

});</pre>
<p>I&#8217;ll explain the Javascript code a little bit. Line 4-19 contain the definition of Select2 library. You can see we have ajax definition on line 7 which will perform AJAX request to  CbunnyObj.APP_PATH + &#8216;users/search&#8217;. CbunnyObj is javascript object variable that we have defined before and will translate into your CakePHP App path ( ex: http://cbunny.rudylee.com ). I believe you understand the rest of the code as I just copied it from Select2 website.</p>
<p>After this, our last step is to create action + view to handle the AJAX request. So we are going back to Users controller and add new action called &#8216;search&#8217;. Here is my &#8216;search&#8217; action code :</p>
<pre class="brush: php; gutter: true">    public function search() {
        $this-&gt;autoRender = false;

        // get the search term from URL
        $term = $this-&gt;request-&gt;query[&#039;q&#039;];
        $users = $this-&gt;User-&gt;find(&#039;all&#039;,array(
            &#039;conditions&#039; =&gt; array(
                &#039;User.username LIKE&#039; =&gt; &#039;%&#039;.$term.&#039;%&#039;
            )
        ));

        // Format the result for select2
        $result = array();
        foreach($users as $key =&gt; $user) {
            $result[$key][&#039;id&#039;] = (int) $user[&#039;User&#039;][&#039;id&#039;];
            $result[$key][&#039;text&#039;] = $user[&#039;User&#039;][&#039;username&#039;];
        }
        $users = $result;

        echo json_encode($users);
    }</pre>
<p>On line 5, we grab the search query term from the URL and store into $term variable. After that, we will perform normal query to the table. When we get the result, we won&#8217;t be able to use it straight away. We will have to reformat it so it can be readable by Select2. On line 12-17 we basically iterate through the $users variable and create new associative array which has id and text as their key.</p>
<p>That&#8217;s it for the tutorial. If you are confuse, feel free to write comment below and I&#8217;ll be happy to answer them.</p>
<p><a href="http://blog.rudylee.com/2013/02/02/select2-ajax-auto-complete-with-cakephp-2-0/">Select2 AJAX Auto Complete with CakePHP 2.0</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/02/02/select2-ajax-auto-complete-with-cakephp-2-0/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Science of Productivity</title>
		<link>http://blog.rudylee.com/2013/01/15/science-of-productivity/</link>
		<comments>http://blog.rudylee.com/2013/01/15/science-of-productivity/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 11:58:18 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[My Stories]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=964</guid>
		<description><![CDATA[Continuing from my previous post about productivity, I just found a video that you guys might wanna check out. It covers some of the techniques from my previous post such as make your todo list doable and set up the morning dash. Science of Productivity is a post from: blog.rudylee.com<p><a href="http://blog.rudylee.com/2013/01/15/science-of-productivity/">Science of Productivity</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Continuing from my <a title="My journey to productivity" href="http://blog.rudylee.com/2013/01/14/my-journey-to-productivity/">previous post about productivity</a>, I just found a video that you guys might wanna check out. It covers some of the techniques from my previous post such as make your todo list doable and set up the morning dash.</p>
<p><iframe src="http://www.youtube.com/embed/lHfjvYzr-3g" frameborder="0" width="560" height="315"></iframe></p>
<p><a href="http://blog.rudylee.com/2013/01/15/science-of-productivity/">Science of Productivity</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/01/15/science-of-productivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My journey to productivity</title>
		<link>http://blog.rudylee.com/2013/01/14/my-journey-to-productivity/</link>
		<comments>http://blog.rudylee.com/2013/01/14/my-journey-to-productivity/#comments</comments>
		<pubDate>Mon, 14 Jan 2013 04:03:15 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[My Stories]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=953</guid>
		<description><![CDATA[Today marks two weeks of my journey trying new method to boost my productivity. For several years, I am an avid fan of procrastination which I am still now. This has bring me a lot of troubles such as projects are off-schedule, self development postponed, and working on assignments at the last minute. I have tried ...<p><a href="http://blog.rudylee.com/2013/01/14/my-journey-to-productivity/">My journey to productivity</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Today marks two weeks of my journey trying new method to boost my productivity. For several years, I am an avid fan of procrastination which I am still now. This has bring me a lot of troubles such as projects are off-schedule, self development postponed, and working on assignments at the last minute. I have tried several productivity techniques and sadly say, none of them show significant effect. One of the popular technique that I used is <a href="http://www.pomodorotechnique.com/" target="_blank">Pomodoro</a> technique. For you guys that never heard about Pomodoro, I suggest to click the link provided. For you guys that are too lazy to click the link, here is the deinition of Pomodoro that I grabbed from the website :</p>
<blockquote><p>It is a time management method created by Francesco Cirillo in the 1980s that helps you accomplish what you want to do by transforming time into a valuable ally. Why is it so popular? Because it is easy to use, and most of all, because it works!</p></blockquote>
<p>Basically the Pomodoro technique tells you to pick a task, working on it under certain time limit ( usually 25 minutes ), take a break for 5 minutes and repeat the same process again. Each cycle is what called Pomodoro, after you have finished 4 Pomodoro, you are allowed to take longer break ( 30 minutes ).</p>
<p>From my personal experience, it is a good technique but you need huge amount of self discipline. People with lack of self discipline tend to lose their focus in the middle of Pomodoro. Most of the time I am only able to do 2 perfect Pomodoro without any distractions, sometimes even less. After that usually I am end up watching Youtube, checking Facebook or even playing games.</p>
<h3>Lifehacker</h3>
<p>I am a type of person that definitely lack of self discipline. I can force and motivate myself to finish a work if there is someone watching my back, for example working in an office environment where you have colleagues monitoring what you are doing. However, one month ago I was trying find a new way to solve this problem because I am on Uni holiday and close to Christmas holiday.</p>
<p>My first choice to find solution is <a href="http://www.lifehacker.com.au/" target="_blank">Lifehacker</a> website. It is one of the popular websites that provides information to boost your productivity in simple ways ( sometimes ). However, because it has lot of articles, most of the time you find it hard to find article that suit your problem.</p>
<p>After trying various keywords to help me find article that match my problem, I decided to give up and looking for books instead. Luckily it&#8217;s not that difficult because as soon as I typed &#8216;lifehacker&#8217; in Amazon, it comes up with this <a href="http://www.amazon.com/Lifehacker-Working-Smarter-Faster-ebook/dp/B0055AUGG8/ref=sr_1_2?ie=UTF8&amp;qid=1357975024&amp;sr=8-2&amp;keywords=lifehacker" target="_blank">book</a> ( Lifehacker: The Guide to Working Smarter, Faster, and Better ). The book basically contains the same articles from the website but the good part is all the articles has been grouped into relevant chapter for easier search and read.</p>
<p>I&#8217;ll suggest you skip most of the chapters in the book and only focus on the chapters that can solve your problem. In my case, I am only focus on these topics :</p>
<ol>
<li>Make your To-Do List Doable. Based on <a href="http://lifehacker.com/270404/how-to-make-your-to+do-list-doable" target="_blank">this article</a>.</li>
<li>Set Up a Morning Dash.</li>
<li>Dash through tasks with a timer.</li>
<li>Limit visits to Time-Wasting websites.</li>
</ol>
<p>Out of those 4 topics, my favourite is number one. To-do list is a must have thing in my daily life. Not only it is useful to remind you what to do, but it also useful as a planning tool. Unfortunately, for the past few years I have done a simple mistake and made most of my to-do items in my list untouched. The mistake is simply on the way I write the todo items.</p>
<p>Before I read this article, I tend to put things such as &#8220;Redesign personal website&#8221;, &#8220;Working on project A&#8221;, and &#8220;Working on project B&#8221; in my todo list. According to the article, these type of tasks cannot be called tasks but projects. Tasks are more descriptive and can be done in short time. So if we pick redesign personal website project, some examples of the tasks are create the sitemap or create the home screen wire frame based on sitemap.</p>
<p>The first time I tried this approach, I am little bit sceptical. But believe it or not, I am find it easier to focus on my tasks when I write clearer task. The problem with unclear task are you will spend time to figure what to do and the chances that it will affect your motivation is higher.</p>
<p>I think that&#8217;s all for this article, I&#8217;ll try share my experience in the next article.</p>
<p><a href="http://blog.rudylee.com/2013/01/14/my-journey-to-productivity/">My journey to productivity</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2013/01/14/my-journey-to-productivity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>No prefix support for mapResources in CakePHP 2.x</title>
		<link>http://blog.rudylee.com/2012/11/28/no-prefix-support-for-mapresources-in-cakephp-2-x/</link>
		<comments>http://blog.rudylee.com/2012/11/28/no-prefix-support-for-mapresources-in-cakephp-2-x/#comments</comments>
		<pubDate>Wed, 28 Nov 2012 02:45:18 +0000</pubDate>
		<dc:creator>Rudy</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://blog.rudylee.com/?p=935</guid>
		<description><![CDATA[REST API is relatively easy to implement if you are using web framework to build your application. In Rails, you just need to add single &#8216;resources&#8217;  entry in your routing file. In CakePHP, it has similar solution as you can read in the Cookbook. However, currently there is no prefix support in CakePHP 2.x and ...<p><a href="http://blog.rudylee.com/2012/11/28/no-prefix-support-for-mapresources-in-cakephp-2-x/">No prefix support for mapResources in CakePHP 2.x</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></description>
				<content:encoded><![CDATA[<p>REST API is relatively easy to implement if you are using web framework to build your application. In Rails, you just need to add single &#8216;resources&#8217;  entry in your routing file. In CakePHP, it has similar solution as you can read in the <a href="http://book.cakephp.org/2.0/en/development/rest.html">Cookbook</a>. However, currently there is no prefix support in CakePHP 2.x and this is confirmed in these links :</p>
<ul>
<li><a href="http://cakephp.lighthouseapp.com/projects/42648/tickets/968-rest-routes-with-prefix">http://cakephp.lighthouseapp.com/projects/42648/tickets/968-rest-routes-with-prefix</a></li>
<li><a href="https://github.com/cakephp/cakephp/pull/763">https://github.com/cakephp/cakephp/pull/763</a></li>
</ul>
<p>This is a drawback because you are most likely will use prefix to build REST API. In my case, I have products controller in my application which has default CRUD actions and another set of actions with prefix ( api_index, api_view, etc ). Those actions with prefix in front of it will act as our RESTful API.</p>
<p>You can try another approach by creating separate controller only to handle API request. For example, you will have to create controller called products_api to handle all restful API for specific controller. I am not a fan of this approach because you might end up having a lot of files and it&#8217;s difficult to maintain.</p>
<p>So, if you are on the same boat as me, you can follow this solution that I found. This solution only requires you to add one line of code to Router.php file in CakePHP lib folder ( <a href="https://github.com/DiegoMax/cakephp/commit/f203202ff78da930b472ecce817fdc6f19d6dfda">https://github.com/DiegoMax/cakephp/commit/f203202ff78da930b472ecce817fdc6f19d6dfda</a> ).</p>
<p>Not a best solution but I don&#8217;t want to wait until CakePHP 3.x released to finish my first CakePHP + Backbone.JS app. That&#8217;s all, have a nice day.</p>
<p><a href="http://blog.rudylee.com/2012/11/28/no-prefix-support-for-mapresources-in-cakephp-2-x/">No prefix support for mapResources in CakePHP 2.x</a> is a post from: <a href="http://blog.rudylee.com">blog.rudylee.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rudylee.com/2012/11/28/no-prefix-support-for-mapresources-in-cakephp-2-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
