<?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: AC1556</title>
    <description>The latest articles on DEV Community by AC1556 (@theallenc).</description>
    <link>https://dev.to/theallenc</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%2F152998%2Fde989f92-cc1f-4307-abd8-88372e8d6dcf.jpeg</url>
      <title>DEV Community: AC1556</title>
      <link>https://dev.to/theallenc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theallenc"/>
    <language>en</language>
    <item>
      <title>How to enable HTTPS for a local network Nextcloud instance</title>
      <dc:creator>AC1556</dc:creator>
      <pubDate>Wed, 07 Dec 2022 02:08:58 +0000</pubDate>
      <link>https://dev.to/theallenc/how-to-enable-https-for-a-local-network-nextcloud-instance-1pal</link>
      <guid>https://dev.to/theallenc/how-to-enable-https-for-a-local-network-nextcloud-instance-1pal</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;a href="https://paper.wf/urbanlife/how-to-enable-https-for-a-local-network-nextcloud-instance"&gt;This post can also be read over on my federated WriteFreely blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This post will go over the basic steps to enable HTTPS for an intranet Nextcloud service. I have to mess with this every three months when Let's Encrypt expires my certs, and it's always annoying.&lt;/p&gt;

&lt;p&gt;This kind of setup might be useful for when you self-host a Nextcloud instance and don't want to open your home network to the public. I use Zerotier to provide a static IP address and connect to my Nextcloud server.&lt;/p&gt;

&lt;p&gt;Environment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu 22.04.1 LTS&lt;/li&gt;
&lt;li&gt;Nextcloud 24.0.7snap1&lt;/li&gt;
&lt;li&gt;DNS is managed using Namecheap&lt;/li&gt;
&lt;li&gt;Zerotier for external network access&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 - Generate new certs
&lt;/h2&gt;

&lt;p&gt;This will start the cert generation process using the challenge method to prove domain ownership.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;~$ sudo certbot certonly --manual --preferred-challenges dns&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Enter the FULL domain for the certs&lt;/li&gt;
&lt;li&gt; Copy the value that it returns for the next step&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2 - Create TXT records
&lt;/h2&gt;

&lt;p&gt;On whatever DNS service you use, create a TXT record using the "acme-challenge" domain Let's Encrypt created and the random string it generated.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Create TXT record.

&lt;ol&gt;
&lt;li&gt; Domain should be &lt;code&gt;_acme-challenge.&amp;lt;your domain&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Value should be whatever random string was generated by LetsEncrypt&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt; Verify that the record has been updated by using &lt;a href="https://toolbox.googleapps.com/apps/dig"&gt;&lt;/a&gt;&lt;a href="https://toolbox.googleapps.com/apps/dig"&gt;https://toolbox.googleapps.com/apps/dig&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: For subdomains, only the "subdomain" portion is needed for the domain record&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: When verifying, you should see the value of the TXT record. If you don't wait until the record has been verified, you'll need to start the process over again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 3 - Copy the certs into Nextcloud
&lt;/h2&gt;

&lt;p&gt;We will now copy the generated certs into the Nextcloud directory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Copy the certs from where Let's Encrypt dumped them
&lt;code&gt;/etc/letsencrypt/live/&amp;lt;your domain&amp;gt;&lt;/code&gt; into &lt;code&gt;/var/snap/nextcloud/common&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Rename &lt;code&gt;privkey.pem&lt;/code&gt; to &lt;code&gt;key.pem&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: Certs must be a directory that the Nextcloud snap has access to. The easiest is to place them into &lt;code&gt;/var/snap/nextcloud/common&lt;/code&gt;. These can be removed once the process is over.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 4 - Apply the certs
&lt;/h2&gt;

&lt;p&gt;We will now apply the new certs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Disable HTTPS for Nextcloud
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nextcloud.disable-https
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt; Stop the Nextcloud snap service
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    ~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;snap stop nextcloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt; Enable HTTPS with new certs
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    ~ &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nextcloud.enable-https custom &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="se"&gt;\n&lt;/span&gt;
    /&amp;lt;path to cert.pem&amp;gt;&lt;span class="se"&gt;\n&lt;/span&gt;
    /path to key.pem&amp;gt; &lt;span class="se"&gt;\n&lt;/span&gt;
    /&amp;lt;path to chain.pem&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt; Start Nextcloud
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    ~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;snap start nextcloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now be able to access Nextcloud using HTTPS.&lt;/p&gt;

