<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator uri="http://jekyllrb.com" version="2.4.0">Jekyll</generator>
<link href="http://donwilson.net/feed.xml" rel="self" type="application/atom+xml" />
<link href="http://donwilson.net/" rel="alternate" type="text/html" />
<updated>2015-10-03T19:22:55+00:00</updated>
<id>http://donwilson.net/</id>
<subtitle>Things Don Wilson said.</subtitle>
<author>
<name>Don Wilson</name>
</author>
<entry>
<title>Blackbird! - A Game for Rook fans on iPhone, iPad, and iPod Touch</title>
<link href="http://donwilson.net/2012/10/blackbird-a-game-for-rook-fans-on-iphone-ipad-and-ipod-touch/" rel="alternate" type="text/html" title="Blackbird! - A Game for Rook fans on iPhone, iPad, and iPod Touch" />
<published>2012-10-31T04:55:57+00:00</published>
<updated>2012-10-31T04:55:57+00:00</updated>
<id>http://donwilson.net/2012/10/blackbird-a-game-for-rook-fans-on-iphone-ipad-and-ipod-touch</id>
<content type="html" xml:base="http://donwilson.net/2012/10/blackbird-a-game-for-rook-fans-on-iphone-ipad-and-ipod-touch/">&lt;p&gt;Just to get this out of the way: I am not affiliated with Hasbro!&lt;/p&gt;

&lt;p&gt;It has been a month now since my iOS card game app based on Rook,
&lt;a href=&quot;https://itunes.apple.com/us/app/blackbird!/id563960217?ls=1&amp;amp;mt=8&quot;&gt;Blackbird&lt;/a&gt;,
has been approved in the App Store. It has been a blast! It is definitely the
funnest project that I have worked on. I think that is mainly due to the fact
that I did it all myself and the App Store is a big market. Well, I can’t
really say that because I’ve had lots of input and help with testing from
friends and family - mostly my dad who is a big Rook fan. I thought I’d just
write up a quick post on some things I’ve learned, and throw in some app
statistics.&lt;/p&gt;

&lt;h3 id=&quot;some-things-i-have-learned&quot;&gt;Some things I have learned&lt;/h3&gt;

&lt;p&gt;I chose to write an iOS app simply because I have an iPhone and most of my
family have iPhones.&lt;/p&gt;

&lt;p&gt;I didn’t use a cross-platform developer tool like Titanium that would allow me
to write code once and deploy to iOS and Android. This was a very hard decision
for me, but I’m glad I went the XCode/Objective C route. Here are my reasons:
(Whenever I say, “Titanium”, I really mean any project like it. They all work
very similarly.)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The Objective C language is really growing on me. It’s very different at
first and has some concepts that are unlike any language that I’d learned
before. But I really like it now. So I’m glad I took the time to learn.&lt;/li&gt;
  &lt;li&gt;I have a computer playing AI that I want to be as fast as possible. Even
though they translate the JavaScript into native code, I can write native
code that performs faster for my specific tasks than Titanium can. I feel
comfortable that when I need to work on performance, I can get every inch of
performance possible.&lt;/li&gt;
  &lt;li&gt;I have a problem feeling restricted to the currently implemented features. I
worry about running into a situation where I want to use a feature that is
supported by the platform, but not implemented by Titanium. This may be an
irrational fear, but I still have it.&lt;/li&gt;
  &lt;li&gt;I have recently talked to people who have worked on Titanium projects and
they have told me that they both love it and hate it. They say that some bugs
are really hard to track down because you’re not sure if the bug is in your
code or theirs. They also say that you still end up writing a lot of
platform-specific code. You also have to pay for their nicer versions and you
have to write modules to support native iOS features that aren’t yet
implemented by Titanium.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The up side of writing in a language I’m already familiar with (JavaScript) and
deploying to multiple platforms at the same time just isn’t worth it &lt;strong&gt;to me&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When I released the app, it had relatively few features. I knew that there were
several things that would be in high demand, but I released it without them
anyways. I’m really glad I made that decision. The feedback has poured in and
it has definitely steered me in a different direction that I would have taken
on my own.&lt;/p&gt;

&lt;p&gt;I haven’t done any marketing yet. I’ll be interested to see if I can get some
app review sites to review my app and what effect that will have. I expect that
a multi-player mode and a universal app will also have a big impact. So, I’m
excited for the future!&lt;/p&gt;

&lt;h3 id=&quot;statistics&quot;&gt;Statistics&lt;/h3&gt;

&lt;p&gt;Here are several statistics so far:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Initially approved for sale in the App Store: Sept 29, 2012&lt;/li&gt;
  &lt;li&gt;Total downloads: 561&lt;/li&gt;
  &lt;li&gt;Updates approved: 3&lt;/li&gt;
  &lt;li&gt;App store rejections: 0&lt;/li&gt;
  &lt;li&gt;Most sessions in 1 day: 979&lt;/li&gt;
  &lt;li&gt;Median session length: 6.3 mins&lt;/li&gt;
  &lt;li&gt;Total time spent in app yesterday: 5 days 14 hours&lt;/li&gt;
  &lt;li&gt;iOS versions: 88.9% iOS 6.0, 10% iOS 5.1.1, 1% iOS 5.1 (my app requires iOS 5.1)&lt;/li&gt;
  &lt;li&gt;Users with a device that cannot upgrade to iOS 6: 1%&lt;/li&gt;
  &lt;li&gt;Countries of users: USA, Canada, Japan, Australia, Hong Kong, Kuwait&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;update---nov-28-2013&quot;&gt;Update - Nov 28, 2013&lt;/h3&gt;

&lt;p&gt;There is now an Android version of
&lt;a href=&quot;https://play.google.com/store/apps/details?id=net.donwilson.blackbird&quot;&gt;Blackbird&lt;/a&gt;
in the Google Play store!&lt;/p&gt;

&lt;p&gt;It is also under review in the Amazon store.&lt;/p&gt;
</content>
<category term="iPhone" />
<category term="iOS" />
<category term="Objective-C" />
<summary>Just to get this out of the way: I am not affiliated with Hasbro!</summary>
</entry>
<entry>
<title>How to Setup Reactive Cocoa (RAC) for Use in Your iOS App</title>
<link href="http://donwilson.net/2012/06/how-to-setup-reactive-rac-cocoa-for-use-in-your-ios-app/" rel="alternate" type="text/html" title="How to Setup Reactive Cocoa (RAC) for Use in Your iOS App" />
<published>2012-06-28T06:28:03+00:00</published>
<updated>2012-06-28T06:28:03+00:00</updated>
<id>http://donwilson.net/2012/06/how-to-setup-reactive-rac-cocoa-for-use-in-your-ios-app</id>
<content type="html" xml:base="http://donwilson.net/2012/06/how-to-setup-reactive-rac-cocoa-for-use-in-your-ios-app/">&lt;p&gt;I am writing an iOS app and I found
&lt;a href=&quot;https://github.com/github/ReactiveCocoa&quot;&gt;GitHub’s Reactive Cocoa&lt;/a&gt; very helpful.&lt;/p&gt;

&lt;p&gt;There isn’t any documentation on the ReactiveCocoa README on how to install it
and there are many ways. I tried &lt;a href=&quot;http://cocoapods.org/&quot;&gt;CocoaPods&lt;/a&gt; but it
added and changed a whole bunch of stuff.  It made me uncomfortable, and I’m
the kind of person that likes to know exactly what’s going on, so I decided to
do it on my own. I did it the same way the RACiOSDemo project was setup.&lt;/p&gt;

&lt;h4 id=&quot;create-a-git-submodule&quot;&gt;Create a Git submodule&lt;/h4&gt;

&lt;p&gt;Create a folder called external in the project’s root folder. Then, run this to
add the submodule:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git submodule add https://github.com/ReactiveCocoa/ReactiveCocoa.git external/ReactiveCocoa
$ git add .gitmodules external/ReactiveCocoa
$ git commit -m “Add ReactiveCocoa as a submodule”
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;If you’re not familiar with submodules, submodules are simply a way of
embedding a git repository inside another. If you’re still curious, I recommend
reading the 
&lt;a href=&quot;http://git-scm.com/book/en/Git-Tools-Submodules&quot;&gt;Git book’s chapter on submodules&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, anytime you clone your repository, you’ll also need to run these two
commands to set up the submodule again:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git submodule init
$ git submodule update
{% endhighlight %}&lt;/p&gt;

&lt;h4 id=&quot;setup-reactivecocoa-correctly-in-your-project&quot;&gt;Setup ReactiveCocoa correctly in your project&lt;/h4&gt;

&lt;p&gt;Next we need to get the project to appear and build inside our project. In your
XCode project, right-click on the Frameworks folder and choose “Add Files to
[project]…”. Navigate to external/ReactiveCocoa/ReactiveCocoaFramework and
choose ReactiveCocoa.xcodeproj.&lt;/p&gt;

&lt;p&gt;Now we need to setup the our project’s main target to link to the framework.
Click on your project in the project explorer. Then, click on your main target
and make sure you’re on the Summary tab. Scroll down to the “Linked Frameworks
and Libraries” section. Click the plus and add libReactiveCocoa-iOS.a.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;{{ site.baseUrl }}/assets/libReactiveCocoa.png&quot; alt=&quot;Linking to libReactiveCocoa-iOS.a&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Apparently, for now, we also need to add a linker switch for it to compile the
ReactiveCocoa stuff correctly. Go to the Build Settings tab now and scroll down
to the “Linking” section. Find the “Other Linker Flags” setting and
double-click in the field to the right. Add the -ObjC flag and the -all_load
flags.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;{{ site.baseUrl }}/assets/cocoa-linker-flags.png&quot; alt=&quot;Adding linker switch for ReactiveCocoa&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The last thing we need to do is tell XCode where to look for the framework and
header files. Still in the Build Settings tab, scroll down to the “Search
Paths” section. Find the “Framework Search Paths” and enter the value,
“$(PROJECT_DIR)/external/ReactiveCocoa/ReactiveCocoaFramework”. Then put the
same value in for the “Header Search Path”.&lt;/p&gt;

