<?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 Anh on Medium]]></title>
        <description><![CDATA[Stories by Anh on Medium]]></description>
        <link>https://medium.com/@vuonganht?source=rss-2cc0dd21bc13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bnt80vMiotlrUCFEWNtApQ.png</url>
            <title>Stories by Anh on Medium</title>
            <link>https://medium.com/@vuonganht?source=rss-2cc0dd21bc13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 01:23:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vuonganht/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[Surviving your first developer role: some practical tips]]></title>
            <link>https://levelup.gitconnected.com/surviving-your-first-developer-role-some-practical-tips-986497f5d3bb?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/986497f5d3bb</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Thu, 02 Dec 2021 06:05:33 GMT</pubDate>
            <atom:updated>2021-12-22T00:33:11.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CkEGpA8NCM-4SUG1" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason?utm_source=medium&amp;utm_medium=referral">Jason Leung</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Congratulations! You’ve just landed your first role as a software developer. Ah, the hours of Leetcode toiling, the pile of rejection emails, the nerve-wracking interviews — they have <em>finally paid off!</em></p><p>If you’re anything like me just a year ago, landing that first role feels like the darndest validation of your skills, hard work, and tenacity. But with that shining validation comes a lot of uncertainty-induced fear. I mean, gosh, someone actually deemed you good enough to start giving you money to do this! How do you try to <em>not</em> screw up?</p><p>Lately, I’ve been thinking about where I was last year (and where you might be now, dear reader). And I thought about how if I could give my past self some guidance, what would that guidance look like? So this blog post is the product of that. I hope it’s of some use.</p><h3>Tip #0: Be a sponge — Soak it all up: Write it all down</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HovZayP_vQq5Kfih" /><figcaption>Photo by <a href="https://unsplash.com/@glenncarstenspeters?utm_source=medium&amp;utm_medium=referral">Glenn Carstens-Peters</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>My personal belief, perhaps thanks to my poor memory, is that you ought to write everything down rather than trusting your brain entirely.</p><p>Is the senior dev you’re working with giving you a rundown of the codebase or of some process? Jot down what they’re telling you. Is this your first ticket and you don’t quite know the solution? Document the process it takes you to get there. Are you having a team meeting? Scribble down main ideas discussed. And better yet, notice points of discussion that you <em>don’t</em> yet know — write them down, look them up, write them down again.</p><p>The ultimate goal in being a sponge in this way, is to make your future self’s life as easy as possible. In doing so, you won’t ever have to ask the same question twice, and overtime, <em>you</em> become your own go-to resource.</p><p>Below is an example of the digital pages where I keep my notes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*2MVkzRudCJxKsRvO34qlSg.png" /></figure><p>I’m a big fan of <a href="https://www.notion.so/">Notion</a> (and will rave about it any chance I get), especially because it’s quite easy to use and gives you the ability to do some awesome things. For example, you can generate pages within pages, create tables, format code, and make reusable templates.</p><p>Here is an example of how I organize my sprint notes on Notion:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*Mwu_L1hIulExvCMy3ClN8w.png" /></figure><p>I move pages around in different sections as needed, and have ready-made templates to serve my current work stream. Epic pages are for longer work streams (an epic, like building out a new feature for example, encompasses multiple tasks). And since not all work assigned to me will be part of an epic, I also keep separate a task template page. Here is how my task page looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*5yDGlHngkDFSY7wnbrvk2g.png" /></figure><p>The task page keeps me organized to the degree of the current task branch I am working on. Of course, not all tasks will require extensive note-taking to this degree, but I still find it helpful to have a page as such to organize my thoughts while I find my way to a solution. The Pre-PR Submission checklist is a self-reminder to review my own work before submitting it for review (ever since I read <a href="http://atulgawande.com/book/the-checklist-manifesto/">The Checklist Manifesto</a> by Atul Gawande, I came to really appreciate the simple-yet-extremely-effective method that is the checklist; I highly recommend that book).</p><p>And this is what my Epic note template looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*UG5mmgaVMeVVbeNtdifi7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*lZ0MsaUgIz3jIzU4cvh2Bg.png" /></figure><p>At first glance, these pages may seem excessive. But they work very well for me as I use them to keep organized. Over time, I came to trust the notes on these pages more than I do the scrambled fleeting thoughts in my head. There had been more than one time where I’d come across something that vaguely rings a bell and that I know I should know. All I would have to do is click-clack a few keys on my board and then trace my steps back to arrive at the note I took explaining that very thing. Your note-taking method may not look exactly the same as mine, but I highly recommend creating one and using it consistently. It will pay off.</p><h3>Tip #1: Git familiar</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JtXK1mRg5yJYQAw9" /><figcaption>Photo by <a href="https://unsplash.com/@yancymin?utm_source=medium&amp;utm_medium=referral">Yancy Min</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Okay, so the thing is, you’re going to be contributing to an <em>enterprise-level</em> code base now. Gone are the days where you have the flexibility of committing directly into the master branch of your personal project repo with a silly message like &quot;changed a thing&quot;. Nope, you&#39;re going to be working with different branches, like develop, maybe a staging branch, most definitely a task branch. So it is not an understatement to say that you need to know very well the basics of git. You should also have some knowledge in terms of the <a href="https://dev.to/flippedcoding/difference-between-development-stage-and-production-d0p">differences between different development environments</a>.</p><p>Going back to git though, you should already know the following commands like the back of your hand: git add, git commit, git push, git fetch, git merge, git pull. Know how to write good commit messages. Additionally, I&#39;d recommend also familiarizing yourself with git commit --amend -m and git commit --amend --no-edit. The first combines your current commit with the previous commit with a new message. The second is the same as the first except you&#39;d keep the previous commit&#39;s message. These can help you bundle your commits more concisely so that you don&#39;t end up with 100 commits staling your pull request.</p><h3>Tip #2: Know organizational processes and roles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YsLZOX7bHkIqO3EM" /><figcaption>Photo by <a href="https://unsplash.com/@jasongoodman_youxventures?utm_source=medium&amp;utm_medium=referral">Jason Goodman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You should know broadly what the <a href="https://www.atlassian.com/agile">agile method</a> is and understand the different parts of a <a href="https://www.atlassian.com/agile/scrum/sprints">scrum sprint</a> and how they work. For example, what happens in sprint planning? What is a retro? What’s a backlog? What is point estimation?</p><p>Along the same note, get acquainted to the roles of other folks who may be on your team. Here are some common people you might directly work with:</p><ul><li>Product manager / product owner</li><li>UI/UX designer</li><li>QA engineer</li><li>Dev ops engineer</li><li>Business analyst</li></ul><p>Again, I’ll leave you to research these yourself.</p><h3>Tip #3: Know how to learn from existing code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ht9Jz3EKjdQlMuH5" /><figcaption>Photo by <a href="https://unsplash.com/@florianolv?utm_source=medium&amp;utm_medium=referral">Florian Olivo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of my major concerns when starting out is the enormity of a company’s code base, where just a glimpse can leave you feeling lost and nauseated. On this, the best advice I’ve gotten is from <a href="https://www.youtube.com/c/RealToughCandy">RealToughCandy</a>. She said that you ought to read code <em>line by line</em> (heck, even word-by-word if you need to). And with each line, you should deconstruct in human terms what the code is trying to do. The entire forest may <em>seem</em> overwhelming, but zoom in and you’ll find that you do have the ability to look closely at a tree, count its branches, and see where it takes root. Begin there!</p><p>Also, make use of PR-reviews. As a junior in the early stages, reviewing other people’s work isn’t necessarily about adding your input, because you simply might not be there yet. But still make use of PRs, for they are a huge learning opportunity! With each PR I review early on, I try to understand what it is doing and make notes of what I learned. Even if I don’t understand <em>everything</em> that’s going on in a hefty PR, I’d still pick out a thing or two that I’ve learned, and save the PR as an example to come back to if needed. Below is an example of what I’d jot down after reviewing a PR:</p><blockquote>Link to PR: http://www…<br>What I learned: how to set up routes, how to read from query search params</blockquote><p>Another important related tip is that when you’re assigned something, <em>do not try to do it from scratch!</em> Look for similar examples in the code base, have patience, and read through how a similar feature was previously done. As above, break down the code line-by-line and go through it until you understand it. Make notes along the way and then define a route with which you can take to tackle the work. Only then should you start coding. While this sounds extensive, trust me, learning from previous implementations will ultimately save you a lot of time. You’ll also find that you’re going to pick up useful coding conventions and learn commonly-used patterns along the way.</p><h3>Tip #4: Seek guidance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MiWTRLnP5sD0I7CH" /><figcaption>Photo by <a href="https://unsplash.com/@jasongoodman_youxventures?utm_source=medium&amp;utm_medium=referral">Jason Goodman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The first thing in seeking guidance is knowing <em>how</em> to seek help within your own team. Here is a useful template of how you can ask someone for help on a task after having attempted it yourself for a reasonable time:</p><blockquote><em>Hey </em>&lt;helper’s name&gt;<em>, I’m working on </em>&lt;task&gt;<em>. I’m currently trying to </em>&lt;description of the thing you’re stuck on&gt;<em>. I tried </em>&lt;a potential solution you tried&gt;<em> because </em>&lt;reasoning for trying this solution&gt;<em>. I also tried </em>&lt;another potential solution you tried&gt;<em> to see if </em>&lt;reasoning for trying this solution&gt;<em>, but these didn’t seem to resolve the issue. Do you have any pointers?</em></blockquote><p>If you’re asking for help through Teams or Slack and trying to explain something confusing, bonus point to you if you add a screenshot, or better yet, a screen recording of the issue. The goal is to be respectful of your helper’s time — to help them help you in the most efficient way possible.</p><p>Additionally, you can seek guidance in courses. Does the organization use GraphQL and you’ve only had minimal exposure to the technology? Don’t wait until someone holds your hand and guide you through it! Go and find resources to learn the material yourself. As developers, we know that all it takes nowadays to find resources is a simple Google search.</p><p>Other guidance-related tips (note that examples are a little biased towards frontend, since I’m a frontend dev):</p><ul><li>Subscribe to tech newsletters and read them. Some of my favorites: <a href="https://frontendweekly.co/">Frontend Weekly,</a> <a href="https://frontendfoc.us/">Frontend Focus</a>, <a href="https://reactnewsletter.com/">React Newsletter</a>, <a href="https://programmingdigest.net/">Programming Digest</a>.</li><li>Subscribe to tech podcasts and listen to them. Some of my favorites: <a href="https://www.podbean.com/podcast-detail/m55ng-68d22/React-Round-Up-Podcast//DirEpisode_page/3/page/10">React Round Up</a>, <a href="https://www.frontendhappyhour.com/">Frontend Happy Hour</a>, <a href="https://www.podbean.com/podcast-detail/s3cre-33acb/Developer-Tea-Podcast">Developer Tea.</a></li><li>Read books! Some of my recommendations: <a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a> and <a href="https://www.amazon.com/Clean-Coder-Conduct-Professional-Programmers/dp/0137081073/ref=pd_lpo_2?pd_rd_i=0137081073&amp;psc=1">The Clean Coder</a> by Robert Martin (I also enjoyed this <a href="https://www.youtube.com/watch?v=7EmboKQH8lM">related lecture series</a>), <a href="https://www.amazon.com/You-Dont-Know-JS-Yet-ebook/dp/B084BNMN7T">You Don’t know JS Yet</a> by Kyle Simpson, <a href="https://atomicdesign.bradfrost.com/">Atomic Design</a> by Brad Frost.</li></ul><p>You can also seek mentorship. I’m in a fortunate situation where I’m able to receive mentorship from a senior engineer on my team. I touch base with her often about my technical and soft skills, where I am in my career, and my goals for the future. But just because you don’t have a designated human being to serve as your mentor, doesn’t mean that you are without guidance — just look for resources! Let those who have been there guide you — no matter if the format is of a Youtube video, a blog post, or a book. There are also multiple dev communities in which you can seek mentors or peer mentors. Here are some I recommend: <a href="https://www.linkedin.com/company/nyc-coders/">NYC Coders</a>, <a href="https://www.linkedin.com/company/yearonecareers/">Year One</a>, and <a href="https://www.linkedin.com/company/femmecubator/">Femmecubator</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/0*mBN8Uikjd1HgKyZW.png" /></figure><p>Alas, keep calm and carry on coding! Stick to the methods that work for you, know how to seek guidance, and remember to slow down and breathe sometimes. It’s a marathon, and you’re only at the beginning of the race!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=986497f5d3bb" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/surviving-your-first-developer-role-some-practical-tips-986497f5d3bb">Surviving your first developer role: some practical tips</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Rails/React App]]></title>
            <link>https://medium.com/swlh/deploying-a-rails-react-app-ca2036dc4170?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca2036dc4170</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Mon, 21 Dec 2020 01:02:48 GMT</pubDate>
            <atom:updated>2020-12-21T05:20:56.537Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings fellow beginner Rails/React dev’s! In this short tutorial, I will be retracing and sharing with you my process of deploying a web application that utilizes a React frontend coupled with a Rails backend. I deployed my backend on Heroku, and frontend on Netlify. Before we start, please ensure that your frontend and backend are stored in separate repos. All good? Let’s begin!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcOqbYAuAC5mdpjMMvPQ3A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@weirick?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jake Weirick</a> on <a href="https://unsplash.com/s/photos/train-track?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Deploying a React Frontend to Netlify</h3><ol><li>In the script section of your package.json, in &quot;build&quot;, add “react-scripts build &amp;&amp; echo ‘/* /index.html 200’ &gt; ./build/_redirects”. This script ensures that if you had chose to use something for routing (for example, React Router), the app will serve index.html instead of giving a 404 error, no matter what route you might be accessing the app from. To read more on this, please visit the <a href="https://docs.netlify.com/routing/redirects/">Netlify documentation</a>.</li></ol><pre>...<br>&quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;react-scripts start&quot;,<br>    &quot;build&quot;: &quot;react-scripts build &amp;&amp; echo &#39;/* /index.html 200&#39; &gt; ./build/_redirects&quot;,<br>...</pre><p>2. Create a <a href="https://www.netlify.com/">Netlify account</a>.</p><p>3. Under the Sites section, click “New site from Git”.</p><p>4. Select “Github”.</p><p>5. Select your project.</p><p>6. Select a branch of your project to deploy.</p><p>7. Set up environment variables to be available in Netlify. To do so, click “Site setting”, on the side bar, click “Build &amp; deploy”, click “Environment”, then input variables according to what you have stored in your local .env file. This could be various sensitive API keys, for example. Next, add key CI and set the value to false as one of the environment variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzIP720Fv1a9cvlYFPsTEA.png" /></figure><p>8. Go to “Deploys”, click “Trigger deploy”, and select “Clear cache and deploy site”.</p><p>Congratulations! You should now be able to access your frontend via the link Netlify has provided.</p><h3>Deploying a Rails Backend to Heroku</h3><p>This tutorial assumes that your database runs on PostgreSQL; if you have used SQLite3, which Heroku no longer supports, please follow steps in this <a href="https://flatironschool.com/blog/deploying-a-sqlite3-database-to-heroku-for">Flatiron School’s tutorial</a>.</p><ol><li>Create a <a href="https://www.heroku.com/">Heroku account</a>.</li><li>Install <a href="https://devcenter.heroku.com/articles/heroku-cli">Heroku CLI</a> and login through your terminal by running heroku login.</li><li>Specify origins in config/application.rb</li></ol><pre>config.middleware.insert_before 0, Rack::Cors do<br>  allow do<br>    origins &#39;<a href="http://localhost:3000&#39;">http://localhost:3000&#39;</a>, &#39;<a href="https://desolate-waters-78828.herokuapp.com&/#39;">&lt;URL of frontend/client app&gt;&#39;</a> <br>    resource &#39;*&#39;, :headers =&gt; :any, :methods =&gt; [:get]<br>  end<br>end</pre><p>3. Commit your changes to Github.</p><p>4. In the terminal, run heroku create &lt;name of api&gt;.</p><p>5. Run git push heroku &lt;name-of-branch-to-be-deployed&gt;:master.</p><p>6. Log into Heroku on the web, go to “Settings”, in “Config Vars”, add any local sensitive vars (API keys, for example).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STV52medrHgBij7ZGAcxGg.png" /></figure><p>7. In your terminal, run heroku run rails db:create, heroku run rails db:migrate, heroku run rails db:seed. This creates the database, completes migration, and seeds your data on the Heroku server.</p><p>8. Lastly, go to your frontend code base, for requests made to the backend, ensure that you specify the URL to be your newly deployed API on Heroku. Follow step 8 in the previous section to re-deploy your app after this change.</p><p>And that’s it! Congratulations on the deployment of your full stack application!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca2036dc4170" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/deploying-a-rails-react-app-ca2036dc4170">Deploying a Rails/React App</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[Creating a Simple Countdown Timer Using React useRef Hook]]></title>
            <link>https://medium.com/swlh/creating-a-simple-countdown-timer-using-react-useref-hook-92ae5b6210cb?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/92ae5b6210cb</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javscript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Fri, 11 Dec 2020 21:26:52 GMT</pubDate>
            <atom:updated>2021-10-07T21:33:58.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N_AC9kpN67apkPIb" /><figcaption>Photo by <a href="https://unsplash.com/@goumbik?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Lukas Blazek</a> on <a href="https://unsplash.com/s/photos/countdown?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In React, <a href="https://reactjs.org/docs/hooks-reference.html#useref">useRef</a> is a hook that…</p><blockquote>returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component. (<a href="https://reactjs.org/docs/hooks-reference.html#useref">Source</a>)</blockquote><p>It is normally used to reference underlying DOM elements, an input field for example. However, you can also use it to store reference to any variable. In this way, it may seem no different than useState, but what distinguishes it from useState is that when we update a useRef reference, it does not cause the component to re-render. Simply put, you use it to keep track of a variable, but this variable does not directly impact what is displayed on the DOM (and therefore re-rendering of the component is unnecessary).</p><p>As defined by React above, useRef gives you an object with the .current property. Below is a simple example of how it is used:</p><pre>let count = useRef(1);</pre><p>To later retrieve the value of 1, we can call something like: console.log(count.current).</p><p>To better demonstrate a practical use of useRef, let’s create a simple countdown timer. Our goal is to have a countdown timer that will automatically start counting down from 100 when the page loads. We’ll also have a button that allows for the pausing and resuming of the timer. Let’s get to it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*BM8WoLsS4b5V0HrazlKeJw.gif" /><figcaption>Countdown Timer</figcaption></figure><h3>0. Set Up An App Skeleton</h3><p>We’ll bootstrap our simple app using create-react-app. In the terminal, run: npx create-react-app countdown-timer. Wait for dependencies to be installed, then cd into the created directory.</p><p>We’ll then create a directory within src called components, and create a file called Countdown.js. We will then import Countdown.js into App.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aed1219d963de3593bbef3dcbadeac41/href">https://medium.com/media/aed1219d963de3593bbef3dcbadeac41/href</a></iframe><p>In the Countdown.js file, we will import useRef, useState, and useEffect from React. We’ll also set up the functional component skeleton like the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17c31661c99164b1e8e6e327cfe7784d/href">https://medium.com/media/17c31661c99164b1e8e6e327cfe7784d/href</a></iframe><h3>1. Set Up States and Ref</h3><p>Next, we’ll use useState to initialize the num state to 100 since we’ll start our countdown from 100. We’ll have a pause state initialized to false:</p><pre>const [num, setNum] = useState(100);<br>const [pause, setPause] = useState(false);</pre><p>We will also create an intervalRef, which we will later use to store a reference to our interval.</p><pre>let intervalRef = useRef();</pre><p>We would need a way to refer to the interval because we will have to clear it in several different places in our code. For a quick refresher on setInterval and clearInterval, both window methods which we will use, click <a href="https://stackoverflow.com/questions/5978519/how-to-use-setinterval-and-clearinterval">here</a>.</p><p>We will also add the following to our return statement of the component to display our number, followed by a button that will display either “Run” or “Pause” depending on the value of our pause state:</p><pre>return (<br>    &lt;div&gt;<br>      &lt;div&gt;{num}&lt;/div&gt;<br>      &lt;button&gt;{pause ? &quot;Run&quot; : &quot;Pause&quot;}&lt;/button&gt;<br>    &lt;/div&gt;<br>  );</pre><p>So far we have:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a60a01042b0c1c2522df0552b736a3f7/href">https://medium.com/media/a60a01042b0c1c2522df0552b736a3f7/href</a></iframe><h3>2. Set Up useEffect</h3><p>Next, we’ll add the following to our component:</p><pre>const decreaseNum = () =&gt; setNum((prev) =&gt; prev - 1);</pre><pre>useEffect(() =&gt; {<br>    intervalRef.current = setInterval(decreaseNum, 1000);<br>    return () =&gt; clearInterval(intervalRef.current);<br>  }, []);</pre><p>Relying on the useEffect hook, when we are telling React to do the following when the component mounts:</p><ul><li>use setInterval() to start an interval that will run decreaseNum function every 1000 ms or 1 second. decreaseNum simply updates the num state to 1 less than the previous value</li><li>store the reference to the interval we just set in intervalRef.current</li></ul><p>The function that follows the return statement in useEffect can be used to run whatever cleanup activity needed when the component un-mounts. So here, we specified that we want the interval to clear or stop running, passing in intervalRef.current. Finally, the array that is the second argument to that useEffect stores any dependencies that exist in useEffect that should cause useEffect to run again. In our case, we have none, so using an empty array here will simply have useEffect run once when the component mounts.</p><p>Our code so far:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c08c4bef879f602d99e412342a9ae413/href">https://medium.com/media/c08c4bef879f602d99e412342a9ae413/href</a></iframe><h3>3. Handle Button Click</h3><p>Next, we’ll write a function to handle the button click, add the following event listener to the button element: onClick={handleClick}. Then we’ll write our handleClick function:</p><pre>const handleClick = () =&gt; {<br>    if (!pause) {<br>      clearInterval(intervalRef.current);<br>    } else {<br>      intervalRef.current = setInterval(decreaseNum, 1000);<br>    }<br>    setPause((prev) =&gt; !prev);<br>  };</pre><p>Here, we specify that if currently, pause is false (meaning that our timer is currently running), we should clear the interval. Again, we have access to the interval reference that we previously assigned a value to in the useEffect hook, and we can pass in that reference to clearInterval. Otherwise if the timer is paused, we should start the interval again. Here we also update intervalRef.current to the new interval started. Finally, we toggle the state of pause.</p><p>What the whole component looks like in code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e792cd30c5b36152a634220811ce65e/href">https://medium.com/media/7e792cd30c5b36152a634220811ce65e/href</a></iframe><p>And the finished product:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*BM8WoLsS4b5V0HrazlKeJw.gif" /><figcaption>Countdown Timer</figcaption></figure><h3>Conclusion</h3><p>Hope this brief tutorial demonstrates the usefulness of useRef. For additional information on this hook, check out the official <a href="https://reactjs.org/docs/hooks-reference.html#useref">React documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92ae5b6210cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/creating-a-simple-countdown-timer-using-react-useref-hook-92ae5b6210cb">Creating a Simple Countdown Timer Using React useRef Hook</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[Explain Like I’m 5: Async Javascript]]></title>
            <link>https://medium.com/swlh/explain-like-im-5-async-javascript-807d462b0e14?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/807d462b0e14</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Sat, 05 Dec 2020 17:05:39 GMT</pubDate>
            <atom:updated>2020-12-06T17:52:46.846Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipDs7WrCxHzI4g_BtCUL8g.jpeg" /><figcaption>Michael Browning — Unsplash</figcaption></figure><p>When two or more events are described as “asynchronous,” it refers to them not existing or happening at the same time. If you have ever worked in the service industry, then you probably know well how to manage your tasks asynchronously. For instance, if you were a waiter in a restaurant, once you entered an order on behalf of a customer, you don’t simply stop all you need to do to wait around for the chef to make the food. Rather, you let the “food-making” task run in the background, work on other tasks, then retrieve the food when it’s ready.</p><p>Why is this behavior useful in programming? Well, say you are creating a web application, at some point you’d need to send a request to a server in order to retrieve data. When this request/response process is happening, there might be other functionalities that are present on your app that you would not want disrupted. If asynchronicity did not exist, each time a request is made, no other part of the code is permitted to run, and we are forced to wait for the response to come back before doing any other work. In short, asynchronous Javascript (AJAX) allows for time-consuming tasks to take place in the background without disrupting the remaining functionalities of an app.</p><p>Let’s take some time to dive into the topic of synchronous vs. asynchronous JS in simple terms, continuing on with our restaurant analogy. We’ll first back track and talk about the synchronous nature of JS.</p><h3>Synchronous</h3><p>Javascript is described as <em>“single-threaded”</em>, meaning that by default, the instructions that you write in code is executed in one single sequence. One line of code is read and executed at one time. This is akin to the behavior of an extremely inefficient and naive waiter: First he will take the customer’s order, get the food, and then serve the food, in that exact sequence. In code:</p><pre>function getFood() {<br>  console.log(&quot;Go to kitchen&quot;)<br>  console.log(&quot;Pick up food&quot;);<br>}</pre><pre>console.log(&quot;Take customer&#39;s order...&quot;);<br>getFood();<br>console.log(&quot;Serve food!&quot;);</pre><p>The above will output:</p><pre>Take customer&#39;s order...<br>Go to kitchen<br>Pick up food<br>Serve food!</pre><p>The nitty gritty of this involves the <a href="https://developer.mozilla.org/en-US/docs/Glossary/Call_stack#:~:text=A%20call%20stack%20is%20a,from%20within%20that%20function%2C%20etc.">callstack</a>. Think of this as a sort of special checklist that our waiter uses to keep track of each thing he must do. In this special checklist however, for each item he writes, he must completes and crosses it out before moving on to another. A callstack keeps track of code in a similar way depending on the sequence of which functions are called. In the example above, console.log(“Take customer’s order…”) is called first. It is therefore executed first. Then getFood(), then console.log(“Serve food!”).</p><p>Within getFood(), two additional console.log()’s are called. You can think of these as subtasks within a task that must get done; these subtasks are written on the checklist one at a time, and must be completed/crossed off before the main task is considered completed and can be crossed off. On our callstack then, getFood() is called, then console.log(&quot;Go to kitchen&quot;) is called, executed, and popped off the stack, and then the same would happen with console.log(“Get the food”). Then, since all “subtasks” within the main task of getFood() are now completed, getFood() can be removed from the stack.</p><p>So then, what about async?</p><h3>Asynchronous</h3><p>As described, async allows for the performance of tasks in the background at the same time that other tasks in the foreground are running. Using our analogy, it is akin to the behavior of a seasoned, experienced waiter, who knows that while he is waiting for a food order to be ready, he could do other things! Let’s take a look at this scenario using code. We’ll make use of Window <a href="https://www.w3schools.com/jsref/met_win_settimeout.asp">setTimeout()</a> method as an example to achieve this async behavior. According to w3schools:</p><blockquote>The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.</blockquote><p>In our contrived example, let’s say that it will take 3 seconds for the food to be made. In code:</p><pre>console.log(&quot;Place order for food&quot;);</pre><pre>setTimeout(() =&gt; {<br>  console.log(&quot;Food is ready, bring out the food!&quot;)<br>}, 3000)</pre><pre>console.log(&quot;Flirt with hostess&quot;);</pre><pre>console.log(&quot;Greet guests&quot;)</pre><p>This will return:</p><pre>Place order for food<br>Flirt with hostess<br>Greet guests<br>Food is ready, bring out the food!</pre><p>What happened here? Again, going back to the callstack, we see that console.log(“Place order for food”); is called/executed/popped off the callstack first. Using the checklist analogy, the waiter writes this task on his checklist, completes it, and crosses it off. Next comes the setTimeout(…) function, this is the async task that is required to run in the background so that other things can be completed meanwhile. In the checklist analogy, it is as if the waiter is keeping track of this other task in<em> another checklist</em> while waiting for the food to be made. When code is ran in the browser, we have access to <a href="https://developer.mozilla.org/en-US/docs/Web/API">Web APIs</a>, async code gets passed from the callstack (or our main checklist) to the Web APIs (our second checklist). This allows us to continue running code/completing tasks on our callstack/initial checklist without the async task interfering.</p><p>In the example above, you can see that while the setTimeout() function is waiting for 3000ms or 3s to be up in the background, subsequent console.log()’s functions are allowed to be executed first. While our waiter is waiting for the food after placing the order, he can flirt with the hostess, and greet guests.</p><p>The Web APIs in the browser keep track of time, and when the async process finishes, content inside setTimeout() is now allowed to run. They are moved back on the callstack, get executed, and then removed. Using our analogy, when the food is ready, we move that task from the second checklist to the first, complete the task of serving the food, then cross it off our first checklist.</p><h3>Conclusion</h3><p>Hopefully this analogy gave you a good introduction to asynchronous JS. For more beginner friendly follow-up material, check out:</p><ul><li><a href="https://www.youtube.com/watch?v=_8gHHBlbziw">Async Javascript Tutorial For Beginners</a> by Dev Ed on Youtube</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=807d462b0e14" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/explain-like-im-5-async-javascript-807d462b0e14">Explain Like I’m 5: Async Javascript</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[Explain Like I’m 5: The React Virtual DOM]]></title>
            <link>https://medium.com/better-programming/explain-like-im-5-react-virtual-dom-297ed1b8f7b?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/297ed1b8f7b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Tue, 24 Nov 2020 16:22:25 GMT</pubDate>
            <atom:updated>2020-11-30T15:30:46.015Z</atom:updated>
            <content:encoded><![CDATA[<h4>How does React’s Virtual DOM really work?</h4><figure><img alt="Man drawing blueprint" src="https://cdn-images-1.medium.com/max/1024/1*Q1BLU8QHVBLEMx6KlMSHWQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@d_mccullough?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Daniel McCullough</a> on <a href="https://unsplash.com/s/photos/architect-blueprint?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>.</figcaption></figure><p>If you’re new to React, the concept of the <em>virtual DOM </em>has likely left your head virtually spinning. You’ve read that React solves the problem of DOM manipulation by using a virtual DOM, which is a lightweight representation of the DOM object. You’ve read that manipulating the DOM is slow, whereas doing so with virtual DOM is fast. And yet you’re still confused as to what all this really means.</p><p>In this article, I will simplify the React virtual DOM in a way that hopefully will build a better representation of this concept in your head!</p><h3>The Problem</h3><p>The DOM (or the <em>document object model</em>) is a tree-like representation of your application. When an element updates in the real DOM, a new DOM is created. This process is slow and expensive.</p><p>If you think of the real DOM as a physical house. DOM manipulation is like needing to renovate a room of the house and doing so by tearing the house down to build an entirely new one. This is, of course, wasteful and effortful.</p><figure><img alt="Example of DOM" src="https://cdn-images-1.medium.com/max/486/1*LA6AXbzvC0IQ_d2H8v3NCw.gif" /><figcaption>Source: W3Schools</figcaption></figure><h3>The Fix</h3><p>The virtual DOM, on the other hand, is a lightweight representation of the DOM. Think of the virtual DOM as a current blueprint of your house on paper. You can see all aspects of your house through this blueprint, but drawing a new room on the blueprint alone won’t magically fix the real room. In the same way, the virtual DOM is a great representation of the DOM, but it cannot directly change what you see on the screen. So how is this done?</p><p>The house analogy of what happens with the virtual DOM is like so:</p><ul><li>You want to renovate a room in your house.</li><li>You have access to the blueprint of the house.</li><li>You then make a new copy of the blueprint and make revisions on this new version. The new blueprint now has the new room representation.</li><li>Now you compare the original blueprint and the new blueprint and see what sort of construction needs to be done.</li><li>You then go into the real house and carry out those changes relevant to that room alone without having to rebuild the entire house.</li><li>Since you no longer have any use for the old blueprint, you can throw that away. Now your most recent blueprint is your only blueprint, which represents the most updated version of your house after the fix.</li></ul><p>In this example, the original blueprint of the house is the virtual DOM. You needing to make a fix in the house is akin to when an element needs updating (as triggered by a change in state). You making a revised blueprint based on the changes needed is akin to the virtual DOM updating completely. You comparing the original blueprint with the updated blueprint is akin to React comparing the pre-updated virtual DOM with the updated virtual DOM. In this process, React determines exactly what aspect of the virtual DOM has changed. This is referred to as <em>diffing</em>. Finally, you going into the house to make the exact changes needed is comparable to React updating <em>only the objects </em>that need changing on the actual DOM.</p><h3>Conclusion</h3><p>Hopefully, this analogy helps you see the efficiency and effortless idea behind the use of a virtual DOM<em> </em>in React. For additional beginner-friendly resources, check out:</p><ul><li><a href="https://www.codecademy.com/articles/react-virtual-dom">React: The Virtual DOM</a></li><li><a href="https://programmingwithmosh.com/react/react-virtual-dom-explained/">React Virtual DOM Explained in Simple English</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=297ed1b8f7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/explain-like-im-5-react-virtual-dom-297ed1b8f7b">Explain Like I’m 5: The React Virtual DOM</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[Explain Like I’m 5: Big O Notation]]></title>
            <link>https://medium.com/better-programming/explain-like-im-5-big-o-notation-d16b53f03a4c?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/d16b53f03a4c</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 20:18:37 GMT</pubDate>
            <atom:updated>2020-11-17T16:34:37.983Z</atom:updated>
            <content:encoded><![CDATA[<h4>Making a sometimes intimidating concept simple</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TUgp4E2mpiQqhyg2" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>Hi there. This is the first in a series of articles in which I will be covering computer science concepts in simplified, easy-to-understand terms. From my own personal experience, despite the enormous amount of resources out there, it might be difficult as a beginner to learn new programming concepts. This is because many sources often explain them using overly technical jargon.</p><p>So my goal here is to break things down to analogies/everyday examples as best as I can in order to serve any beginners out there who might be struggling to understand these core concepts.</p><p>Let’s jump into our first topic: Big O Notation.</p><p>Consider an example with me: You are volunteering at a big conference and you’re responsible for giving each attendee their name tag when they show up. You are given a pile of unordered name cards. How will you go about this task?</p><p>The first and terribly inefficient way to complete this task is that for every person who shows up, you look through every single card in the pile until you find their name card. The second way, perhaps that which you just thought of, is organizing the cards in sub-piles based on the attendees’ last names. This might take up a bit more space on your table, but then all you would need is the attendee’s last name and you could retrieve their card in a much faster way.</p><p>In this example, you can see that there are many different ways to solve a problem. Two things we consider are how fast a solution is and how much room a solution takes in order to determine if it is the “best” option. In measuring how “fast” something is, we can literally <em>time </em>the exact amount of seconds or minutes, but this may not be the best way to go. In the first solution where you are going through every single card in a name pile to find a name, you might get lucky and find it immediately, whereas other times you might have to take time to go through almost the whole stack to find it. So measuring the<em> actual time</em> to determine the solution’s effectiveness is not the way to go.</p><p>Instead, we can explain effectiveness using Big O notation. In short, Big O answers this question: As the size of the input increases, how does an algorithmic solution perform in terms of time and space?<strong> </strong>In the example above, what if the conference now takes in an additional 1,000 people? How would your first solution compare with the second? Hint: It’d be even worse!</p><p>The following are some common <em>time complexity</em> cases and real-world examples to help you think about them. In these examples, <em>n</em> represents the size of the input.</p><p><em>Note: You can find many examples of analyzing complexities of actual code on the web, so I won’t go over them here. My favorite lesson is from </em><a href="https://www.youtube.com/watch?v=HfIH3czXc-8"><em>Alvin from Coderbyte</em></a><em>.</em></p><h3>O(1) — Constant</h3><ul><li>The algorithmic solution takes a constant time despite the input size.</li><li>For example, the time it takes for you to clean your living room in preparation for guests is the same despite how many guests you are expecting.</li></ul><h3>O(log n) — Logarithmic</h3><ul><li>The time it takes to perform a solution is described as a logarithm of the input size. Logarithm can be thought of as the opposite of exponent: Exponent is repeated multiplication, whereas logarithm is repeated division.</li><li>For example, you are looking for someone’s name and number in a physical phone book. What you would do is divide the book in half, see if the person’s name is in the first half or second half, look through that half, and repeat. Each time, you are dividing in half to arrive at your solution. Now if the phone book gets a bit thicker (the input size <em>increases</em>), it won’t take <em>that much more</em> time to find the person’s name and number. Think of this in comparison to a solution where you literally flip from page to page to find the person’s info in the book. As the length of the book increases, it’s going to take you <em>that much longer</em> to find them. This brings us to <em>O(n)</em>.</li></ul><h3>O(n) — Linear</h3><ul><li>The time it takes to perform a solution increases <em>in proportion </em>to the input size. Taking our previous example, this would be the “flipping through every single page until you find the person” approach.</li><li>Many life tasks are completed with Big O(n) runtime. For instance, the time it takes for you to fold your laundry depends on the size of your load, the time it takes for you finish reading a book depends on how many pages the book has.</li></ul><h3>O(n²) — Quadratic</h3><ul><li>As the input size increases, the time it takes to perform the algorithm increases quadratically. Time is the square of the input size.</li><li>For example, let’s say you’re in a contrived interview skill practice group with several other people. After every person’s turn at practicing answering an interview question, each and everyone else in the room takes a turn to give the person who went feedback. The time it takes to give feedback in total would grow exponentially as more people join the interview prep group, as everyone is required to go and everyone else is required to give feedback after each turn.</li></ul><h3>Conclusion</h3><p>Hopefully, these examples gave you a good introduction and a better way to relate to the concept of Big O notation. For additional resources, please check out:</p><ul><li><a href="https://www.youtube.com/watch?v=HfIH3czXc-8">The Complete Guide to Big O Notation &amp; Complexity Analysis</a></li><li><a href="https://www.freecodecamp.org/news/my-first-foray-into-technology-c5b6e83fe8f1/">Beginners Guide to Big O Notation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d16b53f03a4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/explain-like-im-5-big-o-notation-d16b53f03a4c">Explain Like I’m 5: Big O Notation</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[Making a Responsive Header With MaterialUI and React]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/making-a-basic-header-responsive-with-materialui-and-react-2198fac923c8?source=rss-2cc0dd21bc13------2"><img src="https://cdn-images-1.medium.com/max/600/0*jc46R__bxxvXYh2j.gif" width="600"></a></p><p class="medium-feed-snippet">Part 2</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/making-a-basic-header-responsive-with-materialui-and-react-2198fac923c8?source=rss-2cc0dd21bc13------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/making-a-basic-header-responsive-with-materialui-and-react-2198fac923c8?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/2198fac923c8</guid>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 13:44:21 GMT</pubDate>
            <atom:updated>2021-05-28T18:54:44.840Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building a Basic Header With MaterialUI and React]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/building-a-basic-header-with-materialui-and-react-js-d650f75b4b0a?source=rss-2cc0dd21bc13------2"><img src="https://cdn-images-1.medium.com/max/2600/0*XAIJSEb5DlZSASL2" width="3200"></a></p><p class="medium-feed-snippet">Read on for how to build a clean, simple header</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/building-a-basic-header-with-materialui-and-react-js-d650f75b4b0a?source=rss-2cc0dd21bc13------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/building-a-basic-header-with-materialui-and-react-js-d650f75b4b0a?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/d650f75b4b0a</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 20:10:05 GMT</pubDate>
            <atom:updated>2020-11-12T22:46:42.931Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[tsiL dekniL a gnisreveR]]></title>
            <link>https://medium.com/swlh/tsil-deknil-a-gnisrever-96d004f23d5?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/96d004f23d5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Tue, 27 Oct 2020 00:19:22 GMT</pubDate>
            <atom:updated>2020-10-28T05:58:10.340Z</atom:updated>
            <content:encoded><![CDATA[<h3>tsiL dekniL a gnisreveR (Reversing a Linked List)</h3><p>Hello all! Today I would like to walk through my iterative solution of how to reverse a linked list. But first, <em>what is a linked list, you ask?</em></p><p>According to <a href="https://en.wikipedia.org/wiki/Linked_list">Wikipedia</a>:</p><blockquote>In computer science, a <strong>linked list</strong> is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence.</blockquote><p>A linked list is made up of nodes. Each node composes of two things: 1) some data value and 2) a pointer to the next node. The next node in a linked list can be accessed via the next property on the current node. See a representation of a short linked list below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7TUkhPoxx1naCC9XiuOndw.png" /></figure><p>To simplify, I will refer to the first node as n1 and the second n2. The <strong>head</strong> of the linked list in the diagram above is n1 and the <strong>tail</strong> is n2. A tail in a linked list will always point to null.</p><p>Let’s now get on with our problem:</p><blockquote><strong>Instruction</strong>: Reverse a singly linked list.<br>Ex. <strong>Input:</strong> 1-&gt;2-&gt;NULL | <strong>Output:</strong> 2-&gt;1-&gt;NULL</blockquote><p>We can solve this problem by having the head (n1) point to null, then have n2 point to n1. Which would give us the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*JdhrLE_16L8BKGjfdkN_kQ.png" /></figure><p>Sounds easy in theory, but how will this be implemented? The trick here is to keep track of all the moving pieces. Let’s take things one step at a time.</p><ol><li>Create a variable called previous, initializing it to null.</li></ol><pre>let previous = null;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BS4OixXPjLq2tGUnEjW7Yg.png" /></figure><p>2. We want our head (n1) to point to previous. However, if we simply do so via head.next = previous, we would lose track of n2! If these nodes were people, it is as if n1 is holding n2’s hand. If n1 lets go (via pointing to something else), then n2 can drift away into the void, and there would be no way for us to refer back to it!</p><p>Therefore, we need to keep track of the second node before pointing the head to previous. We can do so by assigning the second node to a variable, let’s call it nextNode. Remember, right now n1 still points to n2, so we can access n2 by calling head.next.</p><pre>let nextNode = head.next;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gR9teB2nVtmurQDX8vOlPQ.png" /></figure><p>3. Now we can set the pointer of head to previous without worrying that we won’t have access to the second node.</p><pre>head.next = previous;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KP8mfEgqHMbbOeaLRCCwWw.png" /></figure><p>4. The next step is to point n2 to n1, to do so we will need to reassign some variables.</p><p>Since we won’t need access to null anymore, our current head will be the new previous, and nextNode will be our new head. How this looks like in code and diagram:</p><pre>previous = head;<br>head = nextNode;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1o-rcFoX-HaTTjA5wd4xpg.png" /></figure><p>5. Repeat steps 2 to 4 while the head is not null.</p><p>The next iteration of the above steps would have n2 point to n1, which would end up looking like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGL783g2mJDOsMRONvA3Fw.png" /></figure><p>We have our new reversed linked list! The head variable now points to null which indicates that this is where we should end our iterations. All we would have to do is to return previous, which now references our new linked list. (Side note: the second null is now not associated with our linked list, so we can disregard it).</p><p>The process in code:</p><pre>/**<br> * Definition for singly-linked list.<br> * function ListNode(val, next) {<br> *     this.val = (val===undefined ? 0 : val)<br> *     this.next = (next===undefined ? null : next)<br> * }<br> */<br>/**<br> * <a href="http://twitter.com/param">@param</a> {ListNode} head<br> * <a href="http://twitter.com/return">@return</a> {ListNode}<br> */</pre><pre>var reverseList = function(head) {<br>    let previous = null;<br>    <br>    while (head !== null) {<br>        let nextNode = head.next;<br>        head.next = previous;<br>        previous = head;<br>        head = nextNode;<br>    }<br>    <br>    return previous;<br>    <br>};</pre><p>There you have it!</p><p>If you would like to attempt this problem, click <a href="https://leetcode.com/problems/reverse-linked-list/">here</a> to try it on Leetcode.</p><p>If you would like more animated visuals of this problem, check out <a href="https://www.youtube.com/watch?v=jXArj8RBq0Q">this Terrible Whiteboard video</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96d004f23d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/tsil-deknil-a-gnisrever-96d004f23d5">tsiL dekniL a gnisreveR</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[I Got 99 Problems, and Pyramid’s Just One]]></title>
            <link>https://medium.com/swlh/i-got-99-problems-and-pyramids-just-one-778a9a97ff79?source=rss-2cc0dd21bc13------2</link>
            <guid isPermaLink="false">https://medium.com/p/778a9a97ff79</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Anh]]></dc:creator>
            <pubDate>Mon, 05 Oct 2020 13:36:13 GMT</pubDate>
            <atom:updated>2020-10-08T14:30:57.832Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, fellow soon-to-be software developer. If you are preparing for upcoming interviews like me, you’re most likely (or will about to be) grinding away on loads of algorithm problems. In this post, I’d like to share a walkthrough of a problem I recently solved, in hope of better understanding it myself, as well as helping anyone who might be struggling with similar problems.</p><p>For this particular bad boy, we’re tasked with writing a function that prints out a two-sided pyramid of <em>n </em>levels that follows a couple of simple rules. I figured out two ways of tackling this (one I much prefer over the other). Let’s jump in!</p><h4>Two-Sided Pyramid, Explained</h4><p>Specific instruction for this problem is as follows:</p><blockquote>Write a function that accepts a positive number <strong>n</strong>. The function should console log a pyramid shape with <strong>n</strong> levels using the <strong># </strong>character. Make sure the pyramid has spaces on both the left *and* the right-hand sides.</blockquote><p>Examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24d591d9a74e30805b75dfce50b67811/href">https://medium.com/media/24d591d9a74e30805b75dfce50b67811/href</a></iframe><p>Side note: This problem was taken from Stephen Grider’s Udemy course on <a href="https://www.udemy.com/course/coding-interview-bootcamp-algorithms-and-data-structure/">Algorithms + Data Structures</a>, which I highly recommend.</p><h4>Solution #1</h4><p>I first looked at the examples given to identify common patterns shared and jotted down these observations. Here is how I broke down the patterns using pyramid(4) as a case example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe4ccf25b31a8148adb381d2f84ac4c5/href">https://medium.com/media/fe4ccf25b31a8148adb381d2f84ac4c5/href</a></iframe><ul><li>First, I related my observations to the stable argument <em>n.</em> The pyramid consists in this case of 4 or <em>n</em> rows.</li><li>Next, I went row-by-row, and again wrote down my observations regarding how many spaces are on either sides of the #. From this, I deduced that spaceCount or the number of spaces on either side starts at n — 1 (or 4 — 1, which is 3). For each new row, spaceCount decreases by 1 on either side, until you reach the final row, in which case the final spaceCount is 0.</li><li>On the other hand, the hashCount or number of #’s in the middle of each row, starts at 1 and increments by 2 each time you move onto a new row.</li><li>With these observations in mind, I started pseudo-coding out the solution, which looks like this:</li></ul><ol><li>Create a variable called spaceCount initially set to n — 1.</li><li>Create another variable called hashCount initially set to 1.</li><li>While spaceCount hasn’t reached below0, console.log out spaceCount number of spaces, followed by hashCount number of #’s, followed again by spaceCount number of spaces. I used spaceCount as the variable whose value determines when I will be “done”, as I know that we will have finished printing the pyramid once we reach the row with only #&#39;s and no spaces.</li><li>After each iteration, we set the new spaceCount to be one less than what it was, and we set the new hashCount to be two more than what it was.</li></ol><ul><li>Then I coded out my solution:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19b3ccc1e72ad61fb68a8a6c0a8d6f3e/href">https://medium.com/media/19b3ccc1e72ad61fb68a8a6c0a8d6f3e/href</a></iframe><p>Within my outer while loop, I created two variables, called spaces and hashes which will store the actual string fragments; initially they are empty strings. I created two inner while loops that add to said empty strings either spaces or #&#39;s according to the current spaceCount and hashCount. Next, I concatenated the string parts and console.log’ed them out. And lastly, I decrement spaceCount by 1 and increment hashCount by 2 for each iteration of the outer while loop.</p><p>And voila, completed! I like this first solution as it followed exactly what I observed without much math (beyond counting) involved. The next solution is a bit complicated, in my opinion, but I find that learning multiple ways to solve the same problem always ends up teaching me something new.</p><h4>Solution #2</h4><p>This solution involves seeing the pyramid in terms of rows and columns. This way, you can identify each position in the pyramid by specifying the row number it belongs to and the column number it belongs to in a battleship-esque way. Using this matrix, we can determine at which position to add # and at which to add space. I drew out a diagram, labeled rowIdx’s and columnIdx’s and identified some observations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_qfjZq4Ftclp6MLMrcmHQ.png" /></figure><p>There are some “stable” variables we can take note of here. First is that all rows share a common “midpoint” at columnIdx 3, we can use this to figure out the “range” of columnIdx’s where we will be adding #&#39;s rather than spaces. Second, we notice that the length of each row is consistently 7. This is useful to know so that when we are constructing out each row, we know when to stop.</p><p>We will make use of two for loops: an inner loop that adds either # or a space to a particular row, and an outer loop that will print out each row. Let’s solve this one layer at a time, by first constructing the outer loop:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fde44f6d18b2276b1c7d8fe391e3d19a/href">https://medium.com/media/fde44f6d18b2276b1c7d8fe391e3d19a/href</a></iframe><ul><li>In line two, we specify that we will be creating rows from index 0 to the index right before n. Given the 0-based indexing that is happening here, the condition rowIdx &lt; n will make sure that we end the loop with n number of rows printed out. rowIdx++ is the iteration part of the for loop, which ensures that we increment the index by one with each iteration.</li><li>Notice here that row has not yet been defined. Next, let’s talk through the logic regarding how we will flesh out each row given the observations we made, and then code accordingly.</li></ul><p>First I wrote out how to calculate the stable length of each row from n since n is the only argument passed into the function; hence, we need to find ways to deduce everything else in relation to n. To get from n = 4 to rowLength = 7, we can use the formula: rowLength = n * 2 — 1. Knowing the length is useful for our inner for loop, as we can set it as the condition, where as long the columnIdx is less than the rowLength, we can continue adding characters (either # or space).</p><p>Next, I wrote out how I can calculate the midpoint, in the case above, it is at columnIdx 3. And this is the formula: midpoint = Math.floor(rowLength / 2). Since rowLength in this case is 7, 7 / 2 = 3.5. Using Math.floor(), we round the result down to 3, hence arriving at columnIdx 3.</p><p>Next, I deduced the pattern of spaces and #&#39;s for each row in relation to the midpoint and rowIdx, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28e9a1f5f8e0a4f3176be878e3d31c7e/href">https://medium.com/media/28e9a1f5f8e0a4f3176be878e3d31c7e/href</a></iframe><ul><li>Looking at the pattern above, we can say that the columnIdx’s where we will be adding #&#39;s are from the startIdx of midpoint — rowIdx to the endIdx of midpoint + rowIdx. Refer to the drawn diagram above for a visual of the row and column matrix.</li></ul><p>Given all this information, we can write the logic to construct each row as follows:</p><ol><li>Create a variable called row that is initially an empty string</li><li>Define rowLength</li><li>Define midpoint</li><li>Loop from columnIdx to the index just before rowLength</li><li>The range of indices where we are to place the #&#39;s are from startIdx of midpoint — rowIdx to the endIdx of midpoint + rowIdx, as stated above</li><li>If the current columnIdx belongs in that range, then add a # to the row string, if not, add a space instead</li></ol><p>And finally, the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/751b4125ba1b1f2b6964c8b88a6df744/href">https://medium.com/media/751b4125ba1b1f2b6964c8b88a6df744/href</a></iframe><p>Again, I prefer the first solution, as it involves less calculation and is much more straightforward. However, this solution allows for a different view of the same problem. There is a third solution that involves <a href="https://www.freecodecamp.org/news/quick-intro-to-recursion/">recursion</a>, but I won’t be going into that here.</p><p>Skills I practiced from solving this problem include: 1) articulating in human terms step-by-step the patterns I observed in the examples given and 2) relating said observations back to the “stable” variables, especially the argument(s) provided to the function.</p><p>I hope you find this helpful. And I wish you the best on your next coding interview!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=778a9a97ff79" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/i-got-99-problems-and-pyramids-just-one-778a9a97ff79">I Got 99 Problems, and Pyramid’s Just One</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>
    </channel>
</rss>