<?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>Ben Sharpe</title>
	<atom:link href="http://bsharpe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bsharpe.com</link>
	<description>Developer, Entrepreneur, Husband, Dad, Nomad</description>
	<lastBuildDate>Wed, 15 May 2013 16:16:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>ProTip for Corona: Finding Typos</title>
		<link>http://bsharpe.com/code/coronasdk/protip-for-corona-finding-typos/</link>
		<comments>http://bsharpe.com/code/coronasdk/protip-for-corona-finding-typos/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 14:04:47 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[CoronaSDK]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=22</guid>
		<description><![CDATA[<p>One of the most common mistakes in programming is typos.   Your brain wants to type one thing and your fingers another. In Corona (and Lua in general), variables aren&#8217;t declared explicitly before you use them.  When  Lua sees a variable name that you haven&#8217;t declared as local, it starts looking up the chain of [...]</p><p>The post <a href="http://bsharpe.com/code/coronasdk/protip-for-corona-finding-typos/">ProTip for Corona: Finding Typos</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>One of the most common mistakes in programming is typos.   Your brain wants to type one thing and your fingers another.</p>
<p>In Corona (and Lua in general), variables aren&#8217;t declared explicitly before you use them.  When  Lua sees a variable name that you haven&#8217;t declared as local, it starts looking up the chain of scopes until it reaches the Global namespace (_G).  If it gets there, it creates a key in the _G table with your variable name.</p>
<p>This little trick (shown to me by my friend Chris Blackwell) makes Corona tell you whenever this happens.  Sometimes it&#8217;s fine, but most of the time you&#8217;ll find a typo (as I did in the Particle Candy library).   I even found that loading the built-in JSON library causes it to check for a global called &#8220;Chipmunk.&#8221;  Granted, Chipmunk isn&#8217;t a typo, but it is accessing a variable that doesn&#8217;t exist.  This can happen if you&#8217;re check to see if something has been loaded or not.  In those cases this warning can be ignored.</p>
<p>So, put this in your app&#8217;s main.lua, run your app in the simulator and watch the console output.  You might just find a problem you didn&#8217;t know you had.</p>
<p><span style="color: #808080;">Note: You only want this in debug builds.  You could wrap it with a check for running on the simulator, but the best bet is to just remove it before building your final version.</span></p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="lua"><pre class="de1"><span class="kw1">local</span> globalsmeta <span class="sy0">=</span> <span class="br0">&#123;</span>
__index <span class="sy0">=</span> <span class="kw1">function</span><span class="br0">&#40;</span><span class="kw3">table</span><span class="sy0">,</span> key<span class="br0">&#41;</span>
<span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;!!! access to nonexistent global variable &quot;</span><span class="sy0">..</span><span class="kw3">tostring</span><span class="br0">&#40;</span>key<span class="br0">&#41;</span><span class="sy0">..</span><span class="st0">&quot;n&quot;</span><span class="sy0">..</span><span class="kw3">debug</span><span class="sy0">.</span>traceback<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="kw1">end</span>
<span class="br0">&#125;</span>
<span class="kw3">setmetatable</span><span class="br0">&#40;</span><span class="kw3">_G</span><span class="sy0">,</span> globalsmeta<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


<p>This works by adding a metatable to the Global namespace to call this function whenever you access an unknown key in its table.</p>
<p>&nbsp;</p>
<p>The post <a href="http://bsharpe.com/code/coronasdk/protip-for-corona-finding-typos/">ProTip for Corona: Finding Typos</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/code/coronasdk/protip-for-corona-finding-typos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CoronaSDK and SublimeText2 Build System</title>
		<link>http://bsharpe.com/code/coronasdk-and-sublimetext2-build-system/</link>
		<comments>http://bsharpe.com/code/coronasdk-and-sublimetext2-build-system/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 21:20:27 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoronaSDK]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=21</guid>
		<description><![CDATA[<p>[Update May 15, 2013 -  Fixed launcher for osx and windows] I&#8217;ve recently been trying out different editors as I can see the end of the road for TextMate from where I&#8217;m sitting.   I really wanted to be super-awesome and finally learn vi or emacs, but despite several attempts, my brain hasn&#8217;t really latched [...]</p><p>The post <a href="http://bsharpe.com/code/coronasdk-and-sublimetext2-build-system/">CoronaSDK and SublimeText2 Build System</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>[<em>Update May 15, 2013 -  Fixed launcher for osx and windows]</em></p>
<p>I&#8217;ve recently been trying out different editors as I can see the end of the road for TextMate from where I&#8217;m sitting.   I really wanted to be super-awesome and finally learn vi or emacs, but despite several attempts, my brain hasn&#8217;t really latched onto them like it did when TM came onto the scene.</p>
<p>Now there&#8217;s SublimeText 2 (in beta) which is starting to be the editor that TM wanted to be when it grew up.  There&#8217;s still a lot of funky things with it, but I can see the potential.  Not to mention it&#8217;s cross platform like the ancient gods vi and emacs.   I suppose that&#8217;s really just icing on the cake because I rarely leave my home platform for reasons other than duress (Windows) or curiosity (Linux).</p>
<p>The one thing I really missed from TM was the ability to launch the CoronaSDK simulator from the editor.   It&#8217;s fantastic to be able to edit a file and hit a button and have it fire up the simulator and then start reloading the simulator each time the file changes. (actually the simulator does that work for you)  I took a look at the Corona bundle for TM and found quite a few lines of AppleScript that are doing the work (i kid not).</p>
<h3>tl;dr</h3>
<p>In Sublime, select &#8220;Tools &gt; Build System &gt; New Build System&#8230;&#8221;</p>
<p>This opens up a new text file.  Copy and paste this into it:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="json"><pre class="de1">{
&quot;osx&quot; : {
&quot;cmd&quot;: [&quot;/Applications/CoronaSDK/Corona Simulator.app/Contents/MacOS/Corona Simulator&quot;,&quot;main.lua&quot;]
},
&quot;windows&quot; : {
&quot;cmd&quot;: [&quot;C:\Program Files\Corona Labs\Corona SDK\Corona Simulator.exe&quot;,&quot;main.lua&quot;]
},
&quot;file_regex&quot;: &quot;^[ ]*File &quot;(...*?)&quot;, line ([0-9]*)&quot;,
&quot;working_dir&quot;: &quot;${project_path:${folder}}&quot;,
&quot;selector&quot;: &quot;source.lua&quot;
}</pre></div></div></div></div></div></div></div>


<p>By setting the working_dir to the project folder and specifying &#8216;main.lua&#8217; as the file, you can launch the simulator for a project no matter what file you happen to be looking at (or in what subfolder).</p>
<p>Save the file as &#8220;CoronaSDK.sublime-build&#8221;</p>
<ol>
<li>Go to your Corona project</li>
<li>Open a file to edit</li>
<li>Select  Tools &gt; Build System &gt; CoronaSDK</li>
<li>Press Command-B</li>
<li>profit!</li>
</ol>
<p>For Reference,  custom build system files are usually stored in the following locations:</p>
<p><strong>OS X:</strong> <code>~/Library/Application Support/Sublime Text 2/Packages/User</code></p>
<p><strong>Windows:</strong> <code>%APPDATA%/Sublime Text 2/Packages/User</code></p>
<p>The post <a href="http://bsharpe.com/code/coronasdk-and-sublimetext2-build-system/">CoronaSDK and SublimeText2 Build System</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/code/coronasdk-and-sublimetext2-build-system/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CoronaSDK: Building and installing on a Kindle Fire</title>
		<link>http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire/</link>
		<comments>http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 20:09:46 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoronaSDK]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=18</guid>
		<description><![CDATA[<p>Build the app using  File &#62; Build &#62; Amazon/Kindle&#8230; On the Fire, go to Settings and tap More Tap Device Turn ON &#8220;Allow Installation of Applications &#8212; from unknown sources&#8221; Plug in a Micro-B usb cable into the Fire and the other into your computer (in this case a MacBook Air) The Kindle should be [...]</p><p>The post <a href="http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire/">CoronaSDK: Building and installing on a Kindle Fire</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></description>
				<content:encoded><![CDATA[<div>
<img title="Kindle Fire" src="http://bsharpe.wpengine.com/wp-content/uploads/2011/11/KO-aag-apps.jpeg" alt="Amazon's Kindle Fire" width="470" height="240" /></div>
<div><span style="font-size: 14px; line-height: 23px;"><br />
</span></div>
<ol>
<li>Build the app using  File &gt; Build &gt; Amazon/Kindle&#8230;</li>
<li>On the Fire, go to Settings and tap More</li>
<li>Tap Device</li>
<li>Turn ON &#8220;Allow Installation of Applications &#8212; from unknown sources&#8221;</li>
<li>Plug in a Micro-B usb cable into the Fire and the other into your computer (in this case a MacBook Air)</li>
<li>The Kindle should be showing up on your desktop</li>
<li>Copy the .apk file generated by Corona onto the Kindle (I&#8217;m not sure that it makes a difference where &#8212; I used the &#8220;downloads&#8221; folder)</li>
<li>Eject the Kindle from the Mac</li>
<li>On the Kindle you&#8217;ll need a File management application installed (I used &#8220;ES File Explorer&#8221; because it was free and had the most reviews)</li>
<li>Use the File manager to find your app and tap it to install it</li>
<li>Profit!</li>
</ol>
<p>The post <a href="http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire/">CoronaSDK: Building and installing on a Kindle Fire</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CoronaSDK: How to know if a file exists?</title>
		<link>http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists/</link>
		<comments>http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 20:38:19 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoronaSDK]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=14</guid>
		<description><![CDATA[<p>Update: Dejay was correct, you have to try and open the file to know for sure if it&#8217;s there or not. Want to know if a file exists before you use it? Lately, I&#8217;ve been wanting something a little more dynamic in my projects for opening various Scenes (think Director, but not).   I needed [...]</p><p>The post <a href="http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists/">CoronaSDK: How to know if a file exists?</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><em>Update: Dejay was correct, you have to try and open the file to know for sure if it&#8217;s there or not.</em></p>
<p>Want to know if a file exists before you use it?</p>
<p>Lately, I&#8217;ve been wanting something a little more dynamic in my projects for opening various Scenes (think <a title="Directory" href="http://rauberlabs.blogspot.com/2011/08/director-14-books.html" target="_blank">Director</a>, but not).   I needed a way of looking to see if a file existed or not before I tried to load it up.  Here&#8217;s the result:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="lua"><pre class="de1"><span class="kw1">function</span> fileExists<span class="br0">&#40;</span>fileName<span class="sy0">,</span> base<span class="br0">&#41;</span>
  <span class="kw3">assert</span><span class="br0">&#40;</span>fileName<span class="sy0">,</span> <span class="st0">&quot;fileName is missing&quot;</span><span class="br0">&#41;</span>
  <span class="kw1">local</span> base <span class="sy0">=</span> base <span class="kw2">or</span> system<span class="sy0">.</span>ResourceDirectory
  <span class="kw1">local</span> filePath <span class="sy0">=</span> system<span class="sy0">.</span>pathForFile<span class="br0">&#40;</span> fileName<span class="sy0">,</span> base <span class="br0">&#41;</span>
  <span class="kw1">local</span> exists <span class="sy0">=</span> <span class="kw4">false</span>
&nbsp;
  <span class="kw1">if</span> <span class="br0">&#40;</span>filePath<span class="br0">&#41;</span> <span class="kw1">then</span> <span class="co1">-- file may exist. won't know until you open it</span>
    <span class="kw1">local</span> fileHandle <span class="sy0">=</span> <span class="kw3">io.open</span><span class="br0">&#40;</span> filePath<span class="sy0">,</span> <span class="st0">&quot;r&quot;</span> <span class="br0">&#41;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span>fileHandle<span class="br0">&#41;</span> <span class="kw1">then</span> <span class="co1">-- nil if no file found</span>
      exists <span class="sy0">=</span> <span class="kw4">true</span>
      <span class="kw3">io.close</span><span class="br0">&#40;</span>fileHandle<span class="br0">&#41;</span>
    <span class="kw1">end</span>
  <span class="kw1">end</span>
&nbsp;
  <span class="kw1">return</span><span class="br0">&#40;</span>exists<span class="br0">&#41;</span>
<span class="kw1">end</span></pre></div></div></div></div></div></div></div>


<p>Typical usage:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="lua"><pre class="de1"><span class="kw1">if</span> fileExists<span class="br0">&#40;</span><span class="st0">&quot;myGame.lua&quot;</span><span class="br0">&#41;</span> <span class="kw1">then</span>
  <span class="co1">-- do something wonderful</span>
<span class="kw1">end</span></pre></div></div></div></div></div></div></div>


<p>If the file does not exist, the <a href="http://anscamobile.com" target="_blank">CoronaSDK</a> library function <code><a href="http://developer.anscamobile.com/reference/index/systempathforfile" target="_blank">system.pathForFile()</a></code> returns <code>nil</code>.  It also returns a Warning in the console, which can be safely ignored.</p>
<p>By default it checks your app&#8217;s asset directory (system.ResourceDirectory), however, if you&#8217;d like to check if a file you created exists you can pass in an alternative base path like so:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="lua"><pre class="de1"><span class="kw1">if</span> fileExists<span class="br0">&#40;</span><span class="st0">&quot;some_file.txt&quot;</span><span class="sy0">,</span> system<span class="sy0">.</span>DocumentsDirectory<span class="br0">&#41;</span> <span class="kw1">then</span>
  <span class="co1">-- do something wonderful</span>
<span class="kw1">end</span></pre></div></div></div></div></div></div></div>


<p>The three valid options for base path are:</p>
<ol>
<li><a href="http://developer.anscamobile.com/reference/index/system/systemresourcedirectory" target="_blank">system.ResourceDirectory</a></li>
<li><a href="http://developer.anscamobile.com/reference/index/system/systemdocumentsdirectory" target="_blank">system.DocumentsDirectory</a></li>
<li><a href="http://developer.anscamobile.com/reference/index/system/systemtemporarydirectory" target="_blank">system.TemporaryDirectory</a></li>
</ol>
<p>The post <a href="http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists/">CoronaSDK: How to know if a file exists?</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Switching Heroku Accounts</title>
		<link>http://bsharpe.com/misc/switch-heroku-accounts/</link>
		<comments>http://bsharpe.com/misc/switch-heroku-accounts/#comments</comments>
		<pubDate>Thu, 06 May 2010 23:13:17 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=4</guid>
		<description><![CDATA[<p>Update April 2011: I now use the Heroku Plus gem to manage these accounts. I have several Heroku accounts that I need to switch between for clients. I&#8217;ve been doing it by hand for a while, and then I remembered that I could just write a bash script to make a command for my forgetful [...]</p><p>The post <a href="http://bsharpe.com/misc/switch-heroku-accounts/">Switching Heroku Accounts</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></description>
				<content:encoded><![CDATA[<blockquote><p><em>Update April 2011</em>: I now use the <a href="https://github.com/bkuhlmann/heroku_plus">Heroku Plus</a> gem to manage these accounts.</p></blockquote>
<p><span id="more-6"></span></p>
<p>I have several <a href="http://heroku.com">Heroku</a> accounts that I need to switch between for clients.   I&#8217;ve been doing it by hand for a while, and then I remembered that<em> I could just write a bash script to make a command for my forgetful brain</em>.</p>
<p>The basic steps are:</p>
<ul>
<li><code>>heroku keys:clear</code></li>
<li><code>>rm ~/.heroku/credentials</code></li>
<li><code>>heroku list</code></li>
</ul>
<p>So, my little bash script is:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/bin/bash</span>
&nbsp;
heroku keys:clear <span class="sy0">&amp;&amp;</span> <span class="kw2">rm</span> ~<span class="sy0">/</span>.heroku<span class="sy0">/</span>credentials <span class="sy0">&amp;&amp;</span> heroku list</pre></div></div></div></div></div></div></div>


<p>do a quick<br />
<code>>chmod 775 switch_heroku</code></p>
<p>and now I can switch with that simple command.<br />
<em>This is on OS X.  Probably very similar on Linux.  No idea on windows.</em></p>
<p>The post <a href="http://bsharpe.com/misc/switch-heroku-accounts/">Switching Heroku Accounts</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/misc/switch-heroku-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimize your Rails on OS X</title>
		<link>http://bsharpe.com/rails/optimize-your-rails-environment-on-os-x/</link>
		<comments>http://bsharpe.com/rails/optimize-your-rails-environment-on-os-x/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 23:21:09 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=3</guid>
		<description><![CDATA[<p>Getting your development environment setup just the way you like it takes some time.   I&#8217;ve done it several times recently and this is the setup I feel most productive with. The Basics While I could talk you through the whole enchilada. Robby Russell over at Planet Argon has already done this. He&#8217;s done an excellent [...]</p><p>The post <a href="http://bsharpe.com/rails/optimize-your-rails-environment-on-os-x/">Optimize your Rails on OS X</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Getting your development environment setup just the way you like it takes some time.   I&#8217;ve done it several times recently and this is the setup I feel most productive with.<br />
<span id="more-3"></span></p>
<h2>The Basics</h2>
<p>While I could talk you through the whole enchilada.  Robby Russell over at Planet Argon <a href="http://www.robbyonrails.com/articles/2010/02/08/installing-ruby-on-rails-passenger-postgresql-mysql-oh-my-zsh-on-snow-leopard-fourth-edition" target="_blank">has already done this</a>.  He&#8217;s done an excellent job of updating this guide over the years, and it&#8217;s usually the first place I go with a new installation.   Someday, I&#8217;m sure I&#8217;ll have it memorized.</p>
<h2>Ruby</h2>
<p>While you can use the built-in ruby on Snow Leopard, I like to look forward to the day when we&#8217;re all 30% faster simply by deploying on Ruby 1.9.  I use it in development for that very reason.  However, most clients like to use Ruby Enterprise Edition because it&#8217;s so efficient and stable.  Therefore, we need to switch between versions easily.   Enter the <a href="http://rvm.beginrescueend.com/" target="_blank">Ruby Version Manager</a>.</p>
<pre class="bash">>sudo gem install rvm</pre>
<p>RVM not only keeps your system clean, but it allows for easy switching between versions of ruby.</p>
<p>For most cases I like to use the 1.9.3 as my default ruby.</p>
<pre lan="bash">&gt;rvm install 1.9.3
&gt;rvm use 1.9.3 --default</pre>
<p>But I also like to have Ruby 2.0 around for the speed.</p>
<pre class="brush:bash">&gt;rvm install 2.0</pre>
<h2>Gems</h2>
<p>Make sure rubygems is up to date.</p>
<pre class="brush:bash">&gt;gem update --system</pre>
<p>Edit your ~/.gemrc file to contain something like the following:</p>
<pre>---
gem: --no-ri --no-rdoc
:benchmark: false
:backtrace: false
:update_sources: true
:verbose: true
:bulk_threshold: 1000
:sources:
- http://gems.rubyforge.org</pre>
<p>The most important reason to do this is for that second line.  It stops gem from installing the ri and rdoc documentation which I never use anyway.  This speeds up gem installation considerably.</p>
<p>Since we&#8217;re using RVM which keeps separate gem directories for each version of Ruby, you&#8217;ll need to install a few gems. (Even if you went through this from Robby&#8217;s instructions)</p>
<p>The most basic gems first:</p>
<pre>>gem install rails mongrel</pre>
<p>and then the gems for the DB:</p>
<pre">>gem install pg</pre>
<p>and some convience gems:</p>
<pre class="brush:bash">>gem install hirb wirble</pre>
<p>And some optional but useful gems:</p>
<pre class="brush:bash">>gem install haml compass thin cheat</pre>
<p><a href="http://haml-lang.com/" target="_blank">Haml</a> is a huge HTML productivity booster.<br />
<a href="http://wiki.github.com/chriseppstein/compass/" target="_blank"> Compass</a> (and Blueprint) is a huge CSS productivity booster.<br />
<a href="http://code.macournoyer.com/thin/" target="_blank"> Thin</a> is a super-fast webserver for testing and such (doesn&#8217;t tail the log like mongrel or webrick).<br />
<a href="http://cheat.errtheblog.com/" target="_blank"> Cheat</a> is an awesome command-line tool. </p>
<p> If I had a nickle for everytime i&#8217;ve typed:</p>
<pre class="brush:bash">&gt;cheat strftime</pre>
<p>I&#8217;d be rich.</p>
<h2>Tweaks</h2>
<p>Put a file in your home directory called .irbrc and have it include the following:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="ruby"><pre class="de1"><span class="kw3">require</span> <span class="st0">'irb/completion'</span>
&nbsp;
<span class="co1"># History</span>
<span class="co1">#require 'irb/ext/save-history'  #wirble does history</span>
IRB.<span class="me1">conf</span><span class="br0">&#91;</span><span class="re3">:SAVE_HISTORY</span><span class="br0">&#93;</span> = <span class="nu0">100</span>
IRB.<span class="me1">conf</span><span class="br0">&#91;</span><span class="re3">:HISTORY_FILE</span><span class="br0">&#93;</span> = <span class="st0">&quot;#{ENV['HOME']}/.irb-save-history&quot;</span>
&nbsp;
<span class="co1"># Wirble is a plugin to colorize your irb, it's installed from a gem (gem install -y wirble)</span>
<span class="kw3">require</span> <span class="st0">'rubygems'</span>
<span class="kw1">begin</span>
  <span class="co1"># load wirble</span>
  <span class="kw3">require</span> <span class="st0">'wirble'</span>
&nbsp;
  <span class="co1"># start wirble (with color)</span>
  Wirble.<span class="me1">init</span>
  Wirble.<span class="me1">colorize</span>
<span class="kw1">rescue</span> <span class="kw4">LoadError</span> =<span class="sy0">&amp;</span>gt; err
  warn <span class="st0">&quot;Couldn't load Wirble: #{err}&quot;</span>
<span class="kw1">end</span>
&nbsp;
ARGV.<span class="me1">concat</span> <span class="br0">&#91;</span><span class="st0">&quot;--readline&quot;</span>, <span class="st0">&quot;--prompt-mode&quot;</span>, <span class="st0">&quot;simple&quot;</span><span class="br0">&#93;</span>
&nbsp;
<span class="co1"># autoindent of code while typing it</span>
IRB.<span class="me1">conf</span><span class="br0">&#91;</span><span class="re3">:AUTO_INDENT</span><span class="br0">&#93;</span>=<span class="kw2">true</span>
&nbsp;
<span class="co1"># Log to STDOUT if in Rails &amp;amp;&amp;amp; use HIRB if available</span>
<span class="kw1">if</span> ENV.<span class="kw1">include</span>?<span class="br0">&#40;</span><span class="st0">'RAILS_ENV'</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp;<span class="sy0">&amp;</span>amp; !<span class="kw4">Object</span>.<span class="me1">const_defined</span>?<span class="br0">&#40;</span><span class="st0">'RAILS_DEFAULT_LOGGER'</span><span class="br0">&#41;</span>
  <span class="kw1">begin</span>
    <span class="kw3">require</span> <span class="st0">'hirb'</span>
    Hirb.<span class="me1">enable</span>
  <span class="kw1">rescue</span> <span class="kw4">LoadError</span> =<span class="sy0">&amp;</span>gt; err
    warn <span class="st0">&quot;No Hirb: #{err}&quot;</span>
  <span class="kw1">end</span>
  <span class="kw3">require</span> <span class="st0">'logger'</span>
  RAILS_DEFAULT_LOGGER = <span class="kw4">Logger</span>.<span class="me1">new</span><span class="br0">&#40;</span>STDOUT<span class="br0">&#41;</span>
<span class="kw1">end</span>
&nbsp;
<span class="co1"># Easily print methods local to an object's class</span>
<span class="kw1">class</span> <span class="kw4">Object</span>
  <span class="kw1">def</span> local_methods
    <span class="br0">&#40;</span>methods <span class="sy0">-</span> <span class="kw4">Object</span>.<span class="me1">instance_methods</span><span class="br0">&#41;</span>.<span class="me1">sort</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="co1"># copy a string to the clipboard</span>
<span class="kw1">def</span> pbcopy<span class="br0">&#40;</span><span class="kw3">string</span><span class="br0">&#41;</span>
  <span class="st0">`echo &quot;#{string}&quot; | pbcopy`</span>
  <span class="kw3">string</span>
<span class="kw1">end</span></pre></div></div></div></div></div></div></div>


<p>This turns on Hirb/Wirble for the ruby console as well as colorization, history and redirecting the logger to the console for Rails.  This is very handy to see what Rails is doing with your database while you&#8217;re issuing commands in the console.</p>
<p>And lastly, some handy Bash aliases that really help speed up Rails work.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0"># Rails 1.0+</span>
<span class="kw3">alias</span> <span class="re2">ss</span>=<span class="st_h">'script/server'</span>
<span class="kw3">alias</span> <span class="re2">sc</span>=<span class="st_h">'script/console'</span>
<span class="kw3">alias</span> <span class="re2">sg</span>=<span class="st_h">'script/generate'</span>
<span class="kw3">alias</span> <span class="re2">sp</span>=<span class="st_h">'script/plugin'</span>
<span class="kw3">alias</span> <span class="re2">tdl</span>=<span class="st_h">'tail -f log/development.log'</span>
<span class="co0"># Rails 2.0+</span>
<span class="kw3">alias</span> <span class="re2">sdb</span>=<span class="st_h">'script/dbconsole'</span>
<span class="co0"># Rails 3.0+</span>
<span class="kw3">alias</span> <span class="re2">sr</span>=<span class="st_h">'script/rails'</span>
<span class="co0"># Passenger</span>
<span class="kw3">alias</span> <span class="re2">rr</span>=<span class="st_h">'touch tmp/restart.txt'</span>
&nbsp;
<span class="co0"># Useful Git aliases</span>
<span class="kw3">alias</span> <span class="re2">gst</span>=<span class="st_h">'git status'</span>
<span class="kw3">alias</span> <span class="re2">gl</span>=<span class="st_h">'git pull'</span>
<span class="kw3">alias</span> <span class="re2">gp</span>=<span class="st_h">'git push'</span>
<span class="kw3">alias</span> <span class="re2">gdm</span>=<span class="st_h">'git diff | mate'</span>
<span class="kw3">alias</span> <span class="re2">gc</span>=<span class="st_h">'git commit -v'</span>
<span class="kw3">alias</span> <span class="re2">gcam</span>=<span class="st_h">'git commit -v -a -m'</span>
<span class="kw3">alias</span> <span class="re2">gb</span>=<span class="st_h">'git branch --color'</span>
<span class="kw3">alias</span> <span class="re2">gba</span>=<span class="st_h">'git branch --color -a'</span>
<span class="kw3">alias</span> <span class="re2">gaa</span>=<span class="st_h">'git add .'</span>
<span class="kw3">alias</span> <span class="re2">gco</span>=<span class="st_h">'git checkout'</span>
<span class="kw3">alias</span> <span class="re2">gsp</span>=<span class="st_h">'git svn dcommit'</span>
<span class="kw3">alias</span> <span class="re2">gsl</span>=<span class="st_h">'git svn rebase'</span>
<span class="kw3">alias</span> <span class="re2">gsf</span>=<span class="st_h">'git svn fetch'</span></pre></div></div></div></div></div></div></div>


<h2>Appendix A: Use the OS X Dictionary for Rails Documentation.</h2>
<p><a href="http://priithaamer.com/blog/ruby-on-rails-dictionary-for-macosx" target="_blank">Priit Haamer created a OS X dictionary file of the Rails API documentation</a> which is oh so handy.  I use it constantly as it&#8217;s faster that firing up a browser and works anywhere (with or without interweb access).</p>
<h2>Conclusion</h2>
<p>I hope this helps you get optimized with your Rails development.   Please let me know if you have additions or need clarification on some of the items here.</p>
<p>The post <a href="http://bsharpe.com/rails/optimize-your-rails-environment-on-os-x/">Optimize your Rails on OS X</a> appeared first on <a href="http://bsharpe.com">Ben Sharpe</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/rails/optimize-your-rails-environment-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
