<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Jonathan's Techno-tales</title>
	<atom:link href="http://technotales.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://technotales.wordpress.com</link>
	<description>no magic - just tricks</description>
	<lastBuildDate>Tue, 10 Nov 2009 13:41:52 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='technotales.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/9a3c43897dfb6d7ef5280b749a4ab653?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Jonathan's Techno-tales</title>
		<link>http://technotales.wordpress.com</link>
	</image>
			<item>
		<title>My dotfiles moved</title>
		<link>http://technotales.wordpress.com/2009/11/10/my-dotfiles-moved/</link>
		<comments>http://technotales.wordpress.com/2009/11/10/my-dotfiles-moved/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 13:40:41 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=415</guid>
		<description><![CDATA[My config files have been on github for quite a while now. However, I named the project etc_config because I store those files in $HOME/etc. I renamed the project to dotfiles. This is both closer to my intent and more in line with what other people are doing.
I changed all the URLs I owned to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=415&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My config files have been on github for quite a while now. However, I named the project <tt>etc_config</tt> because I store those files in <tt>$HOME/etc</tt>. I renamed the project to <a href="http://github.com/jpalardy/dotfiles">dotfiles</a>. This is both closer to my intent and more in line with what other people are doing.</p>
<p>I changed all the URLs I owned to point to the new project … but I don&#8217;t know what else on the github side is broken (watchers, feeds?)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/415/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=415&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/11/10/my-dotfiles-moved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>
	</item>
		<item>
		<title>Rake completion cache</title>
		<link>http://technotales.wordpress.com/2009/09/18/rake-completion-cache/</link>
		<comments>http://technotales.wordpress.com/2009/09/18/rake-completion-cache/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 14:30:03 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=394</guid>
		<description><![CDATA[Rake task completion is awesome. A quick google search will hook you up … (here&#8217;s one)
Rake completion must invoke rake and that can be SLOW. I use completion to save time … What&#8217;s the point on having bash freeze on rake -T for longer than it would take me to type the whole thing?
I took [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=394&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Rake task completion is awesome. A quick google search will hook you up … (here&#8217;s <a href="http://pastie.org/217324">one</a>)</p>
<p>Rake completion must invoke rake and that can be SLOW. I use completion to save time … What&#8217;s the point on having bash freeze on <tt>rake -T</tt> for longer than it would take me to type the whole thing?</p>
<p>I took it upon myself to cache the output of <tt>rake -T</tt> and to use that if it&#8217;s available.</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><span style="background-color:#1c1c1c;"><font color="#5fafd7">export</font></span><span style="background-color:#1c1c1c;"><font color="#afd787">&nbsp;COMP_WORDBREAKS</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">=</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">${</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">COMP_WORDBREAKS</font></span><span style="background-color:#1c1c1c;"><font color="#ff0000">/\:/</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">}</font></span></p>
<p><span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">_check_rakefile() {</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">!</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-e</font></span>&nbsp;Rakefile <span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">return</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span></p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-e</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">.rake_t_cache</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;local <span style="background-color:#1c1c1c;"><font color="#afd787">tasks</font></span>=<span style="background-color:#1c1c1c;"><font color="#d78787">`cat .rake_t_cache </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">|</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&nbsp;awk </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&#8216;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">{print $2}</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&#8216;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">`</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">else</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;local <span style="background-color:#1c1c1c;"><font color="#afd787">tasks</font></span>=<span style="background-color:#1c1c1c;"><font color="#d78787">`rake &#8211;silent -T </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">|</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&nbsp;awk </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&#8216;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">{print $2}</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&#8216;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">`</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span></p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">COMPREPLY</font></span>=<span style="background-color:#1c1c1c;"><font color="#5fafd7">(</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#ff0000">$(</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">compgen -W </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">${</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">tasks</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">}</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&nbsp;&#8211; </font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$2</font></span><span style="background-color:#1c1c1c;"><font color="#ff0000">)</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">)</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
complete <span style="background-color:#1c1c1c;"><font color="#d78787">-F</font></span>&nbsp;_check_rakefile <span style="background-color:#1c1c1c;"><font color="#d78787">-o</font></span>&nbsp;default rake</p>
<p></font></div>
<p>The magic is in the <tt>.rake_t_cache</tt> file. If it&#8217;s there, use it, if not … well … we haven&#8217;t gained/lost anything, the regular completion behavior is still in place.</p>
<p>Where does <tt>.rake_t_cache</tt> come from?</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">rake_cache() {</font></span><br />
&nbsp;&nbsp;rake -T <span style="background-color:#1c1c1c;"><font color="#5fafd7">&gt;</font></span>&nbsp;.rake_t_cache<br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p><span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">rake_cache_clear() {</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-e</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">.rake_t_cache</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;rm .rake_t_cache<br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p></font></div>
<p>I have been thinking about a way to detect when the cache file needs to be regenerated. However, I leave it in the capable hands of the user. All the time saved completing tasks with the cache will compensate for the inevitable time when the cache will be stale and swear words will be required.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/394/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=394&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/09/18/rake-completion-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>
	</item>
		<item>
		<title>Log slicing with grep and sed</title>
		<link>http://technotales.wordpress.com/2009/06/28/log-slicing-with-grep-and-sed/</link>
		<comments>http://technotales.wordpress.com/2009/06/28/log-slicing-with-grep-and-sed/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 17:20:35 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=368</guid>
		<description><![CDATA[I used to work on a Java application that ran 24/7 and logged to a file on the system. The log file was rotated every week and it usually stood around 4GB.
When the shit hit the fan, I checked the log and tried to reverse-engineer how things got so bad. This is similar to what [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=368&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I used to work on a Java application that ran 24/7 and logged to a file on the system. The log file was rotated every week and it usually stood around 4GB.</p>
<p>When the shit hit the fan, I checked the log and tried to reverse-engineer how things got so bad. This is similar to what investigators do with a black box after a plane crash. How do you inspect a 4GB file with a text editor?  You might be surprised to know how far Vim can take you in that direction. I have opened gigabyte-sized files before, and it worked &#8230; for some value of &#8220;worked&#8221;.</p>
<p>Luckily, the log4j format the application used contained the timestamp in <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. It looked something like YYYY-MM-DD hh:mm:ss. Thankfully, this is trivial to parse and guarantees that alphanumeric sorting (read: plain old sorting) will keep the dates in chronological order.</p>
<h2>grep and sed</h2>
<p>I&#8217;ll cover a simpler example and come back to dates later.</p>
<p>(seq might be called gseq on your system)</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace">seq 10000 &gt; 10000.txt</font></div>
<p>This created a 10000-line file with one number, from 1 to 10000, per line. I used this contrived example instead of ISO 8601 formatted dates because it was simple to generate and the relationship between the line number and the line content is obvious.</p>
<p>The next piece of the puzzle is grep. Grep has the <tt>-n/--line-number</tt> flag to &#8220;prefix each line of output with the line number&#8221;.</p>
<p>We&#8217;re going to extract from the line containing 444 to the line containing 2000. Of course, we <em>know</em> what those line numbers are because of how we generated this file. This is usually not the case.</p>
<p><img src="http://mps.s3.amazonaws.com/images/log_slicing/grep_444_too_much.png" alt="too much" /></p>
<p>Right, we want the first match&#8230; Part of the solution is to use a tighter regular expression. Also, and the reason I did this, is to realize that the file will keep being parsed <em>after</em> the first match is found. On huge files, waiting for grep to finish is both time-consuming and unnecessary.</p>
<p>The <tt>-m NUM/--max-count=NUM</tt> flag will &#8220;stop reading a file after NUM matching lines.&#8221;</p>
<p><img src="http://mps.s3.amazonaws.com/images/log_slicing/grep_444_just_right.png" alt="444 - just right" /></p>
<p><img src="http://mps.s3.amazonaws.com/images/log_slicing/grep_2000_just_right.png" alt="2000 - just right" /></p>
<p>Combining the line numbers, we can slice the log with sed:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace">sed -n &#8216;444,2000p&#8217; 10000.txt</font></div>
<h2>Discussion</h2>
<p>Why not skip grep and just RTF sed manual?</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace">sed -n &#8216;/^444$/,/^2000$/p&#8217; 10000.txt</font></div>
<p>My reason: I want to visually confirm that my regular expressions matched the right lines. The time I would have saved bypassing grep would be wasted the first time I would open a file which didn&#8217;t contain what I really wanted.</p>
<p>Why not just grep for timestamp and use that?</p>
<p>That&#8217;s a subtle point. The log files contained YYYY-MM-DD hh:mm:ss at the beginning of almost every line.</p>
<p>Initially, I tried:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace">grep &#8216;^2009-06-28 04:&#8217; log.file</font></div>
<p>To get the log lines between 4am and 5am on a specific date.</p>
<p>This was simple to understand and explain, and it worked beautifully until we realized that it was <strong><em>almost</em></strong> every line &#8230; it was missing the stack traces. It was also missing, although rare in that application, other multi-line log messages.</p>
<p>So, I used:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace">grep -m 1 -n &#8216;^2009-06-28 04:&#8217; log.file<br />
grep -m 1 -n &#8216;^2009-06-28 05:&#8217; log.file<br />
</font></div>
<p>and used sed to extract the lines in-between.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/368/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/368/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/368/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=368&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/06/28/log-slicing-with-grep-and-sed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/log_slicing/grep_444_too_much.png" medium="image">
			<media:title type="html">too much</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/log_slicing/grep_444_just_right.png" medium="image">
			<media:title type="html">444 - just right</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/log_slicing/grep_2000_just_right.png" medium="image">
			<media:title type="html">2000 - just right</media:title>
		</media:content>
	</item>
		<item>
		<title>JSLint with SpiderMonkey</title>
		<link>http://technotales.wordpress.com/2009/06/21/jslint-with-spidermonkey/</link>
		<comments>http://technotales.wordpress.com/2009/06/21/jslint-with-spidermonkey/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 01:16:05 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=351</guid>
		<description><![CDATA[I&#8217;ve talked about SpiderMonkey before. Being able to instantly evaluate JavaScript code is great but you can use FireBug for that. I argued that the main reason to use SpiderMonkey is to script the command-line. Integrating with JSLint is an example of using your tools intelligently.
JSLint
JSLint is a tool that &#8220;looks for problems in JavaScript [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=351&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve talked about <a href="http://en.wikipedia.org/wiki/SpiderMonkey_(JavaScript_engine)">SpiderMonkey</a> <a href="http://technotales.wordpress.com/2009/06/07/spidermonkey-introduction/">before</a>. Being able to instantly evaluate JavaScript code is great but you can use <a href="http://getfirebug.com/">FireBug</a> for that. I argued that the main reason to use SpiderMonkey is to script the command-line. Integrating with JSLint is an example of using your tools intelligently.</p>
<h2>JSLint</h2>
<p><a href="http://www.jslint.com/">JSLint</a> is a tool that &#8220;looks for problems in JavaScript programs&#8221;. Here&#8217;s a list of things JSLint looks for (<a href="http://www.JSLint.com/lint.html">full list</a>):</p>
<ul>
<li>missing semicolons</li>
<li>missing curly braces ({})</li>
<li>the use of <tt>with</tt></li>
<li>the unfiltered use of <tt>for in</tt></li>
<li>the use of <tt>eval</tt></li>
<li>the implicit use of global variables</li>
<li>missing <tt>break</tt> statements</li>
<li>double <tt>var</tt> definitions</li>
<li>the appropriate use of <tt>=</tt> and <tt>==</tt> and <tt>===</tt></li>
<li>unreachable code</li>
</ul>
<p>JSLint is just a way to check your code. However, JSLint, as it stands, is a textarea on the web:</p>
<p><img src="http://mps.s3.amazonaws.com/images/jslint/textarea.png" alt="textarea" /></p>
<p>Every time you edit your code, do you want to go jslint.com, paste only the relevant portion of your code, fix the errors locally, rinse and repeat? Anything that causes friction won&#8217;t get done. Let&#8217;s minimize that.</p>
<h2>With SpiderMonkey</h2>
<p>As it turns out, JSLint <strong><em>is</em></strong> a JavaScript program that parses JavaScript (!). Knowing that you can evaluate JavaScript on the command-line with SpiderMonkey, you have all the ingredients you need to automate the process.</p>
<p>Most of the solution is <a href="http://whereisandy.com/code/jslint/">here</a>. Look for this button: (<a href="http://whereisandy.com/code/jslint/jslint">direct link</a>)</p>
<p><img src="http://mps.s3.amazonaws.com/images/jslint/download_button.png" alt="button" /></p>
<p>I renamed the file to <tt>jslint.js</tt> and put it in <tt>~/etc/bin</tt>. I then created a shell script to script the process:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><span style="background-color:#1c1c1c;"><font color="#808080">#!/bin/sh</font></span></p>
<p><span style="background-color:#1c1c1c;"><font color="#afd787">filename</font></span>=<span style="background-color:#1c1c1c;"><font color="#d7afd7">${</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">1</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">:?</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">jslint filename</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">}</font></span></p>
<p>js <span style="background-color:#1c1c1c;"><font color="#d78787">-f</font></span>&nbsp;~/etc/bin/jslint.js <span style="background-color:#1c1c1c;"><font color="#5fafd7">&lt;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7afd7">$filename</font></span></p>
<p></font></div>
<p>I named it <tt>~/etc/bin/jslint</tt> (chmod +x).</p>
<h2>Stupid Example</h2>
<p>Let&#8217;s take a stupid example: (stupid.js)</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;stupid(x)&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">{</font></span><br />
&nbsp;&nbsp;y = x</p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if</font></span>(y == 0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">return</font></span>&nbsp;5<br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p></font></div>
<p>What&#8217;s wrong with this? Plenty:</p>
<p><img src="http://mps.s3.amazonaws.com/images/jslint/output_jslint.png" alt="output of jslint" /><br />
After the fixes:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;stupid(x)&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">{</font></span><br />
&nbsp;&nbsp;y = x;</p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if</font></span>(y === 0)&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">{</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">return</font></span>&nbsp;5;<br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p></font></div>
<p>JSLint is just one tool. Let&#8217;s run this code through SpiderMonkey&#8217;s strict mode:</p>
<p><img src="http://mps.s3.amazonaws.com/images/jslint/output_js_strict.png" alt="output of SpiderMonkey's strict mode" /></p>
<p>And this is for a trivial 7-line function. Running JSLint on hundreds of lines of code can be sobering experience. There&#8217;s even a warning on the site:</p>
<p><img src="http://mps.s3.amazonaws.com/images/jslint/warning.png" alt="jslint warning" /></p>
<p>Seriously. As you become better with JavaScript and regularly check your code against JSLint (as a formality, of course), there seems to be no end to how nitpicky JSLint can be.</p>
<p>Finally, you can configure what JSLint will complain about by putting a specially-formatted comment in your file:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><span style="background-color:#1c1c1c;"><font color="#808080">/*jslint bitwise: true, undef: true */</font></span></p>
<p><span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;stupid(x)&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">{</font></span><br />
&nbsp;&nbsp;y = x;</p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if</font></span>(y === 0)&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">{</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">return</font></span>&nbsp;5;<br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p></font></div>
<p>The <tt>undef</tt> option will make JSLint complain about using the global variable <tt>y</tt> which definitely <em>looks</em> like a mistake.</p>
<p>The full list of options is available <a href="http://www.JSLint.com/lint.html#options">here</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/351/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/351/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/351/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/351/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/351/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/351/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/351/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/351/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/351/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/351/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=351&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/06/21/jslint-with-spidermonkey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/jslint/textarea.png" medium="image">
			<media:title type="html">textarea</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/jslint/download_button.png" medium="image">
			<media:title type="html">button</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/jslint/output_jslint.png" medium="image">
			<media:title type="html">output of jslint</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/jslint/output_js_strict.png" medium="image">
			<media:title type="html">output of SpiderMonkey's strict mode</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/jslint/warning.png" medium="image">
			<media:title type="html">jslint warning</media:title>
		</media:content>
	</item>
		<item>
		<title>Netcat tricks</title>
		<link>http://technotales.wordpress.com/2009/06/14/netcat-tricks/</link>
		<comments>http://technotales.wordpress.com/2009/06/14/netcat-tricks/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 23:49:37 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=340</guid>
		<description><![CDATA[Web development means working at a very high level of abstraction. For the magic to work, a multitude of technologies must also work: networks, sockets, HTTP. Like all leaky abstractions, however, we can sidestep a lot of the complexity until things stop working.
Netcat does exactly what its name says: it cats stuff over a network. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=340&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Web development means working at a very high level of abstraction. For the magic to work, a multitude of technologies must also work: networks, sockets, HTTP. Like all <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">leaky abstractions</a>, however, we can sidestep a lot of the complexity <em>until</em> things stop working.</p>
<p>Netcat does exactly what its name says: it cats stuff over a network. It can send or receive bytes over the network.</p>
<h2>File transfer</h2>
<p>client:</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/nc_send.png" alt="nc send" /></p>
<p>server:</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/nc_receive.png" alt="nc receive" /></p>
<p>This is probably one of the fastest and most casual way to transfer a file between two systems. Nothing (besides nc) needs to be installed, no authentication or encryption is performed.</p>
<p>I would reserve this use of netcat for post-apocalyptic server crashes where you need to transfer files but nothing is installed and zombies are about to come crashing in.</p>
<p>More realistically &#8230;</p>
<h2>HTTP tricks</h2>
<p>Let&#8217;s spy on safari:</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/safari_request.png" alt="safari request" /></p>
<p>This will happen after you try to open <tt>localhost:9999</tt> in a browser. You can see all the headers, in the raw form. This is one level above using a packet sniffer like <a href="http://www.wireshark.org/">wireshark</a></p>
<p>Let&#8217;s save the request: (you&#8217;ll have to open <tt>localhost:9999</tt> again)</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/safari_request_file.png" alt="safari request file" /></p>
<p>Feed the request to google.com (or you own web server)</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/google_response_file.png" alt="google response file" /></p>
<p>Have a look at the raw request: (vim response)</p>
<p><img src="https://mps.s3.amazonaws.com/images/netcat/google_response_details.png" alt="google response details" /></p>
<p>Yeah, it&#8217;s gzip compressed. More interestingly, we can use this to mock google:</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/mocking_google.png" alt="mocking google" /></p>
<p>Open <tt>localhost:9999</tt> in a browser, get served, byte-for-byte, what google would have served you.</p>
<p>You can use the <tt>-k</tt> flag to keep the connection open after the file is served:</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/mocking_google_keep.png" alt="mocking google keep" /></p>
<p>This will show you the subsequent requests (images, javascript, css)</p>
<p>Finally, you might want to serve the file more than once:</p>
<p><img src="http://mps.s3.amazonaws.com/images/netcat/mocking_google_repeatedly.png" alt="mocking google repeatedly" /></p>
<h2>Discussion</h2>
<p>I&#8217;ve used netcat in the past to debug gzip compression on nginx and lighttpd. With browsers and curl/wget all doing-the-right-thing with/without gzip compression, how can you really tell if it&#8217;s enabled or not?</p>
<p>You can also use it to spoof requests. Both a request or a response file can be trivially changed whereas the same effect could sometimes be achieved by making significant and/or time-consuming configuration changes to your setup.</p>
<p>Of course, this is not limited to HTTP. Extend the ideas here to fit your life.</p>
<p>Netcat is not the ultimate-solution™. It is called the hacker&#8217;s <a href="http://m.nu/program/util/netcat/netcat.html">swiss army knife</a>. It&#8217;s the kind of program you don&#8217;t need until you <strong><em>really</em></strong> do.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/340/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=340&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/06/14/netcat-tricks/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/nc_send.png" medium="image">
			<media:title type="html">nc send</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/nc_receive.png" medium="image">
			<media:title type="html">nc receive</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/safari_request.png" medium="image">
			<media:title type="html">safari request</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/safari_request_file.png" medium="image">
			<media:title type="html">safari request file</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/google_response_file.png" medium="image">
			<media:title type="html">google response file</media:title>
		</media:content>

		<media:content url="//mps.s3.amazonaws.com/images/netcat/google_response_details.png" medium="image">
			<media:title type="html">google response details</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/mocking_google.png" medium="image">
			<media:title type="html">mocking google</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/mocking_google_keep.png" medium="image">
			<media:title type="html">mocking google keep</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/netcat/mocking_google_repeatedly.png" medium="image">
			<media:title type="html">mocking google repeatedly</media:title>
		</media:content>
	</item>
		<item>
		<title>SpiderMonkey Introduction</title>
		<link>http://technotales.wordpress.com/2009/06/07/spidermonkey-introduction/</link>
		<comments>http://technotales.wordpress.com/2009/06/07/spidermonkey-introduction/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 14:51:09 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=332</guid>
		<description><![CDATA[Lately, I&#8217;ve been working on JavaScript stuff at work. When it comes to JavaScript debugging, Firebug can take you a long way. Firebug is not, however, a very scriptable environment.
SpideMonkey is &#8220;Gecko&#8217;s JavaScript engine written in C&#8221;. For our purposes, SpiderMonkey is a command-line tool to execute JavaScript.
You can build it from source or look [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=332&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Lately, I&#8217;ve been working on JavaScript stuff at work. When it comes to JavaScript debugging, Firebug can take you a long way. Firebug is not, however, a very scriptable environment.</p>
<p><a href="https://developer.mozilla.org/en/SpiderMonkey">SpideMonkey</a> is &#8220;Gecko&#8217;s JavaScript engine written in C&#8221;. For our purposes, SpiderMonkey is a command-line tool to execute JavaScript.</p>
<p>You can <a href="https://developer.mozilla.org/En/SpiderMonkey/Build_Documentation">build it from source</a> or look for it in your system&#8217;s package manager.</p>
<p><img src="http://mps.s3.amazonaws.com/images/js_port_search.png" alt="spidermonkey in port" /></p>
<p>Before I continue, SpiderMonkey defines a few functions which are useful for non-browser environments. In the following examples, I&#8217;ll be using the <tt>print</tt> function which outputs a string to STDOUT.</p>
<p>Interactive mode:</p>
<p><img src="http://mps.s3.amazonaws.com/images/js_interactive.png" alt="spidermonkey, interactive mode" /></p>
<p>Execute (-e) mode:</p>
<p><img src="http://mps.s3.amazonaws.com/images/js_execute.png" alt="spidermonkey, execute mode" /></p>
<p>File (-f) mode:</p>
<p><img src="http://mps.s3.amazonaws.com/images/js_file.png" alt="spidermonkey, file mode" /></p>
<p>File (-f) mode (multiple files):</p>
<p><img src="http://mps.s3.amazonaws.com/images/js_multiple_files.png" alt="spidermonkey, file mode, multiple files" /></p>
<p>Combined mode:</p>
<p><img src="http://mps.s3.amazonaws.com/images/js_file_interactive.png" alt="spidermonkey, file and interactive mode" /></p>
<p>Apart from &#8220;print&#8221;, there are other useful functions:</p>
<pre>
Command        Usage                  Description
=======        =====                  ===========
load           load(['foo.js' ...])   Load files named by string arguments
readline       readline()             Read a single line from stdin
print          print([exp ...])       Evaluate and print expressions
help           help([name ...])       Display usage and help messages
quit           quit()                 Quit the shell
clear          clear([obj])           Clear properties of object
</pre>
<p>This is an abridged version of the available functions, <a href="https://developer.mozilla.org/en/SpiderMonkey/Shell_global_objects">here&#8217;s the full one</a>.</p>
<p>The ability to import other files (load), read from STDIN (readline), output messages (print), and quit are exactly what&#8217;s needed for scripting. In fact, while I was googling for SpiderMonkey, I found this <a href="http://peter.michaux.ca/articles/cgi-hello-js">post</a> which used SpiderMonkey as a primitive CGI script.</p>
<p>More realistically, because SpiderMonkey is MUCH faster to startup than Rhino, you can include it in a command-line workflow to <a href="http://jsunit.berlios.de/">unit test</a> or <a href="http://whereisandy.com/code/jslint/">lint</a> your JavaScript.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/332/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/332/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/332/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=332&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/06/07/spidermonkey-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/js_port_search.png" medium="image">
			<media:title type="html">spidermonkey in port</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/js_interactive.png" medium="image">
			<media:title type="html">spidermonkey, interactive mode</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/js_execute.png" medium="image">
			<media:title type="html">spidermonkey, execute mode</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/js_file.png" medium="image">
			<media:title type="html">spidermonkey, file mode</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/js_multiple_files.png" medium="image">
			<media:title type="html">spidermonkey, file mode, multiple files</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/js_file_interactive.png" medium="image">
			<media:title type="html">spidermonkey, file and interactive mode</media:title>
		</media:content>
	</item>
		<item>
		<title>Vim as a List Picker</title>
		<link>http://technotales.wordpress.com/2009/05/31/vim-as-a-list-picker/</link>
		<comments>http://technotales.wordpress.com/2009/05/31/vim-as-a-list-picker/#comments</comments>
		<pubDate>Sun, 31 May 2009 23:26:15 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=310</guid>
		<description><![CDATA[I think I already established that Vim makes an excellent pager. Let me take it one step further: Vim is a customizable, programmable pager. (!)
There are plenty of cases where you want to pick one (1) thing out of a list. Vim can easily be made into a list picker.
A few examples

pick a deep directory [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=310&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I think I already established that <a href="http://technotales.wordpress.com/2009/05/24/using-vim-as-a-pager/">Vim makes an excellent pager</a>. Let me take it one step further: Vim is a customizable, programmable pager. (!)</p>
<p>There are plenty of cases where you want to pick one (1) thing out of a list. Vim can easily be made into a list picker.</p>
<h2>A few examples</h2>
<ul>
<li>pick a deep directory under the current directory (pick from <tt>find . -type d</tt>)</li>
<li>pick a <span class="caps">GNU</span> screen session out of many (pick from <tt>screen -ls</tt>)</li>
<li>pick a process to kill (pick from <tt>ps</tt>)</li>
</ul>
<p>There are basically 2 components to these examples:</p>
<ul>
<li>what command will generate the list</li>
<li>what command to run on the selection</li>
</ul>
<h2>The Code</h2>
<p>Here&#8217;s the PickerMode plugin (put in <tt>~/.vim/plugin/picker.vim</tt>)</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#5fafd7">function</font></span>&nbsp;PickerMode<span style="background-color:#1c1c1c;"><font color="#5fafd7">()</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">set</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7afd7">cursorline</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">nmap</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d78787">&lt;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">buffer</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&gt;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d78787">&lt;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">CR</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&gt;</font></span>&nbsp;&nbsp;&nbsp;&nbsp;V:w! ~/.picked<span style="background-color:#1c1c1c;"><font color="#d78787">&lt;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">CR</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&gt;</font></span>:qa!<span style="background-color:#1c1c1c;"><font color="#d78787">&lt;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">CR</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">&gt;</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#5fafd7">endfunction</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#5fafd7">command</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">nargs</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">=</font></span><span style="background-color:#1c1c1c;"><font color="#afafd7">0</font></span>&nbsp;PickerMode&nbsp;:<span style="background-color:#1c1c1c;"><font color="#5fafd7">call</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d0d0d0">PickerMode</font></span>()<br />
<span style="background-color:#1c1c1c;"><br />
</font></div>
<p>Comments:</p>
<ul>
<li><tt>cursorline</tt> highlight the line the cursor is on</li>
<li><tt>return</tt> saves the current line to <tt>~/.picked</tt></li>
</ul>
<p>Here&#8217;s the bash code to invoke vim and execute a command on the selection:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#808080"># start vim in PAGER mode, with PickerMode plugin</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">vim_picker() {</font></span><br />
&nbsp;&nbsp;vim -c <span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">PickerMode</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;-R -<br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p><span style="background-color:#1c1c1c;"><font color="#808080"># 1st parameter is command to generate a list</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#808080"># 2nd parameter is command to run on selection</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#808080"># 3rd (optional) parameter is DIRECT selection, bypassing VIM</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">pick_with_vim() {</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-e</font></span>&nbsp;~/.picked <span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;rm ~/.picked<br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span></p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-n</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$3</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">eval</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$1</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">|</font></span>&nbsp;sed <span style="background-color:#1c1c1c;"><font color="#5fafd7">-n</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7afd7">$3</font></span>p <span style="background-color:#1c1c1c;"><font color="#5fafd7">&gt;</font></span>&nbsp;~/.picked<br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">else</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">eval</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$1</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">|</font></span>&nbsp;vim_picker<br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span></p>
<p>&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-e</font></span>&nbsp;~/.picked <span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7afd7">$2</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d78787">`cat ~/.picked`</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
</font></div>
<p>Comments:</p>
<ul>
<li>the selection is written to a file called <tt>~/.picked</tt></li>
<li>the existence of the file <tt>~/.picked</tt> proves that you selected something</li>
<li>functional programming in bash (!)</li>
</ul>
<h2>Using <tt>pick_with_vim</tt></h2>
<p>pick a deep directory under the current directory:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#808080"># pick from a list of directories (recursive) and cd into it</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">c() {</font></span><br />
&nbsp;&nbsp;pick_with_vim <span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">find . -type d</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">cd</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
</font></div>
<p>how to pick from screen:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">screen_r_x() {</font></span><br />
&nbsp;&nbsp;screen -r <span style="background-color:#1c1c1c;"><font color="#d7afd7">$1</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">||</font></span>&nbsp;screen -x <span style="background-color:#1c1c1c;"><font color="#d7afd7">$1</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span></p>
<p><span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">sc() {</font></span><br />
&nbsp;&nbsp;pick_with_vim <span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">screen -ls | awk &#8216;/^\t</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">/ {print </font></span><span style="background-color:#1c1c1c;"><font color="#d78787">\$</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">1}&#8217;</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">screen_r_x</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
</font></div>
<p>Here&#8217;s a much simpler rewrite of &#8220;go&#8221; (<a href="http://technotales.wordpress.com/2007/08/09/bookmark-your-directories-introducing-go/">my directory bookmark miniapp</a>)</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:10px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#808080"># pick from directories in $HOME/.gorc and cd into it</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">go() {</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">if </font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">[</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">!</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">-f</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7afd7">$HOME</font></span>/.gorc <span style="background-color:#1c1c1c;"><font color="#5fafd7">]</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">then</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">echo</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">&nbsp;</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$HOME</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">/.gorc does not exist&#8230;</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">return</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7af87">1</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">fi</font></span></p>
<p>&nbsp;&nbsp;pick_with_vim <span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">cat </font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$HOME</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">/.gorc</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7d7af">cd</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#d7afd7">$1</font></span><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
</font></div>
<h2>What now?</h2>
<p>This code is available as part of my dotfiles on <a href="http://github.com/jpalardy/dotfiles/tree/master">github</a>. (though it is mixed with the rest)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=310&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/05/31/vim-as-a-list-picker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>
	</item>
		<item>
		<title>Using vim as a pager</title>
		<link>http://technotales.wordpress.com/2009/05/24/using-vim-as-a-pager/</link>
		<comments>http://technotales.wordpress.com/2009/05/24/using-vim-as-a-pager/#comments</comments>
		<pubDate>Sun, 24 May 2009 14:52:34 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[cli]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=300</guid>
		<description><![CDATA[I&#8217;ve talked casually about using Vim as a pager before. However, I&#8217;m still surprised to see how many people use Vim regularly and don&#8217;t know about this feature.
Here&#8217;s a quote straight from vim --help

vim [arguments] -               read text from stdin


Admittedly, it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=300&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve talked casually about using Vim as a pager <a href="http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/">before</a>. However, I&#8217;m still surprised to see how many people use Vim regularly and don&#8217;t know about this feature.</p>
<p>Here&#8217;s a quote straight from <tt>vim --help</tt></p>
<blockquote><pre>
vim [arguments] -               read text from stdin
</pre>
</blockquote>
<p>Admittedly, it&#8217;s easy to overlook the hyphen in the explanation.</p>
<p><img src="http://mps.s3.amazonaws.com/images/vim_hyphen.png" alt="vim hyphen" /></p>
<h2>Why Vim as a Pager?</h2>
<p>If you&#8217;re using Vim already, there&#8217;s nothing else to install.</p>
<p>If you&#8217;re using Vim already, it&#8217;s already configured the way you like it.</p>
<p>More importanly, Vim detects the kind of file it is being piped and turns on the appropriate syntax highlighting. Why page in black and white? In this case, &#8220;less&#8221; is definitely less!</p>
<h2>Improving the experience</h2>
<p>As a pager, you want to use Vim in read-only mode.</p>
<p><code>
<pre>
some command | vim -R -
</pre>
<p></code></p>
<p>What the difference? Vim doesn&#8217;t ask you to save the file if you try to quit. Of course, you can still modify and write the file &#8230; the -R flag is just a more reasonable pager default.</p>
<h2>PAGER variable and ANSI Escape Sequences</h2>
<p>You <em>probably</em> don&#8217;t want to set the PAGER variable. Vim doesn&#8217;t understand ANSI escape sequences. As such, a command like &#8220;man vim | vim -R -&#8221; won&#8217;t show colors; it will show escape sequences.</p>
<p><img src="http://mps.s3.amazonaws.com/images/vim_and_ansi.png" alt="vim and ansi" /></p>
<p>I haven&#8217;t found any quick and simple solution to make Vim show ANSI escape sequences, but it&#8217;s pretty easy to strip them out <em>before</em> passing the file to Vim:</p>
<p><code>
<pre>
man vim | col -b | vim -R -
</pre>
<p></code></p>
<p>I use <tt>less</tt> as <tt>PAGER</tt>. I use vim in explicit cases.</p>
<h2>View</h2>
<p>The <tt>view</tt> command gets installed at the same time as vim. It&#8217;s just a symlink to vim. Using <tt>view</tt> is exactly like typing <tt>vim -R</tt>.</p>
<p>There&#8217;s a certain aesthetic in:</p>
<p><code>
<pre>
some command | view -
</pre>
<p></code></p>
<p>But I find that typing <tt>vim -R -</tt> is easier on my finger&#8217;s muscle memory.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=300&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/05/24/using-vim-as-a-pager/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/vim_hyphen.png" medium="image">
			<media:title type="html">vim hyphen</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/vim_and_ansi.png" medium="image">
			<media:title type="html">vim and ansi</media:title>
		</media:content>
	</item>
		<item>
		<title>Git Diff with Vimdiff</title>
		<link>http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/</link>
		<comments>http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/#comments</comments>
		<pubDate>Sun, 17 May 2009 15:18:25 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=282</guid>
		<description><![CDATA[What happens when you type git diff? As with all interesting questions, the answer is &#8220;it depends…&#8221;
Here&#8217;s one thing you want git to do:

Vimdiff!
Step 1: add this to your .gitconfig

[diff]
&#160;&#160;external&#160;=                 git_diff_wrapper
[pager]
&#160;&#160;diff&#160;=

Step 2: create a file named git_diff_wrapper, put it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=282&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>What happens when you type <tt>git diff</tt>? As with all interesting questions, the answer is &#8220;it depends…&#8221;</p>
<p>Here&#8217;s one thing you want git to do:<br />
<img alt="" src="http://mps.s3.amazonaws.com/images/vimdiff.jpg" title="vimdiff" class="alignnone" width="350" height="219" /></p>
<p>Vimdiff!</p>
<p>Step 1: add this to your <tt>.gitconfig</tt></p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:0 10px 20px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#5fafd7">[diff]</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">external</font></span>&nbsp;=                 git_diff_wrapper<br />
<span style="background-color:#1c1c1c;"><font color="#5fafd7">[pager]</font></span><br />
&nbsp;&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">diff</font></span>&nbsp;=<br />
</font></div>
<p>Step 2: create a file named <tt>git_diff_wrapper</tt>, put it somewhere in your $PATH</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:0 10px 20px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#808080">#!/bin/sh</font></span></p>
<p>vimdiff <span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$2</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$5</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span></p>
<p></font></div>
<p>I still have access to the default <tt>git diff</tt> behavior with the <tt>&#45;&#45;no-ext-diff</tt> flag. Here&#8217;s a function I put in my bash configuration files:</p>
<div style="background:#1c1c1c;color:#d0d0d0;font-size:120%;padding:0 10px 20px;"><font face="monospace"><br />
<span style="background-color:#1c1c1c;"><font color="#afd787">function</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#afd787">git_diff() {</font></span><br />
&nbsp;&nbsp;git diff &#45;&#45;no-ext-diff -w <span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span><span style="background-color:#1c1c1c;"><font color="#d7afd7">$@</font></span><span style="background-color:#1c1c1c;"><font color="#5fafd7">&quot;</font></span>&nbsp;<span style="background-color:#1c1c1c;"><font color="#5fafd7">|</font></span>&nbsp;vim -R -<br />
<span style="background-color:#1c1c1c;"><font color="#afd787">}</font></span><br />
</font></div>
<ul>
<li>&#45;&#45;no-ext-diff : to prevent using vimdiff</li>
<li>-w : to ignore whitespace</li>
<li>-R : to start vim in read-only mode</li>
<li>- : to make vim act as a pager</li>
</ul>
<p>When it comes to vimdiff, you can get started with <a href="http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html">this tutorial</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=282&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://mps.s3.amazonaws.com/images/vimdiff.jpg" medium="image">
			<media:title type="html">vimdiff</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Tetris</title>
		<link>http://technotales.wordpress.com/2009/05/10/code-tetris/</link>
		<comments>http://technotales.wordpress.com/2009/05/10/code-tetris/#comments</comments>
		<pubDate>Sun, 10 May 2009 22:37:50 +0000</pubDate>
		<dc:creator>Jonathan Palardy</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://technotales.wordpress.com/?p=265</guid>
		<description><![CDATA[&#8220;How did we get into this mess?&#8221; you exclaim looking at the code equivalent of:

There are a lot of reasons why projects end up looking like that. Beyond incompetence, there is the realization that you know more about a problem after you solve it.
Here&#8217;s a familiar scenario:
You extract an ugly part of a function. Out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=265&subd=technotales&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8220;How did we get into this mess?&#8221; you exclaim looking at the code equivalent of:</p>
<p><img class="aligncenter size-full wp-image-268" title="tetris mess" src="http://technotales.files.wordpress.com/2009/05/mess.png?w=276&#038;h=544" alt="tetris mess" width="276" height="544" /></p>
<p>There are a lot of reasons why projects end up looking like that. Beyond incompetence, there is the realization that you know more about a problem <em>after</em> you solve it.</p>
<p>Here&#8217;s a familiar scenario:</p>
<p>You extract an ugly part of a function. Out of the remaining code, you notice that it&#8217;s just a special case of a problem you have solved in a more general way elsewhere. A few tweaks later, you remove the special case, a whole bunch of code is gone.</p>
<p>The &#8220;Tetris&#8221; effect!</p>
<p>A good refactor feels the same way it does when you clear a couple of rows in Tetris. There <em>are</em> insights which allow you to provide the same (if not more) functionality in less code.</p>
<p>I remember reading <a href="http://www.amazon.com/gp/product/0201485672">Refactoring</a> and being annoyed at the series of seemingly trivial changes that were being done to the code. However, one change at a time, the code was getting more and more manageable.</p>
<p>The same is true with Tetris: clearing the first row of block, you can start attacking the second and so forth. Hopefully you reach to bottom.</p>
<p>Which brings another interesting parallel with Tetris: if you don&#8217;t start simplifying things and cleaning up your mess, you end up with a big pile of unmanageable code. One block goes on top of another until you touch the top. Eventually, you have to start another game.</p>
<p>Compare that to incoming requirements which result in more features piling on top of each other. At some point, somebody starts talking about doing a rewrite. In effect, that would be like restarting the game. It&#8217;s always easier to throw blocks down an empty screen rather than fit them on top of an existing mess.</p>
<p>I&#8217;m not blaming anyone &#8230; there is a time and place for rewrites. Use judgment.</p>
<p>Can you also think of a time where a new requirement messed up the beauty of the model you had built. Something like this?<br />
<img class="aligncenter size-full wp-image-271" title="tetrishappens" src="http://technotales.files.wordpress.com/2009/05/tetrishappens.jpg?w=263&#038;h=436" alt="tetrishappens" width="263" height="436" /></p>
<p>The more I think about it, the more I like it.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/technotales.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/technotales.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/technotales.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/technotales.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/technotales.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/technotales.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/technotales.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/technotales.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/technotales.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/technotales.wordpress.com/265/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=technotales.wordpress.com&blog=761277&post=265&subd=technotales&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://technotales.wordpress.com/2009/05/10/code-tetris/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ecfd1bdc5d3aab1e40f25658817712ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jpalardy</media:title>
		</media:content>

		<media:content url="http://technotales.files.wordpress.com/2009/05/mess.png" medium="image">
			<media:title type="html">tetris mess</media:title>
		</media:content>

		<media:content url="http://technotales.files.wordpress.com/2009/05/tetrishappens.jpg" medium="image">
			<media:title type="html">tetrishappens</media:title>
		</media:content>
	</item>
	</channel>
</rss>