&lt;p&gt;Hopefully someone else finds this helpful! Most people don’t have this setup (Nextcloud Snap with Zerotier) and it took a lot of tinkering to get it to work.&lt;/p&gt;

&lt;p&gt;The main source that used was this blog from David Augustat. It’s a nice read on how to set up HTTPS for intranet domains for general use cases!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://davidaugustat.com/web/set-up-lets-encrypt-on-intranet-website"&gt;https://davidaugustat.com/web/set-up-lets-encrypt-on-intranet-website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextcloud</category>
      <category>https</category>
      <category>linux</category>
      <category>networking</category>
    </item>
    <item>
      <title>Why I love pattern matching</title>
      <dc:creator>AC1556</dc:creator>
      <pubDate>Sun, 08 May 2022 07:18:32 +0000</pubDate>
      <link>https://dev.to/theallenc/why-i-love-pattern-matching-1ahh</link>
      <guid>https://dev.to/theallenc/why-i-love-pattern-matching-1ahh</guid>
      <description>&lt;p&gt;&lt;em&gt;This post can also be read over on my federated &lt;a href="https://paper.wf/urbanlife/why-i-love-pattern-matching"&gt;WriteFreely blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Why I love pattern matching
&lt;/h1&gt;

&lt;p&gt;Last night I was playing around with some simple algorithm questions. The required language was good ol' JavaScript, but being a recent convert to Elixir and the functional programming realm, I went ahead and wrote solutions in both languages.&lt;/p&gt;

&lt;p&gt;The question was to write a function that given an array, returns an array that contains cumulative sums.&lt;/p&gt;

&lt;p&gt;i.e.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cumlativeSums([1, 2, 3, 4, 5]) -&amp;gt; [1, 3, 6, 10, 15]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty standard coding assessment question. Deceptively simple, but not too hard that you can't solve it if you don't know it beforehand. There are also so many solutions out there for it. See &lt;a href="https://stackoverflow.com/questions/20477177/creating-an-array-of-cumulative-sum-in-javascript"&gt;this&lt;/a&gt; Stack Overflow question for inspiration.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Curry 🍛
&lt;/h3&gt;

&lt;p&gt;Now, by far the coolest method you can do is use the native &lt;code&gt;map&lt;/code&gt; function with Currying.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sumArrayCurry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&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="nx"&gt;sum&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="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="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;0&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;This happens to be the top-voted solution on Stack Overview, however, I'm not really a fan. It's honestly hard to read. If I came across this function in an actual codebase I would have to waste time trying to figure out what the hell it was doing. It's even worse if you don't have a strong grasp of what Curring actually is. Here's a &lt;a href="https://stackoverflow.com/a/36321/13996168"&gt;link&lt;/a&gt; to a Stack Overflow explanation since Wikipedia is so dense.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;Array.prototype.reduce&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The method that came to mind when I first read the question was to use &lt;code&gt;&amp;lt;some array&amp;gt;.reduce&lt;/code&gt;. From reading the question I know that I was going to have to do something to every element of the array and then return a new array containing the resultant values.&lt;/p&gt;

&lt;p&gt;This sounds like it would be perfect for &lt;code&gt;map&lt;/code&gt; since it returns an array, but &lt;code&gt;reduce&lt;/code&gt; is nice since we can easily pass the cumulative sum to the next iteration of the call-back function. This doesn't mean that you can't use a map, just how my thought process worked.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sumArrayReduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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="nx"&gt;sums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sums&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I like this because it's easy to follow the programmer's logic and the flow of the program, and if you don't understand what the program is doing, you can easily look up what &lt;code&gt;reduce&lt;/code&gt; does. The one thing about this solution is that it relies on native JavaScript functions. During any sort of coding interview (which, let's be honest, is the only situation where this will come up) you'll probably be asked not to use the native API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recursion
&lt;/h3&gt;

