<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>splat operator</title>
	<atom:link href="http://splatoperator.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://splatoperator.com</link>
	<description>:computering =&#62; *&#039;a&#039;..&#039;z&#039;</description>
	<lastBuildDate>Fri, 13 Apr 2012 19:52:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Clone Ubuntu VMs in VirtualBox</title>
		<link>http://splatoperator.com/2012/04/clone-ubuntu-vms-in-virtualbox/</link>
		<comments>http://splatoperator.com/2012/04/clone-ubuntu-vms-in-virtualbox/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 18:06:35 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[dhcp]]></category>
		<category><![CDATA[udev]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://splatoperator.com/?p=413</guid>
		<description><![CDATA[I installed Ubuntu from mini.iso and I want to make several copies. What are the potential pitfalls? Well, the only real problem is that if we&#8217;re not careful they&#8217;ll all have the same MAC address. There&#8217;s a checkbox to avoid &#8230; <a href="http://splatoperator.com/2012/04/clone-ubuntu-vms-in-virtualbox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I installed Ubuntu from mini.iso and I want to make several copies. What are the potential pitfalls? Well, the only real problem is that if we&#8217;re not careful they&#8217;ll all have the same MAC address. There&#8217;s a checkbox to avoid this in VirtualBox,</p>

<div id="attachment_414" class="wp-caption alignnone" style="width: 616px"><a href="http://splatoperator.com/wordpress/wp-content/uploads/Reinitialize-the-MAC-address-checkbox.png"><img src="http://splatoperator.com/wordpress/wp-content/uploads/Reinitialize-the-MAC-address-checkbox.png" alt="Reinitialize the MAC address checkbox" title="Reinitialize the MAC address checkbox" width="606" height="390" class="size-full wp-image-414" /></a><p class="wp-caption-text">What a convenient checkbox!</p></div>

<p>which gets you halfway there, but when you boot your new system it will still remember that eth0 was that old MAC address. What&#8217;s worse is it will stall for over a minute while booting and tell you it&#8217;s waiting for network configuration&#8230;</p>

<div id="attachment_416" class="wp-caption alignnone" style="width: 652px"><a href="http://splatoperator.com/wordpress/wp-content/uploads/Waiting-up-to-60-more-seconds-for-network-configuration.png"><img src="http://splatoperator.com/wordpress/wp-content/uploads/Waiting-up-to-60-more-seconds-for-network-configuration.png" alt="Waiting up to 60 more seconds for network configuration" title="Waiting up to 60 more seconds for network configuration" width="642" height="260" class="size-full wp-image-416" /></a><p class="wp-caption-text">AAAAHHHHHHHHHHH!!!!</p></div>

<p>The easiest way to get through this is just to wait it out. Eventually you&#8217;ll get a login prompt. When you do, log in. Now you want to edit your udev rules so that you&#8217;re newly generated MAC address maps to eth0. That&#8217;ll fix everything.</p>

<div class="codecolorer-container bash railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>udev<span style="color: #000000; font-weight: bold;">/</span>rules.d<span style="color: #000000; font-weight: bold;">/*</span>-persistent-net.rules</div></div>

<p>Mine looks like this</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># PCI device 0x8086:0x100e (e1000)<br />
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, ATTR{address}==&quot;08:00:27:11:7c:8b&quot;, ATTR{dev_id}==&quot;0x0&quot;, ATTR{type}==&quot;1&quot;, KERNEL==&quot;eth*&quot;, NAME=&quot;eth0&quot;<br />
<br />
# PCI device 0x8086:0x100e (e1000)<br />
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, ATTR{address}==&quot;08:00:27:03:8e:5a&quot;, ATTR{dev_id}==&quot;0x0&quot;, ATTR{type}==&quot;1&quot;, KERNEL==&quot;eth*&quot;, NAME=&quot;eth1&quot;</div></div>

<p>I&#8217;m just going to delete the old eth0 entry (the first one) and change the name of the new one to eth0.</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># PCI device 0x8086:0x100e (e1000)<br />
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, ATTR{address}==&quot;08:00:27:03:8e:5a&quot;, ATTR{dev_id}==&quot;0x0&quot;, ATTR{type}==&quot;1&quot;, KERNEL==&quot;eth*&quot;, NAME=&quot;eth0&quot;</div></div>

<p>A quick reboot and everything&#8217;s shiny. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/04/clone-ubuntu-vms-in-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Depaginate Phoronix Articles</title>
		<link>http://splatoperator.com/2012/04/depaginate-phoronix-articles/</link>
		<comments>http://splatoperator.com/2012/04/depaginate-phoronix-articles/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 21:26:15 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[quickies]]></category>
		<category><![CDATA[depaginate]]></category>
		<category><![CDATA[depagination]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[paginate]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[phoronix]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[user script]]></category>

		<guid isPermaLink="false">http://splatoperator.com/?p=403</guid>
		<description><![CDATA[I sketched this for Phoronix, but you could easily adapt it to any site that uses pagination. I think it&#8217;s an interesting problem, so if you want to see another site depaginated, just ask me in a comment and I&#8217;ll &#8230; <a href="http://splatoperator.com/2012/04/depaginate-phoronix-articles/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I sketched this for Phoronix, but you could easily adapt it to any site that uses pagination. I think it&#8217;s an interesting problem, so if you want to see another site depaginated, just ask me in a comment and I&#8217;ll check it out.</p>

<p>Here&#8217;s the script. It&#8217;s also available <a href="https://gist.github.com/2323037">as a Gist</a> if you want to tinker with it.</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">/**<br />
&nbsp;* Depaginate Phoronix articles<br />
&nbsp;*<br />
&nbsp;* Script by Justin Force, 2012. Released to the public domain.<br />
&nbsp;*<br />
&nbsp;* Stick this in whatever user scripts you have. I keep an unpacked Chrome<br />
&nbsp;* extension. You could also use this with GreaseMonkey or something as long as<br />
&nbsp;* you load jQuery first.<br />
&nbsp;*/</span><br />
<br />
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.phxcms_navigation_format a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&amp;num=/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/Next Page/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; div.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' #phxcms_content_phx'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; div.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.phxcms_navigation_format'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#phxcms_content_phx'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/04/depaginate-phoronix-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropbox: Unable to monitor filesystem</title>
		<link>http://splatoperator.com/2012/02/dropbox-unable-to-monitor-filesystem/</link>
		<comments>http://splatoperator.com/2012/02/dropbox-unable-to-monitor-filesystem/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 03:31:28 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[Dropbox]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[inotify]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysctl]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=382</guid>
		<description><![CDATA[Have you seen this while using Dropbox in Linux? Unable to monitor filesystem Please run: echo 100000 &#124; sudo tee /proc/sys/fs/inotify/max_user_watches and restart Dropbox to correct the problem. Apparently, Linux is imposing some kind of default restriction of the number &#8230; <a href="http://splatoperator.com/2012/02/dropbox-unable-to-monitor-filesystem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you seen this while using Dropbox in Linux?</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Unable to monitor filesystem<br />
Please run: echo 100000 | sudo tee /proc/sys/fs/inotify/max_user_watches<br />
and restart Dropbox to correct the problem.</div></div>

<p>Apparently, Linux is imposing some kind of default restriction of the number of files that you can monitor with <a href="http://en.wikipedia.org/wiki/Inotify" title="inotify on Wikipedia">inotify</a>. This is not Dropbox&#8217;s fault. This is a system-level setting, so you&#8217;ll need root to fix it. The easiest way to fix it is to tell sysctl to increase the limit. Just run this command to add the sysctl configuration:</p>

<div class="codecolorer-container bash railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;fs.inotify.max_user_watches = 99999999999&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sysctl.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20</span>-dropbox-inotify.conf</div></div>

<p>And to load the new configuration immediately, reboot or just run this:</p>

<div class="codecolorer-container bash railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> sysctl <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>sysctl.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20</span>-dropbox-inotify.conf</div></div>

<p>That should permanently fix it.</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/02/dropbox-unable-to-monitor-filesystem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>extconf.rb:4:in `require&#8217;: no such file to load &#8212; mkmf (LoadError)</title>
		<link>http://splatoperator.com/2012/01/extconf-rb4in-require-no-such-file-to-load-mkmf-loaderror/</link>
		<comments>http://splatoperator.com/2012/01/extconf-rb4in-require-no-such-file-to-load-mkmf-loaderror/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 21:47:54 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[loaderror]]></category>
		<category><![CDATA[mkmf]]></category>
		<category><![CDATA[quicky]]></category>
		<category><![CDATA[require]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=378</guid>
		<description><![CDATA[I&#8217;ve hit this a dozen times and I always forget the solution. When you get this on Ubuntu, sudo apt-get install ruby-dev]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve hit this a dozen times and I always forget the solution. When you get this on Ubuntu,</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo apt-get install ruby-dev</div></div>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/01/extconf-rb4in-require-no-such-file-to-load-mkmf-loaderror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ssh Through Two Hosts in One Command</title>
		<link>http://splatoperator.com/2012/01/quickie-ssh-through-two-hosts-in-one-command/</link>
		<comments>http://splatoperator.com/2012/01/quickie-ssh-through-two-hosts-in-one-command/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 19:08:52 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[quickies]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[hop]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=372</guid>
		<description><![CDATA[Say you want a shell on a box but you have to hop through another box to get it. force@harold:~% ssh admin@maude maude:~ force$ ssh root@whee root@whee:~$ echo w00t w00t You can do that in one line using -t (pseudo-tty &#8230; <a href="http://splatoperator.com/2012/01/quickie-ssh-through-two-hosts-in-one-command/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Say you want a shell on a box but you have to hop through another box to get
it.</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">force@harold:~% ssh admin@maude<br />
maude:~ force$ ssh root@whee<br />
root@whee:~$ echo w00t<br />
w00t</div></div>

<p>You can do that in one line using <code>-t</code> (pseudo-tty allocation).</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">force@harold:~% ssh -t admin@maude ssh root@whee<br />
root@whee:~$ echo w00t<br />
w00t</div></div>

<p>After playing with it, I can only get this to work for one hop. So yes, it&#8217;s of
limited use. But I hop through another box <em>every time</em> I ssh at work, so I&#8217;m
going to be getting a lot of mileage out of this little optimization. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/01/quickie-ssh-through-two-hosts-in-one-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Performance: Iterating over Arrays with Holes</title>
		<link>http://splatoperator.com/2012/01/javascript-performance-iterating-over-arrays-with-holes/</link>
		<comments>http://splatoperator.com/2012/01/javascript-performance-iterating-over-arrays-with-holes/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 22:47:02 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[hole]]></category>
		<category><![CDATA[iteration]]></category>
		<category><![CDATA[jsperf]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[undefined]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=363</guid>
		<description><![CDATA[I was sketching some code that basically took some data from a database and cached it in an array to be repeatedly reused. Conveniently, each row from the database had a unique ID, so I could use that as an &#8230; <a href="http://splatoperator.com/2012/01/javascript-performance-iterating-over-arrays-with-holes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was sketching some code that basically took some data from a database and cached it in an array to be repeatedly reused. Conveniently, each row from the database had a unique ID, so I could use that as an array index. But is that a good idea? It just means that when I iterate over the array, I&#8217;ll need to check whether an element is defined before I try to use it. Is it better to code around this? Say, storing the id and other information in an object and simply pushing the objects onto the array? This would save needlessly iterating over undefined values later. Or is it better to use the id as an array index so that I can do quick and dirty iterations with checking? This sounds like a job for <a href="http://jsperf.com">jsPerf</a>! So, following are the details of my experiment. If you like, you can check it out in full and <a href="http://jsperf.com/arrays-with-and-without-holes" title="jsPerf: Arrays with and without Holes">try the jsPerf yourself</a>.</p>

<h2>The Setup</h2>

<p>Here are the simple and complex arrays, the select indexes for the entries that we want to look up later, and the pairs of IDs and names that comprise our data. At the end, there&#8217;s a <code>get()</code> function so that we can look up entries without a numerical index.</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> simple <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> complex <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; selectIndexes <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">14</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; pairs <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> &nbsp; &nbsp;<span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Albert&quot;</span> &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> &nbsp; &nbsp;<span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Bailey&quot;</span> &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> &nbsp; &nbsp;<span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Charlotte&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> &nbsp; &nbsp;<span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Darlene&quot;</span> &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Edna&quot;</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Faron&quot;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">13</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Gary&quot;</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">14</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Helen&quot;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Igor&quot;</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">16</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Justin&quot;</span> &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">17</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Kyle&quot;</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Lynette&quot;</span> &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Morgan&quot;</span> &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nora&quot;</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
<br />
&nbsp; get <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">===</span> i.<span style="color: #660066;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>

<h2>The Experiment</h2>

<h3>simple</h3>

<p>A simple array with integer indexes and holes.</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>pairs<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; simple<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>simple<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">!==</span> window<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// this !== window is a workaround for IE</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>selectIndexes<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; simple<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>

<h3>complex</h3>

<p>A complex array which holds objects with id and name attributes. Since we&#8217;re not using integer indices, we have to supply a get function (defined in Setup above).</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>pairs<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; complex.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>complex<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>selectIndexes<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; get<span style="color: #009900;">&#40;</span>complex<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">name</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>

<h2>The Results</h2>

<p>Have a look at this graph:</p>

<div id="attachment_366" class="wp-caption alignnone" style="width: 926px"><a href="http://sidewaysmilk.com/wordpress/wp-content/uploads/arrays-with-and-without-holes-e1326408599298.png"><img src="http://sidewaysmilk.com/wordpress/wp-content/uploads/arrays-with-and-without-holes-e1326408599298.png" alt="Browser performance graph. Simple arrays with holes are the clear winner." title="Performance of various browsers using arrays with and without holes" width="916" height="466" class="size-full wp-image-366" /></a><p class="wp-caption-text">Simple arrays with holes are the clear winner.</p></div>

<h2>Conclusion</h2>

<p>The simple implementation just wipes the floor with complex one across the board. Not only is it easier to implement and read, but checking whether an element is undefined before you access it appears to be a trivially cheap operation. Arrays with holes are simple and safe to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/01/javascript-performance-iterating-over-arrays-with-holes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Defining Functions Inline Is Just Fine</title>
		<link>http://splatoperator.com/2012/01/defining-functions-inline-is-just-fine/</link>
		<comments>http://splatoperator.com/2012/01/defining-functions-inline-is-just-fine/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 20:00:21 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsperf]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=353</guid>
		<description><![CDATA[I put together this jsperf to see if there&#8217;s a difference between defining your function and then using it or defining it inline when looping with jQuery.each. You can try it yourself if you like, but here are the results: &#8230; <a href="http://splatoperator.com/2012/01/defining-functions-inline-is-just-fine/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I put together this <a href="http://jsperf.com">jsperf</a> to see if there&#8217;s a difference between defining your function and then using it or defining it inline when looping with <a href="http://api.jquery.com/jQuery.each">jQuery.each</a>. You can <a href="http://jsperf.com/functions-in-jquery-each/2/">try it yourself</a> if you like, but here are the results:</p>

<p>I compared using a pre-defined function with using a function defined inline.</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> body <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// cache this for use with both</span><br />
<br />
<span style="color: #006600; font-style: italic;">//pre-defined</span><br />
<span style="color: #006600; font-style: italic;">//</span><br />
<span style="color: #003366; font-weight: bold;">var</span> doSomething <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; body.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class='</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> doSomething<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// inline</span><br />
<span style="color: #006600; font-style: italic;">//</span><br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; body.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class='</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>

<p>Here&#8217;s a graph of the results of different browsers performing the test:</p>

<div id="attachment_358" class="wp-caption alignnone" style="width: 968px"><a href="http://sidewaysmilk.com/wordpress/wp-content/uploads/Screenshot-at-2012-01-04-144457.png"><img src="http://sidewaysmilk.com/wordpress/wp-content/uploads/Screenshot-at-2012-01-04-144457.png" alt="Performance of different browsers running $.each with pre-defined and inline functions" title="Performance of different browsers running $.each with pre-defined and inline functions" width="958" height="620" class="size-full wp-image-358" /></a><p class="wp-caption-text">Don&#039;t take this as an indication of the general performance of the browsers mentioned. Some were run on Linux, some on Mac, one in Wine on Linux, and some in Windows VMs on Linux.</p></div>

<p>The difference is negligible, so use whichever looks more readable to you. I prefer defining my functions inline, and will now do so with confidence.</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2012/01/defining-functions-inline-is-just-fine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Show Duplicate Filenames with Ruby</title>
		<link>http://splatoperator.com/2011/12/show-duplicate-filenames-with-ruby/</link>
		<comments>http://splatoperator.com/2011/12/show-duplicate-filenames-with-ruby/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 01:49:49 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[duplicates]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=344</guid>
		<description><![CDATA[Here&#8217;s a quick one. I want to show just the names of files that have the same basename in a directory. Code require 'find' require 'set' all_files &#160;= &#91;&#93; duplicates = &#123;&#125; basenames &#160;= Set.new ARGV.each do &#124;dir&#124; &#160; Find.find &#8230; <a href="http://splatoperator.com/2011/12/show-duplicate-filenames-with-ruby/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick one. I want to show just the names of files that have the same basename in a directory.</p>

<h2>Code</h2>

<div class="codecolorer-container ruby railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'find'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'set'</span><br />
<br />
all_files &nbsp;= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
duplicates = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
basenames &nbsp;= <span style="color:#CC00FF; font-weight:bold;">Set</span>.<span style="color:#9900CC;">new</span><br />
<br />
ARGV.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>dir<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; <span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">find</span> dir <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; basename = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span> file<br />
&nbsp; &nbsp; all_files <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> file<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">unless</span> basenames.<span style="color:#9900CC;">add</span>? basename<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> duplicates<span style="color:#006600; font-weight:bold;">&#91;</span>basename<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; duplicates<span style="color:#006600; font-weight:bold;">&#91;</span>basename<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> file<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; duplicates<span style="color:#006600; font-weight:bold;">&#91;</span>basename<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>all_files.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span> == basename<span style="color:#006600; font-weight:bold;">&#125;</span>, file<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">puts</span> duplicates.<span style="color:#9900CC;">values</span>.<span style="color:#9900CC;">flatten</span>.<span style="color:#9900CC;">sort_by</span>.<span style="color:#9900CC;">with_index</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f,i<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span>, i<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></div>

<h2>Example</h2>

<p>Here&#8217;s some example terminal interaction.</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">force@zit:/tmp/demo% find . &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.<br />
./Pictures<br />
./Pictures/February<br />
./Pictures/February/family.jpg<br />
./Pictures/February/fruit.jpg<br />
./Pictures/index.html<br />
./Pictures/January<br />
./Pictures/January/car.jpg<br />
./Pictures/January/family.jpg<br />
./Pictures/March<br />
./Pictures/March/dogs.jpg<br />
./Pictures/March/cats.jpg<br />
./Videos<br />
./Videos/Aruba<br />
./Videos/Aruba/scenic.mkv<br />
./Videos/Aruba/water.mkv<br />
./Videos/index.html<br />
./Videos/Grand Canyon<br />
./Videos/Grand Canyon/scenic.mkv<br />
./Videos/Grand Canyon/water.avi<br />
./Videos/Grand Canyon/walls.mkv<br />
<br />
force@zit:/tmp/demo% ruby ~/show_duplicates.rb . &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ./Pictures/February/family.jpg<br />
./Pictures/January/family.jpg<br />
./Pictures/index.html<br />
./Videos/index.html<br />
./Videos/Aruba/scenic.mkv<br />
./Videos/Grand Canyon/scenic.mkv<br />
force@zit:/tmp/demo%</div></div>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2011/12/show-duplicate-filenames-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby instance_eval gotcha</title>
		<link>http://splatoperator.com/2011/11/ruby-instance_eval-gotcha/</link>
		<comments>http://splatoperator.com/2011/11/ruby-instance_eval-gotcha/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 19:56:55 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[blocks]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[instance_eval]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=329</guid>
		<description><![CDATA[I don&#8217;t know how much of a &#8220;gotcha&#8221; this is since it&#8217;s just a defined behavior and feature of the language, but I still found it a little counterintuitive when I encountered it, and I had to actually read the &#8230; <a href="http://splatoperator.com/2011/11/ruby-instance_eval-gotcha/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how much of a &#8220;gotcha&#8221; this is since it&#8217;s just a defined behavior and feature of the language, but I still found it a little counterintuitive when I encountered it, and I had to actually read the source of the Gem I was using to figure out what was going on. Specifically, I was doing this with Sinatra and Mail:</p>

<div class="codecolorer-container ruby railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">get <span style="color:#996600;">'/'</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; <span style="color:#0066ff; font-weight:bold;">@body</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:body</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; Mail.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; to &nbsp; &nbsp; &nbsp;<span style="color:#996600;">'someone@example.com'</span><br />
&nbsp; &nbsp; from &nbsp; &nbsp;<span style="color:#996600;">'me@example.com'</span><br />
&nbsp; &nbsp; subject <span style="color:#996600;">'Gotcha!'</span><br />
&nbsp; &nbsp; body &nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@body</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>

<p>That resulted in an</p>

<div class="codecolorer-container text railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">undefined method `length' for :Mail::Body</div></div>

<p>around that <code>body @body</code> line. Hrm? So I look at the source, and I find that after a bit of wrapping, eventually Mail&#8217;s <code>message.rb</code> is calling this.</p>

<div class="codecolorer-container ruby railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">instance_eval<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span></div></div>

<p>And that&#8217;s how I learned about <a href="http://www.ruby-doc.org/core-1.9.3/BasicObject.html#method-i-instance_eval">instance_eval</a>. It takes a block, then executes that block in the context of the instance which calls it. So it effectively changes any references to <code>self</code> to be the instance where you write it. Therefore, my reference to <code>@body</code> was looking for <code>@body</code> in <code>Message</code> and not in my own app. This will probably be clearer with another example. Say we have these two classes:</p>

<div class="codecolorer-container ruby railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Foo<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> speak<br />
&nbsp; &nbsp; <span style="color:#996600;">'arf!'</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> act <span style="color:#006600; font-weight:bold;">&amp;</span>block<br />
&nbsp; &nbsp; local = <span style="color:#0000FF; font-weight:bold;">true</span><br />
&nbsp; &nbsp; external = <span style="color:#006666;">0</span><br />
&nbsp; &nbsp; instance_eval <span style="color:#006600; font-weight:bold;">&amp;</span>block<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> Bar<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> speak<br />
&nbsp; &nbsp; <span style="color:#996600;">'hello'</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> dizzy?<br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">true</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@name</span> = <span style="color:#996600;">'dirt'</span><br />
&nbsp; &nbsp; age = <span style="color:#006666;">27</span><br />
&nbsp; &nbsp; local = <span style="color:#0000FF; font-weight:bold;">false</span><br />
<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> speak &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># &quot;hello&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> dizzy? &nbsp; <span style="color:#008000; font-style:italic;"># true</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#0066ff; font-weight:bold;">@name</span> &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># &quot;dirt&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> age &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># 27</span><br />
<br />
&nbsp; &nbsp; Foo.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">act</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> speak &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># &quot;arf!&quot; - because we are referring to Foo::speak</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> dizzy? &nbsp; <span style="color:#008000; font-style:italic;"># Runtime error! Foo does not have a dizzy? method!</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#0066ff; font-weight:bold;">@name</span> &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># Runtime error! Foo does not have a @name variable!</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> external <span style="color:#008000; font-style:italic;"># Runtime error! This block doesn't have access to local variables in Foo::act!</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> age &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># 27 &nbsp; &nbsp; - wait...that worked?</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">p</span> local &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># false &nbsp;- This local is used and not the one from Foo::act.</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Bar.<span style="color:#9900CC;">new</span>.<span style="color:#9966CC; font-weight:bold;">do</span></div></div>

<p><strong>Gotcha again!</strong> Your local variables are still passed into the block!</p>

<p>So, <code>instance_eval</code> is why the rest of that block works with the calls to the <code>to</code>, <code>from</code>, and <code>subject</code> methods. Those methods aren&#8217;t defined in my context, and that was my first clue. Those methods <em>are</em> defined in <code>Message</code>&#8216;s context, and <code>instance_eval</code> gives my block access to them, but that instance can now access my local variables (but not my instance variables), and my block cannot access the local variables of the context calling <code>instance_eval</code>.</p>

<p>Whew! I get it now, but it still sounds a bit complicated.</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2011/11/ruby-instance_eval-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Strings: instanceof vs. typeof</title>
		<link>http://splatoperator.com/2011/11/javascript-strings-instanceof-vs-typeof/</link>
		<comments>http://splatoperator.com/2011/11/javascript-strings-instanceof-vs-typeof/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 00:31:15 +0000</pubDate>
		<dc:creator>force</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[ie9]]></category>
		<category><![CDATA[instanceof]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[quirk]]></category>
		<category><![CDATA[savari]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[typeof]]></category>

		<guid isPermaLink="false">http://sidewaysmilk.com/?p=326</guid>
		<description><![CDATA[I&#8217;ve discovered some really interesting (read as &#8220;horrible&#8221;) behavior in Safari 5 and Internet Explorer 9. I was using this with great success in Chrome and Firefox. if &#40;typeof this === 'string'&#41; &#123; &#160; &#160; doStuffWith&#40;this&#41;; &#125; Then I test &#8230; <a href="http://splatoperator.com/2011/11/javascript-strings-instanceof-vs-typeof/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve discovered some really interesting (read as &#8220;horrible&#8221;) behavior in Safari 5 and Internet Explorer 9. I was using this with great success in Chrome and Firefox.</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; doStuffWith<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>

<p>Then I test in IE9, and it doesn&#8217;t work at all. Big surprise. But in Safari, it&#8217;s intermittent! So I start debugging, and I find that Internet Explorer is <em>always</em> returning <code>false</code>. But the weirdest thing is that Safari seems to be doing some kind of optimization in its JavaScript VM where it is <code>true</code> the first time, but <code>false</code> <strong><em>every time you hit reload!</em></strong></p>

<p>My brain almost exploded.</p>

<p>So now I&#8217;ve settled on this:</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span> <span style="color: #000066; font-weight: bold;">instanceof</span> String <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; doStuffWith<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>

<p>And now everything works great. Note that you can call &#8220;a string&#8221;.toString() and it just returns a copy of the string, i.e.</p>

<div class="codecolorer-container javascript railscasts sidewaysmilk" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;a string&quot;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a string&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// true</span></div></div>

<p>So I&#8217;ll be using both from now on.</p>
]]></content:encoded>
			<wfw:commentRss>http://splatoperator.com/2011/11/javascript-strings-instanceof-vs-typeof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