&lt;p&gt;That’s it. Now, you can happily use Reactive Cocoa all you want!&lt;/p&gt;
</content>
<category term="ReactiveCocoa" />
<category term="RAC" />
<category term="Objective-C" />
<summary>I am writing an iOS app and I foundGitHub’s Reactive Cocoa very helpful.</summary>
</entry>
<entry>
<title>Deploying A Rails App To Rackspace Cloud Servers On Ubuntu Using Nginx and Unicorn</title>
<link href="http://donwilson.net/2012/04/deploying-a-rails-app-to-rackspace-cloud-servers-using-nginx-and-unicorn/" rel="alternate" type="text/html" title="Deploying A Rails App To Rackspace Cloud Servers On Ubuntu Using Nginx and Unicorn" />
<published>2012-04-05T01:00:02+00:00</published>
<updated>2012-04-05T01:00:02+00:00</updated>
<id>http://donwilson.net/2012/04/deploying-a-rails-app-to-rackspace-cloud-servers-using-nginx-and-unicorn</id>
<content type="html" xml:base="http://donwilson.net/2012/04/deploying-a-rails-app-to-rackspace-cloud-servers-using-nginx-and-unicorn/">&lt;p&gt;I recently setup a Rails server on Ubuntu using Nginx and Unicorn and a
database running on the same server using Postgres. I also used rbenv and
ruby-build for ruby. I had to look up a lot of information to get this all
working. I just wanted to consolidate everything I did into one place.
Hopefully, all this can help someone else.&lt;/p&gt;

&lt;p&gt;Here are some links to the different parts of this post:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#why-these&quot;&gt;Why use these technologies?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#configure-server&quot;&gt;The server&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#postgresql&quot;&gt;PostgreSQL&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#nginx&quot;&gt;Nginx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#unicorn&quot;&gt;Unicorn&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#capistrano&quot;&gt;Capistrano&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some resources I used to get everything setup the way I wanted:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://sirupsen.com/setting-up-unicorn-with-nginx/&quot;&gt;Setting up Unicorn with Nginx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://help.ubuntu.com/community/PostgreSQL&quot;&gt;Setting up PostgreSQL on Ubuntu&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://ariejan.net/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn&quot;&gt;Lighting fast, zero-downtime deployments with git, capistrano, nginx and Unicorn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I took my approach from many different places and I’ll explain why I did what I
did.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt; - I have since watched a few Railscasts that are very well done and
explain most of the same concepts. There are several things that he recommends
doing that I will definitely do. He is charging money to see those episodes
($9/month), so I would feel a little guilty posting what I learned here.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://railscasts.com/episodes/335-deploying-to-a-vps&quot;&gt;Deploying To A VPS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://railscasts.com/episodes/293-nginx-unicorn&quot;&gt;Nginx &amp;amp; Unicorn&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://railscasts.com/episodes/337-capistrano-recipes&quot;&gt;Capistrano Recipes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;why-these&quot;&gt;Why use these technologies?&lt;/h3&gt;

&lt;h4 id=&quot;hosting&quot;&gt;Hosting&lt;/h4&gt;

&lt;p&gt;Originally, I wanted to host my website on &lt;strong&gt;Heroku&lt;/strong&gt;. Heroku is
easy, awesome, and really simple. One web dyno is free and it can scale really
easily. For the foreseeable future, however, I will have very low traffic and I
want it to be as cheap as possible.&lt;/p&gt;

&lt;p&gt;My problem with Heroku came when I realized that I needed more than 5MB of
database space. The next tier up gives me 20GB and costs $15/month. This is way
more space than I need and costs a lot more than I want to pay.&lt;/p&gt;

&lt;p&gt;So, I started looking at VPS hosting since I can get a cheap VPS and have more
than 5MB of space for my database, plus I can use it to run jobs if I want,
etc. I looked at the cheapest offered solutions at Linode, Dreamhhost,
MediaTemple, Amazon, and Rackspace. Rackspace beats them all with 256MB of RAM
and 10GB Disk for $11/month + $0.18/GB of bandwidth. I highly doubt that I’ll
even use 1GB of bandwidth. Plus, if I do need to scale, it will be really easy
to do it with Rackspace Cloud Servers.&lt;/p&gt;

&lt;h4 id=&quot;web-framework&quot;&gt;Web Framework&lt;/h4&gt;

&lt;p&gt;Honestly, my main reason for doing my site in Rails is because I love Ruby and
Rails is fun to work in.&lt;/p&gt;

&lt;h4 id=&quot;http-server&quot;&gt;Http Server&lt;/h4&gt;

&lt;p&gt;My reasons are better stated by others:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://cmelbye.github.com/2009/10/04/thin-vs-unicorn.html&quot;&gt;Thin vs. Unicorn&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/blog/517-unicorn&quot;&gt;Unicorn!&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://labs.revelationglobal.com/2009/10/06/mongrel_passenger_unicorn.html&quot;&gt;Mongrel vs. Passenger vs. Unicorn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since this is for a low traffic site, I went on the word of others. If I was
expecting a lot of traffic, I probably would have done more research and some
of my own benchmarks. That said, I do feel pretty confident in this setup even
though I didn’t do that. Let’s get started!&lt;/p&gt;

&lt;h3 id=&quot;configure-server&quot;&gt;Configure the server&lt;/h3&gt;

&lt;h4 id=&quot;get-a-server-with-ubuntu&quot;&gt;Get a server with Ubuntu&lt;/h4&gt;

&lt;p&gt;With Rackspace Cloud Servers, this is very easy. Login to Rackspace, choose
Cloud Servers under Hosting, click Add Server, and choose your OS. I chose
Ubuntu 11.10 (Oneiric Ocelot). In just a minute, you’ll have an IP address and
root credentials that you can use for ssh.&lt;/p&gt;

&lt;h4 id=&quot;install-stuff&quot;&gt;Install Stuff&lt;/h4&gt;

&lt;p&gt;I did everything using ssh. If you’ve never done this, Google it and learn the
best way to do it on your platform.&lt;/p&gt;

&lt;p&gt;When you first get your server, it is pretty bare. Let’s get some stuff
installed. First, you’ll want to update apt-get so that it installs the latest
versions of everything:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ apt-get update
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Then, upgrade all the currently installed packages (-y means say yes to all
prompts):&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ apt-get upgrade -y
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now, we’ll install new stuff:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ apt-get install git-core, build-essentials, curl, zlib1g-dev, \
    libxml2-dev, libxslt1-dev, openssl, nodejs, postgresql, libpq-dev, \
    nginx
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;I installed nodejs, so that I’d have a javascript runtime to compile my static
assets. The postgresql packages is to run a PostgreSQL server on the machine.
The ligpq-dev is so that my pg ruby gem can connect to the PostgreSQL server.
The git-core package is so that I can run a &lt;code&gt;git pull&lt;/code&gt; command to
update the code on the server. Everything else is a pretty fundamental
need.&lt;/p&gt;

&lt;p&gt;Since I used rbenv and ruby-build for ruby, I didn’t install any ruby package
here. Instead, I just made sure that all ruby’s dependencies were
installed.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ apt-get build-dep ruby1.9.3
{% endhighlight %}&lt;/p&gt;

&lt;h4 id=&quot;create-a-new-user&quot;&gt;Create a new user&lt;/h4&gt;

&lt;p&gt;Now, we need to create a user for our app to run as. I called mine &lt;code&gt;app_user&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ useradd -m -g staff app_user
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;The -m option will create the new user’s home directory (/home/app_user). The
-g option tells it which group to add the user to (staff).&lt;/p&gt;

&lt;p&gt;Set your new user’s password.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ passwd app_user
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;To allow app_user to execute commands with super-user privileges, you need to
add him to the sudoers file located at /etc/sudoers.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
# /etc/sudoers
app_user ALL=(ALL) ALL
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now you’re set to log out as root and log back in as app_user. If I specify any
commands that it says you don’t have rights to access, just put &lt;code&gt;sudo&lt;/code&gt; in front
of the command, enter app_user’s password and it will let you.&lt;/p&gt;

&lt;h4 id=&quot;ruby&quot;&gt;Ruby&lt;/h4&gt;

&lt;p&gt;I really like &lt;a href=&quot;https://github.com/sstephenson/rbenv&quot;&gt;rbenv&lt;/a&gt;. These steps are
mostly copied from its homepage, but slightly simplified for my use case.&lt;/p&gt;

&lt;p&gt;Clone rbenv into ~/.rbenv.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ cd
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”’ » ~/.bash_profile
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Add rbenv init to your shell to enable shims and autocompletion.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ echo ‘eval “$(rbenv init -)”’ » ~/.bash_profile
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Restart your shell so the path changes take effect. You can now begin using
rbenv.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ exec $SHELL
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now, we’ll install ruby-build that makes it really simple to install ruby.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
$ git clone git://github.com/sstephenson/ruby-build.git
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Install the version of ruby that you want.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ rbenv install 1.9.3-p125
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Set the global version of ruby to that version (1.9.3).&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ rbenv global 1.9.3-p125
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Rebuild the shim binaries. You should do this any time you install a new Ruby
binary (for example, when installing a new Ruby version, or when installing a
gem that provides a binary).&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ rbenv rehash
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;We’re done installing ruby. Let’s add some reasonable defaults for installing
ruby gems.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
# ~/.gemrc
—
:update_sources: true
:verbose: true
:buld_threshold: 1000
:backtrace: false
:benchmark: false
gem: –no-ri –no-rdoc
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now let’s just install a couple ruby gems that will allow us to use capistrano
later.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ gem install rake
$ gem install bundler
$ rbenv rehash
{% endhighlight %}&lt;/p&gt;

