<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lee Bardon on Medium]]></title>
        <description><![CDATA[Stories by Lee Bardon on Medium]]></description>
        <link>https://medium.com/@leerbardon?source=rss-ee13e196da1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wIprDRzG4yBuhHXBclHHkg.jpeg</url>
            <title>Stories by Lee Bardon on Medium</title>
            <link>https://medium.com/@leerbardon?source=rss-ee13e196da1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:29:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leerbardon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build a DIY Supercomputer: Part 2!]]></title>
            <link>https://medium.com/@leerbardon/build-a-diy-supercomputer-part-2-8a40a484c0e2?source=rss-ee13e196da1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a40a484c0e2</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Lee Bardon]]></dc:creator>
            <pubDate>Sat, 05 Sep 2020 13:58:33 GMT</pubDate>
            <atom:updated>2020-09-14T14:13:51.021Z</atom:updated>
            <content:encoded><![CDATA[<h4>Operating System Configuration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EW8jiLCsnIRGahlnd3goOA.jpeg" /><figcaption><strong>My Odroid N2+ Cluster</strong>: Janky, homemade casing optional :)</figcaption></figure><p>Hello again! In <a href="https://medium.com/the-innovation/build-a-diy-supercomputer-a6461b2087d3"><strong>PART ONE</strong></a>, we assembled the hardware and components needed to build a distributed computing cluster using readily-available single board computers (SBC’s). The Raspberry Pi is a popular choice of SBC, largely due to its extensive community, and associated instructional materials (check out Jeff Geerling’s <a href="https://www.pidramble.com/">fantastic site</a>). However, I opted for the Odroid N2+, due to its superior performance.</p><p>In this article, we’ll get technical, and begin the process of transforming our lump of silicon, metal and children’s lunchbox lids, into a fully-fledged parallel and distributed computing workhorse!</p><h4>1. Choose Operating System</h4><p>Every computer needs an operating system (OS). An operating system is an essential tool for managing a computer’s memory and processes, and all of its software and hardware. It also allows us to communicate with the computer, without needing to be fluent in binary. The first thing you need to be aware of when choosing an OS for your nodes is that, in common with mobile devices, many SBC’s run on ARM processors and architecture. These are less powerful than e.g. the Intel processors found in desktops and laptops, but they also consume much less power, and generate much less heat. They are also much more diverse that a generic Intel/AMD architecture.</p><p>As such, they not only require an OS that has been compiled for use with ARM architectures, but ideally with your particular system. The manufacturer will typically have downloadable disk images available for your particular units, often in several ‘flavours’. In my case, I decided to use a <a href="https://wiki.odroid.com/getting_started/os_installation_guide#operating_systems_we_re_providing"><strong>Ubuntu MATE 18.04 image</strong></a>, which I obtained from Hardkernel (the manufacturer of the Odroid N2+ unit).</p><h4>2. Flash SD Cards</h4><p>The next step is to load the OS onto your microSD cards, for which you’ll need access to a laptop or desktop (<em>NOTE:</em> I opted for microSD cards for financial reasons; they aren’t super stable over time, so if you can afford it, eMMC cards, or even full external SSD hard drives, are the better option).</p><p>There are several ways to achieve this, but among the simplest is to use the excellent cross-platform, open-source utility <a href="https://www.balena.io/etcher/"><strong>Etcher</strong>,</a> which will streamline the process for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*rh4X2meS6kJQHCFKx_aJVw.jpeg" /><figcaption>Oooh, pretty!</figcaption></figure><p>Simply download your chosen OS image onto your laptop/desktop, insert the SD card and reader, fire up Etcher, and follow the instructions!</p><h4>3. Configure Operating System</h4><p>Once you’ve flashed the OS images onto your chosen storage devices, insert them into the respective slots on your SBC. Starting with your master node (choose either the bottom or top device for this, for ease), connect your ethernet cable and adjust the boot selector switch according to whether you’re using eMMC or microSD to boot.</p><p>For the master node, you should also connect the ethernet dongle to a USB port. I also connected my USB keyboard and mouse and HDMI cable, although it’s possible to SSH in from your laptop/desktop, assuming that the SBC is connected to your home network, and that you can obtain IP address (using your service provider’s network manager, or a scanning utility e.g. <a href="https://inetapp.de/en/inetx.html">iNet</a>).</p><p>If all has gone to plan, you’ll now be greeted with something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xaDVaG97tUIXvyhaS18ZEQ.jpeg" /><figcaption>Login screen! (emoji’s not included)</figcaption></figure><p>If you’re using the Odroid devices, you’ll typically have an initial default login of <strong>user:</strong> odroid, <strong>password: </strong>odroid. Go ahead and log in, and immediately open a terminal using <em>Ctrl-alt-T.</em></p><h4>Repeat After Me</h4><p>The following processes will need to be performed separately on all of your nodes, with some slight variations in the case of the master node (the one you have plugged the USB ethernet dongle into).</p><p>The first thing we need to do, is obtain the hardware MAC address for each node; these will be needed for configuring our network (I’ll cover this in the next post in the series). In the terminal, issue the command <strong><em>ifconfig. </em></strong>You’ll be greeted with something like the following:</p><blockquote>eth0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; mtu 1500<br> inet 192.168.1.116 netmask 255.255.255.0 broadcast 10.10.10.255<br> inet6 fe80::53e4:558:a0c9:211f prefixlen 64 scopeid 0x20&lt;link&gt;<br> ether <strong><em>00:1d:06:42:52:bg </em></strong>txqueuelen 1000 (Ethernet)<br> RX packets 7207 bytes 816740 (816.7 KB)<br> RX errors 0 dropped 0 overruns 0 frame 0<br> TX packets 8593 bytes 5631670 (5.6 MB)<br> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0<br> device interrupt 22</blockquote><blockquote>lo: flags=73&lt;UP,LOOPBACK,RUNNING&gt; mtu 65536<br> inet 127.0.0.1 netmask 255.0.0.0<br> loop txqueuelen 1 (Local Loopback)<br> RX packets 152 bytes 11348 (11.3 KB)<br> RX errors 0 dropped 0 overruns 0 frame 0<br> TX packets 152 bytes 11348 (11.3 KB)<br> TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</blockquote><p>I’ve highlighted the area where you’ll find the unit’s MAC address in bold. Make a note of this somewhere, and ensure that you know which unit this MAC address refers to. For the master node, you will also need the MAC address for the dongle. This will be found using the same command, in the block starting with <strong><em>eth1. </em></strong>It’s possible that your device will use names other than <strong><em>eth0</em></strong> and <strong><em>eth1</em></strong>, but using the above structure, you should be able to work it out.</p><p>Next, install and run the <a href="https://github.com/mdrjr/odroid-utility"><strong><em>Odroid Utility</em> tool</strong></a><strong> </strong>by entering the following four commands into your terminal:</p><pre>&gt;&gt; sudo -s  </pre><pre>&gt;&gt; wget -O /usr/local/bin/odroid-utility.sh <a href="https://raw.githubusercontent.com/mdrjr/odroid-utility/master/odroid-utility.sh">https://raw.githubusercontent.com/mdrjr/odroid-utility/master/odroid-utility.sh</a></pre><pre>&gt;&gt; chmod +x /usr/local/bin/odroid-utility.sh</pre><pre>&gt;&gt; odroid-utility.sh</pre><p>The first command, <strong><em>sudo -s</em></strong>, will drop you into root user/administrator. The second command, beginning <strong><em>wget -O,</em></strong> obtains the <em>odroid-utility.sh</em> shell package from its Github repo, and adds it to the <strong><em>/usr/local/bin/</em></strong> directory on your machine. The <strong><em>chmod +x</em></strong> command sets the file permissions, to allow the shell script to be executed, and, finally, <strong><em>odroid-utility.sh </em></strong>runs the script. You should see the following screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_LlRQoE5Ds71nKVTu8rRCw.png" /></figure><p>Here, we want to perform three actions:</p><ol><li><strong>Name the Node: </strong>Select the “Change Hostname” option. Name the node with the ethernet dongle master, and the other three worker1, worker2, and worker3. Note that you can call them whatever you want, as long as you’re consistent :)</li><li><strong>Turn off Xorg</strong>: In the next instalment of this series, we’ll cover network configuration, and will ultimately run these nodes ‘headless’. Thus, we don’t need the added overhead of a GUI that is launched by default. Turning Xorg to <em>‘off’ </em>will prevent this from happening.</li><li><strong>Resize Root Partition:</strong> Whille flashing the microSD, we created the root file system with a 4 GB partition, meaning that there is unclaimed space on your drive. Using <em>“Resize your root partition”</em> will make available all remaining space.</li></ol><p>Once we’ve completed the above, we’ll need to update the <strong><em>hosts</em></strong> file on each machine, to help make each member of our cluster visible. To do so, I use the terminal-based text editor Vim, which <a href="https://medium.com/analytics-vidhya/terminal-based-text-editing-5fe946efdca0">I wrote about on a previous blog</a>. This doesn’t always come as standard, so you’ll have to:</p><pre>&gt;&gt; sudo apt-get install vim </pre><p>As root user, open the hosts file using:</p><pre>vim /etc/hosts</pre><p>And adjust the contents of the file to the following:</p><pre>127.0.0.1       localhost<br>10.10.10.1      master<br>10.10.10.2      worker1<br>10.10.10.3      worker2<br>10.10.10.4      worker3<br>::1             localhost ip6-localhost ip6-loopback<br>ff02::1         ip6-allnodes<br>ff02::2         ip6-allrouters</pre><p>Finally, shutdown the node from the terminal using:</p><pre>shutdown -h now</pre><p>swap the keyboard, mouse and HDMI into the next machine, and repeat!</p><p>Once you’ve done all of the above for each node in your cluster, we’re ready to move onto the next stage: configuring the network to complete the set-up of your compute cluster, with it’s very own network backbone.</p><p>P.S. In the event that you get stuck with the above, please refer to the following useful resource. Until next time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*f7qf-p0fgfGRMEIXhY429A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a40a484c0e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build A DIY Supercomputer!]]></title>
            <link>https://medium.com/@leerbardon/build-a-diy-supercomputer-a6461b2087d3?source=rss-ee13e196da1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6461b2087d3</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[hpc]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Lee Bardon]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 21:24:34 GMT</pubDate>
            <atom:updated>2020-09-05T14:09:12.635Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build A DIY Supercomputer: Part 1!</h3><h4>Hardware Build (Odroid N2+ cluster)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4LD8oGNFoNkJIvmvCdv1w.png" /></figure><p>Ok, so perhaps ‘Supercomputer’ is a bit grand, but by the end of this three-part series, you’ll have the knowledge required to build your very own home parallel computing cluster using widely-available materials. And the best part is that, not only is it inexpensive to run (thanks to the ARM-based architecture), but the whole project will cost you less than £400, plus a day or two of your time.</p><h3>1. WHY?</h3><p>The chances are that if you’ve read this far, you already understand the potential use cases and benefits. But just in case, I’ll first outline my own reasons for undertaking this project.</p><p>Once upon a time, I was a PhD student in computational geophysics. Shortly after (upon a time), I left to pursue an entirely unrelated, nontechnical business opportunity… before ultimately deciding that I missed the challenge and thrill of research. As a result, I’ve dedicated the greater part of the last year to doing everything I can to improve my programming and data science skills. In doing so, I have reinitiated relationships with contacts in the academic world, and have recently entered into some informal research collaborations.</p><h4>1a. Computational Need</h4><p>My role in these collaborations involves processing large geospatial datasets in a variety of ways, before applying some machine learning analyses. Unfortunately, since I’m not currently an official member of any research institution, my only computational tool is my laptop. While it’s certainly possible to perform most of these analyses on my laptop, it can take many hours at a time in some cases, during which the CPU load is consistently high.</p><p>Of course, building your own home cluster is not the only solution for data science enthusiasts with relatively demanding computational requirements: there are numerous cloud computing options that could accomplish a similar feat, and perhaps even less expensively (depending on your requirements). But computational need is not my only reason…</p><h4>1b. Opportunity to Learn</h4><p>During my last stint as a computationally-focused research student, we had two options when it came to running simulations and/or processing data.</p><p>The first option was to use the lab’s desktop workstations for smaller-scale test simulations, and for post-processing. These were 16-core machines with much greater capabilities than the average PC desktop; and a much greater price tag to go along with it. Given my minimal budget, I knew this wouldn’t be an option. In addition, while powerful and usually available, the workstations were not able to utilise parallel computing methods.</p><p>The second option involved being allocated time on the lightening-fast, state-of-the-art university or national supercomputer clusters, that could handle anything we threw at them. However, they are also shared by many, many researchers, and resources are allocated very sparingly. There was often a queue for submitted jobs, and, especially for new and inexperienced PhD students, there was a good chance that your scripts or simulations would fail for some reason, bumping you right back down the queue.</p><p>It often struck me that new HPC users would be better off learning the do’s and don’ts of parallel and distributed computing using smaller scale clusters, rather than wasting precious national supercomputer resources. Indeed, some academics champion the use of Raspberry Pi clusters for this exact reason, and online tutorials already exist within the Raspberry Pi community.</p><p>So, the decision was easy: <em>I was going to build my own home cluster!</em></p><h3>2. EQUIPMENT</h3><p>We’ll go through the details of network design later in this post, with OS set-up in subsequent posts. For now, we’ll stick to gathering and assembling the required hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPouLhjDIjCU62OKFwNHXw.jpeg" /><figcaption><strong>Fig 1. </strong>My Set Up<strong> </strong>(your specific requirements may vary)</figcaption></figure><ol><li><em>Ethernet Switch with power cable (8-port);</em></li><li><em>Odroid N2 x 4 with power cables (I’ll detail why I chose these SBC’s below);</em></li><li><em>Bases For Each SBC ~15cm x 15cm (I repurposed tupperwear box lids);</em></li><li><em>MicroSD cards x 4 (64GB), MicroSD card reader x 1, Ethernet dongle x 1;</em></li><li><em>USB keyboard and mouse (required for initial set-up);</em></li><li><em>Ethernet cables x 5;</em></li><li><em>Male/female spacer and standoff kit (M3);</em></li><li><em>Six-way surge-protected power adapter.</em></li></ol><p>I mentioned above that Raspberry Pi’s have been used for several years to build home clusters. The large and active Raspberry Pi community has many resources that will assist in your build, should this be the route you wish to go down (I especially recommend <a href="http://www.pidramble.com/">Jeff Geerling’s fantastic </a>blog, in this regard). However, one of the criticisms against the home Pi clusters (this does not extend to <a href="https://www.zdnet.com/article/oracle-this-1060-raspberry-pi-supercomputer-is-worlds-largest-pi-cluster/">legit Pi supercomputers</a>), is that they’re a little too underpowered to do any ‘serious’ computation, with the most affordable models having e.g. single 700MHz CPU cores, and 512MB RAM.</p><p>With the release of the Raspberry Pi 4, we see a considerable increase in capabilities. Nonetheless, I opted for the recently released <a href="https://www.hardkernel.com/shop/odroid-n2-with-4gbyte-ram-2/">Odroid N2+</a> from South Korean manufacturer HardKernel. Each board has 6 cores at 2.4 GHz and 4GB RAM, a highly-efficient passive aluminium heatsink, and 800MHz GPU. In other words; it’s quite a little beast!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HWYWu-IXSbUDzXM6qEcp7g.jpeg" /><figcaption><strong>Fig 2.</strong> The new Odroid N2+ from HardKernel</figcaption></figure><h3>3. THE BUILD</h3><p>Before describing the steps needed to assemble the cluster, it would first be instructive to take a sneak-peak at the almost-finished product:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*98KdTrfLgWDuCnlSe7HmhQ.jpeg" /><figcaption><strong>Fig 3</strong>. Almost-complete. It’s…. beautiful?</figcaption></figure><p>The first stage of the build involved attaching the SBC’s to each of the bases. On the bottom of the N2, you’ll find that the heatsink has four small screw holes. The aim is to attach the each SBC to a base via these screws, and then use the M3 brass spacers to attach each unit together, one on top of the other, as per the above image.</p><p>For this, you’ll need a ruler, a pen, a drill with a 2.5–3mm bit, four of the screws that come with the M3 spacer and standoff kit, and four 12mm brass spacers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W98BFrhlBcGvnbK7ub4RCw.jpeg" /><figcaption><strong>Fig 4.</strong> Red crosses align with the holes on the heatsink, blue crosses are where we’ll attach our M3 spacers.</figcaption></figure><p>First, screw the 12mm spacers into the bottom of the heatsink. Then, drill the corresponding holes into the base, as well as the holes for the longer 60mm M3 spacers that span between each unit. Use the screws to secure each of the N2&#39;s, and assemble your tower according to the image in Fig 3.</p><h3>4. NETWORK DESIGN</h3><p>Of key consideration in building our cluster, is understanding how the nodes will interact with each other. In this case, we have 4 compute nodes, one of which will be designated as the ‘master’ node with the others operating as ‘slave nodes’.</p><p>The master node will receive incoming directions, for example, an analysis job, and then distribute that job across the other nodes in the cluster, before compiling and relying the results. In order for this to occur, each node will be connected to each other via the ethernet switch. However, in order to maximise throughput, we will set-up the cluster to operate as a single unit within your home network. Of course, this could have been achieved by purchasing a router instead of a switch, albeit at significant extra costs.</p><p>Instead, we can instruct the master node to operate as a router through the use of a USB ethernet dongle. This will require that we configure it to be both a <a href="https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol">DHCP server</a> for the cluster network, and provide the <a href="https://en.wikipedia.org/wiki/Network_address_translation">NAT service</a> between the external network and the cluster network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvrsEUd1-iYXK0pXnSIXSw.jpeg" /><figcaption><strong>Fig 5</strong>. Network design for Odroid N2+ cluster</figcaption></figure><p>We’ll cover this in a subsequent post. But for now, just connect the cables up as seen in Fig 6 below and <a href="https://medium.com/@leerbardon/build-a-diy-supercomputer-part-2-8a40a484c0e2"><strong>HEAD OVER TO PART 2</strong></a> for OS configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*80nGNOGtWf5otGetRTzrJw.jpeg" /><figcaption><strong>Fig 6</strong>. Hardware build complete! (note that the switch is at the back of the cluster)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6461b2087d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terminal-Based Text Editing:]]></title>
            <link>https://medium.com/analytics-vidhya/terminal-based-text-editing-5fe946efdca0?source=rss-ee13e196da1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fe946efdca0</guid>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Lee Bardon]]></dc:creator>
            <pubDate>Fri, 17 Apr 2020 14:16:22 GMT</pubDate>
            <atom:updated>2020-04-24T17:21:15.036Z</atom:updated>
            <content:encoded><![CDATA[<h3>Terminal-Based Text Editors:</h3><h4>Add a touch of Vim to your productivity.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*6O2fiWWJy7Ban_oF5AJejg.png" /><figcaption>Relevant xkcd :)</figcaption></figure><p>We’ve all been there. You’re just about to commit a feature update for your latest industry-disrupting app “<em>CatPicGenerator_2.0</em>”, when you find yourself in a strange and disorientating place…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxMWqhA1UvBYKsB6XMnoIQ.png" /></figure><p>In your excitement, you managed you type “<em>git commit”</em> without attaching a flag and a message. Which is fine… we all make mistakes, right? Well, git is less forgiving than your fellow programmers might be, so it hoists you into the above environment to force you to make corrections. The trouble is, you have absolutely no idea what to do next.</p><p>First, you hit <em>q</em>… Hmm. Nope.</p><p>Then, you frantically hit <em>Esc</em>, <em>Enter, ctrl-alt-delete, q q q q q q q QQQQQ!!1!!!!!1</em></p><p>Finally you mash your face into the keyboard, close the terminal, gingerly fold down your screen, and toss your laptop out the window, wide-and-glassy-eyed with utter frustration.</p><p>But it doesn’t need to be this way! You’ve simply been introduced — albeit against your will — to a terminal-based text editor called<strong> Vim</strong> and, while the learning curve is admittedly steep, it can be an efficient, powerful tool to have at your disposal. Let’s take a look.</p><h3>Why Use Vim?</h3><p>My own introduction to text based editors (and programming in general) occurred in academic surroundings, during my time as a computational scientist. The seasoned physicists around me knew nothing so fancy as VS Code, or Atom, or RubyMine or PyCharm. As far as they were concerned, the choice was simple: Vi/Vim or EMACS for writing some sweet Fortran95 or shell scripts, and Latex for preparing documents.</p><p>Somewhat arbitrarily, I decided that Vim was my text editor of choice. However, there are many who make a much more reasoned decision. They argue that, while the learning curve is steep, gaining a good degree of mastery in terminal-based editors like Vim, can hugely increase productivity over GUI-based editors.</p><p>For a start, it forces you to use the keyboard only, which means no pausing to move the mouse/trackpad, click on the screen, drag, highlight, drop, delete…. all of these actions can be done at the touch of a key, whether via pre-existing keyboard shortcuts, or ones that you’ve defined yourself in the <em>.vimrc</em> file. One of Vim’s core philosophies argues that we spend more time editing text than writing new text, so it’s built to enable rapid document editing, leaving your workflow unbroken in the process.</p><p>It’s also ubiquitous. It’s available as standard on Linux, Mac and Windows, and is often the default editor in scenarios such as e.g. the Github debacle mentioned at the beginning of this article. Indeed, it’s the only editor available to you, if you spend a lot of time in SSH’d terminal sessions, as I once did while interacting with HPC clusters.</p><p>But this immediately begs a question — if it’s so efficient, and so ubiquitous… why don’t more developers use it? We tend to hear a lot about, for example, VS Code or Atom, but very little about Vim.</p><p>The answer is that, like many powerful tools, it has a steep learning curve, and until you climb it, it can, at first, feel awkward and unintuitive to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*EoHV8AHhzZcP-nM1EQUKIg.jpeg" /><figcaption>The typical Vi/Vim learning curve.</figcaption></figure><h3>Getting Started</h3><p>For the sake of continuity, let’s return to our original Github scenario and work through how we can manage to complete our commit, or simply exit Vim, without any head-banging or laptop-tossing.</p><p>Vim supports multiple modes, but there are three that tend to be the most common; <strong>command mode</strong>, <strong>insert mode </strong>and <strong>visual mode</strong>.</p><h3>Command Mode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZLhGGpRuDWFra7v_Smygyg.png" /><figcaption>Command line begins with a colon.</figcaption></figure><p>We can access the command line by hitting <em>Esc</em>. Here, we can perform operations by typing short commands after the colon and hitting enter. For example, we can save with<em> w, </em>quit with <em>q</em>, or save and quit with <em>wq</em>. We can even force a quit without saving using <em>q!</em>.</p><p>But we can do much more than that. Using <em>:vsplit /path-to-doc/doc </em>will open a new document in splitscreen mode, for easy reference. Copy, paste and delete is <em>y</em>, <em>p</em> and <em>d</em>, respectively, and we can apply this to a whole line using <em>yy </em>or <em>dd</em>, or, indeed, to any number of lines you like by prefixing <em>yy</em> or <em>dd</em> with the relevant number (e.g. <em>5yy</em> to copy 5 lines).</p><h3>Visual Mode</h3><p>Visual mode is super useful for identifying the text that we’d like to manipulate within a document. We can initiate character-based selection using<em> v</em> (lower-case), select whole lines via<em> V</em> (upper-case), and entire blocks using <em>Ctrl+v</em><strong>.</strong></p><p>Selected characters/lines/blocks can then be deleted, copied or modified with any other Vim editing command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eyVxcaWYa1GzZZN4l7JrEg.png" /><figcaption>Visual mode, used for selecting characters, lines and blocks.</figcaption></figure><h3>Insert Mode</h3><p>This one is fairly self-explanatory. Insert mode is where we actually insert content into our document. We access it by hitting<em> Esc</em> followed by <em>i</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*od6FE8ucy4Ua_Rt_fF0nBQ.png" /><figcaption>Insert mode! It needs no explanation :)</figcaption></figure><p>So, with all of the above in mind, how would we navigate our Github-debacle? Well, we could either:</p><ol><li>Finish our commit by entering Insert Mode (<em>Esc </em>followed by <em>i</em>), and adding our flag and message, or;</li><li>Exit Vim by entering Command Mode (<em>Esc</em> followed by a semi-colon) and quitting with <em>q!.</em></li></ol><p>See? Your sanity, and your laptop, have been saved, and we’ve barely scratched the surface of Vim’s power. If you have a spare 30 minutes, type <em>Vimtutor</em> in to your terminal and follow along. You can thank me later…. And yes, I do accept cash, thanks for asking.</p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fe946efdca0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/terminal-based-text-editing-5fe946efdca0">Terminal-Based Text Editing:</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Relationship Advice]]></title>
            <link>https://medium.com/@leerbardon/relationship-advice-d8f909b2a25e?source=rss-ee13e196da1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8f909b2a25e</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[object-relational-mapping]]></category>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Lee Bardon]]></dc:creator>
            <pubDate>Wed, 04 Mar 2020 10:50:36 GMT</pubDate>
            <atom:updated>2020-03-04T12:48:26.940Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guide to Associations in Ruby on Rails</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAQZpHghl1ejGAwgxTcdmA.png" /></figure><p>Ruby on Rails is an open-source, server-side framework that enables fast, efficient web development. It does this by providing a full MVC (model, view, controller) framework that automates many of the time-consuming tasks associated with the web development cycle. Beyond the programming language on which it’s built (Ruby… obvs), Rails is formed of several components, including an ORM layer called <strong>Active Record</strong>.</p><blockquote>“Sooo… what’s an ORM?”</blockquote><p>Good question. ORM stands for ‘<em>object-relational mapping</em>’, and it allows you to convert data stored in a <strong>relational</strong> database, into an <strong>object</strong> that can be used and manipulated within an object oriented language like Ruby.</p><p>For example, let’s say you have a database of <strong>hamsters</strong>, and their <strong>owners</strong>. Perhaps you’d like to obtain an array of<strong> all</strong> hamster objects? Rather than going through the arduous process of writing code to connect to the database, writing a SQL query like SELECT * FROM hamsters and converting those results into an array, Active Record allows you to simply type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpAss3V1by4DWrxKry7QNg.png" /></figure><p>But the magic doesn’t stop there! What if one of our owners adds a new hamster to his or her collection? Without Active Record associations, we’d have to do something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g73BXKP7eUOZ-pHhy05S8A.png" /></figure><p>And what if, shortly thereafter, said owner decides they’ve had enough of adopting hamsters, and wants to be removed from our database?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBTcNv5Wq0z9KbbaRoc41g.png" /></figure><p>Fine… but, what happens when we correctly set-up our Active Record associations? Well, these operations, and many more, become much simpler. If we say that an <strong>owner </strong>has_many <strong>:hamsters</strong>, dependant: destroy, and a <strong>hamster </strong>belongs_to <strong>:owner</strong>, then these two operations become shortened to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6sAxtS8UtgRFSTDyW9EVwg.png" /></figure><p>and;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0rVDZf04-qXxrLeWNCZw6w.png" /></figure><p>Active Record allow you to perform many kinds of database operations in a similarly succinct, elegant, and efficient manner, through these <strong>associations:</strong></p><ul><li>belongs_to</li><li>has_one</li><li>has_many</li><li>has_many :through</li><li>has_one :through</li><li>has_and_belongs_to_many</li></ul><p>Which implement the following <strong>relationships:</strong></p><ul><li>One-to-Many</li><li>Many-to-Many</li><li>One-to-One</li><li>Polymorphic</li></ul><h3>S’all good, man!</h3><p>Better Call Saul is one of my favourite TV shows of recent years. With that in mind, I was inspired to create an illustrative - albeit contrived - example of some common AR associations, based on the interaction between <strong>lawyers</strong>, <strong>clients</strong>, and<strong> cases</strong>.</p><p>I instantiate my lawyer and client objects with a name and an age. In this instance, a<em> lawyer </em>can <strong>have many</strong> <em>cases</em>, and a <em>client </em>can have many <em>cases. </em>Meanwhile, a given <em>case</em> <strong>belongs to</strong> a specific <em>lawyer</em>, and a specific <em>client</em>. This is a <a href="https://guides.rubyonrails.org/association_basics.html#the-has-many-association"><strong>one-to-many</strong></a><strong> </strong>relation - probably the most widely used type. When we instantiate a <em>case, </em>we attach the id of the <em>lawyer </em>and the<em> client </em>that it belongs to – this id is called a <strong>foreign key</strong>, and it’s the join that enables the association between classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_EuwmIrjbbZ5iqbdckDCw.png" /></figure><p>This type of relationship also enables a <strong>many-to-many</strong> association between lawyers and clients, via the has_many :through association. NOTE: It’s important that we use the correct associations in the correct places, as failing to do so can change the logic of our application. However, when correctly specified, these associations let you navigate through the various tables in your database with ease.</p><blockquote>“What if I wanted to examine the first case of the second lawyer in my database, and retrieve the age of his or her client? ”</blockquote><p>I’m glad you asked! We could achieve this with the following, rather elegant, chain of commands:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tq4Wnc-u1iezOkuIDgqh7w.png" /></figure><p>Meanwhile, and although not relevant to this example, we use a <strong>one-to-one</strong> relation when we want a database record to have exactly one instance of another model, and is facilitated by has_one and belongs_to.</p><p>Finally, <strong>polymorphic</strong> relationships are the most complex and advanced option available to us. We use them when we have a model that can belong to many different models, on a single association. For instance, you might want users of your website to be able to post comments to article authors, and on specific articles themselves.</p><p>To achieve this, we’d define e.g. a commentable_id as a foreign key within the <em>comment model</em>, declare belongs_to :commentable, polymorphic: true within the <em>comment model </em>and declare has_many :comments, as: :commentable, within every model that we’d like to have access to comments. Neat!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8f909b2a25e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Regular Expressions]]></title>
            <link>https://medium.com/@leerbardon/regular-expressions-c174ce78029f?source=rss-ee13e196da1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c174ce78029f</guid>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Lee Bardon]]></dc:creator>
            <pubDate>Wed, 12 Feb 2020 15:59:27 GMT</pubDate>
            <atom:updated>2020-02-13T12:58:04.689Z</atom:updated>
            <content:encoded><![CDATA[<h4>An Intro to Regex in Ruby</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVlIZ1ZYC6rASz-dYPzhZQ.jpeg" /></figure><p>It’s Monday morning. You’ve just made a nice, hot cup of coffee, that you’re contentedly sipping as you plan your day. Feeling whimsical, you lean in close to a colleague, and whisper ‘<em>regular expressionsssss</em>’ around mouthfuls of crumbly biscuit. You’re likely to elicit one of the following responses:</p><blockquote><em>“What’s a regular expression?”</em></blockquote><blockquote><em>“This is highly inappropriate behaviour. Also - eww.”</em></blockquote><blockquote>response.gsub!(/\b#{EXTREMELY_BAD_WORDS}\b/i, ‘Sunshine and Lollipops :D’)</blockquote><p>If you’re in the <em>“What’s a regular expression?” </em>camp, then this introductory blog is for you.</p><p>Regular expressions (or <em>‘regex’</em>) are a powerful tool for searching and matching specific patterns in strings. These patterns can consist of any combination of characters, including letters, numbers, white space and special characters. As a result, regex has numerous use cases, from pulling data, to extracting email addresses, to checking the strength of passwords.</p><p>But there’s a complication… regular expressions are HARD. The syntax is cryptic, extremely dense, and subject to different rules and dialects that vary according to the language you’re using. Luckily, regex is fairly straight-forward at an introductory level. Don’t believe me? Let’s have a look.</p><h4>Literal Characters</h4><pre>/a/</pre><p>This matches the string <em>“a”</em>, as well as any string containing the <em>“a”</em>. This works for all characters, with the exception of ‘special characters’, which have a specific meaning to the regex parser.</p><p>Special characters are given as <em>[ ^, $, ?, ., /, \, [, ], {, }, (, ), +, * ],</em> and can be searched as themselves in regex by prefixing them with a backslash, as follows:</p><pre>/\?/</pre><h4>The Wildcard .(dot)</h4><pre>/.string/</pre><p>Occasionally, you might wish to match any character at some point in your pattern. For example you might want to find all the occurrences of “tickle” and “pickle” in your pattern.</p><p>For reasons best known to you, and best left that way.</p><p>Regardless, this is where the wildcard <em>.(dot) </em>comes in handy, which will match any character, with the exception of newline. In our example, our regular expression would be formatted as such:</p><pre>/.ickle/</pre><p>This would not only match “<em>tickle</em>” and “<em>pickle</em>”, but “<em>&amp;ickle</em>”, and “<em>%ickle</em>” too. This is where one must exercise caution — using the wildcard can result in more matches than required. <em>Character Classes</em> has entered the chat…</p><h4>Character Classes</h4><pre>/[chars]/</pre><p>A character class is a list of characters contained within the regular expression in square brackets. With our ‘tickle/pickle’ example, we can apply it as such:</p><pre>/[tp]ickle/</pre><p>This expression will match “<em>t</em>” or “<em>p</em>” followed by <em>“ickle”</em>, allowing you to avoid unwanted matches like <em>“%ickle”</em>.</p><p>We can also insert a range of characters into a character class, such as <em>[aeiou] </em>or <em>[1–9]</em>, or even:</p><pre>/[a-zA-Z0–9]/</pre><p>Which will match any lowercase or uppercase alphabetical character, and any integer. As it happens this is quite a common request, so we have shorthand!</p><pre>\w ---&gt; is equivalent to [0–9a-zA-Z_]</pre><pre>\d ---&gt; is equivalent to [0–9]</pre><pre>\s ---&gt; matches white space (inc. tabs, regular space, newline)</pre><p>This is merely an introduction to the basics of regular expressions in Ruby, so we’ll leave it here for now. But, those of you who would like to explore this topic further might appreciate the following link :)</p><p><a href="https://rubular.com/">Rubular</a></p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c174ce78029f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>