Jekyll2020-07-29T19:42:13+00:00/feed.xmlSwap vim splits from horizontal to vertical2020-06-15T15:39:50+00:002020-06-15T15:39:50+00:00/2020/06/swap-vim-splits<p>I was pairing with a coworker the other day when they asked:</p>
<blockquote>
<p>How do I swap these Vim splits from horizontal to vertical?</p>
</blockquote>
<p>Visually, they wanted to do <!--more-->this:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>+----------------------+ +------------+-------------+
| | | | |
| A | | | |
| | | | |
+----------------------+ -> | A | B |
| | | | šļø |
| B | | | |
| šļø | | | |
+----------------------+ +------------+-------------+
</code></pre></div></div>
<p>A simple question with several different solutions<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote">1</a></sup>.</p>
<p>My prefered way to reposition panes is to use window move commands<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote">2</a></sup> From normal mode press <code class="highlighter-rouge">Ctrl</code>-<code class="highlighter-rouge">w</code>, then <code class="highlighter-rouge">H</code>, <code class="highlighter-rouge">J</code>, <code class="highlighter-rouge">K</code>, or <code class="highlighter-rouge">L</code> to send the current pane to a far side. Note the capital <code class="highlighter-rouge">HJKL</code>, which correspond to left, bottom, top, or right.</p>
<p>To move Split B from the bottom to right, use <code class="highlighter-rouge">Ctrl</code>-<code class="highlighter-rouge">w</code> <code class="highlighter-rouge">L</code></p>
<p><code class="highlighter-rouge">Ctrl</code>-<code class="highlighter-rouge">w</code> <code class="highlighter-rouge">H</code> would put Split B on the left vertical split.</p>
<p>Writing this down in case it helps someone else out there š¤ļø</p>
<div class="footnotes" role="doc-endnotes">
<ol>
<li id="fn:1" role="doc-endnote">
<p>There are always lots of ways to do these things, including <code class="highlighter-rouge">Ctrl</code>-<code class="highlighter-rouge">w</code> <code class="highlighter-rouge">x</code>, which will exchange windows when there are not multiple splits openĀ <a href="#fnref:1" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
<li id="fn:2" role="doc-endnote">
<p>See <code class="highlighter-rouge">:help window-moving</code>Ā <a href="#fnref:2" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
</ol>
</div>I was pairing with a coworker the other day when they asked: How do I swap these Vim splits from horizontal to vertical? Visually, they wanted to doBuild an AirPlay Server From your Raspberry Pi Zero W2017-08-17T00:00:00+00:002017-08-17T00:00:00+00:00/2017/08/build-an-airplay-service-from-a-raspberry-pi-zero-w<p>This summer, I wanted to buy a new AirPlay receiver for my back deck. For some reason, you canāt buy a simple device anymore, so I decided to build my own. Hereās how I did itā¦
<!--more--></p>
<h3 id="overview">Overview</h3>
<p>Weāre going to use a Raspberry Pi Zero W, and <a href="https://github.com/mikebrady/shairport-sync">shairport-sync</a>, to turn it into an AirPlay receiver.</p>
<p>Along the way, Iāll walk through how to install the OS, enable SSH and wifi, set a custom hostname, and change the default password..</p>
<p>Once weāre done, the Raspberry pi will appear as an option in the iOS AirPlay list, just like any āofficialā AirPlay device.</p>
<h3 id="step-1-hardware">Step 1: Hardware</h3>
<p>The Raspberry Pi Zero W is the smallest, cheapest wifi enabled member of the Raspi family. Reviews of the Zero W mentioned it had poor sound quality, so I decided to add on a Digital audio converter (DAC). This meant Iād need to do some soldering, but the finished result has worked out great.</p>
<p><strong>The Parts:</strong></p>
<p>This is what I purchased, feel free to improvise.</p>
<ul>
<li><a href="https://www.adafruit.com/product/3400">Raspberry Pi Zero W</a> ($10)</li>
<li><a href="https://www.adafruit.com/product/3016">Pimoroni Phat DAC</a> ($15)</li>
<li><a href="https://www.adafruit.com/product/2822">Header pins</a> ($1)</li>
<li><a href="https://www.adafruit.com/product/1294">MicroSD card</a> ($10)</li>
<li><a href="https://www.adafruit.com/product/1995">USB Power adapter</a> ($7.5)</li>
</ul>
<p>Youāll also need a computer with an SD Card slot to setup the OS.</p>
<p><strong>The Assembly:</strong></p>
<p>Using the header pins, solder the DAC to the Pi, <a href="https://learn.pimoroni.com/tutorial/sandyj/soldering-phats">per these instructions</a>.</p>
<p>The end result should look similar to this:</p>
<p><img src="/img/build-an-airplay-service-from-a-raspberry-pi-zero-w/pi-with-dac.jpg" alt="" /></p>
<h3 id="step-2-install-operating-system">Step 2: Install Operating System</h3>
<p>Nothing fancy here, weāre going to install a headless version of <a href="https://www.raspbian.org">Raspbian</a> (the standard flavor of linux for Raspberry Pi)</p>
<p>On your computer (not on the Pi), insert the SD card.</p>
<p>Install OS with these steps:</p>
<ol>
<li>Visit <a href="https://www.raspberrypi.org/downloads/raspbian/">raspberrypi.org/downloads/raspbian</a></li>
<li>Download the āLiteā version because we will be running headless</li>
<li>While the image downloads, download and install <a href="http://etcher.io">Etcher</a>, which weāll use to easily copy the Raspian to the SD card</li>
<li>Launch Etcher, select the new linux image, and the SD card.</li>
<li>Press the āFlash!ā button, and install the OS
<img src="/img/build-an-airplay-service-from-a-raspberry-pi-zero-w/etcher.png" alt="" /></li>
</ol>
<h3 id="step-3-enable-ssh-in-raspbian-os">Step 3: Enable SSH in Raspbian OS</h3>
<p>Before booting up our new Raspberry Pi, we need to enable SSH. We do this by adding an empty file to the <code class="highlighter-rouge">boot</code> folder on the SD card.</p>
<p>Once Etcher finishes installing Raspian on your SD card, run the following: (this is from my mac, your directory path may vary)</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">touch</span> /Volumes/boot/ssh
</code></pre></div></div>
<h3 id="step-4-boot-up-your-raspberry-pi">Step 4: Boot up your raspberry pi!</h3>
<p>You can now insert the SD card in the Pi, and power it on.</p>
<p>To configure the Pi for your wireless network, weāre going to connect initially over the USB port labeled ādataā. This allows us to SSH over USB using OTG networking network connection. <a href="https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a">More background here</a>.</p>
<p><strong>Steps:</strong></p>
<ol>
<li>Connect your computer to the Piās USB port labeled ādataā</li>
<li>Boot up the Pi š¤</li>
<li>Once the Pi has booted up, you should be able to SSH in by running</li>
</ol>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ssh pi@raspberry.local <span class="c">#default password is `raspberry`</span>
</code></pre></div></div>
<blockquote>
<p>NOTE from now on all commands will be run in the SSH session we just created above.</p>
</blockquote>
<h3 id="step-5-finish-configuring-your-raspian-os">Step 5: Finish configuring your Raspian OS</h3>
<p>Now that we can SSH into the running Raspberry Pi, lets update the default password/hostname, and enable wifi.</p>
<h4 id="change-the-default-password">Change the default password</h4>
<p>Change the default password for <code class="highlighter-rouge">pi</code> by running</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>passwd
</code></pre></div></div>
<h4 id="update-the-hostname">Update the hostname</h4>
<p>Your Airplay selection menu will display the hostname your Pi, so lets choose a memorable name. Iām naming mine <code class="highlighter-rouge">airplay_pi</code></p>
<ol>
<li>
<p>Update the hostname by running</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">hostname</span>
</code></pre></div> </div>
</li>
<li>
<p>Update <code class="highlighter-rouge">/etc/hosts</code></p>
<div class="language-diff highlighter-rouge"><div class="highlight"><pre class="highlight"><code> - 127.0.1.1 raspberrypi
+ 127.0.1.1 airplay_pi
</code></pre></div> </div>
</li>
<li>
<p>Update <code class="highlighter-rouge">/etc/hostname</code></p>
<div class="language-diff highlighter-rouge"><div class="highlight"><pre class="highlight"><code> - raspberrypi
+ airplay_pi
</code></pre></div> </div>
</li>
</ol>
<h4 id="setup-wifi">Setup wifi</h4>
<p>We can manually set the routerās network name and password by adding it to <code class="highlighter-rouge">/etc/wpa_supplicant/wpa_supplicant.conf</code></p>
<ol>
<li>Run
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
</code></pre></div> </div>
</li>
<li>At the bottom of the file add the following:
<div class="language-properties highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="py">network</span><span class="p">=</span><span class="s">{</span>
<span class="py">ssid</span><span class="p">=</span><span class="s">"testing"</span>
<span class="py">psk</span><span class="p">=</span><span class="s">"testingPassword"</span>
<span class="err">}</span>
</code></pre></div> </div>
</li>
<li>
<p>Shut it down with <code class="highlighter-rouge">sudo poweroff</code> and disconnect it from your laptop.</p>
<p><a href="https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md">See more in the Raspberry Pi docs</a></p>
<blockquote>
<p>NOTE: If you change your wifi password in the future, youāll need to connect over USB and update this file accordingly</p>
</blockquote>
</li>
</ol>
<p>Ok, you can now connect to the Raspberry Pi on your wireless network by running <code class="highlighter-rouge">ssh pi@airplay_pi.local</code> š¤š¤</p>
<h3 id="step-6-power-on-and-connect-to-your-home-network">Step 6: Power on, and connect to your home network</h3>
<p>In this section weāll use our new wifi connection to install the DAC drivers, and the airplay server.</p>
<ol>
<li>
<p>Install the DAC software</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code> curl https://get.pimoroni.com/phatdac | bash
</code></pre></div> </div>
<p>See more at the <a href="https://learn.pimoroni.com/tutorial/phat/raspberry-pi-phat-dac-install">official setup guide</a>.</p>
</li>
<li>
<p>Install airplay software</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nb">sudo </span>apt-get <span class="nb">install </span>shairport-sync
</code></pre></div> </div>
</li>
</ol>
<h3 id="step-7-enjoy-your-new-airplay-device">Step 7: Enjoy your new AirPlay device!</h3>
<p>At this point we should be able to see our Pi as an option from the airplay menu on your iOS device.</p>
<!-- [TODO] image -->
<p>Plug the Pi into some speakers, connect to <code class="highlighter-rouge">airplay_pi</code> and enjoy your new Airplay speakers! š¤š¤š¤</p>This summer, I wanted to buy a new AirPlay receiver for my back deck. For some reason, you canāt buy a simple device anymore, so I decided to build my own. Hereās how I did itā¦