<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kyle Chilcutt</title>
    <description>The latest articles on Forem by Kyle Chilcutt (@chilcutt).</description>
    <link>https://forem.com/chilcutt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F33249%2F3a2530a1-39d4-404f-b0b7-e97263ac85e9.jpg</url>
      <title>Forem: Kyle Chilcutt</title>
      <link>https://forem.com/chilcutt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chilcutt"/>
    <language>en</language>
    <item>
      <title>Smarter git checkout with fzf</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Thu, 30 May 2019 07:00:00 +0000</pubDate>
      <link>https://forem.com/chilcutt/smarter-git-checkout-with-fzf-2k5n</link>
      <guid>https://forem.com/chilcutt/smarter-git-checkout-with-fzf-2k5n</guid>
      <description>&lt;p&gt;After I’ve been working on a project for a while, I tend to have a list of multiple branches of work a repo. When jumping between branches on a project, my workflow is usually something like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;git branch&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;find the branch I want to jump to&lt;/li&gt;
&lt;li&gt;highlight the branch name in the terminal&lt;/li&gt;
&lt;li&gt;copy the branch name&lt;/li&gt;
&lt;li&gt;checkout the branch with &lt;code&gt;git checkout &amp;lt;paste&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5T_XsFMJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://blog.chilcutt.com/assets/2019-05-30-fzf_git_branch/gitbranch.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5T_XsFMJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://blog.chilcutt.com/assets/2019-05-30-fzf_git_branch/gitbranch.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This isn’t too bad, but could it be better?&lt;/p&gt;




&lt;p&gt;I’ve been using &lt;a href="https://github.com/junegunn/fzf"&gt;&lt;code&gt;fzf&lt;/code&gt;&lt;/a&gt; to speed up my workflow on the command line and in vim (as a replacement for ctrlp) for a little while, but it recently occurred to me that you could also &lt;a href="https://medium.com/@sidneyliebrand/how-fzf-and-ripgrep-improved-my-workflow-61c7ca212861"&gt;pipe &lt;code&gt;fzf&lt;/code&gt; into a command&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is extremely useful as you can use it to create an ad hoc UI for making a selection as part of a command.&lt;/p&gt;




&lt;p&gt;The &lt;code&gt;fzf&lt;/code&gt; utility gives us some new flexibility, now instead of needing to use my mouse to cut-and-paste the branch name I want, I can select the branch name using &lt;code&gt;fzf&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After a little bit of experimentation, I came up with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git for-each-ref --format='%(refname:short)' refs/heads | fzf | xargs git checkout
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v-elHhOF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://blog.chilcutt.com/assets/2019-05-30-fzf_git_branch/gitcof.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v-elHhOF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://blog.chilcutt.com/assets/2019-05-30-fzf_git_branch/gitcof.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This oneline uses &lt;code&gt;for-each-ref&lt;/code&gt;, a low-level command for scripting, to get a list of all the local branches in the repository without any decoration. The result is piped to &lt;code&gt;fzf&lt;/code&gt; where we can select the branch we want and finally the result is passed through &lt;code&gt;xargs&lt;/code&gt; so we can &lt;code&gt;git checkout&lt;/code&gt; the branch.&lt;/p&gt;

&lt;p&gt;The last step was to wrap this up in an git so it’s always avaialble to me from my gitconfig.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git config --global alias.cof $'!git for-each-ref --format=\''%\(refname:short\)\'' refs/heads | fzf | xargs git checkout'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above, I’ve configured &lt;code&gt;cof&lt;/code&gt; for “checkout fuzzy” and I fought with the bash escape characters so you don’t have to.&lt;/p&gt;

</description>
      <category>git</category>
      <category>fzf</category>
      <category>productivity</category>
      <category>bash</category>
    </item>
    <item>
      <title>Zooming a pane in Vim</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Fri, 26 Apr 2019 15:31:00 +0000</pubDate>
      <link>https://forem.com/chilcutt/zooming-a-pane-in-vim-dp8</link>
      <guid>https://forem.com/chilcutt/zooming-a-pane-in-vim-dp8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yYUEkBvq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2AcIHErwIINhL0eRp1xee4_Q.jpeg" class="article-body-image-wrapper"&gt;&lt;img alt="zoom" src="https://res.cloudinary.com/practicaldev/image/fetch/s--yYUEkBvq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2AcIHErwIINhL0eRp1xee4_Q.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

