<?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>blogt0sk1 &#187; Tools</title>
	<atom:link href="http://blog.jerodsanto.net/category/tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jerodsanto.net</link>
	<description>with Jerod Santo</description>
	<lastBuildDate>Sat, 19 Jun 2010 14:34:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ad Hoc Command-Line Notifications with Twitter</title>
		<link>http://blog.jerodsanto.net/2009/11/ad-hoc-command-line-notifications-with-twitter/</link>
		<comments>http://blog.jerodsanto.net/2009/11/ad-hoc-command-line-notifications-with-twitter/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 17:03:04 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=765</guid>
		<description><![CDATA[Have you ever spent way too much time babysitting a long-running command? Code compilation, large file transfers, software upgrades and other time consuming tasks can trash productivity by requiring intermittent attention. I have a novel idea; let&#8217;s not do that anymore! There are undoubtedly dozens of solutions for this little problem, but I chose Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever spent way too much time babysitting a long-running command? Code compilation, large file transfers, software upgrades and other time consuming tasks can trash productivity by requiring intermittent attention. </p>
<p>I have a novel idea; <strong>let&#8217;s not do that anymore!</strong></p>
<p><span id="more-765"></span></p>
<p>There are undoubtedly dozens of solutions for this little problem, but I chose Ruby + Twitter for a few reasons:</p>
<ul>
<li>I like Ruby</li>
<li>I like Twitter</li>
<li>I want hassle-free SMS</li>
<li>I want portability (small client-side configuration)</li>
</ul>
<p>So, with those things in mind, here is what I&#8217;ve come up with:</p>
<h2>1) A Special Twitter Account</h2>
<p>Create a new account for your notifications. You&#8217;ll most likely want to protect its tweets unless you don&#8217;t mind <em>just about anybody</em> seeing all the notifications you&#8217;re sending to yourself. Once the account is set up, follow it from your main Twitter account and enable SMS notifications for its tweets.</p>
<p><img src="http://blog.jerodsanto.net/wp-content/uploads/2009/11/twitter-sms.png" alt="twitter-sms" title="twitter-sms" width="532" height="136" class="aligncenter size-full wp-image-767" /></p>
<h2>2) A dead simple Ruby script</h2>
<p>I&#8217;ve written about John Nunemaker&#8217;s Twitter gem a <a href="http://blog.jerodsanto.net/2009/05/expand-your-twitter-network-in-less-than-15-lines-of-ruby/">couple</a> of <a href="http://blog.jerodsanto.net/2009/05/see-which-twitterers-dont-follow-youback-in-less-than-15-lines-of-ruby/">times</a>, and it once again makes its way into the toolbelt. Install if you don&#8217;t have it:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ sudo gem install twitter</pre></div></div>

<p>This gem makes the notification script just a few lines of code:</p>
<script src="http://gist.github.com/234586.js"></script><noscript><code class="gist"><pre><br />
#!/usr/bin/env ruby<br />
require &#8216;rubygems&#8217;<br />
require &#8216;twitter&#8217;</p>
<p>abort %|Usage: #{File.basename(__FILE__)} &#8220;your message&#8221;| unless ARGV.length == 1<br />
user = &#8220;your_username&#8221;<br />
pass = &#8220;your_password&#8221;<br />
Twitter::Base.new(Twitter::HTTPAuth.new(user,pass)).update(&#8220;NOTICE: #{ARGV.first}&#8221;)<br />
</pre></code></noscript>
<p>You can name the script anything you like. I call it <span class="keyword">twitter_notify</span>. Make it executable and ensure it is in your shell&#8217;s execution path (I symlink it so I can keep my code organized):</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ chmod +x src/ruby/twitter/twitter_notify.rb
jerod@mbp:~$ ln -s ~/src/ruby/twitter/twitter_notify.rb /usr/local/bin/twitter_notify</pre></div></div>

<h2>3) A Call to Notify</h2>
<p>Anytime you want to be notified that a command has completed, just follow it with the <span class="keyword">twitter_notify</span> command. There are a couple of ways to do this, and they are slightly different:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cp /tmp/bigfile.tgz /somewhere/else &amp;&amp; twitter_notify &quot;all done copying!&quot;</pre></div></div>

