<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.5" -->
<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>Incoherent Babble</title>
	<link>http://blog.stchur.com</link>
	<description>usually about Javascript, but I don't discriminate</description>
	<pubDate>Fri, 15 Aug 2008 04:54:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Screw you, financially responsible Americans</title>
		<link>http://blog.stchur.com/2008/07/26/screw-you-financially-responsible-americans/</link>
		<comments>http://blog.stchur.com/2008/07/26/screw-you-financially-responsible-americans/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 22:49:44 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[MiniPosts]]></category>

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

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

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

		<category><![CDATA[real estate]]></category>

		<guid isPermaLink="false">http://blog.stchur.com/2008/07/26/screw-you-financially-responsible-americans/</guid>
		<description><![CDATA[Be irresponsible, spend money you don't have, buy things you can't afford, fail to make the payments.  Not to worry -- just cry foul when it is threatened that it will be taken away from you and big government will come in and rescue you, sending the clear message that being financially responsible is, [...]]]></description>
			<content:encoded><![CDATA[<p>Be irresponsible, spend money you don't have, buy things you can't afford, fail to make the payments.  Not to worry -- just cry foul when it is threatened that it will be taken away from you and big government will come in and rescue you, sending the <a href = "http://seattlebubble.com/blog/2008/07/26/us-government-to-responsible-americans-screw-you/" title = "US Government to Responsible Americans: Screw You">clear message</a> that being financially responsible is, not only unnecessary, but actually stupid, since the tax dollars of those who <em>are</em> financially responsible are the dollars that are going to go towards this crappy legislature.</p>

<p>I've never been so irritated!</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/07/26/screw-you-financially-responsible-americans/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wither IE6?</title>
		<link>http://blog.stchur.com/2008/07/22/wither-ie6/</link>
		<comments>http://blog.stchur.com/2008/07/22/wither-ie6/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 13:00:07 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Beating IE into submission]]></category>

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

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

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

		<category><![CDATA[Web-related]]></category>

		<guid isPermaLink="false">http://blog.stchur.com/2008/07/22/wither-ie6/</guid>
		<description><![CDATA[Welcome aboard guys.  Glad you finally decided to start thinking about what I discussed long ago.]]></description>
			<content:encoded><![CDATA[<p>Welcome aboard <a href = "http://ajaxian.com/archives/pondering-support-of-ie6" title = "Pondering Support for IE6">guys</a>.  Glad you <em>finally</em> decided to start thinking about what <a href = "http://blog.stchur.com/2008/01/15/ie5-is-dead-and-ie6-is-on-death-row/" title = "IE5 is dead (and IE6 is on death row)">I discussed</a> long ago.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/07/22/wither-ie6/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Firefox 3 .pageX / .pageY bug</title>
		<link>http://blog.stchur.com/2008/07/03/firefox-3-pagex-pagey-bug/</link>
		<comments>http://blog.stchur.com/2008/07/03/firefox-3-pagex-pagey-bug/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 17:40:49 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Advanced Javascript]]></category>

		<category><![CDATA[Firefox Related]]></category>

		<category><![CDATA[Mozilla-specific]]></category>

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

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

		<category><![CDATA[Firefox 3]]></category>

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

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

		<guid isPermaLink="false">http://blog.stchur.com/2008/07/03/firefox-3-pagex-pagey-bug/</guid>
		<description><![CDATA[	Firefox 3 has a bug.  It's somewhat obscure, and it probably doesn't affect you, but it did affect me.
	It also affected the Microsoft Virtual Earth MapControl, so if you use the VE MapControl for a mashup, your Firefox 3 users are going to be affected by this issue.
	The issue?  It has to do [...]]]></description>
			<content:encoded><![CDATA[	<p>Firefox 3 has a bug.  It's somewhat obscure, and it probably doesn't affect you, but it did affect me.</p>
	<p>It also affected the Microsoft <a href = "http://msdn.microsoft.com/en-us/virtualearth/default.aspx" title = "Microsoft Virtual Earth">Virtual Earth MapControl</a>, so if you use the VE MapControl for a mashup, your Firefox 3 users are going to be affected by this issue.</p>
	<p>The issue?  It has to do with a mouse event's <code>.pageX</code> and <code>.pageY</code> properties.  The values of those properties are supposed to report the "page" position of the mouse cursor, relative to the upper-left corner of the HTML page.  You can think of it as the absolute (x,y) of the mouse cursor.</p>
	<p>The nice thing about <code>.pageX/Y</code> is that serves as an easy way to get the mouse position, <em>regardless</em> of how much (or even if) the browser window is scrolled.</p>
	<p>Contrast <code>.pageX/Y</code> with <code>.clientX/Y</code>:  the latter reports (x,y) coordinates relative to the upper-left corner of the browser window, so these values <em>will</em> be affected by browser scroll position.</p>
	<p>Anyway, at this point, you're probably thinking that I'm going to tell you that Firefox 3 reports the wrong values for <code>.pageX/Y</code>, and that that's the bug.  It's not that simple though (again, I admit this is a somewhat obscure bug).</p>
	<p><em>Most</em> of the time, Firefox 3 reports the right values for <code>.pageX/Y</code>, but there is one case in which it doesn't.</p>
	<h3>Manually Dispatching Events in Javascript</h3>
	<p>A while back, I wrote a post about <a href = "http://blog.stchur.com/2007/11/16/re-routing-events-in-javscript/" title = "Re-routing Events in Javascript">Re-routing events in Javascript</a>.  In it, I explain how to create an event and initialize it with <code>myEvt.initMouseEvents(..)</code> (which takes a <a href = "http://developer.mozilla.org/en/docs/DOM:event.initMouseEvent" title = "Mozilla Developer Center (initMouseEvent)">boat-load</a> of parameters).</p>
	<p>Of all those parameters sent into <code>.initMouseEvents(..)</code>, 4 are of particular interest: <code>.screenX</code>, <code>.screenY</code>, <code>.clientX</code>, and <code>.clientY</code>.</p>
	<p>Notice that <code>.pageX</code> and <code>.pageY</code> are not in the list.  You don't get the ability to pass in <code>.pageX/Y</code> when manually creating/dispatching an event in Javascipt.  Presumably, the values for these properties are computed based on <code>.clientX/Y</code> and the browser's scroll position.</p>
	<p>So for example, if you initialize a MouseEvent with <code>.clientX</code> = 200 and <code>.clientY</code> = 300, and if the browser is scrolled 50 x 75, then your event's <code>.pageX</code> and <code>.pageY</code> values will be 250 and 375 respectively.</p>
	<p>Oops!  I mean, that's what the values <em>should</em> be.</p>
	<h3>The Bug</h3>
	<p>Firefox 2 actually gets it right, but Firefox 3 doesn't.</p>
	<p>When you're manually dispatching a MouseEvent in Firefox 3, the <code>.pageX/Y</code> property values will <em>always</em> be equal to the <code>.clientX/Y</code> values, <em>regardless</em> of browser scroll position.</p>
	<p>As I previously mentioned, this affects the VE MapControl, so it's easy to see the issue in action.  Just use Firefox 3 and point your browser to <a href = "http://maps.live.com" title = "Microsoft Live Search Maps">http://maps.live.com</a>.  Now make your browser window small enough to cause scroll bars to appear.  Scroll the browser window by some amount (doesn't matter how much) and try panning the map.  You should see the map "jump" during the initial pan.  The amount it "jumps" is going to be equal to the amount by which the browser window is scrolled.</p>
	<h3>The Fix</h3>
	<p>Microsoft has a work-around for this issue that is going to be released with the next version of Virtual Earth, but if you're a mashup dev using the VE MapControl, I've got a solution that you can use right now, and it goes like this:</p>
	<div class="dean_ch" style="white-space: nowrap;"><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> mouseEvt;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">typeof</span> document.<span class="me1">createEvent</span> !== <span class="st0">'undefined'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mouseEvt = document.<span class="me1">createEvent</span><span class="br0">&#40;</span><span class="st0">'MouseEvents'</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>mouseEvt &amp;&amp; mouseEvt.__proto__ &amp;&amp; mouseEvt.__proto__.__defineGetter__<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mouseEvt.__proto__.__defineGetter__<span class="br0">&#40;</span><span class="st0">'pageX'</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">clientX</span> + window.<span class="me1">pageXOffset</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; mouseEvt.__proto__.__defineGetter__<span class="br0">&#40;</span><span class="st0">'pageY'</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">clientY</span> + window.<span class="me1">pageYOffset</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
	<p>Just include the preceding code snippet anywhere in your HTML page.  The code is pretty straight-forward and just relies on the fact that Firefox (and others) have the ability to define getters through the use of <code>.__defineGetter__(..)</code>.</p>
	<p>The <code>.pageX/Y</code> properties are read only, but it turns out that the browser will let you redefine these getters, thereby overriding their return logic.  Since the <code>.clientX/Y</code> properties appear to always report the correct value, all we have to do redefine the <code>.pageX/Y</code> getters to use a combination of <code>.clientX/Y</code> + <code>.pageX/YOffset</code>.</p>
	<p>In other words, we've redefined <code>.pageX/Y</code> to always return the position of the event (in our case, the mouse cursor since we're dealing with MouseEvents), relative to the upper-left corner of the browser window + the scrolled position of the browser -- what it should have been all along!</p>
	<p>This code doesn't hurt IE, as it won't execute in that browser, and it doesn't hurt Firefox 2 or other browsers that understand the code either, because the logic we've defined for the getters is going to be essentially the same as what the browser would have done natively anyway.</p>
	<p>I'd like to file a bug to Mozilla on this issue, but I haven't a clue as to how one goes about doing that.  If anyone knows (or wants to do it for me), feel free to speak up!</p>
	<p>Enjoy the fix!</p>
	<p>Comments welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/07/03/firefox-3-pagex-pagey-bug/feed/</wfw:commentRss>
		</item>
		<item>
		<title>CSS Word-wrap: break word; (revisited)</title>
		<link>http://blog.stchur.com/2008/06/29/css-word-wrap-break-word-revisited/</link>
		<comments>http://blog.stchur.com/2008/06/29/css-word-wrap-break-word-revisited/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 00:16:30 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Advanced Javascript]]></category>

		<category><![CDATA[Cross-Browser]]></category>

		<category><![CDATA[Firefox Related]]></category>

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

		<category><![CDATA[Mozilla-specific]]></category>

		<category><![CDATA[Useful Functions]]></category>

		<guid isPermaLink="false">http://blog.stchur.com/2008/06/29/css-word-wrap-break-word-revisited/</guid>
		<description><![CDATA[HedgerWow is a great blog.  If you've never checked it out, you definitely should.

I just noticed the other day that his latest post gives some props to my Emulating CSS word-wrap for Mozilla/Firefox blog post, but his version adds some much needed cross-browser support for browsers I neglected.

Nice One, HedgerWow!]]></description>
			<content:encoded><![CDATA[<p><a href = "http://www.hedgerwow.com" title = "Keep It Simple, Stupid">HedgerWow</a> is a great blog.  If you've never checked it out, you definitely should.</p>

<p>I just noticed the other day that his latest post gives some props to my <a href = "http://blog.stchur.com/2007/03/01/word-wrap-for-mozilla-take-2/" title = "Emulating CSS word-wrap for Mozilla/Firefox">Emulating CSS word-wrap for Mozilla/Firefox</a> blog post, but <a href = "http://www.hedgerwow.com/360/dhtml/css-word-break.html" title = "Cross Browser Word Breaker">his version</a> adds some much needed cross-browser support for browsers I neglected.</p>

<p><a href = "http://www.hedgerwow.com/360/dhtml/css-word-break.html" title = "Cross Browser Word Breaker">Nice One</a>, HedgerWow!</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/06/29/css-word-wrap-break-word-revisited/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Firefox 3</title>
		<link>http://blog.stchur.com/2008/06/19/firefox-3/</link>
		<comments>http://blog.stchur.com/2008/06/19/firefox-3/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 14:45:50 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Firefox Related]]></category>

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

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

		<category><![CDATA[Mozilla-specific]]></category>

		<category><![CDATA[Web-related]]></category>

		<guid isPermaLink="false">http://blog.stchur.com/2008/06/19/firefox-3/</guid>
		<description><![CDATA[Well unless you've been living under a rock, you know that Firefox 3 was released on Tuesday.  This is a big deal for me. When other browser makers release a new version, it's like eh... ok, that's cool (I guess).  But when Mozilla releases a new Firefox, I've got a brand new shiny [...]]]></description>
			<content:encoded><![CDATA[<p>Well unless you've been living under a rock, you know that <a href = "http://www.getfirefox.com" Title = "Firefox">Firefox 3</a> was released on Tuesday.  This is a big deal for me. When other browser makers release a new version, it's like eh... ok, that's cool (I guess).  But when Mozilla releases a new Firefox, I've got a brand new shiny app to get me through my day to day web browsing.</p>

<p>Besides the new theme (on Windows) being a little bland, FF3 does <em>not</em> disappoint!</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/06/19/firefox-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Palindromes</title>
		<link>http://blog.stchur.com/2008/06/14/palindromes/</link>
		<comments>http://blog.stchur.com/2008/06/14/palindromes/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 19:06:11 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Computing]]></category>

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

		<category><![CDATA[Javascript basics]]></category>

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

		<category><![CDATA[Useful Functions]]></category>

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

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

		<guid isPermaLink="false">http://blog.stchur.com/2008/06/14/palindromes/</guid>
		<description><![CDATA[	The other evening while I was watching TV, I happened to have my laptop out, so I started dabbling around in Firebug just for the heck of it.  I'll often just start writing functions for no particular reason, other than to refresh my skills or perhaps discover something about Javascript that I hadn't previously [...]]]></description>
			<content:encoded><![CDATA[	<p>The other evening while I was watching TV, I happened to have my laptop out, so I started dabbling around in Firebug just for the heck of it.  I'll often just start writing functions for no particular reason, other than to refresh my skills or perhaps discover something about Javascript that I hadn't previously known.</p>
	<p>So I was monkeying around, and I decided to write a function to determine if a string were a <a href = "http://en.wikipedia.org/wiki/Palindrome" title = "Wikipedia: Palindrome">palindrome</a>.  This is not a very difficult problem, but it might make for a descent introductory interview question (one of those questions you'd ask to rule out the truly inept).</p>
	<p>With problems like this, I'm mostly interested in two things:</p>
	<ol>
	<li>Writing the function in a clever way, so as to achieve the least amount of code possible</li>
	<li>Writing the function in the most efficient way possible</li>
	</ol>
	<p>Now, if it were Ruby, writing the clever solution (which might also happen to be the most efficient solution in that language -- not sure) would be ridiculously easy:</p>
	<div class="dean_ch" style="white-space: nowrap;"><span class="kw1">def</span> pal<span class="br0">&#40;</span>s<span class="br0">&#41;</span><br />
&nbsp; &nbsp;s == s.<span class="me1">reverse</span><br />
<span class="kw1">end</span></div>
	<p>That's so trivial, it's probably not even worth writing.</p>
	<p>But Javascript doesn't have a .reverse() method on strings, so you have to take an extra step (still pretty easy though):</p>
	<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">function</span> pal<span class="br0">&#40;</span>s<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw1">return</span> s === s.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">''</span><span class="br0">&#41;</span>.<span class="me1">reverse</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">''</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
	<p>Split the string into an array, reverse the array, and then join it back together.  Since this is all native Javascript stuff, it turns out to be reasonably fast, though one might expect you could do better.</p>
	<p>For grins and giggles, I decided to see how a manual solution, where I compare characters starting at each end of the string and work towards the middle, would compare:</p>
	<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">function</span> pal<span class="br0">&#40;</span>s<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> i, j,<br />
&nbsp; &nbsp;len = s.<span class="me1">length</span>,<br />
&nbsp; &nbsp;mid = Math.<span class="me1">floor</span><span class="br0">&#40;</span>len / <span class="nu0">2</span><span class="br0">&#41;</span>;</p>
	<p>&nbsp; &nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span>i = <span class="nu0">0</span>, j = len - <span class="nu0">1</span>; i &lt; mid; i++, j--<span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>s.<span class="me1">charAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span> !== s.<span class="me1">charAt</span><span class="br0">&#40;</span>j<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;<br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="kw1">return</span> <span class="kw2">true</span>;<br />
<span class="br0">&#125;</span></div>
	<p>This function will probably fail quickly, so that's good, but it also turns out to be generally faster than the split/reverse/join version.  It makes sense, since you're going through the string only one time and twice as fast as normal since you're traversing from both ends at the same time.</p>
	<p>Can you do even better though?  Maybe.  At least in Firefox you can, and quick tests seemed to confirm across other browsers too (but I didn't test extensively).</p>
	<p>What if we split the string in half, and only reverse half of it.  Then we can compare the first half with the original half:</p>
	<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">function</span> pal<span class="br0">&#40;</span>s<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">var</span> len = s.<span class="me1">length</span>,<br />
&nbsp; &nbsp;x = len / <span class="nu0">2</span>,<br />
&nbsp; &nbsp;y = x === Math.<span class="me1">floor</span><span class="br0">&#40;</span>x<span class="br0">&#41;</span> ? x : <span class="br0">&#40;</span>x = Math.<span class="me1">floor</span><span class="br0">&#40;</span>x<span class="br0">&#41;</span><span class="br0">&#41;</span> + <span class="nu0">1</span>;</p>
	<p>&nbsp; &nbsp;<span class="kw1">return</span> s.<span class="me1">substr</span><span class="br0">&#40;</span><span class="nu0">0</span>, x<span class="br0">&#41;</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">''</span><span class="br0">&#41;</span>.<span class="me1">reverse</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">''</span><span class="br0">&#41;</span> === s.<span class="me1">substr</span><span class="br0">&#40;</span>y,len<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
	<p>The idea here is just split the string in half, reverse one of the two pieces and compare them.  For example:</p>
	<p>TOOT: splits into "TO" and "OT."  Reverse one of them, say the second part ("OT") and compare.</p>
	<p>If you've got a odd number of characters, you can ignore the middle most character:</p>
	<p>RACECAR: splits into "RAC" and "CAR" (ignore the "E" in the middle).  Reverse the second part ("CAR") and compare.</p>
	<p>As it turned out, this seemed to be faster than the other two methods.  Not by orders of magnitude, but not insignificantly either.  Here are the number from Firefox, running each function 10,000 time on the string "gohangasalamiimalasagnahog" (go hang a salami, i'm a lasagna hog).</p>
	<ul>
	<li>(Traverse from both ends): 797ms</li>
	<li>(Split/Reverse/Join): 969ms</li>
	<li>(Compare halves): 640ms</li>
	</ul>
	<p>Of course, numbers varied slightly during each run, but overall the they were consistent relative to each other.</p>
	<p>So there ya go.  Nothing in particular I wanted to point out here; just found it interesting and thought you might too.</p>
	<p>Think my code sucks?  Got a better solution?  Say so in the comments (you won't hurt my feelings).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/06/14/palindromes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sneak Peek</title>
		<link>http://blog.stchur.com/2008/06/10/sneak-peek/</link>
		<comments>http://blog.stchur.com/2008/06/10/sneak-peek/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 06:02:36 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Blog-related]]></category>

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

		<guid isPermaLink="false">http://blog.stchur.com/2008/06/10/sneak-peek/</guid>
		<description><![CDATA[	I'm working on a new theme for my blog, as the dark colors are starting to hurt my eyes (maybe I am getting old).
	I'm going for something very minimalist this time around.  In fact, the name of the theme I'm working on is "Less Is More."
	Since I've recently installed a Theme Preview Plugin for [...]]]></description>
			<content:encoded><![CDATA[	<p>I'm working on a new theme for my blog, as the dark colors are starting to hurt my eyes (maybe I am getting old).</p>
	<p>I'm going for something very minimalist this time around.  In fact, the name of the theme I'm working on is "Less Is More."</p>
	<p>Since I've recently installed a Theme Preview Plugin for Wordpress, I thought I'd leverage that to allow my readers to get a sneak peak of what the new theme will look like.</p>
	<p>Simply point your browser to: <a href = "http://blog.stchur.com/?preview_theme=less-is-more" title = "Incoherent Babble's Next Theme">http://blog.stchur.com/?preview_theme=less-is-more</a>.</p>
	<p>Feel free to offer feedback on what you like / don't like, but please remember that it's not done (should be done enough though to give you a basic idea of where I'm headed).</p>
	<p>For those of you reading from an RSS reader, come on over and check out the blog the "old fashioned way" for a change, so you too can get a sneak preview of the next Incoherent Babble theme.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/06/10/sneak-peek/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Another Puzzle</title>
		<link>http://blog.stchur.com/2008/06/09/another-puzzle/</link>
		<comments>http://blog.stchur.com/2008/06/09/another-puzzle/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 17:25:38 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Computing]]></category>

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

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

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

		<guid isPermaLink="false">http://blog.stchur.com/2008/06/09/another-puzzle/</guid>
		<description><![CDATA[	Well after some significant thought, I have decided that I was either not given enough information to solve the puzzle in my last post, or I'm going to need a hint from the person who gave me the puzzle.
	Either way though, I don't have an answer to post as I promised I would, but not [...]]]></description>
			<content:encoded><![CDATA[	<p>Well after some significant thought, I have decided that I was either not given enough information to solve the puzzle in my <a href = "http://blog.stchur.com/2008/06/05/a-puzzle/" Title = "Incoherent Babble | A Puzzle">last post</a>, or I'm going to need a hint from the person who gave me the puzzle.</p>
	<p>Either way though, I don't have an answer to post as I promised I would, but not to worry... I have something better: another puzzle!</p>
	<p>This one I heard on NPR's Puzzle Master, so I know it is legit:</p>
	<div>
On a calculator display there are 5 digits.  The first 4 digits are: 8 7 3 5.  What is the fifth digit?
</div>
	<p>It's not a trick question, and there is a simple and elegant solution to the puzzle.</p>
	<p><button onclick="document.getElementById('theAnswer').style.display='block';">Display the answer</button></p>
	<div id = "theAnswer" style = "display: none; border: 2px solid #ccc; margin: 1em; padding: 1em; background: #333;">
	<p>The fifth digit is 5 (so that the calclator display reads: 8 7 3 5 5).  Why?  Because it fits the pattern.  Digits displayed on a calculator are usually displayed with bars. For example a 3 would be displayed with 5 bars, like so:</p>
	<p style = "margin-left: 3em;">
_<br />
_|<br />
_|
</p>
	<p>So if you start with an 8, you can easily figure out the pattern.  An 8 is made up of 7 bars, so 7 is the next digit.  A 7 is made up of 3 bars so 3 is the next digit.  A 3 is made up of 5 bars so 5 is the next digit.  And finally, a 5 is made up of 5 bars, so 5 is again the next digit.</p>
	</div>
	<p>In case you're wondering, I heard this in the car listening to the radio, and I'd estimate that I drove about 5 miles or so before the answers came to me, so I'll guess that that was about 5 minutes.  How long did it take you to solve?</p>
	<p>Comments welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/06/09/another-puzzle/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Puzzle</title>
		<link>http://blog.stchur.com/2008/06/05/a-puzzle/</link>
		<comments>http://blog.stchur.com/2008/06/05/a-puzzle/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 22:45:12 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[Computing]]></category>

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

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

		<guid isPermaLink="false">http://blog.stchur.com/2008/06/05/a-puzzle/</guid>
		<description><![CDATA[	So today at lunch, my co-worker gave me this puzzle to solve:
	
	In some prison, there are 10 prisoners and a prison guard.  The prison guard plans to randomly choose prisoners and take them one by one into a special room that has two switches.  Either switch can be on or off and no [...]]]></description>
			<content:encoded><![CDATA[	<p>So today at lunch, my co-worker gave me this puzzle to solve:</p>
	<div style="background: #333; padding: 1em; margin: 1em; border: 2px solid #ccc">
	<p>In some prison, there are 10 prisoners and a prison guard.  The prison guard plans to randomly choose prisoners and take them one by one into a special room that has two switches.  Either switch can be on or off and no one knows the starting state of each switch ahead of time.  Upon entering the room, the prisoner must throw one (and exactly one switch).  He cannot simply do nothing and then leave the room.</p>
	<p>Once all 10 prisoners have entered the special room, the prison guard will let them go free, but there is a catch.  One of the prisoners needs to declare when all prisoners have entered the special room at least one time.  If his declaration is correct, they all go free.  If not, they all die.  Remember that the guard is bringing prisoners into the special room completely at random, and there is nothing to stop him from bring the same person into the room multiple times.</p>
	<p>Now, before the big event, the prison guard is going to allow the prisoners to meet together and try to come up with a strategy to figure out how to determine how they'll know when all 10 prisoners have entered the special room at least once.</p>
	</div>
	<p>So what's the strategy?</p>
	<p>Now I just heard this problem, and I've only put minimal thought into it so far.  I will post back with the "official" answer in a few days, but before I do, I thought it would be amusing to entertain some of my quick responses, all of which (based on the problem as it was given to me) are completely valid:</p>
	<h3>My first solution:</h3>
	<p>Each prisoner who enters the room takes off one shoe and leaves it behind (while also throwing one switch as per the rules).  When a prisoner enters the room and sees 9 shoes, he'll know he is the 10th prisoner.</p>
	<p>My co-worker then replied that the prisoners don't have any shoes, or any clothes of any kind; they're completely naked.</p>
	<h3>My second solution:</h3>
	<p>Each prisoner who enters the room spits a giant <a href = "http://www.urbandictionary.com/define.php?term=loogie" title = "Definition of loogie">loogie</a> onto the ground (while also throwing one switch as per the rules).  When a prisoner enters the room and sees 9 loogies on the ground, he'll know he is the 10th prisoner.</p>
	<p>My co-worker then replied that the loogies will dry up and you won't be able to see them because the guard will wait a very long time between bringing each prisoner into the room.</p>
	<h3>My third solution:</h3>
	<p>Each prisoner who enters the room will leave a giant poo on the ground (while also throwing one switch as per the rules), and when a prisoner enters the room and sees 9 piles of poo, he'll know he is the 10th visitor.</p>
	<p>At this point, we were all laughing too hard to have any further intelligent discussion on the matter.</p>
	<p>But I do plan to think about this and report back with a "real" solution.  I have a few ideas already, but I don't have sufficient time to get them into words.</p>
	<p>If you'd like to post an answer, you're welcome to do so.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/06/05/a-puzzle/feed/</wfw:commentRss>
		</item>
		<item>
		<title>In Honor of Caspian (enhancing Gimme)</title>
		<link>http://blog.stchur.com/2008/05/16/in-honor-of-caspian-enhancing-gimme/</link>
		<comments>http://blog.stchur.com/2008/05/16/in-honor-of-caspian-enhancing-gimme/#comments</comments>
		<pubDate>Sat, 17 May 2008 03:47:53 +0000</pubDate>
		<dc:creator>sstchur</dc:creator>
		
		<category><![CDATA[CSS Related]]></category>

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

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

		<category><![CDATA[Useful Functions]]></category>

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

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

		<category><![CDATA[John Resig]]></category>

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

		<category><![CDATA[Shaun Inman]]></category>

		<guid isPermaLink="false">http://blog.stchur.com/2008/05/16/in-honor-of-caspian-enhancing-gimme/</guid>
		<description><![CDATA[	The Chronicles of Narnia: Prince Caspian arrived in theaters today, and for those of you who haven't noticed, all of the Gimme codename releases are named after characters from the Chronicles of Narnia, since it is the greatest fantasy series ever written (sorry Lord of the Rings and Harry Potter fans, but I'm afraid that [...]]]></description>
			<content:encoded><![CDATA[	<p><a href = "http://en.wikipedia.org/wiki/Prince_Caspian" title = "Prince Caspian">The Chronicles of Narnia: Prince Caspian</a> arrived in theaters today, and for those of you who haven't noticed, all of the Gimme codename releases are named after characters from the <a href = "http://www.narniaweb.com" title = "Narnia Web">Chronicles of Narnia</a>, since it is the greatest fantasy series ever written (sorry Lord of the Rings and Harry Potter fans, but I'm afraid that yes, Narnia, <em>is</em> better).</p>
	<p>Anyway, since the current beta release of Gimme is "Caspian" I figured I'd do a post today in honor of Gimme and the movie (ok, it helps that I also have something worth writing about too).</p>
	<p>So anyway, on to what this post is really about: enhancing Gimme.</p>
	<p>Not too long ago, <a href = "http://www.shauninman.com" title = "Shaun Inman">Shaun Inman</a> wrote about his proposal for <a href = "http://shauninman.com/archive/2008/05/05/css_qualified_selectors" title = "CSS Qualified Selectors">CSS Qualified Selectors</a>.</p>
	<p>It's a good idea; I've actually had the same idea and thought briefly about making it part of Gimme's core CSS selector engine.  Only, in my model, I have the left-hand-side and the right-hand-side of the <code><</code> symbol switched.  It feels more natural to me that way, because in most CSS selector rules, you can simply look to the far right of the selector rule and know what type of "thing" you're going to be selecting.</p>
	<p>Thus, I feel that this:</p>
	<div class="dean_ch" style="white-space: nowrap;">img &lt; a&nbsp; &nbsp; &nbsp;<span class="coMULTI">/* select all &lt;a&gt; elements that contain an &lt;img&gt; element */</span></div>
	<p>feels more natural than this:</p>
	<div class="dean_ch" style="white-space: nowrap;">a &lt; img&nbsp; &nbsp; &nbsp;<span class="coMULTI">/* same logic as above -- Shaun's approach */</span></div>
	<p>But this is just details; the idea is the same either way.</p>
	<p>So anyway, after Shaun published his idea, <a href = "http://www.ejohn.com" title = "John Resig">John Resig</a> chimed in and mentioned that <a href = "http://www.jquery.com" title = "jQuery">jQuery</a> supports this already via <a href = "http://ejohn.org/blog/qualified-selectors-in-jquery/" title = "jQuery :has(..)">pseudo :has(..)</a>.</p>
	<p>Well that's pretty cool, but since <a href = "http://codeplex.com/gimme" title = "The Gimme Javascript Library">Gimme</a> is my library, naturally, I feel compelled to make sure it stacks up against the competition, so I thought to myself: "self, can Gimme do this?" to which a mental reply came back "No, remember? You decided no to implement it."</p>
	<p>And I would have just left it at that, because after all, I decided not to implement it for a reason (and I figured that's where I <em>would</em> leave it).</p>
	<p>But then, today, my officemate surprised me by asking "Hey, I have a question about Gimme.  I'm working with a page where I need to select a &lt;table&gt; element that has an &lt;h1&gt;.  Can Gimme do this?"</p>
	<p>Well crap!  What are the odds that this would come up again so quickly?</p>
	<p>Not being one to disappoint, I said "You know what? I decided not to implement it, but I did put significant effort into making Gimme's selector engine extensible.  I bet we can write an extension really easily."</p>
	<p>So a few minutes later, we came up with this little gem:</p>
	<div class="dean_ch" style="white-space: nowrap;">Gimme.<span class="me1">Selectors</span>.<span class="me1">addPseudo</span><span class="br0">&#40;</span><span class="st0">'has'</span>, <span class="kw2">function</span><span class="br0">&#40;</span>_elem, _pseudo<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> children = Gimme.<span class="me1">query</span><span class="br0">&#40;</span>_pseudo.<span class="me1">param</span>, _elem<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">return</span> children.<span class="me1">length</span> &gt; <span class="nu0">0</span>;<br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
	<p>Which means you can now use Gimme to do something like:</p>
	<div class="dean_ch" style="white-space: nowrap;">g<span class="br0">&#40;</span><span class="st0">'p:has(img.funny)'</span><span class="br0">&#41;</span>;&nbsp; <span class="co1">// select all &lt;p&gt;s that contain &lt;img&gt;s with class &quot;funny&quot;</span></div>
	<p>Unlike what John did, I didn't bother to map this back to the <code><</code> symbol.  I thought about it, and you could do it easily enough, but the more I think about it, the more I like how <code>:has(..)</code> reads.</p>
	<p>It's not likely that I'll make something like this part of the core Gimme library unless it start popping up everywhere.  It comes up occasionally, but not enough to warrant making it part of the core (at least, not enough in my personal experiences so far anyway).</p>
	<p>So there ya go!  Think of this as edition 1 of "Gimme can do that too" with (hopefully) many more editions to come.</p>
	<p>Comments welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stchur.com/2008/05/16/in-honor-of-caspian-enhancing-gimme/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
