<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Code in the hole (Entries tagged as commandlinefu)</title>
    <link>http://codeinthehole.com/</link>
    <description>David Winterbottom</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    
    

<item>
    <title>Auto-generating an FAQ with Prototype</title>
    <link>http://codeinthehole.com/archives/28-Auto-generating-an-FAQ-with-Prototype.html</link>
            <category>Tidbits</category>
    
    <comments>http://codeinthehole.com/archives/28-Auto-generating-an-FAQ-with-Prototype.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=28</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=28</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;p&gt;Have just been writing an FAQ page for &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.commandlinefu.com&#039;);&quot;  href=&quot;http://www.commandlinefu.com&quot;&gt;commandlinefu.com&lt;/a&gt;.  Documenting is always tiresome, but FAQs particularly so when hand-coding the HTML links between each question and the summary table at the top of the page.&lt;/p&gt;
&lt;p&gt;Javascript to the rescue: I cobbled together a quick Prototype script which automatically generates the FAQ summary links by parsing the DOM for the appropriate links:&lt;/p&gt;
&lt;code class=&quot;prettyprint&quot;&gt;document.observe(&#039;dom:loaded&#039;, function(){
    $$(&#039;a.question&#039;).each(function(ele){
        var id = ele.innerHTML.unescapeHTML().gsub(/[^\w- ]/, &#039;&#039;).gsub(/[\s-]+/, &#039;-&#039;).toLowerCase();
        ele.writeAttribute({id: id});
        var link = new Element(&#039;a&#039;, {href: &#039;#&#039;+id})
            .update(ele.innerHTML)
            .observe(&#039;click&#039;, function(event){
                event.stop();
                Effect.ScrollTo(ele); 
            });
        $(&#039;questions&#039;).insert(new Element(&#039;li&#039;).insert(link));
    });
});&lt;/code&gt;
&lt;p&gt;Now, all I have to do is write my FAQ ensuring the questions live in anchor tags with the class &quot;question&quot; and there is an empty list tag at the top of the page to house the summary block.&lt;/p&gt;
&lt;p&gt;Here&#039;s two snapshots the relevant section of the DOM before and after the &lt;code&gt;dom:loaded&lt;/code&gt; event has fired.  Before:&lt;/p&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&amp;lt;ul id=&quot;questions&quot;&gt;&amp;lt;/ul&gt;
&amp;lt;dl&gt;
    &amp;lt;dt&gt;&amp;lt;a class=&quot;question&quot;&gt;What is this site?&amp;lt;/a&gt;&amp;lt;/dt&gt;
    &amp;lt;dd&gt;...&amp;lt;/dd&gt;
    &amp;lt;dt&gt;&amp;lt;a class=&quot;question&quot;&gt;Who created this site?&amp;lt;/a&gt;&amp;lt;/dt&gt;
    &amp;lt;dd&gt;...&amp;lt;/dd&gt;
&amp;lt;/dl&gt;&lt;/code&gt;
&lt;p&gt;and after:&lt;/p&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&amp;lt;ul id=&quot;questions&quot;&gt;
    &amp;lt;li&gt;&amp;lt;a href=&quot;#what-is-this-site&quot;&gt;What is this site?&amp;lt;/a&gt;&amp;lt;/li&gt;
    &amp;lt;li&gt;&amp;lt;a href=&quot;#who-created-this-site&quot;&gt;Who created this site?&amp;lt;/a&gt;&amp;lt;/li&gt;
&amp;lt;/ul&gt;
&amp;lt;dl&gt;
    &amp;lt;dt&gt;&amp;lt;a class=&quot;question&quot; id=&quot;what-is-this-site&quot;&gt;What is this site?&amp;lt;/a&gt;&amp;lt;/dt&gt;
    &amp;lt;dd&gt;...&amp;lt;/dd&gt;
    &amp;lt;dt&gt;&amp;lt;a class=&quot;question&quot; id=&quot;who-created-this-site&quot;&gt;Who created this site?&amp;lt;/a&gt;&amp;lt;/dt&gt;
    &amp;lt;dd&gt;...&amp;lt;/dd&gt;
&amp;lt;/dl&gt;&lt;/code&gt;
&lt;p&gt;As you can see, the javascript simply extracts the relevant content from the questions and inserts the appropriate identities and links into the DOM to form the quick-links.  
Using the &lt;code class=&quot;prettyprint&quot;&gt;Effect.ScrollTo&lt;/code&gt; function also gives a pleasant user experience.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Mon, 25 May 2009 20:34:01 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/28-guid.html</guid>
    <category>commandlinefu</category>
