<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>John K. Ferguson&apos;s Blog</title><description>Personal website and blog of John K. Ferguson, exploring software development, technology, and more.</description><link>https://johnkferguson.com/</link><item><title>The Cure for Sleepy Heroku Dynos</title><link>https://johnkferguson.com/the-cure-for-sleepy-heroku-dynos/</link><guid isPermaLink="true">https://johnkferguson.com/the-cure-for-sleepy-heroku-dynos/</guid><pubDate>Sat, 24 May 2014 21:21:00 GMT</pubDate><content:encoded>&lt;p&gt;If your application on Heroku has been having slow initial page load times, the
most likely cause is a
&lt;a href=&quot;https://devcenter.heroku.com/articles/dynos#dyno-sleeping&quot;&gt;sleeping dyno&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Dynos are Heroku&apos;s own lightweight virtualized containers that are used to house
and serve your app. When using only one dyno, such as with Heroku&apos;s free plan,
Heroku will put your dyno to sleep when there has no been no activity on your
app for over an hour. This often occurs when no visitors have been to your site
in a while.&lt;/p&gt;
&lt;p&gt;When Heroku puts your dyno to sleep, it takes its allotted resources, such as
processors and memory, and re-allocates them elsewhere. While sleeping, your
application is idle and is unable to do anything. However, once a new request
comes back into your application, Heroku will give back the resources to your
app. During this process, your app will go through the process of booting up
and any visitor to your site will have to endure a very long initial page load
time.&lt;/p&gt;
&lt;p&gt;To prevent this from happening, all that has to be done is to automatically
trigger a http request to your site at least once a hour. With such a scheduled
request, there will be no opportunity for you app to go to sleep and for users
to experience such slow page load times.&lt;/p&gt;
&lt;p&gt;There are various ways to ping your site via a scheduled http request, such as
through using a &lt;a href=&quot;http://en.wikipedia.org/wiki/Cron&quot;&gt;cron&lt;/a&gt; job that curls your
app, &lt;a href=&quot;https://docs.newrelic.com/docs/alert-policies/availability-monitoring&quot;&gt;New Relic&apos;s availability monitoring&lt;/a&gt;
or &lt;a href=&quot;http://uptimerobot.com/&quot;&gt;various&lt;/a&gt; &lt;a href=&quot;http://kaffeine.herokuapp.com/&quot;&gt;other&lt;/a&gt;
&lt;a href=&quot;http://unidler.herokuapp.com/&quot;&gt;free services&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One of the simplest solutions out there is to use Heroku&apos;s own
&lt;a href=&quot;https://addons.heroku.com/scheduler&quot;&gt;Heroku Scheduler&lt;/a&gt; to set up a repeating
curl request directed at your application&apos;s url. This post will cover how to
properly configure such a solution.&lt;/p&gt;
&lt;h2&gt;Setting up Heroku Scheduler&lt;/h2&gt;
&lt;p&gt;Assuming you already have an app set up on Heroku, you&apos;ll need to get the Heroku
Scheduler add-on.&lt;/p&gt;
&lt;p&gt;To do so, from within your app&apos;s page on heroku, click on the Get Add-ons button.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/the-cure-for-sleepy-heroku-dynos/heroku_get_add_ons.png&quot; alt=&quot;Add-on Button&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Scroll down the page to the Workers and Queueing section of the Add-Ons page
and click on Heroku Scheduler.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/the-cure-for-sleepy-heroku-dynos/heroku_workers_and_queueing.png&quot; alt=&quot;Workers and Queueing&quot; /&gt;&lt;/p&gt;
&lt;p&gt;On the Heroku Scheduler&apos;s add-on page, select the app you&apos;d like to use the
scheduler with and click the add button.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/the-cure-for-sleepy-heroku-dynos/heroku_scheduler_page.png&quot; alt=&quot;Heroku Scheduler Page&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Navigate to your App&apos;s Page in Heroku and click on the Heroku Scheduler icon.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/the-cure-for-sleepy-heroku-dynos/heroku_add_ons_list.png&quot; alt=&quot;Heroku Add Ons List&quot; /&gt;&lt;/p&gt;
&lt;p&gt;From within the Heroku Scheduler&apos;s configuration page, click on the add job
button. Next, enter in the url of the app you&apos;d like to prevent from sleeping
(in this example I&apos;ve used &lt;code&gt;my-app.herokuapp.com&lt;/code&gt;). This should be a page that
is publicly accessible. Finally, set the frequency to &apos;Every 10 minutes&apos;
and click Save.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/the-cure-for-sleepy-heroku-dynos/heroku_scheduler_config.png&quot; alt=&quot;Heroku Scheduler Configuration&quot; /&gt; ss&lt;/p&gt;
&lt;p&gt;That&apos;s it, you&apos;re all set. Your Heroku app won&apos;t go to sleep again.&lt;/p&gt;
&lt;p&gt;If you&apos;d like to explore other options on how to keep your app from going to
sleep, check out
&lt;a href=&quot;http://stackoverflow.com/questions/5480337/easy-way-to-prevent-heroku-idling&quot;&gt;this question&lt;/a&gt;
on StackOverflow.&lt;/p&gt;
</content:encoded></item><item><title>Five Great Gems To Use During Rails Development</title><link>https://johnkferguson.com/five-great-gems-to-use-during-rails-development/</link><guid isPermaLink="true">https://johnkferguson.com/five-great-gems-to-use-during-rails-development/</guid><pubDate>Thu, 17 Oct 2013 15:20:00 GMT</pubDate><content:encoded>&lt;p&gt;When deciding whether to use a gem during Rails Development, the questions you
should be asking yourself are: &quot;Will this gem make me more efficient?&quot;,
&quot;Will it make me more productive?&quot;, or &quot;Will it enable me to make better
decisions?&quot; If the answer to any of these questions is yes, then you should
add that gem to your Gemfile.&lt;/p&gt;
&lt;p&gt;Now, of course, this is a very different process than what goes into deciding
whether to use a gem outside of your development environment. In those
situations, you are making decisions about the design of the app and its
infrastructure. Those types of decisions have much more far-reaching
consequences. Because of this, you have to take into consideration things
like, &quot;Is this gem flexible and will it be able to adapt to the evolving demands
of our application?&quot; or &quot;How difficult would it be to roll our own solution?&quot;
and &quot;Is this gem being actively maintained and supported?&quot;&lt;/p&gt;
&lt;p&gt;However, these concerns become much less important when figuring out your
development process. This is because it is a question of workflow and not one
of application design. A workflow can adapt and evolve more easily than the
structure of your app. As a consequence, development gems have a much more
modular quality to them. They can easily be added in or taken out without
affecting the rest of your app. However, this is not true for gems outside of
development. As an example, let&apos;s say you have decided to use
&lt;a href=&quot;https://github.com/plataformatec/devise&quot;&gt;Devise&lt;/a&gt; as your authentication
solution. If at some point in the future, you decide you no longer want to
use Devise, you can&apos;t just remove it from your Gemfile and expect things to
work. Much of the app would have to be changed to accomodate this change while
still providing the same functionality. However, if you are using a gem
like &lt;a href=&quot;https://github.com/brentd/xray-rails&quot;&gt;xray-rails&lt;/a&gt; in development, you
can add it or remove it as you please with no far-reaching implications.&lt;/p&gt;
&lt;p&gt;I use quite a few gems as a default during Rails development and testing. Instead of explaining all of
them, I thought it&apos;d be best to cover my five favorites.&lt;/p&gt;
&lt;h2&gt;5. &lt;a href=&quot;https://github.com/evrone/quiet_assets&quot;&gt;quiet_assets&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/evrone/quiet_assets&quot;&gt;quiet_assets&lt;/a&gt; does one thing and does
it well: it turns off all of the noisy Rails asset_pipeline message that show
up in your development log.&lt;/p&gt;
&lt;p&gt;Before installing quiet_assets, you may find that a simple web request will
produce something like the following in your Rails server log:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Started GET &quot;/&quot; for 127.0.0.1 at 2013-10-16 16:32:29 -0400
  ActiveRecord::SchemaMigration Load (2.3ms)  SELECT &quot;schema_migrations&quot;.* FROM &quot;schema_migrations&quot;
