<?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 Nate Park on Medium]]></title>
        <description><![CDATA[Stories by Nate Park on Medium]]></description>
        <link>https://medium.com/@stomg7969?source=rss-2414dbf988c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6TKuobb7YQt7ons2.jpg</url>
            <title>Stories by Nate Park on Medium</title>
            <link>https://medium.com/@stomg7969?source=rss-2414dbf988c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:53:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stomg7969/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[Deploying a static website: GatsbyJS to AWS S3 (and more)]]></title>
            <link>https://medium.com/swlh/deploying-a-static-website-gatsbyjs-to-aws-s3-and-more-a1c496527576?source=rss-2414dbf988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1c496527576</guid>
            <category><![CDATA[aws-codepipeline]]></category>
            <category><![CDATA[aws-codebuild]]></category>
            <category><![CDATA[amazon-cloudfront]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[aws-iam]]></category>
            <dc:creator><![CDATA[Nate Park]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 23:05:10 GMT</pubDate>
            <atom:updated>2019-07-31T22:13:55.634Z</atom:updated>
            <content:encoded><![CDATA[<h4>AWS S3, IAM, CodePipeline, CloudFront, and Route 53</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSd0DQoAN7GeoZafy6x1EQ.png" /><figcaption>Each official logo downloaded from each official website (GatsbyJS &amp; Amazon Web Service)</figcaption></figure><p>Today, deploying a personal website is easier than ever. There are hosting websites such as Wix, SquareSpace, Shopify, and many more. However, we have to pay a fixed price and it is not automatically scalable. For example, if you built a portfolio just for your potential employers, you may feel like even the basic plan can be too expensive.</p><p>Amazon Web Service (AWS) is perfect in this situation. It is <strong>scalable</strong>, and you only <strong>pay what you use</strong>. If no one visits the website (hopefully not), you pay <strong>nothing</strong>. As an AWS Certified Cloud Practitioner, I would like to introduce you to how to deploy your website using AWS resources step by step.</p><p>Before writing this blog, I also went through a lot of trouble to successfully deploy my website (by the way, you are always welcome to check out my portfolio website! — <a href="http://www.thedevelopark.com/"><strong>www.thedevelopark.com</strong></a>). I saw numerous articles and blogs about deploying instruction. In this blog, I combined all of them into one, and also, I wanted to share with you about some unexpected situation that I had to figure out on my own.</p><p><em>For anyone who is not familiar with AWS, but interested in learning, I recommend taking courses instead of following instructions like this.</em></p><h3>1. Amazon Simple Storage Service (S3) bucket</h3><p><strong>*UPDATE (July 31, 2019)*</strong> <em>Emiliano Gabrielli gave me awesome feedback about hosting a website in a more secure way — (</em><a href="https://medium.com/faktiva/deploy-a-static-website-on-aws-the-right-way-e83f47d60fdc"><em>Emiliano’s Article</em></a><em>). The updates are written under </em><strong><em>4. Amazon CloudFront. </em></strong><em>There are </em><strong><em>two</em></strong><em> updated sections. The updates are added in the way that you don’t need to delete and recreate anything.</em></p><p>S3 bucket is one of the ways to host a website. But it is only compatible with a static website that doesn’t require server-side technologies.</p><p>First, create a bucket with a name. It <strong>must be unique</strong> because S3 bucket name is <strong>shared globally</strong>. If you have owned domain, it is better to have the bucket name to be the domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*98xHzcfauqjpa7QEbtt-Kw.png" /></figure><p>Going through step by step, while leaving everything as it is (default settings), the only section we need to change is the tab 3, ‘<strong>Set permission</strong>’. Uncheck ‘<strong><em>Block all public access</em></strong>’, otherwise, people will not be able to visit your website.</p><p>Once created, click the bucket <strong>row</strong>. It will toggle the bucket information. Click ‘<strong>Copy Bucket ARN</strong>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aN3pbXT10DcW5UdL_2OeiQ.png" /></figure><p>Now let’s go into the bucket by clicking the <strong>text </strong>exactly<strong>. </strong>For me, it is ‘thedevelopark.com’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*FaSFRVHpGriO9rnE-nQSEw.png" /></figure><p>Then, click ‘<strong>Permissions</strong>’ → click ‘<strong>Bucket Policy</strong>’.</p><p>Our Bucket policy editor is empty because the bucket is newly created. Mostly, other similar blogs should have the same policy as mine, but for guide purpose, let’s generate one!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6o_a4YXj3PS0v2Mif8Uyg.png" /></figure><p>There are four red circles that we need to change unless AWS Service is not Amazon S3.</p><p>First Circle — <strong>Select Type of Policy</strong> → S3 Bucket Policy.<br>Second Circle — <strong>Principal</strong> → *<br>Third Circle — <strong>Actions</strong> → GetObject<br>Forth Circle — <strong>ARN</strong> → paste what we previously copied, then (<strong>IMPORTANT</strong>) add /* at the end. /* gives access to the contents inside of the bucket.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c47344e4e8bc771f34c5d7a93a237c3b/href">https://medium.com/media/c47344e4e8bc771f34c5d7a93a237c3b/href</a></iframe><p>→ Click ‘<strong>Add Statement</strong>’ → click ‘<strong>Generate Policy</strong>’. In the end, it will return the Policy as JSON format.</p><p>In generated policy, note that the Action has an array. If only one action, we can <strong>remove</strong> the array. Also, if you want to just copy policy, make sure to <strong>change</strong> the &#39;Resource&#39; to yours.</p><p>Copy the generated policy and paste to the empty Bucket policy editor.</p><p>It will give a warning when we save. We can ignore it.</p><p>Two more steps to go!</p><p>Now, our bucket needs some contents to show visitors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRPoPF8vn3P6o6Jw09SpMQ.png" /></figure><p>Go to ‘<strong>Overview tab</strong>’ (it is located along with the ‘Permissions’ tab) → click ‘<strong>Upload</strong>’. Then <strong>DRAG</strong> your contents. ‘Add files’ does not know how to handle folders.</p><p>Click ‘Next’ → under ‘<strong>2. Set permissions</strong>’, find ‘<strong>Manage public permissions</strong>’, change to ‘<strong>Grant public read access to this object(s)</strong>’ → choose <strong>Standard</strong> (free tier).</p><p>For the last step, allow the bucket to host a website with the uploaded contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q81yXzj39YTDcWkddGjGng.png" /></figure><p>Go to ‘<strong>Properties</strong>’ tab → click ‘S<strong>tatic website hosting</strong>’ → click ‘<strong>Use this bucket to host a website</strong>’ → put down index.html and 404.html if applicable. → Save. Done.</p><p><strong>IMPORTANT!</strong></p><p>The ‘<strong>Endpoint</strong>’ is your website address based on the S3 bucket. It <strong>will not work</strong> because we are using GatsbyJS. Your index.html is located in the public directory and S3 bucket can only find what is in the root directory.</p><p>To solve this issue, we need a “<strong>builder</strong>” in between your code and S3 bucket. A “builder” that can take theindex.html file out from the public directory so the bucket can successfully host your website. There are <strong>several options</strong> and it purely depends on your preference.</p><ul><li>Manually type in everything using CLI.</li><li>Use AWS CodeBuild.</li><li>Use Third-Party integration such as Travis CI.</li></ul><p>For readers who decided to use Travis CI:</p><ul><li><strong>travis-ci.org</strong> can only see public GitHub repositories.</li><li><strong>travis-ci.com</strong> can also see private repositories.</li><li>You can finish reading from here and refer to the following video.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F3tGMsdS3kSc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D3tGMsdS3kSc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F3tGMsdS3kSc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cc6a20427780281c3cd892814216e02/href">https://medium.com/media/0cc6a20427780281c3cd892814216e02/href</a></iframe><ul><li>If you see build logs saying, ‘Access Denied’, read my IAM part (add the policy to ‘<strong>user’, </strong>not role) and try again.</li><li>We will need to write .travis.yml. Here is the cheatsheet — (<a href="https://devhints.io/travis">CHEATSHEET FOR Travis.yml</a>).</li></ul><h3>2. Identity &amp; Access Management (IAM)</h3><p>However, before going over each one, IAM setup needs to be setup. Just like we push our code to GitHub, we can use our CLI to upload the files to the S3 bucket — (<a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html"><em>AWS documentation for CLI configuration</em></a><em>).</em></p><p>The command I used is:</p><pre>aws s3 sync ./public/ s3://&lt;your domain&gt; --delete</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01ace0192acb96b8bb0ff176b05d6ae5/href">https://medium.com/media/01ace0192acb96b8bb0ff176b05d6ae5/href</a></iframe><p><strong>In words</strong>:<br>From the root directory, synchronize files in the public directory to S3 bucket called, ‘thedevelopark.com’. Lastly,--delete will delete files that are in the destination, in this case, the S3 bucket. To learn more about this command, you can check out — (<a href="https://techburst.io/synchronizing-aws-s3-an-overview-5eaa12934d38">Synchronizing AWS S3 — an Overview</a>).</p><p>Now, back to IAM.</p><p>Without the IAM permission setup, access to the bucket will be denied. This is because the S3 bucket only allows public access for GetObject action, nothing else. You can allow more actions through configuring S3 bucket policy, but it is safer to use IAM service for the <strong>security matter</strong>.</p><p>AWS documentation provides great instruction on how to set up — (<a href="https://docs.aws.amazon.com/codebuild/latest/userguide/setting-up.html#setting-up-service-role">Policy Setup</a>). In the page, we will see four topics. We can check the <strong>first two</strong>.</p><p>If you decided to manually type in commands, then read the first topic. Otherwise, go directly to the second topic.</p><h3>3. AWS CodePipeline</h3><p>Next is AWS CodePipeline. It is a <strong>must-have</strong> AWS resource that <strong>automates</strong> the deployment process (Continous Delivery). For example, when you push changes to GitHub, AWS CodePipeline detects the change and triggers the process to upload the changes to the connect S3 bucket.</p><p>Let’s create a pipeline! There are <strong>5 steps</strong>:</p><p><strong>Step 1</strong>: Go to CodePipeline from the console → click ‘<strong>Create pipeline</strong>’ → create pipeline name (e.g. my-website-project) → choose <strong>Service role</strong> → click ‘<strong>Next</strong>’.</p><p><strong>Service Role</strong></p><ul><li>Choose ‘<strong>New service role</strong>’. The Role name will be auto-filled when we type in the Pipeline name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaUBE40rW7cYNejk-YdADg.png" /></figure><p><strong>Step 2</strong>: Choose GitHub for your <strong>source</strong> → connect your GitHub and choose the right repository → choose branch → select GitHub <strong>webhooks</strong> (selected by default) → click ‘<strong>Next</strong>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxPxzu-56zUUIwoVi1DIgQ.png" /></figure><p><strong>Step 3</strong>: If you are using AWS CodeBuild, stay. Otherwise, skip to step 4. <br>Choose AWS CodeBuild for Build provider → click ‘<strong>create project</strong>’ (a new window will pop-up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ctueJwI4gx9QnLMo9av1Nw.png" /></figure><p>The New window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bNqqPdE6T-f20saCfjUgEA.png" /></figure><p>→ Type in ‘<strong>Project name</strong>’ → select ‘<strong>Managed image</strong>’, then a new section will show up → choose ‘Standard’ for <strong>Runtime</strong> → choose ‘standard:2.0’ for <strong>Image</strong> → leave the rest as they are and find ‘Service role’ → select ‘<strong>Existing service role</strong>’ → find the role that we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o8xq6b88rak5Z2nv892Z-w.png" /></figure><p>→ Leave the rest as default. I recommend CloudWatch logs to be <strong>checked</strong> in case of a failure → click ‘<strong>Continue to CodePipeline’</strong> → click ‘<strong>Next</strong>’.</p><p><strong>Step 4</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrKNIhJYALETZzl795rplA.png" /></figure><p>Choose ‘Amazon S3’ for provider → <strong>make sure your Region is the same as the S3 bucket’s region</strong> → find the bucket and choose → check ‘<strong>Extract file before deploy</strong>’ → click ‘<strong>Next</strong>’.</p><p><strong>Step 5</strong>: Review the steps and click ‘Create Pipeline’. We will have something like this (If you created AWS CodeBuild, there should be ‘Build’ stage between ‘Source’ and ‘Deploy’).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9GP5vNurN845S08VAzcLg.png" /></figure><p>From now on, when you make changes to your code and push to the GitHub, AWS CodePipeline will detect the change and automatically upload the code to the S3 bucket.</p><p><strong>For AWS CodeBuild users only</strong>, we are not done! For users who prefer manual way, skip this part.</p><p>We need to provide buildspec.yml as an instruction for AWS CodeBuild.</p><p>First, here is the AWS documentation for buildspec.yml — (<a href="https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-name-storage">Build Specification Reference for CodeBuild</a>). This should give you some understanding of it.</p><p>Also, here are some examples:</p><ul><li>Since using the Image version of standard 2.0, version <strong>must</strong> be 0.2 and runtime-versions is <strong>required</strong>.</li><li>Except above point, the rest phases are optional.</li></ul><p>Option A:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a19f797b7e25abe45d1e3da6b33e278/href">https://medium.com/media/5a19f797b7e25abe45d1e3da6b33e278/href</a></iframe><ul><li>commands: is for CLI commands.</li><li>echo is to echo current phases.</li></ul><p>Option B:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76239437043dc2556afad3593d98f1b8/href">https://medium.com/media/76239437043dc2556afad3593d98f1b8/href</a></iframe><p><strong>In words</strong>: <br>First, delete all files in S3 bucket → create a new directory called build-output → move all files that are in public directory to build-output directory → delete everything except build-output → move all files that are in build-output → then delete build-output.</p><p>However, ‘Option B’ is <strong>not</strong> a successful example because it only keeps files that are in the public directory and deletes the rest (Gastsby files).</p><p>Purpose of examples is to show you that there are many different ways to command your AWS CodeBuild to process deployment. I am also having trouble succeeding in the CodeBuild process (<a href="https://stackoverflow.com/q/57189244/11530680">My question on StackOverflow</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*j3hVoNpm7nMPfSEwy_KDtw.gif" /><figcaption>Deployment process example, gif image from <a href="https://medium.com/@kyle.galbraith/how-to-continuously-deploy-a-static-website-in-style-using-github-and-aws-3df7ecb58d9c">https://medium.com/@kyle.galbraith/how-to-continuously-deploy-a-static-website-in-style-using-github-and-aws-3df7ecb58d9c</a></figcaption></figure><p>Once all process is successful, your S3 bucket should be updated.</p><p><strong>For Manually typing users,</strong> after creating AWS CodePipeline, in your terminal, type in following commands:</p><pre>npm run build</pre><pre>aws s3 sync ./public/ s3://&lt;your domain&gt; --delete</pre><pre>git add &amp;&amp; commit &amp;&amp; push</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6a6b621814d4539dd5f285f4126bcf9/href">https://medium.com/media/a6a6b621814d4539dd5f285f4126bcf9/href</a></iframe><p>Unless your website requires constant change, then I recommend the manual way.</p><p>That is it! Go to your S3 bucket and click the bucket ‘Endpoint’. Your website should be up and running.</p><h3>4. Amazon CloudFront</h3><h4>(Optional, but recommended)</h4><p>Now you may be realized, we only have the S3 bucket Endpoint for your website address and it is not looking pretty.</p><p>We can purchase a domain through <strong>Amazon Route 53’s </strong>Domain Name Service (DNS) and request Secure Sockets Layer/Transport Layer Security (SSL/TLS) certificates through <strong>AWS Certificate Manager</strong>.</p><p>To connect your domain to the S3 bucket, <strong>Amazon CloudFront</strong> will handle everything.</p><blockquote><strong>Amazon CloudFront</strong> is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment. — <a href="https://aws.amazon.com/cloudfront/"><strong>AWS</strong></a></blockquote><h4>How to set up:</h4><p>Go to CloudFront from AWS console → click ‘<strong>Create Distribution</strong>’ → click ‘<strong>Get Started</strong>’ under ‘<strong>Web</strong>’ section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8oZxW8jJd758cPBItRWbg.png" /></figure><p>Find and choose your S3 bucket in ‘<strong>Origin Domain Name</strong>’ → Find ‘<strong>Viewer Protocol Policy</strong>’ and select ‘Redirect HTTP to HTTPS’.</p><p><strong>*UPDATE*</strong> To make your website more secure, I added extra steps. We will restrict bucket access (and update S3 bucket after).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*7PcxDclSy5IbA0xA-yUf3g.png" /></figure><p>Check ‘Yes’ for ‘<strong>Restrict Bucket Access’, </strong>then more options will appear → choose ‘<strong>Origin Access Identity</strong>’. If you are ‘creating’, the name is automatically created. → check ‘Yes, Update Bucket Policy’ for ‘<strong>Grant Read Permissions on Bucket</strong>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAzDun8CdSBWK5hNhdDx2g.png" /></figure><p>→ If you want to customize Time to Live (TTL), cache expiration time, select ‘Customize’ from ‘<strong>Object Caching</strong>’ and change TTL, otherwise, skip → check ‘Yes’ for ‘<strong>Compress Objects Automatically’.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SsALfUbwOvIS089cKV0vqg.png" /></figure><p>→ Find ‘<strong>Alternate Domain Names (CNAMEs)</strong>’, put down your purchased domain name both with and without ‘www’ → select ‘<strong>Custom SSL Certificate</strong>’ → choose the certificate created from AWS Certificate Manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pBl1dMZrrjisd44stMD1zg.png" /></figure><p>→ Input ‘index.html’ in ‘<strong>Default Root Object</strong>’ → write your domain name on ‘<strong>Comment</strong>’ (optional) → Done! It is going to take some time to create the distribution.</p><p>Now, we should have another domain name that looks like ‘aoiwenf3oisfj.cloudfront.net’. If it leads to your website, it means the CloudFront distribution is successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmJVOhpZDjkoXUTxDDNFNw.png" /></figure><p>If you have and 404 page, we can lead visitors to pre-made ‘404’ page by creating a custom error response.</p><h3>4–1 Back to S3 bucket</h3><p><strong>*UPDATE</strong>* Now that CloudFront is all set, let’s go back to S3 bucket and secure it.</p><p>First, Disable ‘<strong>Static website hosting</strong>’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*9cXZQamVDlalNyea1jbtYw.png" /></figure><p>Now that we have CloudFront has its own domain name along with your purchased domain, we no longer need the Endpoint.</p><p>Second, Enable ‘<strong>Block <em>all</em> public access</strong>’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*fvpW_h0eJAQ7U-US85V0tw.png" /></figure><p>We can block all public access, but it is still accessible through CloudFront.</p><p>In order for CloudFront to access the bucket, we need to update the ‘<strong>Bucket Policy’</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*PfHhG647LIkdDCxEjCgxZg.png" /></figure><p>Notice that the policy is different from what we originally created (the red rectangle is added). It is because when we were creating the CloudFront distribution, we checked ‘Yes, Update Bucket Policy’ for ‘<strong>Grant Read Permissions on Bucket</strong>’.</p><p>If we compare, every key has the same values <strong>except</strong> “<strong>Principal</strong>”. Instead of *, it is something about ‘CloudFront Origin Access Identity’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*34fStBHN21OVeN1pQX_lAQ.png" /></figure><p>Go to <strong>CloudFront</strong> → click the <strong>ID</strong>, → go to ‘<strong>Origins and Origin Groups</strong>’ tab. You will see the ‘Origin Access Identity’.</p><p>Now, delete the original policy, and add a new one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*1j7YfWAMDxa6ZhpW03iBBA.png" /></figure><pre>,{<br>   &quot;Sid&quot;: &quot;AllowListBucketContents&quot;,<br>   &quot;Effect&quot;: &quot;Allow&quot;,<br>   &quot;Principal&quot;: {<br>       &quot;AWS&quot;: &quot;arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity &lt;your identity ID&gt;&quot;<br>   },<br>   &quot;Action&quot;: &quot;s3:ListBucket&quot;,<br>   &quot;Resource&quot;: &quot;arn:aws:s3:::&lt;your domain name&gt;&quot;<br>}</pre><p>New above Element is added. The two elements are very similar except ‘<strong>red</strong>’ and ‘<strong>orange</strong>’ underlines. Make sure the check (also <strong>comma</strong> between elements!).</p><p>Your website is now secured!</p><h3>5. Route 53</h3><h4>(Optional, but recommended)</h4><p>Now, it is time to connect and redirect all services to your domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IIFKVx0u2Qvg5u_ccjoudQ.png" /><figcaption>Route 53 Dashboard</figcaption></figure><p>Since you purchased a domain name, there should be 1 Hosted zone created already. Going into ‘<strong>Hosted zones</strong>’ and click the domain, you will see the following two types are already created with values that start with ‘ns’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3PVlOnrs3Dz48gRvWCzugw.png" /></figure><p>If you accidentally deleted the hosted zone, you can always recreate it and match the values by editing.</p><p>Now, let’s create type ‘A’ and ‘CNAME’ Record set to connect the domain name to CloudFront domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*RXmkoutEssR6agQab0zWGg.png" /></figure><p>Leave the ‘<strong>Name</strong>’ empty → choose <strong>type</strong> ‘A’ → write your CloudFront domain name (ao3rijrojnsd8.cloudfront.net) in ‘<strong>Value</strong>’ → click Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*fzkZEyvzkavtlgOShV3uew.png" /></figure><p>→ Write ‘www’ in ‘<strong>Name</strong>’ → choose ‘CNAME’ for ‘<strong>Type</strong>’ → write your CloudFront domain in ‘<strong>Value</strong>’ → click ‘Create’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*l7R6u5LWpbqnVnzde4Jr7Q.gif" /><figcaption>gif from giphy.com</figcaption></figure><p>Now we have your website properly published!</p><h3>Conclusion:</h3><p>My knowledge of AWS is still basic and I am very excited to continue this path to become a professional AWS developer.</p><p>AWS provides many different resources to host your websites such as AWS Amplify, AWS Elastic BeanStalk, Amazon Elastic Cloud Compute (EC2), and more. There are hundreds of blogs, articles, and videos that guide you on how to do. If you are thinking of running a startup, even if you are already, I really recommend learning more about AWS. It is truly interesting and also potentially will help you grow faster.</p><h3>References</h3><ul><li>AWS CLI Documentation — <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html</a></li><li>AWS S3 sync command — <a href="https://techburst.io/synchronizing-aws-s3-an-overview-5eaa12934d38">https://techburst.io/synchronizing-aws-s3-an-overview-5eaa12934d38</a></li><li>AWS IAM policy setup Doc — <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/setting-up.html#setting-up-service-role">https://docs.aws.amazon.com/codebuild/latest/userguide/setting-up.html#setting-up-service-role</a></li><li>AWS Build Specification Ref — <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-name-storage">https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-name-storage</a></li><li>Travis YAML file cheat sheet — <a href="https://devhints.io/travis">https://devhints.io/travis</a></li><li>buildspec.yml example — <a href="https://www.linkedin.com/pulse/how-build-pipeline-automate-deployment-github-aws-codebuild-nguyen/">https://www.linkedin.com/pulse/how-build-pipeline-automate-deployment-github-aws-codebuild-nguyen/</a></li><li>Emiliano Gabrielli’s article — <a href="https://medium.com/faktiva/deploy-a-static-website-on-aws-the-right-way-e83f47d60fdc">https://medium.com/faktiva/deploy-a-static-website-on-aws-the-right-way-e83f47d60fdc</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1c496527576" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/deploying-a-static-website-gatsbyjs-to-aws-s3-and-more-a1c496527576">Deploying a static website: GatsbyJS to AWS S3 (and more)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use axios.js for your HTTP requests!]]></title>
            <link>https://medium.com/@stomg7969/use-axios-js-for-your-http-requests-1c56e47433e2?source=rss-2414dbf988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c56e47433e2</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nate Park]]></dc:creator>
            <pubDate>Wed, 22 May 2019 01:25:16 GMT</pubDate>
            <atom:updated>2019-05-22T01:25:16.262Z</atom:updated>
            <content:encoded><![CDATA[<h4>A short guide on how to replace fetch with axios.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FbyiT0FphAPRrl10h3mLMg.jpeg" /><figcaption>Google Image — <a href="https://d585tldpucybw.cloudfront.net/sfimages/default-source/blogs/older-content/tdn/fetch_header.jpg?sfvrsn=a27590e1_1">https://d585tldpucybw.cloudfront.net/sfimages/default-source/blogs/older-content/tdn/fetch_header.jpg?sfvrsn=a27590e1_1</a></figcaption></figure><p>When I first learned javascript, I developed an application without using any external libraries or frameworks. I had no idea how inefficient I was being. After leanring React.js, I can hardly imagine myself developing an application without it. It is very useful to write DRY and readable codes. <strong>Well, </strong><strong>axios can make our codes even cleaner.</strong></p><p>A purpose of this blog is to share with you how I simplified my codes using axios. I will run through full CRUD with authentication &amp; authorization.</p><p><strong><em>Important message for beginners</em></strong><em>:</em> I highly recommend that you have strong knowledge about how fetch works and what CRUD is.</p><p><a href="https://medium.freecodecamp.org/a-practical-es6-guide-on-how-to-perform-http-requests-using-the-fetch-api-594c3d91a547">A practical ES6 guide on how to perform HTTP requests using the Fetch API</a></p><p>This article is a great resource about Fetch API.</p><h3>axios</h3><p><a href="https://github.com/axios/axios">GitHub - axios/axios: Promise based HTTP client for the browser and node.js</a></p><p>It is a library that we can replace fetch() with this. It does a lot of things for us beforehand. When building an application, we consistently have to fetch request to render data from the server side. During this process, we have to write the same things over and over. Because configuration that each CRUD performs are different it is also not feasible to create one united configuration. The bottom line is, IT IS NOT DRY.</p><p>I developed an eCommerce website that I need to geta list of products, post customer information when login/signup, patch my inventory when customers buy products, and delete customer database when they do not want to use my website anymore. Other than the above-listed <strong>CRUD</strong> actions, I have many more features that require an HTTP request.</p><p>I am going to go over each fetch request and show you before and after refactoring using axios. Note that some of my fetch requests require Authorization token to allow customers to have access to my database. The refactoring process will also show you how to handle them.</p><h3>GET</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da3ef93e7754eef9c674e06c8809153d/href">https://medium.com/media/da3ef93e7754eef9c674e06c8809153d/href</a></iframe><p>Although it is only get request, above is required format since the request needs to be authorized with token. There isn’t much to explain in this request except dealing with the response. With regular fetch request, it doesn’t automatically turn the data into json format, which requires .json(). Meanwhile, since axios already turns the data into json format, we just need to call the response with .data.</p><h3>POST</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54ab24d98d08f264f3e88ac4e8ffe766/href">https://medium.com/media/54ab24d98d08f264f3e88ac4e8ffe766/href</a></iframe><p>This is where axios becomes useful. Unlike regular fetch, axios already internally handles configuration. Unless explicitly given, such as authorizing token, it takes care of everything else. It only needs new data for “posting”.</p><h3>PATCH</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f7058893bdf03d80d9328c24e11c467/href">https://medium.com/media/3f7058893bdf03d80d9328c24e11c467/href</a></iframe><p>PATCH request is very similar to thePOST request. It only needs some data to update API. However, for this request, there is the token that needs to be passed to the server. This is where axios becomes, relatively, complicated. If there are multiple configuration keys to pass, we are no longer be able to write axios.patch(), instead, the method must be passed as a part of configuration.</p><p>Just for a reference, there is another option:</p><pre>axios({<br>   method: &#39;patch&#39;, // &lt;= axios doesn&#39;t require uppercasing.<br>   url: &lt;url&gt;,<br>   headers: {},<br>   data: {}<br>}) </pre><p>URL also can be a part of the configuration. This is completely up to developers.</p><h3>DELETE</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49af896975e1cf5d9186bdf8d2f41e9d/href">https://medium.com/media/49af896975e1cf5d9186bdf8d2f41e9d/href</a></iframe><p>Just like get request, delete request is simple, but still cleaner than regular fetch.</p><h3>Conclusion</h3><p>There are a lot more features to this library, but I wanted to share some simple examples of CRUD with auth configuration. I hope this demonstration intrigued every developer who didn’t know about axios. <strong>AGAIN</strong>, for beginners, I strongly recommend you to practice using regular fetch request first. Otherwise, it will be harder to understand the concept of what HTTP requesting is.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c56e47433e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Multi-Filter Function to Filter Out Multiple Attributes Using Javascript]]></title>
            <link>https://medium.com/better-programming/creating-a-multi-filter-function-to-filter-out-multiple-attributes-javascript-react-rails-5aad8e272142?source=rss-2414dbf988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5aad8e272142</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Nate Park]]></dc:creator>
            <pubDate>Sun, 12 May 2019 02:43:35 GMT</pubDate>
            <atom:updated>2020-09-30T10:14:34.692Z</atom:updated>
            <content:encoded><![CDATA[<h4>When one filter just isn’t enough</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*e5GJWv9b_7M8-H08kEBXSQ.jpeg" /><figcaption><a href="http://www.techtalk.gfi.com/wp-content/uploads/2011/07/web-content-filtering-200x300.jpg">http://www.techtalk.gfi.com/wp-content/uploads/2011/07/web-content-filtering-200x300.jpg</a></figcaption></figure><p>For the final project of a recent bootcamp, I was tasked with creating <a href="https://moonya-ecommerce.herokuapp.com/">an eCommerce website</a> where customers can buy children clothing. While building the site, my biggest challenge was writing a .filter function where customers can click on tags to narrow down their list of products.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSswj4N0Nd-090eAFx4HHA.png" /><figcaption>Customers can click on any tags, my filter function will render only products that satisfy customers’ choice.</figcaption></figure><p>In this piece, I’ll be walking through my process and codes and the final outcome while detailing <strong>how to create a multi-filter function</strong> that compares all of a product’s attributes and customer’s chosen tags to output a filtered list of products.</p><h3>What is .filter() in Javascript?</h3><blockquote>The <strong>filter()</strong> method creates a new array with all elements that pass the test implemented by the provided function. — <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">MDN documentation</a></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ff4e3cc1d2ce7a4aabc6a5a52f3aa97/href">https://medium.com/media/0ff4e3cc1d2ce7a4aabc6a5a52f3aa97/href</a></iframe><p>Accepting a function as an argument, using .filter() will return a new array with all elements that return true.</p><h3>Product table design</h3><p>Before diving straight into explaining, let&#39;s review the properties of the products we will be filtering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOAJEyFBXl5-lgP0z3-R4w.png" /></figure><p>Here are the values for each key:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca7554a5a59ea56702302b8950ccabc4/href">https://medium.com/media/ca7554a5a59ea56702302b8950ccabc4/href</a></iframe><p>Not only it was challenging because I wanted to create a dynamic filter function, but also because material is an array that contains multiple elements.</p><h3>My Complete Codes</h3><p>One feature of the website is that customers can see what tags they chose above search input. To cancel tags, simply click on chosen tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5NiPVmvlWek6cy4O49lG5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*3OqZMJyR8Q1IG8CKNB8NOA.gif" /></figure><p>In order to render the chosen tags between the magnifier icon and searching section, I had to design my react’s state in a specific way. The “tag-collecting” section (small red rectangle) will collect any tags that customers clicked, meaning that when one of the tags are clicked, it triggers a callback, callFilterClickListener(), that sets the boolean state to true.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89da2d4e616c664c54d15ebc619a848a/href">https://medium.com/media/89da2d4e616c664c54d15ebc619a848a/href</a></iframe><p>Because each element in each key has a different responsibility and because I required each of them to be clickable tags for customers, I had to write <a href="https://gist.github.com/stomg7969/7d4cb0d4dc0a7864ab250c8f05fdf15e">a very long script</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2QpbhASevfrabDRb4cCCRQ.png" /><figcaption>Each key has its own ‘div’ tag but calls the same function with different arguments.</figcaption></figure><p>Since customers can click on any of the tags to cancel them, including tags that are already chosen, I included another component that looks very similar to the above component.</p><h3>.allFilterClickListener()</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e5ba6ed9774b94f9ecd248bd33e200b/href">https://medium.com/media/4e5ba6ed9774b94f9ecd248bd33e200b/href</a></iframe><p>The function allFilterClickListener() dynamically takes an event and the name of the property as arguments (refer to the<em> </em>first image<em> </em>under My Complete Codes).</p><p><em>Side Note: React Doc recommends to use </em><em>prevState when using </em><em>.setState(). You can find more information in </em><a href="https://teamtreehouse.com/community/react-docs-now-recommends-using-function-with-prevstate-inside-of-setstate"><strong><em>this link</em></strong></a><em>.</em></p><p>Let’s say a customer clicks on white, pink, cotton and girl. The function will search through the state, find the key called color and change the boolean value to true or false depending on the state of state. The process is then repeated for filtering material to cotton and gender with girl.</p><h3>.filteredCollected()</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c791d074d4e6282e6ade1a1ebf144ccb/href">https://medium.com/media/c791d074d4e6282e6ade1a1ebf144ccb/href</a></iframe><p>This function returns collectedTrueKeys by looping through color, gender, material, and category separately and pushing the keys that have values that are true to each array. Since I selected white, pink, cotton, and girl, collectedTrueKeys , it will look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ab429ab64f09b3524697621c63455be/href">https://medium.com/media/7ab429ab64f09b3524697621c63455be/href</a></iframe><h3>.multiPropsFilter()</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1ecae1bf6171062bc503c4d38c75653/href">https://medium.com/media/b1ecae1bf6171062bc503c4d38c75653/href</a></iframe><p>This is a function I found on <a href="https://gist.github.com/jherax/f11d669ba286f21b7a2dcff69621eb72"><strong><em>GitHub</em></strong></a>. The function compares the two arguments, products and filters, and returns the only products that pass through the given filters.</p><p>However, simply copy-pasting the code from the resource was not enough because material is an array that contains multiple materials. Thus, in addition to the code, I added in from line 182 to 186. If one of the keys in the product is an array, it will loop through it again and will return anything that is true.</p><h3>.searchProducts()</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c72c429f089a0ae4adf2b7867f708064/href">https://medium.com/media/c72c429f089a0ae4adf2b7867f708064/href</a></iframe><p>Because customers can search for products by typing, .searchProducts() handles filtering and searching simultaneously.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aea285774c10253f96c4f00c974bf9ce/href">https://medium.com/media/aea285774c10253f96c4f00c974bf9ce/href</a></iframe><p>Then, the child component ProductContainer will receive the already-filtered list of products.</p><h3>Summary</h3><ol><li>Customers will trigger .allFilterClickListener(event, &lt;key name&gt;) when clicking on any filter tags.</li><li>.allFilterClickListener() receives clicked tags and change the right state.</li><li>.filteredCollected() loops through the state and collect any keys with values that are true.</li><li>.multiPropsFilter() takes in all product list and filter to return the filtered product list.</li><li>Because of the child component ProductContainer always call .searchProducts(), both number three and four will be responsive to changes.</li></ol><h3>Conclusion</h3><p>It is just so amazing that I can do anything I want when using Javascript. I will still be able to get the desired outcome even if my material even more nested with arrays. The .filter() challenge for my last project as a bootcamp student helped my thinking process and was a great and enjoying experience that I will always keep with me as I move forward.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5aad8e272142" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/creating-a-multi-filter-function-to-filter-out-multiple-attributes-javascript-react-rails-5aad8e272142">Creating a Multi-Filter Function to Filter Out Multiple Attributes Using Javascript</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use your time more efficiently (Javascript Frontend).]]></title>
            <link>https://medium.com/@stomg7969/use-your-time-more-efficiently-javascript-frontend-8274ba2e75f9?source=rss-2414dbf988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8274ba2e75f9</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nate Park]]></dc:creator>
            <pubDate>Tue, 26 Mar 2019 17:18:36 GMT</pubDate>
            <atom:updated>2019-03-26T17:18:36.627Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*1X_PFtd6K0zVSAeieL-IMQ.gif" /><figcaption>giphy.com ‘efficient’</figcaption></figure><p>When you have to work under time pressure, it would be more productive if there are ways to use time efficiently. As a Flatiron School student, I need to be able to prove if I am ready to learn further materials by testing. Within a given time, students have to meet all the deliverables. It becomes very important to use our time efficiently. We can do that by minimizing unnecessarily wasting time.</p><h3>How I organized mine.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EW6ZzdEYuh93Bzmh_Rb1jQ.png" /></figure><p>If you are programming in Object-Oriented way, you can skip this part.</p><p>After writing multiple lines of codes, you realize that there is an error, you need to go back to previous codes to locate the errors/mistakes. It is hard to remember where all the functions, variables, and/or event listeners are. To prevent using the time to locate the errors/mistakes, we can organize the code by section.</p><ul><li>Global variables section</li><li>Event listeners section</li><li>Functions section</li><li>Fetching functions section.</li></ul><p>By dividing sections, codes become more organized and clear to read. It is also important to test each time complete a function, but this way, even if not, can save some time. In addition to organizing, this Atom text editor package will do a great synergy to my organization.</p><p>A small additional tip* instead of fetching every time, we can store the API to a variable. (How I store API so I don’t fetch again)</p><p>On top, we declare, then after fetching is over, we can assign the response into the declared variable.</p><h3>‘highlight-selected’ package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GcmafYpRWGug2AOOJxRV-w.png" /><figcaption><a href="https://atom.io/packages/highlight-selected">https://atom.io/packages/highlight-selected</a></figcaption></figure><p>This package will highlight all the same words(case sensitivity is optional).</p><p>It is very useful when you are trying to check how many times and where you used a variable or a function. It is also useful when checking spellings. If there is a typo, you can instantly notice it because your typo will not highlight any other words.</p><p>Lastly, it also shows a count at the bottom how many are highlighted. Let’s say that you created a variable, never use it, and forget about it. Later, you come back and are confused about what that variable is. All you need to do it highlight that word and check if you used it. If not, you can delete it with no worries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JvWgpdSEu8bbJSHiR1Wo6w.png" /><figcaption>Can easily understand how, where, and how many the variable is used.</figcaption></figure><h3>4. Chrome console with ‘debugger’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*43PabJdkSlNsq-8sOUx9wg.png" /><figcaption>Chrome is now paused in ‘debugger’(highlighted in Sources tab)</figcaption></figure><p>Lastly, I recommend using the debugger for testing (I also recommend console.log, but with debugger, you can go much deeper and detail) because Chrome’s console is very kind that it gives you many possible options that when you write something, it auto fills in methods for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8iUK7kJ5PfINxh5WuigCrg.png" /></figure><p>When you create an event listener for a button, for instance, there needs to be a checker that you are clicking the right target. Chrome console is very useful that it will show all the options that you can just grab to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pod7Nu5v3aFG36CD3J3vmg.png" /></figure><p>Instead of thinking about how you are going to check if the event listener is pointing to the right target, Chrome will provide you multiple options to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*uboTnjrKSmZ-hyVaGNbK9Q.gif" /><figcaption>giphy.com ‘coding’</figcaption></figure><p>My tips and recommendations will not be able to save you tons of time, but I guarantee that it will make you be more productive and reduce daily stress.</p><p>Happy Code!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8274ba2e75f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s be Test-driven Development (TDD).]]></title>
            <link>https://medium.com/@stomg7969/lets-be-test-driven-development-tdd-a974a5c63919?source=rss-2414dbf988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a974a5c63919</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Nate Park]]></dc:creator>
            <pubDate>Wed, 06 Mar 2019 02:24:32 GMT</pubDate>
            <atom:updated>2019-03-06T02:24:32.045Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*Dzy7LNY7TlltC2h41yvHlw.png" /><figcaption>Resource: <a href="https://madeintandem.com/blog/2015-3-testing-rake-tasks-with-rspec-and-fantaskspec/">https://madeintandem.com/blog/2015-3-testing-rake-tasks-with-rspec-and-fantaskspec/</a></figcaption></figure><p><strong>F</strong>latiron School students learn materials from Learn.co. Through our terminal, we use the commands: ‘learn open’, ‘learn’, and ‘learn submit’. These commands are so useful and students are used to it that many of them likely to mistakenly input the commands on labs that don’t even have tests to run. Personally, sometimes I find myself lost studying because it’s uncomfortable to move along with the labs without any tests.</p><p>The purpose of Flatiron School’s providing those tests is to teach us how to read the failing tests and how important it is to understand them. When developers are programming, the codes, even if they make is very organized, it will be very hard to detect which part of their codes are failing without any written tests. This is why we recommend Test-driven Development (TDD).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*McjngLcHkvn2aDP5rYy5XQ.gif" /><figcaption>GIF file from giphy.com</figcaption></figure><p>Below, I’ve collected some tests from Flatiron School’s labs for module 2 rails project for us. Instead of creating one myself, I decided to collect some useful tests that students can all use.</p><p>Of course, for Ruby on rails, we can check if there are any errors by typingrails s in the terminal, but it will save a lot of time if you have some tests prepared and just type rspec.</p><h3>“rails new &lt;project name&gt; -T”</h3><p>When are creating a new rails project, we use a command rails new &lt;PROJECT NAME&gt;. Before pressing enter, add -T at the end # =&gt; rails new &lt;PROJECT NAME&gt; -T. The reason is because rails uses Test::Unit for testing by default. We want to use RSpec because, why not use something we know how to use and focus more on the project?</p><h3>“rspec-rails” gem</h3><p>Using the RSpec requires gem installation.</p><ul><li>Type in gem &#39;rspec-rails&#39; in your Gemfile.</li><li>Install the gem by bundling bundle install.</li><li>Generate the spec folder for the tests bundle exec rails g rspec:install.</li></ul><p>This will create, <strong>spec/spec_helper.rb</strong> and <strong>spec/rails_helper.rb</strong>.</p><h3>require “rails_helper”</h3><p>When you create your spec file, the first thing you must have on your first line is: require &#39;rails_helper&#39; to connect your new file with spec and rails helpers. Make sure your new spec file’s name ends with &#39;_spec.rb&#39;.</p><h3>Let’s create test!</h3><p>Here are some tests that I found from the Learn.co labs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihSOOAQh4-Ud3oUsXo-jKQ.png" /><figcaption>image from ‘rails-cru-form_for-lab’ lab</figcaption></figure><pre>describe &#39;navigate&#39; do<br>  ...<br>end</pre><p>This helps us understand which part of your code this test is testing, at this example, it is testing if the codes are well written to navigate users to the right path.</p><pre>before do <br>  @genre = Genre.create(name: &quot;My Genre&quot;)<br>end</pre><p>Before beginning the test, this will create a sample Genre class with name “My Genre”. We can create as many variables as possible, for the purpose of testing, too many will make things complex and that is surely not the purpose of “RSpec”.</p><h3>Rendering page status</h3><pre>it &#39;to genre pages&#39; do<br>  visit &quot;/<a href="/service/mailto:genres/#{&lt;a%20href=">@genre</a>.id&quot;&gt;genres/#{<a href="http://twitter.com/genre">@genre</a>.id}&quot;<br>  expect(page.status_code).to eq(200)<br>end</pre><p>This test will check if the route is properly working. We can always use rails s to check if the routes are working, but by just rspec we can check it fast.</p><h3>Page with the right content</h3><pre>it &#39;shows the name on the show page in a h1 tag&#39; do<br>  visit &quot;/<a href="/service/mailto:genres/#{&lt;a%20href=">@genre</a>.id&quot;&gt;genres/#{<a href="http://twitter.com/genre">@genre</a>.id}&quot;<br>  expect(page).to have_css(&quot;h1&quot;, text: &quot;My Genre&quot;)<br>end</pre><p>If there are some contents you must not forget to include, this test will help us reminded.</p><h3>fill_in, click_on, and content</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*874h5Od-JIglHSVur7DWtg.png" /><figcaption>image from ‘rails-cru-form_for-lab’ lab</figcaption></figure><pre>it &#39;shows a new form that ... and prints out params&#39; do<br>  visit new_song_path</pre><pre>  fill_in &#39;song[name]&#39;, with: &quot;My song name&quot;<br>  fill_in &#39;song[artist_id]&#39;, with: <a href="http://twitter.com/artist">@artist</a>.id<br>  fill_in &#39;song[genre_id]&#39;, with: <a href="http://twitter.com/genre">@genre</a>.id</pre><pre>  click_on &quot;Create Song&quot;</pre><pre>  expect(page).to have_content(&quot;My song name&quot;)<br>end</pre><p>fill_in will fill in with whatever is given. In order for this to work, you will need before do ... end and create and store@artist and @genre variables with objects first.</p><p>We can also check if the code updates or destroys properly and more.</p><p>The provided above are one of the basic tests that we can write easily. There are more good tests will can refer to in other labs such as, crud-with-validations (<a href="https://github.com/learn-co-students/crud-with-validations-lab-nyc-web-career-012819">crud-with-validations-lab</a>). You will be able to find enough tests to use.</p><h3>Test to have the right link path</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QbeZHuSomlEbOrHyTb0oxQ.png" /><figcaption><a href="https://github.com/stomg7969/has-many-through-forms-rails-labs-nyc-web-career-012819">has-many-through-forms-rails-labs</a></figcaption></figure><pre>describe &#39;show page&#39; do</pre><pre>it &#39;should link to all of the posts the user commented on&#39; do<br>      visit user_path(<a href="http://twitter.com/user">@user</a>)<br>      expect(page).to have_link(<a href="http://twitter.com/post">@post</a>.title, href: post_path(<a href="http://twitter.com/post">@post</a>))<br>    end<br>  end</pre><p>We can have our spec to check if the page to have the right link(href).</p><h3>Validation test</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e0gqUfIW_jNbkUJGr4k1ww.png" /><figcaption><a href="https://github.com/stomg7969/has-many-through-forms-rails-labs-nyc-web-career-012819">has-many-through-forms-rails-labs</a></figcaption></figure><p>These tests can see if our validations on model tables are working properly.</p><pre>RSpec.describe Song, type: :model do<br>  let(:valid_attributes) do<br>    {<br>      title: &quot;Talisman&quot;,<br>      artist_name: &quot;Air&quot;,<br>      release_year: 2007,<br>      released: true,<br>      genre: &quot;Post-Rock&quot;<br>    }<br>  end</pre><pre>let(:missing_title) { valid_attributes.except(:title) }<br>let(:missing_release_year) { valid_attributes.except(:release_year) }<br>let(:unreleased) { missing_release_year.merge(released: false) }<br>let(:future_release_year) { valid_attributes.merge(release_year: Date.today.year + 1) }</pre><pre>it &quot;is valid when expected&quot; do<br>    expect(Song.new(valid_attributes)).to be_valid<br>  end</pre><pre>it &quot;is invalid without title&quot; do<br>    expect(Song.new(missing_title)).to be_invalid<br>  end</pre><pre>it &quot;is invalid without release year when released is true&quot; do<br>    expect(Song.new(missing_release_year)).to be_invalid<br>  end</pre><pre>it &quot;is valid without release year when released is false&quot; do<br>    expect(Song.new(unreleased)).to be_valid<br>  end<br>end</pre><h3>And more…</h3><p>There are many more tests you can use especially from <strong>CRUD with validations lab</strong> in <a href="http://learn.co/">Learn.co</a>. This lab has a variety of tests.</p><h3><strong>Conclusion</strong>:</h3><p>The purpose of this blog is to share what we already have and for convenience.</p><p>It is important that you understand how to write tests on your own. However, having MVP for your project is essential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*SNnnAN5EYWZuIynw0pRP8g.gif" /><figcaption>giphy.com</figcaption></figure><h3>Summary:</h3><ol><li>rails new &lt;PROJECT NAME&gt; -T in your terminal</li><li>gem &#39;rspec-rails&#39; in your Gemfile. (For some tests, you need ‘capybara’ gem, but rails new command will bundles it for us.</li><li>bundle install &amp;&amp; bundel exec rails g rspec:installin your terminal</li><li>Make sure your new spec file’s name ends with &#39;_spec.rb&#39;.</li><li>require &#39;rails_helper&#39; in your new spec file.</li><li>Paste or create your tests!</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a974a5c63919" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your own ‘Leet’ with Ruby(entry level)]]></title>
            <link>https://medium.com/@stomg7969/make-your-own-leet-with-ruby-entry-level-39894b579c87?source=rss-2414dbf988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/39894b579c87</guid>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[ascii]]></category>
            <category><![CDATA[hash]]></category>
            <category><![CDATA[array-methods]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nate Park]]></dc:creator>
            <pubDate>Thu, 14 Feb 2019 03:51:04 GMT</pubDate>
            <atom:updated>2019-02-14T03:51:04.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZrSvUrS-6zQQBfevGed2w.gif" /><figcaption>gif from giphy.com</figcaption></figure><blockquote>“97 108 114 105 103 104 116 121 010 116 104 101 110”</blockquote><p>You may wonder what this quote means.</p><p>While studying and preparing for a bootcamp, I learned how to change a regular word (“abcd”) to a leet (“$%ph#”). I would like to share my little work with any beginners who might be interested in learning and use it somewhere for fun or talk to friends with a language no one else can understand.</p><p>This exercise also can be a good looping hash and array exercise for fellow beginners that are having a hard time understanding. When I learned this exercise back then, I was only able to handle a word at a time, instead, I wrote codes that also can handle a sentence. Note that ‘leet-translating’ can be complicated indefinitely. Meaning, mine only handles alphabets and limited <a href="http://www.asciichart.com/">ASCII decimals</a>. My code will not be able to understand anything else except the variables I provided.</p><h3>What is “Leet”?</h3><p>‘<strong>Leet</strong>’, or 1337, is an informal language or code used on the Internet, in which standard letters are often replaced by numerals or special characters that resemble the letters in appearance.</p><p>and…</p><ul><li>skilled at computer programming</li><li>extremely good; excellent</li></ul><p>— <a href="https://www.google.com/search?q=leet&amp;oq=leet&amp;aqs=chrome.0.69i59l2j69i61j69i59j69i60l2.503j0j1&amp;sourceid=chrome&amp;ie=UTF-8">Google Dictionary</a></p><blockquote>“Alex is leet.” — web012819</blockquote><h3>Variables (1/3)</h3><pre>@eng_letters = (&#39;a&#39;..&#39;z&#39;).to_a # =&gt; [&#39;a&#39;..&#39;z&#39;]</pre><pre>@leet_letters = (&#39;b&#39;..&#39;z&#39;).to_a + [&#39;a&#39;] # =&gt; [&#39;b&#39;..&#39;z&#39;] + [&#39;a&#39;]</pre><pre>def ascii_decimal<br>  @eng_letters.collect { |lett| lett.downcase.ord  }<br>end<br># =&gt; [97..122]</pre><p>These are my three variables stored using an array. ‘@eng_letters’ variable is an array from English letter ‘a’ to ‘z’ and ‘@leet_letters’ is an array from English letter from ‘b’ to ‘z’ plus ‘a’. by adding ‘a’ behind (‘b’..’z’), ‘@leet_letters’ becomes an array from (‘b’ … ‘x’ ‘y’ ‘z’, then ‘a’). I used ‘@’ to make global variables so they can be used inside any methods.</p><p>Next is a method called, ‘ascii_decimal’, that returns an array of numbers collected from the English letters using ‘.ord’. Using this array created by ‘ascii_decimal’ method, I can either turn some numbers into words or the opposite.</p><h3>Dictionary (2/3)</h3><pre>def eng_ord_dictionary<br>  eng_to_ord = {}<br>  i = 0<br>  while i &lt; <a href="http://twitter.com/eng_letters">@eng_letters</a>.count<br>    eng_to_ord[<a href="http://twitter.com/eng_letters">@eng_letters</a>[i]] = ascii_decimal[i]<br>    i += 1<br>  end<br>  eng_to_ord<br>end</pre><pre># =&gt; returns hash: eng(keys), ascii(values)</pre><p>This method is my English-to-leet dictionary. I used the term ‘dictionary’ because I am going to need this method (or dictionary) to translate my sentence to another “language”.</p><p>I used ‘while loop’ to assign ‘i’s as indexes for all the variables. For this particular example, I assigned the English letters as <strong>keys</strong> of the hash called, ‘eng_to_leet’, and leet letters as <strong>values</strong> of the hash.</p><p>As a result, the ‘eng_to_leet’ hash would look something like this.</p><pre>eng_to_leet = {&#39;a&#39; =&gt; 97, &#39;b&#39; =&gt; 98, &#39;c&#39; =&gt; 99 ... &#39;z&#39; =&gt; 122};</pre><pre># So when I translate &quot;hello&quot;, it becomes, &quot;104 101 108 108 111&quot;.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*o8u2K3cuSCXeGq637kQjvw.gif" /><figcaption>gif from giphy.com</figcaption></figure><h3>Translator (3/3)</h3><blockquote>“Hello World”</blockquote><pre>def eng_ord_translator(eng_string) # space =&gt; &#39;010&#39;<br>  eng_string.split(&#39;&#39;).map { |lett| lett == &#39; &#39; ? lett = &#39;010&#39; : eng_ord_dictionary[lett.downcase] }.join(&#39; &#39;)<br>end</pre><p>Just like Flatiron School’s way, I will break this down and set ‘eng_string’ as ‘hello world’.</p><pre>def eng_ord_translator(&#39;hello world&#39;)</pre><p>I put ‘hello’ string as an argument to ‘eng_ord_translator’ method.</p><pre>&#39;hello world&#39;.split(&#39;&#39;).map { |lett| <br>lett == &#39; &#39; ? lett = &#39;010&#39; : eng_ord_dictionary[lett.downcase] <br>}.join(&#39; &#39;)<br>end</pre><ul><li>Using .split(‘’) without space, it will break ‘hello’ to `[‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘ ‘, ‘w’, ‘o’, ‘r’, ‘l’, ‘d’]`.</li><li>Loop through this array using .map, which will give us a new array of numbers.</li><li>‘A ? X: Y’ format: If A is true, return X or if A is false, return Y.<br>Since I need to handle sentences as an argument, I decided to assign &lt;space&gt; as a number, 010. <br>So to translate this format, “while looping through the string, if there is a space, it will return 010, otherwise, return numbers according to the eng_ord_dictionary”.</li><li>Using .join(‘ ‘) with one space, I will return my translated language back to string from array.</li></ul><p>As a result, the string ‘hello world’ will become:</p><p>“104 101 108 108 111 010 119 111 114 108 100”.</p><h3>Conclusion</h3><p><a href="https://github.com/stomg7969/eng-number-leet-translator">Here is a link to my Github</a>. You can run it on your terminal.</p><p>When I was having trouble understanding Array and Hash, this exercise helped me so much. As my coding skill grows, I will add more complicated codes to it.</p><p>So what does “97 108 114 105 103 104 116 121 010 116 104 101 110” mean at the top?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*HYM3fkAIk5WBL6JB2qt0Kw.gif" /><figcaption>My favorite gif from giphy.com</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39894b579c87" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>