&lt;h3 id=&quot;postgresql&quot;&gt;PostgreSQL&lt;/h3&gt;

&lt;h4 id=&quot;setup-the-postgresql-server&quot;&gt;Setup the PostgreSQL server&lt;/h4&gt;

&lt;p&gt;Since I’m installing the web app on the same server as the database, I was able
to take advantage of a cool feature in PostgreSQL: ident sameuser
authentication. Basically, it allows my application to not have to specify a
password. To use this, first we need to create a user in PostgreSQL with the
same username.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ sudo -u postgres createuser –superuser $USER
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Then, give your new PostgreSQL user a password:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
# Run the psql command as the postgres user
$ sudo -u postgres psql
postgres=# \password app_user
# Type ctrl-d to exit psql
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now, you could make it even easier and not even have to specify a database name
if you create a database with the same name as your user, but I didn’t do that.
I created a database with the same name as my app.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ createdb my_app_name
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;You should be done setting up the PostgreSQL server. If you run into any
issues, try looking &lt;a href=&quot;https://help.ubuntu.com/community/PostgreSQL&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;configure-rails-to-talk-to-postgresql&quot;&gt;Configure Rails to talk to PostgreSQL&lt;/h4&gt;

&lt;p&gt;Make sure that you have the pg gem in your Gemfile:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
# Gemfile
gem ‘pg’, group: :production
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Add this to your database.yml file:&lt;/p&gt;

&lt;p&gt;{% highlight yaml %}
# config/database.yml
production:
  adapter: postgresql
  database: my_app_name
  pool: 5
  timeout: 5000
{% endhighlight %}&lt;/p&gt;

&lt;h3 id=&quot;nginx&quot;&gt;Nginx&lt;/h3&gt;

&lt;p&gt;I pretty much copied my configuration from
&lt;a href=&quot;http://ariejan.net/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn&quot;&gt;Ariejan de Vroom&lt;/a&gt;
with some changes for Rails 3.1 assets.&lt;/p&gt;

&lt;p&gt;We just need to edit two files.  Make sure that you replace my_app_name with
your app’s name.&lt;/p&gt;

&lt;p&gt;{% gist 2303555 %}&lt;/p&gt;

&lt;p&gt;Now, start nginx.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ sudo nginx
{% endhighlight %}&lt;/p&gt;

&lt;h3 id=&quot;unicorn&quot;&gt;Unicorn&lt;/h3&gt;

&lt;p&gt;Add unicorn to your Gemfile:&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
# Gemfile
gem “unicorn”
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Add this file to your rails app.  I pretty much copied this from
&lt;a href=&quot;http://ariejan.net/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn&quot;&gt;Ariejan de Vroom&lt;/a&gt;
and &lt;a href=&quot;https://github.com/blog/517-unicorn&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;{% gist 2303638 %}&lt;/p&gt;

&lt;h3 id=&quot;capistrano&quot;&gt;Capistrano&lt;/h3&gt;

&lt;p&gt;This is a must-have since I wasn’t going with Heroku. You can read more about
configuring Capistrano &lt;a href=&quot;https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning&quot;&gt;here&lt;/a&gt;.
First, you’ll need the capistrano gem on your development box (not the server).
I put it in my Gemfile in my development group, then run capify.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ gem install capistrano
$ capify .
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Open up your Capfile and uncomment the assets line&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
# Capfile
load ‘deploy’
load ‘deploy/assets’ # Using Rails’ asset pipeline
Dir[‘vendor/gems/&lt;em&gt;/recipes/&lt;/em&gt;.rb’,’vendor/plugins/&lt;em&gt;/recipes/&lt;/em&gt;.rb’].each { |plugin| load(plugin) }
load ‘config/deploy’ # Remove this line to skip loading any of the default tasks
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now we need to modify the config/deploy.rb file to setup our tasks.&lt;/p&gt;

&lt;p&gt;{% gist 2304004 %}&lt;/p&gt;

&lt;p&gt;I overrode the assets:precompile task so that it only precompiles them if they
changed. The comments really pretty much describe everything in there.&lt;/p&gt;

&lt;h4 id=&quot;our-first-deploy&quot;&gt;Our first deploy&lt;/h4&gt;

&lt;p&gt;Run these capistrano tasks and resolve any errors that you may get. (There
should be any).&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
# Create directories for your app, etc
$ cap deploy:setup
# Check to make sure everything is ready to go
$ cap deploy:check
# Deploy your code
$ cap deploy:update
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;SSH into the server and run this (You can do this part with Capistrano. I
didn’t.)&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
# load the schema into the database
$ rake RAILS_ENV=production db:schema:load
# see if the application can start
$ bundle exec rails c production
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;If your application started up, you’re set to go. From now on, to deploy you
can just push your code changes to GitHub and run cap deploy and you’re set!&lt;/p&gt;

&lt;h4 id=&quot;thoughts&quot;&gt;Thoughts&lt;/h4&gt;

&lt;p&gt;I’m really happy with this setup. My website is pretty fast. Pages consistently
load in less than 400ms. It’s amazing to me how it can be so fast running on
256MB of RAM.&lt;/p&gt;

&lt;p&gt;This was my first time deploying a website like this. I know that I’ll learn
more and probably make changes as I go. I’ll keep this post up to date with
what I have learned. If you have suggestions or questions, feel free to
ask.&lt;/p&gt;

&lt;p&gt;At some point, I’ll probably configure upstart to monitor my application. I’ll
use an ssl certificate. I’ll probably also use this same server to host other
websites. I’m curious to see what effect it will have if I tweak some of the
settings like the number of unicorn workers, etc. It would be fun to test that
and find the right number.&lt;/p&gt;

</content>
<category term="envelopes" />
<category term="Ruby" />
<category term="Rails" />
<category term="deployment" />
<category term="capistrano" />
<category term="nginx" />
<category term="unicorn" />
<summary>I recently setup a Rails server on Ubuntu using Nginx and Unicorn and adatabase running on the same server using Postgres. I also used rbenv andruby-build for ruby. I had to look up a lot of information to get this allworking. I just wanted to consolidate everything I did into one place.Hopefully, all this can help someone else.</summary>
</entry>
<entry>
<title>A Simple Site To Automate Sending Texts/Emails</title>
<link href="http://donwilson.net/2012/03/a-simple-site-to-automate-sending-textsemails/" rel="alternate" type="text/html" title="A Simple Site To Automate Sending Texts/Emails" />
<published>2012-03-16T02:00:39+00:00</published>
<updated>2012-03-16T02:00:39+00:00</updated>
<id>http://donwilson.net/2012/03/a-simple-site-to-automate-sending-textsemails</id>
<content type="html" xml:base="http://donwilson.net/2012/03/a-simple-site-to-automate-sending-textsemails/">&lt;p&gt;I’m often thinking about things that I could code up that would make tasks
simpler. Generally, that means that I spend a lot of time up front to write a
tool that automates a task. Then, I slowly get that time back over time using
the tool. But, it’s fun anyways. So, this is what I decided to automate.&lt;/p&gt;

&lt;h2 id=&quot;justification&quot;&gt;Justification&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://mormon.org/me/2ZXC/&quot;&gt;I am a Mormon&lt;/a&gt;. No one is paid to do anything at
my church. So, we have to setup all the chairs for everyone every Sunday. We
have split into different groups so that we really only have to come setup
chairs once every month. I am in charge of reminding my group that it’s our
turn. These groups change pretty often with people moving in and out, so we
keep the list of groups in a Google Spreadsheet. I often forget that I need to
remind everyone until it’s inconvenient for me. I have often looked up the list
in the Google spreadsheet on my phone and copied them, 5 at a time, into Google
Voice to send texts. It feels painful.&lt;/p&gt;

&lt;h2 id=&quot;solution&quot;&gt;Solution&lt;/h2&gt;

&lt;p&gt;To make this easier for me, I decided to write a simple website that would read
the data from the Google spreadsheet for me. Then, I could type type in my
message and click “Send SMS” and be done. I was able to do this in about 4 days
in my spare time, but there are some caveats. I’m going to give a brief tour of
this tiny little site. I’m not going to talk about any of the code, but it’s up
on GitHub. If you’re interested, I used &lt;a href=&quot;http://www.sinatrarb.com/&quot;&gt;Sinatra&lt;/a&gt;
with &lt;a href=&quot;http://haml-lang.com/&quot;&gt;Haml&lt;/a&gt;, the
&lt;a href=&quot;https://developers.google.com/google-apps/spreadsheets/&quot;&gt;Google Spreadsheet API&lt;/a&gt; 
via the &lt;a href=&quot;http://code.google.com/p/google-api-ruby-client&quot;&gt;Google API Ruby Client&lt;/a&gt;
and &lt;a href=&quot;https://github.com/technoweenie/faraday&quot;&gt;Faraday&lt;/a&gt;,
&lt;a href=&quot;https://addons.heroku.com/moonshadosms&quot;&gt;Moonshado SMS&lt;/a&gt;,
&lt;a href=&quot;http://www.mongodb.org/&quot;&gt;MongoDB&lt;/a&gt; with &lt;a href=&quot;http://mongoid.org/&quot;&gt;Mongoid&lt;/a&gt;
on &lt;a href=&quot;https://mongolab.com/home&quot;&gt;MongoLab&lt;/a&gt;, the 
&lt;a href=&quot;http://twitter.github.com/bootstrap/&quot;&gt;Twitter Bootstrap&lt;/a&gt;,
and &lt;a href=&quot;http://www.heroku.com/&quot;&gt;Heroku&lt;/a&gt;. It was all free!!! If
you want my code, &lt;a href=&quot;https://github.com/dontangg/eq_automator&quot;&gt;look here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;short-tour&quot;&gt;Short Tour&lt;/h2&gt;