<category>javascript</category>
<category>prototype</category>

</item>
<item>
    <title>Using a Phing filter to flush browser caches</title>
    <link>http://codeinthehole.com/archives/25-Using-a-Phing-filter-to-flush-browser-caches.html</link>
            <category>Deployment</category>
    
    <comments>http://codeinthehole.com/archives/25-Using-a-Phing-filter-to-flush-browser-caches.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=25</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=25</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;p&gt;A quick &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/phing.info/trac/&#039;);&quot;  href=&quot;http://phing.info/trac/&quot;&gt;Phing&lt;/a&gt; tip that&#039;s made my life easier when deploying new versions of &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.commandlinefu.com&#039;);&quot;  href=&quot;http://www.commandlinefu.com&quot;&gt;commandlinefu.com&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt;One of the &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/stevesouders.com/hpws/rule-expires.php&#039;);&quot;  href=&quot;http://stevesouders.com/hpws/rule-expires.php&quot;&gt;key performance recommendations&lt;/a&gt; from Steve Souders&#039; excellent &amp;quot;High Performance Websites&amp;quot; is to use Expires HTTP headers to set far-future expiration dates for your site components (such as images, Javascript files and CSS stylesheets).  This way, browsers can cache the files between requests giving a performance boost to your site.  Assuming you&#039;re using Apache for serving, the following settings can be used to set these headers for all Javascript and CSS files (there are a few alternative ways of achieving the same result):&lt;/p&gt;

&lt;code class=&quot;prettyprint&quot;&gt;&amp;lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$&quot;&gt;
    Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&amp;lt;/FilesMatch&gt;&lt;/code&gt;

&lt;p&gt;The main issue to be aware of using this technique is that, when your components change, you need to ensure your visitors are forced to download the latest version rather than using the one cached by their browser.  The only way to ensure this happens is to use a different URL for the assets in question.  One option might be to rename the files themselves but a more convenient alternative is to include a query string as part of the request URL (eg &lt;code&gt;&amp;lt;script src=&amp;quot;/js/behaviour.js?2009-03-15&amp;quot; type=&amp;quot;text/javascript&amp;quot; /&amp;gt;&lt;/code&gt;).  Then changing the query string component is sufficient to force browsers to make a full request for the new component.  &lt;/p&gt;&lt;p&gt;This works well but is an easy-to-forget overhead for deployment.  However, this substitution can be automated by making use of the Filters that Phing provides.  Doing so is trivial: simply insert a tokenised string as the query string after your asset URLs.  That is:&lt;/p&gt;

&lt;code class=&quot;prettyprint&quot;&gt;&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;http://codeinthehole.com/css/styles.css?~~CACHEBUSTER~~&quot; type=&quot;text/css&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://codeinthehole.com/js/site-behaviour.js?~~CACHEBUSTER~~&quot;&gt;&lt;/script&gt;&lt;/code&gt;

&lt;p&gt;where the &#039;~~&#039; delimiter indicates the token.  Then include something like the following snippet in your Phing deployment script.&lt;/p&gt;

&lt;code class=&quot;prettyprint&quot;&gt;&amp;lt;tstamp&gt;
    &amp;lt;format property=&quot;build.datetimestring&quot; pattern=&quot;%Y-%m-%d-%H-%M&quot; /&gt;
&amp;lt;/tstamp&gt;
...
&amp;lt;target name=&quot;create-temp-build&quot; description=&quot;Creates a temporary copy of the source files&quot;&gt;	
    &amp;lt;echo msg=&quot;Copying deployment files into temporary directory&quot; /&gt;
    &amp;lt;copy todir=&quot;${dev.folder.temp}&quot;&gt;
        &amp;lt;filterchain&gt;
            &amp;lt;replacetokens begintoken=&quot;~~&quot; endtoken=&quot;~~&quot;&gt;
                &amp;lt;token key=&quot;CACHEBUSTER&quot; value=&quot;${build.datetimestring}&quot; /&gt;
            &amp;lt;/replacetokens&gt;
        &amp;lt;/filterchain&gt;
	&amp;lt;fileset refid=&quot;deployment-files&quot; /&gt;
    &amp;lt;/copy&gt;
&amp;lt;/target&gt;&lt;/code&gt;

&lt;p&gt;The filterchain component of the copy task parses the given fileset for matching tokens that match and replaces them with the given value.  In this example, I&#039;m using timestamps as the replacements as these will ensure a different query string on each deployment.  Doing so ensures that the deployed HTML includes the lines:&lt;/p&gt;

