<?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"
	>

<channel>
	<title>[ mkhairul.com ] &#187; code</title>
	<atom:link href="http://mkhairul.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://mkhairul.com</link>
	<description>Musings of a web ninja</description>
	<pubDate>Tue, 06 Jan 2009 09:57:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Making jQuery selector/contains case insensitive</title>
		<link>http://mkhairul.com/2008/11/26/making-jquery-selectorcontains-case-insensitive/</link>
		<comments>http://mkhairul.com/2008/11/26/making-jquery-selectorcontains-case-insensitive/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 07:10:49 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[Troubleshoot]]></category>

		<category><![CDATA[blog]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://mkhairul.com/?p=804</guid>
		<description><![CDATA[Just another stuff from work. There&#8217;s huge list to select people to be put into groups in the LMS. I added a javascript function for the user to type in a name and it will search and select a user in the list box.

I use Selector/contains for this but the problem is, it is case [...]]]></description>
			<content:encoded><![CDATA[<p>Just another stuff from work. There&#8217;s huge list to select people to be put into groups in the LMS. I added a javascript function for the user to type in a name and it will search and select a user in the list box.</p>
<p>
I use <a href="http://docs.jquery.com/Selectors/contains">Selector/contains</a> for this but the problem is, it is case sensitive. That&#8217;s gonna be a problem to type in the exact case from the list. Here&#8217;s a snippet to extend the selector.
</p>
<pre name="code" class="javascript">
jQuery.extend(
        jQuery.expr[':'], {
                contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
});
</pre>
<p>Took the snippet from <a href="http://stackoverflow.com/questions/187537/is-there-a-case-insensitive-jquery-contains-selector">StackOverflow</a>, but it has a typo.</p>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/11/26/making-jquery-selectorcontains-case-insensitive/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CodeIgniter 1.7 DBForge Error (Array to string conversion error)</title>
		<link>http://mkhairul.com/2008/11/20/codeigniter-17-dbforge-error-array-to-string-conversion-error/</link>
		<comments>http://mkhairul.com/2008/11/20/codeigniter-17-dbforge-error-array-to-string-conversion-error/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 03:57:13 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[Troubleshoot]]></category>

		<category><![CDATA[blog]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mkhairul.com/?p=799</guid>
		<description><![CDATA[I think the ellislab team is swamped with bug reports and stuffs. But I&#8217;m sure the next release will solve this problem.
I found this solution at the forum, CI 1.7 Forge Problems.  Basically what you need to do is find DB_driver.php inside the database folder. Go to function _protect_identifiers (most probably on line 1193).
Add [...]]]></description>
			<content:encoded><![CDATA[<p>I think the ellislab team is swamped with bug reports and stuffs. But I&#8217;m sure the next release will solve this problem.</p>
<p>I found this solution at the forum, <a href="http://codeigniter.com/forums/viewthread/94829/#479981">CI 1.7 Forge Problems</a>.  Basically what you need to do is find <strong>DB_driver.php</strong> inside the <strong>database folder</strong>. Go to <strong>function _protect_identifiers</strong> (most probably on <strong>line 1193</strong>).</p>
<p>Add in this code (inside the function).</p>
<pre name="code" class="php">
if (is_array($item))
{
	$array = array();

	foreach($item as $one)
	{
		$array[] = $this->_protect_identifiers($one, $prefix_single, $protect_identifiers, $field_exists);
	}

	return $array;
}
</pre>
<p>Alright, that should fix it up.</p>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/11/20/codeigniter-17-dbforge-error-array-to-string-conversion-error/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adding confirm dialogue box for delete links with jQuery</title>
		<link>http://mkhairul.com/2008/11/15/adding-confirm-dialogue-box-for-delete-links-with-jquery/</link>
		<comments>http://mkhairul.com/2008/11/15/adding-confirm-dialogue-box-for-delete-links-with-jquery/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 17:15:33 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[blog]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://mkhairul.com/?p=776</guid>
		<description><![CDATA[I use this all the time. Its simple, clean and gracefully degrades. Even though its simple some people might miss it. So I post it here.

$('.delete').click(function(){
    if(!confirm('Are you sure you want to delete?'))
    {
        return false;
    }
})

By returning false [...]]]></description>
			<content:encoded><![CDATA[<p>I use this all the time. Its simple, clean and <a href="http://www.digital-web.com/articles/fluid_thinking/">gracefully degrades</a>. Even though its simple some people might miss it. So I post it here.</p>
<pre class="javascript" name="code">
$('.delete').click(function(){
    if(!confirm('Are you sure you want to delete?'))
    {
        return false;
    }
})
</pre>
<p>By returning false you stop any action from the link (redirecting you to the url)</p>
<p>You can see the demo <a href="http://mkhairul.com/experiments/delete_demo.html">here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/11/15/adding-confirm-dialogue-box-for-delete-links-with-jquery/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Debugging an SQL Query</title>
		<link>http://mkhairul.com/2008/11/12/debugging-sql-query/</link>
		<comments>http://mkhairul.com/2008/11/12/debugging-sql-query/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 15:57:26 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Troubleshoot]]></category>

		<category><![CDATA[blog]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://mkhairul.com/?p=765</guid>
		<description><![CDATA[So, I debugged an error for a good friend recently. Only certain kind of item would be displayed, everything else was not found in the search. The first thing I suspect is the SQL Query. I printed out the SQL Query and tried to debug it.
The first thing I did is to arrange the SQL [...]]]></description>
			<content:encoded><![CDATA[<p>So, I debugged an error for a good friend recently. Only certain kind of item would be displayed, everything else was not found in the search. The first thing I suspect is the SQL Query. I printed out the SQL Query and tried to debug it.</p>
<p>The first thing I did is to arrange the SQL Query in a readable manner.</p>
<div align="center"><a href="http://mkhairul.com/wp-content/uploads/2008/11/debug1.jpg"><img height="288" width="300" class="aligncenter size-medium wp-image-766" title="debug1" src="http://mkhairul.com/wp-content/uploads/2008/11/debug1-300x288.jpg" /></a></div>
<p>Since I do not have the time to follow the trail from the SQL Query manually, I just comment out 3 conditions at a time, and add a condition each time until the item was found. In the above picture, I&#8217;ve found the culprit its the one below the commented out line.</p>
<p>When I commented out the line, the results for the keyword appeared as follow. </p>
<div align="center"><a href="http://mkhairul.com/wp-content/uploads/2008/11/debug2.jpg"><img height="80" width="300" src="http://mkhairul.com/wp-content/uploads/2008/11/debug2-300x80.jpg" title="debug2" class="alignnone size-medium wp-image-767" /></a></div>
<p>So thats the divide and conquer part. So now I know the problem is with the commented out criteria and the one below it. I traced it back to its table (products_to_categories) and found out that the category_id value is empty. Thats why it can&#8217;t join in with the categories table and thus there&#8217;s no result.</p>
<div align="center"><a href="http://mkhairul.com/wp-content/uploads/2008/11/debug3.jpg"><img height="260" width="267" class="alignnone size-medium wp-image-769" title="debug3" src="http://mkhairul.com/wp-content/uploads/2008/11/debug3.jpg" /></a></div>
<p>So what did I do? I told my friend about the problem, explained it to him (I gave him a couple of screenshots to explain the problem) and gives him a solution. <em>UPDATE products_to_categories SET categories_id = xx</em>. So that all the item have a category and will be displayed when it is searched by the application.</p>
<p>Erm, yeah. Thats about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/11/12/debugging-sql-query/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Check for valid date</title>
		<link>http://mkhairul.com/2008/09/11/check-for-valid-date/</link>
		<comments>http://mkhairul.com/2008/09/11/check-for-valid-date/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 16:55:57 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[blog]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mkhairul.com/?p=622</guid>
		<description><![CDATA[Maybe I&#8217;m missing something here. I really think something like this already exist out there. Could not find it so I tried my own.
$pattern = '/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/';
$subject = array();
$subject[] = '30/04/2008'; // valid date
$subject[] = '/30/2008';  // invalid format
$subject[] = '111/30/2008';  // invalid format
$subject[] = '04/30/2008'; // invalid date

foreach($subject as $item)
{
  preg_match($pattern, $item, [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe I&#8217;m missing something here. I really think something like this already exist out there. Could not find it so I tried my own.</p>
<pre class="php" name="code">$pattern = '/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/';
$subject = array();
$subject[] = '30/04/2008'; // valid date
$subject[] = '/30/2008';  // invalid format
$subject[] = '111/30/2008';  // invalid format
$subject[] = '04/30/2008'; // invalid date

foreach($subject as $item)
{
  preg_match($pattern, $item, $matches,  PREG_OFFSET_CAPTURE);
  print_r($matches);
  if($matches)
  {
    list($day, $month, $year) = split('/', $item);
    if(!checkdate($month, $day, $year))
    {
       print "<br/><strong>invalid date</strong>: $item";
    }
  }
  else
  {
    print '<br/><strong>invalid format</strong>';
  }
  print '<br/>';
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/09/11/check-for-valid-date/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Retrieve the content of FCKEditor</title>
		<link>http://mkhairul.com/2008/09/10/retrieve-the-content-of-fckeditor/</link>
		<comments>http://mkhairul.com/2008/09/10/retrieve-the-content-of-fckeditor/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 02:34:28 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[Tips]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://mkhairul.com/?p=610</guid>
		<description><![CDATA[Here&#8217;s an interesting problem that I faced few days ago on MyQuotes. I wanted to apply a lightbox kind of preview for the content the user put in. I use FCKEditor for the textarea. I have no idea how to retrieve the contents from the textarea (to put it into the lightbox).
After googling around ( [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting problem that I faced few days ago on <a href="http://mkhairul.com/quotes">MyQuotes</a>. I wanted to apply a lightbox kind of preview for the content the user put in. I use FCKEditor for the textarea. I have no idea how to retrieve the contents from the textarea (to put it into the lightbox).</p>
<p>After googling around ( I forgot the keyword that I used ), I found it, it can be retrieved using FCKEditor&#8217;s API.</p>
<pre name="code" class="javascript">oEditor = FCKeditorAPI.GetInstance('quote'); 	
myValue = oEditor.GetXHTML(oEditor.FormatOutput);
</pre>
<p>The FCKEditor is using BBCode, to minimize abuse (hope it works! LOL). Since I don&#8217;t know how to convert the bbcode values retrieved from the content into HTML tags, I use the next best thing. Send it to be converted and tagged up using jQuery&#8217;s $.post().</p>
<div>
  <a title="MyQuotes Screenshot" href="http://www.flickr.com/photos/25768438@N07/2840776933/"><br />
  <img alt="MyQuotes Screenshot" src="http://farm4.static.flickr.com/3176/2840776933_89f5e4e1ab.jpg" /><br />
  </a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/09/10/retrieve-the-content-of-fckeditor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Focus on first input text in jQuery</title>
		<link>http://mkhairul.com/2008/09/04/focus-on-first-input-text-in-jquery/</link>
		<comments>http://mkhairul.com/2008/09/04/focus-on-first-input-text-in-jquery/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 17:40:46 +0000</pubDate>
		<dc:creator>mkhairul</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://mkhairul.com/2008/09/04/focus-on-first-input-text-in-jquery/</guid>
		<description><![CDATA[I&#8217;m doing a little bit of polishing while finishing up some forms. I got this fade-in effect and wants to get the first input text to be focused when the animation ends.

function show_form(formname)
{
    hide_all();
	$('#' + formname).css('opacity', 0).parent().show();
    $('#' + formname).animate({opacity: 1}, 'normal', function(){

		// focus on the first input in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m doing a little bit of polishing while finishing up some forms. I got this fade-in effect and wants to get the first input text to be focused when the animation ends.</p>
<p><pre name="code" class="javascript">
function show_form(formname)
{
    hide_all();
	$('#' + formname).css('opacity', 0).parent().show();
    $('#' + formname).animate({opacity: 1}, 'normal', function(){

		// focus on the first input in the form
		$('#'+formname+' input:text:first').focus();

		offset = $('#add_new').offset().top;
		$('html, body').animate({
                 scrollTop: offset }, 2000);
	});

    return false;
}
</pre>
</p>
<p>&nbsp;There&#8217;s an additional effect in that function. It&#8217;ll scroll down to the form because there&#8217;s a list above the form, so, it&#8217;ll just scroll right pass it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mkhairul.com/2008/09/04/focus-on-first-input-text-in-jquery/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
