<?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>BSharpe dot com</title>
	<atom:link href="http://bsharpe.com/feed" rel="self" type="application/rss+xml" />
	<link>http://bsharpe.com</link>
	<description></description>
	<lastBuildDate>Fri, 13 Jan 2012 23:04:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CoronaSDK and SublimeText2 Build System</title>
		<link>http://bsharpe.com/misc/coronasdk-and-sublimetext2-build-system</link>
		<comments>http://bsharpe.com/misc/coronasdk-and-sublimetext2-build-system#comments</comments>
		<pubDate>Fri, 13 Jan 2012 21:20:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=21</guid>
		<description><![CDATA[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 &#8230; <a href="http://bsharpe.com/misc/coronasdk-and-sublimetext2-build-system">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<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>
<pre class="javascript PluGeSHin"><span class="br0">&#123;</span>
<span class="st0">&quot;cmd&quot;</span><span class="sy0">:</span> <span class="br0">&#91;</span><span class="st0">&quot;/Applications/CoronaSDK/simulator&quot;</span><span class="sy0">,</span><span class="st0">&quot;$file_path&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span>
<span class="st0">&quot;selector&quot;</span><span class="sy0">:</span> <span class="st0">&quot;source.lua&quot;</span>
<span class="br0">&#125;</span></pre>
<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>
]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/misc/coronasdk-and-sublimetext2-build-system/feed</wfw:commentRss>
		<slash:comments>1</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>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoronaSDK]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=18</guid>
		<description><![CDATA[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 &#8230; <a href="http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<img title="Kindle Fire" src="http://bsharpe.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>
]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/code/coronasdk-building-and-installing-on-a-kindle-fire/feed</wfw:commentRss>
		<slash:comments>0</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>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoronaSDK]]></category>

		<guid isPermaLink="false">http://bsharpe.com/?p=14</guid>
		<description><![CDATA[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 &#8230; <a href="http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>
<pre class="lua PluGeSHin"><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>
<p>Typical usage:</p>
<pre class="lua PluGeSHin"><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>
<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>
<pre>if fileExists("some_file.txt", system.DocumentsDirectory) then
  -- do something wonderful
end</pre>
<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>
]]></content:encoded>
			<wfw:commentRss>http://bsharpe.com/code/coronasdk-how-to-know-if-a-file-exists/feed</wfw:commentRss>
		<slash:comments>1</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>admin</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[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 &#8230; <a href="http://bsharpe.com/misc/switch-heroku-accounts">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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-4"></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:<br />
<code><br />
#!/bin/bash</p>
<p>heroku keys:clear &#038;&#038; rm ~/.heroku/credentials &#038;&#038; heroku list<br />
</code></p>
<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>
]]></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 environment 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>admin</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[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 &#8230; <a href="http://bsharpe.com/rails/optimize-your-rails-environment-on-os-x">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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="brush:bash">&gt;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 <a href="http://www.rubyenterpriseedition.com/" target="_blank">Ruby Enterprise Edition</a> for it&#8217;s efficiency as my default ruby.</p>
<pre class="brush:bash">&gt;rvm install ree
&gt;rvm use ree --default</pre>
<p>But I also like to have Ruby 1.9 around for the speed.</p>
<pre class="brush:bash">&gt;rvm install 1.9.1</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 class="brush:text">---
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 class="brush:bash">&gt;gem install rails mongrel</pre>
<p>and then the gems for the DB:</p>
<pre class="brush:bash">&gt;gem install pg</pre>
<p>and some convience gems:</p>
<pre class="brush:bash">&gt;gem install hirb wirble</pre>
<p>And some optional but useful gems:</p>
<pre class="brush:bash">&gt;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.  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>
<pre class="brush:ruby">require 'irb/completion'

# History
#require 'irb/ext/save-history'  #wirble does history
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

# Wirble is a plugin to colorize your irb, it's installed from a gem (gem install -y wirble)
require 'rubygems'
begin
  # load wirble
  require 'wirble'

  # start wirble (with color)
  Wirble.init
  Wirble.colorize
rescue LoadError =&gt; err
  warn "Couldn't load Wirble: #{err}"
end

ARGV.concat ["--readline", "--prompt-mode", "simple"]

# autoindent of code while typing it
IRB.conf[:AUTO_INDENT]=true

# Log to STDOUT if in Rails &amp;&amp; use HIRB if available
if ENV.include?('RAILS_ENV') &amp;&amp; !Object.const_defined?('RAILS_DEFAULT_LOGGER')
  begin
    require 'hirb'
    Hirb.enable
  rescue LoadError =&gt; err
    warn "No Hirb: #{err}"
  end
  require 'logger'
  RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end

# Easily print methods local to an object's class
class Object
  def local_methods
    (methods - Object.instance_methods).sort
  end
end

# copy a string to the clipboard
def pbcopy(string)
  `echo "#{string}" | pbcopy`
  string
end</pre>
<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>
<pre class="brush:bash"># Rails 1.0+
alias ss='script/server'
alias sc='script/console'
alias sg='script/generate'
alias sp='script/plugin'
alias tdl='tail -f log/development.log'
# Rails 2.0+
alias sdb='script/dbconsole'
# Rails 3.0+
alias sr='script/rails'
# Passenger
alias rr='touch tmp/restart.txt'

# Useful Git aliases
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gdm='git diff | mate'
alias gc='git commit -v'
alias gcam='git commit -v -a -m'
alias gb='git branch --color'
alias gba='git branch --color -a'
alias gaa='git add .'
alias gco='git checkout'
alias gsp='git svn dcommit'
alias gsl='git svn rebase'
alias gsf='git svn fetch'</pre>
<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>
]]></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>