&lt;p&gt;As I mentioned before, I'm a recent Elixir convert. I just discovered a love of functional programming after years of hate due to the abuse that &lt;a href="https://en.wikipedia.org/wiki/Scheme_(programming_language)"&gt;Scheme&lt;/a&gt; left on me during university. Being that an Elixir solution would probably use something with recursion, I wanted to use that without depending on the native JavaScript &lt;code&gt;reduce&lt;/code&gt; function.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sumArrayRecursive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sumArrayHelper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sumArrayHelper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevSum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sums&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;curSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;prevSum&lt;/span&gt;
  &lt;span class="nx"&gt;sums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;curSum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sumArrayHelper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;curSum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arr&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;This solution does rely on some of the native API, but it does eliminate the &lt;code&gt;reduce&lt;/code&gt;. It also follows a tail-recursive pattern, even though that doesn't mean much in the current JavaScript world (Safari is the only browser that supports proper tail calls &lt;a href="https://kangax.github.io/compat-table/es6/"&gt;source&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Beautiful Elixir
&lt;/h2&gt;

&lt;p&gt;Elixir makes functional programming make sense and enjoyable with things like pattern matching and tail recursion. Pattern matching is what I particularly like. For those who are not familiar with pattern matching, it means what it sounds like: you can do things based on how they look. This is quite common when it comes to things like cases, conditional statements, or in our case here, function definitions.&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;defmodule&lt;/span&gt; &lt;span class="no"&gt;ListHelper&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;cumlative_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;p_cumlative_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;# 1&lt;/span&gt;
  &lt;span class="k"&gt;defp&lt;/span&gt; &lt;span class="n"&gt;p_cumlative_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_prev_sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;Enum&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 2&lt;/span&gt;
  &lt;span class="k"&gt;defp&lt;/span&gt; &lt;span class="n"&gt;p_cumlative_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev_sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sums&lt;/span&gt;&lt;span class="p"&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="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;p_cumlative_sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev_sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prev_sum&lt;/span&gt; &lt;span class="o"&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;sums&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;tail&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;Here I create a module called &lt;code&gt;ListHelper&lt;/code&gt; just so I can run the program inside of &lt;code&gt;iex&lt;/code&gt; (interactive Elixir). I define one public function &lt;code&gt;cumlative_sum/1&lt;/code&gt; which will take a list (Elixir does not have traditional "arrays" only linked lists). I also define two private functions to handle the recursion &lt;code&gt;p_cumlative_sum/3&lt;/code&gt;. These private functions have the same name and the same number of parameters, but what's different is the pattern that they match on.&lt;/p&gt;

&lt;p&gt;The third parameter is defined to be a list. &lt;em&gt;#1&lt;/em&gt; &lt;code&gt;p_cumlative_sum/3&lt;/code&gt; will match only when that third argument is an empty list, whereas &lt;em&gt;#2&lt;/em&gt; will match only when the list is not empty. This behavior is the same as the JavaScript recursive solution where we check the list's length before we proceed to do any logic &lt;code&gt;if(!arr.length) {...}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To me, this just makes a lot more sense in my mind, and in practical situations, it helps build cleaner solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Side effects
&lt;/h2&gt;

&lt;p&gt;Also, on a side note, data in Elixir is immutable. This means &lt;strong&gt;no side effects&lt;/strong&gt;. The recursive JavaScript solution above has a glaring issue. The &lt;code&gt;arr.shift()&lt;/code&gt; call. The array passed to the function will be modified during the function's execution. Meaning, after the function has returned, whatever array you passed to it will be empty.&lt;/p&gt;

&lt;p&gt;Side effects have been my biggest gripe while Going from JavaScript to Elixir and back again. I want to write in a functional way, but inconsistencies in JavaScript, and all the side effects that pop off just make it so hard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;I'm not really sure what the point of this was supposed to be, but I had fun playing around with both languages while solving a simple algorithm. I am by no means an expert when it comes to JavaScript or Elixir, and I didn't spend too much time optimizing my solutions so take my code with some 🧂 and 🌶.&lt;/p&gt;

&lt;p&gt;Feel free to leave your own solutions to the question, or even improve upon mine. I'm sure there's a way to use recursion in JavaScript without having to use &lt;code&gt;Array.prototype.shift&lt;/code&gt;, or even a way to remove the &lt;code&gt;Enum.reverse/1&lt;/code&gt; in the Elixir solution.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 👨‍💻&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>javascript</category>
      <category>node</category>
      <category>interview</category>
    </item>
    <item>
      <title>Entering JavaScript &amp; Overcoming Frustrations</title>
      <dc:creator>AC1556</dc:creator>
      <pubDate>Sun, 21 Apr 2019 21:56:38 +0000</pubDate>
      <link>https://dev.to/theallenc/entering-javascript-overcoming-frustrations-48kh</link>
      <guid>https://dev.to/theallenc/entering-javascript-overcoming-frustrations-48kh</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3m3Dw9wT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/urs4lo5nsjdz57bc9jya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3m3Dw9wT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/urs4lo5nsjdz57bc9jya.png" alt="header" width="880" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Entering JavaScript &amp;amp; Overcoming Frustrations
