<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.1" -->
<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/"
	>

<channel>
	<title>Spadgos</title>
	<link>http://spadgos.com</link>
	<description>It's "Spad-joss"</description>
	<pubDate>Fri, 25 Jun 2010 06:41:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.1</generator>
	<language>en</language>
			<item>
		<title>Image radio buttons</title>
		<link>http://spadgos.com/?p=66</link>
		<comments>http://spadgos.com/?p=66#comments</comments>
		<pubDate>Fri, 25 Jun 2010 06:41:13 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

		<guid isPermaLink="false">http://spadgos.com/?p=66</guid>
		<description><![CDATA[I came across this Stack Overflow question today about replacing radio buttons with images, however the answers there didn't sit quite right with me. They were completely reliant on javascript, which was fine according to the OP, but I feel that javascript enhancements like this, especially when they deal with things which require user input, [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this Stack Overflow question today about <a href="http://stackoverflow.com/questions/3114166/replacing-radio-buttons-with-different-images">replacing radio buttons with images</a>, however the answers there didn't sit quite right with me. They were completely reliant on javascript, which was fine according to the OP, but I feel that javascript enhancements like this, especially when they deal with things which require user input, should be just that: <strong>enhancements</strong> and not the entire solution itself.</p>
<p><a href="http://www.alistapart.com/articles/progressiveenhancementwithjavascript/">Progressive enhancement</a> is a fairly well known concept. Start with a valid, semantic and, most importantly, <em>usable</em> page and then add the niceties to it with javascript. If javascript isn't available or something breaks, then you don't have the niceties but you still have a usable page. Like I said, this is especially important for user input. Nothing is more frustrating than not being able to use a form because some half-wit developer thought they'd do something clever with javascript... or so my users tell me, anyway.</p>
<p>So, getting back to the radio buttons. We should set up some requirements.</p>
<ul>
<li>Instead of radio buttons, we'd like to see an icon which has two states: on and off.</li>
<li>The icon behaves exactly like a radio button:
<ol>
<li>Clicking on it or its label activates it.</li>
<li>Clicking on a different button in the group deactivates it.</li>
<li>Accessible via the keyboard or mouse</li>
</ol>
</li>
<li>With javascript turned off, it should still work</li>
<li>Minimal extra markup required.</li>
<li>Cross browser</li>
</ul>
<p>The styles, including the icon images will be handled via CSS, so each radio button will need a class to identify which icon to use. We'll also need a class to identify which radio buttons should be replaced with images. This leaves our HTML fairly standard:</p>
<pre>
&lt;input type="radio" name="sex" value="male"
    class="image_radio male_icon" id="male_radio" />
&lt;label for="male_radio">Male&lt;/label>
&lt;input type="radio" name="sex" value="female"
    class="image_radio female_icon" checked="checked" />
</pre>
<p>I've not given the second radio button an ID or label, just to demonstrate that both are optional. I'm not much of a fan of the overuse of ID attributes...</p>
<p>Almost all the styling is done via CSS, of course:</p>
<pre>
label.image_radio {
    width: 16px;    /* the same size as our icons */
    height: 16px;
    display: inline-block;
}
label.image_radio input.image_radio {
    margin-left: -9999px;
    /* this effectively hides the radio button
    without removing it from the document flow */
}

/* define the icons for each radio */
label.male {          background-image: url(male_off.png);   }
label.male.active {   background-image: url(male_on.png);    }
label.female {        background-image: url(female_off.png); }
label.female.active { background-image: url(female_on.png);  }
</pre>
<p>So, if you were to take a look at this in your browser, you'd see a completely unstyled page with standard radio buttons. Excellent. Without the javascript, we haven't broken anything. Now, <a href="http://www.youtube.com/watch?v=Vxq9yj2pVWk">let's enhance</a>.</p>
<p>Before I jump into the jQuery, I'll just get on my soapbox for a quick second to note that if it weren't for IE, the following code would be a single statement (kinda). If you click on a label associated with an input, IE doesn't pass the click event on to the input so we have to manually add those labels into our result set before applying the click event.</p>
<div class="syntax_hilite">
<div id="php-2">
<div class="php">jQuery<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// get all the image radio buttons</span><br />
&nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$radios</span> = $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'input.image_radio'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<a href="http://www.php.net/each"><span style="color:#000066;">each</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$t</span> = $<span style="color:#006600; font-weight:bold;">&#40;</span>this<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// wrap each in a label, copying over all the classes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$t</span>.wrap<span style="color:#006600; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"&lt;label&gt;&lt;/label&gt;"</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; className: <span style="color:#0000FF;">$t</span>.attr<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'className'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .toggleClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span>, <span style="color:#0000FF;">$t</span>.is<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">':checked'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// $clickTarget will be the elements to apply</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// the click event handler to</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color:#0000FF;">$clickTarget</span> = <span style="color:#0000FF;">$radios</span><br />
&nbsp; &nbsp; ;</p>
<p>&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>$.browser.msie<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// get the parent labels</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clickTarget</span> = <span style="color:#0000FF;">$radios</span>.parent<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// now find all the labels which are for this element</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$radios</span>.<a href="http://www.php.net/each"><span style="color:#000066;">each</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>this.id<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clickTarget</span> = <span style="color:#0000FF;">$clickTarget</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .add<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'label[for=&quot;'</span> + this.id + <span style="color:#FF0000;">'&quot;]'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color:#0000FF;">$clickTarget</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .click<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$t</span> = $<span style="color:#006600; font-weight:bold;">&#40;</span>this<span style="color:#006600; font-weight:bold;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$label</span> = <span style="color:#0000FF;">$t</span>.closest<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'label'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$label</span>.is<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">".active"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'label.active:has(:radio[name=&quot;'</span> + <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$t</span>.is<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">":radio"</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#0000FF;">$t</span> : <span style="color:#0000FF;">$t</span>.find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">":radio"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.attr<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'name'</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color:#FF0000;">'&quot;])'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .removeClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$label</span>.addClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; ;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>And that's all there is to it. There's probably still quite a bit more work you could put into it (for example, though it's still completely accessible via the keyboard, there's no visual indication that a particular button has focus), but it provides nice progressive enhancement for your radio buttons. With some very small tweaks, the same code could also apply to checkboxes too!</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=66</wfw:commentRss>
		</item>
		<item>
		<title>Javascript default values</title>
		<link>http://spadgos.com/?p=65</link>
		<comments>http://spadgos.com/?p=65#comments</comments>
		<pubDate>Wed, 05 May 2010 06:36:48 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

		<guid isPermaLink="false">http://spadgos.com/?p=65</guid>
		<description><![CDATA[Just a small post here to share a bit of benchmarking I just did. In Javascript, the boolean operators (&#124;&#124; and &#038;&#038;) behave a little differently to how many people expect. In PHP, the result of using &#124;&#124; or &#038;&#038; is always a boolean:


// PHP:
$x = "hello" &#124;&#124; false; // bool(true)
$x = false &#124;&#124; 0; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a small post here to share a bit of benchmarking I just did. In Javascript, the boolean operators (|| and &#038;&) behave a little differently to how many people expect. In PHP, the result of using || or &#038;& is always a boolean:</p>
<div class="syntax_hilite">
<div id="php-7">
<div class="php"><span style="color:#FF9933; font-style:italic;">// PHP:</span><br />
<span style="color:#0000FF;">$x</span> = <span style="color:#FF0000;">"hello"</span> || <span style="color:#000000; font-weight:bold;">false</span>; <span style="color:#FF9933; font-style:italic;">// bool(true)</span><br />
<span style="color:#0000FF;">$x</span> = <span style="color:#000000; font-weight:bold;">false</span> || <span style="color:#CC66CC;">0</span>; <span style="color:#FF9933; font-style:italic;">// bool(false) </span></div>
</div>
</div>
<p>
Javascript, on the other hand, returns the <strong>first determining value in the statement</strong>.</p>
<div class="syntax_hilite">
<div id="php-8">
<div class="php"><span style="color:#FF9933; font-style:italic;">// Javascript:</span><br />
<span style="color:#000000; font-weight:bold;">var</span> x = <span style="color:#FF0000;">"hello"</span> || <span style="color:#000000; font-weight:bold;">false</span>; <span style="color:#FF9933; font-style:italic;">// string(&quot;hello&quot;)</span><br />
<span style="color:#000000; font-weight:bold;">var</span> x = <span style="color:#000000; font-weight:bold;">false</span> || <span style="color:#CC66CC;">0</span>; <span style="color:#FF9933; font-style:italic;">// int(0)</span><br />
<span style="color:#000000; font-weight:bold;">var</span> x = <span style="color:#CC66CC;">0</span> || <span style="color:#FF0000;">"hello"</span>; <span style="color:#FF9933; font-style:italic;">// string(&quot;hello&quot;)</span><br />
<span style="color:#000000; font-weight:bold;">var</span> x = <span style="color:#CC66CC;">5</span> &amp;&amp; <span style="color:#CC66CC;">2</span>; <span style="color:#FF9933; font-style:italic;">// int(2)</span><br />
<span style="color:#000000; font-weight:bold;">var</span> x = <span style="color:#CC66CC;">5</span> &amp;&amp; <span style="color:#FF0000;">""</span>; <span style="color:#FF9933; font-style:italic;">// string(&quot;&quot;)</span><br />
<span style="color:#000000; font-weight:bold;">var</span> x = NaN &amp;&amp; <span style="color:#CC66CC;">6</span>; <span style="color:#FF9933; font-style:italic;">// NaN </span></div>
</div>
</div>
<p>
That is, when using ||, the result will be the first truthy value or the last value.</p>
<p>When using &#038;&, the result will be the first falsey value or the last value.</p>
<p>"Truthy" and "falsey" here obviously means a value which, when cast to a boolean, is true or false, respectively. Falsey values are 0, -0, false, null, undefined, and NaN. Truthy values are everything else (including "0", empty arrays and empty objects).</p>
<p>Knowing this gives us the opportunity to use a handy little shortcut for setting some default values for variables.</p>
<div class="syntax_hilite">
<div id="php-9">
<div class="php"><span style="color:#000000; font-weight:bold;">function</span> foo<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; a = a || <span style="color:#FF0000;">"default a"</span>;<br />
&nbsp; &nbsp; alert<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
foo<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; <span style="color:#FF9933; font-style:italic;">// &quot;default a&quot;</span><br />
foo<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// &quot;default a&quot;</span><br />
foo<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"my message"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// &quot;my message&quot; </span></div>
</div>
</div>
<p></p>
<p>The other important thing to know about the boolean operators is that they will <em>short-circuit</em> the processing once enough information is known to determine the output. That is, when using &#038;&, if the first parameter is falsey, then it doesn't matter at all what the second parameter is, since the output will always be false(y), so it skips evaluating that parameter. Similarly with ||, if the first parameter is truthy, then we can stop right there. This allows us to write a slightly more efficient default-value routine.</p>
<div class="syntax_hilite">
<div id="php-10">
<div class="php"><span style="color:#000000; font-weight:bold;">function</span> foo<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; a || <span style="color:#006600; font-weight:bold;">&#40;</span>a = <span style="color:#FF0000;">"default a"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; alert<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#FF9933; font-style:italic;">// this produces the same output as above </span></div>
</div>
</div>
<p>
If the first parameter is truthy, then it stops right there and never actually evaluates the second parameter which would assign a value to a. This is a bit more efficient than the first example, since there is only ever an assignment when it is required. How slight is this gain? Over 1,000,000 loops, running the first method took ~1640ms compared to ~1400ms for the second, so it's not going to make even a vaguely noticeable difference, but it doesn't hurt to do things the best way, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=65</wfw:commentRss>
		</item>
		<item>
		<title>Ubuntu, nooooo!</title>
		<link>http://spadgos.com/?p=64</link>
		<comments>http://spadgos.com/?p=64#comments</comments>
		<pubDate>Mon, 29 Mar 2010 00:06:04 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[ramblings]]></category>

		<guid isPermaLink="false">http://spadgos.com/?p=64</guid>
		<description><![CDATA[Starting with version 10.10, coming out in October this year, Ubuntu will be using base 10 units, taking its lead from Apple's move last year which I didn't much like. At least Ubuntu will give users an option to switch back, something Apple is yet to do. (Options? On a mac? ha!)
]]></description>
			<content:encoded><![CDATA[<p>Starting with version 10.10, coming out in October this year, <a href="http://www.neowin.net/news/ubuntu-implements-units-policy-will-switch-to-base-10-units-in-future-release">Ubuntu will be using base 10 units</a>, taking its lead from Apple's move last year which <a href="/?p=49">I didn't much like</a>. At least Ubuntu will give users an option to switch back, something Apple is yet to do. (Options? On a mac? ha!)</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=64</wfw:commentRss>
		</item>
		<item>
		<title>The great rep recalc of 2010</title>
		<link>http://spadgos.com/?p=63</link>
		<comments>http://spadgos.com/?p=63#comments</comments>
		<pubDate>Mon, 22 Mar 2010 06:44:01 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[ramblings]]></category>

		<guid isPermaLink="false">http://spadgos.com/?p=63</guid>
		<description><![CDATA[The Stack Overflow team recently announced that they were changing the question upvotes to only give 5 points instead of 10. 
Though I've got plenty more reputation than I could possibly need (that is, I have full user-moderator rights), this has affected my score. A lot. Like -4250. Bummer. I ask a lot of questions [...]]]></description>
			<content:encoded><![CDATA[<p>The Stack Overflow team recently announced that they were <a href="http://blog.stackoverflow.com/2010/03/important-reputation-rule-changes/">changing the question upvotes to only give 5 points instead of 10</a>. </p>
<p>Though I've got plenty more reputation than I could possibly need (that is, I have full user-moderator rights), this has affected my score. A lot. Like -4250. Bummer. <a href="http://spadgos.com/?p=58">I ask a lot of questions</a> and I think doing so is a really good thing, so I'm a little disappointed to see it go this way in discouraging new questions. Good questions already only attracted a fraction of the number of votes which good answers receive, so I guess I don't see it as fixing anything which was broken in the first place.</p>
<p>As you'd imagine, it stirred up a bit of malcontent in the comments thread (though, this happens with <em>any</em> change):</p>
<blockquote><p>This constant changing and making it all retroactive to all previous votes cast is crap. When people signed up you told them the rules and awarded points based on those rules.</p>
<p>I understand that things change and need to be changed in order to keep possible issues and problems in check. However rolling back people’s points is a jerk move and one you seem to have no issue doing.</p></blockquote>
<blockquote><p>I feel bad for the people [who have lost much rep], but we all get the added bonus of *having our questions answered* when we ask them. I think this change just shifts the focus of asking a question away from gaining reputation and towards getting an answer. Just as it should be.</p></blockquote>
<blockquote><p>I can understand the need of the changes *now*, but why punish those who helped bootstrap the system by providing lots of questions in the beginning?</p></blockquote>
<blockquote><p>Well, that’s demotivating. I’m pretty close to 10K, and this rule-change/recalc will drop me back to 8.7K.</p>
<p>Not much incentive to keep running on the rat machine, is it?</p></blockquote>
<p>I feel this guy's pain. Though it's obviously not the main reason I or anyone else would visit the site, trying to achieve a "high score" is one key feature, and knowing that it could be arbitrarily taken away from you just like that is quite demotivating. Though how can you argue when the site owner says this:</p>
<blockquote><p>I think it’s healthy for everyone to realize that rep is kind of an arbitrary concept, and think about what it means to them, to anyone else, and why.</p></blockquote>
<p>Overall, it seems as though not many are actually too concerned about the change in rep, but there's quite a lot of people who are <em>very</em> annoyed at the fact that it is being applied retroactively. There was a bit of a discussion/speculation about the notion that this was technically the only way to do it, which is rubbish. Yes, you don't want to have to keep a history of rules and the dates they changed, since that would grow unwieldy and awkward very quickly. Here's a smarter way to do it: get the Community User to double every single vote, then halve the score to +5. Done.</p>
<p>For a website built on community contribution, I'm just saddened to see how little they actually listened to their users. Perhaps only the voices of the top users were heard? The ones with <a href="http://spadgos.com/?p=58">nothing to lose anyway</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=63</wfw:commentRss>
		</item>
		<item>
		<title>A suggestion for Ford</title>
		<link>http://spadgos.com/?p=62</link>
		<comments>http://spadgos.com/?p=62#comments</comments>
		<pubDate>Sat, 16 Jan 2010 02:48:21 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[ramblings]]></category>

		<guid isPermaLink="false">http://spadgos.com/?p=62</guid>
		<description><![CDATA[Breaking with the theme of this blog, but this has been irritating me for some time now.
The "Voice Control" ad for the Ford Mondeo.





If you're going to make an ad touting a new feature such as voice control, it'd probably be a good idea to not highlight how buggy your software is.
]]></description>
			<content:encoded><![CDATA[<p>Breaking with the theme of this blog, but this has been irritating me for some time now.</p>
<p>The "Voice Control" ad for the Ford Mondeo.</p>
<object width="480" height="295">
<param name="movie" value="http://www.youtube.com/v/HgirOMNxlfM&#038;hl=en_GB&#038;fs=1&#038;"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<p><embed src="http://www.youtube.com/v/HgirOMNxlfM&#038;hl=en_GB&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object>
<p>If you're going to make an ad touting a new feature such as voice control, it'd probably be a good idea to not highlight how buggy your software is.</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=62</wfw:commentRss>
		</item>
		<item>
		<title>jQuery 1.4 released</title>
		<link>http://spadgos.com/?p=61</link>
		<comments>http://spadgos.com/?p=61#comments</comments>
		<pubDate>Thu, 14 Jan 2010 14:07:08 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://spadgos.com/?p=61</guid>
		<description><![CDATA[Despite the risk of joining in the echo chamber that I'm sure will start up very soon, I just wanted to write a little observation.
jQuery 1.4 has been released. Kinda.
It's a little baffling to me, considering the first release candidate was only announced one day ago, yet the dedicated jQuery 1.4 website proudly states "jQuery [...]]]></description>
			<content:encoded><![CDATA[<p>Despite the risk of joining in the <a href="http://chris.pirillo.com/10-ways-to-eliminate-the-echo-chamber/">echo chamber</a> that I'm sure will start up very soon, I just wanted to write a little observation.</p>
<p>jQuery 1.4 has been released. Kinda.</p>
<p>It's a little baffling to me, considering the first release candidate was only announced <a href="http://jquery14.com/pre-release-2/jquery-14rc1">one day ago</a>, yet the dedicated <a href="http://www.jquery14.com">jQuery 1.4 website</a> proudly states <em>"jQuery 1.4 has been released!"</em>, but alas, there is no link. The <a href="http://code.jquery.com/jquery-nightly.js">nightly build</a> still reads "1.4a2-pre", so I guess it's up to me.</p>
<p><a href="http://code.jquery.com/jquery-1.4.js">jQuery 1.4 is here.</a></p>
<p>It's a tad overdue. The roadmap slated it for a November 2009 release, and it's been promised for a while now, but it's here now anyway. I was looking at a <a href="http://futurecolors.ru/jquery/">jQuery cheat sheet</a> which contains the new functions introduced in 1.4, and two of them jumped out at me: <a href="http://api.jquery.com/nextUntil/">nextUntil()</a> and <a href="http://api.jquery.com/prevUntil/">prevUntil</a>. They seem to be very similar to <a href="http://fisher.spadgos.com/jqAdjacent.html">something I've seen before</a>. Kinda. Maybe I'm just seeing things.</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=61</wfw:commentRss>
		</item>
		<item>
		<title>Common Mistakes Part 1: SJAX</title>
		<link>http://spadgos.com/?p=60</link>
		<comments>http://spadgos.com/?p=60#comments</comments>
		<pubDate>Sun, 10 Jan 2010 14:11:40 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

		<guid isPermaLink="false">http://spadgos.com/?p=60</guid>
		<description><![CDATA[Here's another common mistake I see on Stack Overflow from time to time. The basic pattern goes like this:


// get the contents from some remote file
$&#40;'#myElement'&#41;.load&#40;'lipsum.html'&#41;;&#160; &#160;
alert&#40;$&#40;'#myElement'&#41;.html&#40;&#41;&#41;;&#160; &#160; 
// wtf, it's still empty?!? 



This is something that I struggled with when I started playing with AJAX techniques, too. It's quite understandable how so many people [...]]]></description>
			<content:encoded><![CDATA[<p>Here's another common mistake I see on Stack Overflow from time to time. The basic pattern goes like this:</p>
<div class="syntax_hilite">
<div id="php-13">
<div class="php"><span style="color:#FF9933; font-style:italic;">// get the contents from some remote file</span><br />
$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#myElement'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.load<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'lipsum.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp;<br />
alert<span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#myElement'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.html<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; &nbsp; <br />
<span style="color:#FF9933; font-style:italic;">// wtf, it's still empty?!? </span></div>
</div>
</div>
<p>
This is something that I struggled with when I started playing with AJAX techniques, too. It's quite understandable how so many people run into this issue. I mean, virtually other bit of code you write is executed in the order you write it. You'd expect that the alert() above would be run after load() function has run. Of course, you forget that A is for Asynchronous.</p>
<p><strong>Solving the problem the wrong way: SJAX</strong><br />
The first logical step that many people seem to move to is to avoid the situation altogether. If making an asynchronous call is causing this problem, we'll just switch to synchronous calls - problem solved! This is entirely the wrong way to do it. Synchronous <acronym title="XMLHttpRequest">XHR</acronym> calls will allow the the code sample above to run as the developer would hope, but it has the <em>very</em> nasty side effect of freezing the browser while it waits. No further code is executed until it get the response from the server. This is often overlooked due to poor testing. On a developer's local machine, the request completes in milliseconds and everyone's happy. In real life, a slow connection or an overworked server can render the user's browser useless for 30 seconds or a minute. Depending on the browser, you can't scroll the page, change tabs, open new links, etc. This is probably not the "improved user experience" you were hoping to deliver.</p>
<p><strong>Solving the problem the right way: callbacks</strong><br />
When setting up an XHR call, you are able to specify a function to be run when its status changes. Using <acronym title="javascript without 3rd party libraries like jQuery or Prototype">vanilla javascript</acronym>, this can be a pain, but libraries such as <a href="http://jquery.com">jQuery</a> make it much simpler.</p>
<div class="syntax_hilite">
<div id="php-14">
<div class="php">$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#myElement'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.load<span style="color:#006600; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">"lipsum.html"</span><br />
&nbsp; &nbsp; , <span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>responseText<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; alert<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Complete! The server said: "</span> + responseText<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p>
You do have to adjust how you think about your program flow, but once you starting thinking with <strike>portals</strike> AJAX, you'll never look back.</p>
<p><strong>Addendum</strong><br />
The basic message of this post has been <strong>synchronous XHR is evil</strong>, but I should mention the ONE place where its use is legitimate: inside onunload events. These events are called when the user leaves the page or closes the browser. If you want something to happen then, such as automatically saving a page, then asynchronous XHR will not help, since the browser closing or page changing will cancel the request immediately. In this scenario, locking up the browser while the request is being processed is somewhat acceptable. Just remember to test that it doesn't take too long!</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=60</wfw:commentRss>
		</item>
		<item>
		<title>Anyone have any questions?</title>
		<link>http://spadgos.com/?p=58</link>
		<comments>http://spadgos.com/?p=58#comments</comments>
		<pubDate>Sun, 13 Dec 2009 13:53:36 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[ramblings]]></category>

		<guid isPermaLink="false">http://spadgos.com/?p=58</guid>
		<description><![CDATA[So I'm a little addicted to Stack Overflow. I'll admit it. I browse it for fun, even during lunch-breaks and after work. As far as the reputation ranking goes, for the past 12 months or so, I've been sitting at around 30th to 40th place, first hitting the front page back in November 08, when [...]]]></description>
			<content:encoded><![CDATA[<p>So I'm a little addicted to Stack Overflow. I'll admit it. I browse it for <em>fun</em>, even during lunch-breaks and after work. As far as the reputation ranking goes, for the past 12 months or so, I've been sitting at around 30th to 40th place, first hitting the front page back in November 08, when 8000 rep was all you needed and even Jon Skeet was only third.</p>
<p>As you can see, I have been treating it as a bit of a game - trying to get a high score, trying to beat the other players. <em>Obviously that's not my only motivation, but you know what I mean: it's always nice to see rewards for your work, even if it's just a number.</em> As such, I've looked at the profiles of some of the people above and around my score and very quickly noticed a trend: <strong>the top users on Stack Overflow ask barely any questions</strong>. Below is a graph of the number of questions and answers from the top 36 users:</p>
<p><img src='http://spadgos.com/wp-content/uploads/2009/12/questions_to_answers_ratio_top_36_.png' alt='Questions-to-Answers ratio on Stack Overflow' /></p>
<p>Can you see me on there? Waaay over on the right, with 250 questions - sixteen times the median! My question-to-answer ratio is right on 4, whereas the median in this group is 139. There are two people there with reputations well in excess of 35,000 who have never asked a single question. Obviously, this baffles me.</p>
<p>It really makes me think about who these people are, and what they are doing in their daily jobs such that they have <em>no</em> questions? Some of the people we're talking about here literally wrote the book on their chosen field of programming, so they're probably excused, but still... no questions? It leads me to draw some conclusions:</p>
<ol>
<li>This person knows everything there is to know about C#, or Ruby, or PHP. They are never posed with any programming problems they can't solve without help.</li>
<li>This person considers asking the Internet for help to be unprofessional, or that the Stack Overflow community would be helpful in answering their questions.</li>
<li>This person works in an environment with a lot of other really-smart people, and help is attained offline.</li>
</ol>
<p>In response to these:</p>
<ol>
<li>Learn something new, man! Pick up some Javascript, or Go! or a new Framework in your current language, but choose <em>something</em>.</li>
<li>This doesn't seem too likely, and I hope it's not true. If someone who was already active in a Q&#038;A forum had a question but withheld it to save face, that would seem a bit vain to me. I personally have no problems asking questions which would seem simple to my peers.</li>
<li>Well... top effort! Lucky you.</li>
</ol>
<p>To me at least, asking questions is a sign that you're learning. I always have questions about the work I'm doing, whether it's how to actually get it right, or whether there's a better way than what I'm already doing.</p>
<p><em>What's your opinion on the matter? If you're a Stack Overflower, what's your question:answer ratio?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=58</wfw:commentRss>
		</item>
		<item>
		<title>Common Mistakes Part 0: 83.333% of jQuery</title>
		<link>http://spadgos.com/?p=57</link>
		<comments>http://spadgos.com/?p=57#comments</comments>
		<pubDate>Thu, 03 Dec 2009 12:50:02 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

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

		<guid isPermaLink="false">http://spadgos.com/?p=57</guid>
		<description><![CDATA[I've decided to start writing a short series of posts highlighting some common mistakes I see in questions and, more importantly, answers on Stack Overflow. I enter this knowing fully well that I am but an amateur who is also learning new things daily. Anyway, the series kicks off with Part Zero, titled 83.333% of [...]]]></description>
			<content:encoded><![CDATA[<p>I've decided to start writing a short series of posts highlighting some common mistakes I see in questions and, more importantly, answers on Stack Overflow. I enter this knowing fully well that I am but an amateur who is also learning new things daily. Anyway, the series kicks off with Part Zero, titled <strong>83.333% of jQuery</strong>.</p>
<p>This is actually one of my biggest pet peeves in reading jQuery related information, whether it's questions or answers on SO, or in numerous blogs or articles. It's such a common occurrence that I found myself shouting at the screen whenever I saw it:</p>
<blockquote style="font-size: 200%"><p>83.333% of jQuery is Query.</p></blockquote>
<p>The one thing you must always remember is that jQuery is a query tool. Sure it's not <em>just</em> that any more, but it was <a href="http://ejohn.org/blog/selectors-in-javascript/">born from inspiration</a> taken from my <a href="http://spadgos.com/?p=20">previous-favourite</a> javascript library, Behaviour <em>(now defunct, but written by <a href="http://bennolan.com/">Ben Nolan</a>)</em>.</p>
<p>It seems like a lot people get into jQuery by reading a "Top 20 Best Ever Amazing Useful jQuery Plugins Of All Time" list, where the only code they provide is this:</p>
<div class="syntax_hilite">
<div id="php-20">
<div class="php">$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#yourElement'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.doSomethingAwesome<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p>...and they really don't realise the massive power sitting right in front of them in the <a href="http://docs.jquery.com/Selectors">selectors</a> and <a href="http://docs.jquery.com/Traversing">traversal functions</a>. Here's an example of what I mean:</p>
<div class="syntax_hilite">
<div id="code-21">
<div class="code">&lt;ul class=<span style="color:#CC0000;">"nav"</span> id=<span style="color:#CC0000;">"nav"</span>&gt;<br />
&nbsp; &nbsp; &lt;li id=<span style="color:#CC0000;">"list1"</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=<span style="color:#CC0000;">"#"</span> id=<span style="color:#CC0000;">"link1"</span>&gt;Toggle&lt;/a&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=<span style="color:#CC0000;">"submenu"</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/li&gt;<br />
&nbsp; &nbsp; &lt;li id=<span style="color:#CC0000;">"list2"</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=<span style="color:#CC0000;">"#"</span> id=<span style="color:#CC0000;">"link2"</span>&gt;Toggle&lt;/a&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=<span style="color:#CC0000;">"submenu"</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/li&gt;<br />
&lt;/ul&gt;</div>
</div>
</div>
<p></p>
<p>This is naturally followed with inexplicable code like this:</p>
<div class="syntax_hilite">
<div id="php-22">
<div class="php">$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#link1'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.click<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#list1'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.addClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#list2'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.removeClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#link1'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<a href="http://www.php.net/next"><span style="color:#000066;">next</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'div.submenu'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.show<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#link2'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.click<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#008000;">/* etc... */</span> <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</div>
</div>
<p></p>
<p>Here's my rule of thumb: for each behaviour you're writing, <strong>if you use more than one id selector, you're doing it wrong</strong>. Ids should be used only as an entry, as a front door to the house which is your HTML. From there, you can use intelligent selections and traversals to get everything you want. Here's how I'd rewrite the HTML above, assuming there was only ever going to be one menu:</p>
<div class="syntax_hilite">
<div id="code-23">
<div class="code">&lt;ul id=<span style="color:#CC0000;">"nav"</span>&gt;<br />
&nbsp; &nbsp; &lt;li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=<span style="color:#CC0000;">"#"</span>&gt;Toggle&lt;/a&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt; ... &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/li&gt;<br />
&nbsp; &nbsp; &lt;li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=<span style="color:#CC0000;">"#"</span>&gt;Toggle&lt;/a&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt; ... &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/li&gt;<br />
&lt;/ul&gt;</div>
</div>
</div>
<p>
That's right: every single one of the ids and classes (except for the front door) were completely redundant and unneeded <small><em>(get it? ah, nevermind.)</em></small></p>
<p>Along with the much cleaner HTML comes much cleaner jQuery:</p>
<div class="syntax_hilite">
<div id="php-24">
<div class="php">$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'#nav a'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.click<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span>this<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<a href="http://www.php.net/next"><span style="color:#000066;">next</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .show<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .closest<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'li'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .addClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .siblings<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'.active'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .removeClass<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'active'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;<br />
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p>
This is just an example, and not actually tested and functioning code, but with a very few changes, this tiny snippet would provide all the behavioural code needed for nested menus to any depth, without a single class or id being added anywhere else.</p>
<p>If your HTML is littered with ids for the sake of javascript, please take another look at it. Is there any other way you could select or traverse your way to that element? If the only selectors you are writing start with a hash, then you're not using jQuery to it's potential. By my reckoning, you're only at about 16.667%.</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=57</wfw:commentRss>
		</item>
		<item>
		<title>Regex for PHP function declarations</title>
		<link>http://spadgos.com/?p=56</link>
		<comments>http://spadgos.com/?p=56#comments</comments>
		<pubDate>Thu, 03 Dec 2009 05:28:28 +0000</pubDate>
		<dc:creator>Fisher</dc:creator>
		
		<category><![CDATA[Code]]></category>

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

		<guid isPermaLink="false">http://spadgos.com/?p=56</guid>
		<description><![CDATA[Here's a little snippet of the day for you. A regex to grab the names of functions from a PHP file.


/^\s*&#40;?:&#40;?:public&#124;private&#124;protected&#124;static&#124;abstract&#124;final&#41;\s+&#41;*
function\s+&#38;?&#40;&#91;a-zA-Z_\x7f-\xff&#93;&#91;a-zA-Z0-9_\x7f-\xff&#93;*&#41;/



Linebreak added for legibility.
If you were wanting to know the functions which exist in a particular class or file for an application or similar, you'd be better off using the PHP Reflection functions which are [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a little snippet of the day for you. A regex to grab the names of functions from a PHP file.</p>
<div class="syntax_hilite">
<div id="code-26">
<div class="code">/^\s*<span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">&#40;</span>?:public|private|protected|static|abstract|final<span style="color:#006600; font-weight:bold;">&#41;</span>\s+<span style="color:#006600; font-weight:bold;">&#41;</span>*<br />
function\s+&amp;?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z_\x7f-\xff<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z0-<span style="color:#800000;">9</span>_\x7f-\xff<span style="color:#006600; font-weight:bold;">&#93;</span>*<span style="color:#006600; font-weight:bold;">&#41;</span>/</div>
</div>
</div>
<p></p>
<p><em>Linebreak added for legibility.</em></p>
<p>If you were wanting to know the functions which exist in a particular class or file for an application or similar, you'd be better off using the <a href="http://php.net/manual/en/book.reflection.php">PHP Reflection functions</a> which are very powerful and much more robust than any regex solution. I'm just using this regex for <a href="http://www.ultraedit.com">my text editor</a> so it will detect all the functions in the current file. The default regex didn't handle all the less-used styles such as "protected static final function".</p>
]]></content:encoded>
			<wfw:commentRss>http://spadgos.com/?feed=rss2&amp;p=56</wfw:commentRss>
		</item>
	</channel>
</rss>
