<?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 Ed Huang on Medium]]></title>
        <description><![CDATA[Stories by Ed Huang on Medium]]></description>
        <link>https://medium.com/@_edhuang?source=rss-8d79c17fe739------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TsSLHIWUzBq6Q1pjj2Boxw.jpeg</url>
            <title>Stories by Ed Huang on Medium</title>
            <link>https://medium.com/@_edhuang?source=rss-8d79c17fe739------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:18:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_edhuang/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[JS Bubble Bubble Bubble]]></title>
            <link>https://medium.com/@_edhuang/js-bubble-bubble-bubble-8d0e7dd7a069?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d0e7dd7a069</guid>
            <category><![CDATA[event-propagation]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 01:38:31 GMT</pubDate>
            <atom:updated>2019-09-05T01:38:31.230Z</atom:updated>
            <content:encoded><![CDATA[<p>JS Event Propagation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*ozYATcM7bH5rFatGlYowMg.jpeg" /></figure><blockquote>Interviewer: Are you familiar with event propagation?<br>Me: uh Yeah, click events, and when something else clicks?<br>Interviewer: Can you explain it to me please, Why is it important?<br>Me: …</blockquote><p>Long time ago, this was literally a conversation I had. Since then I’ve gotten much more familiar with how events work with LOL. Event propagation is something that comes up a lot in interviews. They’re also really important in frontend development, so lets dive in.</p><h3>HTML</h3><pre>&lt;div class=&quot;container&quot;&gt;<br>  &lt;ul class=&quot;list&quot;&gt;<br>    &lt;li class=&quot;item&quot;&gt;A&lt;/li&gt;<br>    &lt;li class=&quot;item&quot;&gt;B&lt;/li&gt;<br>    &lt;li class=&quot;item&quot;&gt;C&lt;/li&gt;<br>  &lt;/ul&gt;<br>&lt;/div&gt;</pre><h3>JS</h3><pre>$(&#39;.container&#39;).on(&#39;click&#39;, () =&gt; {<br>  console.log(&#39;container clicked.&#39;);<br>})</pre><pre>$(&#39;.list&#39;).on(&#39;click&#39;, (e) =&gt; {<br>//     e.stopPropagation();<br>  console.log(&#39;list clicked.&#39;);<br>})</pre><pre>$(&#39;.item&#39;).on(&#39;click&#39;, (e) =&gt; {<br>//   e.stopPropagation();<br>  console.log(&#39;item clicked.&#39;);<br>})</pre><h3>CSS</h3><p>Some simple CSS</p><pre>.container {<br>  background: blue;<br>  padding: 10px;<br>}</pre><pre>.list {<br>  background: pink;<br>    width: 40px;<br>  height: 40px;<br>    padding: 5px;<br>}</pre><pre>.item {<br>  background: green;<br>  width: 20px;<br>  height: 20px;<br>}</pre><h3>Result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*0mNl_mTF2sCtauiqS3uRhA.png" /><figcaption><a href="https://jsbin.com/kibilotate/edit?html,css,js,console,output">JS Bin example</a></figcaption></figure><p>As you can see, there are three item elements, one list ul and a div container. So question is what happens when you click on the div that wraps the list? Or what happens when you click on the list or the item?</p><p>The answer lies in bubbling. If a child triggers an event (click), it’s parent will also receive the event, and the event will “bubble” all the way to the greatest ancestor. In our example, we have an item &lt; list &lt; container. The container being the greatest ancestor, and the list being the parent of the items.</p><p>In our example JS</p><pre>$(&#39;.item&#39;).on(&#39;click&#39;, (e) =&gt; {<br>//   e.stopPropagation();<br>  console.log(&#39;item clicked.&#39;);<br>})</pre><p>When the item is clicked, the ul.list will also a be called, all the way up to the div.container</p><h3>stopPropagation()</h3><p>So when call the event stopPropagation method e.stopPropagation() inside of the item click callback, You’ll see that the list callback no longer responds to the click event. You’ll also notice that the div.container is not responding either. This is because the event is no longer bubbling up the chain.</p><h3>e.target</h3><p>Differentiating between items in the list is also something that is really important. Every event has a property called target if you add a console log for e.target you’ll see that it’s an object with many of it’s own properties that useful. One in particular is textContent</p><pre>$(&#39;.item&#39;).on(&#39;click&#39;, (e) =&gt; {<br>  e.stopPropagation();<br>  console.log(e.target);<br>})</pre><p>Here we can distinguish whether item A, B, or C are clicked by looking at the e.target.textContent</p><h3>Conclusion</h3><p>There are all sorts of events which is whole other subject on it’s own, but know that events will bubble, and knowing how to use target to distinguish between a list of items is really useful, instead of having to define a click handler for each individual item. Hope that helps, Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d0e7dd7a069" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Bind, Call, and Apply?]]></title>
            <link>https://medium.com/@_edhuang/why-bind-call-and-apply-1a3b19a37cb?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a3b19a37cb</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-call-and-apply]]></category>
            <category><![CDATA[javascript-tutorial]]></category>
            <category><![CDATA[javascript-basics]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Fri, 10 May 2019 06:02:18 GMT</pubDate>
            <atom:updated>2019-05-11T02:23:24.737Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is JavaScript Bind, Call, and Apply?</h3><p>Few days I wrote about <a href="https://medium.com/@_edhuang/what-is-a-javascript-class-36102f6f6c2e">what a Javascript Class</a> is, and how the race of Humans in World of Warcraft can be thought of as a Class, where each individual person is an instance of a class Human.</p><p>Today we’re gonna talk about bind, call, and apply. These are a <strong>MUST</strong> knows for anyone looking to work with javascript. Simply put, bind, call, and apply are different ways of invoking a function. call and apply are the same only in that they take in arguments differently. call takes in arguments as a list, where as apply takes in an arguments as an array. bind, allows you to set the context of this and returns a function. Hopefully this example will help you understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*r3Smjbf7RpFg4bXI.jpg" /><figcaption>For The Horde by Genzoman</figcaption></figure><h3>Tale of Two Races</h3><p>We’ll start of with Humans and Orcs. Each character has name, hitpoints, and levelOfAttack.</p><pre>function Character(name, hitpoints, levelOfAttack, race) {<br>  this.name = name;<br>  this.hitpoints = hitpoints;<br>  this.levelOfAttack = levelOfAttack;<br>  this.race = race;  <br>}</pre><pre>let eenie = new Character(&#39;Ennie&#39;, 110, 10, &#39;Human&#39;);<br>let meenie = new Human(&#39;Meenie&#39;, 200, 20, &#39;Human&#39;);<br>let mo = new Human(&#39;Mo&#39;, 300, 30, &#39;Human&#39;);<br>let myHero = new Human(&#39;Steve&#39;, 400, 50, &#39;Human&#39;);</pre><pre>let orky = new Orc(&#39;Orky&#39;, 100, 50, &#39;Orc&#39;);<br>let orphus = new Orc(&#39;Orphus&#39;, 200, 60, &#39;Orc&#39;);<br>let oracle = new Orc(&#39;Oracle&#39;, 500, 70, &#39;Orc&#39;);</pre><h3>The Attack</h3><p>Each unit will have the ability to attack. It takes an argument called enemy, and will subtract it’s hitpoints by the amount of it’s levelOfAttack.</p><pre>Character.prototype.attack = function(enemy) {<br>  enemy.hitpoints = enemy.hitpoints - this.levelOfAttack;<br>}</pre><pre>orky.attack(eenie);</pre><p>When Orky attacks Eenie, it’s pretty straightforard. Eenie’s hitpoints go down by whatever Orky’s levelOfAttack is. But here we can use bind and do something different.</p><pre>let eenieBorrowsAttack = orky.attack.bind(eenie);</pre><pre>// notice it is not invoked until we () it. </pre><pre>eenieBorrowsAttack(orky)<br>// We&#39;ll explicitly pass in an argument and invoke it.</pre><pre>// or</pre><pre>let eenieBorrowsAttack = orky.attack.bind(eenie, orky);<br>// We can pass in the argument alongside the bind.</pre><pre>eenieBorrowsAttack()</pre><pre>// and invoke it here.</pre><p>So <strong>BIND </strong>is just a way of letting the function attack, know what is this and who is enemy . We took a method that belonged to Orky, and borrowed it for later. bind returns the method with the given context.</p><h3>Blood Lust</h3><p>In Warcraft there’s a spell which allows you to increase your level of attack for a given amount of time. Orcs are pretty famous for this spell.</p><p>For fun, and the sake of demonstration we’re taking in two arguments a password, and a name. These will be used to show you what the different of call and apply are. If the character is an Orc he’ll be leveled up 20, for the given period.</p><pre>orky.invokeBloodLust.call(orphus, &#39;Wrong password&#39;);<br>orky.invokeBloodLust.call(oracle, &#39;Nada&#39;);<br>// Orphus and Oracle will have +20 levelOfAttack for 10 seconds</pre><pre>orky.invokeBloodLust.apply(myHero, [&#39;Captain&#39;, &#39;Steve&#39;]);<br>orky.invokeBloodLust.apply(myHero, [&#39;AABB&#39;, &#39;Tony&#39;]);<br>// Look at the code to see what happens.<br>// apply takes in an array of arguments. Which will be translated at the methods ...arguments array</pre><p>Here’s the code.</p><pre>Character.prototype.invokeBloodLust = function(password, name) {<br>  let _this = this;<br>  let addedBloodLustAttack = 10;</pre><pre>if (this.type === &#39;Orc&#39;) {<br>    addedBloodLustAttack = 20;<br>  }</pre><pre>if (name === &#39;Steve&#39;) {<br>     console.log(&quot;I&#39;m worthy!!!&quot;);<br>     addedBloodLustAttack = 40;<br>  }</pre><pre>if (password === &#39;AABB&#39;) {<br>  console.log(&quot;You must be Ironman!!!&quot;);<br>  addedBloodLustAttack = 100;<br>  }  <br>  <br>this.levelOfAttack += addedBloodLustAttack;<br> <br>  setTimeout(function() {<br>    _this.levelOfAttack = _this.levelOfAttack -     addedBloodLustAttack;<br>  }, 10000);<br>}</pre><p>Hope that helps! So to conclude, bind call and apply are all all just ways of:</p><p>setting the context of this for a function</p><ol><li>bind is different from call and apply in that it only sets the context of this , and returns a function, Where as call and apply actually invoke the function.</li><li>call and apply are ways of invoking a function, with different ways of passing in arguments. call is a comma separated list, where apply is an array.</li></ol><p><a href="https://jsbin.com/sedafudape/edit?js,console">https://jsbin.com/sedafudape/edit?js,console</a></p><p>Hope that helps! Lemme know if you have any questions, comments, or see any typos or mistakes!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a3b19a37cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is a Javascript Class?]]></title>
            <link>https://medium.com/@_edhuang/what-is-a-javascript-class-36102f6f6c2e?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/36102f6f6c2e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-class]]></category>
            <category><![CDATA[javascript-tutorial]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Thu, 02 May 2019 06:32:17 GMT</pubDate>
            <atom:updated>2019-05-02T06:32:17.374Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qY_P19xP9mhvfMHd.jpg" /><figcaption>Warcraft III Reforged</figcaption></figure><p>If you’re new to programming, or javascript you’ve probably heard of objects, and classes. Understanding what a class is can be difficult, you’ll hear words like “this”, “instances”, “objects”, “instantiated”, “new” etc… So lets dive in!</p><h3>First there was an Object.</h3><p>In Javascript, everything is an Object. Even a function, is considered an Object (but that’s for another day). An object is simply {} two curly braces, and inside there can be bunch of key value pairs:</p><pre>let myHero = {<br>  name: &quot;Khadgar&quot;,<br>  age: 30,<br>  height: 190,<br>  speed: 20,<br>  attack: 10,<br>  hitpoints: 100<br>};</pre><pre>myHero.name; // &quot;Khadgar&quot;<br>myHero.age; // 30</pre><p>So what happens, when we want to create another hero.</p><pre>let mySecondHero = {<br>  name: &quot;Rhonin&quot;,<br>  age: 33,<br>  height: 188,<br>  speed: 25,<br>  attack: 7,<br>  hitpoints: 120<br>};</pre><pre>let yourHero = {<br>  name: &quot;Zaetar&quot;,<br>  age: 55,<br>  height: 50,<br>  speed: 5,<br>  attack: 30,<br>  hitpoints: 200<br>};</pre><p>etc.. <br>As you can see, if we keep doing this. It isn’t very convenient. So in programming we have something called Classes.</p><p><strong>And then there was the Class</strong></p><p>If you think of Humans, as a <strong>Class</strong> and every character as an <strong>instance </strong>we now can do something like this:</p><pre>function Human(name, age, height, speed, attack, hitpoints) {<br>  this.name = name;<br>  this.age = age;<br>  this.height = height;<br>  this.speed = speed;<br>  this.attack = attack;<br>  this.hitpoints = hitpoints;<br>}</pre><pre>// OR With class syntax</pre><pre>class Human {<br>  constructor(name, age, height) {<br>    <strong>this</strong>.name = name;<br>    <strong>this</strong>.age = age;<br>    this.height = height;<br>    this.speed = speed;<br>    this.attack = attack;<br>    this.hitpoints = hitpoints;<br>  }<br>}</pre><pre>let myHero = new Human(&quot;Khadgar&quot;, 30, 190, 20, 10, 100);<br>console.log(myHero.name); // &quot;Khadgar&quot; </pre><p>And now we have something exactly like before. Where now we have an <strong>instance </strong>of a Human. A class is a special type of function that has the ability to create instances with its own unique properties. We can create a new Human object, with the new keyword followed by the Class name with values for the new instance we want to generate.</p><p>Classes can also have methods (functions) that do things.</p><pre>Human.prototype.punch = function(enemy) {<br>  enemy.hitpoints = enemy.hitpoints - this.attack;<br>}</pre><pre>or </pre><pre>class Human {<br>  constructor(name, age, height) {<br>    // same as above ...<br>  }<br>  punch(enemy) {<br>    enemy.hitpoints = enemy.hitpoints - this.attack;<br>  }<br>}</pre><pre>// and then</pre><pre>myHero.punch(yourHero);<br>// your hero now only has 190 hitpoints. </pre><pre>mySecondHero.punch(yourHero);<br>// your hero now only has 183 hitpoints.</pre><h4><strong>What is “<em>this”</em>, all about?</strong></h4><p>So in our punch method, we have this.attack earlier we also had this.name, this.age and a few other properties. this refers to the current instance or (context) of what is being called. So for the example above this would refer to myHero . myHero attack value is 10, and then when used inside of the method to calculate how much damage to take off from the enemy.hitpoint . When mySecondHero.punch(yourHero); is called, this now refers to mySecondHero, and all of mySecondHero’s values will be applied to the method that is being called.</p><p>We could create another Class called Orcs, with different abilities, and properties, where all races, have basic properties, and different methods. But the idea here is that, Different races “Humans”, “Orcs”, and “Elves” can have many instances of each of their own type.</p><p>Hope that helps! comment below if you have any questions, or comments, or corrections.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36102f6f6c2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add a custom attribute to an Ember component.]]></title>
            <link>https://medium.com/@_edhuang/add-a-custom-attribute-to-an-ember-component-81f485f8d997?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/81f485f8d997</guid>
            <category><![CDATA[attributes]]></category>
            <category><![CDATA[ember-tips]]></category>
            <category><![CDATA[ember]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Sat, 24 Feb 2018 05:24:11 GMT</pubDate>
            <atom:updated>2018-02-24T05:24:11.411Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever needed to add a custom attribute to an add-on or helper in Ember.</p><p>It’s actually really easy. All you need to do is reopen the class. You can do this inside an initializer, a controller, component, or actually anywhere you plan on using it. For example, inside a controller:</p><pre>import Ember from &#39;ember&#39;;<br>const { LinkComponent } = Ember;</pre><pre>LinkComponent.reopen({<br>  attributeBindings: [&#39;my-custom-attr&#39;]<br>});</pre><pre>export default Ember.Controller.extend({<br>  appName: &#39;Ember Twiddle&#39;<br>});</pre><p>So now I can do something like this.</p><p>{{#link-to &quot;a-route&quot; my-custom-attr=&quot;Value&quot;}}Check it out!{{/link-to}}</p><p><a href="https://ember-twiddle.com/0e9e34f715c83363ecdaa18b768823ce?openFiles=controllers.application.js%2C&amp;route=%2Fdogs">Here’s a simple twiddle</a>.</p><p>If you inspect the dom you’ll see the output:</p><pre>&lt;a my-custom-attr=&quot;Dogs&quot; href=&quot;/a-route&quot;&gt;Dogs&lt;/a&gt;</pre><p>We’ve had to do this for other add-ons that might not have attributes we need, say for testing.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81f485f8d997" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web scraping Node.js, Chrome, & Puppeteer]]></title>
            <link>https://medium.com/@_edhuang/web-scraping-node-js-chrome-puppeteer-90b4d1a1d816?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/90b4d1a1d816</guid>
            <category><![CDATA[puppeteer]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[chrome]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Wed, 10 Jan 2018 07:38:26 GMT</pubDate>
            <atom:updated>2018-01-10T07:39:03.510Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever want to build your own bot? Now it’s easier than ever with <a href="https://github.com/GoogleChrome/puppeteer">Puppeteer</a>!</p><p>So I was playing around with and and thought I’d share my simple program. This bot will get all the vin numbers off the <a href="http://tesla.com/used">tesla.com/used</a> site. It’s basically three steps.</p><ol><li>Navigate to the site</li><li>Click on a vehicle link</li><li>Grab information off the tabbed page.</li></ol><p>We’ll be using async/await for this so make sure your Node is up to date. I’m using version 8.0.0</p><p>Let’s jump in the code!</p><h4>1. Navigating to the site</h4><pre>const puppeteer = require(&#39;puppeteer&#39;);</pre><pre>async function run() {<br>  let browser = await puppeteer.launch(); // { headless: false }<br>  let pages = await browser.pages();      // To see the browser in<br>                                          // action.</pre><pre>  await pages[0].goto(&#39;<a href="https://tesla.com/used&#39;">https://tesla.com/used&#39;</a>);<br>  // More below...<br>}</pre><pre>run();</pre><p>So this snippet here will create a new browser instance, and then return all the pages(tabs) that belong to it. We’ll grab the 0 indexed page that is created from the browser and go to the site with this page.</p><p><em>NOTE: In the docs it says to use </em><em>browser.newPage(); What I didn’t like about this is that it creates a new tab in your browser, leaving you now with two tabs. One being empty.</em></p><h4><em>2. Clicking all the cars</em></h4><p>So once we land on the page, we want to click on the links of the vehicles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUT_q-ecTMHoWEkTOq2IQg.png" /></figure><pre>let carHandles = await page.$$(&#39;.vehicle-link&#39;);</pre><pre>for (let i = 0; i &lt; carHandles.length; i++) {<br>  carHandles[i].click();<br>}</pre><p>page.$$(selector) will return an array of Element Handles. From the api docs we see there’s a <a href="https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#elementhandleclickoptions">click method</a> that each handle has that will open up a new tab with the car details.</p><p>Unfortunately if you just ran this, it wouldn’t work. Because in order to click on an element it needs to be loaded first. Let’s go ahead and handle this.</p><p>We need to waitForSelector to be loaded.</p><pre>for (let i = 0; i &lt; carHandles.length; i++) {<br>  await page.waitForSelector(&#39;.vehicle-link&#39;);<br>  carHandles[i].click();<br>  // a new tab is created after clicked.</pre><pre>}</pre><h4>3. Grab information off the tabbed page.</h4><p>Next we need to go to each of the newly opened tabs and scrape information off the detail page.</p><p>We’ll go ahead and get pages again like above. We’ll see that we now have more tabs opened in the browser.</p><p>pages = await browser.pages();</p><p>The browser’s pages method will give us an array all of the opened tabs. Unfortunately like selectors we need to make sure that the tab has been created.</p><pre>let count = 0;</pre><pre>while (count &lt; carHandles.length) {<br>  pages = await browser.pages();<br>  count = pages.length;<br>}</pre><p>The number of tabs opened should be the number of car links plus the initial tab that was opened by the browser. This way we keep checking to see if all the tabs have been created until it is one more than the number of links.</p><p><em>NOTE: You could also use browser.on(‘targetCreated’) event to detect if a tab you has been created. As of now, I’m not too sure of any other ways of tracking when all the pages are loaded.</em></p><p>Once we have the opened detailed tabs, we can scrape the information we’re looking for off the page. We’ll use the page.evaluate method to get into the context of the browser, so we can use document.querySelector.</p><pre>let vins = [];</pre><pre>for (let i = 1; i &lt; carHandles.length; i++) {<br>  let vin = await pages[i].evaluate((sel) =&gt; {<br>    return document.querySelector(sel).innerHTML;<br>  }, VIN_SELECTOR);</pre><pre>  vins.push(vin);<br>  await pages[i].close();<br>}</pre><pre>for (let i = 0; i &lt; vins.length; i++) {<br>    console.log(`${i + 1}: ${vins[i]}`);<br>  }</pre><pre>browser.close();</pre><p>VIN_SELECTOR is a variable I created by inspecting the VIN numbers on the detail page. I it should look something like.</p><pre>const VIN_SELECTOR = &#39;#page &gt; div &gt; div.pane-content-constrain &gt; main &gt; div &gt; div &gt; div &gt; div &gt; section.side &gt; aside &gt; p.extra-info &gt; span:nth-child(3)&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yULpRhH9-AZkjeqikqpJGw.png" /></figure><pre>document.querySelector(sel).innerHTML;</pre><p>I return the value to a variable called vin, and then push into the vins array.</p><p>After that we’ll go ahead and close the tab. Once we have all our vins stored in our array, we can console log them. You should then see all the vins from the used cars.</p><p>I hope that helps. Here’s a link to the actual code. <br><a href="https://gist.github.com/dwerdo/9d6761d203964162561b3349b64c71df">https://gist.github.com/dwerdo/9d6761d203964162561b3349b64c71df</a></p><p>Hope that helps. Have fun building bots!</p><p><strong>This was inspired by </strong><a href="https://medium.com/@e_mad_ehsan/getting-started-with-puppeteer-and-chrome-headless-for-web-scrapping-6bf5979dee3e"><strong>Emad Ehsan’s Getting started with Puppeteer.</strong></a><strong> Check it out for a great tutorial on puppeteer!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90b4d1a1d816" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phoenix Tutorial — Simple CRUD With Generator]]></title>
            <link>https://medium.com/@_edhuang/phoenix-post-request-87c79370cc20?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/87c79370cc20</guid>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[phoenix-tutorial]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Tue, 18 Apr 2017 11:52:31 GMT</pubDate>
            <atom:updated>2017-04-18T15:06:50.527Z</atom:updated>
            <content:encoded><![CDATA[<p>This is assuming you’ve already installed elixir, phoenix and all dependencies.</p><p>mix phoenix.new book-app</p><p>Follow the instructions that say, cd into the directory and then run the ecto.migrate command.</p><p>After that, you can run the json generator.</p><p>mix phoenix.gen.json Book books title:string author:string<br><br>This command does a bunch of stuff for you. It creates your model, your router path, views, and everything you need in your controller.</p><p><strong>GET Request </strong><br>Only thing to notice is that it will generate your path under <strong>api</strong><br>so you need to point your browser or Postman to i.e. <br>http://localhost:4000/<strong>api</strong>/books</p><pre>#router.ex<br>scope “/api”, Bookswopp do<br> pipe_through :api<br> resources “/books”, BookController, except: [:new, :edit]<br>end</pre><p><strong>Post Request<br></strong>If you type the command mix phoenix.routes you should see something like this.</p><pre>page_path  GET     /               Bookswopp.PageController :index</pre><pre>book_path  GET     /api/books      Bookswopp.BookController :index</pre><pre>book_path  GET     /api/books/:id  Bookswopp.BookController :show</pre><pre>book_path  POST    /api/books      Bookswopp.BookController :create</pre><pre>book_path  PATCH   /api/books/:id  Bookswopp.BookController :update</pre><pre>PUT     /api/books/:id  Bookswopp.BookController :update</pre><pre>book_path  DELETE  /api/books/:id  Bookswopp.BookController :delete</pre><p>notice that book_path POST is /api/books and there’s an action called :create</p><p>In postman select <strong>POST </strong>in your body select <strong>raw </strong>and then <strong>make sure your </strong>format is <strong>JSON.</strong></p><p>body should be something like this:</p><p>{“book&quot;: {&quot;title&quot;: &quot;Learning Phoenix&quot;, &quot;author&quot;: &quot;Chris Mccord&quot;}}</p><p>Notice the first Key is called “book”. In our controller the create action will be expecting a <a href="http://elixir-lang.org/getting-started/keywords-and-maps.html#maps">Map</a> with this key in place.</p><p>def create(conn, %{“book” =&gt; book_params}) do</p><p>If you don’t have “book” inside your body request you’ll get an error because the create action is looking for the keyword “book” inside the Map argument.</p><p><strong>PUT Request<br></strong>PUT /api/books/:id</p><p>:id should be <strong>1</strong>, If you’ve followed along this far. If you haven’t already made POST request this won’t work because you won’t have any records in your database. Again make sure you use JSON format the body request will need “book” as the key. We’ll go ahead and change the author. <br>{“book&quot;: {&quot;title&quot;: &quot;Learning Phoenix&quot;, &quot;author&quot;: &quot;Bruce Tate&quot;}}</p><p><strong>DELETE Request<br></strong>In postman simply DELETE /api/books/:id<br>Once you do a GET on /api/books your record should no longer show up.</p><p>Hope this helped anybody out there.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87c79370cc20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript — For, Foreach, and Callbacks]]></title>
            <link>https://medium.com/@_edhuang/javascript-for-foreach-and-callbacks-206288604656?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/206288604656</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[callback]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Thu, 05 Jan 2017 18:33:37 GMT</pubDate>
            <atom:updated>2017-01-05T18:33:37.690Z</atom:updated>
            <content:encoded><![CDATA[<p>Confused about higher order functions? Callbacks, first-class objects? In this short post I hope to explain these in a simpler way.</p><p>Most people are familiar with a for loop and from there they can move on to the foreach. If you can understand how the foreach function works on an array then you already know what a callback is, you just might not know it yet.</p><h4>The For loop</h4><p>Here we have:</p><ul><li>an array of five letters.</li><li>and function that will log the argument passed in</li><li>for loop</li></ul><pre>var myArray = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;];</pre><pre>function currentLetter(letter) {<br>  console.log(&#39;The current letter is: &#39; + letter);<br>}</pre><pre>for (var i = 0; i &lt; myArray.length; i++) {<br>  currentLetter(myArray[i]);  <br>}</pre><p>Easy peasy right, pretty straight forward right? So the function currentLetter will be called five times because the array has five elements.</p><h4>The Foreach loop</h4><p>We could do the same thing with a forEach loop.<br>Here we’ll use an <a href="http://www.w3schools.com/js/js_function_definition.asp"><strong>anonymous function</strong></a> to console log the letters.</p><pre>myArray.forEach(function(value) {<br>  console.log(&#39;The current letter is: &#39; + value;<br>});</pre><p>Or… using the currentLetter function from up above.</p><pre>myArray.forEach(currentLetter);</pre><p>If you’re confused about how this works, know that the forEach function expects a function (callback function) as parameter and will implicitly call it for each element in the array. It probably looks something like this:</p><pre>function forEach(callback) {<br>  for (var i = 0; i &lt; theCurrentArray.length; i++) {<br>    var value = theCurrentArray[i];    <br>    callback(value, i, theCurrentArray);  <br>  }<br>}</pre><p>This is <strong>NOT </strong>how the actual forEach is implemented, but hopefully it shows you that inside the forEach method, it is actually executing the function (callback function) that is being passed in.</p><p>forEach, map, filter, button.click, save, etc… In a lot of code you’ll see code where methods expect a callback function.</p><pre>myArray.forEach(callback); //For each element do something</pre><pre>button.click(callback); //Click then do something</pre><pre>server.save(callback); //After save do something</pre><p>Hopefully you get the point. And really, that’s all there is a to a callback. It’s just a function that gets passed in as a parameter and executed within that function body.</p><p>Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=206288604656" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why your next startup should be built with Ember.js]]></title>
            <link>https://medium.com/@_edhuang/why-your-next-startup-should-be-built-with-ember-js-2b6b2e9b6c0f?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b6b2e9b6c0f</guid>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Sat, 10 Sep 2016 05:02:55 GMT</pubDate>
            <atom:updated>2016-09-10T05:04:34.596Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKPCYgK4BbRWjE0dwCnsSw.jpeg" /></figure><p>As a front-end developer I can list so many reasons why I love using ember.js. However with Ember’s testing environment and mocking servers with Ember Mirage, I believe it takes the cake.</p><h3>Testing with Qunit</h3><p>Testing comes right out of the box with ember-cli. Your developers can create end to end tests (acceptance tests), component tests, and unit tests all with ember-cli. In Ember there’s no setup of third party libraries like Karma, Jasmine, or Mocha. And even better, there’s no build tools like Grunt or Gulp. Writing tests can be hard enough as is, but having to worry about testing environments and configurations just adds to the complexity. Luckily in Ember, whenever we generate a resource, model, or component ember-cli sets up all the tests and does the scaffolding for you. That leaves your developers with more time to code and less time configuring the app. Hence Ember’s motto, “Convention over configuration.”</p><h3>Mock servers in Mirage</h3><p>As with all projects there comes a time when the frontend needs to integrate with the backend. Unfortunately this usually doesn’t go as smoothly as planned. Many times resources are limited, backend and frontend might be working on completely separate projects. All that’s in place is a Jira ticket and a half backed api contract. Features are added, requirements change, and as time goes by we discover other missing pieces. This leads to changes on both on the backend and frontend which can be time consuming and expensive. With Mirage, the frontend can mock out the backend server with confidence and get pretty close to the real thing. In the past frontend devs usually had a json stub, some fixture data, or if they were lucky a fake api to consume. These solutions were brittle, tedious, and hard to change. Unfortunately, many times they didn’t even represent the end product. With Mirage, we now have a lot more flexibility (and responsibility) building out our own mock servers.</p><h3>Conclusion</h3><p>Ember is built on top of the tried and true principles of Rails. Scaffolding, conventions, and testing are all really similar. It’s no wonder because contributors to Rails are actually core members on the Ember team. With testing in place your app is less prone to bugs, and with mirage your development process is going to be more streamlined and efficient. Give it a try, you won’t regret it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b6b2e9b6c0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ember mut helper — Let’s mutate!]]></title>
            <link>https://medium.com/@_edhuang/ember-mut-helper-lets-mutate-acdf6b58a0df?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/acdf6b58a0df</guid>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Wed, 17 Aug 2016 01:56:25 GMT</pubDate>
            <atom:updated>2019-05-09T22:44:56.124Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*21XIuhyJqnMuE5-Xke0GsA.jpeg" /><figcaption>mutant ninja tutles!</figcaption></figure><p>So if been using ember since 1.13 you’ve seen this mut for a while. I thought I’d do a deep dive and hopefully share some insights.</p><p>Here’s a link to the official Ember doc:<br><a href="https://api.emberjs.com/ember/release/classes/Ember.Templates.helpers/methods/mut?anchor=mut">https://api.emberjs.com/ember/release/classes/Ember.Templates.helpers/methods/mut?anchor=mut</a></p><p>“The mut helper lets you <strong>clearly specify</strong> that a child Component can update the (mutable) value passed to it, which will <strong>change the value of the parent component</strong>.”</p><h3>Mut by itself.</h3><pre>&lt;!-- parent.hbs --&gt;<br>{{clickable-ninja-turtle mutableTurtle=(mut turtle)}}</pre><pre>&lt;!-- clickable-ninja-turtle.hbs --&gt;<br><br>//clickable-ninja-turtle.hbs<br>&lt;button&gt;Transform!!!&lt;/button&gt;</pre><p>With that, inside my component I can do something like this:</p><pre>//components/parent.js<br>export default Component.extend({<br>  turtle: &#39;I\&#39;m green!&#39;<br>});</pre><pre><br>//components/clickable-ninja-turtle.js<br>export default Component.extend({<br>  click: function() {<br>    this.set(&#39;mutableTurtle&#39;, &#39;I\&#39;m  a ninja!&#39;);<br>  }<br>});</pre><p>Now inside turtle power, my turtle property should have the value of “I’m a ninja!”</p><h3>Including the “action” helper</h3><p>What seems to be more popular is using the mut helper in conjunction with an actions helper. This is a shortcut, and saves you from having to define an action if your main goal is just to update a property.</p><pre>// Parent.hbs<br>&lt;button onclick={{action (mut turtle) &quot;I&#39;m a ninja&quot;}}&gt;Transform!!!&lt;/button&gt;</pre><p>What’s happening is that the actions helper is turning our attribute into a function that takes in an implicit value and updates it with what’s passed in.</p><p>Our turtle has now become a ninja.</p><h3>Conclusion</h3><p>This is all to keep in line with Ember DDAU convention so that we don’t change things downstream, unless we are intentionally doing so.</p><p>Hope that helps. Would love to hear any feedback or insights. Go team ember!</p><p>Here’s a twiddle:<br><a href="https://ember-twiddle.com/bbafa870cce358a33e50f7ceedb0f286">Ninja turtle twiddle</a></p><h4>Update:</h4><p>Thanks to <a href="http://thejsguy.com/">thejsguy</a>. The last section regarding “including the actions helper” the mut helper needs to be wrapped by an action helper for it to work. This essentially turns mutableTurtle into a function.</p><p>Here’s a <a href="https://gist.github.com/ilovethebends/0c5c71438738efb806dc9742e29bc583">twiddle</a> of the example.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acdf6b58a0df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CCI 1.2 Check Permutations]]></title>
            <link>https://medium.com/@_edhuang/cci-check-permutations-e83dfd05f0b6?source=rss-8d79c17fe739------2</link>
            <guid isPermaLink="false">https://medium.com/p/e83dfd05f0b6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ed Huang]]></dc:creator>
            <pubDate>Sun, 22 May 2016 15:32:13 GMT</pubDate>
            <atom:updated>2016-05-24T17:51:04.392Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a two strings, check to see if they are permutations of each other.</p><p>A permutation is defined as, “a way, especially one of several possible variations, in which a set or number of things can be ordered or arranged.”</p><p>So for us we’ll use a string for example. A string of characters can be rearranged in however many ways.</p><p>In CCI 1.2 the question asks given two strings check to see if one is a permutation of the other. Given that this is the chapter on arrays and hash tables lets solve this problem using a hash table. This is similar to CCI 1.1 (isUnique).</p><p>Step 1: Check to see if the strings are the same length. If this is not true we can return false.</p><p>Step 2: Count each character in the first string. We’ll use a hash table and use each character in the first string as a hash key. For each of these keys, we then increment.</p><p>Step 3: Using the second string we can then decrement the count using the same idea.</p><p>Step 4: Go back through the first string and see if each value for the hash is equal to zero. If they are all zero we know we have a permutation.</p><pre>function checkPermutation(str1, str2) {<br>  if(str1.length !== str2.length) {<br>    return false;<br>  }</pre><pre>  var myHash = [];</pre><pre>  for(var i = 0; i &lt; str1.length; i++) {<br>    if(myHash[str1[i]]) {<br>      myHash[str1.charAt(i)]++;<br>    } else {<br>      myHash[str1.charAt(i)] = 1;<br>    }<br>   }</pre><pre>  for(i = 0; i &lt; str2.length; i++) {<br>    myHash[str2.charAt(i)]--;<br>  }</pre><pre>  for(i in myHash) {<br>    if(myHash[i] !== 0) {<br>      return false;<br>    }<br>  }<br>  return true;<br>}</pre><p>And that’s it. The other method of seeing if they’re permutations is to sort both the strings and then just compare.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e83dfd05f0b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>