&lt;/h1&gt;

&lt;p&gt;I’ll like to preface this post with this, my experiences with the topic of this blog are one-sided and therefore the ideas that I am going to present might be biased or straight-up incorrect. Being a computer science student rushing to finish up his seven year-long trek to his bachelors degree has also vastly limited my time available to do research. That being said, these are my ideas and if they are wrong they should be corrected so that I may learn. And please remember that in the end, we as students, engineers all spend time crawling through the depths of Stack Overflow grasping for hints without considering the underlying details. Let’s begin!&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript. Beginner's entry into the confusing world of asynchronous programming.
&lt;/h2&gt;

&lt;p&gt;JavaScript. The name alone is confusing; as many young developers may not know it has no relation to Java. If you dig around you can find the taxonomy of the early days of the now ECMA standardized languages, but I like to think of it like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Some brothers over at Netscape (RIP) had a dare to create a scripting language in about a week. Unbeknownst to them, their language would fill a gap that was forming in the web development space, but there was one caveat, their homunculus was trash. It was garbage, no one wanted to use it. So they through “java” into its name to    confuse people into thinking that it had something to do with the all powerful Java. People would think, “Well Java’s pretty hot, maybe its cousin is pretty cool too..” and then use it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This worked, JavaScript is literally everywhere!&lt;/p&gt;

&lt;p&gt;Jokes and bad names aside, JavaScript (and other ECMA derivatives) came about during a time when a solution was needed for advanced web technologies. I, unfortunately, was two preoccupied with learning to walk when JavaScript came onto the scene, but I think it is safe to say that while it was a solution it was not an ideal solution.&lt;/p&gt;

&lt;p&gt;As I mentioned in the PSA at the beginning of this post, my experience with JavaScript is limited. I began teaching myself JavaScript a few years ago when I joined my internship as test engineer a local software company. At the time my job was to develop and maintain a preparatory automated test system using the popular node.js testing framework, Mocha. My company’s main product is a node-based web application, so using a node-based testing framework seemed natural.&lt;/p&gt;

&lt;p&gt;Before this internship my language experience consisted of: BASIC, Visual Basic, C/++, and Java. When I applied for the job I had no idea that JavaScript was the primary language that I would be using, and I am not really sure how, but it never came up in the interview process. I remember my first day my test-lead gave me assignment to watch videos on “callback hell and their promise based solutions”, and not understanding any of it. However overtime, with much persistence, practice, and failure I learned to really hate JavaScript.&lt;/p&gt;

&lt;p&gt;Scoping, syntax, asynchronous programming? How is this language the number one language on GitHub when these three things are literally garbage. Of course, my opinions were a symptom of my inexperience, but it wasn’t until the summer after I started my internship where I actually learned to appreciate the complete mess that is JavaScript.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Like, seriously. There are three ways to declare a function in JavaScript, but each one has its own quirks that are clear up front.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;doThingMakesSense&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// The classical C-Style function declaration&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doThingWhatIsThis&lt;/span&gt; &lt;span class="o"&gt;=&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="c1"&gt;// This is an anonymous function that's doing a bad job at being anonymous&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doThingOkayThisIsRedundant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// At this point it seems redundant&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During that summer I had some free time to play around with some pet projects. I wanted to make a bot for a Discord server that my friends and I use share all our dank memes. There are a few different frameworks that can be used to hook into Discord’s API, these are all written in different languages (Java, C#, Rust, etc..). Initially I used one of the Java based framework, and after a whole weekend of trying to get the Mavin configuration up and running, I decided to look towards my new “friend” JavaScript.&lt;/p&gt;

