<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eric H on Medium]]></title>
        <description><![CDATA[Stories by Eric H on Medium]]></description>
        <link>https://medium.com/@hardimaneric?source=rss-abcc18a8c964------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*894b4Rh-BByFN97h.jpg</url>
            <title>Stories by Eric H on Medium</title>
            <link>https://medium.com/@hardimaneric?source=rss-abcc18a8c964------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:53:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hardimaneric/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using a Windows PC at Flatiron]]></title>
            <link>https://medium.com/@hardimaneric/using-a-windows-pc-at-flatiron-e1f793d9e133?source=rss-abcc18a8c964------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1f793d9e133</guid>
            <category><![CDATA[flatiron-school]]></category>
            <dc:creator><![CDATA[Eric H]]></dc:creator>
            <pubDate>Sat, 11 May 2019 17:19:04 GMT</pubDate>
            <atom:updated>2019-05-23T03:28:03.346Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbbuFeE_GioiZ7uGL_AO_w.png" /></figure><p>Before getting started, open your Start Menu, and type in Turn Windows Features and open the first result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*45Dp-p-cmPlYO_2Ujxf9XA.png" /></figure><p>Scroll to the bottom, and enable Windows Subsystem for Linux then hit OK.<br>It’ll most likely ask you to Reboot your PC after enabling it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*NoVTJ52BJLXU0kcfWsmYuA.png" /></figure><p>Next, open the Microsoft Store, and search for Ubuntu in the top right — Then install it to your PC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*azLN8CWwJWQr08QuUEEfkg.png" /></figure><p>Once it’s finished, launch it, and it’ll begin to install the Ubuntu subsystem.<br>Next, it’ll ask you to create a username — it has to be all lowercase — as well as a password to go with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*vxJ07mmGlM0Lfwdjs1yCZQ.png" /></figure><p>After you’re logged into your newly made account, type the following, and hit enter: sudo apt-get update &amp;&amp; sudo apt-get upgrade.</p><p>If it finds any upgrades available, it’ll ask you to type Y and hit Enter.</p><h3>Note</h3><p>If you find yourself not being able to copy/paste in your terminal:<br>Right-Click the top of your terminal, and click Defaults.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/137/0*_r4BROvqmOAwqH4H.png" /></figure><p>Then check the following options, and hit OK:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/0*_q5woJd7RH90V9ff.png" /></figure><h3>Installing Homebrew</h3><p>In the terminal, type in the following, and then hit enter.<br>sh -c &quot;<strong>$(</strong>curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh<strong>)</strong>&quot;</p><p>A few moments later, it’ll ask you to hit Enter to continue.</p><p>Next, do the following five commands one after the other.</p><pre>eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)</pre><pre>test -d ~/.linuxbrew &amp;&amp; eval $(~/.linuxbrew/bin/brew shellenv)</pre><pre>test -d /home/linuxbrew/.linuxbrew &amp;&amp; eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)</pre><pre>test -r ~/.bash_profile &amp;&amp; echo &quot;eval \$($(brew --prefix)/bin/brew shellenv)&quot; &gt;&gt;~/.bash_profile</pre><pre>echo &quot;eval \$($(brew --prefix)/bin/brew shellenv)&quot; &gt;&gt;~/.profile</pre><p>The last thing we’re going to run to finalize the Homebrew install is: <br>sudo apt-get install build-essential</p><p>Be sure to hit Y to confirm the installation — This will take a bit of time.</p><h3>Setting Up Git</h3><p>First things first, type in brew install git.</p><p>Next, type in ssh-keygen — You can hit enter and leave the passphrase blank when it asks.</p><p>Then, type in cat ~/.ssh/id_rsa.pub and it’ll output your SSH Key.<br>Copy the entire output, starting from ssh-rsa, and then head over to here:</p><p><a href="https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account">Adding a new SSH key to your GitHub account</a></p><p>And follow along starting from Step 2.</p><p>Lastly, type in the next to following lines:<br>git config --global user.email &quot;you@example.com&quot;<br>git config --global user.name &quot;Your Username&quot;</p><p>Now that Git is finished, we can move onto the Support Libraries.</p><p>Simply type brew install gmp once that is finished,brew install gnupg.</p><p>If you get the following error: Warning: gnupg already installed, it&#39;s just not linked, run: brew link gnupg.</p><h3>Installing Ruby Version Manager</h3><p>To begin the install of RVM, run curl -sSL https://get.rvm.io | bash<br>Then run source ~/.bash_profile to refresh the terminal.</p><p>Once refreshed, run rvm install 2.6.1 and wait for it to finish.<br>Next run rvm use 2.6.1 --default</p><p>Finally, run rvm list and you should see =* ruby-2.6.1 [ X86_64 ]<br>If you see the =* next to it, then you’ve successfully installed and setup RVM.</p><h3>Installing Ruby Gems</h3><p>Run the following commands in your terminal:</p><pre>gem update --system<br>gem install bundler<br>gem install nokogiri</pre><h3>SQLite, PostgreSQL, Node, and Rails</h3><p>First thing we’re going to run is brew install sqlite</p><p>Once that’s finished, we’re going to Download PostgreSQL — <a href="http://oscg-downloads.s3.amazonaws.com/packages/PostgreSQL-9.6.2-2-win64-bigsql.exe">Click Here</a>.</p><p>When that is done downloading, go through the entire install.<br>You can keep everything as default until it asks you to make a password.</p><p>Make the password whatever you’d like, just make sure you remember it.</p><p>After PostgreSQL is finished, in your terminal run brew install postgresql</p><p>Open the Windows Start Menu, and Search for Command Prompt.<br>Right click it, and Run as Administrator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/0*pyAG2fq3TJujFE-0.png" /></figure><p>Run psql -p 5432 -h localhost -U postgres</p><p>If all went well, you’ll see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/0*IFCHd-jhDQn73BZU.png" /></figure><p>To exit, type in \q and hit Enter, and then you can Exit Command Prompt.</p><p>Run curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash in your terminal. Make sure you do not use sudo .</p><p>Run echo &#39;export NVM_DIR=&quot;$HOME/.nvm&quot;&#39; &gt;&gt; ~/.bash_profile .</p><p>Run echo &#39;[ -s &quot;$NVM_DIR/nvm.sh&quot; ] &amp;&amp; . &quot;$NVM_DIR/nvm.sh&quot;&#39; &gt;&gt; ~/.bash_profile .</p><p>Run source ~/.bash_profile . This will refresh your shell after making these changes. This way you wont have to quit terminal and open it again.</p><p>Finally, run<br>nvm install node<br>nvm use node<br>nvm alias default node<br>to get the latest version of node, switch to using it, and set it as the default.</p><p>Finally, we can run gem install rails.</p><h3>Future PostgreSQL Projects</h3><p>Just a quick note — For when you create a new Rails project that will be using PostgreSQL, you will need to edit your config/database.yml.</p><pre>default: &amp;default<br>  adapter: postgresql<br>  encoding: unicode<br>  pool: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt;<br>  host: localhost</pre><pre>development:<br>  &lt;&lt;: \\*default<br>  database: <br>  username: postgres<br>  password: Password You Set in Install</pre><pre>test:<br>  &lt;&lt;: \\*default<br>  database: <br>  username: postgres<br>  password: Password You Set in Install</pre><p>There are 3 changes in this from the original file.</p><p>You’re adding host: localhost to the default.<br>You’re adding username: postgres, and password: to development as well as test. <strong>We’re not changing anything in the production</strong>, don’t edit it at all.</p><h3>Atom</h3><p>If you are going to be using Atom, download it from here:</p><p><a href="https://atom.io/">Sunsetting Atom</a></p><p>Once downloaded and installed, go to:<br>File &gt; Settings &gt; Packages &gt; Platformio ID Terminal &gt; Settings &gt; Shell Override and set it to ubuntu.exe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/0*MjcV2vGmd9xm2Ciq.png" /></figure><p>This way, whenever you open a Terminal in Atom, it opens with the Ubuntu Bash, instead of Windows Powershell.</p><h3>VSCode</h3><p>If you are going to be using Visual Studio Code, download it from here:</p><p><a href="https://code.visualstudio.com/">Visual Studio Code - Build what comes next</a></p><p>Once downloaded and Installed, hit F1 on your Keyboard, and search:<br>Terminal: Select Default Shell, and click the first option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*KUhcFUSxAAQSf7ej.png" /></figure><p>From the list of options, select WSL Bash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/0*X8q7l4_s-kKxKZHR" /></figure><p>This way, whenever you open a Terminal in VSCode, it opens with the Ubuntu Bash, instead of Windows Powershell.</p><h3>Learn Gem</h3><p>Run gem install learn-co to install the Learn Gem.</p><p>Once installed, run learn whoami and it’ll prompt you for an OAuth Token.<br>To get it, head over to <a href="https://learn.co/">https://learn.co</a> and login. After login, on the top right hit the dropdown on your Profile Picture, and click on Your Profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*jLnmeWdhWwcXeKb3.png" /></figure><p>All the way on the bottom, you’ll find your OAuth Token.<br>Copy the part starting after OAuth token:, paste it in terminal, and hit enter.</p><p>Now for the really annoying part — on your Keyboard hit Windows + R to bring up a Run Window. In there, type %localappdata%/packages and hit OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/0*h-fpsAvbs7ofwFDt.png" /></figure><p>Find a weird folder that includes the text UbuntuonWindows in it.<br>Once you find it, navigate to LocalState &gt; rootfs &gt; home &gt; Your Username.</p><p>Right-click the file .learn-config and open it with your Editor of Choice.</p><p>All you’re going to change is the 3rd line.<br>For Atom do :editor: &#39;atom&#39; — for VSCode do :editor: &#39;code&#39;.<br>Then Save and Close.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1f793d9e133" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Full CRUD with Fetch and JavaScript]]></title>
            <link>https://medium.com/@hardimaneric/full-crud-with-fetch-and-javascript-4e6c43080261?source=rss-abcc18a8c964------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e6c43080261</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Eric H]]></dc:creator>
            <pubDate>Wed, 20 Mar 2019 11:21:58 GMT</pubDate>
            <atom:updated>2019-03-21T00:36:17.533Z</atom:updated>
            <content:encoded><![CDATA[<p>Now that we’re in Module 3 of our journey through Flatiron, we’re starting to work with JavaScript, APIs, and manipulating the DOM. For the Mod 3 Code Challenge, we’re required to be able to perform full CRUD to a DOM from the API’s response. This blog will be going over the <a href="https://github.com/learn-co-students/js_toy_tale-nyc-web-career-012819">Toy Tale lab</a>.</p><p>The requirements for this lab are:<br>- Fetch the API and Get all the Toys.<br>- Display all the Toys to the Index<br>- Fetch the API and Post a new Toy.<br>- Fetch the API and Patch the likes.</p><p>Since we’re doing full CRUD, I also added a Delete button, but that’ll come in a little further on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8e4682476ad768a85e5bf9faa3f567c/href">https://medium.com/media/c8e4682476ad768a85e5bf9faa3f567c/href</a></iframe><p>The default database base for this lab looks like this.</p><p>So the first Fetch to get all of the Toys is super simple:</p><pre>function fetchToys(){<br>  fetch(&#39;<a href="http://localhost:3000/toys&#39;">http://localhost:3000/toys&#39;</a>)<br>  .then(resp =&gt; resp.json())<br>  .then(renderToys)<br>}</pre><p>After retrieving the Response from the API, we return it as a JSON and send that to another Function — renderToys():</p><pre>const toyCollection = document.getElementById(&#39;toy-collection&#39;)<br>function renderToys(toys) {<br>  toyCollection.innerHTML = &quot;&quot;<br>  toys.forEach(function (toy) {<br>    toyCollection.innerHTML += `<br>   &lt;div class=&quot;card&quot; data-id=${toy.id}&gt;<br>        &lt;h2&gt;${toy.name}&lt;/h2&gt;<br>        &lt;img src=&quot;${toy.image}&quot; class=&quot;toy-avatar&quot; /&gt;<br>        &lt;p&gt;${toy.likes} Likes&lt;/p&gt;<br>        &lt;button class=&quot;like-btn&quot;&gt;Like &lt;3&lt;/button&gt;<br>        &lt;button class=&quot;delete-btn&quot;&gt;Delete&lt;/button&gt;<br>   &lt;/div&gt;<br>  `<br>  })<br>}</pre><p>In this function, we’re selecting an Element from the DOM called <strong><em>toy-collection</em></strong>. As soon as the function is called, it clears out the innerHTML, and then goes through the passed through Object. So forEach toy, it’ll iterate through, and create the innerHTML of the toyCollection. Setting the <strong>${toy.name}</strong>, <strong>${toy.image}</strong>, <strong>${toy.likes}</strong>, and <strong>${toy.id}</strong>.</p><p>Upon calling our method, fetchToys(), our index.html will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JVNOdruiXZeXy3T8WMzQQ.png" /></figure><p>Next step of this lab is to be able to create a new toy — with a Fetch to the API using a Post method.</p><pre>const addToyForm = document.querySelector(&#39;.add-toy-form&#39;)<br>addToyForm.addEventListener(&#39;submit&#39;, function (event) {<br>  fetch(`<a href="http://localhost:3000/toys/:id">http://localhost:3000/toys</a>/`, {<br>    method: &#39;POST&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;,<br>    },<br>    body: JSON.stringify({<br>      name: `${event.target.name.value}`,<br>      image: `${event.target.image.value}`,<br>      likes: 0<br>    })<br>  })<br>    .then(resp =&gt; resp.json())<br>    .then(renderToys)<br>})</pre><p>Here we’re selecting another element from the DOM, which is <strong><em>.add-toy-form</em></strong>.</p><p>On that element, we’re adding an eventListener for when the user hits Submit on that form.</p><p>Once they hit the submit button, with the fields filled in, it sends a Fetch to the API with a Post request. Within that Post, we’re giving it the parameters for the new toy to be rendered. Then we take the response, and send it back to our renderToys() function.</p><p>Now, our last two deliverables that we have to meet for this lab, are to increase the Like count when you hit the Like Button, and Delete the toy when you hit the Delete button.</p><pre>const toyCollection = document.getElementById(&#39;toy-collection&#39;)<br>toyCollection.addEventListener(&#39;click&#39;, function (event) {<br>  let likeButtonIsPressed = event.target.className === &quot;like-btn&quot;<br>  let delButtonIsPressed = event.target.className === &quot;delete-btn&quot;</pre><pre>  if (likeButtonIsPressed) {<br>    let id = event.target.parentElement.dataset.id<br>    let like = event.target.previousElementSibling<br>    let likeCount = parseInt(event.target.previousElementSibling.innerText)<br>    like.innerText = `${++likeCount} likes`</pre><pre>fetch(`<a href="http://localhost:3000/toys/:id">http://localhost:3000/toys/</a>${id}`, {<br>      method: &#39;PATCH&#39;,<br>      headers: {<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      },<br>      body: JSON.stringify({<br>        likes: likeCount<br>      })<br>    })<br>    .then(response =&gt; response.json())<br>  }</pre><p>So here again, we’re adding an <strong>eventListener </strong>to our element <strong>toyCollection</strong>, but this time we’re listening for a ‘click’. Next we’re making 2 variables <strong><em>likeButtonIsPressed </em></strong>and <strong><em>delButtonIsPressed</em></strong>. All those check is if the target that was clicked has a className === to like-btn or delete-btn.</p><p>If the likeButtonIsPressed is true, it creates 3 variables:<br>- <strong>id </strong>— &lt;div class=”card” data-id=${toy.id}&gt;<br>- <strong>like </strong>— &lt;p&gt;${toy.likes} Likes&lt;/p&gt;<br>- <strong>likeCount</strong> — Which is just the parseInt of the number of likes</p><p>After that, it sets the innerText of <strong>like </strong>to the <strong>likeCount</strong>+1 for each time they click the Like Button — which changes the DOM. So now we just send a Patch to the API, with the URL set to find the ${id} of the target clicked. Each time the button is clicked, it sets the likes key: to the likeCount value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*2qyU3lQsnFJlnh5JpDAmYQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*lVgXH4OnJxPTiYOx-5GZUQ.png" /></figure><p>Now the last thing we have to do is add the function to Delete whichever toy you click the Delete button on.</p><pre>else if (delButtonIsPressed) {<br>    let id = event.target.parentElement.dataset.id<br>    fetch(`<a href="http://localhost:3000/toys/:id">http://localhost:3000/toys/</a>${id}`, {<br>      method: &#39;DELETE&#39;<br>    })<br>    .then(response =&gt; response.json())<br>    .then(fetchToys)<br>  }<br>})</pre><p>So in that same event listener, we have an else if — So if the delButtonIsPressed is true, it finds the ID from the clicked target again.<br>Then it sends the Delete to the API, which finds the ID in the Database.</p><p>After it finds the ID, it destroys it from the Database, and then fetchToys() is called again to see the updated list of toys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*L1rS_CClDPhwwiGS_w3XUg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*sURdqmFsFY_LNjQn3bOEeg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e6c43080261" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Your Coding Knowledge Outside of Class]]></title>
            <link>https://medium.com/@hardimaneric/test-your-coding-knowledge-outside-of-class-799f1002e052?source=rss-abcc18a8c964------2</link>
            <guid isPermaLink="false">https://medium.com/p/799f1002e052</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Eric H]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 06:30:24 GMT</pubDate>
            <atom:updated>2019-02-27T06:30:24.562Z</atom:updated>
            <content:encoded><![CDATA[<p>In our five weeks here at Flatiron, I’ve noticed a very repetitive type of behavior when it comes to doing labs. We are all doing the same labs, to get to a <em>similar</em> solution, in order to pass the same tests — day after day. Which made me think, what if we wanted a way to test our knowledge outside of class? The answer to that being, with more labs of course!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FdEdmW17JnZhiU%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fthe-office-eye-roll-dEdmW17JnZhiU&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FdEdmW17JnZhiU%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/27374d847d34330052630f1bf74de362/href">https://medium.com/media/27374d847d34330052630f1bf74de362/href</a></iframe><p>There are plenty of online code training websites (Project Euler, HackerRank, LeetCode,) but the one that this blog is going to be talking about is… <a href="https://www.codewars.com/">CodeWars</a>. Now to be clear, this is <strong>not</strong> a website that is going to teach you how to code. The website will give you challenges, starting from the very basics, and get quite advanced.</p><p>Upon going to register for the site, you’ll be presented with all of the languages that the website can train you on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*2dv7hazZdW7aprKZgfsw3Q.png" /></figure><p>After picking your language, you’ll be asked to complete a super hard challenge, just to make sure that you know what you’re getting yourself into.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*laFCKkJfL3ITCqVRmdXb_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*nUbOfEtyU5E0tANn2hsQMA.png" /></figure><p>Once registered and logged in, you are ready to begin your training! From your Dashboard, you can choose your Language and type of challenge you want to try and complete:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*-rV5f65RrpdP7yf8FjtjPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*nldaUd-3Uw6uEx2qlHKpVg.png" /></figure><p>When you select your Language and Challenge Focus, you can hit the train button which will redirect you to the challenge page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czUBPTMFBiX6_0kHnNbRew.png" /></figure><p>So from this page, you should be able to see what is required of you to pass this challenge. It’s telling you what the program is supposed to do — It’s giving you the example input — As well as what the output for each example should be. On the bottom right, it’s showing you the example tests that it’ll be running against your code — and above that is where you will be typing your code in order to pass the challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKftBWAf7en1VaeOoNTPuw.png" /></figure><p>After you finish typing your code, you can run the sample tests against it to see if you’ve completed the challenge. If everything comes back green, you can submit the final code, which will then get added toward your progress on the site.</p><p>The super cool thing about CodeWars is the community inside. So although your code passed the challenge, you might want to see how other people completed the challenge. On the bottom of the page, you can hit View Solutions to see how other members completed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*BqRlv5e2buN3NssMVokYkA.gif" /></figure><p>Since CodeWars is a very community-driven website, they also give you the option to create clans with friends/coworkers/classmates. It turns it into a <em>gamification </em>style of learning — allowing you to earn points, unlock achievements, and compare your progress with other members along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*CRorUEr4JWKGCLbnMbF5Xw.png" /></figure><p>Once you’re in a clan with all your friends, you’re able to follow their progress, check their solutions, share your solutions, or even ask them for help!</p><p>Check out CodeWars, or any of the other Online Training Websites below, and happy training! :)</p><ul><li><a href="https://www.codewars.com/">Codewars - Achieve mastery through coding practice and developer mentorship</a></li><li><a href="https://www.hackerrank.com/">HackerRank</a></li><li><a href="https://leetcode.com/">LeetCode - The World&#39;s Leading Online Programming Learning Platform</a></li><li><a href="https://projecteuler.net/">About - Project Euler</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=799f1002e052" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Module One: Tying Everything Together]]></title>
            <link>https://medium.com/@hardimaneric/module-one-tying-everything-together-a4cd7c835f5f?source=rss-abcc18a8c964------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4cd7c835f5f</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Eric H]]></dc:creator>
            <pubDate>Tue, 12 Feb 2019 11:48:49 GMT</pubDate>
            <atom:updated>2019-02-12T18:05:56.335Z</atom:updated>
            <content:encoded><![CDATA[<p>Throughout our journey here at Flatiron, our first Module is coming to an end. Looking back from where we started, to where we are now, we’ve learned quite a lot of material in these last three weeks. Starting at the very basics of Ruby — learning how to create variables, and methods. Leading into looping, hashes, and classes. Now we’re at the end, having learned about SQL, Object Relational Mapping (ORM), and tying it all together with ActiveRecord.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5wWf7GW1AzV6pF3MaVW%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Feditingandlayout-the-office-high-five-5wWf7GW1AzV6pF3MaVW&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2F5wWf7GW1AzV6pF3MaVW%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="251" frameborder="0" scrolling="no"><a href="https://medium.com/media/52783976a3ba9f13cbf9d18d06132c25/href">https://medium.com/media/52783976a3ba9f13cbf9d18d06132c25/href</a></iframe><h4><strong>What is ActiveRecord?</strong></h4><p>ActiveRecord is a Ruby library (gem) that allows us to map database tables to Ruby classes. It uses Object Relational Mapping to translate between our program, without having to write any SQL. This allows making relationships in programs a lot easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*InK4ZEVTLyyIbtGGM3htdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*hhpDFvIKJJH26uEms7jspA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*s0rbQqO9wfPMxlNoOHjO6Q.png" /></figure><p>In the join table, Review, the class is initialized with an instance of a customer and a salon. The Salon has two methods — one to the Reviews, and the other to the customers, through Reviews. Same scenario for the Customers — one method to the Reviews, and the other to the Salon, through Reviews.</p><p>By inheriting <strong><em>ActiveRecord::Base</em></strong><em> </em>we get to use the has_many — through and belongs_to relations. Using ActiveRecord, we can transform all of that code into this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*qUnmOBY7e_QQu-DxEtE-qg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*_GKjccJFIPwJU_YI9oNuHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*Pmiy_d4C5gNZzOSyCcQOYw.png" /></figure><p>While inheriting <strong><em>ActiveRecord::Base </em></strong>we also get to use a lot of other ‘built in’ methods. The most common ones that I find myself to be using are:</p><blockquote><strong>Where — </strong>Returns a new relation, which is the result of filtering the current relation according to the conditions in the arguments.</blockquote><p><strong><em>String</em></strong></p><pre><a href="https://apidock.com/rails/Client">Client</a><strong>.</strong><a href="https://apidock.com/rails/ActiveRecord/QueryMethods/where">where</a><strong>(&quot;</strong>orders_count = &#39;2&#39;<strong>&quot;)</strong><br><em># SELECT * FROM clients WHERE orders_count = &#39;2&#39;;</em></pre><p><em>String input is not recommended, as it is susceptible to SQL Injection.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PUFYX9zgN58JOgdy9nrnJg.png" /><figcaption>Simple SQL Injection</figcaption></figure><p><strong><em>Array</em></strong></p><pre><a href="https://apidock.com/rails/User">User</a><strong>.</strong><a href="https://apidock.com/rails/ActiveRecord/QueryMethods/where">where</a><strong>([&quot;</strong>name = ? and email = ?<strong>&quot;,</strong> <strong>&quot;</strong>Joe<strong>&quot;,</strong> <strong>&quot;</strong>joe@example.com<strong>&quot;])</strong><br><em># SELECT * FROM users WHERE name = &#39;Joe&#39; AND email = &#39;joe@example.com&#39;;</em></pre><p><strong><em>Hash</em></strong></p><pre><a href="https://apidock.com/rails/User">User</a><strong>.</strong><a href="https://apidock.com/rails/ActiveRecord/QueryMethods/where">where</a><strong>({</strong> name<strong>:</strong> <strong>&quot;</strong>Joe<strong>&quot;,</strong> email<strong>:</strong> <strong>&quot;</strong>joe@example.com<strong>&quot;</strong> <strong>})</strong><br><em># SELECT * FROM users WHERE name = &#39;Joe&#39; AND email = &#39;joe@example.com&#39;</em></pre><blockquote><strong>find_or_create_by — </strong>Finds the first record with the given attributes, or creates a record with the attributes if one is not found.</blockquote><pre><em># Find the first user named &quot;</em>Eric<em>&quot; or create a new one.</em><br><a href="https://apidock.com/rails/User">User</a><strong>.</strong><a href="https://apidock.com/rails/ActiveRecord/Relation/find_or_create_by">find_or_create_by</a><strong>(</strong>first_name<strong>:</strong> <strong>&#39;</strong>Eric<strong>&#39;)</strong><br><em># =&gt; #&lt;User id: 1, first_name: &quot;</em>Eric<em>&quot;, last_name: nil</em></pre><pre><em># Find the first user named &quot;Eric&quot; or create a new one with</em><br><em># a particular last name.</em><br><a href="https://apidock.com/rails/User">User</a><strong>.</strong>create_with<strong>(</strong>last_name<strong>:</strong> <strong>&#39;</strong>Hardiman<strong>&#39;).</strong><a href="https://apidock.com/rails/ActiveRecord/Relation/find_or_create_by">find_or_create_by</a><strong>(</strong>first_name<strong>:</strong> <strong>&#39;</strong>Eric<strong>&#39;)</strong><br><em># =&gt; #&lt;User id: 2, first_name: &quot;Eric&quot;, last_name: &quot;Hardiman&quot;&gt;</em></pre><blockquote><strong>delete_all— </strong>Deletes the records matching conditions without instantiating the records first, and hence not calling the destroy method nor invoking callbacks.</blockquote><pre><a href="https://apidock.com/rails/Post">Post</a><strong>.</strong><a href="https://apidock.com/rails/ActiveRecord/Relation/delete_all">delete_all</a><strong>(&quot;</strong>person_id = 5 AND (category = &#39;Something&#39; OR category = &#39;Else&#39;)<strong>&quot;)</strong><br><a href="https://apidock.com/rails/Post">Post</a><strong>.</strong><a href="https://apidock.com/rails/ActiveRecord/Relation/delete_all">delete_all</a><strong>([&quot;</strong>person_id = ? AND (category = ? OR category = ?)<strong>&quot;,</strong> 5<strong>,</strong> <strong>&#39;</strong>Something<strong>&#39;,</strong> <strong>&#39;</strong>Else<strong>&#39;])</strong></pre><p><em>Sources referenced:</em></p><p><a href="https://apidock.com/rails/v4.2.7/ActiveRecord">ActiveRecord - APIdock</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4cd7c835f5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>