<?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: Matt Gahrns</title>
    <description>The latest articles on DEV Community by Matt Gahrns (@mattgahrns).</description>
    <link>https://dev.to/mattgahrns</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%2F265061%2Fbc9aa080-1a78-4b2b-8202-6d28f2433e87.jpeg</url>
      <title>DEV Community: Matt Gahrns</title>
      <link>https://dev.to/mattgahrns</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mattgahrns"/>
    <language>en</language>
    <item>
      <title>What is a JWT?</title>
      <dc:creator>Matt Gahrns</dc:creator>
      <pubDate>Fri, 03 Jan 2020 01:03:27 +0000</pubDate>
      <link>https://dev.to/mattgahrns/what-is-a-jwt-fb5</link>
      <guid>https://dev.to/mattgahrns/what-is-a-jwt-fb5</guid>
      <description>&lt;h1&gt;
  
  
  The JSON Web Token
&lt;/h1&gt;

&lt;p&gt;JWT stands for JSON Web Token. If you are also wondering what JSON stands for it is: JavaScript Object Notation. Lastly if you are wondering if JWT has a pronunciation, it does, and it is pronounced "jit".&lt;/p&gt;

&lt;p&gt;JWTs being tokens, unsurprisingly, use token-based authentication which is stateless. This means that no information about a logged in user is stored on the server. The client (browser) is doing the storing of the token. The client will send the token to any request that needs to be authenticated within the headers. The JWT is encoded, so when you are sending your user data with it, if it is intercepted by anyone shady it will be protected.&lt;/p&gt;