&lt;p&gt;I settled on an amazing API called &lt;a href="https://discord.js.org/#/"&gt;Discord.js&lt;/a&gt; (seriously even the API is a joy to read). What blew me away was how quickly it was to get a project up and running with NPM. It took me minutes not hours or days to get the node modules installed. Within a matter of hours I had already created a bot that was responding to my messages in Discord. No messing around with IntelliJ projects. No trying to integrate Mavin to ensure that my Java libraries are updated. Just a simple, &lt;code&gt;npm install --save discord.js&lt;/code&gt; and my project is up and running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zA5DIYAk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://assets.nakamap.com/img/grp/f41b32b612e2bee7b890e92e3912bc841f8356bb_raw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zA5DIYAk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://assets.nakamap.com/img/grp/f41b32b612e2bee7b890e92e3912bc841f8356bb_raw.jpg" alt="Discord.js Logo" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The whole experience shed light on the the main reason JavaScript has become so ubiquitous in recent years; it’s flexible. Seeing how just how it quickly I could get a project up and running using a language that I am pretty familiar with, just by finding a specific node module.&lt;/p&gt;

&lt;p&gt;This whole thing can pretty much be attributed to Node’s amazing contributors, but still if the foundation was not there attempts at trying to use JavaScript outside of its normal environment would end up like trying to use Java to drive a web UI.&lt;/p&gt;

&lt;p&gt;This semester, my final semester, I am finally dipping my toes into the world of web development. Once again I get to witness another application of this brilliant language. In this lecture we are not permitted to use any frameworks. Everything must be done from scratch using a limited toolset: PHP, HTML, JavaScript (strictly jQuery). This is so that we, as beginner web developers, learn how the numerous frameworks that have been developed over the years came to be, and frankly the reason that they were developed. Being that JavaScript was forged out of the need to make webpages more “interactive” this class has taught me, in limited capacity, to understand where JavaScript came from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overcoming frustrations
&lt;/h2&gt;

&lt;p&gt;Initially, my lack of inexperience with JavaScript caused me to feel extremely negative. I would have anxiety about asking my seniors at work questions because usually all my problems had very simple solutions. However as I learned more I still grew to love the language, even will all its faults. The only difference now is that learning about things that I don’t understand excites me.&lt;/p&gt;

&lt;p&gt;As I scroll through the &lt;a href="https://dev.to/t/javascript"&gt;#javascript&lt;/a&gt; tag here on Dev and read about all the exciting different applications that people are using JavaScript inspires me. While this attitude might just be a product of me maturing as a student and a developer I feel as if JavaScript was a catalyst for me to realizes something: rather than being frustrated from inexperience you should be excited to learn something new (unless you’re learning Scheme. In that case just give up).&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Frustration from inexperience is stupid...
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;By in large, frustration from inexperience is stupid, and you should be excited to learn new things. As we are all taught in school, and as we experience everyday at work - the computer science industry is changing everyday. Twenty years ago, privacy was never considered an issue and today people are dragged in before congress to testify about issues over privacy. We are in this industry to learn about new things everyday and if that doesn’t excite you then I don’t know what will.&lt;/p&gt;

&lt;p&gt;JavaScript was one of the first real things that I had to teach myself, and reflecting on this has made me so excited to finally finish off my schooling and truly begin my venture into this difficult yet instructing field.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here are some of the sources that I used for this post. Some of them are quite interesting!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/lambdatesting/fixing-javascript-cross-browser-compatibility-issues-51pl?utm_source=additional_box&amp;amp;utm_medium=internal&amp;amp;utm_campaign=regular&amp;amp;booster_org=lambdatesting"&gt;https://dev.to/lambdatesting/fixing-javascript-cross-browser-compatibility-issues-51pl?utm_source=additional_box&amp;amp;utm_medium=internal&amp;amp;utm_campaign=regular&amp;amp;booster_org=lambdatesting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/trekhleb/algorithms-and-data-structures-in-javascript-49i3"&gt;https://dev.to/trekhleb/algorithms-and-data-structures-in-javascript-49i3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/tylermcginnis/a-beginners-guide-to-javascripts-prototype-5kk"&gt;https://dev.to/tylermcginnis/a-beginners-guide-to-javascripts-prototype-5kk&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/winduptoy/a-javascript-free-frontend-2d3e"&gt;https://dev.to/winduptoy/a-javascript-free-frontend-2d3e&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.sitepoint.com/anatomy-of-a-modern-javascript-application/"&gt;https://www.sitepoint.com/anatomy-of-a-modern-javascript-application/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.sitepoint.com/object-oriented-javascript-deep-dive-es6-classes/"&gt;https://www.sitepoint.com/object-oriented-javascript-deep-dive-es6-classes/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>learning</category>
      <category>beginners</category>
      <category>school</category>
    </item>
  </channel>
</rss>