&lt;p&gt;The home page is just a simple page with a random quote about time that changes
every time you come to the page and a link to the contact page. I’m guessing
that I might add more tools like this in the future.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;{{ site.baseurl }}/assets/eq-automator-1.png&quot; alt=&quot;home&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When you click on the “Contact the quroum” link it takes you to a Google page
where it tells you that I’m asking for permission to use your spreadsheets. If
you give permission, it takes you to the only other page in the app, the
contact page. You can select from a bunch of preset groups of contacts or you
can manually click on the names to add them or remove them from the list. You
can see who has an email or phone number in the spreadsheet with the icons next
to each name. Then, you type in your message and click the SMS button if you
want it to send a text message. Or, click the Email button if you want to send
an email. The site responds to your browser size too. So, if you are on a
mobile phone, it’s still pretty usable. Pretty simple. (I removed a bunch of
names and changed the names in the screenshot below).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;{{ site.baseurl }}/assets/eq-automator-2.png&quot; alt=&quot;home&quot; /&gt;&lt;/p&gt;

&lt;p&gt;One caveat is that right now, I can only send 17 text message a month for free.
I have 19 people in my group. Also, when it sends the text, it adds “Msg&amp;amp;data
rates may apply txt STOP to opt-out.” That’s kind of crappy.  Also, if I’m
asking a question and they want to reply, their reply won’t make it to my
phone. So, I’m thinking of changing from using MoonShado SMS to Twilio. With
Twilio it won’t be free, but I’ll get everything that I want for about
$1.17/month. I’m still deciding if it’s worth it to me. Either way it was a fun
project and I’ll still use it!&lt;/p&gt;

</content>
<category term="Ruby" />
<category term="Sinatra" />
<category term="Google API" />
<category term="SMS" />
<category term="Email" />
<summary>I’m often thinking about things that I could code up that would make taskssimpler. Generally, that means that I spend a lot of time up front to write atool that automates a task. Then, I slowly get that time back over time usingthe tool. But, it’s fun anyways. So, this is what I decided to automate.</summary>
</entry>
<entry>
<title>Constructing A Less Than Simple Query With Rails And ARel</title>
<link href="http://donwilson.net/2011/11/constructing-a-less-than-simple-query-with-rails-and-arel/" rel="alternate" type="text/html" title="Constructing A Less Than Simple Query With Rails And ARel" />
<published>2011-11-27T07:38:31+00:00</published>
<updated>2011-11-27T07:38:31+00:00</updated>
<id>http://donwilson.net/2011/11/constructing-a-less-than-simple-query-with-rails-and-arel</id>
<content type="html" xml:base="http://donwilson.net/2011/11/constructing-a-less-than-simple-query-with-rails-and-arel/">&lt;p&gt;I say the query is less than simple because it’s not really complicated either.
In my little application, I really only have one query that is like this and
this is the one. This is the query that I wanted to run:&lt;/p&gt;

&lt;p&gt;{% highlight sql %}
SELECT “envelopes”.*, COALESCE(SUM(“transactions”.”amount”), 0) AS total_amount
FROM “envelopes” LEFT OUTER JOIN “transactions” ON “envelopes”.”id” = “transactions”.”envelope_id”
WHERE “envelopes”.”user_id” = 3
GROUP BY “envelopes”.”id”, “envelopes”.”name”, “envelopes”.”user_id”, “envelopes”.”income”, “envelopes”.”unassigned”, “envelopes”.”parent_envelope_id”, “envelopes”.”expense”, “envelopes”.”created_at”, “envelopes”.”updated_at”
ORDER BY “envelopes”.”name”
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Don’t try to read that. It looks more complicated than it is because it’s long.
In my application, users have envelopes and those envelopes have transactions
and transactions have a cash amount. Basically, I’m getting all the envelopes
owned by a user and the total amount for each envelope (a SUM of all the
amounts of all the transactions in those envelopes). This query is definitely
more complicated than the typical query, but as far as SQL goes, it’s still
pretty simple. Here were my priorities for this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;One query that gets the job done. Not more than one query.&lt;/li&gt;
  &lt;li&gt;Use ActiveRecord to consume the query. I still wanted to work with Envelope
objects even though I also wanted the total.&lt;/li&gt;
  &lt;li&gt;No extensive use of strings because I use SQLite3 for development and
Postgres for production. There are differences in syntax (quoting, etc.) that
I don’t want to worry about.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My first attempt was just creating a SQL string to see if I could just use the
&lt;code&gt;find_by_sql&lt;/code&gt; method to get all the data back and still access the total.&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
sql = ‘SELECT “envelopes”.*, COALESCE(SUM(“transactions”.”amount”), 0) AS total_amount FROM “envelopes” LEFT OUTER JOIN “transactions” ON “envelopes”.”id” = “transactions”.”envelope_id” WHERE “envelopes”.”user_id” = 3 GROUP BY “envelopes”.”id”, “envelopes”.”name”, “envelopes”.”user_id”, “envelopes”.”income”, “envelopes”.”unassigned”, “envelopes”.”parent_envelope_id”, “envelopes”.”expense”, “envelopes”.”created_at”, “envelopes”.”updated_at” ORDER BY “envelopes”.”name”’
envelopes = Envelope.find_by_sql(sql)
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;This worked great. It turns out that all the columns returned were accessible.
For example, when I have an envelope populated with data from this query, I can
just say &lt;code&gt;envelope.total_amount&lt;/code&gt; to get the value and it doesn’t do any other
queries even though &lt;code&gt;total_amount&lt;/code&gt; isn’t a column in the envelopes table. To
make this access even nicer, I added a method to my Envelope class.&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
def total_amount
  @total_amount ||= read_attribute(:total_amount) || transactions.sum(:amount)
end
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;&lt;code&gt;read_attribute&lt;/code&gt; is what is called behind the scenes whenever you access your
data. I call that since it won’t get to &lt;code&gt;method_missing&lt;/code&gt; anymore when I try to
access &lt;code&gt;total_amount&lt;/code&gt;. If that value wasn’t provided in the query that
populated this envelope object, then I get it by summing all the transactions’
amounts. Either way, I memoize the value in an instance variable. If the
instance variable is set, it will return it’s value before doing anything else.
Using a tip found on &lt;a href=&quot;http://weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing&quot;&gt;Jamis Buck’s blog&lt;/a&gt;
was very helpful in testing this to make sure it was working. To see all the
SQL queries that are run, you can just run &lt;code&gt;ActiveRecord::Base.logger =
Logger.new(STDOUT)&lt;/code&gt; in the Rails console.&lt;/p&gt;

&lt;p&gt;This solution is nice because it solves the first two concerns I had. However,
it isn’t very portable. The whole query is just a string. So I looked through
the Rails documentation to see if it was possible to build this query just
using the Active Record Query Interface. The things that I was having a hard
time figuring out how to do was getting all of the envelopes columns while
summing the transactions as well as getting an outer join in the query. If
there aren’t any transactions, I still want the envelope to return (inner join
doesn’t work). I could get it to do an outer join if I used the &lt;code&gt;includes&lt;/code&gt;
method and I put something in the &lt;code&gt;where&lt;/code&gt; that required the included table.
Anyways… I decided to just build the SQL string using ARel and just plop it
into the &lt;code&gt;find_by_sql&lt;/code&gt; method. After a lot of digging through ARel
documentation and looking through the source code, I finally found a way to do
it. Here it is:&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
et = Envelope.arel_table
tt = Transaction.arel_table&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;envelopes_columns = Envelope.column_names.map {&lt;/td&gt;
      &lt;td&gt;column_name&lt;/td&gt;
      &lt;td&gt;et[column_name.to_sym] }&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;sum_function = Arel::Nodes::NamedFunction.new(‘SUM’, [tt[:amount]])
aggregation = Arel::Nodes::NamedFunction.new(‘COALESCE’, [sum_function, 0], ‘total_amount’)&lt;/p&gt;

&lt;p&gt;sql = et.project(et[Arel.star], aggregation)
        .join(tt, Arel::Nodes::OuterJoin).on(et[:id].eq(tt[:envelope_id]))
        .where(et[:user_id].eq(user_id))
        .group(*envelopes_columns)
        .order(et[:name]).to_sql&lt;/p&gt;

&lt;p&gt;Envelope.find_by_sql(sql)
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;There are a couple of tricks that I learned worth mentioning. The first one
that appears in the code above is that you can get ARel to do any function
supported in databases even if ARel doesn’t natively understand it. Just use
the NamedFunction class and pass in all the arguments for that function as an
array. The 3rd argument is an optional alias. Even though &lt;code&gt;SUM()&lt;/code&gt; is natively
supported, I had to add it this way because it puts an alias in the wrong spot
if I used the native way since I want the &lt;code&gt;SUM()&lt;/code&gt; inside the &lt;code&gt;COALESCE()&lt;/code&gt;. I
want the &lt;code&gt;COALESCE()&lt;/code&gt; because if it returns null, then I’ll do another
database query in my &lt;code&gt;total_amount&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;The next trick is that you can do &lt;code&gt;et[Arel.star]&lt;/code&gt; to generate &lt;code&gt;&quot;Envelopes&quot;.*&lt;/code&gt;.
This is nice because the Envelopes table is quoted in the database-specific way
(for sqlite here) and the splat is not quoted.&lt;/p&gt;

&lt;p&gt;The last thing that if you want to use an outer join, just pass in the join
class you want to use as a second parameter to the &lt;code&gt;join&lt;/code&gt; method…  easy!&lt;/p&gt;

