<?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>Jon&#039;s Blog</title>
	<atom:link href="http://jctweb.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jctweb.net</link>
	<description>My blog</description>
	<lastBuildDate>Wed, 07 Dec 2011 22:01:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Lazy with bitwise operators</title>
		<link>http://jctweb.net/2011/12/07/lazy-with-bitwise-operators/</link>
		<comments>http://jctweb.net/2011/12/07/lazy-with-bitwise-operators/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 21:57:29 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=157</guid>
		<description><![CDATA[There is a certain charm in using a single variable to store a bunch of boolean flags. Binary is convenient because it is all 1&#8242;s (true) and 0&#8242;s (false). The part I don&#8217;t like is assigning variables to each position &#8230; <a href="http://jctweb.net/2011/12/07/lazy-with-bitwise-operators/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is a certain charm in using a single variable to store a bunch of boolean flags. Binary is convenient because it is all 1&#8242;s (true) and 0&#8242;s (false). The part I don&#8217;t like is assigning variables to each position in the binary number. When mapping out the variable, there are a couple of ways you may think of defining your flags. It would be somewhat convenient if you could write the binary numbers out like:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$is_user</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_admin</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_superhero</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_troll</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10000000000000000</span><span style="color: #339933;">;</span></div></div>
<p>PHP does not offer this convenience. Some devs might suggest hex notation (0&#215;1, 0&#215;2, etc) or something that makes me sad like using bindec(). Then there is the tried-and-true method of defining your variable for each position in the binary string:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$is_user</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_admin</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_superhero</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_troll</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">65536</span><span style="color: #339933;">;</span></div></div>
<p>I prefer a more lazy approach (and I think it is more readable, personally) to defining my boolean flags; use the shift left <a title="PHP Bitwise Operators" href="http://us3.php.net/operators.bitwise" target="_blank">operator</a><span style="color: #000000;"><strong> &lt;&lt;</strong></span></p>
<p>The shift left operator is basically multiplying a number times 2. Since the binary positions are powers of 2, I can define my flags like so:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$is_user</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_admin</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//2</span><br />
<span style="color: #000088;">$is_superhero</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//4</span><br />
<span style="color: #000088;">$is_troll</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">17</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//65536</span></div></div>
<p>I like writing it this way for a number of reasons:</p>
<ul>
<ul>
<li>the second number tells me which position the flag is in (starting from 0)</li>
<li>It is easy for me to tell when I&#8217;m running out of flags (you only get 32 bits per number!).</li>
<li>bitwise operations are fast</li>
</ul>
<p>I understand that there are many more ways I could do this (like the pow() function and others); but that would be less fun, right?<br />
Checking against my permission variable is easy with the &amp; bitwise operator:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$permission</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$is_admin</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">/* do admin stuff */</span> <span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2011/12/07/lazy-with-bitwise-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sessions without Cookies in CodeIgniter</title>
		<link>http://jctweb.net/2011/09/20/sessions-without-cookies-in-codeigniter/</link>
		<comments>http://jctweb.net/2011/09/20/sessions-without-cookies-in-codeigniter/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 16:56:23 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=151</guid>
		<description><![CDATA[Why No Cookies? I wrote a web application that is primarily used by university students. Students use it primarily from their school&#8217;s computer labs, libraries, and in their classrooms. They rarely access the application from their own computer. The most &#8230; <a href="http://jctweb.net/2011/09/20/sessions-without-cookies-in-codeigniter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Why No Cookies?</h2>
<p>I wrote a web application that is primarily used by university students. Students use it primarily from their school&#8217;s computer labs, libraries, and in their classrooms. They rarely access the application from their own computer. The most surprising (and frustrating) thing about this scenario is that at least half of these universities have disabled cookies on any school-owned computer.</p>
<p>This becomes a challenge because the cookie is the primary means that PHP keeps track of the session ID.  I saw 2 alternatives:</p>
<ol>
<li>Put the session ID in the URL</li>
<li>Use POST instead of GET</li>
</ol>
<p>I went with Option 1.  It isn&#8217;t ideal (<a href="https://www.owasp.org/index.php/Session_hijacking_attack">session hijacking</a>, anyone?) but I figured it&#8217;s the best I could do given the circumstances.</p>
<h2>Standard PHP</h2>
<p>When you disable cookies for standard (non CodeIgniter) PHP sites, the PHP parser does a little bit of magic. For example if your page contains an anchor tag:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/path/to/page.php&quot;</span>&gt;</span>Click Me!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></div></div>
<p>PHP (with session cookies turned off) will render this:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/path/to/page.php?PHPSESSID=THESESSIONIDHERE&quot;</span>&gt;</span>Click Me!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></div></div>
<p>It&#8217;s nice that PHP does that &#8211; but by default, CodeIgniter doesn&#8217;t have GET parameters enabled!</p>
<h2>CodeIgniter Routing</h2>
<p>CodeIgniter has a nice feature called routing that allows me to break the normal URI pattern of</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/controller/method/parameter</div></div>
<p>Since I have no idea how many parameters any particular method will need, I can&#8217;t necessarily put the session id at the end of the URL.  I also have the capability of adding folders where my controllers are, so I can conceivably have a uri with folders like this:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/folder/controller/method/parameter</div></div>
<p>or this:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/folder/folder/controller/method/parameter</div></div>
<p>I decided that it was best to use routing to put the session id in segment 1 of the uri (typically reserved for the controller &#8211; but could be a folder as well).  My final pattern is now:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/session id/controller/method/parameter</div></div>
<p>I change /application/config/routes.php to ignore segment 1 when CodeIgniter is looking for the right controller:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'(\w*)/(.*)'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span><span style="color: #339933;">;</span></div></div>
<p>In my controllers, I make sure I retrieve the session id from the routed uri:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990000;">session_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PHPSESSID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$sid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uri</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">segment</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">session_id</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>That&#8217;s it!  Sessions without cookies using CodeIgniter.</p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2011/09/20/sessions-without-cookies-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using a CSS framework &#8211; don&#8217;t style the structure!</title>
		<link>http://jctweb.net/2011/08/02/using-a-css-framework-dont-style-the-structure/</link>
		<comments>http://jctweb.net/2011/08/02/using-a-css-framework-dont-style-the-structure/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 13:38:23 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=147</guid>
		<description><![CDATA[I&#8217;m a fan of using CSS frameworks. Two in particular have come in handy; Blueprint and the 960 Grid System. I like the CSS framework for a couple of major reasons: Greatly reduce cross-browser frustration with visual elements Make it &#8230; <a href="http://jctweb.net/2011/08/02/using-a-css-framework-dont-style-the-structure/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a fan of using CSS frameworks. Two in particular have come in handy; <a href="http://blueprintcss.org/" target="_blank">Blueprint</a> and the <a href="http://960.gs/" target="_blank">960 Grid System</a>. I like the CSS framework for a couple of major reasons:</p>
<ol>
<li>Greatly reduce cross-browser frustration with visual elements</li>
<li>Make it really easy to create complex table-less layouts</li>
</ol>
<p>One of the major features of both frameworks is the use of columns for layout. Class names generally refer to the number of columns any particular div spans across.  The challenge that I&#8217;ve noticed many developers face is overcoming their desire to style these structural elements.  Take this example (using blueprint):</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-12&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Left side text<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-12 last&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Right side text<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<p>What if I want a border around the left side?  At first glance, you might think it would be easy to add an ID to the first div and give it a border, right?  That&#8217;s actually a bad idea.  Why? Because the grid portion of the CSS framework is made for structure and layout &#8211; not for style.  Adding a border actually widens the div; which would break the column layout!</p>
<p>My recommendation is to add an additional &#8220;styling&#8221; div inside the structural div for any block styling you want to do (background color, padding, borders, etc):</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-12&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border:1px solid #000; padding:1em;&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Left side text<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-12 last&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Right side text<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<p>While it may feel like you&#8217;re approaching &#8220;tag soup&#8221;, you still have cleaner markup than a table-based layout.</p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2011/08/02/using-a-css-framework-dont-style-the-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A useful use of SQL &#8220;LIKE&#8221;</title>
		<link>http://jctweb.net/2010/12/15/a-useful-use-of-sql-like/</link>
		<comments>http://jctweb.net/2010/12/15/a-useful-use-of-sql-like/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 16:05:52 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=136</guid>
		<description><![CDATA[I needed to update a set of records in the database where a &#8220;code&#8221; column followed a specific format: prefix_shortname_number As it turned out, there were a bunch of entries that I did *not* want to update that followed a &#8230; <a href="http://jctweb.net/2010/12/15/a-useful-use-of-sql-like/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I needed to update a set of records in the database where a &#8220;code&#8221; column followed a specific format:</p>
<p>prefix_shortname_number</p>
<p>As it turned out, there were a bunch of entries that I did *not* want to update that followed a similar format:</p>
<p>prefix_shortname_letter</p>
<p>This would have been bad:</p>
<div class="codecolorer-container sql twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #993333; font-weight: bold;">SET</span> column_name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'value'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> code <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'prefix_shortname[_]%'</span></div></div>
<p>As luck would have it, SQL Server (I didn&#8217;t check this on MySQL) allows a little bit of semi-regex in LIKE statements.  This update statement worked perfectly:</p>
<div class="codecolorer-container sql twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #993333; font-weight: bold;">SET</span> column_name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'value'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> code <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'prefix_shortname_[0-9]%'</span></div></div>
<p>SQL Server will match a single character within the range provided between the brackets; which was all I needed <img src='http://jctweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/12/15/a-useful-use-of-sql-like/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To-do Lists with Vimwiki</title>
		<link>http://jctweb.net/2010/09/24/to-do-lists-with-vimwiki/</link>
		<comments>http://jctweb.net/2010/09/24/to-do-lists-with-vimwiki/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 19:57:18 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=127</guid>
		<description><![CDATA[One of my challenges (as evidenced by my epic fail with Project52) has been to maintain a list of things to do and getting them done.&#160; I’ve tried a number of online services such as remember the milk (RTM), Todoist, &#8230; <a href="http://jctweb.net/2010/09/24/to-do-lists-with-vimwiki/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of my challenges (as evidenced by my epic fail with <a href="http://project52.info/" target="_blank">Project52</a>) has been to maintain a list of things to do <strong>and getting them done</strong>.&#160; I’ve tried a number of online services such as <a href="http://www.rememberthemilk.com/" target="_blank">remember the milk</a> (RTM), <a href="http://todoist.com/" target="_blank">Todoist</a>, and <a href="http://tadalist.com/" target="_blank">Ta-da List</a>. Each of those are free online services that specialize in creating manageable lists of things to do.&#160; Personally, I still use <abbr title="Remember The Milk">RTM (</abbr>though only for specific types of tasks) because:</p>
<ol>
<li>I can use SMS (through twitter direct messaging) to create tasks </li>
<li>I get SMS reminders when tasks are coming up </li>
<li>There’s a cool <a href="http://www.rememberthemilk.com/services/gmail/gadget/" target="_blank">gmail gadget</a> that I use a lot </li>
</ol>
<p>Usually the “speific types of tasks” for RTM are those non-specific things that are important but don’t require me to be in front of my pc.&#160; things like birthday gift ideas, remembering to call the cable company about my bill, and reminding myself to check out a cool website are all tasks that I want to do at a certain time; but aren’t tied to a specific project/client/job and therefore don’t need to be “in my face” all the time.</p>
<p>“What’s the problem?” you may ask,&#160; “These services are more than sufficient to handle even the busiest of schedules and largest task lists!” </p>
<p>I certainly agree with the assertion that those existing tools are sufficient to handle my needs.&#160; I would argue, however, that the imposed workflow of those tools are what keep me from fully utilizing them.&#160; Imagine this scenario:&#160; I’m working on some code (in GVIM, of course)and realize a change needs to be made in a different part of the site</p>
<ol>
<li>I open new tab in my browser </li>
<li>go to my todo list website </li>
<li>log in (if the site didn’t remember me) </li>
<li>find the correct list (i keep my lists based on clients and projects) </li>
<li>add the new item to the list </li>
<li>resume work </li>
</ol>
<p>Not sure if that represents how I would always use it; I suppose I could skip the “open new tab, go to website, log in, find list” steps by just doing that part first when I start working on a project.&#160; Regardless of whether or not there are ways to make the use of online to-do lists more efficient, I knew that there had to be a way to manage lists of things without leaving the comfort of my favorite editor.</p>
<p>Enter vimwiki (<a href="http://code.google.com/p/vimwiki/">http://code.google.com/p/vimwiki/</a>)</p>
<p>In a nutshell, the above scenario changes a little:</p>
<ol>
<li>:tabnew </li>
<li>\ww </li>
<li>navigate to the list </li>
<li>move to list of items i’m working on </li>
<li>o </li>
<li>type in new task </li>
<li>:up </li>
<li>:tabr </li>
<li>resume work </li>
</ol>
<p>While that looks less efficient (9 steps instead of 6) &#8211; remember that my hands never leave the keyboard; so there&#8217;s no hunting around with the mouse followed by the click-and-wait web experience.  I could also save a few steps if I leave the current project&#8217;s buffer open in the tab so I only have to switch to it when I need to add an item.</p>
<p>Commands explained:</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">:</span>tabnew</div></div>
<p>Creates a new &quot;tab&quot; with an empty buffer</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">\<span style="color: #668080;">ww</span></div></div>
<p>Opens my default wiki page</p>
<p>Navigating between pages is easy with the ENTER and BACKSPACE keys</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">o</div></div>
<p>Insert a new line under the curser and switch to Insert mode</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">:</span>up</div></div>
<p>Update (Save) the current buffer</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">:</span>tabr</div></div>
<p>Switch to the first tab</p>
<p>This probably seems more difficult than it needs to be.&#160; Why not just have a text file with a list of items that need to be done?&#160; I could have one text file for each client/project and be done with it!&#160; Here’s where the real power of vimwiki comes into play.&#160; Since I’m using wiki syntax to enter the to do items (I also like to take notes into my wiki files and describe requirements,etc), the finished files are then exportable to just about any wiki; so the data becomes portable.</p>
<p>There’s also a feature that lets me publish the wiki content into HTML files that I can view in my browser (if I so desire).</p>
<p>Overall, it took about 5 minutes for me to install, configure, and start using vimwiki with positive results.&#160;&#160; I’m able to jot down notes and to do items quickly and efficiently and save them in a portable format.</p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/09/24/to-do-lists-with-vimwiki/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code folding with VIM &#8211; the manual way</title>
		<link>http://jctweb.net/2010/01/29/code-folding-with-vim-the-manual-way/</link>
		<comments>http://jctweb.net/2010/01/29/code-folding-with-vim-the-manual-way/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 15:41:10 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://jctweb.net/2010/01/29/code-folding-with-vim-the-manual-way/</guid>
		<description><![CDATA[Now that I’ve been using VIM (GVIM, to be exact) for the last few months exclusively as my code editor, I’m finally becoming comfortable with the some of the more common keyboard commands.&#160; For example, I was editing an unordered &#8230; <a href="http://jctweb.net/2010/01/29/code-folding-with-vim-the-manual-way/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Now that I’ve been using VIM (GVIM, to be exact) for the last few months exclusively as my code editor, I’m finally becoming comfortable with the some of the more common keyboard commands.&#160; For example, I was editing an unordered list yesterday and wanted to fill it will a bunch of items.&#160; Without thinking, I put my cursor onto the list item I wanted to copy and typed:</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">yy10p</div></div>
</p>
<p>What did that do?&#160; Copied the current line and pasted it in 10 times.&#160; How many keystrokes would YOU have had to use in your editor?&#160; A lot more, I’m guessing <img src='http://jctweb.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Anyway, code folding is a must-have when I’m editing.&#160; When the HTML code is particularly long, I like to fold stuff out of the way so I can focus on what I’m working on rather than see all the surrounding document.&#160; Rather than rely on indentation or syntax, it’s faster for me to use the ‘manual’ folding method.&#160; You can temporarily set this mode on the current buffer with the following command:</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">:</span><span style="color: #804040;">set</span> <span style="color: #668080;">fdm</span>=manual</div></div>
</p>
<p>Once that’s done, folds can be created manually by typing</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">zf</div></div>
</p>
<p>Let’s say I’m working on a large HTML file and I’m on line 500.&#160; I want to fold everything above where I’m working.&#160; There are several ways to do this, but here’s how I did it today.&#160; Assumption: my cursor is already on line 500:</p>
<p><div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jvggzf</div></div>
</p>
<p>Ugh – looks ugly…but it is effective.&#160; Here’s what it does:</p>
<ol>
<li>j = move the cursor up one line (to line 499)</li>
<li>v = switch to visual block selection mode</li>
<li>gg = move the cursor to the top of the document</li>
<li>zf = create a fold</li>
</ol>
<p>The end result?&#160; Everything above line 500 is folded out of the way.&#160; Very handy <img src='http://jctweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/01/29/code-folding-with-vim-the-manual-way/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Doctrine ORM with CodeIgniter: Introduction</title>
		<link>http://jctweb.net/2010/01/19/doctrine-codeigniter-intro/</link>
		<comments>http://jctweb.net/2010/01/19/doctrine-codeigniter-intro/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 04:22:58 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[doctrine]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=108</guid>
		<description><![CDATA[I&#8217;m currently developing a website for scheduling a volunteer group. (I&#8217;ll announce that in a separate entry). For this particular project, I chose the following: CodeIgniter PHP Framework Blueprint CSS Doctrine ORM jQuery/jQuery UI jQuery Calendar Plugin I&#8217;m going to &#8230; <a href="http://jctweb.net/2010/01/19/doctrine-codeigniter-intro/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently developing a website for scheduling a volunteer group.  (I&#8217;ll announce that in a separate entry).  For this particular project, I chose the following:</p>
<ul>
<li><a href="http://codeigniter.com">CodeIgniter PHP Framework</a></li>
<li><a href="http://blueprintcss.org/">Blueprint CSS</a></li>
<li><a href="http://www.doctrine-project.org/">Doctrine ORM</a></li>
<li><a href="http://jquery.com">jQuery</a>/<a href="http://jqueryui.com">jQuery UI</a></li>
<li><a href="http://arshaw.com/fullcalendar/">jQuery Calendar Plugin</a></li>
</ul>
<p>I&#8217;m going to focus on the Doctrine integration for this entry.  I got the idea to try Doctrine from <a href="http://www.phpandstuff.com/articles/author/burak">Burak</a>&#8216;s blog &#8220;PHP and Stuff&#8221;.  I started with this entry on using <a href="http://www.phpandstuff.com/articles/codeigniter-doctrine-from-scratch-day-1-install-and-setup">CodeIgniter with Doctrine</a>.</p>
<p>The idea is this &#8211; If you&#8217;re already accessing objects in PHP to handle things like form validation, creating users, logging in, etc; why not use objects to represent your data as well?  Doctrine provides a really nice framework to help do just that.</p>
<p>Typically, I would write my CodeIgniter Models to include a method for each operation I would need to perform on a particular type of data (Typical <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a>)</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//methods in a user &quot;model&quot; in code igniter</span><br />
<span style="color: #000000; font-weight: bold;">function</span> insert_user<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//SQL code to insert a user</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> update_user<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//SQL code to update a user</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> get_user<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//SQL to get user info from the database</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> delete_user<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//SQL to delete a user</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Doctrine does things a little differently.  The &#8220;model&#8221; is really just a definition of the User database table and its relationships rather than an object containing the SQL itself.  The Doctrine library provides all of the behind-the-scenes database interaction for you.</p>
<p>Let&#8217;s say I have a user is defined like so:</p>
<ul>
<li>First Name</li>
<li>Last Name</li>
<li>Email Address</li>
<li>Favorite Color</li>
</ul>
<p>In doctrine, I can simply define the User object</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_name'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fav_color'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unique'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>that&#8217;s it!  I don&#8217;t need to do anything else to peform all the CRUD operations on any users.  To create a user:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">first_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Jon'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Trelfa'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'user@example.com'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fav_color</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'blue'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
</p>
<p>I don&#8217;t think I need to repeat much of what Burak and the Doctrine project have already documented &#8211; so I will end this introduction for now.  Stay tuned as I document my discoveries <img src='http://jctweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/01/19/doctrine-codeigniter-intro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using jQuery&#8217;s .data() feature</title>
		<link>http://jctweb.net/2010/01/14/using-jquerys-data-feature/</link>
		<comments>http://jctweb.net/2010/01/14/using-jquerys-data-feature/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 15:33:54 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=102</guid>
		<description><![CDATA[jQuery has a feature that allows you to assign arbitrary data to DOM elements by way of the data storage methods.  I ran into a scenario today where this feature came in very handy.  Here is how the process works: &#8230; <a href="http://jctweb.net/2010/01/14/using-jquerys-data-feature/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="jQuery Home Page" href="http://www.jquery.com" target="_blank">jQuery</a> has a feature that allows you to assign arbitrary data to DOM elements by way of the <a title="jQuery API docs for Data Storage Methods" href="http://api.jquery.com/category/miscellaneous/data-storage/" target="_blank">data storage</a> methods.  I ran into a scenario today where this feature came in very handy.  Here is how the process works:</p>
<ol>
<li>The user clicks a checkbox in a list</li>
<li>The checkbox&#8217;s parent &lt;li&gt; element is hidden using the &#8220;highlight&#8221; effect</li>
<li>A new &lt;li&gt; element is created in a different list to show the user&#8217;s selection</li>
</ol>
<p>The problem is the use of the highlight effect.  It was possible that a user could click on the checkbox twice (quickly) &#8211; which would perform step #3 twice!  Thus I would end up with 2 identical elements in the &#8220;selected&#8221; list.</p>
<p>I&#8217;m certain there are probably a zillion different ways to handle this scenario &#8211; but this is the one I chose&#8230;</p>
<p>Using the .data() method on the elements, I ended up with this code:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#available_container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input:checkbox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'enableclick'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</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;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'enableclick'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; $<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;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'enableclick'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; $<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;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'highlight'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; add_item<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//adds the new item to the &quot;selected&quot; list</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">//here is the function when items in the &quot;selected&quot; list are clicked</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#available_container'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li:has(input:checkbox[value='</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'])'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'highlight'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input:checkbox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'enableclick'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>This seemed the simplest way to temporarily disable the &#8220;click&#8221; event while the &lt;li&gt; was hiding itself and it works pretty well.</p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/01/14/using-jquerys-data-feature/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Choosing WP Blog Theme</title>
		<link>http://jctweb.net/2010/01/06/choosing_atheme/</link>
		<comments>http://jctweb.net/2010/01/06/choosing_atheme/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 02:54:45 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jctweb.net/?p=81</guid>
		<description><![CDATA[I&#8217;m trying to find a better theme for my blog &#8211; I&#8217;m too lazy to design my own, I suppose. Update &#8211; I&#8217;ve *chosen* a theme. I like this one]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m trying to find a better theme for my blog &#8211; I&#8217;m too lazy to design my own, I suppose.</p>
<p>Update &#8211; I&#8217;ve *chosen* a theme.  I like this one</p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/01/06/choosing_atheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project 52</title>
		<link>http://jctweb.net/2010/01/05/project-52/</link>
		<comments>http://jctweb.net/2010/01/05/project-52/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 16:21:02 +0000</pubDate>
		<dc:creator>Jon Trelfa</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jctweb.net/2010/01/05/project-52/</guid>
		<description><![CDATA[For me, “deciding” to start/stop doing something as a resolution for the New Year is far different than actually following through.&#160; The good news is that I’ve found a way to better motivate myself.&#160; How do I do it? I &#8230; <a href="http://jctweb.net/2010/01/05/project-52/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For me, “deciding” to start/stop doing something as a resolution for the New Year is far different than actually following through.&#160; The good news is that I’ve found a way to better motivate myself.&#160; How do I do it?</p>
<p>I publish my commitment</p>
<p>For whatever reason, telling my Facebook friends and/or blog readers (I think there’s 2 if you include me and myself) what I’m actually committed to doing actually motivates me more than just deciding on my own.</p>
<p>So I’ve put my name on the <a href="http://project52.info/" target="_blank">Project52</a> website as my published commitment to write at least 1 new article per week for the whole year.</p>
<p>I’m not sure if this one counts but since I’m technically already behind (last week was the first week of 2010 after all), I may go ahead and put a tick mark for week 1 <img src='http://jctweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here’s to 2KX <img src='http://jctweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jctweb.net/2010/01/05/project-52/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