&lt;code class=&quot;prettyprint&quot;&gt;&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;http://codeinthehole.com/css/styles.css?2008-03-15-21-51&quot; type=&quot;text/css&quot; /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;http://codeinthehole.com/js/site-behaviour.js?2008-03-15-21-51&quot;&gt;&lt;/script&gt;&lt;/code&gt;

&lt;p&gt;which then ensure that all subsequent visitors download the latest versions of the CSS and javascript files.  The above target is taken from a deployment script I use which creates a temporary snapshot of the codebase that I want to deploy, but the basic principle of using the &lt;code class=&quot;prettyprint&quot;&gt;replacetokens&lt;/code&gt; filter is easily transferable to any deployment script.&lt;/p&gt; 
    </content:encoded>

    <pubDate>Sun, 15 Mar 2009 19:01:13 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/25-guid.html</guid>
    <category>commandlinefu</category>
<category>deployment</category>
<category>phing</category>
<category>php</category>

</item>
<item>
    <title>The most important command-line tip - incremental history searching with .inputrc</title>
    <link>http://codeinthehole.com/archives/17-The-most-important-command-line-tip-incremental-history-searching-with-.inputrc.html</link>
            <category>Tidbits</category>
    
    <comments>http://codeinthehole.com/archives/17-The-most-important-command-line-tip-incremental-history-searching-with-.inputrc.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=17</wfw:comment>

    <slash:comments>6</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=17</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;p&gt;Getting &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.commandlinefu.com&#039;);&quot;  href=&quot;http://www.commandlinefu.com&quot;&gt;www.commandlinefu.com&lt;/a&gt; off the ground has renewed my interest in Bash, UNIX and all things command-line.  Powerful one-liners are things of beauty and are worth collecting; however what I consider to be the most influential command-line tip I know covers four:&lt;/p&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&quot;\e[A&quot;: history-search-backward