&lt;p&gt;That’s it. This worked. (If you’re wondering about the &lt;code&gt;*envelopes_columns&lt;/code&gt;
part, you need to go through &lt;a href=&quot;http://tryruby.org&quot;&gt;Try Ruby&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;This actually met all of my initial priorities, but something didn’t sit right
with me. I didn’t like how this query was not chainable like all of the other
ActiveRecord queries. I can’t use any of my other scopes with it. So, I went
back to the ActiveRecord Query Interface and this time, I dug into the
documentation more and looked through some Rails code. I found a way to make it
all work using a combination of ActiveRecord and ARel.&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
et = Envelope.arel_table
tt = Transaction.arel_table&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;envelopes_columns = Envelope.column_names.map {&lt;/td&gt;
      &lt;td&gt;column_name&lt;/td&gt;
      &lt;td&gt;et[column_name.to_sym] }&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;sum_function = Arel::Nodes::NamedFunction.new(‘SUM’, [tt[:amount]])
aggregation = Arel::Nodes::NamedFunction.new(‘COALESCE’, [sum_function, 0], ‘total_amount’)&lt;/p&gt;

&lt;p&gt;select([et[Arel.star], aggregation])
  .joins(Arel::Nodes::OuterJoin.new(tt, Arel::Nodes::On.new(et[:id].eq(tt[:envelope_id]))))
  .group(envelopes_columns)
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;I’m not going to explain all of this, but it’s pretty cool that all of the
ActiveRecord methods take ARel as parameters. Notice that the where clause is
missing from this. That’s because I moved it out into its own scope that I can
chain on when I want. This also now uses my default scope which just specifies
the order.&lt;/p&gt;

&lt;p&gt;I think that this is great because it works with all my scopes and it’s
chainable and everything. I hope that this can be of some use to someone other
than me. I learned a lot while trying to do this and I’m actually pretty
surprised that it is all possible. I was half expecting to just have to use my
string SQL query and leave it at that.&lt;/p&gt;

</content>
<category term="Ruby" />
<category term="Rails" />
<summary>I say the query is less than simple because it’s not really complicated either.In my little application, I really only have one query that is like this andthis is the one. This is the query that I wanted to run:</summary>
</entry>
<entry>
<title>I Went To MountainWest RubyConf 2011!</title>
<link href="http://donwilson.net/2011/03/i-went-to-mountainwest-rubyconf-2011/" rel="alternate" type="text/html" title="I Went To MountainWest RubyConf 2011!" />
<published>2011-03-23T00:00:09+00:00</published>
<updated>2011-03-23T00:00:09+00:00</updated>
<id>http://donwilson.net/2011/03/i-went-to-mountainwest-rubyconf-2011</id>
<content type="html" xml:base="http://donwilson.net/2011/03/i-went-to-mountainwest-rubyconf-2011/">&lt;p&gt;I recently went to MountainWest RubyConf 2011 (Mar 17-18). It was in Salt Lake
City at the public library. It was pretty fun. I met a guy that recognized me
from Taylorsville elementary school! People were mostly from the western US,
but there were people there from the east as well.&lt;/p&gt;

&lt;p&gt;Probably the biggest surprise for me was that I expected for all of the
sessions to be centered around Ruby and for everyone to discourage all other
languages, but they weren’t and they didn’t. Here is a short list of things
that I noticed:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ruby coders are not Ruby exclusive.&lt;/li&gt;
  &lt;li&gt;Coding is actually called hacking.&lt;/li&gt;
  &lt;li&gt;Ruby really is a community (so many things about what everyone considers
“core” to Ruby were contributed by other people).&lt;/li&gt;
  &lt;li&gt;Bioinformaticians exist. I met one and he enjoys his job in Arizona!&lt;/li&gt;
  &lt;li&gt;There are lots of Ruby on Rails jobs in Utah.&lt;/li&gt;
  &lt;li&gt;Ruby development is largely Mac-centric with some linux. Windows users are
made fun of (light-heartedly).&lt;/li&gt;
  &lt;li&gt;Everyone is nice and willing to help you and eager to learn (MINASWAN).&lt;/li&gt;
  &lt;li&gt;IRC is a great way to ask/collaborate with other developers.&lt;/li&gt;
  &lt;li&gt;There is a big community of Ruby developers in Utah at
&lt;a href=&quot;https://groups.google.com/forum/?pli=1#!forum/urug&quot;&gt;URUG&lt;/a&gt; that meet together
monthly.&lt;/li&gt;
  &lt;li&gt;Twitter is used way more than I thought.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I tried to keep that first list to things that were less techy. Here is a list
of more technical cool things that I learned:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;There are lots of well-developed Ruby interpreters (MRI, JRuby, Rubinius,
MacRuby, Maglev).&lt;/li&gt;
  &lt;li&gt;If you’re unhappy with your tools, you should write your own.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://mjijackson.com/citrus/index.html&quot;&gt;Citrus&lt;/a&gt; is a great way to parse.&lt;/li&gt;
  &lt;li&gt;I want to participate more in the community (ie. &lt;a href=&quot;http://www.railsmentors.org/&quot;&gt;Rails Mentors&lt;/a&gt;
or &lt;a href=&quot;http://rubysoc.org/&quot;&gt;Ruby Summer of Code&lt;/a&gt; among other things if they do it again).&lt;/li&gt;
  &lt;li&gt;I want to &lt;a href=&quot;http://try.redis-db.com/&quot;&gt;Try Redis&lt;/a&gt; and &lt;a href=&quot;http://try.mongodb.org/&quot;&gt;Try MongoDB&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;You can create a website using &lt;a href=&quot;http://pages.github.com/&quot;&gt;GitHub Pages&lt;/a&gt; for
free.&lt;/li&gt;
  &lt;li&gt;There is a cool Ruby University that is free called &lt;a href=&quot;http://university.rubymendicant.com/&quot;&gt;Ruby Mendicant University&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.pragprog.com/titles/btlang/seven-languages-in-seven-weeks&quot;&gt;Learn 7 languages in 7 weeks&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;There are better ways to handle concurrency than just using threads
(&lt;a href=&quot;http://www.igvita.com/2010/12/02/concurrency-with-actors-goroutines-ruby/&quot;&gt;read more&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I also learned some quirky things about the guys in general. They like:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.minecraft.net/&quot;&gt;Minecraft&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;sparkly unicorns&lt;/li&gt;
  &lt;li&gt;beer&lt;/li&gt;
  &lt;li&gt;random animal sounds&lt;/li&gt;
  &lt;li&gt;sombreros&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, it was a really interesting, fun experience. I’m glad I went. I
learned lots of interesting things and it changed my outlook on different
languages and programming in general!&lt;/p&gt;

</content>
<category term="Conference" />
<summary>I recently went to MountainWest RubyConf 2011 (Mar 17-18). It was in Salt LakeCity at the public library. It was pretty fun. I met a guy that recognized mefrom Taylorsville elementary school! People were mostly from the western US,but there were people there from the east as well.</summary>
</entry>
<entry>
<title>I Contributed to An Open Source Project!</title>
<link href="http://donwilson.net/2010/11/i-contributed-to-an-open-source-project/" rel="alternate" type="text/html" title="I Contributed to An Open Source Project!" />
<published>2010-11-15T11:00:44+00:00</published>
<updated>2010-11-15T11:00:44+00:00</updated>
<id>http://donwilson.net/2010/11/i-contributed-to-an-open-source-project</id>
<content type="html" xml:base="http://donwilson.net/2010/11/i-contributed-to-an-open-source-project/">&lt;p&gt;In my last post, I talked about my envelopes budgeting project a little bit.
Well, obviously, I need to display numbers as a currency. I found a convenient
function in Rails where I could supply a number and it would format it nicely
(eg. $50.12). However, I quickly noticed that negative numbers were formatted
incorrectly (eg. $-50.12 instead of -$50.12). I did some searching on the internet and found others
frustrated with that as well, so I just wrote my own function.&lt;/p&gt;

&lt;p&gt;I left it for a while, but then I decided to see if I could contribute my
solution to the Ruby on Rails source code. It was a fun process. I had to learn
how to use Git a little more. I had to learn more about the way Rails works.
But, I was finally able to submit a patch that was accepted and will be
incorporated in version 3.0.2 of Rails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; It is now incorporated into Rails. You can see my change in the
documentation
&lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;an-overview-of-what-i-did&quot;&gt;An Overview of What I Did&lt;/h1&gt;

&lt;p&gt;Here are the basic steps that I took:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Searched for existing tickets and conversations about the issue.&lt;/li&gt;
  &lt;li&gt;Researched and learned the way that the function was currently working.&lt;/li&gt;
  &lt;li&gt;Planned out a solution based on research of how it should work.&lt;/li&gt;
  &lt;li&gt;Cloned the Rails repository and made my changes.&lt;/li&gt;
  &lt;li&gt;Created a patch and attached it to a ticket to be reviewed by the Rails
team.&lt;/li&gt;
  &lt;li&gt;Implemented feedback from the Rails ticket and submitted patches until it
was accepted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is a lot of steps, but the actual process didn’t take very long. I started
researching it and thinking about it on Friday, October 29 and it was accepted
into Rails on Tuesday, November 2. So, that’s only 5 days and I wasn’t doing it
all the time.&lt;/p&gt;

&lt;h1 id=&quot;a-little-more-detail&quot;&gt;A Little More Detail&lt;/h1&gt;

&lt;p&gt;I thought I would describe in more detail what I did, so that you can do it
too, if you want. First of all, I found out that different open source projects
want you to contribute in different ways. Obviously, I’m going to describe the
Rails way. They have an article (&lt;a href=&quot;http://guides.rubyonrails.org/contributing_to_rails.html&quot;&gt;http://guides.rubyonrails.org/contributing_to_rails.html&lt;/a&gt;)
on how to contribute to Rails that I looked at quite a bit.&lt;/p&gt;

&lt;h2 id=&quot;research-current-conditions&quot;&gt;Research Current Conditions&lt;/h2&gt;

&lt;p&gt;I did a lot of Google searches to see if others were seeing the same problem as
me and if there was anyone that had already attempted to fix it. I did find a
lot of people with their own little hacks to get it to work the way they
wanted. I also found one person several years ago that submitted a patch to fix
it, but it went stale and never got incorporated. It was a good way to learn
what people wanted and to see suggestions on how it should work.&lt;/p&gt;

&lt;h2 id=&quot;learn-and-research-rails&quot;&gt;Learn And Research Rails&lt;/h2&gt;

&lt;p&gt;All of the Rails code is open source (duh, that’s why I can contribute). It’s
all hosted on &lt;a href=&quot;https://github.com/rails/rails&quot;&gt;GitHub&lt;/a&gt;. So, I went to the code
and started getting familiar with how the number_to_currency function worked. I
found the file I needed to change fairly easily by looking at the
&lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency&quot;&gt;documentation for the function&lt;/a&gt;
for the function. The path to the file was right there when I clicked view
source. Finding the files where the tests were stored was a little more
challenging, but not too hard.&lt;/p&gt;

&lt;h2 id=&quot;researched-best-solution&quot;&gt;Researched Best Solution&lt;/h2&gt;

&lt;p&gt;I knew that this was not a simple issue to resolve. Well, it was a simple issue
to resolve, but not a simple issue to decide what the best resolution would be
especially because of how much it can vary by locale. So, I looked at other
languages to see what they did to determine how to format negative currencies.
I looked at all of the people that I found had issues with it and how they
wished it would work and I decided what I thought would be the best way to do
it.&lt;/p&gt;

&lt;h2 id=&quot;fix-it&quot;&gt;Fix It&lt;/h2&gt;

&lt;p&gt;Finally, it was time to get my hands dirty. I already had Git installed on my
computer and I already had a GitHub account (it’s free). I went to the Rails
repository on Git and I clicked “Fork.” This basically creates a copy of the
repository under your name. I don’t know if I would do it this way again,
though. In other open source projects, you fork and then when you’re done, you
send a pull request. That’s not how Rails does it. With Rails, you just make
your changes and submit a patch. So, it’s not necessary to create your own copy
under your account.&lt;/p&gt;

&lt;p&gt;Once, I had my forked copy, I cloned it onto my computer.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git clone git://github.com/dontangg/rails.git
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;As I’m sure you know, this basically puts a copy of the repository on my
computer in a folder named rails. It also creates a link (called a remote in
Git) to the origin on GitHub.&lt;/p&gt;

&lt;p&gt;Since we need to make sure that what we have is always in sync with the actual
rails repository, we have to add another remote.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git remote add upstream https://github.com/rails/rails.git
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;This creates another remote called upstream (call it what you want) to the main
rails repository. Now, we can pull the source from the main repository to make
sure we have the latest stuff (if we don’t I’d be surprised).&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git pull upstream master
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;This pulls the code from upstream into our master branch in our local
repository. Now, we can create a branch for our fix. We’ll call the branch
currency-fix.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git checkout -b currency-fix
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now, I was ready to make my changes. Once the changes were made, I modified
Rails tests to help prevent regression (breaking functionality later on). To
run the tests, first I had to make sure that I had all the gems I needed. This
is easy now with bundler. Make sure you have bundler.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ gem install bundler
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Then, to install all the needed gems:&amp;lt;/p&amp;gt;&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ bundle install –without db
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Now, with all the prerequisites installed, I went to the actionpack/test/
directory in rails and ran this command:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ ruby -I . template/number_helper_test.rb
Loaded suite template/number_helper_test
Started
………………..
Finished in 0.459888 seconds.&lt;/p&gt;

&lt;p&gt;20 tests, 212 assertions, 0 failures, 0 errors, 0 skips
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Sweet, all the tests passed including the ones I added. We just need to make
sure that we still have the latest rails stuff and then we’re ready to go!
Let’s switch back to the master branch and get the code again. Then we’ll have
to switch back to our branch and “rebase” our branch on the master.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git checkout master
Switched to branch ‘master’
$ git pull upstream master
…
$ git checkout currency-fix
Switched to branch ‘currency-fix’
$ git rebase master
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Rebase basically rewinds our changes back to where we branched from master
originally. Then, it applies changes made to the master branch and then it
applies our changes again. This way our branch has the latest stuff from the
master branch (that it got from the Rails repository).&lt;/p&gt;

&lt;h2 id=&quot;create-a-patch-and-create-a-ticket&quot;&gt;Create A Patch And Create A Ticket&lt;/h2&gt;

&lt;p&gt;Creating a patch is pretty simple. Just run this:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ git format-patch master –stdout &amp;gt; my_new_patch.diff
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;That creates a patch in the directory that you run the command. The Rails
community like you to create a ticket in Lighthouse and describe the issue and
attach your patch. You can see the ticket I created
&lt;a href=&quot;https://rails.lighthouseapp.com/projects/8994/tickets/5894-number_to_currency-doesnt-format-negative-numbers-correctly&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;implement-feedback-and-submit-more-patches&quot;&gt;Implement Feedback and Submit More Patches&lt;/h2&gt;

&lt;p&gt;I got some feedback and I had to make a couple more changes and resubmit
patches a few times, but the process was always the same. I thought it was a
lot of fun and kind of rewarding to see my changes actually get implemented
into Rails. My name is now also on a list of 1,693 people that have contributed
to Rails. That’s a lot of people, but I’m one of them. It was a fun little
project for me. I enjoyed it a lot.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;{{ site.baseurl }}/assets/rails-contributor.png&quot; alt=&quot;I&#39;m a Rails contributor&quot; /&gt;&lt;/p&gt;

</content>
<category term="open-source" />
<summary>In my last post, I talked about my envelopes budgeting project a little bit.Well, obviously, I need to display numbers as a currency. I found a convenientfunction in Rails where I could supply a number and it would format it nicely(eg. $50.12). However, I quickly noticed that negative numbers were formattedincorrectly (eg. $-50.12 instead of -$50.12). I did some searching on the internet and found othersfrustrated with that as well, so I just wrote my own function.</summary>
</entry>
<entry>
<title>Envelopes Budgeting Is Out of Sight</title>
<link href="http://donwilson.net/2010/11/envelopes-budgeting-is-out-of-sight/" rel="alternate" type="text/html" title="Envelopes Budgeting Is Out of Sight" />
<published>2010-11-10T11:00:09+00:00</published>
<updated>2010-11-10T11:00:09+00:00</updated>
<id>http://donwilson.net/2010/11/envelopes-budgeting-is-out-of-sight</id>
<content type="html" xml:base="http://donwilson.net/2010/11/envelopes-budgeting-is-out-of-sight/">&lt;p&gt;Managing your money is obviously a very important thing to do. Everyone comes
up with a different way of doing it. I have asked lots of people how they do it
and I don’t think that any one method is the best for everyone. Some people do
it in Excel. Some use Quicken or Mint.com. Some have so much money, they don’t
need to think about it. Others have even more money and they pay people to
think about their money.&lt;/p&gt;

&lt;p&gt;Behind all of these different ways to manage your money, there are two main
philosophies behind them. You either create a budget at the beginning of the
month and try to spend less than the money you’ve budgeted in each category.
Or, you “cash” your paycheck and allocate your cash into different “envelopes”
and when you go somewhere you only spend out of that cash that you allocated
for that expenditure.&lt;/p&gt;

&lt;h1 id=&quot;why-use-envelopes&quot;&gt;Why Use Envelopes?&lt;/h1&gt;

&lt;p&gt;Here again, everyone has a different preference. I prefer using envelopes.
Here’s why I like it:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;You can always be confident that you’re not using money that you don’t
have.&lt;/strong&gt; When you use a traditional budget, you may budget $400 for the month
for groceries. That doesn’t mean that you can go spend all $400 at the
beginning of the month. You probably don’t have all the money you budget
for the month at the beginning of the month. When you use envelopes, you
are limited to the money you have in the envelope and you know how much
you can spend.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;It makes it easier to make the once-in-a-while expenditures.&lt;/strong&gt; Every year,
we have to renew the registration on the car. Who knows how much it will be,
but I know it happens every year. Without envelopes, I can budget to set
aside a little money every month, but there is no simple way to set that
money aside and know how much you’ve set aside. With envelopes, I put money
in that envelope every month and I can completely forget about it until time
comes to pay it. It’s nice not to panic or worry about having money for
Christmas, or oil changes.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Your bank account balance grows (which makes you happier and safer).&lt;/strong&gt;
We’ve been doing this for a while now and every month, we have all the money
that we’ll spend at the beginning of the month. For example, November just
started and all the money that we need for November is already in our bank
account. If something bad happened, we have savings, but on top of that we
could already last at least a month.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Financial communication is easier.&lt;/strong&gt; If you are married and share funds
with your spouse, you have to communicate what you’re spending to the other
person. With envelopes, you still have to communicate, but you both know by
just looking in the envelope how much you have left for that category of
purchases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The downside to this is obviously that you have to go to the bank to get cash
every time you get paid and that you have to find a really safe place for your
money in your house.&lt;/p&gt;

&lt;p&gt;To solve this, there are some computer websites and programs that simulate the
act of putting money into envelopes. All of your money stays in your bank and
the website just manages what envelopes it is all split into. When you go to
buy something, you just have to check how much is in the envelope and force
yourself not to spend more.&lt;/p&gt;

&lt;h1 id=&quot;the-ideal-setup&quot;&gt;The Ideal Setup&lt;/h1&gt;

&lt;p&gt;I have personally used &lt;a href=&quot;http://www.mvelopes.com&quot;&gt;mvelopes.com&lt;/a&gt; for a while now.
I had a friend that got me to sign up during a promotion where I paid $60 for a
year (a year usually costs $130). I like that it is online and I can access it
anywhere and that it is an envelopes budgeting system. However, there is plenty
that I don’t like. I don’t like the cost. I don’t like that it is all done in
Flash.  There are lots of features that I don’t use that confuse me every once
in a while (how to handle credit card payments, for one). And there are more
negative sides to it that I won’t talk about because I’m not really intending
to review mvelopes.com. My point is that I don’t like what I’m using.&lt;/p&gt;

&lt;p&gt;I have found other solutions (like &lt;a href=&quot;http://www.youneedabudget.com/&amp;quot;&quot;&gt;You Need A Budget&lt;/a&gt;,
but I haven’t found one that I want to stick with. My ideal setup would be like
this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Online&lt;/strong&gt; so that I can access it from my phone, work, or home without
requiring any synchronization.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Not in Flash or Java.&lt;/strong&gt; Those technologies are great, but something like
this can be done with HTML, CSS, and JavaScript and when something online can
be done without Flash or Java, it should be.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Very simple.&lt;/strong&gt; I want my wife to feel completely comfortable and safe
logging in to check balances of our envelopes. Mvelopes.com is too
complicated. I know, I know… it’s not that complicated, but it needs to be
more simple and it can be.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Free.&lt;/strong&gt; Obviously.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Budget using envelopes.&lt;/strong&gt; &lt;a href=&quot;http://www.mint.com/&quot;&gt;Mint.com&lt;/a&gt; is awesome
except in this one category. I really like Mint.com, but I like to budget
using envelopes even more.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generate monthly reports.&lt;/strong&gt; Since we’re not actually using envelopes and
spending with cash, it’s easy to make a mistake and overspend in an envelope.
It’s nice to evaluate how we did at the end of every month.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since I have not found anything that suits all those categories and envelopes
budgeting websites are hard to come by, I have decided to write my own. Guess
what language I’m using to write it in? If you know me, you probably already
knew I was doing this. If you don’t know me, you can probably guess since my
last few posts have revolved around it. Ruby on Rails!!! and I’m having a blast
doing it. Our year of mvelopes.com will expire within the next couple of
months, so I’m really hoping to have it done soon. I’ll let you know when I’m
done and I’ll post some screenshots or something.&lt;/p&gt;

</content>
<category term="envelopes" />
<summary>Managing your money is obviously a very important thing to do. Everyone comesup with a different way of doing it. I have asked lots of people how they do itand I don’t think that any one method is the best for everyone. Some people doit in Excel. Some use Quicken or Mint.com. Some have so much money, they don’tneed to think about it. Others have even more money and they pay people tothink about their money.</summary>
</entry>
<entry>
<title>Tutorial: Debugging in Ruby</title>
<link href="http://donwilson.net/2010/11/tutorial-debugging-in-ruby/" rel="alternate" type="text/html" title="Tutorial: Debugging in Ruby" />
<published>2010-11-06T02:15:20+00:00</published>
<updated>2010-11-06T02:15:20+00:00</updated>
<id>http://donwilson.net/2010/11/tutorial-debugging-in-ruby</id>
<content type="html" xml:base="http://donwilson.net/2010/11/tutorial-debugging-in-ruby/">&lt;p&gt;Debugging is extremely useful to find problems in code. I’m going to give a
really brief tutorial on how to use Ruby’s built-in debugger for the most
common debugging reasons. When I debug, these constitute 95% of what I ever
want to do when I’m debugging. In simple terms, here’s what I like to do when
debugging:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Pause the code in the middle of execution (breakpoint)&lt;/li&gt;
  &lt;li&gt;View the contents of variables (locals, watch, etc.)&lt;/li&gt;
  &lt;li&gt;Run one line of code at a time (step over, step into, etc.)&lt;/li&gt;
  &lt;li&gt;Run my own code while the program is paused&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just to be clear, this is not a tutorial on how to use the gem ruby-debug. This
is also not a tutorial on how to use irb. There are a lot of great tools and
methods out there for debugging, but this is just about how to use the built-in
ruby debugger. I am also only going to talk about the basics of debugging in
Ruby. The built-in debugger, does much more than what I will show you. Learn
more here: &lt;a href=&quot;http://www.ruby-doc.org/docs/ProgrammingRuby/html/trouble.html&quot;&gt;http://www.ruby-doc.org/docs/ProgrammingRuby/html/trouble.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is the code I’m going to be working with:&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
# lottery_numbers.rb
def next_lottery_number(last_number)
  case last_number
  when nil
    4
  when 4
    8
  when 8
    15
  when 15
    16
  when 16
    23
  when 23
    42
  else
    nil
  end
end&lt;/p&gt;

&lt;p&gt;current_number = 1
while current_number
  current_number = next_lottery_number(current_number)
  puts current_number
end
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Basically, all that it should do is output the lottery ticket numbers that
would make you win the lottery (4, 8, 15, 16, 23, 42). When I run the program
nothing outputs. It doesn’t work and I can’t figure out why. So, we’ll debug
it.&lt;/p&gt;

&lt;p&gt;To start the debugger, we just type:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
ruby -r debug lottery_numbers.rb
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;The -r option tells Ruby to require a library before it runs my program and I
specified to require the debug library.&lt;/p&gt;

&lt;p&gt;When I run that, it responds with this:&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
Debug.rb
Emacs support available.&lt;/p&gt;

&lt;p&gt;lottery_numbers.rb:2:def next_lottery_number(last_number)
(rdb:1)
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;It shows the line that it is about to execute. Of course, it skipped the first
line because it was a comment and we are now looking at line 2. Just to feel
safe that we are where we think we are, lets run ‘list’ to see for sure.
(Also, the commands I type all start with (rdb:#).  Everything else is output
by the debugger.)&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) list
[-3, 6] in lottery_numbers.rb
   1  # 4 8 15 16 23 42
=&amp;gt; 2  def next_lottery_number(last_number)
   3    case last_number
   4    when nil
   5      4
   6    when 4
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Yep, that’s where we are! Ok we’re not too interested in this line. This line
is just going to define a method, let’s go to the “next” line.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) next
lottery_numbers.rb:21:current_number = 1
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;It skipped the entire method definition because it doesn’t execute anything
inside the method until the method is called. So, now we are on the line that
defines our variable. We are definitely interested in this. Let’s tell it to
keep us updated on the contents of that variable by running the “display”
command.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) display current_number
1: current_number =
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Currently, our variable doesn’t have anything. That will change when we go to
the next line (“n” is a shortcut for the next command).&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) n
lottery_numbers.rb:22:while current_number
1: current_number = 1
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Alright, now we can see that our &lt;code&gt;current_number&lt;/code&gt; has the value of 1 in it.
Everything is going the way we planned it. I’ll keep going to the next line
until I see something suspicious.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) n
lottery_numbers.rb:23:  current_number = next_lottery_number(current_number)
1: current_number = 1
(rdb:1) n
lottery_numbers.rb:24:  puts current_number
1: current_number =
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Uh oh! For some reason, &lt;code&gt;current_number&lt;/code&gt; was set back to nothing before
anything was output. We also learned that the next (n) command steps over
methods. It didn’t take us into the next_lottery_number method. Let’s quit the
debugger, and debug again. This time we’ll step into the method.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) q
Really quit? (y/n) y
$ ruby -r debug lottery_numbers.rb
Debug.rb
Emacs support available.&lt;/p&gt;