Photo by &lt;a href="https://unsplash.com/photos/7KLa-xLbSXA?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Paul Skorupskas&lt;/a&gt;on&lt;a href="https://unsplash.com/search/photos/lens?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;




&lt;p&gt;When coding with vim, I tend to pretty heavily use split panes and tabs in my workflow. Having different files open side-by-side helps me trace through the code to identify where I need to make changes.&lt;/p&gt;

&lt;p&gt;Once I find where I want to make an edit, I usually want to shift my focus to just one file. That’s where a handy &lt;a href="https://github.com/vim-scripts/ZoomWin"&gt;little plugin called ZoomWin&lt;/a&gt; comes in. With the ZoomWin package installed I can just toggle zooming a pane with &lt;code&gt;&amp;lt;c-w&amp;gt; o&lt;/code&gt; (control + w, followed by o).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--okvDx1d6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2168/1%2AFCd4GfSAFWTtmAfTGrajzA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--okvDx1d6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2168/1%2AFCd4GfSAFWTtmAfTGrajzA.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vim</category>
      <category>productivity</category>
      <category>devtips</category>
    </item>
    <item>
      <title>RSpec nested subjects</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Wed, 24 Apr 2019 15:21:23 +0000</pubDate>
      <link>https://forem.com/chilcutt/rspec-nested-subjects-593l</link>
      <guid>https://forem.com/chilcutt/rspec-nested-subjects-593l</guid>
      <description>&lt;p&gt;The &lt;a href="https://relishapp.com/rspec/rspec-core/v/3-8/docs/subject/explicit-subject"&gt;RSpec subject functionality&lt;/a&gt; can be useful for simplifying your spec setup and getting straight to the point. I really like using an explicit subject because it helps describe what functionality is under test when you’re writing your specs. Recently, I learned it was possible to nest your subject when using a named subject.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6zJemXg1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/12000/1%2AofMfrqFMfpaTH_RMvI_RQA.jpeg" class="article-body-image-wrapper"&gt;&lt;img alt="programming" src="https://res.cloudinary.com/practicaldev/image/fetch/s--6zJemXg1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/12000/1%2AofMfrqFMfpaTH_RMvI_RQA.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

Photo by &lt;a href="https://unsplash.com/photos/95YRwf6CNw8?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Clément H&lt;/a&gt; on &lt;a href="https://unsplash.com/search/photos/programming?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;







&lt;p&gt;The &lt;code&gt;subject&lt;/code&gt; syntax allows you to use the &lt;a href="https://relishapp.com/rspec/rspec-core/v/3-8/docs/subject/one-liner-syntax"&gt;one-liner syntax&lt;/a&gt; for writing a test which can really clean up a spec file. Let’s take a trivial example of a Rails model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;let&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:car&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;"is a vehicle"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;be_a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For this trivial case, you’ll notice that our expectation pretty literally matches the description of the test case. This might be a good use case for &lt;code&gt;subject&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;be_a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above will test the same functionality and also leave pretty similar spec output when the spec is run.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OsUPs57g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3624/1%2A8CMdd5YkCsObQJMDTy9B_A.png" class="article-body-image-wrapper"&gt;&lt;img alt="failures" src="https://res.cloudinary.com/practicaldev/image/fetch/s--OsUPs57g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3624/1%2A8CMdd5YkCsObQJMDTy9B_A.png"&gt;&lt;/a&gt;&lt;br&gt;Failures look slightly different, but make the same point.
  &lt;/p&gt;

&lt;p&gt;You can also redefine your &lt;code&gt;subject&lt;/code&gt; for different blocks of your test. Let’s set the &lt;code&gt;subject&lt;/code&gt; for an instance method that I want to test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;be_a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s2"&gt;"#parked?"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parked?&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Dope. By redefining the &lt;code&gt;subject&lt;/code&gt; we can use the one-line syntax wherever we want.&lt;/p&gt;

