<?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 Rebekah Zhou on Medium]]></title>
        <description><![CDATA[Stories by Rebekah Zhou on Medium]]></description>
        <link>https://medium.com/@rebekahzhou?source=rss-8350d43fadc1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*an0m3Er-GPC61ct5yp2wMw.jpeg</url>
            <title>Stories by Rebekah Zhou on Medium</title>
            <link>https://medium.com/@rebekahzhou?source=rss-8350d43fadc1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:10:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rebekahzhou/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[Dare to Be Uncomfy]]></title>
            <link>https://medium.com/@rebekahzhou/dare-to-be-uncomfy-21a9bd489646?source=rss-8350d43fadc1------2</link>
            <guid isPermaLink="false">https://medium.com/p/21a9bd489646</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[career-change]]></category>
            <dc:creator><![CDATA[Rebekah Zhou]]></dc:creator>
            <pubDate>Fri, 22 Apr 2022 09:07:53 GMT</pubDate>
            <atom:updated>2022-04-22T09:07:53.678Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s amazing the amount of growth that humans can go through. I know, because I’ve seen it. I’ve watched my students discover that they can build math skills when they thought people were just “born with it”. Just yesterday, I witnessed a group of incredible individuals present full-stack web applications that they created after just 15 weeks in a coding bootcamp. Heck, I even surprised myself with how much I’ve grown this past year: I moved three times (don’t recommend), reunited with family I hadn’t seen in six years, and graduated alongside these amazing humans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qOexhq9LnPMD2OlpO3qeLQ.png" /><figcaption>Front Page of My <a href="https://github.com/rebekah-zhou/math-test-gen">Capstone Project</a></figcaption></figure><p>How did I do all of this? Pulled myself up by my <em>bootstrap</em>s. (Sorry, had to.) No, but honestly, I’ve been pretty blessed with having a great support system. It kind of reminds me of when one of my students asked me how I learn so fast, and I told him, “What, you want to know the secret to learning?” His eyes lit up, and I told him, grinning, “You have to love to learn.” He was disappointed by my answer.</p><p>In all seriousness, the secret(s) to learning boil down to a few points, which are cliché, but true. The most important of all is to believe you can learn. When I was in the classroom, I told my students the first day of class: “I don’t expect you to love or even like math. I just ask that you are open-minded to it.” Secondly, you must be willing to make mistakes AND learn from the mistakes. You can believe in yourself all you want, but if you just keep making the same mistakes and don’t actively make an effort to fix them, you’re just running in place. The last step to learning is to push your boundaries and</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FnKaia4nhmM0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DnKaia4nhmM0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FnKaia4nhmM0%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/b4ce632ffec334198e589e05b85ca96f/href">https://medium.com/media/b4ce632ffec334198e589e05b85ca96f/href</a></iframe><p>which brings me to my last point. Recently I went to a conference — <a href="https://womenimpacttech.com/">Women Impact Tech</a>. There was a panel on self-advocacy and one woman said something that just really clicked with me. She said, “Get comfortable being uncomfortable,” so I wanted to pass it on.</p><p>I challenge you to be “uncomfy” —in whatever way that means for <em>you</em>. For me, when I was accepted into Flatiron’s bootcamp and made the full switch from teaching into tech, I was terrified. I felt inadequate, behind all the programmers that started their first coding session in middle school. <em>How am I ever going to catch up?</em></p><p>Trust me, I <em>know </em>it’s so uncomfortable. You feel the tightness in your chest just thinking about it, the sweat culminating in your palms, and your voice ever so slightly falters when you speak about it. But you know what? It’s worth it. Yes, you’ll fail. You may even crash and burn. But that’s <em>how </em>we grow. That’s how we continue bettering ourselves, and when you succeed despite the setbacks and the challenges? It’s <em>empowering</em>. It’s how we can pave the path for others to follow suit.</p><p>We can start small. I know the first step is always the hardest, so I’ll start. I haven’t posted anything on LinkedIn. It’s scary! But I can’t just talk the part, I need to walk the part. So I’m posting this blog as my first LinkedIn post at 2 am. (Unite, night owls!) As for you, my dear reader, I dare you to comment on my post: what will you do this week that makes you uncomfy?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21a9bd489646" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Insertion Sort & Merge Sort]]></title>
            <link>https://medium.com/@rebekahzhou/insertion-sort-merge-sort-91ffa7baccd1?source=rss-8350d43fadc1------2</link>
            <guid isPermaLink="false">https://medium.com/p/91ffa7baccd1</guid>
            <category><![CDATA[complexity]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Rebekah Zhou]]></dc:creator>
            <pubDate>Thu, 07 Apr 2022 22:01:45 GMT</pubDate>
            <atom:updated>2022-04-11T22:23:04.774Z</atom:updated>
            <content:encoded><![CDATA[<p>In preparation for technical interviews, I wanted to share what I’ve learned about two sorting algorithms: Insertion Sort and Merge Sort.</p><h3>Insertion Sort</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/0*C5prixSOQOuy-1Hd" /></figure><p>If you grew up playing cards, then this sorting algorithm should be quite intuitive to follow. Imagine you were dealt a hand of cards and you wanted to sort them by their value. One way to sort them is to start building a sorted section of cards by taking cards from the unsorted section and inserting them into the sorted section. Now unfortunately since computers can only compare two things at a time (imagine if you had to open two doors to see what numbers you are trying to compare), we need to account for that in our algorithm.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FRT1FGyqTzrhvD7tDbp%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FRT1FGyqTzrhvD7tDbp&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2FRT1FGyqTzrhvD7tDbp%2Fgiphy.gif%3Fcid%3D790b7611f8f96d34ca809fadff589bbb054a8ad6f324c36c%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="403" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d6996964620c73b1fd6c4bed1874898/href">https://medium.com/media/8d6996964620c73b1fd6c4bed1874898/href</a></iframe><p>When reading others’ code, I found it very helpful to look at visuals to see what each line of our code is doing. <a href="https://www.programiz.com/dsa/insertion-sort">Programiz</a> does a great job of step-by-step visuals. Below we have a nice overview image of what insertion sort does by <a href="https://www.geeksforgeeks.org/insertion-sort/">GeeksforGeeks</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*Berg0nupil06fldD.png" /></figure><h4>Algorithm</h4><p>Upon trying to implement an insertion sort algorithm myself, I remembered reading about one and came up with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1b7202837de1d37eb97d6c138a81408/href">https://medium.com/media/c1b7202837de1d37eb97d6c138a81408/href</a></iframe><p>But after looking up a few, I found this algorithm to be the common way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3fdca44b9d1c3efa967b03d56541b12/href">https://medium.com/media/a3fdca44b9d1c3efa967b03d56541b12/href</a></iframe><p>Not that it super matters which of the two you use anyway, because you want a more efficient algorithm than O(n²), right?</p><h3>Merge Sort</h3><p>As a math teacher, merge sort reminds me of <a href="https://miro.medium.com/max/1170/1*u5r1-IQdd4zMsk1YBxHyxw.png">factor trees</a>. But I think it’s mostly because we are breaking down one thing into smaller things.</p><p>Merge sort is a <a href="https://www.geeksforgeeks.org/divide-and-conquer-algorithm-introduction/">divide and conquer algorithm</a>, which involves the following steps:</p><ol><li>Dividing the problem into smaller subproblems</li><li>Solving those subproblems recursively</li><li>Combining the subproblems to get the final solution to the original problem</li></ol><p>For merge sort, specifically, we can go further into detail:</p><ol><li>Divide the array into halves using the half-way point, continue dividing until each array has only one element</li><li>Starting with the single element arrays, merge the subarrays into sorted subarrays</li><li>Repeat step 2 until you have a single sorted array</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Yxj2KlfEhlu7a9I.png" /><figcaption>Follow the numbers below the arrays to trace the order of the recursive calls.</figcaption></figure><p>The algorithm is actually quite satisfying, following <a href="https://stackabuse.com/merge-sort-in-javascript/">stackabuse’s</a> example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79986fc1a61ce85256722b975fbb1599/href">https://medium.com/media/79986fc1a61ce85256722b975fbb1599/href</a></iframe><h3>Big <em>O</em> Notation</h3><p>Big O notation is used to talk about the worse-case execution time (or number of actions taken by the computer) by an algorithm. I chose insertion sort and merge sort specifically due to their differences, namely, insertion sort has a pretty bad complexity rating: <em>O</em>(n²), whereas merge sort has the most efficient of comparison based sorting algorithms: <em>O(n⋅</em>log(<em>n))</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*pTWvyi3vKWOiWDQMvW211A.png" /><figcaption>Dotted line: O(n²), Dashed line: O(nlog_2(n))</figcaption></figure><p>Looking at this graph, we can easily see how rapidly worse O(n²) gets with larger arrays, compared with the bunny slope of <em>O(n⋅</em>log(<em>n))</em>.</p><h3>Logarithms Review</h3><h4>Why do we care about logarithms, anyway?</h4><p>The most efficient sorting algorithms have a run time complexity of <em>O(n⋅</em>log(<em>n)). </em>In fact, a Big O with logarithms is a huge hint as to what algorithm approach is used — specifically divide and conquer algorithms, like merge sort.</p><h4>What is a logarithm?</h4><p>Let’s start with <strong>exponential functions</strong>. Say I am a zombie and each zombie can infect another person at a rate of one person per minute (scary, right?). Essentially, the zombies are doubling per minute. Within one minute, there would be two zombies. In two minutes, the two zombies would infect another two for a total of four zombies. Then in three minutes, these four zombies would raise the total to eight zombies. This is an example of the exponential function 2<em>ⁿ. </em>This function is handy to have because now we can make a prediction of how many zombies there will be after <em>n</em> minutes. After just 8 minutes, we have a sizable zombie hoard of 256 zombies. Yikes.</p><p>A logarithm is the <em>inverse</em> of an exponential function. A nice visual of what I mean by inverse can be seen by the picture below. The function 2ⁿ is the inverse of log₂(<em>n</em>); notice in the picture that the columns are switched. Let’s break it down a little. Thinking of our previous zombie example, what if we wanted to reverse engineer it a bit and think about how long would it take for there to be 256 zombies? That’s where log₂(<em>n</em>) comes in. Logarithms answer the question: “How many of a certain number do we need to multiply to get another number, <em>n</em>?” Breaking it down further, “How many 2’s need to be multiplied to get 256?” Well, 2×2×2×2×2×2×2×2 = 256 (eight times!). Therefore, log₂(256) = 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*tcZZnvXkQnXg4Tm1X-xvtw.png" /><figcaption>Review the relationships between 2^n, log_2(n), and nlog_2(n)</figcaption></figure><p>Feel free to play around with the <em>x</em>² and <em>x</em>log<em>x</em> graphs:</p><p><a href="https://www.desmos.com/calculator/cvpfkudzgy">Function Table</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91ffa7baccd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Graph Data Structures]]></title>
            <link>https://medium.com/@rebekahzhou/graph-data-structures-f31098c98ee3?source=rss-8350d43fadc1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f31098c98ee3</guid>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[graph]]></category>
            <dc:creator><![CDATA[Rebekah Zhou]]></dc:creator>
            <pubDate>Tue, 15 Mar 2022 08:48:29 GMT</pubDate>
            <atom:updated>2022-03-15T08:48:29.045Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s my introductory take on one of the many data structures out there: graphs.</p><p>Most of you are familiar with the word <strong>graph</strong>, probably from your high school years, and hopefully not, but likely, tainted by any thought of the word <em>math</em>. Now, the math teacher in me <em>really </em>wants to rant about why math is not a “skill” that you’re born with, and how excelling in mathematics is just like any other hobby (which requires persistence, learning from mistakes, and a willingness to learn). But that’s not why you’re here. In fact, some of you might just ‘nope’</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FeJiX4lpUuD2fxmVZ8g%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fmoodman-eJiX4lpUuD2fxmVZ8g&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2FeJiX4lpUuD2fxmVZ8g%2Fgiphy.gif%3Fcid%3D790b7611895cc72152b8eb50298a835e49d2c236fac2bc2b%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="314" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e9dd1df121b6ed042d4fe3219d2c67b/href">https://medium.com/media/9e9dd1df121b6ed042d4fe3219d2c67b/href</a></iframe><p>straight out of this page at any mention of math, running far, far away from the voice of your 9th grade math teacher who took off points for not boxing your answers. Or even worse, maybe you had <em>me </em>as a teacher. 😇</p><p>You’ll be surprised to know that there is actually very little in common between the coordinate plane graph you learned in algebra/geometry and a graph data structure in computer science (which is based on the mathematics field of graph theory). In fact, the only real connections are that they share the word ‘graph’ and both can be drawn.</p><p>So, what <em>is</em> a graph? Let’s use a real-world example. Suppose we wanted to map out my friend group relationships, via example #1 below (it’s hard making friends as an adult, you know). If each of the circles (vertices) represented me and my friends, then each of the lines (edges) shows who we are friends with. We see that A is friends with B, C, and D, but not E. That’s because when A and B became friends, they were like, “C your way out before D and E come to F you up, G.” Anyway, I try to stay out of the drama.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Y1rwCY_ZRUv6iAy2e-tu8Q.png" /><figcaption>#1 Example of a graph</figcaption></figure><h3>Components of a Graph</h3><p>A graph is made of two components: a set of finite <strong>vertices</strong> (aka <em>points</em> or <em>nodes</em>) and a set of <strong>edges </strong>(aka <em>lines </em>or <em>links</em>). Essentially, we can think an edge as a relationship between any two vertices.</p><p>In the example #1 above, we have our set of vertices: {A, B, C, D, E} and the set of edges: {(A, B), (A, C), (A, D), (B, D), (B, E), (C, D), (D, E)}.</p><p>Since none of the edges have arrows, we know that the example is an <strong>undirected </strong>graph, meaning (A, B) is the same as (B, A). Another way to decide if you need an <em>undirected </em>versus <em>directed </em>graph is to think about whether these two are the same: “A is friends with B” and “B is friends with A”. In this case, they are! So we can stick with using an undirected graph. Now what if we wanted to put a number to the relationship between our friendships?</p><h3>Directed and Weighted Graphs</h3><p>When we add number values to our edges, we now have a weighted graph. Here’s an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*ZmfCFkZI2urG6LTHLQ9wLA.png" /><figcaption>#2 Example of a weighted graph</figcaption></figure><p>Suppose this graph displays my friend group and a route between our houses. The numbers above show the distance between each friend in miles of that particular route. We see that friends A and B live 3 miles apart, B and D live 2 miles apart, etc. Now why might we hypothesize that friends A and D don’t have a connection? It could be that there is no direct route from A’s house to D’s house, and the only path there is through B’s house. Similar to our last example, since the relationship A to B is the same as B to A, this is an undirected graph, which leads us to our final example: a directed, weighted graph.</p><p>Let’s say my friend group owed each other some money, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*DFtMj5hs9OgdxuGe_A5ZTA.png" /><figcaption>#3 Example of a directed, weighted graph</figcaption></figure><p>In this example, the arrows show which friend owes money to whom, and the numbers depict how much that friend owes. These numbers are the “weighted” portion of our graph. So we can see that friend A owes a whooping $60 to friend D and $12 to friend C. Seems friend E stayed relatively responsible and only owes $7 to friend A. Even better, friend D owes nothing! I’ll let you guys figure out which friend I am. 😉</p><p>In each of these examples, the set of vertices stays the same: {A, B, C, D, E}. However, the set of edges in this directed, weighted graph is</p><p>{(A, C, 12), (A, D, 60), (B, A, 10), (C, B, 20), (C, D, 32), (E, A, 7)}.</p><p>Since I’m sure friend C would argue that “A owes $12 to C” is different than “C owes $12 to A”, we see that a directed graph (with arrows) is necessary to show the direction of the relationship.</p><h4>Ruby Implementation of a Directed, Weighted Graph</h4><p>In Ruby, we can use the <a href="https://github.com/monora/rgl">RGL gem</a> to implement this graph for us.</p><pre>require &#39;rgl/adjacency&#39;<br>require &#39;rgl/dot&#39;</pre><pre>graph = RGL::DirectedAdjacencyGraph.new</pre><pre>edge_weights = {<br> [A, C] =&gt; 12,<br> [A, D] =&gt; 60,<br> [B, A] =&gt; 10,<br> [C, B] =&gt; 20,<br> [C, D] =&gt; 32,<br> [E, A] =&gt; 7<br>}</pre><pre>edge_weights.each { |(friend1, friend2), w| graph.add_edge(friend1, friend2) }</pre><p>If you’re interested in viewing the graph, then you’ll want to install <a href="https://www.graphviz.org/download/">GraphViz</a> to your local machine. Additionally, add the following line to your ruby file to create a jpg:</p><pre>graph.write_to_graphic_file(&#39;jpg&#39;) &quot;graph.jpg&quot;</pre><p>It’s not as pretty, but check it out!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*UnbUf5KzMqKVdfW_IGs2jQ.jpeg" /><figcaption>RGL image of Example #3</figcaption></figure><p>As an ending note, let’s expand my graph and be my friend! As you can see, I could use a few more. 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f31098c98ee3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RegEx & Love Letters?!]]></title>
            <link>https://medium.com/@rebekahzhou/regex-love-letters-4318b90bf656?source=rss-8350d43fadc1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4318b90bf656</guid>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Rebekah Zhou]]></dc:creator>
            <pubDate>Mon, 07 Mar 2022 09:24:36 GMT</pubDate>
            <atom:updated>2022-03-07T09:29:45.111Z</atom:updated>
            <content:encoded><![CDATA[<p>No, we’re not talking about your regular ex… What even is a regular ex, anyway? An ex you go back to? Welp.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3otPoPoCbPjSP4ktGw%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3otPoPoCbPjSP4ktGw%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3otPoPoCbPjSP4ktGw%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1e89f3bfd538c11a9a4fe626e55cab9/href">https://medium.com/media/f1e89f3bfd538c11a9a4fe626e55cab9/href</a></iframe><p>Hope you don’t have one of those. My guide won’t really be able to help you with that, but maybe it’ll inspire you. Oh, and if you want a beginner’s guide to Ruby RegEx, short for a <em>regular expression</em>, then be sure to read on.</p><p>Say you were sick and tired of going back to your regular ex, and finally found a new lover, Sean. Ah, Sean… cute, <em>dreamy</em>, perfect. Just oblivious to your love. What better way to profess yourself to him than a love letter!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*31v4su8ZDmc9uG8-.jpg" /></figure><p>(In case you’re also curious about making sure you don’t accidentally delete your draft while typing it up, <a href="https://medium.com/@rebekahzhou/useeffect-37980f162ab3">this</a> blog can help with that.) Do love letters scare you? Don’t worry, I’ve got a <a href="https://www.writeexpress.com/love07.html">draft</a> for you. Just be sure that you don’t miss replacing all the “Lisa”s! And the perfect tool for that? RegEx.</p><h3>What is RegEx? Why is it useful?</h3><p>RegEx is a sequence of characters that will help us search through text for patterns. Let’s work through an example and observe the magic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F18293181&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fmagic-gif-18293181&amp;image=https%3A%2F%2Fc.tenor.com%2Fmd3foOULKGIAAAAC%2Fmagic.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c8a1b43161de7bef810d71c36a25daa/href">https://medium.com/media/6c8a1b43161de7bef810d71c36a25daa/href</a></iframe><p>Follow along with me using: <a href="https://rubular.com/r/cZbG34uBQFoirR">https://rubular.com/r/gOHHRJzl4U2P80</a></p><p>In Ruby, we usually put RegEx in between forward slashes, like so: /regex/ . In Rubular, they’ve already been written, so let’s replace “write your regex here” with “Lisa”. We don’t want Sean to know this love letter was recycled, do we?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DeF_OBsocwFrDDRMuxIytQ.png" /><figcaption>Since I know 85% of you didn’t click that link, here’s a snapshot. I actually think the percentage is higher… I just wanted to be optimistic.</figcaption></figure><p>Notice “lisa” won’t work, since RegEx matches the exact string.</p><h3>Basics</h3><p>Now that we’ve gone over the simplest case of matching a string, what else can RegEx do?</p><h4>1. Specific Character</h4><p>If you wanted to see if your text contained a vowel, you could try: /[aeiou]/ . Using this on our love letter, we can see there’s a lot of vowels, as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xStcjFvZ3-AXtL7oeWBLEQ.png" /><figcaption>Find the hidden message! Just kidding…</figcaption></figure><h4>2. Ranges</h4><p>What if you wanted to check if your text contained any letter of the alphabet? If you’re not willing to write your own love letter, I’m guessing you’re not willing to type out the alphabet either. Thankfully, we have ranges! Examples:</p><ul><li>[0–9] is the same as [0123456789]</li><li>[a-z] is the same as … the alphabet.</li></ul><p>There’s even a shorter syntax for some character ranges:</p><ul><li>\w is the same as [0–9a-zA-Z_]</li><li>\d is equivalent to [0–9]</li><li>\s matches white space (tabs, spaces, newlines)</li></ul><p>If you want the negative form, change the syntax from lowercase to uppercase: (\W, \D, \S). For example, \D is anything that’s not a number.</p><h4>3. Dot Character</h4><p>The dot character . is the catch all — it lets us match everything except new lines. However, if you want the period itself, you’ll need to escape it by using a backwards slash. Say we wanted to find sentences ending with the word ‘you’, we could use the RegEx /you\./</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QIvkyFcLReSqU5yqwDgZg.png" /></figure><h3>Modifiers</h3><p>So far we’ve only talked about matching a single character, if we want multiple characters, try out the following modifiers:</p><ul><li>+ (matches 1 or more characters)</li><li>* (0 or more)</li><li>? (0 or 1)</li><li>{5,10} (between 5 and 10)</li></ul><h3>Using RegEx with Ruby Methods</h3><p>You can use regular expressions with Ruby methods such as .split, .scan, .match, .gsub, and more! Uncomment the methods below to see what they do:</p><p><a href="https://replit.com/@RZhou1/CringeyLoveLetter#main.rb">CringeyLoveLetter</a></p><p>Not sure if you caught it, but be sure to replace the word “woman” to whoever suits your fancy!</p><p>And there you have it, the long way instead of just pressing ctrl+f and replacing the name. Although, it’s likely that whoever implemented ctrl+f probably has regex in their code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4318b90bf656" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useEffect()]]></title>
            <link>https://medium.com/@rebekahzhou/useeffect-37980f162ab3?source=rss-8350d43fadc1------2</link>
            <guid isPermaLink="false">https://medium.com/p/37980f162ab3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Rebekah Zhou]]></dc:creator>
            <pubDate>Tue, 15 Feb 2022 08:16:34 GMT</pubDate>
            <atom:updated>2022-02-15T08:19:16.745Z</atom:updated>
            <content:encoded><![CDATA[<h3>useEffect() and Love Letters?!</h3><p>Has anyone ever drafted an extensive, multi-paragraph response pouring their heart out to their long-lost lover about why things couldn’t be ten years ago (because your high school self only had eyes for Sean Faris)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*jlHq9U-FXyJiScVQ-QEl4w.jpeg" /></figure><p>only to accidentally refresh the page and now all of your heart-wrenching words are gone, never to be read, perhaps for the best?</p><p>No? Yeah… me neither… <em>I mean, who does that…</em></p><p>Since I’m sure you would agree that we can’t let that hard work be washed down the drain, let me show you how you can help others avoid such a blunder (not the letter itself… I mean losing their draft, of course).</p><h4>The Version Where We Lose The Letter On Refresh</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*V0x_MfKK73zAvmq3nlvVXQ.png" /><figcaption>Mess with the code <a href="https://replit.com/@RZhou1/LoveLettersIntoTheAbyss#src/App.jsx">here</a></figcaption></figure><h4>The Version Where The User Can Save Their Letter On Refresh</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*y_2GjMrSJ8aARuHmH5h2_g.png" /><figcaption>Mess with the code <a href="https://replit.com/@RZhou1/SavedOnRefresh#src/App.jsx">here</a></figcaption></figure><p>The main differences in words:</p><ol><li>Import useEffect</li><li>Change the initialization of our text state variable from “” to localStorage.getItem(“insert-anything-here-even-potato”)</li><li>Add the useEffect() hook inside our App component, which takes in a callback function with localStorage.setItem(“insert-anything-here-even-potato”) inside, and a dependencies array: [text]</li></ol><h4>Let’s break down the useEffect hook a bit more</h4><p>The useEffect hook lets us do side effects inside our function components. So <em>after</em> our component renders, we can have useEffect perform data fetching, manually manipulating the DOM, using a timer, etc.</p><h4>useEffect(callbackFunction, dependencies)</h4><p>Inside our useEffect() hook is a callback function that contains our side effect code. In our example above, our callback function has localStorage.setItem(‘love-letter’, text), which allows us to store our data from the text state variable into our localStorage as a key-value pair. Thus, we have our key ‘love-letter’ and the value being whatever the user types into the input box (since text state variable contains the user input via the onChange event handler).</p><h4>Dependencies</h4><p>After our callback function we have a dependencies argument. Dependencies may contain an array that the useEffect hook refers to in order to trigger the side effect. Since our example has [text] as its dependencies argument, this means that our useEffect hook is looking to see if text<em> </em>has been updated. After the component re-renders, the useEffect hook runs the side effect again. We can set different arguments as dependencies to allow us to control when the side effect runs:</p><ol><li>An array containing state/prop values [text, prop1, prop2, …]. We can add more values if desired so that the side-effect runs when any of the dependency values change.</li><li>An empty array []. This will have the useEffect run only <em>once </em>after the initial rendering.</li><li>Nothing. The side effect will run after <em>every </em>render.</li></ol><h4>useEffect Tips</h4><ul><li>If you want to implement several side effects, then don’t be afraid to use multiple useEffect hooks.</li><li>Got an async function? Throw it into useEffect.</li></ul><h4>TL;DR</h4><p>You can use the Effect Hook in react components to ensure that your cringy love letter doesn’t get lost when you refresh the page.</p><p>Be sure to check out the <a href="https://reactjs.org/docs/hooks-effect.html">React Docs</a> on the Effect Hook!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37980f162ab3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>