<?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>DEV Community: ᴙɘɘᴙgYmɘᴙɘj</title>
    <description>The latest articles on DEV Community by ᴙɘɘᴙgYmɘᴙɘj (@reergymerej).</description>
    <link>https://dev.to/reergymerej</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%2F171590%2Fde72c362-db00-4a5b-9c03-bdd622b62c7c.JPG</url>
      <title>DEV Community: ᴙɘɘᴙgYmɘᴙɘj</title>
      <link>https://dev.to/reergymerej</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reergymerej"/>
    <language>en</language>
    <item>
      <title>Pattern Matching in Elixir</title>
      <dc:creator>ᴙɘɘᴙgYmɘᴙɘj</dc:creator>
      <pubDate>Fri, 11 Jun 2021 12:22:07 +0000</pubDate>
      <link>https://dev.to/reergymerej/pattern-matching-in-elixir-58ef</link>
      <guid>https://dev.to/reergymerej/pattern-matching-in-elixir-58ef</guid>
      <description>&lt;p&gt;&lt;em&gt;reposted from &lt;a href="https://reergymerej.github.io/blog/2021/06/11/pattern-matching.html"&gt;https://reergymerej.github.io/blog/2021/06/11/pattern-matching.html&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When discussing pattern matching in Elixir (and other languages), it seems like most of what people talk about isn't the actual &lt;em&gt;matching&lt;/em&gt; part.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern Matching
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pattern matching&lt;/strong&gt; is the ability to check if the left and right match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MatchError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="ss"&gt;value:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is sensitive to &lt;strong&gt;data types&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MatchError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="ss"&gt;value:&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It checks the &lt;strong&gt;shape&lt;/strong&gt; of the data as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MatchError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="ss"&gt;value:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can be used to &lt;strong&gt;branch&lt;/strong&gt; code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"one"&lt;/span&gt;
  &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"two"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="s2"&gt;"one"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's really all there is to it.  Everything else is &lt;em&gt;using&lt;/em&gt; pattern matching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Pattern Matching
&lt;/h2&gt;

&lt;p&gt;When matching, you can &lt;strong&gt;bind&lt;/strong&gt; values on the LHS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works in &lt;code&gt;case&lt;/code&gt;s too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can &lt;strong&gt;destructure&lt;/strong&gt; values while binding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can &lt;strong&gt;ignore&lt;/strong&gt; parts of the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MatchError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="ss"&gt;value:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use underscore as a &lt;strong&gt;wildcard&lt;/strong&gt; when branching.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"bitch"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="s2"&gt;"cops"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"yep"&lt;/span&gt;
  &lt;span class="s2"&gt;"critics"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"yep"&lt;/span&gt;
  &lt;span class="s2"&gt;"paparazzi"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"yep"&lt;/span&gt;
  &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"ain't one"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="s2"&gt;"ain't one"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally, the ever-popular &lt;strong&gt;splitting&lt;/strong&gt; of head/tail of a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>elixir</category>
    </item>
    <item>
      <title>Find and Replace a Bunch</title>
      <dc:creator>ᴙɘɘᴙgYmɘᴙɘj</dc:creator>
      <pubDate>Thu, 03 Jun 2021 02:00:51 +0000</pubDate>
      <link>https://dev.to/reergymerej/find-and-replace-a-bunch-3imp</link>
      <guid>https://dev.to/reergymerej/find-and-replace-a-bunch-3imp</guid>
      <description>&lt;p&gt;&lt;em&gt;Reposted from &lt;a href="https://reergymerej.github.io/blog/2021/06/03/redactor.html"&gt;original article&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Say I'm writing a journal and want to make sure I'm not leaking names.  I'd like to change it consistently so it's anonymous, but still makes sense.&lt;/p&gt;

&lt;p&gt;Instead of this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;John force-pushed to `master` for some reason.  Harold didn't pull before he
added his fix and Betty ended up cherry-picking into yet another branch.  To
avoid this, next time we could...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Farmboy force-pushed to `master` for some reason.  Jimmybob didn't pull before
he added his fix and Horsenator ended up cherry-picking into yet another
branch.  To avoid this, next time we could...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find-and-replace is what I want to do, but consistently and repeatedly (and quickly!).  &lt;code&gt;sed&lt;/code&gt; is the tool for the job.&lt;/p&gt;

&lt;p&gt;First, define the replacements in files named &lt;code&gt;encode&lt;/code&gt; and &lt;code&gt;decode&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encode
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s/Betty/Horsenator/g
s/Harold/Jimmybob/g
s/John/Farmboy/g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Decode
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s/Horsenator/Betty/g
s/Jimmybob/Harold/g
s/Farmboy/John/g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Replace
&lt;/h2&gt;