&lt;p&gt;The final trick is we can add an name to our initial &lt;code&gt;subject&lt;/code&gt; so we can reference it later within the spec:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:car&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;be_a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s2"&gt;"#parked?"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parked?&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I find this particularly useful if the &lt;code&gt;subject&lt;/code&gt; in the enclosing block has some complex setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;let&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:driver&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;let&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:front_seat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:car&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;driver: &lt;/span&gt;&lt;span class="n"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;front_seat: &lt;/span&gt;&lt;span class="n"&gt;front_seat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;be_a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s2"&gt;"#parked?"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parked?&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;is_expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can leverage any earlier setup while still having the benefits of different subjects in each context.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Shout out to &lt;a href="https://twitter.com/zackmariscal"&gt;Zack Mariscal&lt;/a&gt; for helping me edit and improve this post and my writing in general.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>testing</category>
      <category>rspec</category>
      <category>tdd</category>
    </item>
    <item>
      <title>Auto-correct git spelling mistakes</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Fri, 19 Apr 2019 14:13:41 +0000</pubDate>
      <link>https://forem.com/chilcutt/auto-correct-git-spelling-mistakes-3896</link>
      <guid>https://forem.com/chilcutt/auto-correct-git-spelling-mistakes-3896</guid>
      <description>&lt;p&gt;I use git a lot for both work and personal projects, which means I type a lot of commands each day. git has a built-in spelling auto-correct system for when you’re not quite having the most precise day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; auto-correct git spelling mistakes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git config --global help.autoCorrect 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This turns this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UVdoPCI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/996/1%2ARTZe8E30Kvdyn929OuCnBQ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UVdoPCI_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/996/1%2ARTZe8E30Kvdyn929OuCnBQ.gif" alt=""&gt;&lt;/a&gt;aarrggghhhh&lt;/p&gt;

&lt;p&gt;To this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Db3-zbiD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/996/1%2A_gsovN49Hcda_msIT4MieA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Db3-zbiD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/996/1%2A_gsovN49Hcda_msIT4MieA.gif" alt=""&gt;&lt;/a&gt;aww yiss&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git config --global help.autoCorrect 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The argument is the number of deciseconds (0.1 sec) to wait before correcting and executing a command and 1 is the shortest possible delay. If only a single option is found it will be executed, if multiple commands could be possible, it will error and ask you to try again:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5UKq7kwY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/996/1%2A0F0D-F4z2VNCvsDWTzUdGQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5UKq7kwY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/996/1%2A0F0D-F4z2VNCvsDWTzUdGQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Combined with a handful of bash aliases for the ways I commonly misspell git and there’s a chance I can get some stuff done without that extra cup of coffee.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ alias gi='git'
$ alias gti='git'
$ alias gits='git'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I probably accidentally use this git config more than any other…&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>programming</category>
      <category>bash</category>
    </item>
    <item>
      <title>git current</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Wed, 17 Apr 2019 07:00:00 +0000</pubDate>
      <link>https://forem.com/chilcutt/git-current-15g0</link>
      <guid>https://forem.com/chilcutt/git-current-15g0</guid>
      <description>&lt;p&gt;As an avid &lt;code&gt;vim&lt;/code&gt; user, I have a weird aversion to ever using the mouse/trackpad to do anything–especially while at the command line. I noticed that one common thing for me to do was to run git branch or git status to see what branch I was on in order to use the branch name in another command. I didn’t like that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; create a git alias for seeing your current branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config alias.current &lt;span class="s2"&gt;"rev-parse --abbrev-ref HEAD"&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git current &lt;span class="c"&gt;# displays the current branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The aliased command prints the current branch that you’re on to &lt;code&gt;STDOUT&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BzXdaIjb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AQvA9ubVXTQwsUIPmiI6hNA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BzXdaIjb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AQvA9ubVXTQwsUIPmiI6hNA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we have the alias created, we can do this even more simply:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dkm4FLk7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AfK9Yii2QMsIDjsASz5FdOQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dkm4FLk7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AfK9Yii2QMsIDjsASz5FdOQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The real beauty of the command is when you use it to compose another shell command. Let’s say I’m about to take on a few complicated and potentially dangerous operations and I want to create a backup branch because I don’t like spelunking the ref list if I can avoid it. I can easily create a backup branch based on the same name now:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C1NRucPC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Alj8i1we_cR5hvOCh_4pZ4g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C1NRucPC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Alj8i1we_cR5hvOCh_4pZ4g.png" alt="git current composition"&gt;&lt;/a&gt;Useful in a case with a more complicated base branch name...&lt;/p&gt;