&lt;p&gt;lottery_numbers.rb:2:def next_lottery_number(last_number)
(rdb:1) b 23
Set breakpoint 1 at lottery_numbers.rb:23
(rdb:1) c
Breakpoint 1, toplevel at lottery_numbers.rb:23
lottery_numbers.rb:23:  current_number = next_lottery_number(current_number)
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Notice that this time, I set a breakpoint on line 23 (b 23) then I told the
program to continue (c) until it hit that breakpoint. Now, we’re ready to step
in with the step command (“s” is the shortcut).&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) s
lottery_numbers.rb:3:  case last_number
(rdb:1) l
[-2, 7] in lottery_numbers.rb
   1  # 4 8 15 16 23 42
   2  def next_lottery_number(last_number)
=&amp;gt; 3    case last_number
   4    when nil
   5      4
   6    when 4
   7      8
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Alright! We’re in the method now. Now we can follow it to see what went wrong.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) disp last_number
1: last_number = 1
(rdb:1) s
lottery_numbers.rb:24:  puts current_number
1: last_number =
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Oh, I guess the way that I wrote it, we don’t really get to see much by
stepping into the method. Let’s experiment. I’m going to quit the debugger, go
back to line 23 and manually set current_number to 4 before it calls the method
to get the next number.&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
(rdb:1) q
Really quit? (y/n) y
dons-macbook:Sites don$ ruby -r debug lottery_numbers.rb
Debug.rb
Emacs support available.&lt;/p&gt;