<p>Or:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cp /tmp/bigfile.tgz /somewhere/else; twitter_notify &quot;command complete!&quot;</pre></div></div>

<p>Using <span class="keyword">&#038;&#038;</span> will only call the second command if the first command completed successfully. Using <span class="keyword">;</span> will call the second command regardless of how the first command completed. Adjust usage depending on your circumstance.</p>
<h2>4) A Deserved Break</h2>
<p>Now that you&#8217;ve set up your tools to handle the grunt work, walk away from the computer! Go outside, watch a movie, hang with your fam, who cares! When that task is complete you&#8217;ll get an SMS and you can deal with it then.</p>
<p>That&#8217;s all I got.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/11/ad-hoc-command-line-notifications-with-twitter/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Cheating on Rails</title>
		<link>http://blog.jerodsanto.net/2009/10/cheating-on-rails/</link>
		<comments>http://blog.jerodsanto.net/2009/10/cheating-on-rails/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 14:35:06 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=681</guid>
		<description><![CDATA[Fellow command-line junkies either love the cheat gem by Chris Wanstrath or they&#8217;ve never heard of it. What &#8220;cheat&#8221; offers is a plethora (currently 601) of text-based cheat sheets at the tip of your fingers. Go ahead, give it a try: jerod@mbp:~$ sudo gem install cheat jerod@mbp:~$ cheat apache2 Pretty cool, huh? Some cheats are [...]]]></description>
			<content:encoded><![CDATA[<p>Fellow command-line junkies either love <a href="http://cheat.errtheblog.com/" rel="external">the cheat gem</a> by <a href="http://ozmm.org/" rel="external">Chris Wanstrath</a> or they&#8217;ve never heard of it.</p>
<p>What &#8220;cheat&#8221; offers is a plethora (currently 601) of text-based cheat sheets at the tip of your fingers. Go ahead, give it a try:<br />
<span id="more-681"></span></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ sudo gem install cheat
jerod@mbp:~$ cheat apache2</pre></div></div>

<p>Pretty cool, huh?</p>
<p>Some cheats are kind of long, so pipe them to &#8220;less&#8221; for pagination:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cheat git | less</pre></div></div>

<p>List all the cheats available:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cheat sheets</pre></div></div>

<p>Or find one matching a search string:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cheat sheets | grep [your search string]</pre></div></div>

<p>To learn more about cheat:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cheat cheat</pre></div></div>

<h3>Cheat on Rails</h3>
<p>There a bunch of Rails-related cheats, which are great help in a pinch. Here are a few that I highly recommend:</p>
<ul>
<li><strong>status_codes</strong> &#8211; all HTTP status codes and their matching Rails symbols</li>
<li><strong>rails_migrations</strong> &#8211; for when you forget valid data types</li>
<li><strong>rubydebug</strong> &#8211; debugging is powerful but it&#8217;s easy to forget how</li>
<li><strong>rails_tips</strong> &#8211; nice reminders and tips for beginners</li>
<li><strong>jquery</strong> &#8211; you are using jQuery in your Rails apps, right?</li>
</ul>
<p>Let me know if you find any juicy cheats that I should know about.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/10/cheating-on-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>cd up, up, and a-up</title>
		<link>http://blog.jerodsanto.net/2009/09/cd-up-up-up/</link>
		<comments>http://blog.jerodsanto.net/2009/09/cd-up-up-up/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 23:10:44 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=634</guid>
		<description><![CDATA[Command-line jockeys are intimately familiar with the cd command. We&#8217;ve typed commands like this one a gozillion times: jerod@mbp:~/src/ruby/rails$ cd .. jerod@mbp:~/src/ruby$ We all know that . represents the current working directory and .. represents the current working directory&#8217;s parent directory. If we follow this pattern to its logical conclusion, then &#8230; would represent the [...]]]></description>
			<content:encoded><![CDATA[<p>Command-line jockeys are intimately familiar with the <strong><em>cd</em></strong> command. We&#8217;ve typed commands like this one a gozillion times:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~/src/ruby/rails$ cd ..
jerod@mbp:~/src/ruby$</pre></div></div>

<p>We all know that <strong><em>.</em></strong> represents the current working directory and <strong><em>..</em></strong> represents the current working directory&#8217;s parent directory. If we follow this pattern to its logical conclusion, then <strong><em>&#8230;</em></strong> would represent the current working directory&#8217;s parent&#8217;s parent, etc. Unfortunately, <strong><em>cd</em></strong> doesn&#8217;t work that way.<br />
<span id="more-634"></span></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~src/ruby/rails$ cd ...
-bash: cd: ...: No such file or directory
jerod@mbp:~$</pre></div></div>

<p>Total bummer!</p>
<p>Instead, we have to repeat ourselves for every directory up we want to move. So, we end up typing commands that look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~/src/ruby/rails$ cd ../..
jerod@mbp:~/src$</pre></div></div>

<p>The more directories up  to move in the file system, the more ridiculous the command becomes:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~/src/ruby/rails/box-office/app/models$ cd ../../../../..
jerod@mbp:~/src$</pre></div></div>

<p><strong>*note*</strong> <em>- in this contrived example, cd ~/src would be a much better way of navigating</em></p>
<p>If you&#8217;ve ever typed a command like that one, you feel my pain. I put up with this for a long time, but I&#8217;ve finally had enough of it. Here is a simple <strong>bash</strong> function that allows us to simply append <strong><em>.</em></strong>&#8216;s to the <strong><em>cd</em></strong> command for each directory we want to move up.</p>
<p><img src="http://blog.jerodsanto.net/wp-content/uploads/2009/09/bad_function.png" alt="bad_function" title="bad_function" width="645" height="296" class="alignnone size-full wp-image-659" /></p>
<p><strong>*update*</strong> &#8211; <a href="http://blog.jerodsanto.net/2009/09/cd-up-up-up/#comment-16188007">some guy</a> pointed out that my function didn&#8217;t correctly handle pathnames with spaces in it and he was kind enough to supply a simplified function to the one I wrote.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000; font-weight: bold;">function</span> <span style="color: #0086B3;">cd</span> <span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
  <span style="color: #000; font-weight: bold;">if</span> <span style="color: #000;">&#91;</span><span style="color: #000;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #000;">&gt;</span> <span style="color: #000000;">0</span> <span style="color: #000;">&#93;</span><span style="color: #000;">&#93;</span>; <span style="color: #000; font-weight: bold;">then</span>
    <span style="color: #000; font-weight: bold;">if</span> <span style="color: #000;">&#91;</span> <span style="color: #6F6F6F;">${1:0:2}</span> == <span style="color: #ff0000;">'..'</span> <span style="color: #000;">&#93;</span>; <span style="color: #000; font-weight: bold;">then</span>
      <span style="color: #007800;">rest</span>=<span style="color: #6F6F6F;">${1:2}</span>
      <span style="color: #007800;">rest</span>=<span style="color: #6F6F6F;">${rest//./../}</span>
      <span style="color: #0086B3;">builtin</span> <span style="color: #0086B3;">cd</span> <span style="color: #D14;">&quot;<span style="color: #007800;">${1:0:2}</span>/<span style="color: #007800;">${rest}</span>&quot;</span>
    <span style="color: #000; font-weight: bold;">else</span>
      <span style="color: #0086B3;">builtin</span> <span style="color: #0086B3;">cd</span> <span style="color: #D14;">&quot;$1&quot;</span>
    <span style="color: #000; font-weight: bold;">fi</span>
  <span style="color: #000; font-weight: bold;">else</span>
    <span style="color: #0086B3;">builtin</span> <span style="color: #0086B3;">cd</span>
  <span style="color: #000; font-weight: bold;">fi</span>
<span style="color: #000;">&#125;</span></pre></td></tr></table></div>

<p>This is a simple wrapper function that ends up calling the shell&#8217;s built-in <strong><em>cd</em></strong> command. Drop it in your <strong>.bashrc</strong> or <strong>.bash_profile</strong> and give it a whirl!</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~/src/ruby/rails$ cd ...
jerod@mbp:~/src$</pre></div></div>

<p>Much better!</p>
<p><strong>p.s. &#8211; </strong> I added this function to my <strong>.bashrc</strong> which I store in a <a href="http://github.com/sant0sk1/dotfiles/tree/master" rel="external">dotfiles repo on GitHub</a>. Feel free to check it out and see if there&#8217;s any other useful tricks you can add to your command-line r&eacute;pertoire.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/09/cd-up-up-up/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