&lt;p&gt;Or if I realize I’ve gone down the wrong path and need to start over:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T1Br8R_Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ASzFFqSLxTPJB43EF2hp3UA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T1Br8R_Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ASzFFqSLxTPJB43EF2hp3UA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Being lazy sometimes sparks some cool ideas for minor tips/tricks/hacks that just make work more enjoyable. What are your favorites?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>devtips</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Ad-hoc reverse SSH for getting things from remote locations</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Fri, 05 Apr 2019 07:00:00 +0000</pubDate>
      <link>https://forem.com/chilcutt/ad-hoc-reverse-ssh-for-getting-things-from-remote-locations-2ej8</link>
      <guid>https://forem.com/chilcutt/ad-hoc-reverse-ssh-for-getting-things-from-remote-locations-2ej8</guid>
      <description>&lt;p&gt;As a web developer, I’m often working with remote servers over SSH. Sometimes I’m working with a file on the remote server and want to get it back to my local machine (e.g. script output, a CSV, or a log file). One way I can easily get them back is by opening a reverse SSH port along my connection to the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; open a reverse connection to your local computer and &lt;code&gt;scp&lt;/code&gt; a file home&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# from the remote shell, get into the SSH prompt
$ &amp;lt;enter&amp;gt; ~C

ssh&amp;gt; -R 127.0.0.1:2222:127.0.0.1:22

$ scp -P2222 move_this_file.txt kyle@127.0.0.1:~/Downloads
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let’s take a look at what’s going on here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ &amp;lt;enter&amp;gt; ~C
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That’s the “enter” key, followed by a “tilde”, followed by a capital “C”. This string of keystrokes will get you into the &lt;code&gt;ssh&lt;/code&gt; command line and give you a new prompt.&lt;/p&gt;

&lt;pre&gt;
ssh&amp;gt; &lt;b&gt;-R&lt;/b&gt; 127.0.0.1:2222:127.0.0.1:22
&lt;/pre&gt;

&lt;p&gt;From the new prompt we’re going to request a remote forward port…&lt;/p&gt;

&lt;pre&gt;
ssh&amp;gt; -R &lt;b&gt;127.0.0.1:2222&lt;/b&gt; :127.0.0.1:22
&lt;/pre&gt;

&lt;p&gt;From the remote machine on port 2222…&lt;/p&gt;

&lt;pre&gt;
ssh&amp;gt; -R 127.0.0.1:2222: &lt;b&gt;127.0.0.1:22&lt;/b&gt;
&lt;/pre&gt;

&lt;p&gt;To the local machine on port 22.&lt;/p&gt;

&lt;p&gt;Once this is set up, we can see a forwarded port opened on port 2222:&lt;/p&gt;

&lt;pre&gt;
$ netstat -nap | grep 2222 tcp 0 0 127.0.0.1: &lt;b&gt;2222&lt;/b&gt; 0.0.0.0:*
&lt;/pre&gt;

&lt;p&gt;We can then use this port to connect to the SSH server on the local machine and move any files using the scp command (or any command that can use the SSH connection).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ scp -P2222 move_this_file.txt kyle@127.0.0.1:~/Downloads
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the case above, I’m sending the file named &lt;code&gt;move_this_file.txt&lt;/code&gt; to my local machine in my Downloads folder off my home directory.&lt;/p&gt;

