<?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>Squirrel Hacker &#187; Open Source</title>
	<atom:link href="http://blog.seanja.com/category/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.seanja.com</link>
	<description>I have come forward in time from the year 1986 to share this with you</description>
	<lastBuildDate>Mon, 06 Feb 2012 12:38:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Frigging Huge PDFs</title>
		<link>http://blog.seanja.com/2011/05/frigging-huge-pdfs/</link>
		<comments>http://blog.seanja.com/2011/05/frigging-huge-pdfs/#comments</comments>
		<pubDate>Fri, 13 May 2011 11:43:09 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Adobe Creative Suite]]></category>
		<category><![CDATA[Adobe Photoshop]]></category>
		<category><![CDATA[Application software]]></category>
		<category><![CDATA[Canada]]></category>
		<category><![CDATA[Computer graphics]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Ghost]]></category>
		<category><![CDATA[Graphic design]]></category>
		<category><![CDATA[Manitoba]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[Portable Document Format]]></category>
		<category><![CDATA[Proprietary software]]></category>
		<category><![CDATA[Raster graphics editors]]></category>
		<category><![CDATA[Tweaking]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=38730</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/05/frigging-huge-pdfs/' addthis:title='Frigging Huge PDFs '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Turns out this is how you fix up a frigging huge pdf that probably came out of photoshop or some such beast with all of the layers and history that is mostly useless to you. It seems to work quite well, 230 MB down to 6MB. Of course you can do some tweaking to reduce [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/05/frigging-huge-pdfs/' addthis:title='Frigging Huge PDFs ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/03/links-for-2009-03-19/' rel='bookmark' title='links for 2009-03-19'>links for 2009-03-19</a></li>
<li><a href='http://blog.seanja.com/2009/02/backing-things-up-a-la-crashplan/' rel='bookmark' title='Backing things up a la Crashplan'>Backing things up a la Crashplan</a></li>
<li><a href='http://blog.seanja.com/2009/01/launchy/' rel='bookmark' title='Launchy'>Launchy</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/05/frigging-huge-pdfs/' addthis:title='Frigging Huge PDFs '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Turns out this is how you fix up a frigging huge pdf that probably came out of photoshop or some such beast with all of the layers and history that is mostly useless to you. It seems to work quite well, 230 MB down to 6MB.</p>
<p>Of course you can do some tweaking to reduce the size even more if you want to (take a look at the ghost script manual).</p>
<p><code>gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf</code></p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/05/frigging-huge-pdfs/' addthis:title='Frigging Huge PDFs ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2009/03/links-for-2009-03-19/' rel='bookmark' title='links for 2009-03-19'>links for 2009-03-19</a></li>
<li><a href='http://blog.seanja.com/2009/02/backing-things-up-a-la-crashplan/' rel='bookmark' title='Backing things up a la Crashplan'>Backing things up a la Crashplan</a></li>
<li><a href='http://blog.seanja.com/2009/01/launchy/' rel='bookmark' title='Launchy'>Launchy</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/05/frigging-huge-pdfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instead of just Killing off IE6&#8230;</title>
		<link>http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/</link>
		<comments>http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 18:37:03 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[postaweek2011]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[FTP clients]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Internet Explorer 6]]></category>
		<category><![CDATA[Internet Explorer 7]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[RSS aggregators]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=38707</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/' addthis:title='Instead of just Killing off IE6&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Why not kill off IE7 while we are at it? So, IE6 is on the death march. It&#8217;s support ended July 13th 2010. Unfortunately it persists because of Windows XP, as it&#8217;s support lasts until 2014. I figured I should help out, but I want to help kill of IE7 as well, so I found [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/' addthis:title='Instead of just Killing off IE6&#8230; ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/' rel='bookmark' title='Using Valums File Uploader with CodeIgniter'>Using Valums File Uploader with CodeIgniter</a></li>
<li><a href='http://blog.seanja.com/2011/07/check-if-the-current-node-has-been-updated/' rel='bookmark' title='Check if the current node has been updated'>Check if the current node has been updated</a></li>
<li><a href='http://blog.seanja.com/2011/01/ajaxy-pagination-using-jquery/' rel='bookmark' title='Ajaxy Pagination using jQuery'>Ajaxy Pagination using jQuery</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/' addthis:title='Instead of just Killing off IE6&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>Why not kill off IE7 while we are at it?</p>
<p>So, IE6 is on the death march. It&#8217;s support ended July 13th 2010. Unfortunately it persists because of Windows XP, as it&#8217;s support lasts until 2014.</p>
<div class="wp-caption alignnone" style="width: 721px"><a href="http://i.seanja.com/lhngi8"><img alt="" src="http://i.seanja.com/sites/default/files/imagecache/Viewable/kill-ie6.png" title="IE6 market share... #forshame" width="545" /></a><p class="wp-caption-text">http://www.theie6countdown.com/</p></div>
<p>I figured I should help out, but I want to help kill of IE7 as well, so I found an IE6 notice script here: <a href="https://code.google.com/p/ie6-upgrade-notification-bar/">https://code.google.com/p/ie6-upgrade-notification-bar/</a>. I have made quite a few changes to it, and here is the result:</p>
<p><a href="http://seanja.com/demos/ie7-notice/">http://seanja.com/demos/ie7-notice/</a>.</p>
<p>The source is available on github <a href="https://github.com/SeanJA/ie7-notice">https://github.com/SeanJA/ie7-notice</a>.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/' addthis:title='Instead of just Killing off IE6&#8230; ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/' rel='bookmark' title='Using Valums File Uploader with CodeIgniter'>Using Valums File Uploader with CodeIgniter</a></li>
<li><a href='http://blog.seanja.com/2011/07/check-if-the-current-node-has-been-updated/' rel='bookmark' title='Check if the current node has been updated'>Check if the current node has been updated</a></li>
<li><a href='http://blog.seanja.com/2011/01/ajaxy-pagination-using-jquery/' rel='bookmark' title='Ajaxy Pagination using jQuery'>Ajaxy Pagination using jQuery</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/03/instead-of-just-killing-off-ie6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP SQL Query Builder</title>
		<link>http://blog.seanja.com/2011/01/php-sql-query-builder/</link>
		<comments>http://blog.seanja.com/2011/01/php-sql-query-builder/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 03:18:22 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[postaweek2011]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Condition]]></category>
		<category><![CDATA[Data management]]></category>
		<category><![CDATA[From]]></category>
		<category><![CDATA[Human Interest]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL keywords]]></category>
		<category><![CDATA[Where]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=34813</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/01/php-sql-query-builder/' addthis:title='PHP SQL Query Builder '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>As an excersise I have started building another php based sql query builder (separate from my stagnating php framework). So far I can do SELECT [columns] FROM table WHERE [conditions] This is how it should be used (so far): (for the examples, assume that $q is a query object) $q-&#62;table&#40;'test'&#41; -&#62;column&#40;'test_2', 'test'&#41; -&#62;table&#40;'test_3', 'test_2'&#41;; //=&#62; [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/01/php-sql-query-builder/' addthis:title='PHP SQL Query Builder ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/09/a-look-at-postgresql/' rel='bookmark' title='A look at PostgreSQL'>A look at PostgreSQL</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
<li><a href='http://blog.seanja.com/2009/04/smarty-again/' rel='bookmark' title='Smarty&#8230; again'>Smarty&#8230; again</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/01/php-sql-query-builder/' addthis:title='PHP SQL Query Builder '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>As an excersise I have started building another php based sql query builder (separate from my stagnating php framework). So far I can do SELECT [columns] FROM table WHERE [conditions]</p>
<p>This is how it should be used (so far):<br />
(for the examples, assume that $q is a query object)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">column</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test_2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test_3'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test_2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//=&gt; SELECT test_2 as test FROM test, test_3 AS test_2</span></pre></div></div>

<p>You can also group conditions:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">begin_and</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">and_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'col_1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">or_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'col_2'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">end_and</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">or_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'col_3'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'!='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//=&gt;SELECT * FROM table WHERE ( col_1 = '1'  OR col_2 = '2' ) or col_3 != '3'</span></pre></div></div>

<p>which is fun.</p>
<p>I have just tried this example and am pleased to say that you can put multiple groups at the start of the query:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">begin_and</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">begin_and</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">and_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'col_1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">or_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'col_2'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">end_and</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">end_and</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">or_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'col_3'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'!='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//=&gt;SELECT * FROM table WHERE ( ( col_1 = '1' OR col_2 = '2' ) ) OR col_3 != '3'</span></pre></div></div>

<p>You can follow along <a href="https://github.com/SeanJA/query-builder">here</a> if you want, suggest improvements, criticize it to no end because I am doing it toally wrong, or &#8220;steal&#8221; my ideas and make your own (but give me some of the credit at least).</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/01/php-sql-query-builder/' addthis:title='PHP SQL Query Builder ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/09/a-look-at-postgresql/' rel='bookmark' title='A look at PostgreSQL'>A look at PostgreSQL</a></li>
<li><a href='http://blog.seanja.com/2010/03/re-top-10-php-techniques-that-will-save-you-time-and-effort/' rel='bookmark' title='RE: Top 10 PHP Techniques That Will Save You Time and Effort'>RE: Top 10 PHP Techniques That Will Save You Time and Effort</a></li>
<li><a href='http://blog.seanja.com/2009/04/smarty-again/' rel='bookmark' title='Smarty&#8230; again'>Smarty&#8230; again</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/01/php-sql-query-builder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Valums File Uploader with CodeIgniter</title>
		<link>http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/</link>
		<comments>http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 05:12:23 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Code Igniter]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[postaweek2011]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[2]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Initialisms]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Strlen]]></category>
		<category><![CDATA[This]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=33524</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/' addthis:title='Using Valums File Uploader with CodeIgniter '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>Valums file uploader is a fancy pants ajaxy uploader widgit that is meant to be used with normal php pages. It, by default, doesn&#8217;t really play well with CodeIgniter. Fortunately, it isn&#8217;t that hard to make it work. There is a bit of a modification to the .js file: Basically, you just have to turn [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/' addthis:title='Using Valums File Uploader with CodeIgniter ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/' rel='bookmark' title='PHP DateTime is missing methods in 5.2'>PHP DateTime is missing methods in 5.2</a></li>
<li><a href='http://blog.seanja.com/2011/01/ajaxy-pagination-using-jquery/' rel='bookmark' title='Ajaxy Pagination using jQuery'>Ajaxy Pagination using jQuery</a></li>
<li><a href='http://blog.seanja.com/2009/01/netbeans-subversion-eclipse-subversion/' rel='bookmark' title='Netbeans Subversion &gt; Eclipse Subversion'>Netbeans Subversion &gt; Eclipse Subversion</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/' addthis:title='Using Valums File Uploader with CodeIgniter '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p><a href="http://valums.com/ajax-upload/" target="_blank">Valums file uploader</a> is a fancy pants ajaxy uploader widgit that is meant to be used with normal php pages. It, by default, doesn&#8217;t really play well with CodeIgniter.</p>
<p>Fortunately, it isn&#8217;t that hard to make it work. There is a bit of a modification to the .js file:</p>
<p><script src="https://gist.github.com/777345.js?file=ci_patch.patch"></script></p>
<p>Basically, you just have to turn the <code>?qqfile=blah</code> into <code> /blah </code>. Granted, this is a quick fix&#8230; and it will not work if you want to pass extra params to the upload. A better fix would be to rewrite parts of the <code>qq.obj2url</code> function so that it accepts a different separator.</p>
<p>The other thing you have to worry about is CodeIgniter&#8217;s magical stripping of characters that it doesn&#8217;t like specifically: the <code>.</code> in your file&#8217;s name. Fortunately this is easy to fix:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//snip [......]</span>
	  <span style="color: #666666; font-style: italic;">//codeigniter replaces the . with a _ argh, we can fix that by doing this:</span>
	  <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//[......]   /snip</span></pre></div></div>

<p>That is about it, the code is available here: <a href="https://github.com/SeanJA/uploadr">https://github.com/SeanJA/uploadr</a>.</p>
<p>Also, since I don&#8217;t subscribe to the &#8220;we must support php 4 forever&#8221; mentality, you will notice that the methods in my classes have private, public, and protected, you can just remove all of those if you need to support PHP 4 still (but you really should upgrade&#8230;).</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/' addthis:title='Using Valums File Uploader with CodeIgniter ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/' rel='bookmark' title='PHP DateTime is missing methods in 5.2'>PHP DateTime is missing methods in 5.2</a></li>
<li><a href='http://blog.seanja.com/2011/01/ajaxy-pagination-using-jquery/' rel='bookmark' title='Ajaxy Pagination using jQuery'>Ajaxy Pagination using jQuery</a></li>
<li><a href='http://blog.seanja.com/2009/01/netbeans-subversion-eclipse-subversion/' rel='bookmark' title='Netbeans Subversion &gt; Eclipse Subversion'>Netbeans Subversion &gt; Eclipse Subversion</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2011/01/using-valums-file-uploader-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP DateTime is missing methods in 5.2</title>
		<link>http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/</link>
		<comments>http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 11:28:32 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[System time]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[Timekeeping]]></category>
		<category><![CDATA[Timestamp]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=938</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/' addthis:title='PHP DateTime is missing methods in 5.2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>It turns out that in PHP 5.2, the DateTime class is missing a couple of methods (get/setTimestamp) that are available in PHP 5.3. These are some strange methods to be missing as a lot of people in the PHP world seem to work on Timestamps using these concepts, so you would have thought that php [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/' addthis:title='PHP DateTime is missing methods in 5.2 ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/documenting-php-code/' rel='bookmark' title='Documenting PHP Code'>Documenting PHP Code</a></li>
<li><a href='http://blog.seanja.com/2010/04/an-alternative-to-poor-mans-mvc-in-php/' rel='bookmark' title='An alternative to Poor Man&#8217;s MVC in PHP'>An alternative to Poor Man&#8217;s MVC in PHP</a></li>
<li><a href='http://blog.seanja.com/2011/01/php-sql-query-builder/' rel='bookmark' title='PHP SQL Query Builder'>PHP SQL Query Builder</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/' addthis:title='PHP DateTime is missing methods in 5.2 '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>It turns out that in PHP 5.2, the DateTime class is missing a couple of methods (get/setTimestamp) that are available in PHP 5.3. These are some strange methods to be missing as a lot of people in the PHP world seem to work on Timestamps using these concepts, so you would have thought that php would have included these methods initially. Unfortunately they did not, so here is a fix for that:</p>
<p><script src="http://gist.github.com/349273.js?file=datetime_52.class.php"></script></p>
<p>And since using it in production would be no good if it were not tested properly, here are the unit tests to make sure that it returns the same values as the new one in PHP 5.3:</p>
<p><script src="http://gist.github.com/349273.js?file=datetime_52Test.php"></script></p>
<p>You use it the same way that you would use the normal DateTime class, it even includes the poorly named php functions date_timestamp_get / date_timestamp_set if they don&#8217;t exist so you can use them as well.</p>
<p>Hopefully this is helpful for those of you that have used this functionality mistakenly (as I did) before realizing that it wasn&#8217;t actually available.</p>
<p>(get it on github: http://gist.github.com/349273)</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/' addthis:title='PHP DateTime is missing methods in 5.2 ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/documenting-php-code/' rel='bookmark' title='Documenting PHP Code'>Documenting PHP Code</a></li>
<li><a href='http://blog.seanja.com/2010/04/an-alternative-to-poor-mans-mvc-in-php/' rel='bookmark' title='An alternative to Poor Man&#8217;s MVC in PHP'>An alternative to Poor Man&#8217;s MVC in PHP</a></li>
<li><a href='http://blog.seanja.com/2011/01/php-sql-query-builder/' rel='bookmark' title='PHP SQL Query Builder'>PHP SQL Query Builder</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/03/php-datetime-is-missing-methods-in-5-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery :contains selector and unicode characters</title>
		<link>http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/</link>
		<comments>http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 12:30:51 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[contains]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[Typography]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=934</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/' addthis:title='jQuery :contains selector and unicode characters '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>I have an element like this (to save space in the menu since they can put up to 255 characters in it): &#60;span class=&#34;tool_tip&#34; title=&#34;The full title&#34;&#62;The ful&#38;#8230;&#60;/span&#62; While this seems to work: jQuery&#40;'span:contains(…)'&#41;; this does not: jQuery&#40;'span:contains(&#38;#8230;)'&#41;; I am pretty sure that it would be bad to use the first one because if someone [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/' addthis:title='jQuery :contains selector and unicode characters ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/jquery-and-wordpress/' rel='bookmark' title='JQuery and WordPress'>JQuery and WordPress</a></li>
<li><a href='http://blog.seanja.com/2011/01/ajaxy-pagination-using-jquery/' rel='bookmark' title='Ajaxy Pagination using jQuery'>Ajaxy Pagination using jQuery</a></li>
<li><a href='http://blog.seanja.com/2009/07/a-better-way-to-use-jquery-in-wordpress-themes/' rel='bookmark' title='A better way to use jQuery in WordPress Themes'>A better way to use jQuery in WordPress Themes</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/' addthis:title='jQuery :contains selector and unicode characters '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>I have an element like this (to save space in the menu since they can put up to 255 characters in it):</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">    &lt;span class=&quot;tool_tip&quot; title=&quot;The full title&quot;&gt;The ful&amp;#8230;&lt;/span&gt;</pre></div></div>

<p>While this seems to work:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span:contains(…)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>this does not:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span:contains(&amp;#8230;)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I am pretty sure that it would be bad to use the first one because if someone else saves the file, or the browser decides to get the file in a different character set for some reason things will not work.</p>
<p>There has to be a way to properly select this span, right? Turns out there is:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&nbsp;
    jQuery('span:contains(\u2026)');</pre></div></div>

<p>In other words:</p>
<p>Use the hex value instead of the decimal value as the selector and things will work out fine.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/' addthis:title='jQuery :contains selector and unicode characters ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/jquery-and-wordpress/' rel='bookmark' title='JQuery and WordPress'>JQuery and WordPress</a></li>
<li><a href='http://blog.seanja.com/2011/01/ajaxy-pagination-using-jquery/' rel='bookmark' title='Ajaxy Pagination using jQuery'>Ajaxy Pagination using jQuery</a></li>
<li><a href='http://blog.seanja.com/2009/07/a-better-way-to-use-jquery-in-wordpress-themes/' rel='bookmark' title='A better way to use jQuery in WordPress Themes'>A better way to use jQuery in WordPress Themes</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/03/jquery-contains-selector-and-unicode-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Documenting PHP Code</title>
		<link>http://blog.seanja.com/2010/03/documenting-php-code/</link>
		<comments>http://blog.seanja.com/2010/03/documenting-php-code/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 13:00:40 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Boolean data type]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Comparison of programming languages]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[Property]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Value at risk]]></category>
		<category><![CDATA[Vroom Framework]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=924</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/documenting-php-code/' addthis:title='Documenting PHP Code '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>I know we all hate documenting code, but it can really help out future you or me when we need to go back and fix something. Poorly documented code is the bane of anyone who will be taking on your code after you leave (or invite more people into) the project. One thing that can [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/documenting-php-code/' addthis:title='Documenting PHP Code ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2007/06/code-golf-home-on-the-range/' rel='bookmark' title='Code Golf &#8211; Home On The Range'>Code Golf &#8211; Home On The Range</a></li>
<li><a href='http://blog.seanja.com/2011/07/code-custom-node-addedit-title/' rel='bookmark' title='Code: Custom Node Add/Edit Title'>Code: Custom Node Add/Edit Title</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/documenting-php-code/' addthis:title='Documenting PHP Code '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>I know we all hate documenting code, but it can really help out future you or me when we need to go back and fix something. Poorly documented code is the bane of anyone who will be taking on your code after you leave (or invite more people into) the project. One thing that can really help is documenting the variables that you can get via the __get and __set magic methods:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * @property bool $development_environment
 * @property string $base_url
 * @property string $index_file
 * @property string $allowed_uri_characters
 * @property string $char_encoding
 * @property string $default_location
 * @property string $helper_prefix
 * @property array $auto_load
 * @property string $auto_load['helpers']
 * @property array $db
 * @property string $db['name']
 * @property string $db['user']
 * @property string $db['password']
 * @property string $db['host']
 * @property string $db['type']
 * @property array $users
 * @property string $users['table']
 * @property string $users['encryption']
 * @property array $users['fields']
 * @property string $users['session_name']
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> config<span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Get a var from the config values
	 * @param string $var
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' does not exist in '</span><span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Set a new/current config value
	 * @param string $var
	 * @param multiple $value
	 * @return  multiple
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Adding the @property values to the top of the class lets you see at a quick glance what default properties that the class gives you. It can even help you in your ide when you are trying to figure out what you can actually get out of a class:</p>
<p><a href="http://blog.seanja.com/wp-content/uploads/2010/03/code_hints.png"><img src="http://blog.seanja.com/wp-content/uploads/2010/03/code_hints.png" alt="" title="code_hints" width="552" height="721" class="aligncenter size-full wp-image-930" /></a></p>
<p>Remember, try not to piss off future you, they know where you live.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/documenting-php-code/' addthis:title='Documenting PHP Code ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/04/php-functions-youre-doing-it-wrong/' rel='bookmark' title='PHP Functions, you&#8217;re doing it wrong&#8230;'>PHP Functions, you&#8217;re doing it wrong&#8230;</a></li>
<li><a href='http://blog.seanja.com/2007/06/code-golf-home-on-the-range/' rel='bookmark' title='Code Golf &#8211; Home On The Range'>Code Golf &#8211; Home On The Range</a></li>
<li><a href='http://blog.seanja.com/2011/07/code-custom-node-addedit-title/' rel='bookmark' title='Code: Custom Node Add/Edit Title'>Code: Custom Node Add/Edit Title</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/03/documenting-php-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using the jQuery-UI Autocomplete Widget</title>
		<link>http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/</link>
		<comments>http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 13:00:24 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[America]]></category>
		<category><![CDATA[Associative array]]></category>
		<category><![CDATA[Autocomplete]]></category>
		<category><![CDATA[Canada]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[jQuery-ui site]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[K]]></category>
		<category><![CDATA[Mexico]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=925</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' addthis:title='Using the jQuery-UI Autocomplete Widget '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>The latest version of jQuery-ui has an autocomplete widget. No more looking for one that will work (you get the point) with the version of jQuery that you have. All you have to do is pull the latest one down from the jQuery-ui site and you are good to go. First the jQuery to use [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' addthis:title='Using the jQuery-UI Autocomplete Widget ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/jquery-and-wordpress/' rel='bookmark' title='JQuery and WordPress'>JQuery and WordPress</a></li>
<li><a href='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' rel='bookmark' title='A couple useful jQuery Snippets'>A couple useful jQuery Snippets</a></li>
<li><a href='http://blog.seanja.com/2009/12/simple-tool-tip-with-jquery/' rel='bookmark' title='Simple Tool Tip with jQuery'>Simple Tool Tip with jQuery</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' addthis:title='Using the jQuery-UI Autocomplete Widget '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>The latest version of jQuery-ui has an autocomplete widget. No more <a href="http://code.google.com/p/jquery-autocomplete/">looking</a> <a href="http://docs.jquery.com/Plugins/Autocomplete">for</a> <a href="http://code.drewwilson.com/entry/autosuggest-jquery-plugin">one</a> <a href="http://stackoverflow.com/questions/967199/jquery-auto-suggest-serverside">that</a> <a href="http://www.ajaxdaddy.com/demo-jquery-autocomplete.html">will</a> <a href="http://plugins.jquery.com/project/jq-autocomplete">work</a> (you get the point) with the version of jQuery that you have.</p>
<p>All you have to do is <a href="http://jqueryui.com/download">pull the latest one down</a> from the jQuery-ui site and you are good to go.</p>
<p>First the jQuery to use the autocomplete plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">//we will be using this to cache the responses from the server</span>
<span style="color: #003366; font-weight: bold;">var</span> ajaxCache <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//activate autocomplete on boxes that have the autocomplete class</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input.auto_complete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	source<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//what are we searching for</span>
		<span style="color: #003366; font-weight: bold;">var</span> query_type <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'element'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//the cacheterm that we use to save it in the cache</span>
		<span style="color: #003366; font-weight: bold;">var</span> cachedTerm <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>request.<span style="color: #660066;">term</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">+</span> query_type<span style="color: #009900;">&#41;</span> . <span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//if the data is in the cache and the data is not too long, use it</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ajaxCache<span style="color: #009900;">&#91;</span>cachedTerm<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> undefined <span style="color: #339933;">&amp;&amp;</span> ajaxCache<span style="color: #009900;">&#91;</span>cachedTerm<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//map the data into a response that will be understood by the autocomplete widget</span>
			response<span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span>ajaxCache<span style="color: #009900;">&#91;</span>cachedTerm<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
					label<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span>
					value<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">value</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #006600; font-style: italic;">//get the data from the server</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/ajax/auto_complete.php&quot;</span><span style="color: #339933;">,</span>
				dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
				data<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
					query_type<span style="color: #339933;">:</span> query_type<span style="color: #339933;">,</span>
					q<span style="color: #339933;">:</span> request.<span style="color: #660066;">term</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
				success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #006600; font-style: italic;">//cache the data for later</span>
					ajaxCache<span style="color: #009900;">&#91;</span>cachedTerm<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> data<span style="color: #339933;">;</span>
					<span style="color: #006600; font-style: italic;">//map the data into a response that will be understood by the autocomplete widget</span>
					response<span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
							label<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span>
							value<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">value</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #006600; font-style: italic;">//start looking at 3 characters because mysql's limit is 4</span>
	minLength<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
	<span style="color: #006600; font-style: italic;">//when you have selected something</span>
	select<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//close the drop down</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">close</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #006600; font-style: italic;">//show the drop down</span>
	<span style="color: #000066;">open</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-corner-all&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-corner-top&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #006600; font-style: italic;">//close the drop down</span>
	<span style="color: #000066;">close</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-corner-top&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-corner-all&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The ajax/auto_complete.php would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//make sure that we only allow valid query types</span>
<span style="color: #009933; font-style: italic;">/**
 * @var array
 */</span>
<span style="color: #000088;">$validQueryTypes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'country'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'city'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'first_name'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'last_name'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * @var string
 */</span>
<span style="color: #000088;">$column</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query_type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query_type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$validQueryTypes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009933; font-style: italic;">/**
 * @var string
 */</span>
<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%'</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'country'</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'city'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'addresses'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #666666; font-style: italic;">//to make things simpler for the javascript, always select as value</span>
				<span style="color: #339933;">-&gt;</span><span style="color: #004000;">column</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' as value'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #339933;">,</span> <span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'LIKE'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//SELECT $column as value FROM addresses WHERE $column LIKE '$q%';</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'first_name'</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'last_name'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">-&gt;</span><span style="color: #004000;">column</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' as value'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #339933;">,</span> <span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'LIKE'</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//SELECT $column as value FROM users WHERE $column LIKE '$q%';</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//$result is something like this:</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Canada'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'America'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Mexico'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Netherlands'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//then return it to the javascript</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then the simplest part of the exercise:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&nbsp;
City:
&lt;input type=&quot;text&quot; name=&quot;city&quot; id=&quot;city&quot; title=&quot;enter a city&quot; class=&quot;auto_complete&quot; /&gt;
&nbsp;
Country:
&lt;input type=&quot;text&quot; name=&quot;country&quot; id=&quot;country&quot; title=&quot;enter a country&quot; class=&quot;auto_complete&quot; /&gt;
&nbsp;
First Name:
&lt;input type=&quot;text&quot; name=&quot;first_name&quot; id=&quot;first_name&quot; title=&quot;enter a first_name&quot; class=&quot;auto_complete&quot; /&gt;
&nbsp;
Last Name:
&lt;input type=&quot;text&quot; name=&quot;last_name&quot; id=&quot;last_name&quot; title=&quot;enter a last_name&quot; class=&quot;auto_complete&quot; /&gt;</pre></div></div>

<p>And if they don&#8217;t have javascript enabled it doesn&#8217;t detract from the form (go progressive enhancement!).</p>
<p><ins datetime="2011-09-12T22:11:23+00:00"></p>
<p>Edit:</p>
<p>
This post is pretty old, but just in-case you were wondering sQuery is this: <a href="https://github.com/SeanJA/ShoestringPHP/blob/master/library/classes/squery.class.php" target="_blank">https://github.com/SeanJA/ShoestringPHP/blob/master/library/classes/squery.class.php</a> and there is also a better tested more standalone-y version here as a separate project: <a href="https://github.com/SeanJA/query-builder" target="_blank">https://github.com/SeanJA/query-builder</a>.
</p>
<p></ins></p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' addthis:title='Using the jQuery-UI Autocomplete Widget ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/jquery-and-wordpress/' rel='bookmark' title='JQuery and WordPress'>JQuery and WordPress</a></li>
<li><a href='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' rel='bookmark' title='A couple useful jQuery Snippets'>A couple useful jQuery Snippets</a></li>
<li><a href='http://blog.seanja.com/2009/12/simple-tool-tip-with-jquery/' rel='bookmark' title='Simple Tool Tip with jQuery'>Simple Tool Tip with jQuery</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Finding corrupted images</title>
		<link>http://blog.seanja.com/2010/03/finding-corrupted-images/</link>
		<comments>http://blog.seanja.com/2010/03/finding-corrupted-images/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 12:00:46 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[British Columbia]]></category>
		<category><![CDATA[Canada]]></category>
		<category><![CDATA[Computer file]]></category>
		<category><![CDATA[Computer graphics]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Graphics file formats]]></category>
		<category><![CDATA[Image file formats]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Libpng]]></category>
		<category><![CDATA[Portable Network Graphics]]></category>
		<category><![CDATA[Tagged Image File Format]]></category>
		<category><![CDATA[the Olympics]]></category>
		<category><![CDATA[Vancouver]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=913</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/finding-corrupted-images/' addthis:title='Finding corrupted images '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>As zoe kindly pointed out, two Wednesdays have passed since I last posted. I blame the Olympics (I was in Vancouver for the first week, and I was still recovering from it the second week Go Canada!). You can see my photos on flickr.com as I post them here. Apparently you can only post 100 [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/finding-corrupted-images/' addthis:title='Finding corrupted images ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/dynamic-images-with-php/' rel='bookmark' title='Dynamic Images with PHP'>Dynamic Images with PHP</a></li>
<li><a href='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' rel='bookmark' title='Using the jQuery-UI Autocomplete Widget'>Using the jQuery-UI Autocomplete Widget</a></li>
<li><a href='http://blog.seanja.com/2010/02/new-posts-every-wednesday/' rel='bookmark' title='New posts every Wednesday'>New posts every Wednesday</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2010/03/finding-corrupted-images/' addthis:title='Finding corrupted images '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>As <a href="http://zoeandgavin.com">zoe</a> kindly <a href="http://blog.seanja.com/2010/02/getting-started-with-phpunit/#comment-4921">pointed out</a>, two Wednesdays have passed since I last posted. I blame the Olympics (I was in Vancouver for the first week, and I was still recovering from it the second week Go Canada!). You can see my photos on flickr.com as I post them <a href="http://www.flickr.com/photos/96381253@N00/">here</a>. Apparently you can only post 100 mb/month, so it might take a while. </p>
<p><a href="http://www.flickr.com/photos/96381253@N00/4379856709/" title="DSCN0543 by SeanJA, on Flickr"><img src="http://farm5.static.flickr.com/4059/4379856709_121f99880a_m.jpg" width="240" height="180" alt="DSCN0543" /></a></p>
<p>Anyway, onto the post:</p>
<p>This month at work, one of our servers decided to act up and corrupt quite a few things. We had about 10000 images on that server, many of them were corrupted, many of them were not. Instead of going through all of the images one by one, opening them and checking if they were corrupted, I was tasked with writing a php script to find them. My first instinct was to do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/path/to/files'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Directory handle: <span style="color: #006699; font-weight: bold;">$handle</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Files:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* loop over the directory. */</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Unfortunately, getimagesize only looks at the start of a png file to get the information, meaning that if the file was corrupted after those first few bits of information it would not show up on the list.</p>
<p>The second idea was to use this method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/path/to/files'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Directory handle: <span style="color: #006699; font-weight: bold;">$handle</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Files:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Since they are all png files, this will work: */</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Which, in theory, should have worked because it reads the whole file in and then returns false if the image could not be created. Unfortunately there was (is) something wrong with the libpng library so I kept getting errors like this locally:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">libpng warning: Ignoring bad adaptive filter <span style="color: #7a0874; font-weight: bold;">type</span>
libpng warning: Extra compressed data.
libpng warning: Extra compression data</pre></div></div>

<p>Which would be fine if they were php errors. I could have ignored them because the script worked properly and listed all of the files that had problems. Unfortunately for what ever reason, the server was dying on these errors instead of continuing like it was doing locally.</p>
<p>In comes imagemagick to the rescue. Using the identify command (at the command line) it reads in the whole image file and then tells you what it is. Since you might have 10000 images like we did, it is probably also a good idea to send the output to a file instead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    identify <span style="color: #ff0000;">&quot;./path/to/files/*&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>badImages.txt <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></pre></div></div>

<p>You will also want to make sure that the path has &#8221; &#8221; around it, because otherwise you will end up with an &#8220;Argument list too long&#8221; error. In the <em>badImages.txt</em> file you will have a list of images that are in the folder you specified. Any of the lines that start with <strong>identify</strong> are no good.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2010/03/finding-corrupted-images/' addthis:title='Finding corrupted images ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2008/06/dynamic-images-with-php/' rel='bookmark' title='Dynamic Images with PHP'>Dynamic Images with PHP</a></li>
<li><a href='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' rel='bookmark' title='Using the jQuery-UI Autocomplete Widget'>Using the jQuery-UI Autocomplete Widget</a></li>
<li><a href='http://blog.seanja.com/2010/02/new-posts-every-wednesday/' rel='bookmark' title='New posts every Wednesday'>New posts every Wednesday</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2010/03/finding-corrupted-images/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A couple useful jQuery Snippets</title>
		<link>http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/</link>
		<comments>http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 01:38:04 +0000</pubDate>
		<dc:creator>SeanJA</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[HTML element]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Value at risk]]></category>

		<guid isPermaLink="false">http://blog.seanja.com/?p=695</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' addthis:title='A couple useful jQuery Snippets '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>For popups, just add class=&#8221;popup&#8221; jQuery&#40;'a.popup'&#41;.live&#40;'click', function&#40;&#41;&#123; newwindow=window.open&#40;$&#40;this&#41;.attr&#40;'href'&#41;,'','height=200,width=150'&#41;; if &#40;window.focus&#41; &#123;newwindow.focus&#40;&#41;&#125; return false; &#125;&#41;; To open in a new tab, add class=&#8221;newTab&#8221; jQuery&#40;'a.newTab'&#41;.live&#40;'click', function&#40;&#41;&#123; newwindow=window.open&#40;$&#40;this&#41;.href&#41;; jQuery&#40;this&#41;.target = &#34;_blank&#34;; return false; &#125;&#41;; Check if something is in view function in_view&#40;elem&#41;&#123; var docViewTop = jQuery&#40;window&#41;.scrollTop&#40;&#41;; var docViewBottom = docViewTop + jQuery&#40;window&#41;.height&#40;&#41;; &#160; var elemTop = jQuery&#40;elem&#41;.offset&#40;&#41;.top; var [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' addthis:title='A couple useful jQuery Snippets ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>
Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' rel='bookmark' title='Using the jQuery-UI Autocomplete Widget'>Using the jQuery-UI Autocomplete Widget</a></li>
<li><a href='http://blog.seanja.com/2009/07/a-better-way-to-use-jquery-in-wordpress-themes/' rel='bookmark' title='A better way to use jQuery in WordPress Themes'>A better way to use jQuery in WordPress Themes</a></li>
<li><a href='http://blog.seanja.com/2008/06/jquery-and-wordpress/' rel='bookmark' title='JQuery and WordPress'>JQuery and WordPress</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style " addthis:url='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' addthis:title='A couple useful jQuery Snippets '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div><p>For popups, just add class=&#8221;popup&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.popup'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	newwindow<span style="color: #339933;">=</span>window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'height=200,width=150'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #000066;">focus</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>newwindow.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To open in a new tab, add class=&#8221;newTab&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.newTab'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	newwindow<span style="color: #339933;">=</span>window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">target</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;_blank&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Check if something is in view</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> in_view<span style="color: #009900;">&#40;</span>elem<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> docViewTop <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> docViewBottom <span style="color: #339933;">=</span> docViewTop <span style="color: #339933;">+</span> jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> elemTop <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span>elem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> elemBottom <span style="color: #339933;">=</span> elemTop <span style="color: #339933;">+</span> jQuery<span style="color: #009900;">&#40;</span>elem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>elemBottom <span style="color: #339933;">&gt;=</span> docViewTop<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>elemTop <span style="color: #339933;">&lt;=</span> docViewBottom<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>elemBottom <span style="color: #339933;">&lt;=</span> docViewBottom<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>  <span style="color: #009900;">&#40;</span>elemTop <span style="color: #339933;">&gt;=</span> docViewTop<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/' addthis:title='A couple useful jQuery Snippets ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div><p>Related posts:<ol>
<li><a href='http://blog.seanja.com/2010/03/using-the-jquery-ui-autocomplete-widget/' rel='bookmark' title='Using the jQuery-UI Autocomplete Widget'>Using the jQuery-UI Autocomplete Widget</a></li>
<li><a href='http://blog.seanja.com/2009/07/a-better-way-to-use-jquery-in-wordpress-themes/' rel='bookmark' title='A better way to use jQuery in WordPress Themes'>A better way to use jQuery in WordPress Themes</a></li>
<li><a href='http://blog.seanja.com/2008/06/jquery-and-wordpress/' rel='bookmark' title='JQuery and WordPress'>JQuery and WordPress</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.seanja.com/2009/08/a-couple-useful-jquery-snippets/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