&lt;p&gt;Then to replace, we use one of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sed -i "" -f encode journal.md
sed -i "" -f decode journal.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, we don't want to keep the encode/decode files with the output, but you get the idea.  You can also send a whole bunch of files through &lt;code&gt;sed&lt;/code&gt; with this set up.  Maybe you could add a build step that cleans up content or something.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reergymerej.github.io/blog/2018/12/06/thats-what-she-sed.html"&gt;This article&lt;/a&gt; gives explains a few more basic &lt;code&gt;sed&lt;/code&gt; options that may help you get started.&lt;/p&gt;

&lt;p&gt;You can find an example &lt;a href="https://github.com/reergymerej/doof"&gt;here&lt;/a&gt; to play with.&lt;/p&gt;

</description>
      <category>sed</category>
      <category>text</category>
    </item>
    <item>
      <title>One-Handed Vim</title>
      <dc:creator>ᴙɘɘᴙgYmɘᴙɘj</dc:creator>
      <pubDate>Mon, 08 Jul 2019 19:41:02 +0000</pubDate>
      <link>https://dev.to/reergymerej/one-handed-vim-2hpa</link>
      <guid>https://dev.to/reergymerej/one-handed-vim-2hpa</guid>
      <description>&lt;p&gt;Vim takes a lot of dexterity and practice.  Speed comes with time and a lot of muscle memory. It's a big investment, but worth it.&lt;/p&gt;

&lt;p&gt;And then you break your hand.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75ocbwry73x2t2yjcg6n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75ocbwry73x2t2yjcg6n.jpg" alt="mono" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's OK.  You can still work &lt;a href="https://www.youtube.com/watch?v=wvSW6W3Xdu8" rel="noopener noreferrer"&gt;at a decent pace&lt;/a&gt;.  Here are some tips.&lt;/p&gt;

&lt;h2&gt;
  
  
  Macro Everything
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Basic
&lt;/h3&gt;

&lt;p&gt;First, add a macro to edit and to source your vimrc.  You will need to edit it a lot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;" edit this file
:nnoremap &amp;lt;leader&amp;gt;ev :vsplit $MYVIMRC&amp;lt;cr&amp;gt;

" re-source this file
:nnoremap &amp;lt;leader&amp;gt;sv :source $MYVIMRC&amp;lt;cr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Going forward, you can open, change, save, and source your runtime config in no time.&lt;/p&gt;

&lt;p&gt;Add mappings for write and quit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:nmap &amp;lt;leader&amp;gt;ww :w&amp;lt;cr&amp;gt;
:nmap &amp;lt;leader&amp;gt;qq :wq&amp;lt;cr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Common Structures
&lt;/h3&gt;

&lt;p&gt;As you're writing code, you will recognize structures you use a lot.  Add insert mappings for them.  For example, in insert mode, if I want to &lt;code&gt;reduce&lt;/code&gt; an array, I can type ...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rrr&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and it will be swapped with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take the time to write these.  You'll have to goof around to find what you like, hence the quick source thing we did at the beginning.  Here are some I'm using for JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;" insert if block
" if () {
"
" }
:imap iii if () {&amp;lt;cr&amp;gt;}&amp;lt;esc&amp;gt;kwa