&lt;p&gt;lottery_numbers.rb:2:def next_lottery_number(last_number)
(rdb:1) b 23
Set breakpoint 1 at lottery_numbers.rb:23
(rdb:1) c
Breakpoint 1, toplevel at lottery_numbers.rb:23
lottery_numbers.rb:23:  current_number = next_lottery_number(current_number)
(rdb:1) current_number = 4
4
(rdb:1) disp current_number
1: current_number = 4
(rdb:1) l
[18, 27] in lottery_numbers.rb
   18    end
   19  end
   20
   21  current_number = 1
   22  while current_number
=&amp;gt; 23    current_number = next_lottery_number(current_number)
   24    puts current_number
   25  end
(rdb:1) n
lottery_numbers.rb:24:  puts current_number
1: current_number = 8
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;To run my own line of code, all I had to do is type in the code that I wanted
to run! That’s pretty easy, right? And look! When I started out as 4, it
correctly set the next number to 8. Well, as you probably noticed, I originally
thought that I would pass nil into the function the first time through. That
changed when I got to the bottom and I realized that I couldn’t pass nil in if
I wanted to use it in the while loop the way that I did. Then, I just forgot
that it would affect the method that I wrote. Let’s make a small change to line
4 to check for the number 1 instead of nil.&lt;/p&gt;

