<?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 Shirley Lin on Medium]]></title>
        <description><![CDATA[Stories by Shirley Lin on Medium]]></description>
        <link>https://medium.com/@shirleyl?source=rss-d97a0273c051------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7UltuIHig4YWFmvUOSwEqg.jpeg</url>
            <title>Stories by Shirley Lin on Medium</title>
            <link>https://medium.com/@shirleyl?source=rss-d97a0273c051------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 09:04:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shirleyl/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[Lessons Learned: Migrating Fill in the Blank Assessments from CodeMirror to Monaco]]></title>
            <link>https://medium.com/codecademy-engineering/lessons-learned-migrating-fill-in-the-blank-assessments-from-codemirror-to-monaco-9141b4803836?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/9141b4803836</guid>
            <category><![CDATA[syntax-highlighting]]></category>
            <category><![CDATA[monaco-editor]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Fri, 29 Jan 2021 16:33:28 GMT</pubDate>
            <atom:updated>2021-01-29T16:33:28.242Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGjlBWza947LGsmQ9_0G3Q.png" /><figcaption>A Fill in the Blank Assessment on Codecademy</figcaption></figure><p>At Codecademy, we are committed to building the best learning experience possible. A large part of this is providing an in-browser, no-setup coding experience for our learners that gives them much of the same feeling as coding locally in an IDE.</p><p>To accomplish this, we leverage Microsoft’s <a href="https://microsoft.github.io/monaco-editor/index.html">Monaco Editor</a> project. Fun fact — If you use <a href="https://code.visualstudio.com/">VSCode</a> as your IDE, Monaco is the text editor that powers that!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AlQKPXYNg5CmI80-.gif" /><figcaption>via code.visualstudio.com</figcaption></figure><p>But it didn’t always used to be that way! In fact, about a year ago, we were using <a href="https://codemirror.net/">CodeMirror</a> for editor needs. We switched to Monaco because of its rich features, which include:</p><ul><li>better accessibility support (our long term goal is to provide a fully accessible editor experience)</li><li><a href="https://microsoft.github.io/monaco-editor/playground.html#creating-the-diffeditor-navigating-a-diff">code diffing</a> (which is now integrated into our product, where we use it to show the difference between your code and solution code)</li><li><a href="https://code.visualstudio.com/docs/editor/intellisense">Intellisense</a>, snippets, color themes, and others that we haven’t started to integrate into Codecademy yet</li></ul><p>By late 2020, the only remaining piece of the codebase that was still using CodeMirror was what we call CodeBlocks. CodeBlocks are used throughout the site to display code snippets outside of the editor experience. For instance, they may appear on cheatsheets or in articles. CodeMirror was powering the <a href="https://en.wikipedia.org/wiki/Syntax_highlighting#:~:text=Syntax%20highlighting%20is%20a%20feature,to%20the%20category%20of%20terms.">syntax highlighting</a> of these blocks.</p><h3>Act I: The Migration</h3><p>Syntax highlighting — it seems simple, right? Moving from CodeMirror’s syntax highlighting API to Monaco’s API wasn’t too complicated, as the interface is fairly similar. Here is what Monaco’s colorizer API looks like:</p><pre>const colorized = await monaco.editor.colorize(text, language, {});</pre><p>The variable colorized now contains HTML with classnames that link to Monaco’s theming (which plugs in CSS styles) that we provide to our CodeBlock component.</p><p>There was one place where we ran into issues, though — Fill in the Blank questions. On Codecademy, we use CodeBlocks in quizzes to ask our learners questions about code to reinforce what they’ve learned. This is what that looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*NlTYAkGgSyS_VZArPe9-tw.gif" /></figure><p>The tricky part here is that:</p><ol><li>We need our code to be syntax highlighted (through CodeMirror or Monaco).</li><li>We also need to know where our blanks that users fill in should go.</li><li>We need find these blanks and replace them a different, interactive React Component that controls all the special behavior that the blanks have, such as drag &amp; drop and clearing the blank.</li></ol><p>For our curriculum developers that create these questions, they are simply writing a short code snippet. In order to turn that code snippet into an interactive Fill in the Blank question, we need to have some sort of agreement that we both use to know where the blanks should go.</p><p>To accomplish this, we use a special <a href="https://en.wikipedia.org/wiki/Delimiter"><strong>delimiter</strong></a>. In this case, our delimiter is a special word, or sequence of characters, that we all decide means “this is where a blank goes”. When we run the code snippet through our syntax highlighter, though, we have to be careful that the syntax highlighting doesn’t recognize the delimiter as a reserved word (like const ), or gets tripped up by the syntax of it (like __~BLANK~__ ). The easiest way to do this is to use a simple word, so that the highlighting recognizes it as a variable name.</p><p>In the CodeMirror world, we used the string, fitbblank. For example, this is what a raw Fill in the Blank question might look like:</p><pre>p + fitbblank (fitbblank = fitbblank, fitbblank = fitbblank)</pre><p>When properly rendered, each fitbblank will map to an interactive blank. When switching over to Monaco, though, we ran into an issue!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*Wq1D4eO1zKHq0sak" /><figcaption>what happened to that last blank??</figcaption></figure><p>Occasionally, a fitbblank would not correctly be replaced with the Blank component and render the quiz unusable. The colorized code that Monaco would return would look something like this:</p><pre>&lt;span&gt;... = fitbb&lt;/span&gt;&lt;span&gt;lank&lt;/span&gt;</pre><p>What made this particularly hard to track down was that this didn’t happen in the majority of quizzes. Eventually, it was narrowed down to the fact that For performance reasons, Monaco chops <a href="https://en.wikipedia.org/wiki/Lexical_analysis#Token">tokens</a> apart if they are longer than 50 characters as it causes performance issues. A token’s definition may vary by programming language, but in this case the entire line is one token.</p><p><strong><em>Lesson Learned: With a package that you don’t own or fully understand, unexpected behavior can (and a lot of time, will!) happen.</em></strong></p><h3>Act II: The Domino Falls</h3><p>Once the root cause was identified, the challenge of fixing it started. Our first thought was to see if we could get Monaco to play by our rules. Unfortunately, the token length before splitting is currently not an option that is exposed to users of the package. For most cases, this doesn’t cause issues with using their syntax highlighting implementation — except in this rare case where we need to ensure that our blank delimiter does not get chopped up! One option was to submit an issue to Monaco to expose the option of turning the chopping off (or allowing adjustment of length). While this is the ideal fix, the timeline of this called for an immediate fix first.</p><p>Upon thinking about this problem, we realized that a single character delimiter would be the only delimiter that would ensure it would not be chopped by Monaco. But what character would suffice? We couldn’t use something that might be used by our curriculum developers legitimately, e.g. &amp; or * , as that would cause any use of that character to be turned into a blank.</p><p><strong><em>Lesson Learned: Technical decisions aren’t always purely technical. Oftentimes, they involve balancing other team’s needs, future projects, deadlines, and a number of other factors.</em></strong></p><p>We could’ve chosen a fairly obscure character like ë, but what would happen in the future if we translated our content into a language that uses that character? What would happen when a new curriculum developer joins and unknowingly uses that character?</p><p>Eventually, we decided that a <em>very</em> special character needed to be used here. Something that is still a single character, but wouldn’t accidentally be used by curriculum developers. That character was an emoji. 🁡, to be exact. There wasn’t an especially detailed reasoning on why that particular emoji was chosen, other than that we felt like it would be unlikely to be used in curriculum, and that we just liked it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FzFb4l4CvD4MOQ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FzFb4l4CvD4MOQ%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FzFb4l4CvD4MOQ%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/01bc3550970cc80ec3420976c3275a03/href">https://medium.com/media/01bc3550970cc80ec3420976c3275a03/href</a></iframe><p>Side note: it was even trickier picking an emoji to use because Codecademy offers a course in <a href="https://www.codecademy.com/learn/learn-emojicode">Emojicode</a> (which you should definitely take, by the way!).</p><p>With this new delimiter in place, the above broken quiz was now fixed. Unfortunately, though, that was not the end. With using this obscure character, we unknowingly introduced another issue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/0*vWee-WYQ8USyDMt-" /><figcaption>That ?? should be a blank.</figcaption></figure><h3>Act III: The Replacement</h3><p>� is called the Unicode Replacement Character, and you can read more about it <a href="https://en.wikipedia.org/wiki/Specials_(Unicode_block)">here</a>. It seems like while 🁡 was a clever trick that could’ve solved our issue, Monaco was most likely running into some sort of encoding issue. One example is this code snippet:</p><pre>const a = { name: &#39;Example&#39; };<br>if (a.🁡 === &#39;Examples&#39;) return true;</pre><p>In the above example, the quiz should display a blank at the domino. Instead, we were getting an encoding issue, agin rendering the blank unusable. After playing around with a few other delimiter options, we ended up using � as our delimiter — due to some of its special properties and place in the Unicode spec.</p><p>The Unicode Replacement Character is not characterized as an ‘emoji’. Instead, it is a special character and was added way back in Unicode 1.1.0 (June 1993). For reference, Unicode is now on <a href="http://www.unicode.org/versions/Unicode13.0.0/">version 13.0.0</a>. The Unicode Replacement character is also included in the <a href="https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane">Basic Multilingual Plane</a>, while emojis and many newer special symbols are included in what is known as <a href="https://en.wikipedia.org/wiki/Plane_(Unicode)">Supplementary Planes</a>.</p><p>With the delimiter sorted out, there’s one final piece to touch on. There were many mistakes and known pitfalls discovered during this process, but only a very small group of engineers worked on this piece of code. Even with sharing this through knowledge-sharing channels, it’s very likely that engineers not actively involved in this part of the codebase (or even engineers who are!) will not remember the details in 6 months.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fnms2xnxztoXvy%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fnms2xnxztoXvy%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fnms2xnxztoXvy%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="182" frameborder="0" scrolling="no"><a href="https://medium.com/media/18543ff2eb187c426b25ed49e766406f/href">https://medium.com/media/18543ff2eb187c426b25ed49e766406f/href</a></iframe><p><strong><em>Lesson Learned: Leave clear and helpful documentation behind you for the next person!</em></strong></p><p>As an engineer, learning these pitfalls and engineering a solution to them is only half of the problem. The other half of the problem is to pass on that knowledge and ensure that the next person does not inadvertently make the same mistakes that you do. To combat this, we left a detailed comment above the relevant code explaining why we use this delimiter, and linked out to more detailed documentation that explains all the known problems and history behind why this piece of code looks the way it does.</p><p>The comment reads as follows:</p><pre>/**</pre><pre>* This used to be &#39;fitbblank&#39;. Monaco colorization was occasionally</pre><pre>* breaking up the string if the line was too long,</pre><pre>* causing the &lt;span class=&quot;fitb-locator&quot;&gt; replacement to fail.</pre><pre>* by using a single character, monaco will not break up this string.</pre><pre>* This is the replacement character. (https://en.wikipedia.org/wiki/Specials_(Unicode_block)</pre><pre>* This means that curriculum can not use this character.</pre><pre>*</pre><pre>* If you would like to change this, please look here first: &lt;internal notion link to further documentation&gt;</pre><pre>*/</pre><h3>Wrap-up &amp; TLDR;</h3><p>Even seemingly small changes can snowball into bugs and headaches, especially when it involves code that you don’t own. Software is constant iteration, learning, and knowledge-sharing. Mistakes are unavoidable, but the slog through, it’s important to reflect and understand what you have learned from it.</p><p>These are three lessons we learned while transitioning our Syntax Highlighting from Monaco to CodeMirror.</p><ol><li><strong><em>With a package that you don’t own or fully understand, unexpected behavior can (and a lot of time, will!) happen.</em></strong></li><li><strong><em>Technical decisions aren’t always purely technical. Oftentimes, they involve balancing other team’s needs, future projects, deadlines, and a number of other factors.</em></strong></li><li><strong><em>Leave clear and helpful documentation behind you for the next person!</em></strong></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9141b4803836" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codecademy-engineering/lessons-learned-migrating-fill-in-the-blank-assessments-from-codemirror-to-monaco-9141b4803836">Lessons Learned: Migrating Fill in the Blank Assessments from CodeMirror to Monaco</a> was originally published in <a href="https://medium.com/codecademy-engineering">Codecademy Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2 Years In: A Software Engineering Retrospective]]></title>
            <link>https://medium.com/@shirleyl/2-years-in-a-software-engineering-retrospective-d188427aaf4f?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/d188427aaf4f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Fri, 13 Mar 2020 15:52:40 GMT</pubDate>
            <atom:updated>2020-03-13T15:52:40.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sRm6Chf6f_4Ugcxhd7rww.jpeg" /><figcaption>The best thing about birthdays is that they provide another picture for these retros.</figcaption></figure><p>Welcome back to my yearly life-as-a-software-engineer retrospectives! If you haven’t already (and you’re interested), check out my retrospective from my first year as a software engineer <a href="https://medium.com/grailed-engineering/my-first-year-as-a-software-engineer-a-retrospective-94ec75f1f4f1">here</a>.</p><p><em>My name is Shirley, and I currently work as a software engineer in NYC at </em><a href="https://www.datacamp.com/"><em>DataCamp</em></a><em>. I’m a bootcamp grad, former knitwear designer, and at-home cheese maker with my partner in our little Brooklyn apartment.</em></p><h4>New Year, New Job</h4><p>Since last year, the biggest change I’ve made is a change in workplace! I currently work as a Full Stack Engineer at <a href="https://www.datacamp.com/">DataCamp</a>, a Data Science education platform. I originally joined as an Experimentation engineer — solely focused on running A/B tests, but now work on the Growth team.</p><p>Changing jobs is never easy, as every job comes with its own unique challenges and learnings. My first year as an engineer was filled with a new shiny thing and a new unknown at every turn. Honestly, my second year was not much different. I’ve been thinking a lot about the <a href="https://en.wikipedia.org/wiki/Curse_of_knowledge">curse of knowledge</a> (thank you to my teammate <a href="https://twitter.com/dandenney">Dan</a> for introducing me to this phrase). Trying to remember what I knew a year ago is honestly impossible — but while compiling this list, I realize that I’ve learned and grown as much, if not more than I did in my first year. Okay, let’s get going!</p><h3>Some Technologies/Things I’ve Learned:</h3><h4>A/B Testing</h4><p>Like I said earlier, I originally joined DataCamp as a full time Experimentation engineer. At my previous job, I had run a few experiments, but I didn’t really understand the methodology or analysis of these experiments. In my first few weeks, I learned so much about things like <a href="https://en.wikipedia.org/wiki/P-value">p-value</a>, calculating what percentage of increase was within range of fluctuation, finding out what the LTV of an experiment is, and why <a href="https://codeascraft.com/2018/10/03/how-etsy-handles-peeking-in-a-b-testing/">peeking is a horrible sin</a>. Thankfully, DataCamp has incredible data scientists who do this as a living, but I learned so much from working with them. A/B Testing is <em>not</em> just slapping a red button instead of blue button in and ramping up with a 1% change. If you’re looking for resources on A/B testing, I’d start with <a href="http://datadriven.club/">this</a> or <a href="http://iterative.club/">this</a>.</p><h4>Gatsby</h4><p>In my current work on the Growth team, we focus a lot on revenue focused initiatives. One of those initiatives is optimizing our flow for new users, and our Marketing App (which handles logged-out pages) is built in Gatsby. I’d never touched Gatsby before joining DataCamp, and I’ve had a really great time working with it. It’s super easy to pick up if you know React — the main difference is getting used to how data flows (GraphQL, mostly!) and understanding the build steps.</p><h4>Kubernetes/Google Cloud Platform</h4><p>In my personal time, my partner and I have been hacking on a project together to track airline miles and credit card points (stay tuned for the release). Through that project, I’ve been able to learn a lot of things that normally might come up in a corporate environment. One of the biggest was Kubernetes — neither of us had any experience with it but we chose it as our hosting platform. I’m not going to lie; I probably have a very superficial understanding of how Kubernetes really works, but I wrote the CI steps, and our project is fully hosted, so that’s a win in my book!</p><h4>Other Fun Things I’ve Learned More About:</h4><ul><li><a href="https://tagmanager.google.com/">Google Tag Manager</a></li><li><a href="https://www.terraform.io/">Terraform</a> (a little, okay)</li><li><a href="https://www.datadoghq.com/">DataDog</a></li><li><a href="https://aws.amazon.com/">https://aws.amazon.com/</a></li><li><a href="https://relishapp.com/vcr/vcr/v/1-6-0/docs/test-frameworks/usage-with-rspec">RSpec/VCR</a></li><li><a href="https://circleci.com/">CircleCI</a></li></ul><h3>Some Fun Tools/Libraries I’ve Found:</h3><ul><li><a href="https://getpixelsnap.com/">Pixel Snap </a>— if you ever find yourself fake taking a screenshot to measure things, <strong><em>use this</em></strong>. It’s magical, I swear.</li><li><a href="https://tableplus.com/">Table Plus</a> — slick little database explorer.</li><li><a href="https://chrome.google.com/webstore/detail/form-filler/bnjjngeaknajbdcgpfkgnonkmififhfo">Form Filler</a> — stop filling out the sign up form. Please, stop.</li><li><a href="https://tailwindcss.com/">Tailwind CSS</a> — I love utility classes and you can’t stop me!</li><li><a href="https://emotion.sh/docs/introduction">Emotion </a>— but sometimes styled components are a good choice too, I guess.</li></ul><h3>Some Things I’ve Done:</h3><h4>Took A Design Course</h4><p>Since DataCamp is an education company, it makes sense that they put a large focus on personal development. We have a generous budget that we are free to spend on any professional development initiatives. One thing I did this year was take a 4-week design course through <a href="https://trydesignlab.com/">DesignLab</a>. I think it’s important for both engineers and designers to have a shared language, and coming from a fashion design background I thought it would be fun to get into a little bit of web design. It was enlightening — web design is <em>so hard</em>. My final product didn’t end up being all that great, but I did get some great insights into how designers think and what unique challenges they face that sometimes roll over into implementation.</p><h4>Went to 2 Conferences — one in Hawaii!</h4><p>My first year, I went to 1 conference. This year, 2. Clearly, my personal conference trend is doubling each year, so I’ll get back to you next year when I have attended 4. With the aforementioned generous professional development budget, I attended SmashingConf in NYC and JSConf in Hawaii. JSConf was especially fun, as the talks were really interesting and everyone was really nice and welcoming. It can be scary to go to a conference on your own, especially one 10 hours away, but I met a ton of really cool people and got to hear some extremely relevant talks. Also, who’s going to say no to Hawaii?</p><h4>Ran multiple 6 figure LTV Experiments</h4><p>In my stint as an Experimentation engineer, I got to run some really exciting, impactful experiments. One example was testing out a Referral program. This didn’t exist, but I hacked one together (the best thing about running an experiment is being just a <em>tiny</em> bit messy) and we tested it out. It did surprisingly well, leading to an estimated 6 figure LTV gain! Seeing numbers tied directly to the work you did is extremely satisfying.</p><h3>Lessons I’ve Learned:</h3><ol><li><strong>Remote work is a different beast </strong>— DataCamp has offices in London and Belgium, and the majority of their engineers are there. This means that oftentimes people who you may need to work with are not keeping the same hours as you! I found this really hard in the beginning, as I was used to an office where everyone sat within 50 feet of each other, but I learned that open communication and organization are key to making this work well.</li><li><strong>Company culture is a real thing</strong> — This might sound silly, but when I joined DataCamp I found so many small things that were just…<em>different</em>. Not in a bad way, necessarily, but each company has their own customs. For example, one thing I love about DataCamp is that we’re extremely strict on meeting times. If a meeting is from 1–2, you better believe that people are waiting outside the room at 1:59 to take over! I was totally not used to this, but I actually really love it; I think it shows a real regard for an individual’s time.</li><li><strong>Celebrate successes, but also celebrate failures </strong>— Everybody messes up. Mistakes hurt the most, though, when they’re covered up and never learned from. If you don’t learn from what you (and others) have done wrong, the pace of improvement slows to a crawl. There’s no shame in celebrating failures!</li><li><strong>There are so many ways to solve the same problem</strong> — DataCamp’s architecture is based in a micro-service model. We have many, many different apps that serve different parts of our product. Coming from a monolithic app, this was <em>so</em> different. After working in this model for a year, I think that there are a ton of pros and cons for both, and situations where either might make sense. In essence, <em>there is no right answer</em>.</li><li><strong>Focus on personal wellness </strong>— If you’re not happy outside of work, you’re not going to be very happy at work either. I often take an hour or two during working hours to go to the gym. Outside of work, I took an oil painting class. I’m knitting a sweater, making a quilt, and I like to cook and travel. I also do a little bit of recreational coding. My point is — do what makes you happy, and you will be a better and more productive engineer for it.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d188427aaf4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Year as a Software Engineer: A Retrospective]]></title>
            <link>https://medium.com/grailed-engineering/my-first-year-as-a-software-engineer-a-retrospective-94ec75f1f4f1?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/94ec75f1f4f1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 15:15:15 GMT</pubDate>
            <atom:updated>2019-04-24T14:16:53.874Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5FrqDcdg4-Wxl2SugoM1g.png" /></figure><p><em>My name is Shirley, and I’m a Fashion Designer turned Software Engineer, currently tech leading the Buyer Squad at Grailed.</em></p><p>A year ago, I had just finished up the Web Development Immersive at the Flatiron School. I’d met an Engineer from Grailed, and had interviewed and accepted my first big-girl Software Engineering role. And I was <em>terrified</em>.</p><p>One year later, I can safely say that I’m a (real) Software Engineer. I’m tech leading a team at Grailed, working on improving the experience of buyers on the platform. A quick aside — thank you to everyone who supported me, and the team at Grailed that gave me opportunities to succeed, laughed with me, and learned with me. I remember the vast ocean of unknowns I had before starting my job, and it’s crazy to look back at how far I’ve come in just a year. To any new engineers who are feeling doubt or experiencing imposter syndrome —<em> you are not alone</em>. A year later, you too will look back at everything you’ve accomplished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*YD19AJucK47rxNzJWm1gZw.png" /></figure><h3>Some Technologies/Things I’ve Learned:</h3><h4>vim</h4><p>Within the first week of starting my job, I realized that almost every other engineer was using vim. They were flying through tabs, almost never even touching their mouse. And I wanted to be like them! Vim is <strong>hard</strong>. But the only way to learn it is to use it. I remember having to pair program with my manager, and fumbling my way through shortcuts that I had definitely not memorized yet. Nowadays, though, my workflow is efficient and comfortable — I’ve found a great compromise by using Atom w/ vim keybindings.</p><p><em>Key Learning: Improve your workflow. It will make you a faster and happier developer.</em></p><h4>Flow Typing</h4><p>At Grailed, our front-end is built with React and Redux. With a huge amount of Javascript, we’re always looking for tools to make developing easier. We use <a href="https://flow.org/">Flow</a>, a static type checker for Javascript, to enforce some safety for our types. It doesn’t quite make Javascript a typed language, but it’s a baby step towards it, and it makes it very easy to look at a function and know exactly what should be passed in and returned.</p><p><em>Key Learning: When there’s 15 developers touching the same codebase, making code readable is VERY important.</em></p><h4>Lodash/Functional Programming</h4><p>Before starting at Grailed, I had never really ventured into libraries like <a href="https://underscorejs.org/">underscore.js</a> or <a href="https://lodash.com/docs/4.17.11">lodash</a>. Lodash is used fairly heavily within our stack, particularly lodash/fp. My first time seeing something like:</p><pre>compose([<br>  map(prop(&#39;value&#39;)),<br>  filter(&#39;searchable&#39;),<br>  prop(&#39;filters.stratas&#39;),<br>]);</pre><p>I had no idea what I was looking at. Functional programming was a whole new style for me, but I embraced the challenge. I’m always looking to see how I can pull out a compose.</p><p><em>Key Learning: There will always be something you don’t know.</em></p><h4>Other Fun Things I’ve Learned:</h4><ul><li><a href="https://www.algolia.com/">Algolia</a></li><li><a href="https://medium.com/square-corner-blog/product-analytics-at-square-8796766a14e3">Analytics</a></li><li><a href="https://medium.com/@InVisionApp/a-b-and-see-a-beginner-s-guide-to-a-b-testing-a16406f1a239">A/B Testing</a></li><li>Thinking about Product</li><li><a href="https://upshotstories.com/stories/one-simple-agile-development-strategy-saved-300-000">Deployment Processes</a></li><li><a href="https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/">PR reviews</a></li><li><a href="https://medium.com/innodev/agile-development-for-dummies-dd161da253c7">Sprint Planning/Retros</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9bdxatYDuAYPLeaJ2wxnEQ.gif" /></figure><h3>Some Things I’ve Done:</h3><h4>Attended a Conference</h4><p>Last June, I attended <a href="https://dinosaurjs.org/">dinosaur.js</a> in Denver, with 2 of my coworkers. Grailed has a great conference policy, and encourages developers to go to at least 1 conference a year. I’d never been to a conference before, and it was an amazing experience. There were tons of interesting talks, some valuable workshops, and a great community of like-minded individuals. Being in a place with hundreds of developers is a crazy thing, and something I highly recommend you seek out.</p><p><em>Key Learning: If your company has opportunities to attend conferences, </em><strong><em>take them!</em></strong></p><h4>Interviewed Candidates</h4><p>Being on the other side of the interview process has been enlightening and <em>way</em> less scary. I’ve been involved with the interview process in some way since about 3 months into my time at Grailed, and my involvement has gradually evolved from there. At Grailed, we focus a lot on hiring the right people. I get asked a lot by prospective employees what my favorite part about working at Grailed is, and my answer is always the people I work with. The engineering team at Grailed is filled with smart, low-ego, collaborative people that foster a sense of learning and responsibility.</p><p><em>Key Learning: If culture is important to you, find a company where culture is just as important to them.</em></p><h4>Hosted a Lunch &amp; Learn</h4><p>Public speaking has never been my thing, so the prospect of getting up in front of a group of engineers, and speaking about something that I (sort of) know about is incredibly daunting. Thankfully, when that group of engineers are all friends, and are supportive, silly people — it’s a lot less scary. Recently, I hosted a lunch and learn on <a href="https://www.cypress.io/">Cypress</a>, a very cool end-to-end testing framework that was actually my first real project at Grailed. I was still a little shaky and nervous, but spreading your knowledge is extremely valuable for the entire team.</p><p><em>Key Learning: You have something to share. Share it.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LEm2XgChBkHgR5idqpTZA.png" /></figure><ol><li><strong>Embrace the Fear </strong>— Beginning your career as a Software Engineer isn’t easy. You’ll run into countless things you don’t know, you’ll take the site down, and you’ll be pushed out of your comfort zone. Know that everyone has been there.</li><li><strong>Be Curious </strong>— Nobody knows everything. Make an honest effort to figure things out on your own, but don’t be afraid to ask questions. You won’t look stupid, I promise. When you see something you don’t understand in the codebase, ask someone who does. You’ll get so much more out of it, so much faster.</li><li><strong>Step Up </strong>— Especially in a start up environment, there will be things that may not necessarily be your responsibility, but you have the capacity to do. Be flexible and willing to help out, and it will only benefit you in the long-run.</li><li><strong>Think About the User </strong>— Having empathy for your user is extremely important. It may make perfect sense to you to do something one way, but always keep in mind that you are not building things for yourself, you’re building for millions of people that you don’t know.</li><li><strong>Know Your Strengths, &amp; Your Weaknesses </strong>— And be willing to admit them. I still have so much to learn about databases and performance. I’m still slightly fuzzy on <em>how</em> exactly webpack works. I should speak up more and be more proactive about giving feedback. But I’m also really good at thinking through projects. I can build you what you want in React quickly. And I strike a good balance of keeping in mind Product &amp; Engineering. Nobody’s perfect, but know your weaknesses, and work on them.</li><li><strong>Welcome Feedback </strong>— It may not be fun to feel like you’re being criticized and doing things wrong, but feedback is vital to growing and learning. Be open and receptive to feedback, and try to process it and <em>really</em> think it through before reacting. A culture of feedback will help you be a better engineer and a better coworker.</li></ol><p><em>If you’re interested in joining us at </em><a href="https://www.grailed.com/"><em>Grailed</em></a><em>, we’re hiring! Check out our openings </em><a href="https://grnh.se/c6fbe5962"><em>here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94ec75f1f4f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/grailed-engineering/my-first-year-as-a-software-engineer-a-retrospective-94ec75f1f4f1">My First Year as a Software Engineer: A Retrospective</a> was originally published in <a href="https://medium.com/grailed-engineering">Grailed Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Building of thread’d: React, three.js, & p5.js]]></title>
            <link>https://medium.com/front-end-weekly/the-building-of-threadd-react-three-js-p5-js-fc988e687686?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc988e687686</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[p5js]]></category>
            <category><![CDATA[fashiontech]]></category>
            <category><![CDATA[threejs]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Wed, 31 Jan 2018 21:56:36 GMT</pubDate>
            <atom:updated>2018-11-09T16:49:47.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hPm65AZcfe--e5M_6-fcHA.png" /><figcaption>A screenshot of the render page from thread’d</figcaption></figure><p>For my most recent and most ambitious project yet, I wanted to make an interactive way to create patterns, save them, and then render those patterns onto a 3D model. <a href="https://threadd-adc5f.firebaseapp.com/">Here’s</a> the finished product, in case you’d like to poke around. I’d done little demos in preparation for this project using three.js and vanilla Javascript but the biggest hurdle for this project was combining all these elements together with React.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>p5.js</h3><p>Using p5.js with React was a little bit of an adventure. The thing I was most worried about going into this project was letting React handle the lifecycle of the p5js canvas component. I needed to make sure all functions that were associated with the sketches stopped when the component unmounted.</p><p>Here’s are a couple of the p5.js sketches I made for thread’d:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*18seIBllI6ec5PQLOBLZsg.gif" /><figcaption>size of circles is controlled by scroll input</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ieW9k9vT4NZdvE4SrHM_YQ.gif" /><figcaption>the landing page for thread’d</figcaption></figure><p>To integrate p5.js with React, I ended up using a handy little wrapper called <a href="https://github.com/NeroCor/react-p5-wrapper">react-p5-wrapper</a>, though I did end up making a small modification to it to allow for easier clean up. You can see my updated wrapper <a href="https://github.com/slin12/react-p5-wrapper">here</a>.</p><p>Using the wrapper, it was fairly easy to create p5 sketches, though there were a few tricks to optimize for React. Here are the top things I learned:</p><h4>React + p5.js</h4><ol><li><strong>Clean up is NOT easy on a Single Page App. </strong>I did some weird things to ensure my sketches stopped when the component unmounted, including passing down a prop as a flag, editing the wrapper, and even editing the p5.js library.</li><li><strong>Usually p5.sound and p5.dom is totally possible. </strong>It’s always weird when you google something and there aren’t any results for what you’re trying to do. But through a little trial and error, I did manage to use both p5.dom and p5.sound. If you’re interested in implementing, see <a href="https://github.com/slin12/thread-d-front-end/blob/master/src/sketches/LandingPageSketch.js">this</a> and <a href="https://github.com/slin12/thread-d-front-end/blob/master/src/sketches/Draw.js">this</a> part of my github repo.</li><li><strong>Simplicity is impressive. </strong>p5.js is <em>powerful, </em>and I just scratched the surface of it with my implementation. But just by using some circles, rectangles, and interactions, I managed to create customizable and interesting interactive elements.</li></ol><h3>three.js</h3><p>While there are a few libraries out there for three.js and React, I ended up using <a href="https://github.com/toxicFork/react-three-renderer">react-three-renderer</a>. It’s a nice little library that simplifies three.js, but it was a little difficult because I wanted to use custom models I created and exported from Blender. I also wanted Orbit Controls, which are not included out of the box with react-three-renderer. Here’s a little demo of what I ended up with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3xwdez47VXMheIkKCsZR7g.gif" /><figcaption>Orbit Controls! A Blender-exported model!</figcaption></figure><p>Before starting thread’d, I had done a sample of importing the model and rendering the texture from a url in vanilla Javascript and the regular three.js library, so I felt confident I could replicate it with React. Of course, things are <em>always</em> easier in your head. Here are the top things I learned:</p><h4>React + three.js</h4><ol><li><strong>Async and Component Lifecycle Methods Matter.</strong> One bug that I ran into early on was handling the loading of the model, texture, and setting up orbit controls. I had all of these things happening in componentDidMount(), but my scene wouldn’t render without both the texture and model loaded in. The controls, though, would error out if the scene was not loaded.</li><li><strong>Your first try may not be the final solution</strong>. I tried hijacking the orbit controls with a setTimeout, which worked (most of the time). If the loaders took extraordinarily long, though, we were stuck. I moved on with other parts of the project, leaving the temporary patch. A few days later, though, with new eyes, I realized the solution! It was simple, really. I chained together the loads — loading the texture after the model loaded, and <em>then</em> setting orbit controls.</li><li><strong>Libraries are useful, but not perfect.</strong> You will run into many, many situations where your library does not do exactly what you need it to do, or doesn’t include a feature that you want. For instance, react-three-renderer didn’t handle importing models, or orbit controls. I had to come up with creative solutions and defer to vanilla three.js in order to make things works.</li></ol><h3>Summary</h3><p>Starting a project is never easy, especially when you’re trying to use many different libraries in conjunction. It’s important to remember that <em>you’re in control, </em>and these libraries are here just to help you. You can modify them, expand them, and make them work for you.</p><p><a href="https://threadd-adc5f.firebaseapp.com/">thread’d</a> — an interactive, custom clothing creator</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc988e687686" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/the-building-of-threadd-react-three-js-p5-js-fc988e687686">The Building of thread’d: React, three.js, &amp; p5.js</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Responsible, Responsive Design]]></title>
            <link>https://medium.com/@shirleyl/responsible-responsive-design-35c500300178?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/35c500300178</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[responsive-design]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Thu, 14 Dec 2017 14:27:11 GMT</pubDate>
            <atom:updated>2017-12-14T14:27:11.876Z</atom:updated>
            <content:encoded><![CDATA[<p>In 2014, the <a href="http://www.independent.co.uk/life-style/gadgets-and-tech/news/there-are-officially-more-mobile-devices-than-people-in-the-world-9780518.html">GSMA</a> tracker told us that there were more mobile connections in the world than there were people. Still, though, it’s estimated that only about <a href="http://www.internetworldstats.com/stats.htm">50%</a> of the world are on the internet. I find these numbers staggering, and it’s clear that it’s only going to trend up. With that in mind, and the fact that there are more and more devices popping up (game consoles, phablet, tablets, FRIDGES) that access the internet in different ways, it’s important as web developers to think about accessibility and responsiveness of our creations.</p><h4>What is A Responsive Site?</h4><p>A Responsive site is a site that’s trying to please. No matter how or with what a user is viewing it with, it will display something that is readable and formatted to work with that device. Now, that may seem like a huge and insane concept — the difference in size between a smartphone and a flat-screen tv is huge — but it’s actually not as scary as it sounds. The main, overarching idea is <em>fluidity</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F74Gczlhl7jE1G%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fweb-design-74Gczlhl7jE1G&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F74Gczlhl7jE1G%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="284" frameborder="0" scrolling="no"><a href="https://medium.com/media/47ec89d4022665d52d0b29b2c5a3c1c9/href">https://medium.com/media/47ec89d4022665d52d0b29b2c5a3c1c9/href</a></iframe><p><a href="https://designmodo.com/responsive-design-examples/">This</a> is a great website to look at some examples of Responsive Design, or take a peek at my <a href="http://www.shirleyl.in/">personal website</a> to see a little bit of responsiveness there.</p><h3>Roadmap to Responsiveness</h3><p>Now that we’ve gotten the definition of responsiveness out of the way, let’s talk a little bit about how we actually make something responsive.</p><h4>1. Add A Metatag to your &lt;head&gt;&lt;/head&gt;</h4><p>Make sure this tag is in your &lt;head&gt;</p><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</pre><p>This tag should really be included in all your web pages, but double-check just in case. What this does is it sets our width to the actual width of the device we’re viewing on. Without it, our responsive design wouldn’t do anything!</p><h4>2. Don’t Hardcode Values</h4><p>An easy trap to fall into as a beginner is to use pixels for everything. You make it look amazing on your screen, but as soon as someone else views it on anything that’s not your computer, it looks <em>completely</em> different from what you remember. Instead of pixels, you should be using percentages for widths, margins, etc. and ems for fonts. These units of measurement dynamic, rather than pixels, which is static and will always be the same.</p><p>A simple formula to remember if you need to convert your pixels into percentages is as follows:</p><pre>percent = (pixels / context) * 100</pre><p>So, for example, if your page if screen is 800px wide and you have a 200px wide div, that div’s width, responsively, would be 25%. Also, the context of something can change:</p><pre>&lt;div style=&quot;width: 800px&quot;&gt;<br><strong>  My context is the screen width!</strong></pre><pre>  &lt;div style=&quot;width: 200px&quot;&gt;<br><strong>    My context is 800px!<br></strong>  &lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><h4><strong>3. Use Media Queries To Create Break Points</strong></h4><p>Now that we have percentages, our website is already looking more fluid! Here’s an example I drew up:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT0xejP6HhUQaeziWA%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fweb-design-responsive-xT0xejP6HhUQaeziWA&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxT0xejP6HhUQaeziWA%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="210" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cfc0a296dccd63763ddaaa4ecfc9328/href">https://medium.com/media/7cfc0a296dccd63763ddaaa4ecfc9328/href</a></iframe><p>You can see it in action and the HTML/CSS for this right <a href="https://codepen.io/shirshirlove/full/BJaOjJ/"><strong>here</strong></a>.</p><p>It looks alright, but there’s a problem. When is gets small, it’s starting to look really squished. Wouldn’t it be better if, once it starts getting small, we could get out of our column format, and instead stack our two divs on top of each other?</p><p>This is where <em>media queries</em> come into play. Think of media queries as a set of conditions — if one condition is met, than apply the styling inside of it. Most commonly, you’ll probably use something that looks like this:</p><pre>@media screen and (max-width: 500px) {<br>  <strong>regular css</strong> <strong>styling goes here!</strong><br>}</pre><p>This is basically telling us that if our viewport width is less than 500px, we’re going to do whatever styling is inside those curly brackets. There’s tons of media queries, but this is a standard and commonly used query. You can read more about media queries <a href="https://www.w3schools.com/css/css_rwd_mediaqueries.asp">here</a>.</p><blockquote><strong>Sidenote</strong>: it’s commonly said you should design for mobile first, as it speeds up loading times for mobile devices, but we are not following that convention here. Keep that in mind when making things for the real world.</blockquote><p>To find a breakpoint, I like to open up my Developer Tools on Chrome (cmd-opt-i on Mac, or right-click and choose Inspect) and move the toolbar down to the bottom of the screen. It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W-55owLszvi4W_wjYvuNYQ.png" /><figcaption><em>Make sure you’re viewing in 100% before moving on! Cmd-plus or Cmd-minus if you’re unsure.</em></figcaption></figure><p>Now when you resize your screen, you should see numbers changing in the top right corner. The first number tells us exactly how many pixels wide our screen currently is. Now we can size down until we find a place where things start looking bad, and write a media query to change it! It’s important to not base your media queries on specific device sizes, as there’s no way you could cover every single device. Instead, you should base your queries on <em>where your design breaks down</em>.</p><p>On my test project, I decided to write a media query at 800px. Here’s the code for my media query, and what is looks like after:</p><pre><a href="http://twitter.com/media">@media</a> screen and (max-width: 800px) {<br>  .column {<br>    float: none;<br>    width: 100%;<br>    margin: 0 auto;<br>    background-color: #80ADA0;<br>  }<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxUOxeYdCFH5IBkk5uE%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fweb-design-responsive-xUOxeYdCFH5IBkk5uE&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxUOxeYdCFH5IBkk5uE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="212" frameborder="0" scrolling="no"><a href="https://medium.com/media/14952d97ae531e22356c6221ca95bcd2/href">https://medium.com/media/14952d97ae531e22356c6221ca95bcd2/href</a></iframe><p>Check out the final code <a href="https://codepen.io/shirshirlove/full/vpYQBw/"><strong>here</strong></a>.</p><h4>4. Further Reading</h4><p>With a few simple media queries, you can start optimizing your design for devices other than your computer screen. There’s so much more to learn about responsive design, so I’ve linked some great resources below.</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images">Responsive images - Learn web development | MDN</a></li><li><a href="https://www.w3schools.com/css/css_rwd_mediaqueries.asp">W3Schools.com</a></li><li><a href="https://developers.google.com/web/fundamentals/design-and-ux/responsive/">Responsive Web Design Basics | Web Fundamentals | Google Developers</a></li><li><a href="https://learn.shayhowe.com/advanced-html-css/responsive-web-design/">Responsive Web Design - Learn to Code Advanced HTML &amp; CSS</a></li><li><a href="https://designmodo.com/responsive-test/">Responsive Web Design Test Tool - Designmodo</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35c500300178" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginning JS Animation: Building Snowdays With Canvas]]></title>
            <link>https://medium.com/@shirleyl/beginning-js-animation-building-snowdays-with-canvas-fec989680e1e?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/fec989680e1e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-animation]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Thu, 30 Nov 2017 18:18:30 GMT</pubDate>
            <atom:updated>2017-12-01T13:34:13.848Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you ever see crazy, beautiful animations and graphics on websites that are dynamic and interactive? They always seemed insanely complicated and out of reach. In reality, though, they’re often made with simple concepts and a whole lot of fiddling. In HTML, there’s a mysterious, seemingly useless tag called &lt;canvas&gt;. With the power of a little Javascript, though, this canvas can be manipulated in all sort of magical ways. Below is a little example made completely (HTML + JS) in 100 lines of code.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fshirshirlove%2Fembed%2Fpreview%2FQOJXyG%3Fheight%3D600%26slug-hash%3DQOJXyG%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fshirshirlove%2Ffull%2FQOJXyG%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F143995.QOJXyG.small.e9638536-eee0-431e-9679-470702a86020.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4823986878b3d96504edeb47901847e2/href">https://medium.com/media/4823986878b3d96504edeb47901847e2/href</a></iframe><p>Knowing Javascript opens up a whole new can of worms of what you can do on a website. I think the true power of Javascript is being able to make things <em>dynamic</em>. Instead of refreshing the page every time something is clicked, we can just make things disappear and reappear! Make true single page apps! Grab data from external sources and post data! And create slick, beautiful animations.</p><p>I’m not going to cover all the small details of &lt;canvas&gt; and it’s methods, but here’s a few great resources if you want to read (this tutorial was heavily inspired by this great youtube series!):</p><p><a href="https://www.youtube.com/watch?v=EO6OkltgudE&amp;list=PLpPnRKq7eNW3We9VdCfx9fprhqXHwTPXL&amp;index=1">youtube series</a> || <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API">documentation tutorial</a></p><h4>Getting Started</h4><p>Setting up a canvas project is as simple as can be — in this example everything was done in just one file. Here’s the basic setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cvIP5SLuyjkiwefwPg6wQ.png" /><figcaption>one tag for html!</figcaption></figure><p>For any canvas project, there are few set up lines to get us ready to actually draw with our canvas. Those lines are below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2469d2a840a1409bc8617a4de2369416/href">https://medium.com/media/2469d2a840a1409bc8617a4de2369416/href</a></iframe><p>Here, I’m using a query selector to select my canvas, then defining it’s width and height. I’m using the window’s innerWidth and innerHeight to make a full-screen canvas. I’m setting a background color for a pretty blue, and lastly getting a 2d context. There are other contexts that other engines may use, such as 3d, but we’re just sticking with the basics and using 2d for now.</p><h4>Drawing Our First Circle</h4><p>Drawing in Javascript may seem a little complicated and convoluted, but it’s actually a fairly logical series of steps. Here’s how to draw a simple circle:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30de86bad6700bc455119f06995f4014/href">https://medium.com/media/30de86bad6700bc455119f06995f4014/href</a></iframe><p>The basic flow:</p><ol><li>You start with a beginPath(). This is telling your canvas that it’s time to get drawing!</li><li>You use an arc and pass in a whole bunch of things in to tell your canvas exactly where and how you want your circle drawn. X and Y are relative to the top left corner of your canvas(which would be 0, 0). Most complicated is the start and end; these are actually written in radians, not degrees. This may trip you up, but some basic notes: 2π is a full circle, π is half of a circle.</li><li>Decide if you want to fill the circle or just create a stroke for the circle. Then you can set either fillStyle or strokeStyle to determine how your circle will look. This can either be text, a hex value, or a rgba value — just like CSS!</li><li>Call stroke() or fill(), and then you’re done!</li></ol><h4>Animating A Circle</h4><p>To animate, we’re essentially refreshing the page very quickly, and changing the position of our circle. We’re going to wrap our circle creating in a recursive function, and make a few other tweaks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fd2a551b9ae42dc92b747cd925bf2b4/href">https://medium.com/media/6fd2a551b9ae42dc92b747cd925bf2b4/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fshirshirlove%2Fembed%2Fpreview%2FooJXNe%3Fheight%3D600%26slug-hash%3DooJXNe%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fshirshirlove%2Fpen%2FooJXNe&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F143995.ooJXNe.small.b5f4a1c3-3531-4b44-881e-1e908cb74404.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e5a92a7945424e87ab739fa80b02cb8/href">https://medium.com/media/0e5a92a7945424e87ab739fa80b02cb8/href</a></iframe><p>Notice that we’re now using variables to represent the data we need to change, such as x and y. We also have some other sneaky variables called dx and dy — these represent the speed our circle is going to be moving. If it’s a positive number, it’ll be moving right(dx) or down(dy). If it’s negative, the circle will move left(dx) or up(dy).</p><p>Our if statements are checking if the x or y value is within the constraints of our canvas, we don’t want our circle running off forever!</p><h4>Making 200 Circles and Randomizing Values</h4><p>Now that we’ve got those basics out of the way, let’s talk a little about randomizing our values and how to mass produce our little circles.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F6djJPJeaWwTrW%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ffactory-6djJPJeaWwTrW&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F6djJPJeaWwTrW%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="230" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ba3bf509c315de3131a0d8a88e9b368/href">https://medium.com/media/6ba3bf509c315de3131a0d8a88e9b368/href</a></iframe><p>Knowing we have Math.random() on our side and that we have variables created, we can easily control and create random values for some of our attributes.</p><p>For instance, if we want our circle’s x value and y value to be any value within our canvas, we could do something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7d2e3d1f71ad562b4f5fbb97c376e0e/href">https://medium.com/media/c7d2e3d1f71ad562b4f5fbb97c376e0e/href</a></iframe><p>In the same way, we can randomize our dx and dy values, and also extract portions of our color and opacity to randomize. In Snowdays, here are my randomized values:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/104b546ae8e32736498a3906f1054880/href">https://medium.com/media/104b546ae8e32736498a3906f1054880/href</a></iframe><p>Now to open our circle factory. We’re going to be using a little bit of Object Oriented Javascript to create a Circle class. We’ll also have an array to hold all our circle objects, and use a for loop to generate new random values each time, and add each circle object into our array. This is a little bit of a lengthy step, so let’s take a look at my code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02adbf7710bd8705c4e72abe6cffff18/href">https://medium.com/media/02adbf7710bd8705c4e72abe6cffff18/href</a></iframe><p>We now have a class Circle, and we’ve broken up the rendering and the moving into two separate functions. We instantiated a circleArray, and then a for loop to make 200 circles. Our update() function is calling draw() so that later on, when we call update(), it will handle both things for us.</p><h4>Bringing It All Together</h4><p>Now that we have 200 circles, let’s bring it all together. We just need to update our animate() function to map through our array and update each one. Each circle is going to act independently and we’re going to get a beautiful snow effect!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F12RAfAXFH8g5LG%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fsnow-rainbow-12RAfAXFH8g5LG&amp;image=http%3A%2F%2Fmedia1.giphy.com%2Fmedia%2F12RAfAXFH8g5LG%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="242" frameborder="0" scrolling="no"><a href="https://medium.com/media/5360fcff9eb578a5846cb3fffb6d6b8e/href">https://medium.com/media/5360fcff9eb578a5846cb3fffb6d6b8e/href</a></iframe><p>As a last touch, I added a little mountain to the background and changed the clearRect() to a fillRect() with an opacity for a slight blur effect. You can see the final code on codepen.io <a href="https://codepen.io/shirshirlove/pen/QOJXyG">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*MWW9r8_BV2PuyWXgHJ3Cow.gif" /><figcaption>snow!</figcaption></figure><h4>A Challenge For You</h4><p>Now that you know the basics, here’s a little project for you. Using these same principles but adding a mouseover event listener, see if you can make something like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fshirshirlove%2Fembed%2Fpreview%2FZaVMbq%3Fheight%3D600%26slug-hash%3DZaVMbq%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fshirshirlove%2Ffull%2FZaVMbq%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2be842303fc702966d892de4718727e/href">https://medium.com/media/c2be842303fc702966d892de4718727e/href</a></iframe><h4>Resources</h4><p>Again, I highly recommend <a href="https://www.youtube.com/watch?v=EO6OkltgudE&amp;list=PLpPnRKq7eNW3We9VdCfx9fprhqXHwTPXL&amp;index=1">this</a> youtube series if you want a beginner-friendly, easy-to-visualize guide to canvas.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fec989680e1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect 4: From CLI to Rails App]]></title>
            <link>https://medium.com/@shirleyl/connect-4-from-cli-to-rails-app-fc9cad0d948f?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc9cad0d948f</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[connect-4]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Fri, 17 Nov 2017 15:40:46 GMT</pubDate>
            <atom:updated>2017-11-17T15:40:46.617Z</atom:updated>
            <content:encoded><![CDATA[<p>A coding bootcamp isn’t for everyone. It’s a big commitment — to quit your job and dedicate your entire life for 12 to 15 weeks to code. But the results and growth I’ve seen in myself so far has been astonishing. In my second week at bootcamp, I built a small CLI Connect 4 app. I struggled with getting the logic right (especially the diagonals! Those stupid diagonals!) and I remember the feeling of elation when it finally worked. <a href="https://github.com/slin12/connect4">This</a> is a link to the repository of my Connect 4 game written in Ruby.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*G-y98_gYtjpSrYHgK_rnOw.gif" /></figure><p>Now that I’ve moved upwards and onwards onto Rails, I was challenged to port that Connect 4 game into a web app with (hopefully) better graphics and practice my routing and rendering skills.</p><h3>Approaching the Rails App</h3><p>I knew that things were going to have to change when I moved from the command line to rendering on the web, but I ran into some problems that made it trickier than I thought it would be. Here are some lessons I learned while building my Rails Connect 4 App:</p><h4>Don’t Be Afraid to Delete Code</h4><p>One of the scariest feelings is having code that works, but having to delete it or not use it. But it also is essential to creating a better product. I’m sure many of us have heard of <em>Make it Work, Make it Right, Make it Fast. </em>The first pass through, just make your code work. I think that is definitely the most gratifying and exciting step. Refactoring? That part is more of a grind. When I moved the CLI app to Rails, I could reuse a decent amount of the code (mostly the logic), but a lot of it needed to be refactored to make it work on Rails.</p><h4>HTTP is Stateless</h4><p>One of the biggest hurdles I ran into early on was how to persist a game’s data through the requests. With the CLI, it was easy — each game was an instance of the ConnectFour class and it kept it’s data with itself. But with my Rails app, each click of the button created a new HTTP Post request, with the column number in it’s params. How would I keep track of what the board looked like before the click? I could pass the board information through the request somehow with a hidden field, but that felt like that could get really messy, really fast. There had to be a better solution!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F14d9NIRFMS0UNy%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F14d9NIRFMS0UNy&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F14d9NIRFMS0UNy%2Fgiphy-downsized-large.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/80f517c7245cc901b0d3f25934163c74/href">https://medium.com/media/80f517c7245cc901b0d3f25934163c74/href</a></iframe><h4>Use A Database</h4><p>To persist the data, I decided to use a database. That way, I could keep all the data where it needed to be, and not push that responsibility onto my views. But that grew into another problem — how do I store an array in the database? After googling around, it seemed that storing arrays in Postgres is actually very easy. For my CLI, I stored my entire game board as a nested array. For my Rails app, though, I stored each row separately and created a method in the Board Model to recreate the entire game board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*Yv9k4ZkdNpFpT7xwWZ4ZHA.png" /><figcaption>This is what my board looked like in my CLI app</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*FBnwbnvC31g3vb9Go1UmvA.png" /><figcaption>just set array: true if using PostGres</figcaption></figure><h4>Utilize ERB to Your Advantage</h4><p>When I first began the Rails project, I started with creating the game board in HTML and CSS first, without thinking about the logic. The problem with that was that I ended up writing a separate &lt;div&gt; for each cell. 6 rows by 7 columns meant that there were a total of 42 divs just for my squares! After making it work, though, it was time to make it right: with ERB, I condensed all that code into just a few lines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*bH1MNBu-RfySZHsbrttUew.png" /><figcaption>9 lines of code to create all the squares and circles!</figcaption></figure><h3>The Final Product</h3><p>After learning these lessons, the rest of the app was a breeze. You can find the completed app right <a href="http://rails-connect-four.herokuapp.com/">here</a>. Next step? Rebuild this with Javascript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*yCf-k3o73RWsg_zkBeswMw.gif" /></figure><h4>Useful Links</h4><ul><li><a href="http://rails-connect-four.herokuapp.com/">Connect4</a></li><li><a href="https://github.com/slin12/connect4-rails">slin12/connect4-rails</a></li><li><a href="http://blog.plataformatec.com.br/2014/07/rails-4-and-postgresql-arrays/">Rails 4 and PostgreSQL Arrays</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc9cad0d948f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Big O No(tation)]]></title>
            <link>https://medium.com/@shirleyl/the-big-o-no-tation-bbfe0e54ab21?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbfe0e54ab21</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Wed, 01 Nov 2017 17:33:02 GMT</pubDate>
            <atom:updated>2017-11-05T20:32:04.837Z</atom:updated>
            <content:encoded><![CDATA[<p>O notation — it sounds rather scary, doesn’t it?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F2xx76aWGM39zW%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fcat-arab-2xx76aWGM39zW&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F2xx76aWGM39zW%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="209" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ac2b79d104f418d85f4dadc1dd5d1cd/href">https://medium.com/media/3ac2b79d104f418d85f4dadc1dd5d1cd/href</a></iframe><p>Although the phrase itself can sound very academic and mathematical, it’s a pretty simple concept and important to know if you intend to work with computers. Big O Notation is used in computer science to describe the time complexity of an algorithm — in other words, how long it will take to run. As a beginner developer, it’s easy to not think about scale and huge datasets, but that’s not reality. Big O Notation gives us a sense of how an algorithm will <em>scale</em>. And of course, we’re always looking at worst case scenarios. Below, I’ve put together a graph that shows the basic idea of O notation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*hDzuOGr4KO9RLArX7O_yTQ.jpeg" /><figcaption>adapted from <a href="http://bigocheatsheet.com/">http://bigocheatsheet.com/</a></figcaption></figure><p>You may need to reach back a little to those days of high school math, but the concept is actually quite simple — ideally, you want your algorithm to stay in the green. Think about a bubble sort; maybe the time isn’t so bad when you only have 10 elements. But what if there’s 1000? Or 10,000? That’s where Big O Notation really comes in handy, it allows you to look at your code and categorize it, and gives you a look into how that code may react when it’s significantly scaled up. Let’s walk through some examples of each of these notations.</p><h3>O(1)</h3><p>O(1) is the simplest of the O notations, and easily the best. It means that even when the action is scaled up, i.e. 2 elements vs 20,000 elements, the time spent to perform the action is <em>constant</em>. An example of this is accessing an index. Grabbing array[0] from an array is going to be the same amount of time, no matter how many elements are in the array. O(1) methods are very rare, and really not feasible when we’re writing an algorithm, but they’re a great starting point to think about.</p><pre>array = [1, 2, 3]<br>array[0]</pre><pre>array = [1, 2, 3, 4, 5, 6, 7, 9........]<br>array[0]</pre><h3>O(n)</h3><p>What the heck is the n doing there?!?! Well, the n represents the number of elements in the array. This notation means that the time needed to complete the method grows linearly with the number of elements. An easy way to think about is this — if your method uses an iterator to run through every element in an array, adding an element is going to add a loop. Thus, the amount of time needed grows is tandem with the number of elements in the array.</p><p>We could call one loop 1 time-unit(doesn’t matter, as O notation is all <em>relative</em>). So if we have 3 loops, we would have 3 time-units. And with 1000 loops, 1000 time-units.</p><blockquote>n loops through an array results in n time-units, which is O(n).</blockquote><pre>array = [1, 2, 3, 5] #4 elements = 4 loops = 4 time-units<br>array2 = [1, 4, 6, 2, 5, 7] #6 elements = 6 loops = 6 time-units</pre><pre>array.each do |element| <br>  puts element <br>end </pre><h3>O(log n)</h3><p>Now this is where things start to get interesting! A O(log n) notation means that as the array grows in the size, the time needed to complete starts to taper off. Did you ever have to graph a log function in high school algebra? This is exactly what’s happening here. You might be thinking — what kind of method does this apply to?</p><p>The most frequently cited example is binary search. If you’d like to read more about binary search and binary search trees, please read this amazing blog post <a href="https://medium.com/basecs/leaf-it-up-to-binary-trees-11001aaf746d">here</a>. The basic gist of binary search goes like this:</p><p>Imagine you have a dictionary and you’re looking for the word “notation”. It would take forever to flip through every page until you get to that, wouldn’t it? Instead, any sane human would probably open the dictionary somewhere in the middle, skipping half of the dictionary. This is the basic idea of binary search — in a sorted array, I can look at the middle integer and drop half of the array because I know my number is not in there.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FWbdMEyP252goM%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Falgorithm-WbdMEyP252goM&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FWbdMEyP252goM%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c8f6e0abfc5874f23d16798034f9740/href">https://medium.com/media/0c8f6e0abfc5874f23d16798034f9740/href</a></iframe><p>It may be a little hard to imagine how this can be a O(log n) method, but think about this: If I have an array of 1000 numbers and an array of 2000 numbers, it only takes <strong>one</strong> more step to cut that in half. The same goes for 1 million and 2 million. The power of that is pretty amazing. So while the array may grow significantly in size, the amount of steps or time-units it takes grows minimally as get larger and larger. In fact, at worst, the method will take log n steps to find the given integer.</p><h3>O(n log n)</h3><p>These are getting worse and worse to look at, aren’t they? O(n log n ) can be a little confusing but, as always, let’s look at an example. Have you heard of merge sort?</p><p>It’s a great little sort method that uses recursion and the divide and conquer technique to sort an array of numbers. Here’s a short gif to explain the concept, read on if you just want a tldr;</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5uqt8lIQ7W6Ck%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Falgorithm-5uqt8lIQ7W6Ck&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F5uqt8lIQ7W6Ck%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="261" frameborder="0" scrolling="no"><a href="https://medium.com/media/33f68db4ba82ac82e54e9594c11317be/href">https://medium.com/media/33f68db4ba82ac82e54e9594c11317be/href</a></iframe><p>The basic idea is that merge sort recursively splits an array until the array is a single element — one element has to be sorted, right? It then compares that element to another one element array, and <em>merges</em> them together. It continues this, merging a two element array with a two element, then 4 with 4, etc. until we get a whole array back that’s sorted.</p><p>It’s a O(n log n) notation method because the splitting part(similar to binary search, where you’re splitting things in 2), takes log n. Comparing the numbers and merging is the extra n, as the worst case scenario is you have to compare each number. Confused? Here’s a few links that may help you out:</p><p><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwi-g8Do3Z3XAhWH7IMKHdSCCkcQFggwMAE&amp;url=https%3A%2F%2Fmedium.com%2Fbasecs%2Fmaking-sense-of-merge-sort-part-1-49649a143478&amp;usg=AOvVaw1ZTJ_hQT5Vwd03ZWSYfrxY">Basecs Merge Sort Part 1</a> | <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwi-g8Do3Z3XAhWH7IMKHdSCCkcQFggqMAA&amp;url=https%3A%2F%2Fmedium.com%2Fbasecs%2Fmaking-sense-of-merge-sort-part-2-be8706453209&amp;usg=AOvVaw1fHW_ic_vSxYNlel9wIC5z">Basecs Merge Sort Part 2</a></p><h3>O(<strong>N²</strong>)</h3><p>If your method is O(n²), don’t even think about scaling it. This is sort of the opposite of O(log n), the time needed just gets worse and worse as more numbers are added. An example is below, my implementation of the notorious and hated bubble sort:</p><pre>def bubble_sort(array)<br>  #use this variable as a flag<br>  sorted = false</pre><pre>until sorted<br>    #set sorted each time to true, so the loop will finish if no swaps are done<br>    sorted = true<br>    for i in 1..array.length - 1<br>      #compares each pair in the array<br>      if array[i - 1] &gt; array[i]<br>        #put up the flag so the iteration will continue<br>        sorted = false<br>        #swap the two elements<br>        array[i - 1], array[i] = array[i], array[i - 1]<br>      end<br>    end<br>  end<br>  array<br>end</pre><p>So why does the O notation grow exponentially? Well, notice that there are <strong>2</strong> for loops running. So for each number added, it not only adds a main loop but also a subloop that has to run through every other number. If you have 10 numbers and add an element, you now have to run 1 more main loop and (potentially) 10 <em>more</em> subloops. 1 element added 11 loops! Now imagine if that array has 1000 elements. These kind of methods should <em>only</em> <em>ever </em>be saved for very small datasets, because they can quickly turn into a disaster.</p><h3>The Big O No (way, I get it!)</h3><p>Hopefully this quick primer to Big O Notation gave you a little bit of background and understanding into why developers use Big O Notation. It’s a useful skill to conceptualize time complexity; and it’s definitely something you should keep in mind while writing code.</p><p>If you’re interested in seeing some more common sorting algorithms and trying to analyze time complexity, see <a href="https://github.com/slin12/sorting-algorithms">here</a> for my implementations in Ruby.</p><p>For more about algorithms or data structures, I’ve fallen in love with <a href="https://medium.com/basecs">Basecs</a>, an amazing primer to basic CS fundamentals that explains things succinctly and clearly.</p><h3>Sources</h3><ul><li><a href="http://bigocheatsheet.com/">Know Thy Complexities!</a></li><li><a href="https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/">A beginner&#39;s guide to Big O notation</a></li><li><a href="https://www.interviewcake.com/article/java/big-o-notation-time-and-space-complexity">Big O Notation | Interview Cake</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbfe0e54ab21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Mystery of #inject in Ruby]]></title>
            <link>https://medium.com/@shirleyl/the-mystery-of-inject-in-ruby-d7fe6d6faed7?source=rss-d97a0273c051------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7fe6d6faed7</guid>
            <category><![CDATA[enumerable]]></category>
            <category><![CDATA[beginner-ruby]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shirley Lin]]></dc:creator>
            <pubDate>Thu, 12 Oct 2017 15:24:03 GMT</pubDate>
            <atom:updated>2017-10-12T15:24:03.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*9hd_8qR0CMZ8L0pVbFLjDw.png" /></figure><p>Of all the enumerables in Ruby, I think #inject is the most misunderstood. I mean, who knows what’s going on when you type something like [1,2,3].inject(:+)? I don’t — I just use it because I know it works. And that’s the only reason I would ever reach for inject, but I’ve since discovered a few neat things that make a case for #inject.</p><h3>So… How does #Inject work?</h3><p>The most common example that you will see #inject being used in the wild is to run through an array and sum numbers up. This is what that looks like:</p><pre>[1,2,5,7,3].inject(0) {|sum, num| sum += num}</pre><p>Note the 0 in this example; that can be changed out to another number (say, 10), in which case the starting sum will be 10 and all the numbers in the array will be added to that. This same structure can be used to multiply all numbers together, or subtract them.</p><p>The basic of idea of inject is that you pass in what is frequently called the ‘memo’ — something that holds whatever you do to all the elements in the array or hash. This memo can be a number, like above, or it can itself be an array or hash. Then, you pass in a block where the first variable is the memo, the second is the element in the object. This can be confusing, which is why you oftentimes only see#inject used in cases like above. Let’s take a look at a few other ways #inject can be used.</p><h3><strong>Chain #map and #select</strong></h3><p>Take a look at this block of code:</p><pre>[1, 5, &quot;dog&quot;, :yes, 6, 1000, &quot;three-hundred&quot;].select {|item| item.is_a?(Fixnum)}.map {|number| number ** 3}</pre><p>There’s nothing inherently wrong with that — it works and it’s probably what I would have reached for if given this problem. This is what that looks like using #inject:</p><pre>[1, 5, &quot;dog&quot;, :yes, 6, 1000, &quot;three-hundred&quot;].inject([]) do |memo, value|<br>  memo &lt;&lt; value ** 3 if value.is_a?(Fixnum) <br>  memo<br>end</pre><p>In terms of readability, I think inject offers a lot. It allows you to perform operations on the object you’re passing in — and return a whole new object.</p><h3>#inject on Hashes</h3><p>While #inject works the same way on hashes, there is one little trick that makes it easier to use on a hash. When inject passed over each key-value pair in a hash, it converts it first into an array.</p><pre>{&quot;one&quot; =&gt; 1, &quot;two&quot; =&gt; 2, &quot;three&quot; =&gt; 3}.inject({}){|memo, hash| memo}</pre><p>To call on the key value of the hash, you would need to use hash.first, and to call on the value of the hash you would need to use hash.last. And easier way to accomplish this is to declare two variables for the hash inside your block. See below:</p><pre>{&quot;one&quot; =&gt; 1, &quot;two&quot; =&gt; 2}.inject({}){|memo, (key, value)| memo}</pre><p>Now you can easily call key or value in your block, making your code much more readable.</p><h3>Using #inject to create Hashes</h3><p>A great use for #inject is to create hashes. Say, for example, you have two arrays that you want to link up into a hash.</p><pre>a = [&quot;Sally&quot;, &quot;Beatrice&quot;, &quot;Bob&quot;, &quot;Molly&quot;]<br>b = [&quot;421-4921&quot;, &quot;293-1839&quot;, &quot;104-1273&quot;, &quot;483-2894&quot;]</pre><p>You could iterate create a new hash, iterate over the first array (maybe with an index), and add each key-value pair to the hash you first created. Or, you could do it in one step with #inject:</p><pre>a.inject({}) do |memo, name| <br>  memo[name] = b[a.index(name)] <br>  memo<br>end</pre><h3>So when should I use #inject?</h3><p>Use #inject if you need to sum all items up, like it’s usually used. Also use #inject if you find yourself first creating an array or hash and then pushing while iterating. Use #inject if you need to create a hash and perform operations while doing it. I find #inject quite flexible, and it has a lot more power than I originally thought. So next time you’re feeling a little tired of your standbys of #each and #map, think about using #inject in your program!</p><h3>Sources</h3><ul><li><a href="https://apidock.com/ruby/Enumerable/inject">inject (Enumerable) - APIdock</a></li><li><a href="http://blog.jayfields.com/2008/03/ruby-inject.html">Ruby: inject</a></li><li><a href="https://stackoverflow.com/questions/710501/need-a-simple-explanation-of-the-inject-method">Need a simple explanation of the inject method</a></li><li><a href="https://codequizzes.wordpress.com/2013/07/16/rubys-inject-method/">Ruby&#39;s inject method</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7fe6d6faed7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>