&quot;\e[B&quot;: history-search-forward
&quot;\e[C&quot;: forward-char
&quot;\e[D&quot;: backward-char&lt;/code&gt;
&lt;p&gt;These lines need to be placed in your &lt;code&gt;~/.inputrc&lt;/code&gt; file, the start-up script for the Readline utility used by Bash (as well as several other applications) and others).   The important commands here are the first two, which bind your up and down cursor keys to incrementally search your history. (The second two ensure that left and right continue to work correctly).&lt;/p&gt;
&lt;p&gt;This is &lt;em&gt;incredibly useful&lt;/em&gt; for retrieving commands you&#039;ve used previously and makes a huge difference to your productivity.  For instance, to find a previous SSH command from a few days ago, simply type &quot;ss&quot; and press up a few times.  This will allow you to browse through all your previous ssh&amp;hellip; commands until you find the right one - you never need to use more than 4 or 5 keystrokes to retrieve any previous command.  If your cycling through too many commands to find the right one, type in a few more characters to refine the search.&lt;/p&gt;
&lt;p&gt;As indicated above, this functionality is available in all applications that use Readline including MySQL, Python, IRB (interactive Ruby shell) and others.  Once you&#039;re used to this feature, it&#039;s hard to live without - the first thing I do once I&#039;ve been set up as a user on a new server is update my .inputrc file to contain these settings.  The one place where I sorely wish this functionality existed is the Firebug Javascript commandline in Firefox (a ticket already exists requesting a similar feature).&lt;/p&gt;
&lt;p&gt;Another way of searching your history is to use CTRL+R, which essentially performs a full-text search on your history (keep pressing CTRL+R to cycle through results).  In this case, searching for &quot;ssh&quot; will locate all commands that feature this string anywhere in the command.  Although this is actually a more powerful feature than the incremental history search described above, I don&#039;t often use it as: (a) the incremental search generally lets me jump to the desired command in fewer key-presses and (b) I find &quot;ssh&quot;, CTRL+R, CTRL+R slightly awkward to type and less intuitive than &quot;ssh&quot;, UP, UP.  Horses for courses really - you could probably be just as efficient with either one.
&lt;p&gt;&amp;raquo; Hat-tip to the place where I first learnt this: &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.ukuug.org/events/linux2003/papers/bash_tips/&#039;);&quot;  href=&quot;http://www.ukuug.org/events/linux2003/papers/bash_tips/&quot;&gt;Power Shell Usage by Simon Myers&lt;/a&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;One extra thing: this functionality can be neatly complimented by some choice history settings in your &lt;code&gt;~/.bashrc&lt;/code&gt; file:&lt;/p&gt;
&lt;code class=&quot;prettyprint&quot;&gt;export HISTSIZE=1000000
export HISTFILESIZE=1000000000&lt;/code&gt;
&lt;p&gt;These simply set your history to be very large so that you have a huge bank of commands to search.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Tue, 03 Feb 2009 23:40:00 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/17-guid.html</guid>
    <category>bash</category>
<category>commandlinefu</category>

</item>
<item>
    <title>Current pet project: Command-Line-Fu</title>
    <link>http://codeinthehole.com/archives/16-Current-pet-project-Command-Line-Fu.html</link>
            <category>Projects</category>
    
    <comments>http://codeinthehole.com/archives/16-Current-pet-project-Command-Line-Fu.html#comments</comments>
    <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=16</wfw:comment>

    <slash:comments>4</slash:comments>
    <wfw:commentRss>http://codeinthehole.com/rss.php?version=2.0&amp;type=comments&amp;cid=16</wfw:commentRss>
    

    <author>nospam@example.com (David Winterbottom)</author>
    <content:encoded>
    &lt;div style=&quot;float:left;margin-right:10px&quot;&gt;
&lt;img src=&quot;http://codeinthehole.com/app/images/screenshots/tomboy-commands-small.jpg&quot; alt=&quot;Tomboy note&quot; /&gt;
&lt;/div&gt;
&lt;p&gt;
If you&#039;re anything like me, you spend a lot of time at the UNIX command-line manipulating the filesystem, configuring Linux, playing with services and so forth.  As any UNIX user knows, tremendous power can be wielded through judicious function selection, piping and output redirection.  It&#039;s often quite staggering what can be achieved in a single line given a rudimentary knowledge of sed, grep, awk, cut&amp;hellip;
&lt;/p&gt;

&lt;p&gt;Indeed, when I stumble upon a line of particular elegance or usefulness, I generally log them to a &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/projects.gnome.org/tomboy/&#039;);&quot;  href=&quot;http://projects.gnome.org/tomboy/&quot;&gt;Tomboy note&lt;/a&gt; (fired up in a flash using &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/do.davebsd.com/&#039;);&quot;  href=&quot;http://do.davebsd.com/&quot;&gt;Gnome-do&lt;/a&gt;).  This has proved extremely useful as I am often returning to the list to recall how to, say, rsync a fileset with an exclude list - it&#039;s generally faster than Googling or going to the man pages.  As time has progressed though, this small repository has grown into a sizable collection and finding a particular command quickly is now a problem.  Motivated by this problem and taking inspiration from my daily reading (&lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/news.ycombinator.com/&#039;);&quot;  href=&quot;http://news.ycombinator.com/&quot;&gt;Hacker News&lt;/a&gt;, &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.reddit.com/r/programming/&#039;);&quot;  href=&quot;http://www.reddit.com/r/programming/&quot;&gt;Programming Reddit&lt;/a&gt; and &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/stackoverflow.com/&#039;);&quot;  href=&quot;http://stackoverflow.com/&quot;&gt;Stack Overflow&lt;/a&gt;), I&#039;m in the process of putting together a lightweight web-app for cataloguing and ranking notable UNIX one liners.
&lt;/p&gt;
&lt;div style=&quot;float:left;margin-right:10px&quot;&gt;
&lt;img src=&quot;http://codeinthehole.com/app/images/screenshots/clf-small.jpg&quot; alt=&quot;Tomboy note&quot; /&gt;
&lt;/div&gt;
&lt;p&gt;The basic idea is for users to be able to store their useful one liners on the site for (a) retrieval in the future and (b) sharing with others who undoubtedly will need to save the same problem.  Once created, these commands are parsed for the functions used and any relevant tags to provide good navigational props.    The individual commands also be discussed and commented on.  Further, users can vote on each others commands allowing simple leaderboards to be constructed.  After a few months, it will be interesting to see what the top 10 most useful awk commands are.  
&lt;/p&gt;
&lt;p&gt;It&#039;s only been a week (working piecemeal after dinner) but the site&#039;s nearly ready for a beta release.  It&#039;s constructed using a combination of CodeIgniter and Zend Framework, making use of the fast and lightweight nature of CodeIgniter coupled with the extensive range of components that ZF provides.  The site&#039;s called &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.commandlinefu.com&#039;);&quot;  href=&quot;http://www.commandlinefu.com&quot;&gt;http://www.commandlinefu.com&lt;/a&gt; and should be live in about a week assuming I find some spare time over the weekend.  Watch this space.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Thu, 22 Jan 2009 23:16:22 +0000</pubDate>
    <guid isPermaLink="false">http://codeinthehole.com/archives/16-guid.html</guid>
    <category>codeigniter</category>
<category>commandlinefu</category>
<category>zend framework</category>

</item>

</channel>
</rss>