<?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>Mike Figueroa</title>
	<atom:link href="http://mikefigueroa.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikefigueroa.com/blog</link>
	<description>Figgalicous</description>
	<lastBuildDate>Tue, 16 Aug 2011 15:51:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Get First Google Image Search Result with PHP</title>
		<link>http://mikefigueroa.com/blog/2011/08/get-first-google-image-search-result-with-php/</link>
		<comments>http://mikefigueroa.com/blog/2011/08/get-first-google-image-search-result-with-php/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 04:33:45 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[computer tips]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[Google API]]></category>
		<category><![CDATA[image search]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=900</guid>
		<description><![CDATA[Here&#8217;s a quick  &#38; dirty way to get the thumbnail image for the first search result in Google Image Search: &#60;?phpif(isset($_GET['q'])){ $q = urlencode($_GET['q']); $jsonurl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&#38;q=".$q; $result = json_decode(file_get_contents($jsonurl), true); header("Content-Type: image/jpg"); $img = imagecreatefromjpeg($result['responseData']['results'][0]['tbUrl']); imagejpeg($img); imagedestroy($img);exit;}?&#62;&#60;html&#62;&#60;body&#62;&#60;form action='' method='post'&#62;&#60;fieldset&#62;&#60;input type='text' name='q' /&#62;&#60;input type='submit' name='submit' /&#62;&#60;/fieldset&#62;&#60;/form&#62;&#60;?phpif(isset($_POST['q'])){ $q = urlencode($_POST['q']); $jsonurl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&#38;q=".$q; $result = json_decode(file_get_contents($jsonurl), [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick  &amp; dirty way to get the thumbnail image for the first search result in Google Image Search:</p>
<p><code>&lt;?php<br />if(isset($_GET['q'])){<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>$q = urlencode($_GET['q']);<br /> </code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>$jsonurl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&amp;q=".$q;<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>$result = json_decode(file_get_contents($jsonurl), true);<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>header("Content-Type: image/jpg");<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>$img = imagecreatefromjpeg($result['responseData']['results'][0]['tbUrl']);<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>imagejpeg($img);<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>imagedestroy($img);<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>exit;<br /></code><code>}<br />?&gt;<br />&lt;html&gt;<br />&lt;body&gt;<br />&lt;form action='' method='post'&gt;<br />&lt;fieldset&gt;<br />&lt;input type='text' name='q' /&gt;&lt;input type='submit' name='submit' /&gt;<br />&lt;/fieldset&gt;<br />&lt;/form&gt;<br />&lt;?php<br />if(isset($_POST['q'])){<br /> </code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>$q = urlencode($_POST['q']);<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>$jsonurl = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&amp;q=".$q;<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>$result = json_decode(file_get_contents($jsonurl), true);<br /></code><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span></code><code>echo "&lt;img src='{$result['responseData']['results'][0]['tbUrl']}' /&gt;";<br />}<br />?&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</code></p>
<p><strong>A few notes:</strong></p>
<ul>
<li>Your PHP install must have <a href="http://www.php.net/manual/en/book.image.php" target="_blank">gd</a> which it probably will if you&#8217;re running 5+ which is required for <code>json_decode </code>(the function <code>file_get_contents</code> is 5.2+, but is just a shorthand function.)</li>
<li>For my purposes I only needed a thumbnail-sized image, but Google&#8217;s API provides piles of useful data. View the data directly <a href="https://ajax.googleapis.com/ajax/services/search/images?v=1.0&amp;q=figgalicous" target="_blank">[example]</a>, and copy+paste into a parser <a href="http://json.parser.online.fr/" target="_blank">[example]</a> if you need help navigating the data structure they provide. PHP&#8217;s <code>json_decode</code> will turn Google&#8217;s JSON data object into a deeply-nested array (and using &#8220;true&#8221; for the optional second parameter will make it an associative array which is helpful.</li>
<li>When you access the script by URL with the <code>'q'</code> variable set the image itself will be served, which I needed for my pipeline. This way I was able to call the script in the HTML itself via:
<ul>
<li><code>&lt;img src='firstgoogleimage.php?q=figgalicous' /&gt; </code>which as of this writing serves:<br /><img title="Mike Figueroa figgalicous" src="http://mikefigueroa.com/code/firstgoogleimage.php?q=figgalicous" alt="Mike Figueroa figgalicous" width="88" height="88" /></li>
</ul>
</li>
</ul>
<ul>
<li>You can try it yourself here: <a href="http://mikefigueroa.com/code/firstgoogleimage.php" target="_blank">http://mikefigueroa.com/code/firstgoogleimage.php</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2011/08/get-first-google-image-search-result-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress shortcode no-value attributes</title>
		<link>http://mikefigueroa.com/blog/2011/06/wordpress-shortcode-no-value-attributes/</link>
		<comments>http://mikefigueroa.com/blog/2011/06/wordpress-shortcode-no-value-attributes/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 20:26:34 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress shortcode plug-in development workaround]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=879</guid>
		<description><![CDATA[As a web developer, I often find that once clients get used to the idea that they can edit their own site many are likely to think about cool design &#38; interactive they have seen on other websites, and think to themselves &#8220;Can I do that in WordPress?&#8221; The answer, of course, is &#8220;Of course,&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>As a web developer, I often find that once clients get used to the idea that they can edit their own site many are likely to think about cool design &amp; interactive they have seen on other websites, and think to themselves <em>&#8220;Can I do that in WordPress?&#8221;</em></p>
<p>The answer, of course, is <em>&#8220;Of course,&#8221;</em> but depending on the feature being requested that can involve some work. Perhaps on the part of the web developer to enable a function or add a javascript library to their WordPress header; but most certainly on the part of the site owner to learn how to employ that new feature. This can mean acquainting oneself with additional code snippets, or memorizing Shortcodes.</p>
<p>For people who work in code everyday, that seems like meeting the client easily half-way. But even WordPress shortcodes can seem cryptic to average users. Especially where there are multiple optional/required attributes, and especially where the client is an organization and you have no idea who will be asssigned to use the tool you&#8217;ve developed. I was recently asked why one needed to write out entire attribute for an optional true/false attribute whose default was false. Example:<br /> <code>[myshortcode]</code> //foo = false<br /> <code>[myshortcode foo="true"] </code>//foo =true</p>
<p>Obviously, part of me was thinking <em>&#8220;Come on, it&#8217;s not that hard is it?&#8221;</em> but I thought I would have a go at finding a workaround so they could merely write:<br /> <code>[myshortcode]</code>// foo = false<br /> <code><strong>[myshortcode foo]</strong> </code>//foo =true</p>
<p>So let&#8217;s go through a practical example. (If you&#8217;ve never worked with shortcodes before,  I recommend you check out the <a href="http://codex.wordpress.org/Shortcode_API">docs</a> on this feature, however you can begin by pasting a given code example in your theme&#8217;s function.php file.)</p>
<p><code>function myShortCodeFunction( $atts ){<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>extract( shortcode_atts( array( <br /> <span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>'text' =&gt; 'Important Notice!', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'width' =&gt; '500', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'height' =&gt; '250', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>), $atts ) );<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>return "&lt;div style='width:{$width}px; height:</code><code>{$height}px;  background-color:aliceblue; border:3px solid SkyBlue;'&gt;{$text}&lt;/div&gt;";<br />}<br />add_shortcode('noticebox', 'myShortCodeFunction');</code></p>
<p>The code above will allow you to create a styled div element containing the text of your choice, and you may optionally set a width &amp; height (default 500px × 250px), merely by typing <code>[noticebox text="10 points from Gryffindor!"]</code></p>
<p>This looks pretty good, but what if on certain pages or in certain contexts the border didn&#8217;t look good? Well we can obviously adapt the myShortCodeFunction to accept:</p>
<p><code>[noticebox text="Some text." border="false"]</code></p>
<p>Which would look something like:</p>
<p><code>function myShortCodeFunction( $atts ){<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>extract( shortcode_atts( array( <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'text' =&gt; 'Important Notice!', <br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>'border' =&gt; 'true',<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'width' =&gt; '500', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'height' =&gt; '250', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>), $atts ) );<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>if($border == 'true'){<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>$borderstyle = '</code><code>border:3px solid  SkyBlue;'</code><code>;<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>} else {<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>$borderstyle = '';<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>}<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>return "&lt;div style='width:{$width}px; height:{$height}px;   background-color:aliceblue; {$borderstyle}'&gt;{$text}&lt;/div&gt;";<br />}<br />add_shortcode('noticebox', 'myShortCodeFunction');</code></p>
<p>In the version above, if the attribute <code>border="false"</code> is NOT detected  then the variable <code>$borderstyle</code> is assigned some inline CSS; otherwise it becomes an empty string, which when included in the returned string does nothing.</p>
<p>However if we wanted to simplify the shortcode from:<br /><code>[noticebox text="Some text." border="false"] </code>// no border<br /><code>[noticebox text="Some text." noborder]</code> // no border</p>
<p>We could modify the code in this way:</p>
<p><code>function myShortCodeFunction( $atts ){<br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>extract( shortcode_atts( array( <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'text' =&gt; 'Important Notice!', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'width' =&gt; '500', <br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>'height' =&gt; '250', <br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>'noborder' =&gt; <strong>isset($atts['noborder']),</strong><br /> <span style='padding:0 12px 0 12px;'>&nbsp;</span>), $atts ) );<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>if($noborder){<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>$borderstyle = '';<br /></code><code><span style='padding:0 12px 0 12px;'>&nbsp;</span>} else {<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>$borderstyle = 'border:3px solid  SkyBlue';<br /><span style='padding:0 12px 0 12px;'>&nbsp;</span>}</code><br /><code> <span style='padding:0 12px 0 12px;'>&nbsp;</span>return "&lt;div style='width:{$width}px; height:{$height}px;   background-color:aliceblue; {$borderstyle}'&gt;{$text}&lt;/div&gt;";<br /> }<br /> add_shortcode('noticebox', 'myShortCodeFunction');</code></p>
<p>In this final version we assign the result of PHP&#8217;s <code>isset()</code> function (which returns <code>true/false</code> ) to the default value for <code>$noborder</code>, then reverse the logic used to assign the <code>$borderstyle</code> variable.</p>
<p>Neat, huh?</p>
<div id="_mcePaste" class="mcePaste" style="position: absolute; left: -10000px; top: 784px; width: 1px; height: 1px; overflow: hidden;"><code>border="false"</code></div>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2011/06/wordpress-shortcode-no-value-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clearing Windows 7 Print Spool</title>
		<link>http://mikefigueroa.com/blog/2011/06/clearing-windows-7-print-spool/</link>
		<comments>http://mikefigueroa.com/blog/2011/06/clearing-windows-7-print-spool/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 21:37:18 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[computer tips]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[printer]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[spool]]></category>
		<category><![CDATA[spooler]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=870</guid>
		<description><![CDATA[Windows 7 and my inkjet printer don&#8217;t always get along. When they start giving each other the silent &#8220;treatment&#8221;, I&#8217;m occasionally forced to restart my computer so I can print documents. I cobbled this batch file together from various sources online. It works about half the time. @echo off echo Stopping print spooler. echo. net [...]]]></description>
			<content:encoded><![CDATA[<p>Windows 7 and my inkjet printer don&#8217;t always get along. When they start giving each other the silent &#8220;treatment&#8221;, I&#8217;m occasionally forced to restart my computer so I can print documents.</p>
<p>I cobbled this <a href="http://en.wikipedia.org/wiki/Batch_file" target="_blank">batch file</a> together from various sources online. It works about half the time.</p>
<p><code>@echo off<br />
echo Stopping print spooler.<br />
echo.<br />
net stop spooler<br />
echo Erasing Temporary Junk Printer Documents<br />
echo.<br />
del /Q /F /S %systemroot%\System32\Spool\Printers\*.*<br />
echo Starting print spooler.<br />
echo.<br />
net start spooler</code></p>
<p>If you&#8217;ve never made a batch file, copy the code above into a <a href="http://en.wikipedia.org/wiki/Plain_text" target="_blank">plain text editor</a> and save the file to your Windows folder with the extension <strong>.bat</strong></p>
<p>To use, call the file from the <strong>Run&#8230;</strong> command in the Windows menu.</p>
<p><img class="alignnone size-full wp-image-872" title="run-fixprintq-bat" src="http://mikefigueroa.com/blog/wp-content/uploads/2011/06/run-fixprintq-bat.jpg" alt="" width="427" height="235" /></p>
<p><a href="http://mikefigueroa.com/blog/wp-content/uploads/2011/06/fixprintq-bat.jpg"><img class="alignnone size-full wp-image-873" src="http://mikefigueroa.com/blog/wp-content/uploads/2011/06/fixprintq-bat.jpg" alt="" width="448" height="226" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2011/06/clearing-windows-7-print-spool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Server-logging client-side javascript errors</title>
		<link>http://mikefigueroa.com/blog/2011/05/server-logging-client-side-javascript-errors/</link>
		<comments>http://mikefigueroa.com/blog/2011/05/server-logging-client-side-javascript-errors/#comments</comments>
		<pubDate>Wed, 25 May 2011 21:08:21 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[log]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=859</guid>
		<description><![CDATA[There are several examples of this already on the net, but this technique came in handy on a recent site I programmed. The concept is that you overwrite any existing browser reaction to the window.onerror event with your own function that sends an XMLHttpRequest containing gathered error information to a server-side script which logs that [...]]]></description>
			<content:encoded><![CDATA[<p>There are several examples of this already on the net, but this technique came in handy on a recent site I programmed. The concept is that you overwrite any existing browser reaction to the <code>window.onerror</code> event with your own function that sends an XMLHttpRequest containing gathered error information to a server-side script which logs that information to a file or database.</p>
<p>The user-experience as defined by the designer &#038; client called for virtually every page to have a &#8220;dashboard&#8221; feel, whereby a site visitor could click buttons &#038; links and the main content area of the page would be replaced (typically via <code>innerHTML</code>.)</p>
<p>Cross-browser debugging nearly became a serious issue; it was like a wild shoot-out in a digital saloon, with AJAX bullets flying through HTML-tag-cowboy hats and ricocheting off the piano player&#8217;s include files.</p>
<p>I got pretty much everything straightened out, but we still had the rare non-responsive button or empty content screen. So as we opened the site to a private beta, the following bit of PHP helped the browsers with issues call attention to themselves.</p>
<p><code>echo "&lt;script&gt;<br />
window.onerror = function(msg, err_url, line){<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>var params = 'jserror=1&#038;msg=' +msg+ '&#038;url=' +err_url+ '&#038;line=' +line+ '&#038;ua={$_SERVER['HTTP_USER_AGENT']}';<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>whateverAjaxCallYouUse('action.php?'+params);<br />
&lt;/script&gt;";</code></p>
<p>With the increasing reliability of <code>document.activeElement</code> you could conceivably get more detailed information about the page element which caused the problem, however in my case I was only interested in the error messages themselves. In the untested example below, I create a string of JSON text from the <code>activeElement</code>&#8216;s attributes.</p>
<p><code>var curr = (document.activeElement) ? document.activeElement : false;<br />
if(curr){<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>var json_string = '{' +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' "element" : "' + curr +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","tagname" : "' + curr.tagName +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","name" : "' + curr.name +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","id" : "' + curr.id +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","parent" : "' + curr.parentNode +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","href" : "' + curr.href +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","src" : "' + curr.src +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","onclick" : "' + curr.onclick +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","onfocus" : "' + curr.onfocus +<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>' ","onblur" : "' + curr.onblur + '"}';<br />
}</code></p>
<p>Or something to that effect, there&#8217;s probably a smarter way to do it.</p>
<p>Obviously, this suppresses any normal error reporting in the browser so you&#8217;ll want a way to deactivate this behavior for when you&#8217;re debugging as you won&#8217;t see any errors yourself. In my case, since the site was decently MVC&#8217;d it was easy to not echo this function based on whether the appropriate administrator variables were set in the $_SESSION array.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2011/05/server-logging-client-side-javascript-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript: Abbreviated DOM methods</title>
		<link>http://mikefigueroa.com/blog/2011/05/javascript-abbreviated-dom-methods/</link>
		<comments>http://mikefigueroa.com/blog/2011/05/javascript-abbreviated-dom-methods/#comments</comments>
		<pubDate>Thu, 19 May 2011 06:03:57 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[Web design]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=845</guid>
		<description><![CDATA[&#60;rant&#62;As a foolishly ardent DIY-er AND a programmer I often try to avoid using third-party libraries, as if my &#8220;real programmer&#8221; credibility depended on complete self-reliance. This is especially a nuisance when crafting modern interactive websites, as it&#8217;s becoming increasingly difficult to avoid libraries such as jQuery. For me, though, it&#8217;s not about some idealist [...]]]></description>
			<content:encoded><![CDATA[<p>&lt;rant&gt;As a foolishly ardent DIY-er <em>AND</em> a programmer I often try to avoid using third-party libraries, as if my &#8220;real programmer&#8221; credibility depended on complete self-reliance.</p>
<p>This is especially a nuisance when crafting modern interactive websites, as it&#8217;s becoming increasingly difficult to avoid libraries such as jQuery.</p>
<p>For me, though, it&#8217;s not about some idealist notion of authorship but rather it boils down to my need to understand the code I&#8217;m deploying. If I am not getting an expected result, and am including some third-party library, it can be hard to tell where the train went off the rails (sorry, sometimes I don&#8217;t have time for breakpoints &amp; stack traces when I&#8217;m trying to push attractive &amp; valid code to the browser from what is often the meat &amp; potatoes of a site project: the back-end code in a template system or CMS.</p>
<p>Well this year I <a href="http://twitter.com/#!/figgalicous/status/34464063383670786">finally</a> got around to <a href="http://jsbeautifier.org/">de-obfuscating</a> the jQuery library and began picking apart how it works.<br />
This is a really important step in deciding to seriously use a tool that I recommend to every practitioner of every craft. Don&#8217;t get me wrong, jQuery has some fabulous docs, but mentally understanding the &#8220;Why&#8221; behind the way things is just as liberating as a complete list of functions &amp; methods.</p>
<p>One way to look at a powerful Javascript library such as jQuery is to canonize it mentally into js, and erase the difference in your mind. That probably works for some people; I don&#8217;t think I can do that. There are times where I can imagine not needing the extra baggage of the whole of it for one or two functions.&lt;/rant&gt;</p>
<h3>Point in case:</h3>
<p>On a site which wasn&#8217;t already using jQuery, I had need of some considerable DOM manipulations; creating &amp; removing elements, applying additional style, and modifying hrefs. All of which are provided simply by javascript, except that the <strong>names of the methods are so freaking long!</strong> Come on, you know what I mean. Even IF you&#8217;re development environment has an auto-completion feature (I use Notepad++, and the shortcut is CTRL+ENTER, but it&#8217;s slower to look through the list and down-arrow to the desired item than it is to just keep typing) document.getElementById(&#8216;&#8230;&#8217;) is just too damn long.</p>
<p>You gotta admit, there&#8217;s something sexy about $(&#8216;#&#8230;&#8217;). C`est la vie, right?</p>
<p>So here&#8217;s what I did, it worked for me, your mileage may vary. Essentially, as a preamble to all the rest of the code, we abbreviate those long names by assigning an anonymous function to a given variable name, like so:</p>
<p><code>$ID = function(f){return document.getElementById(f);};<br />
$NAME = function(f){return document.getElementsByTagName(f);};</code></p>
<p>Then, merely use them like this:<br />
<code>var e = $ID('some-element');<br />
alert(e.innerHTML);</code></p>
<p>Of course, when you really need to boogie, you&#8217;ll need access to elements&#8217; class attributes, so:</p>
<p><code>$CLASS = function(clsName){<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>var classy = new Array();<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>var pool = document.getElementsByTagName("*");<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>for(var i = 0;i &lt; pool.length;i++){<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>if(pool[i].className.indexOf(" ") &gt;= 0){<br />
<span style='padding:0 36px 0 36px;'>&nbsp;&nbsp;&nbsp;</span>var classes = pool[i].className.split(" ");<br />
<span style='padding:0 48px 0 48px;'>&nbsp;&nbsp;&nbsp;&nbsp;</span>for(var j = 0;j &lt; classes.length;j++){<br />
<span style='padding:0 48px 0 48px;'>&nbsp;&nbsp;&nbsp;&nbsp;</span>if(classes[j] == clsName){<br />
<span style='padding:0 60px 0 60px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>classy.push(pool[i]);<br />
<span style='padding:0 48px 0 48px;'>&nbsp;&nbsp;&nbsp;&nbsp;</span>}<br />
<span style='padding:0 36px 0 36px;'>&nbsp;&nbsp;&nbsp;</span>}<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>} else if(pool[i].className == clsName){<br />
<span style='padding:0 36px 0 36px;'>&nbsp;&nbsp;&nbsp;</span>classy.push(pool[i]);<br />
<span style='padding:0 24px 0 24px;'>&nbsp;&nbsp;</span>}<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>}<br />
<span style='padding:0 12px 0 12px;'>&nbsp;</span>return classy;<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2011/05/javascript-abbreviated-dom-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Northwest Horizon</title>
		<link>http://mikefigueroa.com/blog/2011/01/a-northwest-horizon/</link>
		<comments>http://mikefigueroa.com/blog/2011/01/a-northwest-horizon/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 19:36:55 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Show & Tell]]></category>
		<category><![CDATA[landscape]]></category>
		<category><![CDATA[Northwest]]></category>
		<category><![CDATA[panorama]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[trees]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=827</guid>
		<description><![CDATA[Cameraphone picture, cropped.]]></description>
			<content:encoded><![CDATA[<p>Cameraphone picture, cropped.</p>
<div style="overflow: scroll; text-align: center; width: 440px; height: 360px; overflow-y: hidden;"><img class="aligncenter size-full wp-image-786" title="A Northwest Horizon" src="http://mikefigueroa.com/blog/wp-content/uploads/2011/01/2010-12-29.png" alt="" width="1748" height="343" /></div>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2011/01/a-northwest-horizon/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>That&#8217;s how he rolls</title>
		<link>http://mikefigueroa.com/blog/2010/12/thats-how-he-rolls/</link>
		<comments>http://mikefigueroa.com/blog/2010/12/thats-how-he-rolls/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 19:09:51 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Show & Tell]]></category>
		<category><![CDATA[character]]></category>
		<category><![CDATA[computer art]]></category>
		<category><![CDATA[illustration]]></category>
		<category><![CDATA[sad]]></category>
		<category><![CDATA[toilet paper]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=823</guid>
		<description><![CDATA[I have no idea why a roll of toilet paper would be so sad, but it&#8217;s still cute.]]></description>
			<content:encoded><![CDATA[<p>I have no idea why a roll of toilet paper would be so sad, but it&#8217;s still cute.</p>
<p><img class="aligncenter size-full wp-image-824" title="sad toilet paper" src="http://mikefigueroa.com/blog/wp-content/uploads/2010/12/sad-toilet-paper.jpg" alt="" width="366" height="430" /></p>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2010/12/thats-how-he-rolls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Miniature Japanese Lantern</title>
		<link>http://mikefigueroa.com/blog/2010/10/miniature-japanese-lantern/</link>
		<comments>http://mikefigueroa.com/blog/2010/10/miniature-japanese-lantern/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 03:05:54 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[craft]]></category>
		<category><![CDATA[japanese]]></category>
		<category><![CDATA[lantern]]></category>
		<category><![CDATA[miniature]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[paper]]></category>
		<category><![CDATA[wood]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=816</guid>
		<description><![CDATA[A few years ago I purchased a roll of authentic Japanese rice paper from Uwajimaya market in Seattle intending to use it on a number of projects but I only recently started using it. A combination of balsa &#38; basswood is used in the model. I designed it to stand off the floor the same [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">A few years ago I purchased a roll of authentic Japanese rice paper from <a href="http://www.uwajimaya.com/" target="_blank">Uwajimaya</a> market in Seattle intending to use it on a number of projects but I only recently started using it.</p>
<p style="text-align: center;"><a href="http://mikefigueroa.com/blog/wp-content/uploads/2010/10/100_4328_small.jpg"><img class="aligncenter size-full wp-image-817" title="100_4328_small" src="http://mikefigueroa.com/blog/wp-content/uploads/2010/10/100_4328_small.jpg" alt="" width="445" height="593" /></a></p>
<p style="text-align: center;"><a href="http://mikefigueroa.com/blog/wp-content/uploads/2010/10/100_4323_small.jpg"><img class="aligncenter size-full wp-image-818" title="100_4323_small" src="http://mikefigueroa.com/blog/wp-content/uploads/2010/10/100_4323_small.jpg" alt="" width="445" height="507" /></a></p>
<p style="text-align: left;">A combination of balsa &amp; basswood is used in the model. I designed it to stand off the floor the same height as a typical electronic flickering tea light. This is a floor lantern in the Japanese style that is 40 scale inches tall at 1½&#8221; scale. I used a variety of images on the internet as inspiration/reference material. While I was researching designs I realized how similar the visual styles of <a href="http://www.google.com/images?q=japanese+carpentry" target="_blank">Japanese Carpentry</a> are to that of the <a href="http://en.wikipedia.org/wiki/Arts_and_Crafts_Movement" target="_blank">Arts &amp; Crafts Movement</a>.</p>
<p style="text-align: left;">Hmm..</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="445" height="356" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/yGFFRLWcbno?fs=1&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="445" height="356" src="http://www.youtube.com/v/yGFFRLWcbno?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2010/10/miniature-japanese-lantern/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Roof-top Garden Grove</title>
		<link>http://mikefigueroa.com/blog/2010/10/roof-top-garden-grove/</link>
		<comments>http://mikefigueroa.com/blog/2010/10/roof-top-garden-grove/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 03:32:48 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[arches]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[concept]]></category>
		<category><![CDATA[garden]]></category>
		<category><![CDATA[green roof]]></category>
		<category><![CDATA[illustration]]></category>
		<category><![CDATA[ink]]></category>
		<category><![CDATA[living roof]]></category>
		<category><![CDATA[marker]]></category>
		<category><![CDATA[reading]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=810</guid>
		<description><![CDATA[Here&#8217;s an old architectural concept illustration from sometime in 2008. A sort of portico of brick archways suspends a living roof accessible from the second story of the main building to which both are attached. Small fruit-bearing trees could be made to take root making a pleasant garden roof-top. I hope you like it. Marker [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_811" class="wp-caption aligncenter" style="width: 457px"><a href="http://mikefigueroa.com/blog/wp-content/uploads/2010/10/10-08-2010-074744PM-1024x526.jpg"><img class="size-large wp-image-811" title="10-08-2010 07;47;44PM" src="http://mikefigueroa.com/blog/wp-content/uploads/2010/10/10-08-2010-074744PM-1024x526.jpg" alt="" width="447" height="230" /></a><p class="wp-caption-text">Click for full-size.</p></div>
<p style="text-align: left;">Here&#8217;s an old architectural concept illustration from sometime in 2008. A sort of portico of brick archways suspends a living roof accessible from the second story of the main building to which both are attached. Small fruit-bearing trees could be made to take root making a pleasant garden roof-top.</p>
<p style="text-align: left;">I hope you like it. Marker &amp; ink.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2010/10/roof-top-garden-grove/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tree in Wright Park</title>
		<link>http://mikefigueroa.com/blog/2010/09/tree-in-wright-park/</link>
		<comments>http://mikefigueroa.com/blog/2010/09/tree-in-wright-park/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 02:03:20 +0000</pubDate>
		<dc:creator>MikeFig</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[nature]]></category>
		<category><![CDATA[park]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[Tacoma]]></category>
		<category><![CDATA[tree]]></category>
		<category><![CDATA[trees]]></category>

		<guid isPermaLink="false">http://mikefigueroa.com/blog/?p=799</guid>
		<description><![CDATA[It&#8217;s a real treat living close to a real park and arboretum: View Wright Park in a larger map Here&#8217;s an (unedited) picture I took today, which I find makes a great computer desktop image &#8211; have at it.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a real treat living close to a <a href="http://en.wikipedia.org/wiki/Wright_Park_Arboretum" target="_blank">real park and arboretum</a>:</p>
<div id="attachment_800" class="wp-caption aligncenter" style="width: 455px"><a href="http://mikefigueroa.com/blog/wp-content/uploads/2010/09/vintage-photo-tree.jpg"><img class="size-large wp-image-800" title="vintage-photo-tree" src="http://mikefigueroa.com/blog/wp-content/uploads/2010/09/vintage-photo-tree-768x1024.jpg" alt="" width="445" height="595" /></a><p class="wp-caption-text">Click for larger size.</p></div>
<p style="text-align: center;">
<p><iframe width="445" height="550" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?cd=1&amp;ei=cjKMTKLlD6TstAP-_tVR&amp;ie=UTF8&amp;hl=en&amp;view=map&amp;ved=0CIUBEKUG&amp;t=h&amp;source=embed&amp;msa=0&amp;msid=105755546842305803928.0004900642f24a80434f9&amp;ll=47.260316,-122.449096&amp;spn=0.002002,0.002382&amp;z=18&amp;output=embed"></iframe><br /><small>View <a href="http://maps.google.com/maps/ms?cd=1&amp;ei=cjKMTKLlD6TstAP-_tVR&amp;ie=UTF8&amp;hl=en&amp;view=map&amp;ved=0CIUBEKUG&amp;t=h&amp;source=embed&amp;msa=0&amp;msid=105755546842305803928.0004900642f24a80434f9&amp;ll=47.260316,-122.449096&amp;spn=0.002002,0.002382&amp;z=18" style="color:#0000FF;text-align:left">Wright Park</a> in a larger map</small></p>
<p>Here&#8217;s an (unedited) picture I took today, which I find makes a great computer desktop image &#8211; have at it.</p>
<div id="attachment_802" class="wp-caption aligncenter" style="width: 310px"><a href="http://mikefigueroa.com/blog/wp-content/uploads/2010/09/100_3955.jpg"><img class="size-medium wp-image-802" title="100_3955" src="http://mikefigueroa.com/blog/wp-content/uploads/2010/09/100_3955-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">Click for full-size. </p></div>
]]></content:encoded>
			<wfw:commentRss>http://mikefigueroa.com/blog/2010/09/tree-in-wright-park/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  mikefigueroa.com/blog/feed/ ) in 1.13433 seconds, on Feb 5th, 2012 at 11:24 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 6th, 2012 at 12:24 am UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  mikefigueroa.com/blog/feed/ ) in 0.00185 seconds, on Feb 5th, 2012 at 11:39 pm UTC. -->
