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

<channel>
	<title>BogoJoker &#187; ruby</title>
	<atom:link href="http://blog.bogojoker.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bogojoker.com</link>
	<description>&#039;My humble abode&#039;.sub(/ab/,&#039;c&#039;)</description>
	<lastBuildDate>Mon, 04 Apr 2011 07:33:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Visualize the Directory Tree</title>
		<link>http://blog.bogojoker.com/2009/06/visualize-the-directory-tree/</link>
		<comments>http://blog.bogojoker.com/2009/06/visualize-the-directory-tree/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 15:00:56 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[SotD]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[directory tree]]></category>
		<category><![CDATA[listing]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=828</guid>
		<description><![CDATA[Ever have to work with a new directory and you have no idea what its structure is? Or maybe you have a few files laying around but you&#8217;re not sure which sub-directory they are in? Or maybe you&#8217;re showing someone else a project and you want to show them the directory hierarchy. The bare bones [...]]]></description>
			<content:encoded><![CDATA[<p>Ever have to work with a new directory and you have no idea what its structure is?  Or maybe you have a few files laying around but you&#8217;re not sure which sub-directory they are in?  Or maybe you&#8217;re showing someone else a project and you want to show them the directory hierarchy.  The bare bones solutions of `ls -R` or `find .` are just too archaic and offer no visualization of the structure. To solve this problem, people have built their own &#8220;tree&#8221; scripts.</p>
<p>There are a few tree scripts available online.  Some as simple as find | sed and others are slightly more advanced like a python script.  I wasn&#8217;t pleased with the existing solutions, so I wrote my own.  To get an idea of what I&#8217;m talking about take a look at this screenshot showing the listing of a Rails project:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/06/Picture-3.png" alt="tree" title="tree" class="aligncenter" /></p>
<p>Its a simple, clean listing of the directory tree.  I will admit, the style is based off of another tree script that I&#8217;ve seen that I liked.  Also, this isn&#8217;t really production quality code.  I take the lazy way out and first get a directory listing and then work from there.  This means that for large directories there may be an initial pause before it starts outputting.  I wouldn&#8217;t suggest running this on your home directory.  Although I can think of better algorithms its unlikely that I would want to run this on huge directories so I&#8217;m more then happy right now.</p>
<p>The usage is pretty bare bones:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/06/Picture-5.png" alt="tree usage" title="tree usage" class="aligncenter size-full" /></p>
<p>This is one more script I&#8217;ve added to my <a href="http://bogojoker.com/shell/">~/bin</a> and its completely open source <a href="http://github.com/JosephPecoraro/scripts/blob/master/tree">on GitHub</a>.  Its just straight Ruby, no extra packages, works with 1.8 and 1.9.  Oh and did I mention its customizable?</p>
<p>I hope you like it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/06/visualize-the-directory-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if Your Ruby Script is in a Pipe</title>
		<link>http://blog.bogojoker.com/2009/04/check-if-your-ruby-script-is-in-a-pipe/</link>
		<comments>http://blog.bogojoker.com/2009/04/check-if-your-ruby-script-is-in-a-pipe/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 02:20:12 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tty]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=731</guid>
		<description><![CDATA[Short and simple this week. When you&#8217;re writing a Ruby script you might want to know if you&#8217;re in a pipe or not. One reason might be changing how you buffer your input/output. A number of basic Unix commands do this, they act differently when piped. I actually wrote a script where I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p>Short and simple this week.  When you&#8217;re writing a Ruby script you might want to know if you&#8217;re in a pipe or not.  One reason might be changing how you buffer your input/output.  A number of basic Unix commands do this, they act differently when piped.</p>
<p>I actually wrote a script where I wanted to change the command line arguments if I was in a pipe. This is probably confusing but its really useful!  So there is actually an easy way to do this in Ruby:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>!/usr/bin/env ruby
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Prints if the input or output is regular or piped
</span>puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>INPUT:  <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span><span class="support support_class support_class_ruby">STDIN</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>tty?  <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">?</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>regular<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby">:</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>pipe<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>OUTPUT: <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span><span class="support support_class support_class_ruby">STDOUT</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>tty? <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">?</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>regular<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby">:</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>pipe<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
</span></pre>
<p>Proof that it works as advertised:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/04/isatty.png" alt="IO#tty?" title="IO#tty?" width="560" height="414" class="aligncenter size-full wp-image-733" /></p>
<p>The documentation on <a href="http://www.ruby-doc.org/core-1.9/classes/IO.html#M002108">IO#tty?</a> says the following:</p>
<blockquote><p>Returns true if [the IO stream] is associated with a terminal device (tty), false otherwise.</p></blockquote>
<p>For those that don&#8217;t know, tty is short for <em>teletype writer</em>.  This is an old Unix term for an interactive process that takes in user input.  Nowadays it almost always means a shell/console/terminal.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/04/check-if-your-ruby-script-is-in-a-pipe/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby Readline Documentation</title>
		<link>http://blog.bogojoker.com/2009/03/ruby-readline-documentation/</link>
		<comments>http://blog.bogojoker.com/2009/03/ruby-readline-documentation/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 15:00:59 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[libedit]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=530</guid>
		<description><![CDATA[Before today the Ruby readline library lacked documentation! In order to find some decent documentation you would have to read the README packaged with the source. Michael Fellinger (manveru) from #ruby-lang offered to help me get some decent documentation online. Take a look!]]></description>
			<content:encoded><![CDATA[<p>Before today the Ruby readline library lacked documentation!  In order to find some decent documentation you would have to read the README packaged with the source.  Michael Fellinger (manveru) from <a href="irc://irc.freenode.net/#ruby-lang">#ruby-lang</a> offered to help me get some decent documentation online.  <a href="http://bogojoker.com/readline/">Take a look</a>!</p>
<p><a href="http://bogojoker.com/readline/"><img src="http://blog.bogojoker.com/wp-content/uploads/2009/03/readline.png" alt="readline" title="Ruby Readline Documentation" width="500" height="617" class="aligncenter size-full wp-image-531" style="border: 1px solid gray; padding: 0; margin: 20px 40px;" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/03/ruby-readline-documentation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Debugging HTTP Headers</title>
		<link>http://blog.bogojoker.com/2009/03/debugging-http-headers/</link>
		<comments>http://blog.bogojoker.com/2009/03/debugging-http-headers/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 15:30:11 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=503</guid>
		<description><![CDATA[While writing the skreemr shell the other week I ran into an issue that required me to dig down to one of the lowest levels of web communication&#8230; HTTP Headers. I&#8217;m always shocked to learn that so many web developers don&#8217;t know much about headers. So I thought I would try to reenforce the point [...]]]></description>
			<content:encoded><![CDATA[<p>While writing <a href="http://blog.bogojoker.com/2009/02/mini-mp3-searching-shell-skreemr/">the skreemr shell</a> the other week I ran into an issue that required me to dig down to one of the lowest levels of web communication&#8230; HTTP Headers.  I&#8217;m always shocked to learn that so many web developers don&#8217;t know much about headers.  So I thought I would try to reenforce the point that HTTP Headers matter&#8230; and that knowing your stuff can help you debug and solve problems.  Here is the story of my real world example.</p>
<p>I&#8217;m not going to go over HTTP Headers.  <a href="http://www.cs.tut.fi/~jkorpela/http.html">thats</a> <a href="http://www.devshed.com/c/a/PHP/HTTP-Headers-in-Web-Development/">already</a> <a href="http://www.and.org/texts/server-http">been done</a>.  Instead I&#8217;m going to focus on debugging and working with them a little bit.   I&#8217;m going to assume you have already the general concepts.</p>
<h2>The Problem</h2>
<p>I wanted to add pagination to the skreemr shell.  So you could run a search, then get the next page of results, etc.  So a little experimentation with skreemr in my browser produced the following URLs:</p>
<pre>http://skreemr.com/results.jsp?q=test

http://skreemr.com/results.jsp?q=test&#038;l=10&#038;s=10

http://skreemr.com/results.jsp?q=test&#038;l=10&#038;s=20
</pre>
<p>A simple pattern!  &#8220;q&#8221; is the query string, &#8220;l&#8221; is the number per page, &#8220;s&#8221; is the number to start at, indexed from 0.  So that last URL would produce results 21-30.  This all worked well in my browsers, but it wasn&#8217;t working in Ruby:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="meta meta_require meta_require_ruby"><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">require</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>open-uri<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span></span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Grab the pages and read the content
</span>str1 <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> open<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>http://skreemr.com/results.jsp?q=test<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>      <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>read  <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> 1-10
</span>str2 <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> open<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>http://skreemr.com/results.jsp?q=test&amp;s=10<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>read  <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> 11-20
</span>
<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>=&gt; Should print false... but its printing true!
</span>puts str1<span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">==</span>str2</span></pre>
<p>What this was saying was that the content being returned from both of those urls is EXACTLY the same.  That couldn&#8217;t be&#8230; could it?</p>
<h2>More Investigation</h2>
<p>At this point I thought it was a problem in Ruby.  I figured Ruby was doing some caching in the background that I was going to have to disable or work around. (I now know this is not true, but that was my first guess).  To test that hypothesis I turned to my trusty friend curl and checked to see if that showed the proper behavior:</p>
<pre class="textmate-source twilight"><span class="source source_shell">shell<span class="keyword keyword_operator keyword_operator_redirect keyword_operator_redirect_shell">&gt;</span> curl <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>http://skreemr.com/results.jsp?q=test<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>      -o 1.html
shell<span class="keyword keyword_operator keyword_operator_redirect keyword_operator_redirect_shell">&gt;</span> curl <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>http://skreemr.com/results.jsp?q=test&amp;s=10<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span> -o 2.html
shell<span class="keyword keyword_operator keyword_operator_redirect keyword_operator_redirect_shell">&gt;</span> diff -q -s 1.html 2.html
Files 1.html and 2.html are identical
</span></pre>
<p>What!?!  That stunned me.  Curl was getting the exact same results as Ruby.  I took a look at the html files, and indeed 2.html, which should have contained results 11-20 held 1-10.  I opened both urls in my browser&#8230; they showed the correct results.  Something weird was happening!</p>
<h2>Take A Step Back</h2>
<p>At this point you&#8217;ve got to know what is happening.  Curl and Ruby (using Ruby&#8217;s Net:HTTP under the hood) are just making a simple GET request.  Both my browsers Safari and Firefox are sending far more then just a GET request.  They are sending a bunch of other headers.  Lets take a look at what Firebug says Firefox sent:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/03/picture-1.png" alt="firebug" title="firebug" width="657" height="648" class="aligncenter size-full wp-image-507" style="border: none; margin-left: -40px;" /></p>
<p>Thats a mighty long list of headers!  Its entirely possible that one of those might be influencing the server.  Onto the drama!</p>
<h2>Time to Act &#8211; Literally</h2>
<p>The only difference between what curl sent in its request and what Firefox was sending is that header information and possibly any information contained in those cookies (unlikely in this case).  So lets make curl <em>act as if it is</em> Firefox by send the same headers with curl!  I took a quick peek at <a href="http://bogojoker.com/atom/curl.php">my curl reference</a> for the proper switches/formatting and I was ready:</p>
<pre class="textmate-source twilight"><span class="source source_shell">shell<span class="keyword keyword_operator keyword_operator_redirect keyword_operator_redirect_shell">&gt;</span> curl <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>http://skreemr.com/results.jsp?q=test<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span> -o 1.html
shell<span class="keyword keyword_operator keyword_operator_redirect keyword_operator_redirect_shell">&gt;</span> curl <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>http://skreemr.com/results.jsp?q=test&amp;s=10<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>            \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Host: skreemr.com<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>                                  \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>User-Agent: Mozilla/5.0 (...) Firefox/3.0.6<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>        \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Accept: text/html,application/xml;q=0.9,*/*;q=0.8<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>  \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Accept-Language: en-us,en;q=0.5<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>                    \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Accept-Encoding: gzip,deflate<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>                      \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>     \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Keep-Alive: 300<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>                                    \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Connection: keep-alive<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>                             \
            -H <span class="string string_quoted string_quoted_single string_quoted_single_shell"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_shell">'</span>Cache-Control: max-age=0<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_shell">'</span></span>                           \
            -o 2.html
shell<span class="keyword keyword_operator keyword_operator_redirect keyword_operator_redirect_shell">&gt;</span> diff -q -s 1.html 2.html
Files 1.html and 2.html differ
</span></pre>
<p>Jackpot!  Some subset of those headers is indeed fixing my problem, because now it properly fetched the second page of results!  Translating that back into Ruby works as well:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="meta meta_require meta_require_ruby"><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">require</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>open-uri<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span></span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Headers
</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">HEADERS</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">{</span><span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block">
</span>  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Host<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>            <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>skreemr.com<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>User-Agent<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>      <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Mozilla/5.0 (...) Firefox/3.0.6<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Accept<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>          <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>text/html,application/xml;q=0.9,*/*;q=0.8<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Accept-Language<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>en-us,en;q=0.5<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Accept-Encoding<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>gzip,deflate<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Accept-Charset<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>  <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>ISO-8859-1,utf-8;q=0.7,*;q=0.7<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Keep-Alive<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>      <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>300<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Connection<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>      <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>keep-alive<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span>
  <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Cache-Control<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>   <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>max-age=0<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>
<span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">}</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Get the Pages
</span>str1 <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> open<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>http://skreemr.com/results.jsp?q=test<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> <span class="variable variable_other variable_other_constant variable_other_constant_ruby">HEADERS</span> <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>read
str2 <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> open<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>http://skreemr.com/results.jsp?q=test&amp;s=10<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> <span class="variable variable_other variable_other_constant variable_other_constant_ruby">HEADERS</span> <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>read

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Correctly Prints false
</span>puts str1<span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">==</span>str2</span></pre>
<h2>Problem Solved</h2>
<p>Sure, we have a solution but its not pretty.  How much is really needed?  Finding that out is just a matter of eliminating the headers that do nothing.  Remove one, test, remove another, test, remove another test&#8230;  As long as it still works after you&#8217;ve removed an individual header you know that header wasn&#8217;t needed.  It took me a few minutes but I narrowed it down to just a single header:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="variable variable_other variable_other_constant variable_other_constant_ruby">MAGIC</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">{</span><span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block"> </span><span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>Accept-Language<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="punctuation punctuation_separator punctuation_separator_key-value">=&gt;</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>en-us<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">}</span>
</span></pre>
<p>This was a rather unique problem.  It is rare for me to have to dip down to the HTTP Headers to see what is actually happening for such a high level problem.  However, as this problem shows, its important to know what is going on under the hood.  If I didn&#8217;t know about headers, I would not have been able to solve it.<br />
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/03/debugging-http-headers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mini MP3 Searching Shell &#8211; Skreemr</title>
		<link>http://blog.bogojoker.com/2009/02/mini-mp3-searching-shell-skreemr/</link>
		<comments>http://blog.bogojoker.com/2009/02/mini-mp3-searching-shell-skreemr/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 15:30:49 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[SotD]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=493</guid>
		<description><![CDATA[So its way to hard to download an mp3 in Safari. Right click the link and download? Pff, I want to ⌃S and be done with it. Well, this time I decided to avoid the problem all together. I use Skreemr to search for a particular song when it interests me. In the past I [...]]]></description>
			<content:encoded><![CDATA[<p>So its way to hard to download an mp3 in Safari. Right click the link and download? Pff, I want to ⌃S and be done with it. Well, this time I decided to avoid the problem all together. I use <a href="http://skreemr.com/">Skreemr</a> to search for a particular song when it interests me.</p>
<p>In the past I wrote a little bash script, that makes use of curl, to download an mp3 to my desktop unique named so it wouldn&#8217;t have conflicts. This shell essentially wraps and drastically improves that to allow for searching, pagination, history, downloading, and opening mp3s off of Skreemr. It gives me just what I need. The functionality that I want without having to use torrents etc. I&#8217;m thinking of turning this into a gem.</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/02/skreemr.png" width="658" height="846" alt="skreemr.png" style="border:none; margin-left: -35px;" /></p>
<p>This script requires the popular &#8220;escape.rb&#8221; script that gives some nice and safe shell escaping functions. You can download both from my <a href="http://github.com/JosephPecoraro/scripts/tree/master">GitHub scripts project</a>.</p>
<p>Of course its available on my <a href="http://bogojoker.com/shell/">~/bin</a> and there will be another article later on that goes over a few aspects of this simple little script.</p>
<p><a href="http://github.com/JosephPecoraro/scripts/tree/master"><img src="http://blog.bogojoker.com/wp-content/uploads/2009/02/skreemr2.png" width="450" height="150" alt="skreemr2.png" style="margin: 10px 50px; border: 1px solid lightGray" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/02/mini-mp3-searching-shell-skreemr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Updates to line.rb &#8211; Open to more suggestions</title>
		<link>http://blog.bogojoker.com/2009/01/updates-to-linerb-open-to-more-suggestions/</link>
		<comments>http://blog.bogojoker.com/2009/01/updates-to-linerb-open-to-more-suggestions/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 01:43:27 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=370</guid>
		<description><![CDATA[I was chatting with a friend the other day and he had some really good ideas concerning last week&#8217;s line.rb script. He wants to make an improved version. I look forward to seeing what he will come up with because he shared some great ideas. Well, I couldn&#8217;t help but implement them immediately in my [...]]]></description>
			<content:encoded><![CDATA[<p>I was chatting with a friend the other day and he had some really good ideas concerning last week&#8217;s line.rb script.  He wants to make an improved version.  I look forward to seeing what he will come up with because he shared some great ideas.  Well, I couldn&#8217;t help but implement them immediately in my version.  His ideas also spurred a little creativity from me and I came up with a few new features as well.  The usage is now looks like:</p>
<pre class="textmate-source twilight"><span class="source source_ruby">
<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Check Cmd Line Args and Print Usage if needed
</span>  <span class="keyword keyword_control keyword_control_ruby">if</span> <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>size <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">&lt;=</span> <span class="constant constant_numeric constant_numeric_ruby">1</span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>usage: line [options] filename numbers<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span> options:<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   --silent or -s   Just print the line, without [#]<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span> number formats:<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   1-3              Prints lines 1 through 3<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   5                Prints line 5<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   -1               Prints the last line, (negative)<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span> extra formats:<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   ~5               Prints 2 (default) lines before and after 5<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   4~10             Prints 4 lines before and after 10<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   *7 or 8*         Prints all lines before or after the number<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   5/1              Prints 5 lines, then skips 1 line...<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>   2:5/1            Starts at line 2, prints and skips...<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts
    exit <span class="constant constant_numeric constant_numeric_ruby">1</span>
</span></pre>
<p>So there is some cool new syntax:</p>
<ul>
<li>
<p>~# &#8211; prints 2 lines before and after the given line number</p>
</li>
<li>
<p>#~# &#8211; prints the given number of lines before and after the given line number</p>
</li>
<li>
<p>*# &#8211; prints all of the lines before the given line number</p>
</li>
<li>
<p>#* &#8211; prints all of the lines after the given line number</p>
</li>
<li>
<p>#/# &#8211; is a print and skip option</p>
</li>
<li>
<p>#:#/# &#8211; allows you to provide an offset</p>
</li>
</ul>
<p>Lets say you want to print every even line in a text file.  With this script that is not a problem.  The solution is: starting on the 2nd line, print 1 line, then skip 1 line.  (line file 2:1/1):</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/01/picture-23.png" alt="Print only even lines using line.rb" title="Print only even lines using line.rb" width="553" height="462" class="aligncenter size-full wp-image-371" style="border:none;margin: 0px 30px;" /></p>
<p>I think these new formats are pretty neat.  You can always access the latest version of the script <a href="http://github.com/JosephPecoraro/scripts/blob/master/line">on Github</a> or in my <a href="http://bogojoker.com/shell">~/bin</a>.  I&#8217;m willing to change the syntax and introduce new concepts.  Send suggestions my way by dropping a comment! Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/01/updates-to-linerb-open-to-more-suggestions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly Output Lines in a File</title>
		<link>http://blog.bogojoker.com/2009/01/quickly-output-lines-in-a-file/</link>
		<comments>http://blog.bogojoker.com/2009/01/quickly-output-lines-in-a-file/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 04:40:21 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[SotD]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=287</guid>
		<description><![CDATA[The other day I wanted a shell command to have somebody print out the 671st line of /etc/services on their computer. So I gave it some thought, then some more thought, scratched my head, and figured out that I couldn&#8217;t really think of a shell command that does that. A google search came up with [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I wanted a shell command to have somebody print out the 671st line of /etc/services on their computer.  So I gave it some thought, then some more thought, scratched my head, and figured out that I couldn&#8217;t really think of a shell command that does that.  A google search came up with a few `sed` and `awk` examples but I honestly found those to be a bit awkward for something that should be super simple.  So I wrote my own script.</p>
<p>After writing the script to print out a single line, I soon found it made a lot of sense to include ranges.  Taking advantage of Ruby I can even print lines from the end with negative numbers.  So I spent a few minutes to clean up the script and make it a little more reusable, add some formatting, and cleaner.  Here was the result:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/01/picture-21.png" alt="line sample usage" title="line sample usage" width="644" height="526" class="aligncenter size-full wp-image-291" style="border:none; margin-left: -20px;" /></p>
<p><a href="http://github.com/JosephPecoraro/scripts/tree/master/line">line</a> is now the latest addition to my <a href="http://bogojoker.com/shell/">~/bin</a>.</p>
<p>Also, in case you wanted to use this in a shell script or via piping, there is a `&#8211;silent` or `-s` switch that you can use that removes all of the special formatting, and prints only the specified lines.  Much nice for scripts. (See the highlighted line in the image below).  Enjoy!</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/01/picture-3.png" alt="line source" title="line source" width="644" height="660" class="aligncenter size-full wp-image-299" style="border:none; margin-left: -20px;" /></p>
<p>So what exactly is line 671 of /etc/services?  On my mac it is:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2009/01/picture-4.png" alt="line 671 of /etc/services" title="line 671 of /etc/services" width="546" height="286" class="aligncenter size-full wp-image-302" style="border: none;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2009/01/quickly-output-lines-in-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Web URLs with ExpanDrive</title>
		<link>http://blog.bogojoker.com/2008/12/dynamic-web-urls-with-expandrive/</link>
		<comments>http://blog.bogojoker.com/2008/12/dynamic-web-urls-with-expandrive/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 02:10:26 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[SotD]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ExpanDrive]]></category>
		<category><![CDATA[expanurl]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=245</guid>
		<description><![CDATA[Often when I work with ExpanDrive the files I am working on correspond to some website that I own. When I&#8217;m mounted with ExpanDrive each file is accessible via &#8220;my hard drive&#8221; in the mounted volume and, more importantly, from a web URL! I found myself repeatedly opening up my browser and manually typing the [...]]]></description>
			<content:encoded><![CDATA[<p>Often when I work with <a href="http://expandrive.com/">ExpanDrive</a> the files I am working on correspond to some website that I own.  When I&#8217;m mounted with ExpanDrive each file is accessible via &#8220;my hard drive&#8221; in the mounted volume and, more importantly, from a web URL!  I found myself repeatedly opening up my browser and manually typing the URL for files that I just uploaded or edited.  This was error prone, especially if some of the characters needed encoding.  So, I spent some time to write up a Ruby script that can read ExpanDrive&#8217;s preferences, build the file&#8217;s &#8220;web URL,&#8221; and open it in your default browser.</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2008/12/expanurl-usage.png" alt="expanurl usage" title="expanurl usage" width="588" height="478" class="aligncenter size-full wp-image-252" style="border:none" /></p>
<h2>Simple to Use</h2>
<p>I followed along with ExpanDrive&#8217;s previous command line tool named expan and named my script expanurl.  Given no arguments it will open the current directory via its web URL, or you can give a list of files and each will be opened at their web URLs.  Its usage is pretty straightforward but there is a single catch: the server setting in an ExpanDrive Drive may not be a true one-to-one mapping with the web server&#8217;s address.</p>
<p>For example: I provide holly.cs.rit.edu as the server value for one of my personal ExpanDrive drives.  However, when I view files on that server (inside the public_html directory) they have a much different looking URL: http://www.cs.rit.edu/~jjp1820/.  The result?  The script simply keeps its own mapping of ExpanDrive server values to their associated web page prefixes.  When you use expanurl on a Drive you have never used it on before the script will prompt you for that mapping, store the value, and never ask again.</p>
<p>Here it is in action.  I have removed all stored mappings so I can demonstrate what it would be like using expanurl for the first time. Here I use it on my BogoJoker ExpanDrive drive:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2008/12/picture-21.png" alt="expanurl first usage" title="expanurl first usage" width="588" height="430" class="aligncenter size-full wp-image-249" style="border:none;"/></p>
<p>Notice that in the prompt it tells you:</p>
<ul>
<li>the server that the ExpanDrive volume is linked to and the one you will be providing a web url prefix for</li>
<li>an example of a web url prefix (useful)</li>
<li>where the mappings are stored in case you need to edit them later</li>
</ul>
<p>The script is available on GitHub, so feel free to contribute and improve.  <a href="http://github.com/JosephPecoraro/scripts/tree/master/expanurl">Here is a link to the always current version</a>, and here is a snapshot of the current version at the time of writing:</p>
<p>&nbsp;</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>!/usr/bin/env ruby
# Author: Joseph Pecoraro
# Date: Saturday December 13, 2008
# Description: When I'm using ExpanDrive and I'm
# remotely logged into a server, I can use this
# script to "open filename" and it will open using
# the server's associated URL.
</span>
<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> For URL Escaping and Stored Mappings
</span><span class="meta meta_require meta_require_ruby"><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">require</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>uri<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span></span>
<span class="meta meta_require meta_require_ruby"><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">require</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>yaml<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span></span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Exit with a msg
</span><span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">err</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">msg</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
  puts msg
  exit <span class="constant constant_numeric constant_numeric_ruby">1</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Simple Class to handle the mappings
</span><span class="meta meta_class meta_class_ruby"><span class="keyword keyword_control keyword_control_class keyword_control_class_ruby">class</span> <span class="entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby">UrlMap</span></span>

  <span class="variable variable_other variable_other_constant variable_other_constant_ruby">MAP_PATH</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="support support_class support_class_ruby">File</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>expand_path<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>~/.expanurl<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>

  <span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">initialize</span></span>
    <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>hash</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> load
  <span class="keyword keyword_control keyword_control_ruby">end</span>

  <span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">load</span></span>
    <span class="keyword keyword_control keyword_control_ruby">if</span> <span class="support support_class support_class_ruby">File</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>exists?<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">MAP_PATH</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
      <span class="support support_class support_class_ruby">YAML</span><span class="punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby">::</span>load_file<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="support support_class support_class_ruby">File</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>expand_path<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">MAP_PATH</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span> <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
    <span class="keyword keyword_control keyword_control_ruby">else</span>
      <span class="support support_class support_class_ruby">Hash</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span>
    <span class="keyword keyword_control keyword_control_ruby">end</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">add_mapping</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">server<span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> mapto</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>hash</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span>server<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> mapto
    <span class="support support_class support_class_ruby">File</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>open<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">MAP_PATH</span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>w<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span> <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">file</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
      file<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>write<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>hash</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>to_yaml<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
    <span class="keyword keyword_control keyword_control_ruby">end</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">is_mapping?</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">server</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>hash</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>has_key?<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>server<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">get_mapping</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">server</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>hash</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span>server<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

  <span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">path</span></span>
    <span class="variable variable_other variable_other_constant variable_other_constant_ruby">MAP_PATH</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Local Variables
</span>mapping <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="support support_class support_class_ruby">UrlMap</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span>
url_prefix <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">nil</span>
server <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">nil</span>
volume <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">nil</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Check the if the current directory is an
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ExpanDrive Volume and a public_html folder
</span>pwd <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="string string_interpolated string_interpolated_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">`</span>pwd<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">`</span></span>
match <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> pwd<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span>^<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span>Volumes<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span><span class="string string_regexp string_regexp_group string_regexp_group_ruby"><span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">(</span><span class="string string_regexp string_regexp_character-class string_regexp_character-class_ruby"><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">[</span>^<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">]</span></span>+<span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">)</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
<span class="keyword keyword_control keyword_control_ruby">if</span> match<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>nil?
  err<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Not inside an ExpanDrive Volume<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
<span class="keyword keyword_control keyword_control_ruby">elsif</span> <span class="keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby">!</span>pwd<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span>public_html<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span>?<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  err<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Not inside a public_html directory.<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
<span class="keyword keyword_control keyword_control_ruby">else</span>
  volume <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> match<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="constant constant_numeric constant_numeric_ruby">1</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>
  defaults <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="string string_interpolated string_interpolated_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">`</span>defaults read com.magnetk.ExpanDrive Drives<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">`</span></span>
  defaults<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>gsub!<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\n</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  props <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> defaults<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\{</span><span class="string string_regexp string_regexp_character-class string_regexp_character-class_ruby"><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">[</span>^<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\}</span><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">]</span></span>+driveName<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\s</span>+=<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\s</span>+<span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>volume<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="string string_regexp string_regexp_character-class string_regexp_character-class_ruby"><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">[</span>^<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\}</span><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">]</span></span>+server<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\s</span>+=<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\s</span>+"<span class="string string_regexp string_regexp_group string_regexp_group_ruby"><span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">(</span><span class="string string_regexp string_regexp_character-class string_regexp_character-class_ruby"><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">[</span>^"<span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">]</span></span>+<span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">)</span></span>"<span class="string string_regexp string_regexp_character-class string_regexp_character-class_ruby"><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">[</span>^<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\}</span><span class="punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby">]</span></span>+<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\}</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  <span class="keyword keyword_control keyword_control_ruby">if</span> props
    server <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> props<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="constant constant_numeric constant_numeric_ruby">1</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>
  <span class="keyword keyword_control keyword_control_ruby">else</span>
    err<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>This Volume (<span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>volume<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span>) is not an ExpanDrive Volume<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Check if a mapping exists
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Otherwise create and store one
</span><span class="keyword keyword_control keyword_control_ruby">if</span> mapping<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>is_mapping?<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>server<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  url_prefix <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> mapping<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>get_mapping<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>server<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
<span class="keyword keyword_control keyword_control_ruby">else</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Prompt
</span>  puts
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>This is the first time you've used expanurl for <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>volume<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Please Provide us with a mapping for <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>server<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Mappings are stored in <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>mapping<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>path<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Example: http://bogojoker.com/<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  print <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>&gt;&gt; <span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Store user input and proceed
</span>  url_prefix <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> gets<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>chomp
  url_prefix <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">+=</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>/<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="keyword keyword_control keyword_control_ruby">unless</span> url_prefix<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span>$<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  mapping<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>add_mapping<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>server<span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> url_prefix<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Terminal Output
</span>  puts
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Server: <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>server<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Maps to: <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>url_prefix<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts

<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Build the URL
</span>subpath <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> pwd<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span>public_html<span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span>?<span class="string string_regexp string_regexp_group string_regexp_group_ruby"><span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">(</span>.*<span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">)</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="constant constant_numeric constant_numeric_ruby">1</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>
subpath <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">+=</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>/<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span> <span class="keyword keyword_control keyword_control_ruby">unless</span> subpath<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>length<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>zero? <span class="keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby">||</span> subpath<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span>$<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
url_prefix <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">+=</span> subpath

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> If No Files, open the directory
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Otherwise,   open each provided file
</span><span class="keyword keyword_control keyword_control_ruby">if</span> <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>size <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">==</span> <span class="constant constant_numeric constant_numeric_ruby">0</span>
  <span class="string string_interpolated string_interpolated_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">`</span>open <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>url_prefix<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">`</span></span>
<span class="keyword keyword_control keyword_control_ruby">else</span>
  <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">filename</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
    <span class="string string_interpolated string_interpolated_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">`</span>open <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>url_prefix<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}#{</span><span class="support support_class support_class_ruby">URI</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>escape<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>filename<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">`</span></span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="keyword keyword_control keyword_control_ruby">end</span></span></pre>
<p>&nbsp;</p>
<h2>How it Works</h2>
<p>The Ruby Script grabs the current working directory using `pwd` and checks to make sure you&#8217;re in an ExpanDrive volume.  ExpanDrive volume&#8217;s are dynamically generated by parsing the ExpanDrive preferences thanks to their foresight to make them accessible via the `defaults` command.  So if you&#8217;re in an ExpanDrive volume and inside a public_html directory expanurl will then use its mapping to open a uri encoded web url in your default browser with the `open` command.</p>
<p>The mappings are stored in a hidden YAML file in your home directory (~/.expanurl).  This style of storing preferences is just like dozens of other command line applications and scripts.  YAML is just a lightweight textual data format popular with Ruby, similar to JSON and XML.  Its so simple that you could edit the file yourself if you wanted/needed to.  For instance here is what is in mine, just two simple key/value pairs:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2008/12/picture-31.png" alt="~/.expanurl yaml mapping" title="~/.expanurl yaml mapping" width="581" height="286" class="aligncenter size-full wp-image-255" style="border: none" /></p>
<h2>The Future</h2>
<p>Its just that simple.  Being a Ruby Script you can call this from GUI applications, anything with built-in shell access, etc.  It should play friendly with your usual Unix tools.  I will likely make this script more and more robust if others find it useful, so I&#8217;d be happy to hear some feedback.</p>
<p>Cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/12/dynamic-web-urls-with-expandrive/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby Process Controller &#8211; psgrep</title>
		<link>http://blog.bogojoker.com/2008/12/ruby-process-controller-psgrep/</link>
		<comments>http://blog.bogojoker.com/2008/12/ruby-process-controller-psgrep/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 06:33:56 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[SotD]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[psgrep]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=195</guid>
		<description><![CDATA[Every once in a while a process will freeze and will be too stubborn to die when I try to &#8220;Quit&#8221; it. For those stubborn processes I tend to use the terminal to `kill` it. For a while I had been using a simple Perl script for searching through processes. The script would find me [...]]]></description>
			<content:encoded><![CDATA[<p>Every once in a while a process will freeze and will be too stubborn to die when I try to &#8220;Quit&#8221; it.  For those stubborn processes I tend to use the terminal to `kill` it.  For a while I had been using a simple Perl script for searching through processes.  The script would find me the processids and I could then kill it, using whatever power I need.</p>
<p>I found that it was taking far too long for me to do the search, and then carefully type out the process id, and hope I got the right one.  I discovered killall, but the problem is that sometimes I don&#8217;t want to kill &#8220;all&#8221; of the processes with that name.  So, I gave in and wrote up a Ruby script that did what I wanted.  Here is psgrep: <a href="http://github.com/JosephPecoraro/scripts/raw/master/psgrep">(Download)</a></p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>!/usr/bin/env ruby
# Start Date: Saturday December 6, 2008
# Current Version: 0.9
# Author: Joseph Pecoraro
# Contact: joepeck02@gmail.com
# Decription: Quicker handling of process searching
# and killing.  Never type in a PID again, just regexes!
</span>
<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -----------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   Globals
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -----------
</span>kill_mode <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">false</span>
icase_mode <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">false</span>
pattern <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">nil</span>
targets <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[]</span>
pids <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[]</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ---------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   Usage
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ---------
</span><span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">usage</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>usage: <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span><span class="variable variable_other variable_other_readwrite variable_other_readwrite_global variable_other_readwrite_global_pre-defined variable_other_readwrite_global_pre-defined_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">$</span>0</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>split<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\/</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>last<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span> [options] pattern<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>  -k  or --kill   kills all processes<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>  -k# or --kill#  kills the [#] process<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  exit <span class="constant constant_numeric constant_numeric_ruby">0</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -----------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   Options
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -----------
</span><span class="keyword keyword_control keyword_control_ruby">if</span> <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>size <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">&gt;</span> <span class="constant constant_numeric constant_numeric_ruby">1</span>
  <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">arg</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
    <span class="keyword keyword_control keyword_control_ruby">if</span> arg<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span>^-<span class="string string_regexp string_regexp_group string_regexp_group_ruby"><span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">(</span>k|-kill<span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">)(</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\d</span>*<span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">)</span></span>$<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
      kill_mode <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">true</span>
      targets <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">&lt;&lt;</span> <span class="variable variable_other variable_other_readwrite variable_other_readwrite_global variable_other_readwrite_global_pre-defined variable_other_readwrite_global_pre-defined_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">$</span>2</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>to_i <span class="keyword keyword_control keyword_control_ruby">unless</span> <span class="variable variable_other variable_other_readwrite variable_other_readwrite_global variable_other_readwrite_global_pre-defined variable_other_readwrite_global_pre-defined_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">$</span>2</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>empty?
    <span class="keyword keyword_control keyword_control_ruby">elsif</span> arg<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span>^-<span class="string string_regexp string_regexp_group string_regexp_group_ruby"><span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">(</span>i|-ignore<span class="punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby">)</span></span>$<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
      icase_mode <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_language constant_language_ruby">true</span>
    <span class="keyword keyword_control keyword_control_ruby">end</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>
  <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>delete_if <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">{</span><span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block"> </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">e</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span> e<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span>^-<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span> <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">}</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -------------------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   Remaining Args
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -------------------
</span><span class="keyword keyword_control keyword_control_ruby">if</span> <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>size <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">!=</span> <span class="constant constant_numeric constant_numeric_ruby">1</span>
  usage
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="keyword keyword_control keyword_control_ruby">if</span> icase_mode
  pattern <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="support support_class support_class_ruby">Regexp</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="constant constant_numeric constant_numeric_ruby">0</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> <span class="support support_class support_class_ruby">Regexp</span><span class="punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby">::</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">IGNORECASE</span> <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
<span class="keyword keyword_control keyword_control_ruby">else</span>
  pattern <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="support support_class support_class_ruby">Regexp</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span> <span class="support support_class support_class_ruby">ARGV</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="constant constant_numeric constant_numeric_ruby">0</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span> <span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ----------------------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   Actual `ps` Output
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ----------------------
</span>lines <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="string string_interpolated string_interpolated_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">%x{</span> ps -Au<span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span><span class="meta meta_environment-variable meta_environment-variable_ruby"><span class="variable variable_other variable_other_constant variable_other_constant_ruby">ENV</span>[<span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>USER<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span>]</span><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span> <span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">}</span></span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>split<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span><span class="constant constant_character constant_character_escape constant_character_escape_ruby">\n</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
header <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> lines<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>shift

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ----------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   psgrep
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> ----------
</span>puts
puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>     <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>header<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
count <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_numeric constant_numeric_ruby">0</span>
lines<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">line</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
  <span class="keyword keyword_control keyword_control_ruby">unless</span> line <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">=~</span> <span class="string string_regexp string_regexp_classic string_regexp_classic_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span>psgrep<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby">/</span></span>
    <span class="keyword keyword_control keyword_control_ruby">if</span> line<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>match<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>pattern<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
      count <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">+=</span> <span class="constant constant_numeric constant_numeric_ruby">1</span>
      puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>[<span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>count<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span>]: <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>line<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
      <span class="keyword keyword_control keyword_control_ruby">if</span> targets<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>empty? <span class="keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby">||</span> targets<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>member?<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>count<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
        pids <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">&lt;&lt;</span> line<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>strip<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>split<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="constant constant_numeric constant_numeric_ruby">1</span><span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>
      <span class="keyword keyword_control keyword_control_ruby">end</span>
    <span class="keyword keyword_control keyword_control_ruby">end</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -------------
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   Kill Mode
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> -------------
</span><span class="keyword keyword_control keyword_control_ruby">if</span> kill_mode
  puts
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Killing Processes<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>-----------------<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
  pids<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each_with_index <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">pid</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">,</span> <span class="variable variable_other variable_other_block variable_other_block_ruby">i</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
    print targets<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>empty? <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">?</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>[<span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>i<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span>]:<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby">:</span>  <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>[<span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>targets<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span>i<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span>]:<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    print <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span> Killing <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>pid<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span>... <span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    <span class="support support_class support_class_ruby">STDOUT</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>flush
    res <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="string string_interpolated string_interpolated_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">%x{</span> kill <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>pid<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span> <span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">}</span></span>
    puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Dead<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="keyword keyword_control keyword_control_ruby">if</span> <span class="variable variable_other variable_other_readwrite variable_other_readwrite_global variable_other_readwrite_global_pre-defined variable_other_readwrite_global_pre-defined_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">$</span>?</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>exitstatus<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>zero?
  <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Always
</span>puts
</span></pre>
<p>So there it is.  Less then 100 lines of ruby to get a pretty straightforward psgrep/kill program.  Here is an example where I have three perl processes running on my machine.  One of the is running as root (the userid is 0).  I just type &#8220;!! &#8211;kill&#8221; or &#8220;[up-arrow] &#8211;kill&#8221; and it tries to kill them all.  Note that the root perl process doesn&#8217;t terminate and there is an error message but psgrep continues as best as it can, and kills the two normal perl processes: [Note: I could have done `sudo psgrep perl -k` to kill the root process]</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2008/12/picture-11.png" alt="psgrep usage" title="psgrep usage" width="595" height="564" class="size-full wp-image-198" style="border: none" /></p>
<p>Here is another good example.  I have two python instances that I want to kill but there is another python instance running ExpanDrive in the background.  I just ran psgrep and found the two I want to kill are [2] and [3].  Therefore, I can send -k2 and -k3 (or &#8211;kill2 and &#8211;kill3) to kill only those processes.  Here is the result:</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2008/12/picture-3.png" alt="psgrep target" title="psgrep target" width="602" height="420" class="aligncenter size-full wp-image-202" style="border:none" /></p>
<p>Note also that by default psgrep is case-sensitive.  To ignore case just add the -i or &#8211;ignore switch.  So there you have it.  Usage is straightforward.  Switches can go anywhere on the command line makes it easier to just use your history and tack a switch on the end of your previous command.</p>
<p>Feel free to improve it, <a href="http://github.com/JosephPecoraro/scripts/tree/master/psgrep">it is on GitHub!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/12/ruby-process-controller-psgrep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The ARGFy Experiment</title>
		<link>http://blog.bogojoker.com/2008/12/the-argfy-experiment/</link>
		<comments>http://blog.bogojoker.com/2008/12/the-argfy-experiment/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 02:38:38 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ARGF]]></category>
		<category><![CDATA[ARGFy]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=168</guid>
		<description><![CDATA[I wrote an earlier article that talked about Ruby&#8217;s global ARGF variable. I mentioned that I took that a step further, to experiment and learn a number of aspects about Ruby development. Those included: RDoc &#8211; Ruby Autogenerated Documentation RSpec &#8211; Ruby Test Framework aiding Behavior Driven Development General Familiarity with Ruby Classes General Familiarity [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote <a href="http://blog.bogojoker.com/2008/11/data-and-argf-in-ruby/">an earlier article</a> that talked about Ruby&#8217;s global ARGF variable.  I mentioned that I took that a step further, to experiment and learn a number of aspects about Ruby development.  Those included:</p>
<ol>
<li>RDoc &#8211; Ruby Autogenerated Documentation</li>
<li>RSpec &#8211; Ruby Test Framework aiding Behavior Driven Development</li>
<li>General Familiarity with Ruby Classes</li>
<li>General Familiarity with GitHub</li>
</ol>
<p>I have to say that I was really impressed with how strikingly natural, easy, and fun it was to work with these tools.  I already wrote about <a href="http://blog.bogojoker.com/2008/11/rdoc-introduction/">RDoc</a>, hopefully to cover a &#8220;void&#8221; that I saw in the online documentation for it.  I may look into writing about <a href="http://rspec.info/">RSpec</a>, however the current RSpec documentation was quite good so I may focus elsewhere.  Finally GitHub and Ruby are mostly things that you have to personally practice with to get good at, and there are already plenty of great resources for them.  The Ruby community has done a very good job!</p>
<h2>The ARGFy Results</h2>
<p>So, here are the results of my experiment:</p>
<ul>
<li><a href="http://github.com/JosephPecoraro/argfy/tree/master">ARGFy GitHub Repository</a></li>
<li><a href="http://bogojoker.com/argfy/doc/">ARGFy RDoc Documentation</a></li>
</ul>
<p>The GitHub README is very similar to the RDoc, but it goes in more depth by showing the output of the sample.rb script included.  Its not too exciting, but here is what ARGFy does.</p>
<h2>What ARGFy Does</h2>
<p>ARGFy is a class.  In the constructor it takes an Array of filenames.  It then treats those files as one continuous stream of lines.  If no filenames are provided, or if &#8220;-&#8221; is provided as a filename, that input is treated as STDIN.  Everything so far makes ARGFy look and act just like ARGF except you can specify your own files instead of only relying on the command line arguments.
<p>Using ARGFy is mostly like ARGF.  If you call the ARGFy#each method (note that this allows for any Enumerable method!) it will exhaust all the lines of input from all the files as a single stream.  At each line you can check the states of the ARGFy object itself.  The states include filename and lineno like the normal ARGF, but they also include filelineno.  Because there is a filelineno there is a guaranteed way to know if under-the-hood the stream is now processing a different file.  Since this might be a common thing to check there is a ARGFy#new_file? helper method that does just that.
<p>Finally, because its an object you can add a file to the list at any time.  Although removing didn&#8217;t seem to make much sense considering what its purpose was.  Just make use of ARGFy#add_file to add a file to the end of the sequence of input files to the stream.</p>
<p>In the background ARGFy is really just reading and buffering the files one at a time and returning the lines.  Its nothing too exciting, just a little fun working with Ruby.  The example nicely displays how ARGFy works:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> sample.rb
</span><span class="meta meta_require meta_require_ruby"><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">require</span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span>ARGFy<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span></span>

argf <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="support support_class support_class_ruby">ARGFy</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">ARGV</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
argf<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">line</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Per File Header
</span>  <span class="keyword keyword_control keyword_control_ruby">if</span> argf<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>new_file?
    filename <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> argf<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>filename
    filename <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>STDIN<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="keyword keyword_control keyword_control_ruby">if</span> filename <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">==</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>-<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
    puts <span class="string string_quoted string_quoted_single string_quoted_single_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">'</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">'</span></span><span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> filename<span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>-<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span><span class="keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby">*</span>filename<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>length
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Print out the line with line numbers
</span>  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>%3d: %s<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby">%</span> <span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span>argf<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>lineno<span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> line<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>

<span class="keyword keyword_control keyword_control_ruby">end</span>
puts
</span></pre>
<p>Calling sample.rb with a few small input files creates some nicely formatted output:</p>
<pre>shell&gt; ruby sample.rb in1.txt in2.txt 

in1.txt
-------
  1: one
  2: two

in2.txt
-------
  1: alpha, beta, gamma
  2: 0987654321
  3:
  4: NOT BLANK!</pre>
<p>Nothing complex.  It works like you would expect it too.  For more sample usage you can scan the <a href="http://github.com/JosephPecoraro/argfy/tree/master/test/basic_spec.rb">RSpec test cases</a> in the GitHub repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/12/the-argfy-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RDoc Introduction</title>
		<link>http://blog.bogojoker.com/2008/11/rdoc-introduction/</link>
		<comments>http://blog.bogojoker.com/2008/11/rdoc-introduction/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 05:05:43 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[rdoc]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=148</guid>
		<description><![CDATA[Automatically generating documentation from source code has been available as far back as 1993. Its so common now that its expected to be available in any mainstream programming languages. I&#8217;ve seen it most commonly in Object Oriented languages offering nicely formatted descriptions of classs and their public methods/attributes. Consistency is Nice The main advantage I [...]]]></description>
			<content:encoded><![CDATA[<p>Automatically generating documentation from source code has been available as far back as <a href="http://en.wikipedia.org/wiki/Comparison_of_documentation_generators">1993</a>.  Its so common now that its expected to be available in any mainstream programming languages.  I&#8217;ve seen it most commonly in Object Oriented languages offering nicely formatted descriptions of classs and their public methods/attributes.</p>
<h2>Consistency is Nice</h2>
<p>The main advantage I see with automatically generated documentation is that it is consistent.  Take Javadocs for instance.  They are all the same.  When a developer wants to work with a Java library, they expect Javadocs.  Why?  Because they are familiar with them.  They can easily navigate them and quickly find whatever it is that they are looking for.  Documentation in any other way would require wasting time learning how to use/navigate it searching for what you want to know.</p>
<p>RDoc is Ruby&#8217;s documentation generator.  You see RDoc generated documentation all over the place in Ruby.  See <a href="http://www.ruby-doc.org/stdlib/libdoc/yaml/rdoc/index.html">YAML</a>,  <a href="http://code.whytheluckystiff.net/doc/hpricot/">Hpricot</a>, or even core classes like <a href="http://www.ruby-doc.org/core/classes/Array.html">Array</a>.</p>
<p>So, I felt if I want to continue using Ruby I should at least learn how its handled.  It turns out that its easier then I thought.  I&#8217;m a huge fan of Markdown syntax and RDoc turns out to be pretty close to that.  So, here is what I think is all you need to know to handle producing some simple, yet thorough, documentation for a class.</p>
<h2>RDoc Resources</h2>
<p>Start by updating your rdoc.  The latest version at the time of writing is 2.2.1.  The gem provides you with the rdoc and ri tools so that you can both generate and display documentation from the command line.  Here is how you can install them:</p>
<p><code>shell> sudo gem install rdoc</code></p>
<p>The best online resources I found were not surprisingly:</p>
<ul>
<li><a href="http://www.ruby-doc.org/stdlib/libdoc/rdoc/rdoc/index.html">RDoc&#8217;s documentation itself</a> &#8211; an RDoc on RDoc&#8230; actually its RDoc&#8217;s classes but its overview is helpful.</li>
<li><a href="http://rdoc.sourceforge.net/doc/files/README.html">An Older Writeup by Dave Thomas</a> &#8211; has a similar example</li>
<li><a href="http://daringfireball.net/projects/markdown/syntax">Markdown Syntax</a> &#8211; Very similar to what is used in RDoc comments</li>
</ul>
<p></p>
<h2>Structure</h2>
<p>Here is a basic example that shows the structure of the RDoc as it describes a File, Class, Attributes, and Methods.  The placement of the comments is important.  RDoc comments are always on top of what they are documenting:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Documentation for the file itself
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> There should be a blank line between this and any class
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> definition to separate the documentation about the file
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> and the class.  If there is no space then the entire text
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> is used for both the file and the class, no different.
</span>
<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Documentation for the class itself.
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> This will appear at the top of the page specific to this
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> class, before any other content.
</span><span class="meta meta_class meta_class_ruby"><span class="keyword keyword_control keyword_control_class keyword_control_class_ruby">class</span> <span class="entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby">Dice</span></span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Documentation for an attribute
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> To documentation each attribute you must make individual
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> calls to attr_accessor, attr_reader, and attr_writer.
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Appears next to the attribute name in the attrs section
</span>  <span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">attr_accessor</span> <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby"><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby">:</span>sides</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Documentation for the constructor
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Corresponds to the `new` method
</span>  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">initialize</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">sides</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>sides</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> sides
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Documentation for a method
</span>  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">roll</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">times</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="support support_class support_class_ruby">Array</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>times<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>map <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">{</span><span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block"> </span><span class="constant constant_numeric constant_numeric_ruby">1</span><span class="keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby">+</span>rand<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>sides</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span> <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">}</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Documentation for a method
</span>  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">beat</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">num</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    roll<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="constant constant_numeric constant_numeric_ruby">1</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>first <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">&gt;</span> num
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="keyword keyword_control keyword_control_ruby">end</span></span></pre>
<p>Running `rdoc` on <a href="http://bogojoker.com/blog/wp-content/uploads/2008/11/example1/">that file creates this documentation.</a></p>
<h2>Style</h2>
<p>Rich documentation makes the important parts stand out.  It makes use of HTML&#8217;s expressive power and enables lists, headers, links, bold/italics, code, and other presentation helpers.  I&#8217;ll now document the Dice class and add some style and realistic content.</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># == sample.rb
# This file contains the Dice class definition and it runs
# some simple test code on a 16 sided dice.  A 20 dice
# roll fight again the COMPUTER who always rolls 10s!

#
# Multi-sided dice class.  The number of sides is determined
# in the constructor, or later on by accessing the _sides_
# attribute.
#
# == Summary
#
# A #single_roll returns a single integer from 1 to the
# number of sides, _inclusive_.  However, if you want to
# roll multiple times you can can use the #roll method,
# specifying the number of rolls you want, and you will
# get an Array with the values of all the rolls!
#
# == Example
#
#    dice = Dice.new(8)   # An eight sided dice
#    four = dice.roll(4)  # An Array containing 4 rolls
#    sum  = four.inject(0) { |mem,i| mem+i } # Sum of rolls
#
# == Contact
#
# Author::  Joseph Pecoraro (mailto:joepeck02@gmail.com)
# Website:: http://blog.bogojoker.com
# Date::    Saturday November 29, 2008
#
</span><span class="meta meta_class meta_class_ruby"><span class="keyword keyword_control keyword_control_class keyword_control_class_ruby">class</span> <span class="entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby">Dice</span></span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Number of sides on the dice
</span>  <span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">attr_accessor</span> <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby"><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby">:</span>sides</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Create a dice with `sides` of dice.
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Defaults to 6.
</span>  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">initialize</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">sides<span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span><span class="constant constant_numeric constant_numeric_ruby">6</span></span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>sides</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> sides
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Returns an array of size `times` containing
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> a group of dice rolls.
</span>  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">roll</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">times</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    <span class="support support_class support_class_ruby">Array</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span>times<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>map <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">{</span><span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block"> </span>single_roll <span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby">}</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Returns the value of a single dice roll.  The
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> values are from 1 to @sides _inclusive_.
</span>  <span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">single_roll</span></span>
    <span class="constant constant_numeric constant_numeric_ruby">1</span><span class="keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby">+</span>rand<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby"><span class="punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby">@</span>sides</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> A single roll challenge:
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> * makes a single_roll
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> * returns true if the roll was strictly greater
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span>   then the given number
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">  <span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> * returns false otherwise
</span>  <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">beat</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">(</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">num</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby">)</span></span>
    single_roll <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">&gt;</span> num
  <span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Note that this is a constant, which is special
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> and it is documented like a Class Attribute.
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> This is in the RDoc generated documentation for
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> the file.
</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">COMPUTER</span> <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_numeric constant_numeric_ruby">10</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Note that these comments, for generic code
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> are not in the RDoc generated documentation.
</span>dice <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="support support_class support_class_ruby">Dice</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span><span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="constant constant_numeric constant_numeric_ruby">16</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
winCount <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> loseCount <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> <span class="constant constant_numeric constant_numeric_ruby">0</span>
<span class="constant constant_numeric constant_numeric_ruby">20</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>times <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do
</span>  <span class="keyword keyword_control keyword_control_ruby">if</span> dice<span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>beat<span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">(</span><span class="variable variable_other variable_other_constant variable_other_constant_ruby">COMPUTER</span><span class="punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby">)</span>
    winCount <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">+=</span> <span class="constant constant_numeric constant_numeric_ruby">1</span>
  <span class="keyword keyword_control keyword_control_ruby">else</span>
    loseCount <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">+=</span> <span class="constant constant_numeric constant_numeric_ruby">1</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> Output
</span>puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>You won <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>winCount<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span> times and lost <span class="source source_ruby source_ruby_embedded source_ruby_embedded_source"><span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">#{</span>loseCount<span class="punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby">}</span></span> times!<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>
puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Muhahah.  Try again later!!<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>           <span class="keyword keyword_control keyword_control_ruby">if</span> winCount <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">&lt;</span> loseCount
puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>Well Played.  I'll get you next time.<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="keyword keyword_control keyword_control_ruby">if</span> winCount <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">&gt;</span> loseCount
puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>What a match!  Boy that was fun.<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span>      <span class="keyword keyword_control keyword_control_ruby">if</span> winCount <span class="keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby">==</span> loseCount</span></pre>
<p><a href="http://bogojoker.com/blog/wp-content/uploads/2008/11/example2/">That generates this documentation.</a></p>
<h2>Specifics</h2>
<p>There are some subtle points that make this documentation format nicely.  I&#8217;ll point them out and explain them.  Most of this is straight from the above resources, however some of it I could not find documented anywhere.</p>
<ul>
<li>The file documentation links to the Dice class.  Furthermore the Class documentation links down to the single_roll and roll methods.  This is because:<br />
<blockquote><p>Names of classes, source files, and any method names containing an underscore or preceded by a hash character are automatically hyperlinked from comment text to their description.</p></blockquote>
<ol>
<li>sample.rb was a filename and so it was automatically linked.</li>
<li>Dice was the name of a class and so it was automatically linked.</li>
<li>single_roll had an underscore and happened to be a method name so it was automatically linked in a few places.</li>
<li>#roll had a hash character signifying that it should be linked.</li>
</ol>
</li>
<li>Sections begin with a &#8220;=&#8221; or a &#8220;==&#8221;.  I prefer to use double, because it stands out more in the source code.  Technically a single &#8220;=&#8221; becomes a level 1 header, and a double becomes a level 2 header.  However, they both display the same.</li>
<li>URIs like http://blog.bogojoker.com and mailto:email are automatically turned into links and formatted nicely.</li>
<li>Bold, Italics, and Typewriter Text can be quickly formated much like Markdown:<br />
<blockquote><p>_italic_ or &lt;em>italic&lt;/em><br />
  *bold* or &lt;b>bold&lt;/b><br />
  +typewriter+ or &lt;tt>typewriter&lt;/tt></p></blockquote>
</li>
<li>Code is displayed if each line
<li>Tabular Labeled List, like the Contact information, are formatted like:<br />
<blockquote><p>label:: description 1<br />
label2:: both descriptions will line up</p></blockquote>
</li>
<li>Formatting source code is like Markdown.  The code that you want formatted must be indented with a few spaces.  As long as the indention is maintained the text will display as source code in the HTML documentation.</li>
<li>Formatting lists is again like Markdown.  Just use *&#8217;s or -&#8217;s and they will turn into bullet points.  For numbered lists just use numbers followed by a dot and they will be formatted automatically.</li>
</ul>
<p></p>
<h2>Final Notes on `rdoc` itself</h2>
<p>When I created the final documentation above I used a few of rdoc&#8217;s command line switches to customize the output.  What I actually used was:</p>
<p><code>shell> rdoc --title="Dice Documentation" --line-numbers --tab-width=2</code></p>
<p>The title switch changed the &lt;title> for the documentation page, and the other two deal with formatting the htmlized source code that RDoc shows when you click on the function name to view the source in the documentation.  There are plenty of command line switches.  To view the full list do:</p>
<p><code>shell> rdoc --help</code></p>
<p>A few useful switches are &#8220;&#8211;ri&#8221; to create ri documentation so you can access your classes from the command line.  Also you can output to several formats.  For instance you can make a PDF using &#8220;&#8211;format=texinfo&#8221; then using `texi2pdf` on the texinfo file.  The PDF doesn&#8217;t look that bad, here is <a href="http://bogojoker.com/blog/wp-content/uploads/2008/11/dice.pdf">my example as a PDF</a>.</p>
<p>NOTE: Finding the generators was tricky.  I had to check out the rdoc source code and find the different generators.  If anyone knows an easier way to check what generators are available, please let me know.</p>
<p>I hope this helps some people using RDoc for their classes.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/11/rdoc-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DATA and ARGF in Ruby</title>
		<link>http://blog.bogojoker.com/2008/11/data-and-argf-in-ruby/</link>
		<comments>http://blog.bogojoker.com/2008/11/data-and-argf-in-ruby/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 20:18:18 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ARGF]]></category>
		<category><![CDATA[DATA]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=140</guid>
		<description><![CDATA[Of all the &#8220;superglobals&#8221; in Ruby these seemed to be the least documented. It only takes a quick example to understand them. I had some fun and decided to play around with these variables and more. DATA Although this is mostly useless, its a neat trick. In any Ruby script, as soon as the __END__ [...]]]></description>
			<content:encoded><![CDATA[<p>Of all the &#8220;superglobals&#8221; in Ruby these seemed to be the least documented.  It only takes a quick example to understand them.  I had some fun and decided to play around with these variables and more.</p>
<h3>DATA</h3>
<p>Although this is mostly useless, its a neat trick.  In any Ruby script, as soon as the <var>__END__</var> symbol is matched, then the rest of the text in the file is no longer parsed by the interpreter.  Whatever is after <var>__END__</var> can be accessed via <var>DATA</var>.  <var>DATA</var> acts like a File Object, so its like you&#8217;re reading the current script as though you&#8217;re reading from a File.</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> DATA is a global that is actually a File object
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> containing the data after __END__ in the current
</span><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> script file.
</span>puts <span class="support support_class support_class_ruby">DATA</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>read

<span class="string string_unquoted string_unquoted_program-block string_unquoted_program-block_ruby">__END__
</span><span class="text text_plain">I can put anything I want
after the __END__ symbol
and access it with the
DATA global.  Whoa!
</span></span></pre>
<h3>ARGF</h3>
<p><var>ARGF</var> takes each of the elements in <var>ARGV</var>, assumes they are filenames, and allows you to process these files as single stream of input.  This is common with shell programs.  Its a lot like <var>cat</var>.  <var>cat</var> takes multiple files on the command line, and outputs them as a single stream.  If you want to force input to come from STDIN then just provide a hypen &#8220;-&#8221;.  Finally, if there is nothing in ARGV then ARGF defaults to STDIN.</p>
<p>Here is a simple example of ARGF mimicking <var>cat</var>.</p>
<pre>shell&gt; echo "inside a.txt" > a.txt
shell> echo "inside b.txt" > b.txt
shell> cat a.txt b.txt
inside a.txt
inside b.txt</pre>
<p>Here is a Ruby script that can do just that:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> cat.rb
</span><span class="support support_class support_class_ruby">ARGF</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">line</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
  puts line
<span class="keyword keyword_control keyword_control_ruby">end</span></span></pre>
<p>Example usage:</p>
<pre>shell&gt; ruby cat.rb a.txt b.txt
inside a.txt
inside b.txt</pre>
<h3>ARGF Confusion</h3>
<p>What confused me when I first used ARGF was that it has no special class.  It claims it is an Object.  Take a look:</p>
<pre>&gt;&gt; ARGF.class
# =&gt; Object</pre>
<p>But at the same time it has so much more then a regular Object:</p>
<pre>&gt;&gt; ARGF.methods - Object.methods
# => ["select", "lineno", "readline", "eof", "each_byte", "partition", "lineno=", "read", "fileno", "grep", "to_i", "filename", "reject", "readlines", "getc", "member?", "find", "to_io", "each_with_index", "eof?", "collect", "path", "all?", "close", "entries", "tell", "detect", "zip", "rewind", "map", "file", "any?", "sort", "min", "seek", "binmode", "find_all", "each_line", "gets", "each", "pos", "closed?", "skip", "inject", "readchar", "pos=", "sort_by", "max"]</pre>
<p>The important things to note are accessors like <var>lineno</var> and <var>filename</var>.  They can give you some information while you read the lines.  Such as if you&#8217;re reading from a file or STDIN.  You can easily give line numbers to everything being read.  Like so:</p>
<pre class="textmate-source twilight"><span class="source source_ruby"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby">#</span> linenum.rb
</span><span class="support support_class support_class_ruby">ARGF</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>each <span class="keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby">do </span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span><span class="variable variable_other variable_other_block variable_other_block_ruby">line</span><span class="punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby">|</span>
  puts <span class="string string_quoted string_quoted_double string_quoted_double_ruby"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby">"</span>%3d: %s<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby">"</span></span> <span class="keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby">%</span> <span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">[</span><span class="support support_class support_class_ruby">ARGF</span><span class="punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby">.</span>lineno<span class="punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby">,</span> line<span class="punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby">]</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>
</span></pre>
<p>Produces:</p>
<pre>shell&gt; ruby linenum.rb a.txt b.txt
  1: inside a.txt
  2: inside b.txt</pre>
<h3>ARGFy</h3>
<p>As an exercise I wrote a little class to emulate what ARGF does and to make it more useful to me.  For instance ARGF can&#8217;t tell you when it changes files.  You can try and catch when the filename changes but what if the same file is repeated twice in a row?  ARGFy has both a global <var>lineno</var> and a per file <var>filelineno</var>  I&#8217;ll talk more about <a href="http://github.com/JosephPecoraro/argfy/tree/master">ARGFy</a> later.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/11/data-and-argf-in-ruby/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Helpful Configure Options For Development</title>
		<link>http://blog.bogojoker.com/2008/11/helpful-configure-options-for-development/</link>
		<comments>http://blog.bogojoker.com/2008/11/helpful-configure-options-for-development/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 06:37:47 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[suffix]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=126</guid>
		<description><![CDATA[Recently I decided to install Ruby 1.9. I&#8217;ve been compiling programs from source more and more often and I am getting used to the normal workflow: configure, make, make install. But Ruby 1.9 was different. I wanted to easily reference both the Ruby 1.8 and Ruby 1.9 so I could easily work with both. I [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I decided to install Ruby 1.9.  I&#8217;ve been compiling programs from source more and more often and I am getting used to the normal workflow: configure, make, make install. But Ruby 1.9 was different.  I wanted to easily reference both the Ruby 1.8 and Ruby 1.9 so I could easily work with both.  I <a href="http://programblings.com/2008/11/18/installing-ruby-19preview1-on-os-x-leopard/">came across</a> a neat switch that I had never cared to use before but made perfect sense for my situation:
<p><code>shell&gt; ./configure --program-suffix=WHATEVER ...</code></p>
<p>That neat switch will make it so when you finally `make install` the output binaries are named rubyWHATEVER, irbWHATEVER, etc.  Obviously you should choose something better then WHATEVER.  I went with &#8216;&#8211;program-suffix=19&#8242; so that all my Ruby 1.9 binaries are exactly the same as the 1.8 binaries but with &#8220;19&#8243; on the end.  Such as ruby19, irb19, etc.  This will really save me some time as I experiment with Ruby 1.9.</p>
<p>Note when installing Ruby from source on Mac OS X you may run into problems, check out <a href="http://lindsaar.net/2008/1/18/installing-ruby-1-9-on-mac-osx">this article</a> or the one linked above for the fixes.</p>
<p>Also, since I had now had a ruby19 I figured I&#8217;d make a ruby18 as well.  I already have my own &#8216;~/bin&#8217; directory in my shell&#8217;s path.  So I added the following symbolic link which makes `ruby18` reference my default Ruby 1.8 interpreter:</p>
<p><code>shell&gt; ln -s `which ruby` ruby18</code></p>
<p>The `which ruby` in my case evaluates to the default installation of Ruby.  It may not be the case on your computer. That depends on how you&#8217;ve modified your path.  So the explicit version  that should work on any mac is:</p>
<p><code>shell&gt; ln -s /usr/bin/ruby ruby18</code></p>
<p>Here the symbol link means I can use `ruby18` if I want to be dead sure I&#8217;m using Ruby 1.8, and likewise `ruby19` when I want to use Ruby 1.9.  I know I&#8217;m not the first person to do this, but I&#8217;m happy and I want to spread the joy.</p>
<p>Other notable configure options are:</p>
<p><code>shell&gt; ./configure --prefix=PREFIX ...</code></p>
<p>This makes it so when you run `make install` it will install the files to PREFIX/(here).  An example would typically be &#8216;&#8211;prefix=/usr/local&#8217; to install the files into the /usr/local dir.  However, that is normally the default installation directory and therefore most people don&#8217;t bother changing it.  I&#8217;ve used this prefix to install temporary things directly into my home directory.  This made it easy to find, work with, and delete when I was done.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/11/helpful-configure-options-for-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Big Picture Analyzer</title>
		<link>http://blog.bogojoker.com/2008/11/the-big-picture-analyzer/</link>
		<comments>http://blog.bogojoker.com/2008/11/the-big-picture-analyzer/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 15:50:19 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[The Big Picture]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=116</guid>
		<description><![CDATA[One of my favorite blogs that I follow is The Big Picture. Its a collection of amazing pictures. Make sure that you go into each article, that single picture is only a teaser and often collections have over 30 images. At the Big Picture it is very common for commenters to list the numbers of [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favorite blogs that I follow is <a href="http://boston.com/bigpicture/">The Big Picture</a>.  Its a collection of amazing pictures.  Make sure that you go into each article, that single picture is only a teaser and often collections have over 30 images.</p>
<p><a href="http://boston.com/bigpicture/"><img src="http://blog.bogojoker.com/wp-content/uploads/2008/11/picture-11.png" alt="(JOERG KOCH/AFP/Getty Images)" title="autumn_big_picture" width="400" height="259" class="size-medium wp-image-103" style="display: block; margin: 15px 100px" /></a></p>
<p>At the Big Picture it is very common for commenters to list the numbers of the images that they really liked.  This intrigued me a little bit.  Also, the comments on the main page are limited to just<br />
100 comments, when there might actually be over 2000 comments on some collections.</p>
<p>So, I wrote a Ruby Script that I call <a href="http://github.com/JosephPecoraro/scripts/tree/master/bigpicvotes">bigpicvotes</a> that takes in the URL to a Big Picture site and analyzes the comments to make a guess at what pictures were voted for the most!</p>
<p><img src="http://blog.bogojoker.com/wp-content/uploads/2008/11/picture-1.png" alt="bigpicvotes usage" title="bigpicvotes-usage" width="448" height="446" class="size-full wp-image-104" style="border: none; display: block; margin: 5px 60px"/></p>
<p>Above is a sample usage on an article with now over 2600 comments.  Notice that the URL you provide can be either the &#8220;all comments&#8221; URL or just the URL with the pictures that you are likely to be looking at.  Also, the usage allows for a second optional parameter.  This is to show the top N images instead of defaulting to the top 10.</p>
<p>One last thing.  To use it you will need the <a href="http://code.whytheluckystiff.net/hpricot/">Hpricot</a> gem.  That is simple enough to <a href="http://code.whytheluckystiff.net/hpricot/wiki/InstallingHpricot">install</a>:</p>
<pre>shell> gem install hpricot</pre>
<p>Again, the script is available here: <a href="http://github.com/JosephPecoraro/scripts/tree/master/bigpicvotes">bigpicvotes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/11/the-big-picture-analyzer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Ruby 1.8.7 on Mac OS X 10.5.3</title>
		<link>http://blog.bogojoker.com/2008/06/installing-ruby-187-on-mac-os-x-1053/</link>
		<comments>http://blog.bogojoker.com/2008/06/installing-ruby-187-on-mac-os-x-1053/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 18:37:10 +0000</pubDate>
		<dc:creator>Joseph Pecoraro</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[10.5.3]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mac os x leopard]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[ruby 1.8.7]]></category>

		<guid isPermaLink="false">http://blog.bogojoker.com/?p=58</guid>
		<description><![CDATA[Yah, this week is all about solving problems. I run into a lot of them, but it gives me something to blog about. But hey, if I can spend 20 minutes writing down a solution to a couple hour problem that I had, then I could save you a few hours too. Problem Trying to [...]]]></description>
			<content:encoded><![CDATA[<p>Yah, this week is all about solving problems.  I run into a lot of them, but it gives me something to blog about.  But hey, if I can spend 20 minutes writing down a solution to a couple hour problem that I had, then I could save you a few hours too.</p>
<h3>Problem</h3>
<p>Trying to install Ruby 1.8.7 (or even 1.9) on my Leopard machine produces warning messages on &#8220;make&#8221; that look like this:</p>
<pre>gcc -I. -I../../.ext/include/i686-darwin9.1.0 -I../.././include
-I../.././ext/readline -DRUBY_EXTCONF_H=\"extconf.h\"    -fno-common
-g -O2 -pipe -fno-common   -o readline.o -c readline.c
readline.c: In function 'filename_completion_proc_call':
readline.c:659: error: 'filename_completion_function' undeclared
(first use in this function)
readline.c:659: error: (Each undeclared identifier is reported only once
readline.c:659: error: for each function it appears in.)
readline.c:659: warning: assignment makes pointer from integer without a
cast
readline.c: In function 'username_completion_proc_call':
readline.c:684: error: 'username_completion_function' undeclared
(first use in this function)
readline.c:684: warning: assignment makes pointer from integer without a
cast
make[1]: *** [readline.o] Error 1
make: *** [all] Error 1</pre>
<h3>Solution</h3>
<p>I originally came across this problem right around new years and eventually found a solution thanks to Han Kessels on the <a href="http://www.ruby-forum.com/topic/136498">Ruby Forums</a>.  It involved the following steps:</p>
<ol>
<li>
<p>Download the newest version of readline (version 5.2 at the time of writing) at <a href="http://ftp.gnu.org/gnu/readline/">GNU.org</a>.  You may have to apply the following <a href="http://ftp.gnu.org/gnu/readline/readline-5.2-patches/readline52-012">patch</a>.  Thanks to <a href="http://michael.biven.org/2008/01/25/installing-ruby-on-rails-on-mac-os-105-or-patching-dan-benjamins-guide/">Michael Biven</a> for showing a nice simple way to do this from the command line:</p>
<pre>$ curl -O ftp://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
$ tar xzvf readline-5.2.tar.gz
$ cd readline-5.2
$ curl -O http://ftp.gnu.org/gnu/readline/readline-5.2-patches/readline52-012
$ patch -p0 < readline52-012
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ cd ..</pre>
</li>
<li>
<p>Now you can download the 1.8.7 version of ruby, and install it but you should point to the version of readline that you just installed (to /usr/local) like so:</p>
<pre>$ curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz
$ tar xzvf ruby-1.8.7.tar.gz
$ cd ruby-1.8.7
$ ./configure --prefix=/usr/local/ruby1.8.7 --with-readline-dir=/usr/local
$ make
$ sudo make install
$ cd /usr/local/ruby1.8.7/bin
$ ./ruby -v
ruby 1.8.7 (2008-05-31 patchlevel 0) [i686-darwin9.3.0]</pre>
</li>
</ol>
<h3>The End Result</h3>
<p>If you followed my terminal commands from above you should have a working Ruby 1.8.7 version installed in your "/usr/local/ruby1.8.7/bin".  If you wanted ruby in a different directory then change the "--prefix=/usr/local/ruby1.8.7" option on ./configure to instead point to the directory you wanted it.</p>
<p>Why put it in its own directory at all?  Well, I happen to have multiple version of ruby.  By default I have 1.8.6, I have this version of 1.8.7, I even have a 1.9 version I installed a while ago.  Its easy to remember where each is if the directory they reside in clearly states the name.  This way I can test a script, maybe even run benchmarks, in each version of ruby.  However, you might not want to take this extra measure.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bogojoker.com/2008/06/installing-ruby-187-on-mac-os-x-1053/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