&lt;p&gt;When you close the SSH connection to the remote server, the port forward will also be closed.&lt;/p&gt;




&lt;p&gt;If you’re on MacOS, you have an SSH server preinstalled on your machine that’s not active, you can turn it on from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo systemsetup -setremotelogin on
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;p&gt;&lt;em&gt;If you’re forward thinking enough, you can open this SSH remote port forward when you first connect to the remote server:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh -R 127.0.0.1:2222:127.0.0.1:22 remote_user@remote_server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I don’t usually anticipate that far ahead…&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>devops</category>
      <category>bash</category>
      <category>tips</category>
    </item>
    <item>
      <title>nohup for running remote scripts</title>
      <dc:creator>Kyle Chilcutt</dc:creator>
      <pubDate>Thu, 04 Apr 2019 07:00:00 +0000</pubDate>
      <link>https://forem.com/chilcutt/nohup-for-running-remote-scripts-56ah</link>
      <guid>https://forem.com/chilcutt/nohup-for-running-remote-scripts-56ah</guid>
      <description>&lt;p&gt;I’ve been aware of &lt;code&gt;nohup&lt;/code&gt; for a while, but never took the time to do a deeper dive until today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; run a command that won’t die when you log out (useful for tasks on a remote server)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nohup my_long_running_script &amp;gt; script_results.out 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2428%2F1%2Avpv1N6DEHAW-alSBREEZSg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2428%2F1%2Avpv1N6DEHAW-alSBREEZSg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;nohup&lt;/code&gt; utility lets your run another command that is immune to hangups, meaning that it won’t die when you log out of the machine. This is particularly useful for when you’re connected to the terminal of a remote machine (e.g. using &lt;code&gt;ssh&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Let’s break down the example from the beginning:&lt;/p&gt;

&lt;pre&gt;
$ &lt;b&gt;nohup&lt;/b&gt; my_long_running_script &amp;gt; script_results.out 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;nohup&lt;/code&gt; utility causes the script being run to be immune to &lt;a href="https://en.wikipedia.org/wiki/SIGHUP" rel="noopener noreferrer"&gt;&lt;code&gt;SIGHUP&lt;/code&gt;&lt;/a&gt;, the signal which is sent to a process when the terminal controlling it is closed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2840%2F1%2AUSBgmRf4noGAv1-ydENpfQ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2840%2F1%2AUSBgmRf4noGAv1-ydENpfQ.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;
$ nohup &lt;b&gt;my_long_running_script &amp;gt; script_results.out&lt;/b&gt; 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/pre&gt;

&lt;p&gt;The next part is running the command as usual and sending the output to a text file. Because we’re going to disconnect from this terminal session, we’re not going to be observing the output live as the script runs. To capture the output, we direct the output to a file &lt;code&gt;script_results.out&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;
$ nohup my_long_running_script &amp;gt; script_results.out &lt;b&gt;2&amp;gt;&amp;amp;1&lt;/b&gt; &amp;amp;
&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;2&amp;gt;&amp;amp;1&lt;/code&gt; redirects &lt;code&gt;STDERR&lt;/code&gt; to &lt;code&gt;STDOUT&lt;/code&gt;, which will allow us to capture both normal output and error output in our results file.&lt;/p&gt;

&lt;pre&gt;
$ nohup my_long_running_script &amp;gt; script_results.out 2&amp;gt;&amp;amp;1 &lt;b&gt;&amp;amp;&lt;/b&gt;
&lt;/pre&gt;

&lt;p&gt;The final &lt;code&gt;&amp;amp;&lt;/code&gt; causes the nohup command to be run in the background, so that we’re returned immediately to the shell once the command has been started.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Prior to this, I might have started a &lt;code&gt;tmux&lt;/code&gt; or &lt;code&gt;screen&lt;/code&gt; session on the remote machine to make sure the script cannot be interrupted, but nohup feels a lot more straight-to-the-point.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>bash</category>
      <category>shell</category>
      <category>commandline</category>
    </item>
  </channel>
</rss>
