<?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>RuddWire &#187; code</title>
	<atom:link href="http://www.ruddwire.com/category/tech/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ruddwire.com</link>
	<description>Ruddwire.com: food, book, theatre reviews, data presentation projects, code snippets, millisecond date calculators</description>
	<lastBuildDate>Tue, 27 Dec 2011 02:19:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>aboutmydevice.com : a new site that helps explore a mobile browser&#8217;s Javascript properties</title>
		<link>http://www.ruddwire.com/1114/tech/software/aboutmydevice-com-a-new-site-that-helps-explore-a-mobile-browsers-javascript-properties/</link>
		<comments>http://www.ruddwire.com/1114/tech/software/aboutmydevice-com-a-new-site-that-helps-explore-a-mobile-browsers-javascript-properties/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 04:27:30 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tablets]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=1114</guid>
		<description><![CDATA[Here&#8217;s the latest website I&#8217;m releasing onto the world:  aboutmydevice.com.   I wrote  it so that I could explore what Javascript properties, objects, and values exist on the browsers of various mobile devices.   I walk into a store, go to a phone, load up aboutmydevice.com, and see what kind of properties [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the latest website I&#8217;m releasing onto the world:  <a href="http://aboutmydevice.com">aboutmydevice.com</a>.   I wrote  it so that I could explore what Javascript properties, objects, and values exist on the browsers of various mobile devices.   I walk into a store, go to a phone, load up aboutmydevice.com, and see what kind of properties this browser has.   It&#8217;s been helpful in building things out across devices.  Helpful to explore the different geolocation properties across iOS and Android, the different plugin handling, and other areas where browser makers can&#8217;t agree to just do it all the same.</p>
<p>I hope you find it useful.<br />
-Colin</p>
<a href="http://aboutmydevice.com"><img class="size-full wp-image-1116" title="AboutMyDevice.com" src="http://www.ruddwire.com/wp-content/uploads/2011/09/abd.png" alt="screenshot"  /></a>
]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/1114/tech/software/aboutmydevice-com-a-new-site-that-helps-explore-a-mobile-browsers-javascript-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My cousin Graham, living on the bleeding edge of chicken wing consumption tracking technology</title>
		<link>http://www.ruddwire.com/1073/food/my-cousin-graham-living-on-the-bleeding-edge-of-chicken-wing-consumption-tracking-technology/</link>
		<comments>http://www.ruddwire.com/1073/food/my-cousin-graham-living-on-the-bleeding-edge-of-chicken-wing-consumption-tracking-technology/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 04:59:12 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[food]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[rfid]]></category>
		<category><![CDATA[symphony]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/1073/food/my-cousin-graham-living-on-the-bleeding-edge-of-chicken-wing-consumption-tracking-technology/</guid>
		<description><![CDATA[http://grahamc.com/blog/how-to-create-a-super-nerdy-superbowl-that-everyone-will-love/   a rather impressive demonstration of skills
]]></description>
			<content:encoded><![CDATA[<p><a href="http://grahamc.com/blog/how-to-create-a-super-nerdy-superbowl-that-everyone-will-love/">http://grahamc.com/blog/how-to-create-a-super-nerdy-superbowl-that-everyone-will-love/</a>   a rather impressive demonstration of skills</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/1073/food/my-cousin-graham-living-on-the-bleeding-edge-of-chicken-wing-consumption-tracking-technology/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl script make MySQL query, binds variables, outputs JSON</title>
		<link>http://www.ruddwire.com/1049/tech/perl-script-make-mysql-query-binds-variables-outputs-json/</link>
		<comments>http://www.ruddwire.com/1049/tech/perl-script-make-mysql-query-binds-variables-outputs-json/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 00:40:11 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=1049</guid>
		<description><![CDATA[An example of a Perl script that is called by an ajax request.  The script takes in just one parameter, opens a MySQL DB connection, binds the parameter to the query, and sends the query.  The result is then formatted into JSON and returned to the browser.
This can be seen in action on [...]]]></description>
			<content:encoded><![CDATA[<p>An example of a Perl script that is called by an ajax request.  The script takes in just one parameter, opens a MySQL DB connection, binds the parameter to the query, and sends the query.  The result is then formatted into JSON and returned to the browser.</p>
<p>This can be seen in action on this page: <a href="http://www.ruddwire.com/friendly-data/naics-explorer/">http://www.ruddwire.com/friendly-data/naics-explorer/</a>, in the NAICS search box.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>standard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mySQL</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'({&quot;failure&quot;:1})'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#QUERY PARAMS</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$q</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ref</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$table</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tableRow</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
    <span style="color: #0000ff;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'q'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$q</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\s+/%/</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;"># REPLACE SPACES WITH WILD CARD CHARACTER, CAUSES TO SEARCH FOR ALL WORDS, NOT JUST PHRASE</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">### Connect to the database.</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;DBI:mysql:database=***DBNAME***;host=localhost&quot;</span><span style="color: #339933;">,</span>
                         <span style="color: #ff0000;">&quot;***USERNAME***&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;***PASSWORD***&quot;</span><span style="color: #339933;">,</span>
                         <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'RaiseError'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #666666; font-style: italic;">### GET INDUSTRY NAME AND CODE</span>
    	<span style="color: #0000ff;">$mySQL</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT code,industry FROM naics2007IndustryIndex WHERE industry LIKE ? ORDER BY industry&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
     <span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$mySQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">q</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ref</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_hashref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">%$ref</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		  	  <span style="color: #0000ff;">$value</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/&quot;/\\&quot;/g</span><span style="color: #339933;">;</span>
			  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>${value}<span style="color: #000099; font-weight: bold;">\&quot;</span>,&quot;</span><span style="color: #339933;">;</span>
		  <span style="color: #009900;">&#125;</span>
&nbsp;
		  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/,$//</span><span style="color: #339933;">;</span>
		  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;[${tableRow}],&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		  <span style="color: #0000ff;">$table</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$tableRow</span><span style="color: #339933;">;</span>
		  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">$table</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/,$//</span><span style="color: #339933;">;</span>
&nbsp;
	  	<span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'{&quot;failure&quot;:0,&quot;result&quot;:['</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$table</span><span style="color: #339933;">.</span><span style="color: #ff0000;">']}'</span><span style="color: #339933;">;</span>         
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">### END IF QUERY</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Content-type: text/javascript; charset=iso-8859-1<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/1049/tech/perl-script-make-mysql-query-binds-variables-outputs-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl script makes MySQL query; outputs to JSON</title>
		<link>http://www.ruddwire.com/1025/tech/perl-script-makes-mysql-query-outputs-to-json/</link>
		<comments>http://www.ruddwire.com/1025/tech/perl-script-makes-mysql-query-outputs-to-json/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 01:37:34 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=1025</guid>
		<description><![CDATA[<p>An example of a perl script that is called by an ajax request.  The script takes in a few parameters, opens a mySQL DB connection, and then makes a rather tortuous query.  The result is then formatted in to JSON and returned to the browser.</p>]]></description>
			<content:encoded><![CDATA[<p>An example of a Perl script that is called by an ajax request.  The script takes in a few parameters, opens a MySQL DB connection, and then makes a rather tortuous query.  The result is then formatted into JSON and returned to the browser.</p>
<p>This can be seen in action on this page: <a href="http://www.ruddwire.com/friendly-data/naics-explorer/">http://www.ruddwire.com/friendly-data/naics-explorer/</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>standard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mySQL</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'({&quot;failure&quot;:1})'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#QUERY PARAMS</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$strLn</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$classification</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$getDef</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$getIndus</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$naicsMatch</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$countMatch</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@subClasses</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ref</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$table</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tableRow</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> scrubInputText <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #b1b100;">my</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$it</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$shellChars</span> <span style="color: #339933;">=</span> q<span style="color: #339933;">-</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">&amp;;</span><span style="color: #ff0000;">`'<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\|</span><span style="color: #000099; font-weight: bold;">\*</span><span style="color: #000099; font-weight: bold;">\?</span><span style="color: #000099; font-weight: bold;">\~</span>&lt;&gt;<span style="color: #000099; font-weight: bold;">\^</span><span style="color: #000099; font-weight: bold;">\(</span><span style="color: #000099; font-weight: bold;">\)</span><span style="color: #000099; font-weight: bold;">\[</span><span style="color: #000099; font-weight: bold;">\]</span><span style="color: #000099; font-weight: bold;">\{</span><span style="color: #000099; font-weight: bold;">\}</span><span style="color: #000099; font-weight: bold;">\$</span><span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\\</span>r]-;    #`</span>
&nbsp;
    <span style="color: #0000ff;">$it</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/$shellChars//g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$it</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^\s+|\s+$//g</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066;">return</span> <span style="color: #0000ff;">$it</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CGI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #0000ff;">$strLn</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&amp;scrubInputText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'strLn'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$classification</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&amp;scrubInputText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'cls'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$getDef</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&amp;scrubInputText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'getDef'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$getIndus</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&amp;scrubInputText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">param</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'getIndus'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">###HANDLE GROUPED SECTOR CODES, IE: 31-33</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$classification</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/-/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    	<span style="color: #0000ff;">@subClasses</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$classification</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #0000ff;">$naicsMatch</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;AND (&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$subClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$subClasses</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$subClass</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000ff;">$subClasses</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$subClass</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    		<span style="color: #0000ff;">$naicsMatch</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;code LIKE '${subClass}%' OR &quot;</span><span style="color: #339933;">;</span>
    		<span style="color: #0000ff;">$countMatch</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;code LIKE '${subClass}%' OR &quot;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
    	<span style="color: #0000ff;">$countMatch</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/ OR $//</span><span style="color: #339933;">;</span>
    	<span style="color: #0000ff;">$naicsMatch</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/ OR $//</span><span style="color: #339933;">;</span>
    	<span style="color: #0000ff;">$naicsMatch</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
       <span style="color: #0000ff;">$naicsMatch</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;AND code LIKE '${classification}%'&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$strLn</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$countMatch</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;code LIKE Concat(naics2007.code,'%')&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">### Connect to the database.</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;DBI:mysql:database=***DBNAME***;host=localhost&quot;</span><span style="color: #339933;">,</span>
                         <span style="color: #ff0000;">&quot;***USERNAME***&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;***PASSWORD***&quot;</span><span style="color: #339933;">,</span>
                         <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'RaiseError'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$getDef</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    	<span style="color: #0000ff;">$mySQL</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT definition FROM naics2007definitions WHERE code='${classification}'&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elsif</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$getIndus</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    	<span style="color: #666666; font-style: italic;">### GET FINAL INDUSTRY NAME</span>
    	<span style="color: #0000ff;">$mySQL</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT code,industry FROM naics2007IndustryIndex WHERE code LIKE '${classification}' ORDER BY industry&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    	<span style="color: #666666; font-style: italic;">### GET INDUSTRY CLASSIFICATIONS</span>
&nbsp;
&nbsp;
 		<span style="color: #0000ff;">$mySQL</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;SELECT code,title, &quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot;(SELECT COUNT(code) FROM naics2007IndustryIndex WHERE &quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot;CASE naics2007.code &quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot;WHEN '31-33' THEN (code LIKE '31%' OR code LIKE '32%' OR code LIKE '33%') &quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot;WHEN '44-45' THEN (code LIKE '44%' OR code LIKE '45%') &quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot;WHEN '48-49' THEN (code LIKE '48%' OR code LIKE '49%') &quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot;ELSE code LIKE Concat(naics2007.code,'%') END) AS c&quot;</span><span style="color: #339933;">.</span>
     	<span style="color: #ff0000;">&quot; FROM naics2007 WHERE (CHAR_LENGTH(code) = $strLn OR code LIKE '__-__')&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$naicsMatch</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
     <span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$mySQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ref</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_hashref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">%$ref</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		  	  <span style="color: #0000ff;">$value</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/&quot;/\\&quot;/g</span><span style="color: #339933;">;</span>
			  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>${value}<span style="color: #000099; font-weight: bold;">\&quot;</span>,&quot;</span><span style="color: #339933;">;</span>
		  <span style="color: #009900;">&#125;</span>
&nbsp;
		  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/,$//</span><span style="color: #339933;">;</span>
		  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;[${tableRow}],&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		  <span style="color: #0000ff;">$table</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$tableRow</span><span style="color: #339933;">;</span>
		  <span style="color: #0000ff;">$tableRow</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">$table</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/,$//</span><span style="color: #339933;">;</span>
&nbsp;
	  	<span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'{&quot;failure&quot;:0,&quot;result&quot;:['</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$table</span><span style="color: #339933;">.</span><span style="color: #ff0000;">']}'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">### END IF QUERY</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Content-type: application/json; charset=iso-8859-1<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/1025/tech/perl-script-makes-mysql-query-outputs-to-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UNIX/AWK Tricks: How to copy a long list of files into a directory</title>
		<link>http://www.ruddwire.com/999/tech/unixawk-tricks/</link>
		<comments>http://www.ruddwire.com/999/tech/unixawk-tricks/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 22:39:40 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[AWK]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=999</guid>
		<description><![CDATA[

Make your list of files, with complete paths, call it &#8220;imgList.txt&#8221;. Put every file on a new line.
Write a small awk script with the following 1 line:
{ printf(&#8221;cp %s images/\n&#8221;,$0);}

Save the script as &#8220;copyList.awk&#8221;
Do the following command:
awk -f copyList.awk imgList.txt &#124; sh


Brief explanation of the awk script:

%s means you&#8217;re putting a string in that spot [...]]]></description>
			<content:encoded><![CDATA[<div class="mtb">
<ol>
<li>Make your list of files, with complete paths, call it &#8220;imgList.txt&#8221;. Put every file on a new line.</li>
<li>Write a small awk script with the following 1 line:
<div class="code">{ printf(&#8221;cp %s images/\n&#8221;,$0);}</div>
</li>
<li>Save the script as &#8220;copyList.awk&#8221;</li>
<li>Do the following command:
<div class="code">awk -f copyList.awk imgList.txt | sh</div>
</li>
</ol>
<p>Brief explanation of the awk script:</p>
<ul>
<li>%s means you&#8217;re putting a string in that spot of your output,</li>
<li>$0 is the string you&#8217;re putting there</li>
<li>$0 is a match for each line in the file &#8220;imgList.txt&#8221;</li>
<li>images/ is the directory to copy your files to (in this example relative to where the command will be run from &#8211; can be absolute, of course)</li>
<li>\n stands for new line</li>
</ul>
<p>brief explanation of the command:</p>
<ul>
<li>awk executes the awk code found in &#8220;copyList.awk&#8221; on the lines found in &#8220;imgList.txt&#8221; and pipes the output to the shell ( | sh).</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/999/tech/unixawk-tricks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML Character Entities in Javascript</title>
		<link>http://www.ruddwire.com/994/tech/html-character-entities-in-javascript/</link>
		<comments>http://www.ruddwire.com/994/tech/html-character-entities-in-javascript/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 22:34:23 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=994</guid>
		<description><![CDATA[Sometimes you need to write html character entities in javascript, but html character entities can&#8217;t be used, because they don&#8217;t get interpreted by javascript. In javascript, you need to use the equivalent unicode character codes instead.
HTML character entity, wrong:
formElement.value = "Direcci&#38;#243;n";
You get: Direcci&#38;#243;n
Unicode character code, correct:
formElement.value = "Direcci\u00F3n";
You get: Dirección
Unicode character charts are located here: [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to write html character entities in javascript, but html character entities can&#8217;t be used, because they don&#8217;t get interpreted by javascript. In javascript, you need to use the equivalent unicode character codes instead.</p>
<p><span style="font-weight: bold;">HTML character entity, wrong:</span><br />
<code>formElement.value = "Direcci&amp;#243;n";</code><br />
You get: Direcci&amp;#243;n</p>
<p><span style="font-weight: bold;">Unicode character code, correct:</span><br />
<code>formElement.value = "Direcci\u00F3n";</code><br />
You get: Dirección</p>
<p>Unicode character charts are located here: <a href="http://www.unicode.org/charts/">http://www.unicode.org/charts/</a>.  The chart you will most likely need is the <a href="http://www.unicode.org/charts/PDF/U0080.pdf">Latin-1</a> chart.   Character codes must be preceded by \u.  That is, character code 00F3 is written in JavaScript as \u00F3.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/994/tech/html-character-entities-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handy MySQL Commands</title>
		<link>http://www.ruddwire.com/991/tech/handy-mysql-commands/</link>
		<comments>http://www.ruddwire.com/991/tech/handy-mysql-commands/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 22:30:20 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[mySQL]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=991</guid>
		<description><![CDATA[To reset an auto_increment field to 1:
ALTER TABLE tbl_name AUTO_INCREMENT = 1;

To load a local csv file into an empty existing table:
LOAD DATA LOCAL INFILE &#8216;/completePathToLocalData.csv&#8217; INTO TABLE tableName FIELDS TERMINATED BY &#8216;,&#8217; ENCLOSED BY &#8216;&#8221;&#8216; LINES TERMINATED BY &#8216;\n&#8217; IGNORE 1 LINES;
This assumes you&#8217;ve already created your empty table with the same number of [...]]]></description>
			<content:encoded><![CDATA[<div class="mtb">To reset an auto_increment field to 1:</p>
<div class="code">ALTER TABLE tbl_name AUTO_INCREMENT = 1;</div>
</div>
<div class="mtb">To load a local csv file into an empty existing table:</p>
<div class="code">LOAD DATA LOCAL INFILE &#8216;/completePathToLocalData.csv&#8217; INTO TABLE tableName FIELDS TERMINATED BY &#8216;,&#8217; ENCLOSED BY &#8216;&#8221;&#8216; LINES TERMINATED BY &#8216;\n&#8217; IGNORE 1 LINES;</div>
<p>This assumes you&#8217;ve already created your empty table with the same number of fields that your csv file has.</p></div>
<p><a name="js"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/991/tech/handy-mysql-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery parsererror: clean up your JSON objects</title>
		<link>http://www.ruddwire.com/904/tech/jquery-parsererror-clean-up-your-json-objects/</link>
		<comments>http://www.ruddwire.com/904/tech/jquery-parsererror-clean-up-your-json-objects/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 03:49:23 +0000</pubDate>
		<dc:creator>Colin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[parsererror]]></category>

		<guid isPermaLink="false">http://www.ruddwire.com/?p=904</guid>
		<description><![CDATA[Has your JSON using jQuery web app suddenly stopped working?  Getting a parsererror on your JSON objects, where you got none before?  This is what happened to me when my site upgraded to jQuery 1.4.
I use the Google API&#8217;s jQuery, and it automatically upgraded my whole site to jQuery 1.4.   In jQuery 1.4, they [...]]]></description>
			<content:encoded><![CDATA[<p>Has your JSON using jQuery web app suddenly stopped working?  Getting a parsererror on your JSON objects, where you got none before?  This is what happened to me when my site upgraded to jQuery 1.4.</p>
<p>I use the <a href="http://code.google.com/apis/ajaxlibs/documentation/">Google API&#8217;s jQuery</a>, and it automatically upgraded my whole site to jQuery 1.4.   In jQuery 1.4, they decided to tighten up the JSON parsing engine, so that it is now unforgiving of any lax standards.  You have to follow the JSON standard <a href="http://json.org/">spelled out here</a> &#8212; to the letter.  In my case, that meant changing any single quoted values or names to double quotes, and getting rid of opening and closing parentheses.  Like most fixes, it was an easy fix, once I figured it out.  Hope this helps.</p>
<p>-Colin</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ruddwire.com/904/tech/jquery-parsererror-clean-up-your-json-objects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

