<?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 August Giles on Medium]]></title>
        <description><![CDATA[Stories by August Giles on Medium]]></description>
        <link>https://medium.com/@augustgiles8?source=rss-8c1ff22dd66b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*n-AfOvQM-SVt96jc3i0Plg.jpeg</url>
            <title>Stories by August Giles on Medium</title>
            <link>https://medium.com/@augustgiles8?source=rss-8c1ff22dd66b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:50:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@augustgiles8/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[Making Awesome Webpage Animations]]></title>
            <link>https://medium.com/@augustgiles8/making-awesome-webpage-animations-9c721269b82?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c721269b82</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 18:45:05 GMT</pubDate>
            <atom:updated>2019-03-15T00:41:17.757Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making Fun Webpage Animations</h3><h4>With CSS3 Animations and Transformations</h4><h3>Why Animate?</h3><p>Animations carry a lot of weight when it comes to a users tactile experience with a webpage. Animations can serve to give the user indicative feedback as they navigate a page, introduce personality to a brand, give a website polish, and bring some pleasant surprise to an experience. You can truly animate anything on the page — though that may not be suggested.</p><h3>Why CSS3?</h3><p>CSS3 is something that’s already our disposal in our usual development environment, making it a very handy tool to get off the ground. Not only that, but you can also get a feel for what animation libraries are doing under the hood to give desired effects. Speaking of libraries, there are many worth checking out to speed up the animation process for your page like…</p><ul><li><a href="https://zurb.com/playground/motion-ui">Motion UI</a></li><li><a href="https://daneden.github.io/animate.css/">Animate CSS</a></li><li><a href="https://wowjs.uk/">wow.js</a></li></ul><h3>Our First Animation</h3><h4>Environment</h4><p>I’ll be using Codepen in this walk-through and I highly suggest making a Codepen account if you don’t already have one. It is a great sandbox environment to play around with HTML, CSS, and JS. No set up required.</p><h4>Let’s make a shape</h4><p>I like circles, so we’ll make a circle to animate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlhLgu3f90wTuwFVO8MdRQ.png" /><figcaption>Codepen Circle</figcaption></figure><ul><li>Set up a div in the HTML column with a class of circle.</li><li>Set up a body color in the CSS</li><li>Tell the css to refer to the ‘circle’ class set up in the HTML and give it some particular attributes</li><li>Attributes set on the circle just gave it a uniform width and height, then adjusted border properties to give us a hollow circle.</li></ul><p>(For your reference, definitely check out <a href="https://www.w3schools.com/css/">w3schools</a>, as they have great documentation when it comes to what you can do with CSS.)</p><h4>Center the Circle</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wu3awWkFV5-1zrjBwR2xSw.png" /><figcaption>Codepen Center Circle</figcaption></figure><ul><li>Used position and transform properties to fully center the item in the container</li></ul><h4>Setting up the Animation</h4><p>Animating an object on the page requires specifying a few primary things first.</p><ul><li>animation-name … the name of the animation you’re making</li><li>animation-duration … how long that animation takes</li><li>animation-iteration-count … how many times the animation happens</li></ul><p>In our CSS for the circle, let’s go ahead and add those attributes and look at a close up of our current CSS. I’m calling the animation ‘circle-in’. Setting duration for 2 seconds. Iteration count of infinite so it just keeps looping for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*XbPW_7pgeQibyb0u193_Lw.png" /></figure><h4>Keyframes</h4><p>CSS3 allows you to dictate exactly how an animation will respond through it’s duration through a tool called keyframes.</p><p>Let’s take this and put it under the circle class we just made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VWMf9KOX9iO5SE7elEX0qw.png" /></figure><p>At the top line there, ‘circle-in’ is the name that I gave the animation earlier. Whatever you name the animation in the object, you have to name the keyframe the same so your CSS knows to connect the two.</p><p>The percentages on the left indicate that — at this percentage of the animation, the shape should represent the details listed to the right. That means that the duration between the two percentages is where the change happens, and that the details will describe that change.</p><p>(Note: Remember, we used transform to center the object earlier with transform: translate(-50%, -50%) . In this little example I want to change the scale of the object, which is also a transform property, so I am reiterating the translate in order to keep the object centered.)</p><ul><li>Between 0% and 25% of the animation, the scale of the object changes from 0 to 1.</li><li>Between 25% and 75%, the object doesn’t change at all. To keep the object the same, you write the same details so no change happens.</li><li>Between 75% and 100%, the scale changes back from 1 to 0.</li></ul><p>And we have our first animation!</p><h4>Bonus</h4><p>See how we can polish up our little animation by adding more percentages and providing more detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PWN_ShzJhvoL0YI-MX0pqQ.png" /></figure><p>You can use scale and timing to add bounce and stretch to the circle when it enters and exits. Opacity helps it come in and out a bit smoother.</p><p><a href="https://www.w3schools.com/css/default.asp">Go check out the other CSS properties you might want to manipulate!</a></p><p>Until next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c721269b82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making your Create React App a PWA]]></title>
            <link>https://medium.com/@augustgiles8/making-your-create-react-app-a-pwa-a5e9322d487e?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5e9322d487e</guid>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[manifest]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[pwa]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 04:31:08 GMT</pubDate>
            <atom:updated>2019-03-15T00:39:18.772Z</atom:updated>
            <content:encoded><![CDATA[<h3>About PWA’s</h3><p>A Progressive Web App is an application that adheres to a Google-specified set of technologies and best practices that have been compiled to achieve certain web ideals. Those core ideals are all things that we can get behind —fast speed, reliable connection, and native app feel. For a full list of PWA qualities, check <a href="https://developers.google.com/web/progressive-web-apps/checklist">Google’s PWA Checklist</a>.</p><p>Lucky for us, Create React Apps are easily transformed into PWA’s. What we’ll do here is make an example CRA, and get it up to <a href="https://developers.google.com/web/tools/lighthouse/">Lighthouse</a> standards.</p><p>**Note: PWA’s involve a quite a few ideas. An app can implement some of those qualities and decide to not implement others, so there’s a spectrum of PWA-ness that an app can achieve. Here, we won’t go over EVERYTHING for PWA’s, but we’ll go over setting up the service worker and the manifest, and improve the app’s PWA-ness.</p><h4>Lighthouse</h4><p><a href="https://developers.google.com/web/tools/lighthouse/">Lighthouse</a> is a great resource in our Chrome Dev-Tools. We’ll be using it in this example to check the PWA-ness of our app at different points. It’s located in your Chrome Dev-Tools in the ‘Audit’ tab.</p><h3>Getting Started</h3><p>Let’s run…</p><ul><li>npx create-react-app example</li><li>npm start</li></ul><p>Head on over to your Audit tab, and run an initial audit. On my computer, I’m already at a Lighthouse audit score of 54. Pretty good start!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*mqbSHUAYm0p71iBBtZiPQg.png" /></figure><p>By reading the info and resources in the drop-downs, we’ll find that we are not implementing two key things here. The service worker and the manifest.</p><h3>Service Worker</h3><p>The service worker is one of the core parts of a PWA. It’s the technology that allows for speed and consistency of service by page caching, and is also the foundation for push notifications and other cool features.</p><p>A service worker acts as a proxy between your site and your user. The user will make a request and if their browser has a cached version of your site available, it will serve that version before looking back for updates. This is a huge benefit when it comes to speed and consistency because if the site is reached, it will render something. Even in times of low/no connectivity.</p><p>More good reading on <a href="https://developers.google.com/web/fundamentals/primers/service-workers/">service workers</a> here.</p><p>Of our issues above — starting the service worker will correct issues 1 and (of course) 4.</p><h4>Setting up the service worker</h4><p>Create React Apps already have a service worker made for us to implement. Here’s a view from index.js (see the serviceWorker.js below that it’s importing from).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbEaPYsrFZtCamU2RfTGDw.png" /></figure><p>Let’s change line 12 to serviceWorker.register()</p><p>Service workers only go into effect in production. So we’ll build it then serve the build locally.</p><ul><li>npm run build</li><li>npm i serve -g (install serve npm)</li><li>serve -s build</li></ul><p>Run Audit…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*CmaXf4noEviRJy2T_oWRXA.png" /></figure><p>Big difference! Now your app will cache those pages and handle limited network like a breeze. Also, you can see more details on your service worker in the Application tab of your dev-tools.</p><p>Note: It’s a good idea to indicate to your user when they are experiencing limited/no connection.</p><h3>Manifest</h3><p>The manifest helps a lot in giving your site the feel of a native app. It contains information of your app so that it can give users the ability to store it on their home screens, just like a native app! Super cool. This will provide icons, app name, theme color, and other app preferences to the browser. The browser will use that info to create the homescreen icon and even a splash screen for when a user opens the app and it’s loading.</p><p>And thanks, React — they already made a manifest.json file in the public folder in the root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ELkuvZtS17p5OHrylkN0AQ.png" /></figure><p>Right now, the only thing our Lighthouse report is requesting is an icon size of at least 512px., so let’s just add 512x512 to the sizes list in icons. Then just make sure it represents the info you want for your application and bring in your own favicon.</p><p>Read more <a href="https://developers.google.com/web/fundamentals/web-app-manifest/">here</a> on how to customize your manifest to get the desired results for your app.</p><p>Okay, so we added the 512x512, now again…</p><ul><li>npm run build</li><li>serve -s build</li></ul><p>Audit…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKQflBqt_ILw9tbDhzQ1TA.png" /></figure><p>Nice. We addressed the splash screen audit and now your app, in production, will prompt users if they want to download it to their homescreen (which is super satisfying to see).</p><h3>Final Notes</h3><p>I know we just did a very general version here, but those are two main technological configurations you will need to do to get your create react app up closer to PWA standards. HTTP to HTTPS config will depend on the environment, so research to your particular needs there. I hope you enjoy bringing your web apps up to PWA standards! It’s definitely a good endeavor.</p><p>It didn’t show in our example here, but PWA’s are very focused on mobile accessibility, so do remember to practice those development standards for your PWA.</p><p>Not all browsers support all technologies associated with PWA’s, like Safari does not yet support service workers and save to homescreen — but hopefully they’ll hop on that.</p><p>Until next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5e9322d487e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recording and Saving Audio — Pt.2]]></title>
            <link>https://medium.com/@augustgiles8/recording-and-saving-audio-pt-2-edb0885fdeeb?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/edb0885fdeeb</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Mon, 22 Oct 2018 06:52:33 GMT</pubDate>
            <atom:updated>2018-10-22T19:57:20.862Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recording and Saving Audio — Pt.2</h3><h4>React/Rails Stack + S3</h4><p>Hello!</p><p>In <a href="https://medium.com/@augustgiles8/recording-and-saving-audio-pt-1-8598c1dea1ec">Part 1</a>, we set up recording audio with the MediaRecorder API and sent that data to our backend. In this post, we’ll take that information and send it to S3 using Rails Active Storage.</p><h3>S3</h3><p>S3 is one of the data storage services that AWS provides. This is where we’ll store the recordings. You will want to…</p><ul><li>Set up an AWS account</li><li>Set up a bucket in S3 —<a href="https://docs.aws.amazon.com/quickstarts/latest/s3backup/step-1-create-bucket.html"> this page</a> in AWS documentation was very helpful</li><li>They will present you with ‘access key id’ and ‘secret access key’ for your bucket. Keep those safe and we’ll use those here in the next bit.</li></ul><h3>Active Storage</h3><p>The role that active storage plays is that it takes larger information (like our recording) and attaches the record of it to an Active Record object while sending the file to our S3 storage. The Active Storage <a href="https://edgeguides.rubyonrails.org/active_storage_overview.html">docs</a> are wonderful, definitely check those out.</p><h4>To do boilerplate…</h4><ul><li>Add gem <em>&quot;aws-sdk-s3&quot;</em>, require: false to your gemfile to indicate S3</li><li>Active Storage creates two tables in your database. Run rails active_storage:install to create the migration then rails db:migrate to run the migration.</li><li>Now we need to indicate to our application where to store these recordings and how to get there. According to the docs, in your config/storage.yml file, provide the following:</li></ul><pre>local:<br>  service: Disk<br>  root: &lt;%= Rails.root.join(&quot;storage&quot;) %&gt;</pre><pre>test:<br>  service: Disk<br>  root: &lt;%= Rails.root.join(&quot;tmp/storage&quot;) %&gt;</pre><pre>amazon:<br>  service: S3<br>  access_key_id: &quot;&quot;<br>  secret_access_key: &quot;&quot;<br>  bucket: &quot;&quot;<br>  region: &quot;&quot; # e.g. &#39;us-east-1&#39;</pre><ul><li>This is where we get to use that access key and id, but we don’t want to put them straight in the file as it isn’t secure. This is where we utilize the config/credentials.yml.enc file. <a href="https://medium.com/cedarcode/rails-5-2-credentials-9b3324851336">This</a> is a great post on how to get that set up. If using VIM, which I found worked best, go ahead and check out <a href="https://coderwall.com/p/adv71w/basic-vim-commands-for-getting-started">this</a> resource for VIM commands. Then reference that encrypted like so.</li></ul><pre>amazon:<br>  service: S3<br>  access_key_id: &lt;%= Rails.application.credentials.dig(:aws,    :access_key_id) %&gt;<br>  secret_access_key: &lt;%= Rails.application.credentials.dig(:aws, :secret_access_key) %&gt;<br>  region: &quot;&quot; # e.g. &#39;us-east-1&#39;<br>  bucket: &quot;&quot; # &#39;bucket-name&#39;</pre><ul><li>Now in config/environments/production place the following few lines of code. This lets rails know a few things. You are using S3 in production and it should route to your bucket. Also you have a master key that it should be using to decrypt your credentials file.</li></ul><pre>config.active_storage.service = :amazon<br>config.require_master_key = true  </pre><ul><li>Similar action should be taken for your config/environments/development. We are just saving the recordings locally. Feel free to set to amazon if that’s your preference in development.</li></ul><pre>config.active_storage.service = :local</pre><h4>Attaching a Resource</h4><p>Finally!</p><ul><li>Decide which model you want to attach the recording to. At the top of that model, write out the relationship has_one_attached <strong>:</strong>recording<strong> </strong>or has_many_attached :recordings</li><li>Go to your controller and make a method called attach_recording or something along those lines. Below is the method I made.</li></ul><pre>def attach_recording<br>   assignment = Assignment.find(params[:id])<br>   r = assignment.recordings.attach(params[:recording])<br>    url = Rails.application.routes.url_helpers.rails_blob_url(https://medium.com/r.first,%20only_path:%20true)<br>    render json: {message: &quot;Attached to File&quot;, url: url}<br>  end</pre><ul><li>In my case, I wanted to attach my recording to an existing ‘assignment’. So (1) I found the assignment (2) attached the recording to the assignment using assignment.recordings.attach(params[:recording]). (3) After url = is the string that’s needed to get a sharable url from your active storage. (4) We’re sending that sharable url back to the front end in a json response!</li><li>If you want to pull that sharable url back out in any other part of the application, just find the instance and call it using the information after url =</li></ul><h4>Troubleshooting</h4><p>Again, check out the docs. <a href="https://docs.aws.amazon.com/quickstarts/latest/s3backup/step-1-create-bucket.html">AWS</a>. <a href="https://edgeguides.rubyonrails.org/active_storage_overview.html">Active Storage</a>. Active Storage docs in general have a lot of information about setting up S3 to your backend.</p><p>I ran into an issue of permissions for accessing my AWS bucket during this project — specifically when trying to call my information back. If you find yourself in that situation, consider googling different S3 permissions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edb0885fdeeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recording and Saving Audio - Pt. 1]]></title>
            <link>https://medium.com/@augustgiles8/recording-and-saving-audio-pt-1-8598c1dea1ec?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8598c1dea1ec</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[active-storage]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Thu, 13 Sep 2018 13:36:30 GMT</pubDate>
            <atom:updated>2018-09-13T13:36:30.444Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>React/Rails Stack + S3</strong></p><p>While working on an application, I had a decent bit of difficulty finding good resources for handling audio with this stack. Recording audio has a decent amount of resources, but resources for saving audio was very sparse. I hope this little series helps anyone break through those walls!</p><p>In this 2 parter, we’ll walk through the series of events from making an audio blob in the front end, to storing it in S3, then all the way to rendering it back out in some other portion of your app.</p><p>The bit we’ll cover in this first post is setting up the recording component in React and relaying the info to the back.</p><h3>Recording</h3><h4>Setting up the functions</h4><p>I highly recommend using the MediaRecorder API to handle recording the sound — It’s very approachable, easy to manipulate, and applicable. Be sure to check out the <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder">docs</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Using_the_MediaStream_Recording_API">example</a> for more detail. Since we’re in a component structure, we’ll want to handle things a little differently from the Vanilla JS in the docs. Here’s my proposed solution to creating the recording/recording functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*Er4MXWRfQgA5ljCo6tOwAQ.png" /></figure><p>Above: I’ve saved some variables in state that I like to have access to. Then in prepareRecording(), we are getting permission from the user to use audio/initializing the mediaRecorder instance that we will use to capture the media. startRecording() goes ahead and starts streaming the media and when data is available (event that ships with the API), we’ll keep pushing them up to one array so we can compile the larger media event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*Y7CyXJb_qCWMEkJTqQKFhg.png" /></figure><p>Above: stopRecording() stops the media stream and does some handling for us to be able to provide immediate feedback to the user with their new recording. We save the new blob and url to our state for later use. emergencyStop() is for the occasion where the user unexpectedly quits the process and we want to be sure any processes are stopped.</p><h4>Rendering</h4><p>Now for rendering, we’ll put those methods to use as a modal and conditionally render bits for ease of the user - The changes in state above will inform the conditional rendering. Don’t forget to plug in some semantic ui for quick and pretty building.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*_A9J_8aAd1R6edO4sAVQnw.png" /></figure><p>When the modal is opened, we make the call to prepare the recording. At that point, the there is a prompt to start recording. Clicking will trigger our start recording method, that event dataavailable is capturing the sound. On the screen will be a button to stop which, when clicked, will generate our blob and a local url for the blob data. With the local URL, you’re able to play their recording back to them there with the audio html tag (with controls) and render a save button.</p><p>And that’s recording! If that’s all you’re looking for, well done! If you’re one of the sad souls who wants to persist this data, we have a bit more to go here, but mostly in part 2.</p><h3>Sending</h3><p>And this is where it gets a little tricky.</p><ul><li>How do we bundle our new data so that our back end will receive it?</li><li>When received, how do we store that data?</li></ul><p>As for bundling the data, see the last bit of our component below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*WOCQl59rcjpiapaplqeeHw.png" /></figure><p>We’re doing a few things here. Blobs are best sent to the back end with some metadata — what is this blob for? A really clean way to send this ‘blob plus data’ is by creating a FormData object because it bundles up our data as key value pairs and sends it all in a way our backend digests really nicely. In addition, I’m also creating a file from the audio blob and sending that back as opposed to the blob itself. This is personal preference. You can just send the blob if you’d like.</p><p>Okay! If you haven’t done so already, go ahead and set up an S3 bucket (or create an account if you’re not set up but are adventurous!). Then check out the docs for <a href="https://edgeguides.rubyonrails.org/active_storage_overview.html">Active Storage</a>, which will help us connect to AWS S3. Consider this a working intermission. See you in part 2 — we will go over configuration for S3 and Active Storage there a bit, then we’ll figure out how to call on that data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8598c1dea1ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build Your Own Stopwatch Component]]></title>
            <link>https://medium.com/@augustgiles8/how-to-build-your-own-stopwatch-component-fe3b491b8655?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe3b491b8655</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Thu, 30 Aug 2018 19:09:36 GMT</pubDate>
            <atom:updated>2018-08-30T19:09:36.210Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*av3MfP7tEC72pkPKkLAfeQ.jpeg" /></figure><p>When researching resources for my current project, I wanted to find a nice npm stopwatch component that would be flexible to function differently depending on the context if I wished. After digging around and trying out different libraries, I decided to just give it a go myself and it turned out to be a nice, compact addition.</p><p>We’ll build it together here — to see the complete version, just scroll on to the bottom.</p><h4>Starting the component:</h4><p>Set react basics…</p><pre>import React, { Component } from &#39;react&#39;<br>import { Button, Statistic } from &#39;semantic-ui-react&#39;</pre><pre>export default class Stopwatch extends Component {</pre><pre>  render () {</pre><pre>     return (<br>        &lt;React.Fragment&gt;</pre><pre>        &lt;/React.Fragment&gt;<br>     )<br>  }<br>}</pre><p>Don’t forget to install some semantic-ui, because you’re worth it.</p><p>npm install semantic-ui-react</p><h4>Time Aspect</h4><p>The time can be accomplished with some very basic math. We’ll be rendering time in H:MM:SS format. The only denomination of time that we’ll be keeping track of here will be seconds for flexibility</p><ul><li>First, let’s set the state. Make time have a default of 0.</li><li>Then we’ll take care of the math for hours, minutes, and seconds from our time state, assigning them to variables in our render.</li><li>Inside of the return JSX, conditionally format the variables to render with ‘0’ in front if the integer is less than 10. <em>Note the semantic components—</em></li></ul><pre>... </pre><pre>  state = {<br>    time: 0,     <em>// DEFAULT TIME TO START</em><br>  }</pre><pre>render () {</pre><pre>  <em>//  HERE IS THE MATH TO RETRIEVE OUR INTEGERS FOR THE CLOCK</em></pre><pre>  const hours = Math.floor(this.state.time / 3600)<br>  const minutes = Math.floor(this.state.time / 60) % 60<br>  const seconds = this.state.time % 60</pre><pre>return (<br>      &lt;React.Fragment&gt;</pre><pre>        &lt;Statistic<br>          size=&#39;large&#39;<br>          style={{display: &#39;block&#39;, marginLeft: &#39;auto&#39;, marginRight:<br>             &#39;auto&#39;, paddingBottom: &#39;10%&#39;}}<br>        &gt;</pre><pre>       //  <em>Rendering those variables with 0’s in front if the number<br>            is less than 10</em></pre><pre>          &lt;Statistic.Value &gt;<br>           {hours}:<br>           {minutes &lt; 10 ? 0 : &#39;&#39;}{minutes}:<br>           {seconds &lt; 10 ? 0 : &#39;&#39;}{seconds}<br>          &lt;/Statistic.Value&gt;</pre><pre>       &lt;/Statistic&gt;</pre><pre>     &lt;/React.Fragment&gt;<br>  )<br>}</pre><pre>...</pre><p>This should render the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*LI1p3bI2IsQIX79ICBAdVw.png" /></figure><p>Yay! Now let’s make it start counting.</p><h4>What Counts</h4><ul><li>We’ll handle setting the interval when the component mounts using the lifecycle method componentDidMount().</li><li>Also remember to clear the interval upon dismount.</li></ul><pre>...</pre><pre>state = {<br>    time: 0,<br>  }</pre><pre>componentDidMount() {<br>    this.interval = setInterval(() =&gt; {<br>        this.setState({<br>          time: this.state.time + 1<br>        })<br>    }, 1000)<br>}</pre><pre>componentWillUnmount() {<br>    clearInterval(this.interval)<br>}</pre><pre>render () { ...</pre><p>It the stopwatch should be going now! Congrats!</p><h4>Hold Up</h4><p>Let’s add a pause button -</p><ul><li>First, we’ll need to add a state property to pause it. Boolean value will be best for this case, set initially to false.</li><li>Then we’ll add a button with an onClick function to change the state of the paused boolean.</li><li>Finally we’ll add a condition to the interval — it will only increment if the state is false.</li></ul><pre>export default class Stopwatch extends Component {</pre><pre>state = {<br>    time: 0,<br>    isPaused: false,<br>  }</pre><pre>componentDidMount() {<br>    this.interval = setInterval(() =&gt; {<br>      if (!this.state.isPaused) {<br>        this.setState({<br>          time: this.state.time + 1<br>        })<br>      }<br>    }, 1000)<br>  }</pre><pre>componentWillUnmount() {<br>    clearInterval(this.interval)<br>  }</pre><pre>render () {</pre><pre>const hours = Math.floor(this.state.time / 3600)<br>    const minutes = Math.floor(this.state.time / 60) % 60<br>    const seconds = this.state.time % 60</pre><pre>return (<br>      &lt;React.Fragment&gt;<br>        &lt;Statistic<br>          size=&#39;large&#39;<br>          style={{display: &#39;block&#39;, marginLeft: &#39;auto&#39;, marginRight: &#39;auto&#39;, paddingBottom: &#39;10%&#39;}}<br>        &gt;<br>          &lt;Statistic.Value &gt;<br>            {hours}:<br>            {minutes &lt; 10 ? 0 : &#39;&#39;}{minutes}:<br>            {seconds &lt; 10 ? 0 : &#39;&#39;}{seconds}<br>          &lt;/Statistic.Value&gt;</pre><pre>&lt;/Statistic&gt;<br>        <br>        &lt;Button<br>          onClick={() =&gt; this.setState({isPaused: !this.state.isPaused})}<br>          size=&quot;huge&quot;<br>          content={this.state.isPaused? &#39;Continue&#39; : &#39;Pause&#39;}<br>        /&gt;</pre><pre>&lt;/React.Fragment&gt;<br>    )<br>  }<br>}</pre><p>And that’s the rendering for the basic stopwatch version of this component that holds its own state. Play around with moving the state out of the component and passing them in as props. As well as other elements. What if it counted down from a number? It opens up a lot more options of flexibility to what the component can do.</p><p>Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe3b491b8655" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rendering the US with React Simple Maps]]></title>
            <link>https://medium.com/@augustgiles8/rendering-the-us-with-react-simple-maps-2e31fe7d49d?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e31fe7d49d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-simple-maps]]></category>
            <category><![CDATA[usa]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 15:02:00 GMT</pubDate>
            <atom:updated>2018-08-16T15:02:00.644Z</atom:updated>
            <content:encoded><![CDATA[<h4>React Simple Maps</h4><p>If you’re looking to incorporate a general dynamic map into your React project that plots some points and maybe has some simple animation to it, RSM can be a good choice for you. If you haven’t checked RSM out yet — <a href="https://www.react-simple-maps.io/">here you go</a>.</p><p>In this article, we will be rendering an Albers projection of the USA (a conic projection (according to the internet )), which brings Hawaii and Alaska into frame and resizes them. If you hardly know anything about map projections, like myself, I highly recommend watching this great clip which happens to be from the <a href="https://www.youtube.com/watch?v=vVX-PrBRtTY">West Wing</a>.</p><p>Anyways, we are also plotting points based upon latitude and longitude coordinates, which happily works well with the displacement of AK and HI.</p><p>When all is said and done, we’ll get something that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bpC__km8vZjKsx-2Kx3lew.png" /></figure><h4>Step 1:</h4><p>In your terminal under your current project folder, run — npm install — save react-simple-maps</p><h4>Step 2:</h4><p>We’ll make this map a component in our App architecture, so make a new file and import the following at the top.</p><pre>import React, { Component } from &#39;react&#39;;<br>import {<br>    ComposableMap,<br>    ZoomableGroup,<br>    Geographies,<br>    Geography,<br>    Markers,<br>    Marker,<br>  } from &quot;react-simple-maps&quot;</pre><pre>import {geoAlbersUsa} from &quot;d3-geo&quot;;</pre><p>Those elements being imported from react-simple-maps are components from the RSM library. From d3-geo (a dependency of the RSM library), we’re getting the Albers Usa projection.</p><h4>Step 3:</h4><p>Set up your Class Component. At this point, embed the &lt;Map /&gt; component into your code wherever you’d like it to render.</p><pre>(import...)</pre><pre>class Map extends Component {<br>    <br>    render() { <br>        return (<br>           &lt;div className=&quot;map-container&quot;&gt;</pre><pre>              ==== EVERYTHING WILL GO IN HERE ====</pre><pre>           &lt;/div&gt;<br>        )<br>    }<br>}</pre><pre>export default Map</pre><h4>Step 4:</h4><p>Set up your ComposableMap component.</p><pre>&lt;ComposableMap<br>   projection={geoAlbersUsa}<br>   projectionConfig={{ scale: 1000 }}<br>   width={980}<br>   height={551}<br>   style={{<br>      width: &quot;100%&quot;,<br>      height: &quot;auto&quot;,<br>   }}<br>&gt;</pre><pre>   ==== NEXT ELEMENT WILL BE IN HERE ====</pre><pre>&lt;/ ComposableMap&gt;</pre><p>Notice we’re bringing in the geoAlbersUsa that we imported. This whole component lets the system know our general details, how we’re sizing the map, what its projection will be.</p><h4>Step 5:</h4><p>Bring in the Zoomable Group component</p><pre>&lt;ComposableMap ...&gt;<br>  &lt;ZoomableGroup center={[ -97, 40 ]} disablePanning&gt;</pre><pre>    ==== NEXT ELEMENT WILL BE IN HERE ====</pre><pre>  &lt;/ ZoomableGroup&gt;<br>&lt;/ ComposableMap&gt;</pre><p>This component lets RSM know where you’ll be centering your map with the desired coordinate. <strong>PLEASE NOTE — </strong>The order in which you place Latitude and Longitude in the array is different than we usually see it. Make sure to enter: [Longitude, Latitude]. The above coordinates are for central usa.</p><h4><strong>S</strong>tep 6:</h4><p>Probably the most involved step here, we need to make a topoJSON file that will give us the shapes that our projection will use to create the map.</p><ul><li>Go to the following website and download the Shapefile option: <a href="https://gadm.org/download_country_v3.html">https://gadm.org/download_country_v3.html</a></li><li>Go to <a href="http://mapshaper.org/">http://mapshaper.org/</a></li><li>From the folder that you downloaded, import the gadm36_USA_1 files ending in .shp, .dbf, and .prj. (When you import the first one, it’ll show a new screen. Click on the file name in the top center and it’ll allow you to layer the other files there.)</li><li>Click on Simplify in the top right and scroll it down to to however much detail you’d like to render in your program. The more simple it is, the more efficient the file will be to load in the long run. Apply the changes.</li><li>Export the file to topoJSON.</li><li>Bring that new shiny topoJSON file into your project</li></ul><h4>Step 7:</h4><p>Render the map with &lt;Geographies&gt; and &lt;Geography&gt; components.</p><pre>&lt;ComposableMap ...&gt;<br>&lt;ZoomableGroup...&gt;</pre><pre>&lt;Geographies  geography=<strong>&#39;/gadm36_USA.json&#39;</strong>&gt;  &lt;---- FILEPATH TO YOUR <br>  {(geographies, projection) =&gt;                  TOPOJSON FROM ROOT<br>    geographies.map((geography, i) =&gt;<br>     &lt;Geography<br>       key={i}<br>       geography={geography}<br>       projection={projection}<br>       style={{<br>         default: {<br>            fill: &quot;#ECEFF1&quot;,<br>            stroke: &quot;#607D8B&quot;,<br>            strokeWidth: 0.75,<br>            outline: &quot;none&quot;,<br>         },<br>         hover: {<br>            fill: &quot;#CFD8DC&quot;,<br>            stroke: &quot;#607D8B&quot;,<br>            strokeWidth: 1,<br>            outline: &quot;none&quot;,<br>         },<br>         pressed: {<br>            fill: &quot;#FF5722&quot;,<br>            stroke: &quot;#607D8B&quot;,<br>            strokeWidth: 1,<br>            outline: &quot;none&quot;,<br>         }<br>      }}<br>    /&gt;<br>   )<br>  }<br>&lt;/ Geographies&gt;</pre><pre>&lt;/ ZoomableGroup&gt;<br>&lt;/ ComposableMap&gt;</pre><p>This is iterating over the states, making each of them a “geography”. You should definitely check out your site to look at your map! Click, hover around, experiment with changing the styles.</p><h4>Step 8:</h4><p>Let’s plot a point</p><pre>&lt;ComposableMap ...&gt;<br>&lt;ZoomableGroup ...&gt;<br>&lt;Geographies&gt;<br>   &lt;Geography ...&gt;<br>   &lt;/ Geography&gt;<br>&lt;/ Geographies&gt;</pre><pre>&lt;Markers&gt;<br>    &lt;Marker<br>       marker={{coordinates: [-153.2917758, 67.75961636]}}<br>       style={{<br>         default: { fill: &quot;#FF5722&quot; },<br>         hover: { fill: &quot;#FFFFFF&quot; },<br>         pressed: { fill: &quot;#FF5722&quot; },<br>       }}<br>    &gt;<br>       &lt;circle<br>          cx={0}<br>          cy={0}<br>          r={5}<br>          style={{<br>            stroke: &quot;#FF5722&quot;,<br>            strokeWidth: 3,<br>            opacity: 0.9,<br>          }}<br>       /&gt;<br>    &lt;/Marker&gt;<br>&lt;/Markers&gt;</pre><pre>&lt;/ ZoomableGroup&gt;<br>&lt;/ ComposableMap&gt;</pre><p>In Marker — put in the coordinates that you’d like to render. Again, remember the desired coordinate structure is Longitude then Latitude. (Check out the RSM resource provided at the top to see how to iterate over a list to generate markers.)</p><h4>And that’s it!</h4><p>You should have a nice looking map.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e31fe7d49d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bubbling]]></title>
            <link>https://medium.com/@augustgiles8/bubbling-1d4c83a558b3?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d4c83a558b3</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 19:58:06 GMT</pubDate>
            <atom:updated>2018-08-02T19:58:06.754Z</atom:updated>
            <content:encoded><![CDATA[<p>At its base, Bubbling is an action that the browser takes once an event is triggered. It registers your event, then travels up the DOM chain, each level looking to see if that parent has an event to trigger, ALL the way until it reaches the topmost HTML node.</p><p>Take the following for example:</p><pre>//   H T M L  //                              //  D O M   //</pre><pre>&lt;body&gt;                                             HTML<br>  &lt;div id=&quot;imABox&quot;&gt;                                 |  <br>    &lt;button id=&quot;buttonInBox&quot;&gt;&lt;/button&gt;             BODY<br>  &lt;/div&gt;                                            |   <br>&lt;/body&gt;                                            DIV<br>                                                    |<br>                                                  BUTTON</pre><pre>//    J S     //</pre><pre>document.querySelector(&quot;#buttonInBox&quot;).addEventListener(&quot;click&quot;, function(event){<br>  console.log(&quot;Hi, I&#39;m a button&quot;)<br>})</pre><pre>//   C O N S O L E   //  * click on the button</pre><pre>&quot;Hi, I&#39;m a button&quot;</pre><p>In this example, we just have a basic button inside of a div. We then are adding a click event to the button, so when its clicked it console logs: “hello”.</p><p>Since there’s only one event listener here, we can safely assume that we aren’t triggering any other events through the button’s parents. Let’s add a little to this example to see the bubbling in action (changes located between the stars).</p><pre>//   H T M L  //                              //  D O M   //</pre><pre>&lt;body&gt;                                             HTML<br>  &lt;div id=&quot;imABox&quot;&gt;                                 |  <br>    &lt;button id=&quot;buttonInBox&quot;&gt;&lt;/button&gt;             BODY<br>  &lt;/div&gt;                                            |   <br>&lt;/body&gt;                                            DIV<br>                                                    |<br>                                                  BUTTON</pre><pre>//    J S     //</pre><pre>document.querySelector(&quot;#buttonInBox&quot;).addEventListener(&quot;click&quot;, function(event){<br>  console.log(&quot;Hi, I&#39;m a button&quot;)<br>})</pre><pre>*****<br>document.querySelector(&quot;#imABox&quot;).addEventListener(&quot;click&quot;, function(event){<br>  console.log(&quot;This is the box speaking&quot;)<br>}) <br>*****</pre><pre>//   C O N S O L E   //  * click on the button</pre><pre>&quot;Hi, I&#39;m a button&quot;<br>&quot;This is the box speaking&quot;</pre><p>In this instance, it’s the exact same HTML and DOM, just added an event listener to the box around the button. After clicking on that same button we clicked before, now two events are being triggered. Since the button is a child of the the div (box), our browser is first reading the direct button we clicked, then reading up, resulting in first the output of “Hi, I’m a button”, then “This is the box speaking”.</p><p>Another helpful way to visualize this is by observing the layered elements you’re physically clicking on the page. …I apologize for this visualization in advance.</p><pre>                              body</pre><pre>        ----------------------------------------------<br>        |                     box                    |<br>        |         ____________    ___________        |<br>        |         |  button  |    |  button |        |<br>        |         ------------    -----------        |<br>        |                                            |<br>        ----------------------------------------------</pre><p>When we click on a button above, we’re actually also clicking on the box, and we’re also clicking on the body. And to extend our thought, here we have two buttons side by side. Clicking on one would not trigger the other as they aren’t physically layered and, as it comes to the DOM, that would be a sibling element, not a parent.</p><h4>So what’s the big deal?</h4><p>This bubbling isn’t something that we request within the code — it’s just something that the browser does. That being the case, it can absolutely lead to unexpected actions. In our day to day operations, these occasions are most likely to not as easy to identify as the situations rendered above and unintended bubbling can get to be difficult to recognize.</p><h4>Can we stop bubbling?</h4><p>Yup —</p><p>event.stopPropagation()</p><p>Calling the above function on your event variable within the button event handler will keep that bubbling from happening. Going back to our previous example: (changes to JS again are in stars)</p><pre>//   H T M L  //                              //  D O M   //</pre><pre>&lt;body&gt;                                             HTML<br>  &lt;div id=&quot;imABox&quot;&gt;                                 |  <br>    &lt;button id=&quot;buttonInBox&quot;&gt;&lt;/button&gt;             BODY<br>  &lt;/div&gt;                                            |   <br>&lt;/body&gt;                                            DIV<br>                                                    |<br>                                                  BUTTON</pre><pre>//    J S     //</pre><pre>document.querySelector(&quot;#buttonInBox&quot;).addEventListener(&quot;click&quot;, function(event){<br>  **** event.stopPropagation() ****  <br>  console.log(&quot;Hi, I&#39;m a button&quot;)<br>})</pre><pre>document.querySelector(&quot;#imABox&quot;).addEventListener(&quot;click&quot;, function(event){<br>  console.log(&quot;This is the box speaking&quot;)<br>}) <br></pre><pre>//   C O N S O L E   //  * click on the button</pre><pre>&quot;Hi, I&#39;m a button&quot; </pre><p>Now the console only triggers the event for a button click, preventing bubbling up and triggering the div box too.</p><h4>Browsers and Bubbling</h4><p>Along with bubbling, you can hear of browsers doing what’s called Capturing, which is the same process as Bubbling, but moving <strong>down</strong> the DOM tree to your event instead of bubbling <strong>up </strong>from the event<strong>. </strong>Browsers used to choose to function one way or the other, which made predicting these occasions difficult for developers, but the good news is that most common browsers have now standardized to Bubbling.</p><h4>The Takeaway</h4><p>If you catch your program performing tasks you didn’t ask it to perform right then — remember it might be bubbling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d4c83a558b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Rails]]></title>
            <link>https://medium.com/@augustgiles8/debugging-rails-758ee6956dc6?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/758ee6956dc6</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Thu, 12 Jul 2018 18:28:32 GMT</pubDate>
            <atom:updated>2018-07-12T18:28:32.965Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*Jd_Z9Y7b5UfT7q3Bws-osg.jpeg" /></figure><p>My #1 source of frustration when first learning to program: DEBUGGING.</p><p>Tough bugs can be fairly demotivating, but knowing that there are tools to help can aide in feeling confident that you’ll push through it.</p><h3>Rails Console</h3><h4>What is Rails Console?</h4><p>It’s a built in feature of Rails that allows you to test the way in which aspects of your app, like Models and Objects, can be manipulated.</p><p>When in a rails app — run the following command in the terminal to start.</p><pre>$ rails c<br></pre><pre>####### THEN YOU CAN RUN COMMANDS LIKE THE FOLLOWING ############</pre><pre>2.3.3 :001 &gt; Contact.all</pre><pre><strong>Contact Load (16.0ms)</strong>  <strong>SELECT  &quot;contacts&quot;.* FROM &quot;contacts&quot; LIMIT $1</strong>  [[&quot;LIMIT&quot;, 11]]</pre><pre>=&gt; #&lt;ActiveRecord::Relation [#&lt;Contact id: 1, name: &quot;SuzieQ&quot;, email: &quot;DisisSuzie@whatever.com&quot;, user_id: 2, created_at: &quot;2018-07-11 14:32:07&quot;, updated_at: &quot;2018-07-11 14:32:07&quot;&gt;, #&lt;Contact id: 2, name: &quot;Joellen&quot;, email: &quot;melonmelonmelon@whatever.com&quot;, user_id: 1, created_at: &quot;2018-07-11 14:32:07&quot;, updated_at: &quot;2018-07-11 14:32:07&quot;&gt;]&gt;</pre><pre>2.3.3 :002 &gt; joellen = Contact.last</pre><pre><strong>Contact Load (0.5ms)</strong>  <strong>SELECT  &quot;contacts&quot;.* FROM &quot;contacts&quot; ORDER BY &quot;contacts&quot;.&quot;id&quot; DESC LIMIT $1</strong>  [[&quot;LIMIT&quot;, 1]]</pre><pre>=&gt; #&lt;Contact id: 2, name: &quot;Joellen&quot;, email: &quot;melonmelonmelon@whatever.com&quot;, user_id: 1, created_at: &quot;2018-07-11 14:32:07&quot;, updated_at: &quot;2018-07-11 14:32:07&quot;&gt;</pre><pre>2.3.3 :003 &gt; joellen.email</pre><pre>=&gt; &quot;melonmelonmelon@whatever.com&quot;</pre><pre>2.3.3 :004 &gt; joellen.email.reverse</pre><pre>=&gt; &quot;moc.revetahw@nolemnolemnolem&quot;</pre><p>You can snag items, perform more logic, even add to the database!</p><h4>Restraints:</h4><p>As you can probably tell, it’s difficult to get the whole picture of things from here. You would test more about how smaller elements are called and give immediate feedback on how they respond to your influences.</p><h3>Run Rails Server</h3><h4>What is Rails Server?</h4><p>It’s a built in feature of rails that allows you to render your app to <a href="http://localhost:3000/">http://localhost:3000/</a> . From there, you can path through your website.</p><ol><li>Allows immediate feedback on how your code is functioning</li><li>Allows immediate feedback on how your code is NOT functioning… see below section on <em>Error Messages in the Browser</em></li><li>Shows the various requests and responses made, as well as their outcomes… see below section on <em>Log Messages</em></li></ol><p>When in a rails app — run the following command in the terminal to start.</p><pre>$ rails s</pre><p>From there, you can go to the website above and test how it functions. Are things returning the way you expect them to?</p><h4><em>Error Messages in the Browser</em></h4><p>This happens when something in your code breaks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g1ANyYohlwi--Qq5PE4T-g.png" /></figure><h4>— — Why Pay Attention to Browser Error Messages?</h4><ol><li>Ruby is quite helpful in pointing out where the issues lie and what the issues are. In the above example, Ruby shows us that the user is requesting a route [GET] “/routes” and it also shows us that there is no route match for that request</li><li>Ruby also usually attempts to give a solution. Above, it suggests a list of the routes that are present and can be used</li><li>If you still don’t quite get it — This helps the Googling (see below)!</li></ol><h4>Server Log</h4><p>The log’s function is to tell you the the request/response information (GET, POST … ) as well as contact with the database. Following is an example block resulting from a PATCH request…</p><pre>##### <strong>Started PATCH</strong> &quot;/contacts/2&quot; for 127.0.0.1 at 2018-07-11 13:23:35 -0400</pre><pre>Processing by ContactsController#update as HTML</pre><pre>##### <strong>Parameters:</strong> {&quot;utf8&quot;=&gt;&quot;✓&quot;, &quot;authenticity_token&quot;=&gt;&quot;TZmrNUVizKttbvOncamlJltUknA4w5HmfkK3kM+tIlfnUxNF6tZt3TBdrmEG2lcOesxilzcVR7y8icePAKgIXQ==&quot;, &quot;contact&quot;=&gt;{&quot;name&quot;=&gt;&quot;Joellen&quot;, &quot;email&quot;=&gt;&quot;melonmelonmelon&quot;}, &quot;commit&quot;=&gt;&quot;Update Contact&quot;, &quot;id&quot;=&gt;&quot;2&quot;}</pre><pre><strong>Contact Load (1.1ms)</strong>  <strong>SELECT  &quot;contacts&quot;.* FROM &quot;contacts&quot; WHERE &quot;contacts&quot;.&quot;id&quot; = $1 LIMIT $2</strong>  [[&quot;id&quot;, 2], [&quot;LIMIT&quot;, 1]]</pre><pre>↳ app/controllers/contacts_controller.rb:50</pre><pre>##### <strong>(0.3ms)</strong>  <strong>BEGIN</strong></pre><pre>↳ app/controllers/contacts_controller.rb:31</pre><pre><strong>User Load (0.9ms)</strong>  <strong>SELECT  &quot;users&quot;.* FROM &quot;users&quot; WHERE &quot;users&quot;.&quot;id&quot; = $1 LIMIT $2</strong>  [[&quot;id&quot;, 1], [&quot;LIMIT&quot;, 1]]</pre><pre>↳ app/controllers/contacts_controller.rb:31</pre><pre>##### <strong>Contact Exists (0.7ms)</strong>  <strong>SELECT  1 AS one FROM &quot;contacts&quot; WHERE &quot;contacts&quot;.&quot;email&quot; = $1 AND &quot;contacts&quot;.&quot;id&quot; != $2 LIMIT $3</strong>  [[&quot;email&quot;, &quot;melonmelonmelon&quot;], [&quot;id&quot;, 2], [&quot;LIMIT&quot;, 1]]</pre><pre>↳ app/controllers/contacts_controller.rb:31</pre><pre>##### <strong>(0.4ms)</strong>  <strong>ROLLBACK</strong></pre><pre>↳ app/controllers/contacts_controller.rb:31</pre><pre>...</pre><pre>##### <strong>Rendered</strong> contacts/edit.erb within layouts/application (11.4ms)</pre><pre>##### <strong>Completed 200 OK</strong> in 397ms (Views: 382.9ms | ActiveRecord: 3.4ms)</pre><p>Notice the areas above with #####.</p><p>Begun the PATCH transaction → Gave parameters passed in → Started the Patch with the Database → Found that the ‘Contact Exists’ → Rolled back (did not perform the Patch → Rendered page → HTTP Status Code of 200.</p><p>This allows you to see how the behavior through a request is/is not aligned with what you want it to do. If it isn’t aligned, where did the path stray?</p><h3>Google</h3><h4>Why Google?</h4><ol><li>Chances are, someone else has probably run into a similar issue</li><li>The programming community has a very active and helpful online culture</li></ol><p>A good google search often points you in the right direction, if not renders you an appropriate answer. Some great resources to select include <a href="https://stackoverflow.com/">StackOverflow</a>, <a href="http://guides.rubyonrails.org/">Rails Documentation</a>, and Personal Blogs.</p><h4>Restraints:</h4><p>This strategy does require you to have an idea of where the issue lies. What specific part of the code is going wrong? What is the result of the code now? What would you like it to do?</p><h3>Your Favorite Debugging Gem</h3><p>Developers have created many resources that can help in the debugging process, be it walking you through your code, digging into local objects, or making things more readable. Two gems that I’ve enjoyed using are <a href="http://pryrepl.org/">pry</a> and <a href="https://github.com/deivid-rodriguez/pry-byebug">byebug</a>, which are pretty similar, but they allow you to drop into any area of your code to understand what is happening on a smaller level, helping to locate the source of trouble. Go search for some Debugging Gems!</p><h3>Rubber Ducking</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*Iq0oNgMORA9TZ5SwdeE7kg.jpeg" /><figcaption>Because People Are Overrated</figcaption></figure><p>“Rubber Ducking” is the idea you talk the problem out. The act of articulating an issue, getting another being (duck or otherwise) to understand the problem at hand, can have the positive effect of helping you to solve your problem. So tell your issues to Baby Freud Duck. It‘s likely worth it as a starting point!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=758ee6956dc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[R-S-P-E-C]]></title>
            <link>https://medium.com/@augustgiles8/r-s-p-e-c-2b22cf3cb4ec?source=rss-8c1ff22dd66b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b22cf3cb4ec</guid>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[August Giles]]></dc:creator>
            <pubDate>Thu, 28 Jun 2018 07:56:47 GMT</pubDate>
            <atom:updated>2018-06-28T07:56:47.732Z</atom:updated>
            <content:encoded><![CDATA[<h4>…find out what it means to me?</h4><p>As developers, we are expected to build code that is functional! That is by no means the most novel thought —but it is ubiquitous in programming. Code builds upon code which builds upon code and that dependency can magnify problems of functionality that exist within the code. To be sure code works, we could spend time running our own local tests in the console or in a <a href="https://repl.it/repls/OutgoingDarkmagentaFilesize">REPL</a>, but those methods prove difficult as the program grows larger or as it starts communicating with itself as a framework does. That being the case, programmers have created wonderful methodologies and tools to test their code, ensuring that it provides the intended result throughout the development process.</p><p>In this post, we’ll briefly go over two main topics to get started with testing!</p><ul><li>First is RSPEC, which is a tool for testing Ruby code</li><li>Second is TDD (Test Driven Development), a process by which developers can code while implementing and benefiting from tests</li></ul><h4>RSPEC!</h4><p>At its essence, RSPEC is a gem. When it’s put into the Gemfile of an application/directory and initialized, the developer is given the capability to write tests for their code in a Ruby type of format. More about set-up can be read in the <a href="http://rspec.info/">documentation</a>.</p><p>RSPEC is especially designed to test behavior. We’ll discuss this more, but let’s first use the following example:</p><pre>def pocket_chocolates(num_table_chocolates)<br>  p_chocolates = 0<br>  until num_table_chocolates == 0<br>    puts &quot;mmmmm&quot;<br>    p_chocolates += 1<br>    num_table_chocolates -= 1<br>  end<br>  p_chocolates<br>end</pre><p>This method takes a function #pocket_chocolates which accepts one argument (num_table_chocolates), loops until num_table_chocolates == 0 (no more chocolate on the table), and returns the number of pocket_chocolates that I’ve taken from the table and put in my pocket.</p><p>Example RSPEC to test the <strong>return value</strong>:</p><pre>describe &quot;pocket_chocolates&quot; do<br>    it &quot;returns how many chocolates are now in my pocket&quot; do<br>      expect(pocket_chocolates(10)).to eq(10)<br>    end<br>  end</pre><p>The RSPEC syntax works hard to make it easy for us to formulate and understand the tests we’re implementing. More detailed breakdown:</p><pre># ==== method name ====<br>describe &quot;pocket_chocolates&quot; do</pre><pre>    # ==== plain explanation of what the test is asking for ====<br>    it &quot;returns how many chocolates are now in my pocket&quot; do</pre><pre>      # === runs the method with a given argument - equalling 10 ===<br>      expect(pocket_chocolates(10)).to eq(10)</pre><pre>    end</pre><pre>  end</pre><p><strong>To recap:</strong> We tested the<em> behavior </em>of our method, expecting that until the table chocolates were gone, I would keep putting them in my pocket. In other words, until the loop broke, I would keep incrementing my counter. The output of what’s in my pocket should match what was on the table.</p><p>Let’s test another behavior of this method! We are also able to test <strong>output</strong> <strong>to the terminal</strong> through RSPEC. Consider the following:</p><pre>describe &quot;pocket_chocolates&quot; do<br>    it &quot;outputs &#39;mmmmm&#39; to terminal for each chocolate that is      placed in pocket&quot; do<br>      expect {pocket_chocolates(5)}.to      output(&quot;mmmmm\nmmmmm\nmmmmm\nmmmmm\nmmmmm\n&quot;).to_stdout<br>    end<br>  end</pre><p>Breakdown:</p><pre># === method name ===<br>describe &quot;pocket_chocolates&quot; do</pre><pre># === plain explanation of what the test is asking for ===<br>  it &quot;outputs &#39;mmmmm&#39; to terminal for each chocolate that is placed in pocket&quot; do</pre><pre># === runs method with argument expecting terminal output ===<br>    expect {pocket_chocolates(5)}.to output(&quot;mmmmm\nmmmmm\nmmmmm\nmmmmm\nmmmmm\n&quot;).to_stdout</pre><pre>  end<br>  <br>end</pre><p>To recap: This test read my terminal output. Every time I grabbed a chocolate from the table and put the chocolate in my pocket, I posted “mmmmm” to terminal. The test in the output section accounted for the argument provided in the expect section, so that it would post 5 times.</p><p>Now that we have an idea of what these tests are and what they can do — let’s talk about workflow with testing.</p><h4>Test Driven Development</h4><p>Test Driven Development (TDD) is a process by which programmers go about testing and developing. The cycle for this testing goes as follows:</p><pre>         THE TDD CYCLE</pre><pre>          Add Test &lt; -----<br>              |           |<br>        See Test Fail     |<br>              |           |<br>          Write Code      |<br>              |           |<br>          Run Tests &lt; ----|      # this lower segment can be run as <br>              |           |      #   many times as is necessary<br>           Refactor ----- &gt;</pre><p>Let’s follow this cycle for our example above, focusing on the first RSPEC test.</p><ol><li>We know our situation and we’ll write a test for a method #pocket_chocolates , same code as before:</li></ol><pre>describe &quot;pocket_chocolates&quot; do<br>    it &quot;returns how many chocolates are now in my pocket&quot; do<br>      expect(pocket_chocolates(10)).to eq(10)<br>    end<br>  end</pre><p>2. We’ll run the test <strong>without </strong>creating the method yet. Our test output shows as follows:</p><pre>Failures:</pre><pre>1) Candy pocket_chocolates returns how many chocolates are now in my pocket</pre><pre>Failure/Error: expect(pocket_chocolates(10)).to eq(10)</pre><pre>NoMethodError:</pre><pre>undefined method `pocket_chocolates&#39; for #&lt;RSpec::ExampleGroups::Candy::PocketChocolates:0x007fc96ae59940&gt;</pre><pre># ./spec/candy_spec.rb:8:in `block (3 levels) in &lt;top (required)&gt;&#39;</pre><pre>Finished in 0.01268 seconds (files took 0.40351 seconds to load)</pre><pre>1 example, 1 failure  &lt;-- #=== TEST IS SHOWING US ERROR ===<br>                        #=== TEST IS SHOWING US ERROR ===</pre><pre>Failed examples:</pre><pre>rspec ./spec/candy_spec.rb:7 # Candy pocket_chocolates returns how many chocolates are now in my pocket</pre><p>3. We then write our method according to those errors:</p><pre>def pocket_chocolates(num_table_chocolates)<br>  p_chocolates = 0<br>  until num_table_chocolates == 0<br>    puts &quot;mmmmm&quot;<br>    p_chocolates = p_chocolates + 1<br>    num_table_chocolates = num_table_chocolates - 1<br>  end<br>  p_chocolates<br>end</pre><p>4. Test it again!</p><pre>mmmmm               #=== OUTPUTS TO TERMINAL FROM METHOD ===<br>mmmmm<br>mmmmm<br>mmmmm<br>mmmmm<br>mmmmm<br>mmmmm<br>mmmmm<br>mmmmm<br>mmmmm<br>.</pre><pre>Finished in 0.0222 seconds (files took 0.38779 seconds to load)</pre><pre>1 example, 0 failures    #=== PASSING STATUS ===</pre><p>5. Refactor</p><pre>def pocket_chocolates(num_table_chocolates)<br>  p_chocolates = 0<br>  until num_table_chocolates == 0<br>    puts &quot;mmmmm&quot;<br>    p_chocolates += 1                       #=== REFACTORED HERE ===<br>    num_table_chocolates -= 1               #=== REFACTORED HERE ===<br>  end<br>  p_chocolates<br>end</pre><p>6. Test it again! (Same as above)</p><p>There are great<strong> benefits </strong>of utilizing the TDD method.</p><ul><li>It requires the developer to create these tests for many smaller units of code, and then can track those smaller units as they are built into more complex pieces. If a code from another place errors an earlier test, it will show you what happened and in which method so it can be adjusted!</li><li>By testing early and testing often, a developer can escape a lot of troubles that happen when they just create a lot of material, hit an error, and can’t locate the problem.</li><li>By watching the test fail when it’s first created and before the method is made, it keeps developers from creating a test that’s faulty and passing for no reason.</li></ul><p>By implementing these tools and processes in our workflow, we can greatly increase our ability to create cleaner and more functional code from the start.</p><blockquote>All I’m asking is for a little RSPEC</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b22cf3cb4ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>