&lt;p&gt;{% highlight ruby %}
def next_lottery_number(last_number)
  case last_number
  when 1
    4
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;{% highlight bash %}
$ ruby lottery_numbers.rb
4
8
15
16
23
42
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;Awesome! When we run the program now, it works!&lt;/p&gt;

&lt;p&gt;This was a pretty basic example and it doesn’t show all the commands you can
use with the built-in debugger. I hope it can be a quick helpful tutorial for
people trying to debug their Ruby code.&lt;/p&gt;

&lt;p&gt;This would actually be a fun way to debug:
&lt;a href=&quot;http://www.youtube.com/watch?v=8_HSCMTo6xw&quot;&gt;YouTube clip&lt;/a&gt;.&lt;/p&gt;

</content>
<category term="Ruby" />
<summary>Debugging is extremely useful to find problems in code. I’m going to give areally brief tutorial on how to use Ruby’s built-in debugger for the mostcommon debugging reasons. When I debug, these constitute 95% of what I everwant to do when I’m debugging. In simple terms, here’s what I like to do whendebugging:</summary>
</entry>
<entry>
<title>Programming Is Art</title>
<link href="http://donwilson.net/2010/11/programming-is-art/" rel="alternate" type="text/html" title="Programming Is Art" />
<published>2010-11-03T03:27:49+00:00</published>
<updated>2010-11-03T03:27:49+00:00</updated>
<id>http://donwilson.net/2010/11/programming-is-art</id>
<content type="html" xml:base="http://donwilson.net/2010/11/programming-is-art/">&lt;blockquote&gt;
  &lt;p&gt;“When you don’t create things, you become defined by your tastes rather than
ability. your tastes only narrow &amp;amp; exclude people. so create.”&lt;/p&gt;

  &lt;p&gt;– &lt;cite&gt;_why the lucky stiff&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I like this quote. One of the reasons the I like programming on the computer is
because it is my way of being creative. What do you think of this quote?&lt;/p&gt;

&lt;p&gt;It kind of reminds me of this quote from the movie Dead Poets Society:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“We don’t read and write poetry because it’s cute. We read and write poetry
because we are members of the human race. And the human race is filled with
passion. And medicine, law, business, engineering, these are noble pursuits
and necessary to sustain life. But poetry, beauty, romance, love, these are
what we stay alive for. To quote from Whitman, “O me! O life!… of the
questions of these recurring; of the endless trains of the faithless… of
cities filled with the foolish; what good amid these, O me, O life?” Answer.
That you are here - that life exists, and identity; that the powerful play
goes on and you may contribute a verse. That the powerful play &lt;em&gt;goes
on&lt;/em&gt; and you may contribute a verse. What will your verse be?”&lt;/p&gt;

  &lt;p&gt;– &lt;cite&gt;John Keating&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I’d like to think that there are many ways that I have contributed a verse, but
one of them is definitely through the web development and computer programming
that I have done. For me, writing code is my way of being an artist and my art
project consists of different layers of beauty:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;How nice and usable is it for the user?&lt;/li&gt;
  &lt;li&gt;How well does it serve the needs of the user?&lt;/li&gt;
  &lt;li&gt;How beautiful is the actual code? Is it efficient? Is it well documented?
Does it look nice?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I can’t say that I’ve always had the time or been in the mood to do this well
every time, but it important to me.&lt;/p&gt;

&lt;p&gt;I’m going to try to quickly explain the languages that I have experience with
what I like or don’t like about them. This isn’t going to be an in-depth
analysis of them… just a little bit about them… the main reasons that I
have.&lt;/p&gt;

&lt;h1 id=&quot;my-experience-with-different-languages&quot;&gt;My Experience With Different Languages&lt;/h1&gt;

&lt;p&gt;I started telling the computer what to do when I was 10 years old and I used
HyperCard. It used a language called HyperTalk and it was based on a concept
that a program consists of a stack of user interfaces. It was a good place to
start for me. It is what got me excited about programming. It’s too bad they
don’t make it anymore.&lt;/p&gt;

&lt;p&gt;Then I found a book in my school library (in 6th grade I think) on BASIC with
tutorials on how to create games. I learned the basics of subroutines/functions
as well as command line input/output. I had a blast with that one, but beyond
that book, I didn’t have much resource for learning more.We didn’t have the
internet (even if we did, I don’t think that there would be much of a resource
back then). Today, I definitely don’t like VB.Net very much. C# is much better.
In VB, you have to put “Then” after your If statement among many other syntax
vegetables. Yuck!&lt;/p&gt;

&lt;p&gt;Here is a little BASIC. Kind of nostalgic…&lt;/p&gt;

&lt;p&gt;{% highlight basic %}
INPUT “What is your name: “, UserName$
PRINT “Hello “; UserName$
DO
  INPUT “How many stars do you want: “, NumStars
  Stars$ = STRING$(NumStars, “*”)
  PRINT Stars$
  DO
    INPUT “Do you want more stars? “, Answer$
  LOOP UNTIL Answer$ &amp;lt;&amp;gt; “”
  Answer$ = LEFT$(Answer$, 1)
LOOP WHILE UCASE$(Answer$) = “Y”
PRINT “Goodbye “; UserName$
{% endhighlight %}&lt;/p&gt;

&lt;p&gt;For my math classes in Junior High and High School I had a TI-85 and I created
some games on my calculator. I don’t know the name of the language used on the
calculator. Luckily, the calculator came with a great little book with
descriptions on all the commands you could issue to the calculator. This was
awesome because I was great at math and finished my assignments quickly which
left plenty of time for more work on my calculator during class!&lt;/p&gt;

&lt;p&gt;My dad noticed my interest in programming and he wanted to learn too. So, we
went to the bookstore and bought a book on C that we read together and did the
exercises together. I loved learning C more than any other language to that
point. It was the first language that I appreciated not only for what I could
tell the computer to do with it, but also the way that it looked. To this day I
like the wide range of ways that you can accomplish things. Programming in
C/C++ feels like I’m breathing a cleaner air and that I have more freedom than
any other language.&lt;/p&gt;

&lt;p&gt;In High School, I had a computer science class and we learned both C++ and
Pascal. I liked Pascal, but I loved C++.&lt;/p&gt;

&lt;p&gt;Of course, when I went to college, almost all of the computer science classes
were in Java. I really liked Java. Of all the other languages I had learned to
that point, it reminded me most of C++. I know that’s weird, but think it was
just because it’s object oriented. I don’t understand why, but I have this
weird opinion of Java. I really enjoy programming in it, but I don’t enjoy
using programs created with it. Maybe I should figure out why, but I don’t
really care. :) In college, I also had classes on C++, Python, and Perl. Python
and Perl were okay languages to use, but for some reason I found myself
avoiding them rather than interested in them.&lt;/p&gt;

&lt;p&gt;During college, but my job provided an opportunity to learn how to do web
development. At first, I didn’t like it very much. It didn’t feel like
programming to me. I kept doing it anyways, and I eventually learned to
appreciate PHP and I learned to love JavaScript, HTML, and CSS. Today, I feel
neutral about PHP, but I really like HTML, CSS, and JavaScript. It is so easy
and fun to deliver a great experience to people on the web.&lt;/p&gt;

&lt;p&gt;When I graduated, I got a job doing web development with ASP.NET using C#. I
really like C# because it reminds me of C++.&lt;/p&gt;

&lt;h1 id=&quot;and-then-there-was-ruby&quot;&gt;And Then There Was Ruby&lt;/h1&gt;

&lt;p&gt;With all the web development that I’ve done, at some point, I stumbled across
Ruby on Rails. It has taken me a little bit of writing, but that is actually
the reason I wanted to write this post. I love Ruby and I love Rails! I still
love C++, but I feel like Ruby gives me a lot of what I love about the beauty
of code that I enjoy about C++. And, when you pair it with Rails, I get HTML,
CSS, and JavaScript too. Everything that I love.&lt;/p&gt;

&lt;p&gt;A man named _why said, “To write Ruby code is to love… to feel passion.” I
don’t know if I would use the same words, but I feel similarly. I really feel
like I’m creating a work of art when I write Ruby code. It’s like I’m creating
an awesome sculpture for the city square or painting the ceiling of a chapel. I
know that may sound crazy or stupid. I may be exaggerating a little too, but it
definitely is more for me than just getting to the end result.&lt;/p&gt;

&lt;p&gt;If you want to try Ruby or learn more about Ruby on Rails, here’s where I would start:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Try Ruby: &lt;a href=&quot;http://tryruby.org/&quot;&gt;http://tryruby.org/&lt;/a&gt; (this is a quick, fun, and easy way to try Ruby)&lt;/li&gt;
  &lt;li&gt;Railscasts: &lt;a href=&quot;http://railscasts.com/&amp;quot;&quot;&gt;http://railscasts.com/&quot;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&amp;lt;/a&amp;gt;Rails for Zombies: &lt;a href=&quot;http://railsforzombies.org/&amp;quot;&quot;&gt;http://railsforzombies.org/&quot;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Rails Guides: &lt;a href=&quot;http://guides.rubyonrails.org/&amp;quot;&quot;&gt;http://guides.rubyonrails.org/&quot;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Agile Development with Rails: &lt;a href=&quot;http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition&amp;quot;&quot;&gt;http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition&quot;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
<summary>  “When you don’t create things, you become defined by your tastes rather thanability. your tastes only narrow &amp;amp; exclude people. so create.”  – _why the lucky stiff</summary>
</entry>
</feed>