&lt;h1&gt;
  
  
  JWT Auth Flow
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4uQr_XR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lzhrko3j6l8uut86tkz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4uQr_XR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lzhrko3j6l8uut86tkz1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Photo Credit: Learn.co (&lt;a href="https://i.stack.imgur.com/f2ZhM.png"&gt;https://i.stack.imgur.com/f2ZhM.png&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;When a user signs in with a valid username and password (validated by the back end) the backend gives a signed token to the client. The client will store the token and it will be supplied in the headers to every request that needs authorization. Effectively, it is an access pass for the user that stores unique encoded identifiers and the unique signature from the backend. It proves the user is who they say they are.&lt;/p&gt;
&lt;h1&gt;
  
  
  JWT Format
&lt;/h1&gt;

&lt;p&gt;JWTs are a singular object of three concatenated strings separated by a . A sample JWT would look something like this: aaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccc&lt;/p&gt;

&lt;p&gt;The first string (aaa...a) is the header which contains the algorithm used to encrypt it and the type of token which of course is JWT. The second string (bbb...b) is the payload which contains all the meat. It can contain what you want, but generally you'll include the user id and username etc. The third string (ccc...c) is the signature which contains a hash (encryption) of the header and the payload. It is hashed with a secret key that is provided by the developer.&lt;/p&gt;

&lt;p&gt;If you are curious you can go to &lt;a href="https://jwt.io/#debugger"&gt;jwt.io&lt;/a&gt; and try this for yourself!&lt;/p&gt;
&lt;h1&gt;
  
  
  Environment Variables on Rails With Figaro Gem
&lt;/h1&gt;

&lt;p&gt;The &lt;a href="https://github.com/laserlemon/figaro#getting-started"&gt;Figaro&lt;/a&gt; Gem is a helpful Ruby Gem that allows the developer to user environment variables. Environment variables are simply key value pairs that can be called within your app. &lt;/p&gt;

&lt;p&gt;Upon installing the Figaro Gem it will create a file in your config folder called 'application.yml'. The 'application.yml' file will be in your '.gitignore'. This means that when you push your project to GitHub your 'application.yml' will not be visible. That way your secret key can not be seen by the public and you avoid a huge hole in your security.&lt;/p&gt;

&lt;p&gt;Using the environment variables looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# config/application.yml&lt;/span&gt;
&lt;span class="ss"&gt;my_secret_key: &lt;/span&gt;&lt;span class="s2"&gt;"b1g_s3cr3t"&lt;/span&gt;

&lt;span class="c1"&gt;# And to access the environment variable we use this syntax&lt;/span&gt;
&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"my_secret_key"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And that's all I am covering, thanks for reading and I hope you learned something!&lt;/p&gt;

</description>
      <category>jwt</category>
      <category>javascript</category>
      <category>rails</category>
      <category>react</category>
    </item>
    <item>
      <title>Why Using A Mouse On A Laptop Makes You More Productive</title>
      <dc:creator>Matt Gahrns</dc:creator>
      <pubDate>Thu, 19 Dec 2019 23:01:47 +0000</pubDate>
      <link>https://dev.to/mattgahrns/why-using-a-mouse-on-a-laptop-makes-you-more-productive-5be7</link>
      <guid>https://dev.to/mattgahrns/why-using-a-mouse-on-a-laptop-makes-you-more-productive-5be7</guid>
      <description>&lt;p&gt;Let's face it, laptops are a great tool for developers and on the go productivity. Their compact size and ability to last hours on end on a single charge makes them a wonderful tool to work anywhere. To my knowledge every laptop on the market (besides maybe some high-end gaming ones) comes standard with a trackpad. The trackpad is great and embodies the whole concept of having a fully functioning computer in your lap, but it can slow you down a whole lot if you work on a desk. In my opinion investing in even just a $20 mouse can increase your productivity by ten times.&lt;/p&gt;

&lt;p&gt;If you ask just about anyone who has gone from using one monitor to two, or just a laptop to laptop with a monitor they will tell you that they cannot go back. I have the same opinion about using a mouse with a laptop. &lt;/p&gt;

&lt;p&gt;Firstly I have to admit that I don't use my mouse 100% of the time. For instance if I am typing and have to move my cursor just a bit to edit a misspelled word I will sometimes use the trackpad because it is there and using the mouse for the action wouldn't save much time if at all. The trackpad is also faster for some things like scrolling the page down a little. The mouse really comes into play when doing multiple actions. This is especially noticeable while coding.&lt;/p&gt;

&lt;p&gt;Working with tons of lines of code you will most likely be jumping between lines and words constantly. Sometimes using IDE features to use multiple cursors at once. It becomes very slow and tedious to jump between lots of precision points anywhere on your computer screen with a trackpad. Things become even tricker when you take left and right clicks into consideration.&lt;/p&gt;

&lt;p&gt;With a mouse it is really easy to switch between left and right clicks and have a lot more speed and control over your cursor. With a trackpad I find myself constantly running out of "pad" and needing to readjust my fingers which takes a lot of time. This really adds up when you are trying to click multiple targets in a row that are on opposite ends on whatever you are working on. With a mouse you can hit all the targets so much more quickly and accurately once you find the right sensitivity and DPI. A mouse is also way easier to adjust if you over or under shoot your target.&lt;/p&gt;

&lt;p&gt;Obviously trackpads are a great tool and these days can have their sensitivity adjusted as well, but the mouse is just far superior in my eyes. Even with a comfortable sensitivity on my trackpad, I find I am much more accurate and have to readjust my finger/hand position way less and way less often than when using the trackpad. The trackpad can be great for scrolling down a tiny bit, like when I have been writing this blog as Dev.to doesn't automatically scroll for you when you run out of typing space. It's also good for small movements like going back in the sentence you are currently typing to add a letter you might have missed. For doing anything else though the mouse will make life so much easier for you and you wont be able to go back.&lt;/p&gt;

</description>
      <category>mouse</category>
      <category>productivity</category>
      <category>peripherals</category>
    </item>
    <item>
      <title>Strongly vs Weakly Typed Languages</title>
      <dc:creator>Matt Gahrns</dc:creator>
      <pubDate>Tue, 03 Dec 2019 22:09:16 +0000</pubDate>
      <link>https://dev.to/mattgahrns/strongly-vs-weakly-typed-languages-5aee</link>
      <guid>https://dev.to/mattgahrns/strongly-vs-weakly-typed-languages-5aee</guid>
      <description>&lt;h2&gt;
  
  
  The Compiler
&lt;/h2&gt;

&lt;p&gt;The compiler is something that strongly typed languages use. Basically, before it allows the code to run, it "compiles" it to check for errors. If any errors are found it won't allow the code to run and you as the developer must fix it. What it is also doing is translating your code from a high level language to machine language that the computer can actually read and execute.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variable Declaration
&lt;/h2&gt;

&lt;p&gt;When declaring variables in a strongly typed language the developer must specify which type of variable is being declared. For example declaring an integer in Java looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;In strongly typed languages when declaring functions, the developer must also declare if the function will return a something and if so which type of variable it will return. For example if we wanted to declare a function in Java that simply prints "Hello world!" we would declare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;helloWorld&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ln&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello world!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The 'void' keyword is letting the compiler know that we are not returning anything with this function. If we wanted to instead return the string "Hello world!" we would declare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;helloWorld&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello world!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we are letting the compiler know that we want to return a String object. If we did not have a line with the key word 'return' in our function the compiler would throw an error telling us that our 'helloWorld()' function must return a type of String. Hand in hand if we tried to return a variable of any other type than a String we would get a similar error saying that the return value of 'helloWorld()' is not of type String.&lt;/p&gt;

&lt;p&gt;Sticking to the same comparison language, all of the following functions would be completely valid in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;helloWorld&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello world!&lt;/span&gt;&lt;span class="dl"&gt;"&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;helloWorld2&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello world!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;5&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;helloWorld3&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello world!&lt;/span&gt;&lt;span class="dl"&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;As we can see there's no need to specifically declare whether or not our functions are returning anything or not. We can console log, return a string, or return an integer all while following the same function declaration format.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>strongly</category>
      <category>weakly</category>
      <category>typed</category>
      <category>languages</category>
    </item>
    <item>
      <title>if else Statements In JavaScript vs Ruby And Deep Equals In JavaScript</title>
      <dc:creator>Matt Gahrns</dc:creator>
      <pubDate>Mon, 25 Nov 2019 17:11:15 +0000</pubDate>
      <link>https://dev.to/mattgahrns/if-else-statements-in-javascript-vs-ruby-and-deep-equals-in-javascript-2i51</link>
      <guid>https://dev.to/mattgahrns/if-else-statements-in-javascript-vs-ruby-and-deep-equals-in-javascript-2i51</guid>
      <description>&lt;h1&gt;
  
  
  Comparing if else In JavaScript and Ruby
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Ruby Syntax
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;conditional&lt;/span&gt; &lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;conditional&lt;/span&gt; &lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;]){&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;]){&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&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;h2&gt;
  
  
  Differences
&lt;/h2&gt;

&lt;p&gt;In JavaScript our conditional statement has to be within parenthesis where in Ruby you don't need them. Ruby also cuts down on a few characters in the 'else if' statement by calling it 'elsif' as one word. Lastly the code execution blocks in JavaScript are defined by curly braces where as in Ruby they are defined by the next statement or the 'end' keyword if it is the last statement.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Shorthand Trick
&lt;/h2&gt;

&lt;p&gt;Take our JavaScript syntax example from above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;]){&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;]){&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&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;In this case, assuming [some code] is only one line of code, we can use a shorthand version of 'if else' in JavaScript. If the code in your block is only one line, the curly braces can be omitted! Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;JavaScript will automatically detect and determine that there is only one line of code in each block and execute the code perfectly fine. However, if you need to use multiple lines of code in the block you will need the curly braces to avoid an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why You Should Be Weary About Using The JavaScript Shorthand
&lt;/h2&gt;

&lt;p&gt;Firstly, the curly braces, at least in my opinion, increase the readability of the code. Secondly, if you have to add more lines of code to your blocks, you will also have to add the curly braces. If you're adding more lines to a statement with a ton of 'else if's, that is quickly going to turn into a painstaking nightmare. This can be very cumbersome for yourself or other developers that have to work with your code. Lastly, it's 2019 and if your IDE doesn't add the closing curly brace for you, you should probably find a new one.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Deep Equals
&lt;/h2&gt;

&lt;p&gt;When comparing in JavaScript as a developer you must be careful about which comparator operator you are using. Most of the time you will be using the triple deep equals '===' comparator. The difference between the triple equals and the double equals is as follows. A double equals is loose, which means that JavaScript will try to convert the objects being compared to the same type. So for instance if we had&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;11&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;it would evaluate to true. When using the triple deep equals, comparing the same things would resolve to false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;11&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And when we have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;it evaluates to true! So in conclusion you will generally always be using the deep equals comparator unless for some reason you don't want the types of your variables compared as well as the value.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>ruby</category>
      <category>ifelse</category>
    </item>
    <item>
      <title>My First Ruby CLI</title>
      <dc:creator>Matt Gahrns</dc:creator>
      <pubDate>Tue, 12 Nov 2019 00:19:37 +0000</pubDate>
      <link>https://dev.to/mattgahrns/my-first-ruby-cli-1h7</link>
      <guid>https://dev.to/mattgahrns/my-first-ruby-cli-1h7</guid>
      <description>&lt;h1&gt;
  
  
  The Open Movie Database CLI Project
&lt;/h1&gt;

&lt;h3&gt;
  
  
  My Flatiron School Module 1 Project
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/mattgahrns/ruby-project-guidelines-seattle-web-100719"&gt;View and download the project on GitHub.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Overview
&lt;/h3&gt;

&lt;p&gt;This project uses the &lt;a href="http://www.omdbapi.com/"&gt;OMDb API&lt;/a&gt; in combination with SQLite to provide users with instant information about movies and the ability to create a list of favorite movies. The program starts by prompting the user to enter an existing username or create one. Upon successfully logging in the user can do a list of things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find a movie by title&lt;/li&gt;
&lt;li&gt;Find a moie by IMDb ID&lt;/li&gt;
&lt;li&gt;Add a movie to their favorites&lt;/li&gt;
&lt;li&gt;List their favorite movies&lt;/li&gt;
&lt;li&gt;View a movie's poster in their default browser&lt;/li&gt;
&lt;li&gt;View a movie's website in their default browser&lt;/li&gt;
&lt;li&gt;View all the movies that have been favorited by all users&lt;/li&gt;
&lt;li&gt;See their favorite movies that have earned over $100 million dollars at the box office&lt;/li&gt;
&lt;li&gt;See their favorite movies that have a IMDb 1-10 star rating over a number given by the user&lt;/li&gt;
&lt;li&gt;See the movie that has been favorited by the most users&lt;/li&gt;
&lt;li&gt;See the movie with the highest IMDb 1-10 star rating that any user has favorited&lt;/li&gt;
&lt;li&gt;Change their username&lt;/li&gt;
&lt;li&gt;Change their password&lt;/li&gt;
&lt;li&gt;Delete a movie from their favorites&lt;/li&gt;
&lt;li&gt;Delete all their favorites.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From anywhere in the program the user can simply type 'exit' and press enter to log off and close the program.&lt;/p&gt;

&lt;h3&gt;
  
  
  User Stories
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;As a user, I want to be able to save to and retrieve a list of my favorite movies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As a user, I want to search for a movie by title or IMDb id to quickly get IMDb information about that movie.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As a user, I should be able to see all the movies that have been favorited by all the users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As a user, I want to be able to search my favorites by IMDb star rating and box office earnings.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The OMDb API
&lt;/h3&gt;

&lt;p&gt;The Open Movie Database API was a great tool to use for this project. It was my first time working with an API and this was a great one for that. I was also able to use a very handy gem called &lt;a href="https://github.com/jnunemaker/httparty"&gt;HTTParty&lt;/a&gt; that helped make API calls easy as pie. To make a call all I had to do was fill in a standardized url with the search parameters I wanted and my API key. Upon receiving the return values HTTParty helped me convert it into an easy to work with hash. Once I had the hash I could easily work and manipulate the values to do what I wanted.&lt;/p&gt;

&lt;h3&gt;
  
  
  SQLite
&lt;/h3&gt;

&lt;p&gt;When a user wanted to save a movie to their favorites I would use the API to find the movie then I would store it in a database with SQLite. I had a table for Users, Movies, and a join table called FavoriteMovies. When ever a movie lost all of its favorites it was deleted from the Movies table. &lt;/p&gt;

&lt;h3&gt;
  
  
  Data Analytics
&lt;/h3&gt;

&lt;p&gt;Due to the fact that the OMDb API finds one movie at a time and having limited time and resources for this project, all the analytics were done on the Movies table. By using ActiveRecord I was able to easily query my Movies table. However I did have an issue with one query as it took me a while to translate it from SQL into ActiveRecord syntax. Here is a code snippet of the final implementation of that query: &lt;a href="https://imgur.com/ZUOLMgL"&gt;https://imgur.com/ZUOLMgL&lt;/a&gt; . I had to chain 4 ActiveRecord methods together to achieve the result I wanted and it took me many tries to get the order of the chaining right. I'd also like to shout out Google, Stackoverflow and the ActiveRecord documentation for getting me through that one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This project was a great way to jump into working with APIs and really helped solidify my skills in Ruby and building relationships between models. I improved my skills with ActiveRecord and got experience with using a lot of cool Gems. I think IMDb is a great application and getting to use the OMDb API was really cool.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>cli</category>
      <category>api</category>
      <category>omdb</category>
    </item>
  </channel>
</rss>