Processing by SessionsController#new as HTML
  Rendered sessions/_form.html.haml (92.0ms)
  Rendered sessions/new.html.haml within layouts/application (100.6ms)
  Rendered shared/_nav.html.haml (2.5ms)
Completed 200 OK in 312ms (Views: 244.0ms | ActiveRecord: 3.2ms)
Started GET &quot;/assets/application.css?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/scaffolds.css?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/sessions.css?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/users.css?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/jquery.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/xray.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/jquery_ujs.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/turbolinks.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/xray.css?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/sessions.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/users.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
Started GET &quot;/assets/application.js?body=1&quot; for 127.0.0.1 at 2013-10-16 16:32:31 -0400
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After installing quiet_assets, the output will be much more manageable and look like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Started GET &quot;/&quot; for 127.0.0.1 at 2013-10-16 16:35:15 -0400
  ActiveRecord::SchemaMigration Load (1.4ms)  SELECT &quot;schema_migrations&quot;.* FROM &quot;schema_migrations&quot;
Processing by SessionsController#new as HTML
  Rendered sessions/_form.html.haml (91.2ms)
  Rendered sessions/new.html.haml within layouts/application (98.6ms)
  Rendered shared/_nav.html.haml (2.2ms)
Completed 200 OK in 285ms (Views: 225.3ms | ActiveRecord: 2.6ms)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result is that it&apos;s now much easier to track things down in your log,
like SQL queries or ajax requests.&lt;/p&gt;
&lt;h2&gt;4. &lt;a href=&quot;https://github.com/Springest/terminal-notifier-guard&quot;&gt;terminal-notifier-guard&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/Springest/terminal-notifier-guard&quot;&gt;terminal-notifier-guard&lt;/a&gt;
is a sweet little plugin for &lt;a href=&quot;https://github.com/guard/guard&quot;&gt;Guard&lt;/a&gt;. I decided
to include it in this list instead of Guard since Guard is so commonly used.
If you are not familiar with Guard, it&apos;s a command line tool used by Ruby
developers to &quot;easily handle events on file system modifications.&quot; What this
means is that Guard can be configured to monitor files for changes. When a file
changes, Guard can trigger certain actions, such as automatically running the
corresponding Rspec tests. In order for Guard to automatically run those Rspec
tests, you&apos;ll need the &lt;a href=&quot;https://github.com/guard/guard-rspec&quot;&gt;guard-rspec&lt;/a&gt;
plugin. There are many other plugins available that all do different things.
A full list can be seen &lt;a href=&quot;https://rubygems.org/search?query=guard-&quot;&gt;here&lt;/a&gt;.
One such plugin that works in conjunction with guard-rspec is
&lt;code&gt;terminal-notifier-guard&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What &lt;code&gt;terminal-notifier-guard&lt;/code&gt; does is simple: it displays a system
notifications in OS X 10.8 telling you the result whenever guard runs. The
notification looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/five-great-gems-to-use-during-rails-development/terminal_notifier_guard.png&quot; alt=&quot;terminal-notifier-guard notification&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This can be particularly nice if you are working on a small screen or laptop.
In that case, you don&apos;t have to ALT+TAB into Terminal to see the results of your
tests and can just look at your system notification. Of course, it&apos;s also good
if you are working on a setup with a bigger monitor(s).&lt;/p&gt;
&lt;p&gt;To use terminal-notifier-guard, you simply have to add it to your Gemfile and
be using OS X 10.8. If you are using a different OS, then there are other Guard
notification plugins that will work for your system, a full list of which is
&lt;a href=&quot;https://github.com/guard/guard/wiki/System-notifications#terminal-notifier&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you&apos;d like to learn more about Guard, check out this &lt;a href=&quot;https://github.com/guard/guard&quot;&gt;RailsCast&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;3. &lt;a href=&quot;https://github.com/brentd/xray-rails&quot;&gt;xray-rails&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/brentd/xray-rails&quot;&gt;xray-rails&lt;/a&gt; is the most underused and
underrated gem on this list. &lt;code&gt;xray-rails&lt;/code&gt; allows you to see which files are
being rendered in your view. So, if you are looking at one of your site&apos;s pages
on your local machine, you can use the keyboard shortcut &lt;code&gt;cmd + shift + x&lt;/code&gt;
(on OS X) or &lt;code&gt;ctrl + shift + x&lt;/code&gt; to see all of the partials and other files
being rendered in your view. The result of which looks like this.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/five-great-gems-to-use-during-rails-development/xray-screenshot.png&quot; alt=&quot;xray-rails in action&quot; /&gt;&lt;/p&gt;
&lt;p&gt;From there, you can click on any of the overlays to open the corresponding file
in your text editor. xray-rails sets Sublime Text as the default editor but
&lt;a href=&quot;https://github.com/brentd/xray-rails#configuration&quot;&gt;can easily be configured to work with your text editor of choice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Installing xray-rails is simple. Just add it to your Gemfile:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;group :development do
  gem &apos;xray-rails&apos;
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then bundle and delete your cached assets:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ bundle &amp;amp;&amp;amp; rm -rf tmp/cache/assets
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Restart your app and you&apos;re ready to go.&lt;/p&gt;
&lt;h2&gt;2. &lt;a href=&quot;https://github.com/cldwalker/debugger&quot;&gt;debugger&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cldwalker/debugger&quot;&gt;debugger&lt;/a&gt; is a great way to get inside
of your code while it executes and see what&apos;s really going on. The gem is
well-named as its best use case is for, appropriately enough, debugging code.
To use debugger, simply place a &lt;code&gt;debugger&lt;/code&gt; inside one of the methods that you
want to debug. When that line of code is executed, you will be transported into
a terminal session inside of the block of code. I find this to be really helpful
and use it often when working with Rails, particularly when trying to figure out
issues with a controller. I&apos;ll explain with an example.&lt;/p&gt;
&lt;p&gt;In the code below, a user is being created in the UsersController using the
create action. There are different user types, and depending on the type of
user that is being created, that user will be redirected to a particular path.&lt;/p&gt;
&lt;p&gt;Now, let&apos;s say for some reason, users are not being directed to the appropriate
path based upon their type. This is a situation where I might use debugger to
dig into the code and see what&apos;s going on. In this example, I would place the
debugger after setting the &lt;code&gt;@user&lt;/code&gt; instance variable. You can see it in the code
below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class UsersController &amp;lt; ApplicationController
  def create
    @user = User.new(params[:user])
    debugger # this is a good spot to put the debugger
    if @user.save
      session[:user_id] = @user.id
      if @user.is_buyer? || @user.is_agent?
        redirect_to new_wanted_listing_path
      elsif @user.is_homeowner?
        redirect_to new_claim_path
      end
    else
      render &apos;new&apos;, notice: &apos;Sorry, an error occured. Please complete the form again&apos;
    end
  end
 end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, when the create action is triggered, I would be put inside of a debugger