" insert braces
" {
"
" }
:imap {{{ {&amp;lt;cr&amp;gt;}&amp;lt;esc&amp;gt;O

" insert brackets
" [
"
" ]
:imap [[[ [&amp;lt;cr&amp;gt;]&amp;lt;esc&amp;gt;O

" insert arrow fn
" () =&amp;gt; {
"
" }
:imap ((( () =&amp;gt; {{{return

" map loop
:imap .mmm .map((item) =&amp;gt; {&amp;lt;cr&amp;gt;return item&amp;lt;cr&amp;gt;})&amp;lt;esc&amp;gt;kA

" reduce loop
:imap .rrr .reduce((acc, value) =&amp;gt; {&amp;lt;cr&amp;gt;return {&amp;lt;cr&amp;gt;...acc,&amp;lt;cr&amp;gt;}&amp;lt;cr&amp;gt;}, {})&amp;lt;esc&amp;gt;kkA

" console
:imap ccc console.log()&amp;lt;esc&amp;gt;i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Efficient Moving
&lt;/h2&gt;

&lt;p&gt;Take a moment to think about what you're navigating to.  Lazy &lt;code&gt;kkkkkjjjjkj&lt;/code&gt; crap doesn't work well in one-hand mode.  Look at relative line numbers.  Move to them properly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go up 17 lines with &lt;code&gt;17k&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Go to the next r with &lt;code&gt;fr&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Go to the first blank line above you with &lt;code&gt;{&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Go down 3 folds with &lt;code&gt;3zj&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Brush up on your movements a bit and take the time to do them &lt;a href="https://medium.com/usevim/vim-101-quick-movement-c12889e759e0" rel="noopener noreferrer"&gt;correctly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;&amp;lt;C-o&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;C-i&amp;gt;&lt;/code&gt; a lot.  As you hit the wrong keys, you'll bounce around a lot.  These take you back or forward.&lt;/p&gt;

&lt;p&gt;Don't be a purist.  Sometimes the mouse is faster, especially when you're&lt;br&gt;
confused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Typing
&lt;/h2&gt;

&lt;p&gt;Especially if you're typing really long entity names, use &lt;a href="https://github.com/ctrlpvim/ctrlp.vim" rel="noopener noreferrer"&gt;ctrlp.vim&lt;/a&gt; or something to auto complete for you.  This avoids typos and can be much faster.  This includes when opening files.&lt;/p&gt;

&lt;h1&gt;
  
  
  Slow is Smooth, Smooth is Fast
&lt;/h1&gt;

&lt;p&gt;That's an Infantry motto that applies well here.  I'm going to take these next many long weeks to practice deliberate movement and optimizations.  Yeah, it will suck, but I'll come out the other end even faster.&lt;/p&gt;

</description>
      <category>vim</category>
    </item>
    <item>
      <title>Do Whatever You Want, So Will I</title>
      <dc:creator>ᴙɘɘᴙgYmɘᴙɘj</dc:creator>
      <pubDate>Wed, 03 Jul 2019 04:36:40 +0000</pubDate>
      <link>https://dev.to/reergymerej/do-whatever-you-want-so-will-i-1d5k</link>
      <guid>https://dev.to/reergymerej/do-whatever-you-want-so-will-i-1d5k</guid>
      <description>&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Moving toward the creative side may result in more shit, but neat things can grow out of it.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqo991obokdjh2h3xvqj.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqo991obokdjh2h3xvqj.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While writing an article explaining why &lt;a href="https://reactjs.org/docs/jsx-in-depth.html#spread-attributes" rel="noopener noreferrer"&gt;spreading props to React components is a bad idea&lt;/a&gt; - &lt;em&gt;and it is&lt;/em&gt; - my hairline receded, white hairs appeared in my beard, the music around me became too loud, and no one's clothes made any damned sense.&lt;/p&gt;

&lt;p&gt;Technically, all that stuff happened slowly over many years, but I suddenly saw it as I prepared another shit talking session about all the crap code I've run into in the wild.  What the hell?  When did I become so fucking cranky?&lt;/p&gt;

&lt;p&gt;Yes, if everyone did things a certain way, everything would be fine.  Fine-ish.  It may be stable, but without crazy ass innovation.  We would have a world of very resilient, performant spreadsheets.&lt;/p&gt;

&lt;p&gt;But I certainly didn't start writing code because of a desire to take up the cause of the clean code brigade.  I couldn't have given less of a shit.  I had an idea that I wanted to present and the tool to do it was code.  Over time, possibly because of pursuing a career in code and not the &lt;em&gt;artifacts&lt;/em&gt; I once used them for, I've become obsessive over the freaking tools.  Like some crusty, psycho carpenter sharpening and organizing blades, forgetting about the freaking cabinets he was supposed to make.&lt;/p&gt;

&lt;p&gt;"Listen up!  If you want to make cabinets, you need to stop and learn your tools.  I mean really learn them.  Learn care and maintenance, learn other tools you can use to make these tools better, and go around making sure others use their tools right.  If you're interested, I've written a lot about how to use these tools.  I've even made tools that can make other tools.  If people would just use the right freaking tools, all the cabinets would be perfect."&lt;/p&gt;

&lt;p&gt;Meanwhile, some asshole using a chisel as hammer whacked together 16 cabinets.&lt;/p&gt;

&lt;p&gt;Who cares?  Let people suck.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wild analogy shift in 3...2...1
&lt;/h2&gt;

&lt;p&gt;When trying resuscitate a weed-infested lawn, you may be tempted to run straight to the weed killer.  That will kill the weeds, but has a negative overall effect on the lawn's health.  This results in a weaker lawn, which is more likely to sprout weeds.&lt;/p&gt;

&lt;p&gt;Adding poison is a negative action.&lt;/p&gt;

&lt;p&gt;A better reaction is to focus on nurturing the lawn.  Add phosphates and shit.  That will make the grass healthy, which will flourish, and not give the weeds anywhere to hang out.&lt;/p&gt;

&lt;p&gt;Adding fertilizer is positive.&lt;/p&gt;

&lt;p&gt;This pattern comes up a lot in life.  Pessimism and overall negativity are not creative.  And writing software is - hold onto your planning meeting notes - a creative process.  Meetings and story points and micro-managing dickbacks may have slowly sucked the life out of it, but I started doing this because it was another art form and pretty fun.&lt;/p&gt;

&lt;p&gt;I've stashed my cranky article for now.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>cleancode</category>
    </item>
  </channel>
</rss>