session starting where the debugger is placed. I could then move through the
code line by line and follow the logical flow to see where things are going
wrong.&lt;/p&gt;
&lt;p&gt;In addition to regular debugger, I may choose to use a tool like pry instead.
To learn more about pry, check out my previous blog post,
&lt;a href=&quot;http://johnwritecode.com/five-ways-to-get-more-out-of-pry/&quot;&gt;&quot;Five Ways to Get More Out of Pry&quot;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One plugin which I did not mention in that blog post is
&lt;a href=&quot;https://github.com/deivid-rodriguez/pry-byebug&quot;&gt;pry-byebug&lt;/a&gt;, which adds
debugger like functionality to pry, meaning you can place a &lt;code&gt;binding.pry&lt;/code&gt; in
your code and move through it just as you would with debugger. I use both
&lt;code&gt;debugger&lt;/code&gt; and &lt;code&gt;pry-byebug&lt;/code&gt; when working with Rails and have included them in
my default Gemfile at the beginning of this post.&lt;/p&gt;
&lt;p&gt;If you&apos;d like to learn more about using debugger in Rails, check out
&lt;a href=&quot;http://railscasts.com/episodes/54-debugging-ruby-revised&quot;&gt;the following RailsCast&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;1. &lt;a href=&quot;https://github.com/charliesome/better_errors&quot;&gt;better_errors&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;better_errors&lt;/code&gt; is the one gem I couldn&apos;t live without when developing in Rails.
&lt;code&gt;better_errors&lt;/code&gt; replaces the standard Rails error page with a much better and
more useful error page. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/five-great-gems-to-use-during-rails-development/better_errors.png&quot; alt=&quot;better_errors page&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The added features of better_errors are quite powerful and include
(from the &lt;a href=&quot;https://github.com/charliesome/better_errors#features&quot;&gt;better_errors documentation&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Full stack trace&lt;/li&gt;
&lt;li&gt;Source code inspection for all stack frames (with highlighting)&lt;/li&gt;
&lt;li&gt;Local and instance variable inspection&lt;/li&gt;
&lt;li&gt;Live REPL on every stack frame&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The live REPL is of course the most powerful of these features and the one that
I use the most. Anytime I am presented with an error page, I have instant access
to a REPL where I can check out different variables and execute various bits of
code.&lt;/p&gt;
&lt;p&gt;The live REPL feature does not come as a default with &lt;code&gt;better_errors&lt;/code&gt;. To get
the live REPL feature (and you definitely want to), you will also need to
include the &lt;code&gt;binding_of_caller&lt;/code&gt; gem in your Gemfile. After doing so, your
Gemfile should include the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;group :development do
  gem &quot;better_errors&quot;
  gem &quot;binding_of_caller&quot;
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One trick I like to use with &lt;code&gt;better_errors&lt;/code&gt; is to use &lt;code&gt;raise params.inspect&lt;/code&gt;
in my controller actions in order to trigger a &lt;code&gt;better_errors&lt;/code&gt; page.&lt;/p&gt;
&lt;p&gt;As an example, let&apos;s say I want to figure out what&apos;s going on with the &lt;code&gt;update&lt;/code&gt;
action in the &lt;code&gt;UsersController&lt;/code&gt;. I could use a &lt;code&gt;debugger&lt;/code&gt; or &lt;code&gt;binding.pry&lt;/code&gt;
like I discussed previously, but I can also use &lt;code&gt;raise params.inspect&lt;/code&gt; to
trigger the rendering of the &lt;code&gt;better_errors&lt;/code&gt; page. The following code shows how.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class UsersController &amp;lt; ApplicationController
  def update
    raise params.inspect
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, once the update action is triggered, the browser will render the
corresponding &lt;code&gt;better_errors&lt;/code&gt; page.&lt;/p&gt;
&lt;p&gt;As with many of the other gems mentioned, there&apos;s a
&lt;a href=&quot;http://railscasts.com/episodes/402-better-errors-railspanel&quot;&gt;great RailsCast about better_errors&lt;/a&gt;
that gives a good overview of how to best use the gem.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;That covers some of my favorite gems to use during Rails development.&lt;/p&gt;
&lt;p&gt;What are some of your favorites?&lt;/p&gt;
</content:encoded></item><item><title>Five Ways to Get More Out of Pry</title><link>https://johnkferguson.com/five-ways-to-get-more-out-of-pry/</link><guid isPermaLink="true">https://johnkferguson.com/five-ways-to-get-more-out-of-pry/</guid><pubDate>Tue, 14 May 2013 00:20:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;/images/posts/five-ways-to-get-more-out-of-pry/pry_logo_350.png&quot; alt=&quot;Pry&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;What is Pry?&lt;/h2&gt;
&lt;p&gt;Pry is an awesome IRB replacement that offers a ton of powerful features.
This post will highlight five of the most useful, so you can get more out of Pry.&lt;/p&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
&lt;p&gt;To install Pry, type the following into your terminal:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gem install pry
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To start Pry from the terminal, simply enter in Pry like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pry
[1] pry(main)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once in Pry, you can start interacting with Ruby as you would with irb,
but with other added features.&lt;/p&gt;
&lt;h3&gt;1. Use Shell Commands while in Pry&lt;/h3&gt;
&lt;p&gt;When inside a Pry session, it&apos;s possible to execute normal shell commands,
such as &lt;code&gt;pwd&lt;/code&gt;, &lt;code&gt;cd&lt;/code&gt;, or &lt;code&gt;ls&lt;/code&gt;. You can even run more advanced commands like
&lt;code&gt;bundle&lt;/code&gt; or even run rails commands like &lt;code&gt;rails generate&lt;/code&gt; or &lt;code&gt;rails server&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To do so, simply prepend a &lt;code&gt;.&lt;/code&gt; to the start of the shell command you would
like to run. Here&apos;s some examples:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[1] pry(main)&amp;gt; .pwd
/Users/Username
[2] pry(main)&amp;gt; .ls
Desktop   Development Dropbox   Movies    Pictures
Development Downloads Library   Music
[3] pry(main)&amp;gt; .cd Development
[4] pry(main)&amp;gt; .pwd
/Users/Username/Development
[5] pry(main)&amp;gt; .ls
ruby_rocks.rb      Folder
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;2. Make Full Use of Pry&apos;s Methods&lt;/h3&gt;
&lt;p&gt;Pry has a bunch of different methods that can really help you understand your
code. Here are a few of the best:&lt;/p&gt;
&lt;p&gt;1.&lt;code&gt;cd&lt;/code&gt; lets you move into a new context, such as an object or scope. Here&apos;s
how it looks in action&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[1] pry(main)&amp;gt; self
main
[2] pry(main)&amp;gt; class Dog
[2] pry(main)*   def bark
[2] pry(main)*     puts &quot;woof&quot;
[2] pry(main)*   end
[2] pry(main)* end
nil
[3] pry(main)&amp;gt; cd Dog
[4] pry(Dog):1&amp;gt; self
Dog &amp;lt; Object
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above example, we are now inside the Dog class object. We can perform
other actions while inside an object, such as &lt;code&gt;ls&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;2.&lt;code&gt;ls&lt;/code&gt; allows you to list all the various methods that an object can perform.
We can see how it works by continuing our example&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[5] pry(Dog):1&amp;gt; ls
Object.methods: yaml_tag
Dog#methods: bark
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As we can see, typing &lt;code&gt;ls&lt;/code&gt; shows us what methods an object has. In
this example, we see that Dog has the &lt;code&gt;bark&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;3.&lt;code&gt;show-method&lt;/code&gt; lets us see the original code of a method. This can be
of great value when trying to understand what it is a method does.
Continuing with our example, we can see the original bark method.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[6] pry(Dog):1&amp;gt; show-method bark
From: (pry) @ line 3:
Owner: Dog
Visibility: public
Number of lines: 3
def bark
  puts &quot;woof&quot;
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;4.&lt;code&gt;nesting&lt;/code&gt; can be used to help orient yourself in understanding the
scope and inheritance of the current object. Here&apos;s how &lt;code&gt;nesting&lt;/code&gt;
works in our ongoing example.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[7] pry(Dog):1&amp;gt; nesting
Nesting status:
--
0 main (Pry top level)
1 Dog
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Finally, &lt;code&gt;help&lt;/code&gt; can list out all the other methods that Pry offers
that won&apos;t be covered in this blog post. Try it out within Pry yourself
to see all the different options.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;3. Dive Into Running Code with binding.pry&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;binding.pry&lt;/code&gt; can be used to start a Pry session at any point in your
application. This can be great to use to really dive into code and
understand scope, methods and any sort of errors. Here&apos;s how it works.&lt;/p&gt;
&lt;p&gt;Let&apos;s say we have a file, pry-example.rb, with the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;require &apos;pry&apos;

class Example
  def how_binding_works
    binding.pry
  end
end

demonstration = Example.new
demonstration.how_binding_works
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We then run the file within the terminal:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ruby pry-example.rb
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After running the file, we are then put into the code at the point
where &lt;code&gt;binding.pry&lt;/code&gt; is located.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;From: /Users/Username/pry-example.rb @ line 6 Example#how_binding_works:

    5: def how_binding_works
 =&amp;gt; 6:   binding.pry
    7: end

[1] pry(#&amp;lt;Example&amp;gt;)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can then execute whatever commands we want in order to understand
this place in the code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[1] pry(#&amp;lt;Example&amp;gt;)&amp;gt; ls
Example#methods: how_binding_works
locals: _  __  _dir_  _ex_  _file_  _in_  _out_  _pry_
[2] pry(#&amp;lt;Example&amp;gt;)&amp;gt; self
#&amp;lt;Example:0x007fde422f8fc8&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;4. Use Pry with Rails&lt;/h3&gt;
&lt;p&gt;It&apos;s possible to use Pry with your rails app instead of the default rails
console. There are a few options for how to do so. One of the simplest is to
use the &lt;a href=&quot;https://github.com/rweng/pry-rails&quot;&gt;pry-rails&lt;/a&gt; gem with your
application. Doing so will cause &lt;code&gt;rails console&lt;/code&gt; to load Pry instead of IRB,
yet will still retain all of your rails informatin, such as your models,
and all the information in your database.&lt;/p&gt;
&lt;p&gt;To set up your rails app to use Pry, simply add the following code to your
gemfile:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gem &apos;pry-rails&apos;, :group =&amp;gt; :development
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then run &lt;code&gt;bundle install&lt;/code&gt; and the next time you invoke the &lt;code&gt;rails console&lt;/code&gt;,
you&apos;ll be brought into Pry.&lt;/p&gt;
&lt;p&gt;Pry-rails also comes with two additional methods that extend the functionality
of Pry with your rails app. They are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;show-routes&lt;/code&gt; - This shows all of your routes for your application in the
same way that typing &lt;code&gt;rake routes&lt;/code&gt; in the shell would do.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;show-models&lt;/code&gt; - This lists all of the models along with all of their column
name. It is the same as if viewing the schema.rb of your application. However,
in addition, it will also show any associations your models have, such as
&lt;code&gt;belongs_to&lt;/code&gt; or &lt;code&gt;has_many&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;5. Explore All of Pry&apos;s Awesome Documentation &amp;amp; Resources&lt;/h3&gt;
&lt;p&gt;Pry has some of the best documentation and resources around. Here are some of
the best places to start with to get a deeper understanding of Pry.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://pry.github.io/&quot;&gt;Pry&apos;s Main Site&lt;/a&gt; gives a great overview of the project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;a href=&quot;http://vimeo.com/26391171&quot;&gt;Pry Intoductory Screencast&lt;/a&gt; is easy to
follow and does a wonderful job of demonstrating the power of Pry.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The RailsCasts episode, &lt;a href=&quot;http://railscasts.com/episodes/280-pry-with-rails&quot;&gt;Pry with Rails&lt;/a&gt;,
covers some great ways to use Pry with Rails.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/pry/pry/wiki&quot;&gt;Pry Wiki&lt;/a&gt; on &lt;a href=&quot;https://github.com/pry/pry&quot;&gt;Pry&apos;s Github Repository&lt;/a&gt;
is fantastic and provides links to other worthwhile resources as well as clear
documentation on all of Pry&apos;s capabilities.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>The Basics of Collaborating on Github</title><link>https://johnkferguson.com/basics-of-collaborating-on-github/</link><guid isPermaLink="true">https://johnkferguson.com/basics-of-collaborating-on-github/</guid><pubDate>Wed, 03 Apr 2013 00:10:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/github-collabocats.jpg&quot; alt=&quot;Collabocats&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/&quot;&gt;Github&lt;/a&gt; provides an incredible platform for
collaborating on software projects. Features such as forks, pull-requests,
issues, and wikis make Github a flexible tool suitable for various workflows.
This tutorial will provide an introduction to collaborating on Github
and highlight different options for maximizing productivity.&lt;/p&gt;
&lt;h2&gt;Adding Collaborators to a Repository&lt;/h2&gt;
&lt;p&gt;On Github, a collaborator is someone who has read/write access to a repository.
This means they have the ability to make changes to the repository&apos;s codebase,
push any changes to Github, as well as accept pull requests.&lt;/p&gt;
&lt;p&gt;For most projects, it is often best to add team members as collaborators.
However, there are some cases, such as with large open-source projects,
where collaboration can still take place even if the person contributing
code is not listed as an official collaborator.&lt;/p&gt;
&lt;p&gt;In these cases, the way to contribute to a project is to fork its repository,
make any changes and then submit a pull request. The project&apos;s owner or one of
the collaborators can then decide whether to accept the pull request or not.&lt;/p&gt;
&lt;p&gt;Working with pull requests will be covered later. Right now, let&apos;s cover
the process for adding collaborators to a repository.&lt;/p&gt;
&lt;h3&gt;How to add collaborators:&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;From the repository&apos;s main page, click on the settings tab.
&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/github-settings.png&quot; alt=&quot;Github Repository Settings&quot; /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on Collaborators from the left sidebar.
&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/github-collaborators.png&quot; alt=&quot;Github Repository Collaborators&quot; /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter in the usernames of any collaborators you would like to add to a
project and click the add button.
&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/manage-collaborators.png&quot; alt=&quot;Github Repository Collaborators&quot; /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Deciding on a Workflow&lt;/h2&gt;
&lt;p&gt;After setting up a project&apos;s collaborators, it&apos;s important to come to
an agreed upon workflow. The main purpose of the workflow is to detail
how to structure and work with branches, to decide how and when to push to
master, as well as decide whether to utilize pull requests, and if so, how
to do so. From this, a multitude of workflow options emerge. Two popular,
established choices are:&lt;/p&gt;
&lt;h4&gt;&lt;a href=&quot;http://nvie.com/posts/a-successful-git-branching-model/&quot;&gt;Git-Flow&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Git-Flow uses a multiple branch strategy to section off work into appropriate
branches, such as a branch for development, one for hotfixes, another for
releases, and one for features. To manage all of these various branches,
strict rules are enforced about where and how to merge, push or pull.
Given the complex nature of this workflow, developers often use
&lt;a href=&quot;https://github.com/nvie/gitflow&quot;&gt;a helper script&lt;/a&gt; to make sure they are
following the process correctly. For most small projects, Git-Flow may be
overly strict and complicated to the point that it interferes with productivity.&lt;/p&gt;
&lt;h4&gt;&lt;a href=&quot;http://scottchacon.com/2011/08/31/github-flow.html&quot;&gt;Github Flow&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Github Flow is the workflow used by Github. It is much simpler than Git-flow,
and is built around the following basic premises:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Master is always deployable and should be kept clean.&lt;/li&gt;
&lt;li&gt;Always work on small branches.&lt;/li&gt;
&lt;li&gt;When you need feedback or help, or you think the branch is ready for
merging, open a pull request.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&apos;s it. One of the advantages of this workflow is its simplicity and clarity.
Since pull requests are utilized as a sort of code review, developers are able
to maintain quality code while being kept in the loop about what features
are being actively developed.&lt;/p&gt;
&lt;p&gt;For a more detailed explanation of Github Flow in action, check out Zach
Holman&apos;s talk, &quot;How Github Uses Github to Build Github&quot; below:&lt;/p&gt;
&lt;p&gt;&amp;lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/qyz3jkOBbQY&quot; frameborder=&quot;0&quot; allowfullscreen&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/p&gt;
&lt;h3&gt;Suggested Workflow Rules&lt;/h3&gt;
&lt;p&gt;Whatever workflow you choose, there are certain rules that should almost always
be employed. They include:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Don&apos;t work on master.&lt;/strong&gt; Master should always be kept clean and be ready
to deployed. Use whatever other workflow you need to ensure that the code in
master is always ready to be deployed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Keep commits small.&lt;/strong&gt; Large commits can be overwhelming to go through
and understand. By keeping commits small, you make changes intelligible. In
addition, small commits make it much easier to track down problems when
something breaks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Be descriptive with your commit messages.&lt;/strong&gt; Commit messages should
clearly articulate what changes the commit introduces. Clarity in commit
messages makes it much easier to navigate through the history of messages and
find the relevant commit.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Whenever possible, use descriptive names for branches.&lt;/strong&gt; Succinct
branch names makes it easier for your team members to know what features you
are working on. In addition, taking the time to properly name your branch
can provide focus for what you should actually be working on.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Pull Requests&lt;/h2&gt;
&lt;p&gt;Pull Requests are not just limited to forked repositories, but can also be used
between branches on the same project. This means that if you are a collaborator
on a project, you can work on a feature branch, and then open a pull request
whenever you need feedback or help, or you think the branch is ready for merging
into master. Once the pull request has been opened, other collaborators on
the project can review your code, and provide feedback or ideas.&lt;/p&gt;
&lt;p&gt;Pull requests can be opened even if your code is not ready to be merged. This
is one of the amazing features about pull requests. It provides a great platform
where code can be reviewed and improved upon. If you find yourself stuck with
a bit of code, submit a pull request and ask for help. Then once it&apos;s been
fixed and everything looks good, the pull request can be approved and merged
into master.&lt;/p&gt;
&lt;p&gt;There are several benefits to this process. First, since code is reviewed before
being merged into master, the quality of code is kept high. In addition, pull
requests make code changes transparent thereby keeping all team members up to
date of any changes. Lastly, pull requests provide a great jumping off point
for fleshing out a feature or making code right.&lt;/p&gt;
&lt;p&gt;If you&apos;ve never submitted a pull request, follow along with the pictures to
see how it works in action.&lt;/p&gt;
&lt;h4&gt;From the repository page, click on the pull request button.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/pull-request-from-main-page.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;Select the branch that will be the source of the pull request and its destination.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/pull-request-source-destination.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;Enter in a title for the pull request, fill in some comments and submit it.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/pull-request-description.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;This is what your submitted pull request will look like.&lt;/h4&gt;
&lt;p&gt;&lt;em&gt;(Notice the three main tabs: Discussion, Commits, Files Changed.)&lt;/em&gt;
&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/pull-request-discussion.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;The commits tab lists all the commits. You can click on the link to any commit to see it in detail.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/initial-commits.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;The files changed tab shows all the code that has changed.&lt;/h4&gt;
&lt;p&gt;&lt;em&gt;(You can add inline comments to the code by clicking on the blue plus button
that appears when you move your mouse near the line numbers.)&lt;/em&gt;
&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/add-comments.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;Comments appear in the Files Changed section as well as in the Discussion area.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/code-comments-discussion.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;Any future commits from the same branch pushed to github will be included with the pull request.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/push-second-commit.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;The commits tab will include the new commit.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/second-commits-tab.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;The Files changed tab will also include the code from the new commit.&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/basics-of-collaborating-on-github/files-changed-2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The entire Github pull request system provides an incredible way to review and discuss code.&lt;/p&gt;
</content:encoded></item><item><title>Autojump Around the Command Line</title><link>https://johnkferguson.com/autojump-around-command-line/</link><guid isPermaLink="true">https://johnkferguson.com/autojump-around-command-line/</guid><pubDate>Mon, 11 Mar 2013 00:05:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://github.com/joelthelion/Autojump&quot;&gt;Autojump&lt;/a&gt; is a sweet little command
line tool that makes it super easy to move around directories without having
to &lt;code&gt;cd&lt;/code&gt; through its entire file path.&lt;/p&gt;
&lt;p&gt;As an example, if we wanted to move from our octopress directory to our
Documents directory, we could use the standard &lt;code&gt;cd&lt;/code&gt; command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pwd
/Users/MyUsername/Development/code/octopress
$ cd /Users/MyUsername/Documents
$ pwd
/Users/MyUsername/Documents
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or we could use Autojump, and accomplish the same thing in a lot less keystrokes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pwd
/Users/MyUsername/Development/code/octopress
$ j doc
$ pwd
/Users/MyUsername/Documents
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Autojump does this by matching our input against a ranked database of the
directories we spend time in most. We&apos;ll delve deeper into how Autojump works
later and also cover how to best use it, but first, let&apos;s install Autojump.&lt;/p&gt;
&lt;h2&gt;Installation&lt;/h2&gt;
&lt;p&gt;If you&apos;re on OS X, the best way to install Autojump is via
&lt;a href=&quot;http://mxcl.github.com/homebrew/&quot;&gt;Homebrew&lt;/a&gt;w. If you&apos;d prefer to do it manually
or on a Linux machine, check out
&lt;a href=&quot;https://github.com/joelthelion/Autojump#readme&quot;&gt;Autojump&apos;s documentation&lt;/a&gt;
on their Github repo.&lt;/p&gt;
&lt;p&gt;If you already have Homebrew installed, then skip to step 2 to install or
update Python. If you already have Homebrew and Python v2.6+ installed,
then move on to step 3.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Homebrew is an OS X package manager for OS X that can install any additional
libraries you may need. If you don&apos;t already have Homebrew, enter the following
code into a terminal prompt to install it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;```bash
$ ruby -e &quot;$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)&quot;
```
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To check if we have Python v2.6+ installed, type the following into the terminal:
&lt;code&gt;python -V&lt;/code&gt; This will give you the version number of Python. If it&apos;s less
than 2.6, then run the following in the terminal &lt;code&gt;brew install python&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With Python and Homebrew already installed, all that&apos;s left is installing
Autojump, which can be To do that, enter the following command
&lt;code&gt;brew install autojump&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Jumping Around&lt;/h2&gt;
&lt;p&gt;So we&apos;ve got Autojump installed, but we can&apos;t start jumping around between
directories just yet. First Autojump needs to build a database of the
directories we spend time in most. Autojump starts doing this from the
moment it is installed. However, it will have no memory of what directories
we visited prior to its installation and hence will have no database initially.&lt;/p&gt;
&lt;p&gt;To demonstrate this, let&apos;s see what Autojump&apos;s database of directories looks
like right after installation. This can be done through the following
command: &lt;code&gt;j -s&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Since we haven&apos;t changed directories yet, Autojump&apos;s database is empty.
So let&apos;s change directories to start populating Autojump&apos;s database:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cd /Users/MyUsername/Downloads
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now when we use &lt;code&gt;j -s&lt;/code&gt;, we should see the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;20.0: /Users/MyUsername/Downloads
Total key weight: 20. Number of stored dirs: 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&apos;s move to the desktop. Since it&apos;s not in the Autojump database, we can&apos;t
jump to it yet. So we&apos;ll cd into it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cd /Users/MyUsername/Desktop
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&apos;ll run &lt;code&gt;j -s&lt;/code&gt; again to see Autojump&apos;s database:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;20.0: /Users/MyUsername/Downloads
20.0 /Users/MyUsername/Desktop
Total key weight: 40. Number of stored dirs: 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now Autojump has 2 entries in its database and we can jump to them from
anywhere in our filesystem. To move to the Downloads directory, either of the
following commands would work &lt;code&gt;j dow&lt;/code&gt; or &lt;code&gt;j do&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Once in the Downloads directory, let&apos;s hop back to the desktop with either of
the following commands &lt;code&gt;j des&lt;/code&gt; or &lt;code&gt;j de&lt;/code&gt;. Of course, we could enter more
characters to accomplish the same thing. This often becomes necessary if our
database is large and our target directory is ranked low.&lt;/p&gt;
&lt;h3&gt;Understanding Rank&lt;/h3&gt;
&lt;p&gt;As we continue to use the command line as normal, Autojump&apos;s database will keep
populating with new directories. In addition, Autojump will increase the rank
of directories we spend time in most, while decreasing the rank of directories
we don&apos;t visit that often. After using Autojump for a while, our database might
look like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;4.8: /Users/MyUsername/Library
12.7: /Users/MyUsername/Music
13.1: /Users/MyUsername/Documents
18.0: /Users/MyUsername/Development/code/octopress/public
23.3: /Users/MyUsername/Dropbox
24.0: /Users/MyUsername/Development/code/octopress/source
28.5: /Users/MyUsername/Pictures
32.1: /Users/MyUsername/Development
33.8: /Users/MyUsername/Development/code/octopress
36.0: /Users/MyUsername/Desktop
45.7: /Users/MyUsername/Downloads
58.0: /Users/MyUsername/Development/code/octopress/source/_posts
64.1: /Users/MyUsername/Development/code
Total key weight: 394.1. Number of stored dirs: 13
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above, &lt;code&gt;/Users/MyUsername/Development/code&lt;/code&gt; has a key weight of 64.1.
A directory&apos;s key weight determines its rank. A higher key weight means a
higher rank, while a lower key weight means a lower rank. Rank is used when
making a fuzzy match between a user&apos;s input and Autojump&apos;s database of
directories. Higher ranked directories are matched against the user&apos;s input
first before other lower ranked directories.&lt;/p&gt;
&lt;h3&gt;Tab Auto-completion&lt;/h3&gt;
&lt;p&gt;Autojump also supports tab auto-completion. To use tab auto-completion, type in
the first few letters of the directory you want to visit and press tab to have
the complete directory filled in. This is great to use if you are uncertain
about what directory Autojump will hop to based upon your input. In addition,
when there are multiple possible directories after tab is pressed, Autojump
will display all such options. For example:
&lt;code&gt;j d&lt;/code&gt; + &lt;strong&gt;TAB&lt;/strong&gt; will reveal a list of possible directories:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;d__1__/Users/MyUsername/Development/code
d__2__/Users/MyUsername/Downloads
d__3__/Users/MyUsername/Development
d__4__/Users/MyUsername/Dropbox
d__5__/Users/MyUsername/Documents
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Our command line prompt will then read as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ j d_
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All we have to do is enter in the number of the directory we want to go to and
press &lt;strong&gt;TAB&lt;/strong&gt; to have it auto-completed and press enter to jump to it.&lt;/p&gt;
&lt;h3&gt;Jumping to a directory and listing its files&lt;/h3&gt;
&lt;p&gt;We can extend the functionality of autojump to list the files of a directory we
jump to by adding a simple function to our bash profile. Here&apos;s how:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Open your Bash profile in your favorite text editor. Your bash profile will
typically be found in your home directory as a hidden file, often with the
file path of &lt;code&gt;/Users/&apos;Your_Name_Here&apos;/.bash_profile&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once in your Bash profile, add the following line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function jl(){ j &quot;$@&quot; &amp;amp;&amp;amp; ls; }
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Source your terminal to reflect the changes to your Bash profile. This can
be done by entering &lt;code&gt;source /Users/&apos;Your_Name_Here&apos;/.bash_profile&lt;/code&gt; into the
terminal.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now you can use the alias &lt;code&gt;jl&lt;/code&gt; to jump into a directory and &lt;code&gt;ls&lt;/code&gt; all of its contents.&lt;/p&gt;
</content:encoded></item></channel></rss>