<?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 Amos Shin on Medium]]></title>
        <description><![CDATA[Stories by Amos Shin on Medium]]></description>
        <link>https://medium.com/@amosshin?source=rss-af5958adf2d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VEYF6E-mZi6NztP1</url>
            <title>Stories by Amos Shin on Medium</title>
            <link>https://medium.com/@amosshin?source=rss-af5958adf2d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:15:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amosshin/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[Challenges to test your skills!]]></title>
            <link>https://medium.com/@amosshin/challenges-to-test-your-skills-dbb61067a0f6?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbb61067a0f6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[code-challenge]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Sun, 12 May 2019 16:32:03 GMT</pubDate>
            <atom:updated>2019-05-12T16:32:03.621Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you want some challenges to test your coding skills?</p><p>I wrote a few blogs so you can challenge yourself to see if you know a certain coding language!</p><p><a href="https://medium.com/@amosshin/ruby-bakery-challenge-d1bcbe133271">Ruby (Bakery)</a></p><p><a href="https://medium.com/@amosshin/rails-superheroine-challenge-24785be7230d">Ruby on Rails (Superheroine)</a></p><p><a href="https://medium.com/@amosshin/javascript-beer-challenge-ae334aff50e5">Javascript (Beers)</a></p><p><a href="https://medium.com/@amosshin/react-bookshelf-challenge-c0e95284559f">React (Bookshelf)</a></p><p>Good luck and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbb61067a0f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Bookshelf Challenge]]></title>
            <link>https://medium.com/@amosshin/react-bookshelf-challenge-c0e95284559f?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e95284559f</guid>
            <category><![CDATA[books]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[bookshelf]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Sun, 12 May 2019 16:28:28 GMT</pubDate>
            <atom:updated>2019-05-12T16:28:28.193Z</atom:updated>
            <content:encoded><![CDATA[<p>As before, this is to test if you know React. If you can finish this in 90 minutes, you’re golden.</p><ol><li>Fetch to `<a href="http://localhost:3005/books%60">http://localhost:3005/books`</a>. You should get a response that is an array of multiple book objects that look like this:<br>```<br>{<br> “id”: 1,<br> “title”: “The Great Gatsby”,<br> “author”: “F. Scott Fitzgerald”,<br> “img”: “<a href="https://mppl.org/wp-content/uploads/0-214x300.jpg">https://mppl.org/wp-content/uploads/0-214x300.jpg</a>&quot;<br>}<br>```</li></ol><p>2. Render a list of books that show the book title and book img<br>3. Clicking on a book in the Book List should add it to the Book Shelf<br>4. Clicking on a book in the Book Shelf should remove it from the Book Shelf<br>5. Add a controlled form that allows the user to add a book to the Book List (this should _NOT_ persist)<br>6. BONUS: Each book can only be added to Book Shelf one time (Book Shelf should not have duplicate books)</p><h3>Answer</h3><p>(App.js)</p><pre>import React, { Component } from &quot;react&quot;;<br>import &quot;./App.css&quot;;<br>import BookList from &quot;./containers/BookList&quot;;<br>import Bookshelf from &quot;./containers/Bookshelf&quot;;</pre><pre>class App extends Component {</pre><pre>state = {<br>    books: [],<br>    bookshelf: []<br>  }</pre><pre>componentDidMount() {<br>    fetch(&#39;<a href="http://localhost:3005/books&#39;">http://localhost:3005/books&#39;</a>)<br>      .then(res =&gt; res.json())<br>      .then(books =&gt; {<br>        this.setState({<br>          books<br>        })<br>      })<br>  }</pre><pre>handleClick = (obj) =&gt; {</pre><pre>console.log(&#39;ADD FUNCTION&#39;, obj)<br>    const updatedBooks = [...this.state.bookshelf, obj]</pre><pre>this.setState({<br>      bookshelf: updatedBooks<br>    })<br>  }</pre><pre>handleRemoveClick = (obj) =&gt; {<br>    console.log(&#39;REMOVE FUNCTION&#39;, obj)<br>    const removedItemFromBookshelf = this.state.bookshelf.filter(bookshelf =&gt; {<br>      return bookshelf.id !== obj.id<br>    })<br>    this.setState({<br>      bookshelf: removedItemFromBookshelf<br>    })<br>  }</pre><pre>handleSubmit = (e, obj) =&gt; {<br>    e.preventDefault()<br>    const submitted = [...this.state.books, obj]<br>    this.setState({<br>      books: submitted<br>    }, () =&gt; console.log(this.state))<br>  }</pre><pre>render() {<br>    return (<br>      &lt;div className=&quot;book-container&quot;&gt;<br>        &lt;BookList books={this.state.books} handleClick={this.handleClick} handleSubmit={this.handleSubmit} className=&quot;book-list&quot;/&gt;</pre><pre>&lt;Bookshelf bookshelf={this.state.bookshelf} handleRemoveClick={this.handleRemoveClick} className=&quot;book-shelf&quot;/&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><pre>export default App;</pre><p>(Booklist.js)</p><pre>import React from &quot;react&quot;;<br>import Book from &quot;../components/Book&quot;;<br>import Form from &quot;../components/Form&quot;;</pre><pre>const BookList = (props) =&gt; {</pre><pre>const loadBookCards = props.books.map(books =&gt; {<br>      return &lt;Book {...books} handleClick={props.handleClick} key={books.id}/&gt;<br>    })</pre><pre>return (<br>      &lt;div className=&quot;book-list&quot;&gt;<br>        &lt;h1&gt;Book List&lt;/h1&gt;<br>        &lt;Form handleSubmit={props.handleSubmit}/&gt;<br>        &lt;ul&gt;{ loadBookCards }&lt;/ul&gt;<br>      &lt;/div&gt;<br>    );</pre><pre>}</pre><pre>export default BookList;</pre><p>(Bookshelf.js)</p><pre>import React from &quot;react&quot;;<br>import Book from &quot;../components/Book&quot;;<br>import Form from &quot;../components/Form&quot;;</pre><pre>const BookList = (props) =&gt; {</pre><pre>const loadBookCards = props.books.map(books =&gt; {<br>      return &lt;Book {...books} handleClick={props.handleClick} key={books.id}/&gt;<br>    })</pre><pre>return (<br>      &lt;div className=&quot;book-list&quot;&gt;<br>        &lt;h1&gt;Book List&lt;/h1&gt;<br>        &lt;Form handleSubmit={props.handleSubmit}/&gt;<br>        &lt;ul&gt;{ loadBookCards }&lt;/ul&gt;<br>      &lt;/div&gt;<br>    );</pre><pre>}</pre><pre>export default BookList;</pre><p>(Book.js)</p><pre>import React from &quot;react&quot;;</pre><pre>const Book = props =&gt; {<br>  return (<br>    &lt;div onClick={() =&gt; props.handleClick(props)}&gt;<br>      &lt;h2&gt;{props.title}&lt;/h2&gt;<br>      &lt;img src={props.img} alt={props.title} /&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>export default Book;</pre><p>(Form.js)</p><pre>import React from &quot;react&quot;;</pre><pre>class Form extends React.Component {</pre><pre>state = {<br>    title: &#39;&#39;,<br>    img: &#39;&#39;<br>  }</pre><pre>handleChange = (e) =&gt; {<br>    this.setState({<br>      [e.target.name]: e.target.value<br>    }, console.log(this.state))<br>  }</pre><pre>render() {<br>    return &lt;form onSubmit={(e) =&gt; this.props.handleSubmit(e, this.state)}&gt;<br>      &lt;input onChange={this.handleChange} type=&quot;text&quot; name=&quot;title&quot; placeholder=&quot;Title&quot; /&gt;<br>      &lt;br/&gt;<br>      &lt;input onChange={this.handleChange} type=&quot;text&quot; name=&quot;img&quot; placeholder=&quot;Image&quot; /&gt;<br>      &lt;br/&gt;<br>      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>  }<br>}</pre><pre>export default Form;</pre><p>That’s it! Congrats you know React!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e95284559f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript Beer Challenge]]></title>
            <link>https://medium.com/@amosshin/javascript-beer-challenge-ae334aff50e5?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae334aff50e5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[beer]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Sun, 12 May 2019 16:23:52 GMT</pubDate>
            <atom:updated>2019-05-12T16:23:52.855Z</atom:updated>
            <content:encoded><![CDATA[<p>For this challenge, you will be building a Beer info webpage.</p><p>You should be able to finish within 90 minutes</p><p>— As a user, when the page loads, I should see a list of beer names retrieved from an API on the left hand side of the screen.</p><p>— As a user, when I click a beer name, the application should reveal more information about that particular beer.</p><p>— As a user, when looking at the details of a beer, I can edit the current description of a beer. Clicking the ‘Save’ button will save any changes added to the description in the database</p><p>Instead of actually accessing the data from a remote API, this challenge uses a package called [json-server](<a href="https://github.com/typicode/json-server">https://github.com/typicode/json-server</a>) to create a fake API for development and testing.</p><p>It is very easy to set-up.</p><p>1 — Run the command `npm install -g json-server` in the command line from this directory</p><p>2 — Run `json-server — watch db.json`</p><p>That’s it. You will have a server running on `localhost:3000` that serves the JSON data contained in the `db.json` file.</p><p>Troubleshooting: If this fails, be sure you don’t already have something running on port 3000*</p><p>When the page loads, I should see a list of all of the beer names retrieved from the API on the left hand side of the screen. The API endpoint we need to retrieve all the beers is a conventional RESTful route</p><p>* **Route:** GET `<a href="http://localhost:3000/beers%60">http://localhost:3000/beers`</a></p><p>When I click a beer name, the application should reveal more information about that particular beer.<br>See the example above for the additional information that should be displayed.</p><p>* **Route:** GET `<a href="http://localhost:3000/beers/:id%60">http://localhost:3000/beers/:id`</a></p><p>The beer details should be added to this div</p><pre>html<br>&lt;div id=”beer-detail”&gt;<br>&lt;/div&gt;</pre><p>The html should look something like:</p><pre>html<br>&lt;h1&gt;Beer Name&lt;/h1&gt;<br>&lt;img src=”&lt;add beer img url here&gt;”&gt;<br>&lt;h3&gt;Beer Tagline&lt;/h3&gt;<br>&lt;textarea&gt;Beer Description&lt;/textarea&gt;<br>&lt;button id=”edit-beer” class=”btn btn-info”&gt;<br> Save<br>&lt;/button&gt;</pre><p>Edit beer details</p><pre>When looking at the details of a beer, I can edit the current description of a beer. Clicking the &#39;Save&#39; button will save any changes added to the description in the database. The edited beer should also update the DOM. For example, if I update the details of &quot;Beer A&quot; then click on another beer, when I go back to &quot;Beer A&quot;, the description should be updated.</pre><pre>To update a beer you&#39;ll need to make a PATCH request<br>* **Route:** PATCH `<a href="http://localhost:3000/beers/:id%60">http://localhost:3000/beers/:id`</a><br>* **Body:**<br>```js<br>  {description: &quot;your new description&quot;}<br>```<br>* **Headers:**<br>```js<br>  {<br>    &#39;Content-Type&#39;: &#39;application/json&#39;,<br>    &#39;Accept&#39;: &#39;application/json&#39;<br>  }<br>  ```</pre><pre>**Important Notes:**<br>  * For all intents and purposes, PATCH behaves the same as POST. If you know how to POST, you know how to PATCH<br>  * When using `fetch` to make a PATCH request, be sure to capitalize method: &#39;PATCH&#39;</pre><h3>Answer</h3><pre>const ulTag = document.querySelector(&#39;#list-group&#39;);</pre><pre>const divTag = document.querySelector(&#39;#beer-detail&#39;);</pre><pre>const createBeerLi = (beer) =&gt; {<br>   return `&lt;li class=&quot;list-group-item&quot; data-id=&quot;${beer.id}&quot;&gt;${beer.name}&lt;/li&gt;`<br>}</pre><pre>const createBeerDiv = (beer) =&gt; {<br>   return `<br>      &lt;h1 data-id=&quot;${beer.id}&quot;&gt;${beer.name}&lt;/h1&gt;<br>      &lt;img src=&quot;${beer.image_url}&quot;&gt;<br>      &lt;h3&gt;${beer.tagline}&lt;/h3&gt;<br>      &lt;textarea name=&quot;description&quot;&gt;${beer.description}&lt;/textarea&gt;<br>      &lt;br/&gt;<br>      &lt;button id=&quot;edit-beer&quot; class=&quot;btn btn-info&quot;&gt;<br>      Save<br>      &lt;/button&gt;<br>   `<br>}</pre><pre>ulTag.addEventListener(&#39;click&#39;, (event) =&gt; {<br>   if (event.target.className === &#39;list-group-item&#39;) {<br>      // console.log(event.target.dataset.id)<br>      return fetch(`<a href="http://localhost:3000/beers/$%7Bevent.target.dataset.id%7D%60">http://localhost:3000/beers/${event.target.dataset.id}`</a>)<br>         .then(resp =&gt; resp.json())<br>         .then(beer =&gt; {<br>            divTag.innerHTML = createBeerDiv(beer)<br>            // console.log(&#39;hi&#39;)<br>         })<br>   }<br>})</pre><pre>const updateBeerInfo = (id, description) =&gt; {<br>   fetch(`<a href="http://localhost:3000/beers/$%7Bid%7D%60">http://localhost:3000/beers/${id}`</a>, {<br>      method: &#39;PATCH&#39;,<br>      headers: {<br>         &#39;Content-Type&#39;: &#39;application/json&#39;,<br>         &#39;Accept&#39;: &#39;application/json&#39;<br>      },<br>      body: JSON.stringify({<br>         description: description<br>      })<br>   })<br>      .then(resp =&gt; resp.json())<br>      .then(beerDOM =&gt; {<br>         beerDOM.innerHTML = description<br>         // console.log(&#39;hi&#39;)<br>      })<br>}</pre><pre>divTag.addEventListener(&#39;click&#39;, (event) =&gt; {<br>   event.preventDefault();<br>   if (event.target.className === &#39;btn btn-info&#39;) {<br>      // console.log(event.target.parentElement)<br>      const updatedBeerDesc = event.target.parentElement.children[3].value;</pre><pre>const beerId = event.target.parentElement.children[0].dataset.id;<br>      // const currentBeerDesc =</pre><pre>updateBeerInfo(beerId, updatedBeerDesc)</pre><pre>// console.log(&#39;hi&#39;)<br>   }</pre><pre>})</pre><pre>fetch(&#39;<a href="http://localhost:3000/beers&#39;">http://localhost:3000/beers&#39;</a>)<br>   .then(resp =&gt; resp.json())<br>   .then(allBeers =&gt; {<br>      allBeers.forEach(beer =&gt; {<br>         ulTag.innerHTML += createBeerLi(beer)<br>      })<br>   })</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae334aff50e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Superheroine Challenge]]></title>
            <link>https://medium.com/@amosshin/rails-superheroine-challenge-24785be7230d?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/24785be7230d</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[heroine]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Sun, 12 May 2019 16:14:54 GMT</pubDate>
            <atom:updated>2019-05-12T16:14:54.143Z</atom:updated>
            <content:encoded><![CDATA[<p>Last time I challenged you to finish coding with Ruby. This time we’ll dive into Rails. Same challenge as last time, except you’ll have 90 minutes to finish this time (as this might be harder to finish within 60 minutes)</p><p>Here are the prompts:</p><p>You’ve just been hired by ‘Marvel Comics’ — congratulations! The production staff wants you to make a website that will allow the fans to create heroines. To do this, we need a way to keep track of all of the new heroines and powers that have been created by the fans.</p><p>Luckily, another developer has already started the job. We have a model for heroines and a model for powers. Once the database is seeded, visiting `/heroines` displays all of the heroines, and visiting `/powers` displays all of the powers. We just don’t have a way to associate heroines with powers.</p><p>We have several different powers and each can be bestowed upon **more than one heroine**. Each heroine can only have **one power**.</p><p>1. Create the associations between models. You may have to alter the current schema to get your code working.</p><p>If you’ve set up your relationships properly, you should be able to run `rake db:seed` without errors, and confirm in console that the heroines and powers have been created with the proper relations.</p><p>2. On the heroines index page, a heroine’s super name should link to that heroine’s show page.</p><p>3. The heroine show page should include the heroine’s name (eg. Kamala Khan), her super name (eg. Ms. Marvel), and her power. The power should link to the power show page.</p><p>4. The power show page should have its name and description.</p><p>5. As a visitor to the website, I should be able to create a new heroine with her name and super name.</p><p>6. The form should also allow each heroine to be created with **only one of the existing powers**.</p><p>![A form for adding a new heroine](new_heroine_form.gif)</p><p>7. Make sure no two heroines have the same super name.</p><p># BONUS TO BE COMPLETED IF EVERYTHING ELSE IS DONE</p><p>8. Add a filter to the index view of the heroines. This will allow the visitor to search for an existing power and display all the heroines with that power on the same view page.</p><p>Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24785be7230d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Bakery Challenge]]></title>
            <link>https://medium.com/@amosshin/ruby-bakery-challenge-d1bcbe133271?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1bcbe133271</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[bakery]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Sun, 12 May 2019 16:09:48 GMT</pubDate>
            <atom:updated>2019-05-12T16:09:48.508Z</atom:updated>
            <content:encoded><![CDATA[<p>In the spirit of learning Ruby, I wanted to share a challenge you can do to see if you know enough to say you know it. So here’s the rules.<br>1. You have 60 minutes to finish<br>2. You can use Google</p><p>That’s it. If you can finish all the deliverables, then congrats, you know Ruby!</p><p>Answer will be after the prompt</p><p><strong>Prompt:</strong> You are building an app for a national bakery chain.</p><p><strong>Models:</strong> Your models are the following: Bakery, Dessert, and Ingredients</p><p>- A Bakery has many desserts<br>- A Dessert belongs to a Bakery<br>- A Dessert has many Ingredients<br>- An Ingredient belongs to a Dessert</p><p>Write out the relationships using has_many, belongs_to and has_many_through.<br>Draw out the relationships!!! Create the necessary methods to connect these classes.</p><p><strong>Bakery:</strong> When initializing a Bakery, it must have a name and a location. It can change its<br>name after it is initialized. It cannot change its location.</p><p>`#name`<br> — Should return the name of the Bakery instance<br>- `#location`<br> — Should return the location of the Bakery instance<br>- `#desserts`<br> — Should return an array of Dessert instances that this Bakery has made<br>- `#ingredients`<br> — Should return an array of Ingredient instances for the bakery’s desserts<br>- `#shopping_list`<br> — Should return a string of names for ingredients for the bakery<br>- `#average_calories`<br> — Should return a number totaling the average number of calories for the desserts sold at this bakery</p><p><strong>Desserts:</strong> When initializing a Dessert, it must have a name and a calorie_count. It cannot change its name or calorie count after being initialized.<br>- `#name`<br> — Should return a string of the name for the Dessert instance<br>- `#ingredients`<br> — Should return an array of Ingredients for the dessert<br>- `#bakery`<br> — Should return the bakery object for the dessert<br>- `#calorie_count`<br> — Should return an integer of calorie count for the dessert<br>- `.all`<br> — should return an array of all desserts</p><p><strong>Ingredients:</strong> When initializing an Ingredient, it must have a name. It cannot be changed after it’s initialized<br>- `#dessert`<br> — Should return a Dessert object for that ingredient<br>- `#bakery`<br> — Should return the Bakery object for the bakery that uses that ingredient<br>- `.all`<br> — Should return an array of all Ingredient instances<br>- `.find_all_by_name(ingredient_name)`<br> — should take a string argument and return an array of all ingredients that **include** that string in their name<br> — `.find_all_by_name(‘chocolate’)` might return `[‘chocolate sprinkles’, ‘chocolate mousse’, ‘chocolate’]`<br> — make sure you aren’t just looking for exact matches (like ‘chocolate’ == ‘chocolate’)</p><p>Good luck!</p><h3>Answer</h3><p>So first we’ll start with the Bakery</p><p>We need to have a Bakery class so we can start off with class Bakery</p><p>Being that we won’t be actually writing anything to the location (as the location can’t change) we’ll use attr_reader :location.</p><p>The other values can use the accessor, so it should look like attr_accessor :name, :desserts, :ingredients</p><p>Then we need @@all = [] to create a new array of all</p><p>Initialize the variables with</p><pre>def initialize(name, location)<br>  <a href="http://twitter.com/name">@name</a>, <a href="http://twitter.com/location">@location</a>, <a href="http://twitter.com/desserts">@desserts</a> = name, location, desserts</pre><pre>  @@all &lt;&lt; self<br>end</pre><p>or</p><pre>def initialize(name, location)<br>  <a href="http://twitter.com/name">@name</a> = name<br>  <a href="http://twitter.com/location">@location</a> = location<br>  <a href="http://twitter.com/desserts">@desserts</a> = desserts</pre><pre>  @@all &lt;&lt; self<br>end</pre><p>They both do the same thing.</p><p>The rest of the code should look like this</p><pre>def desserts<br>  Dessert.all.select do |dessert|<br>   dessert.bakery == self<br>  end<br>end</pre><pre>def new_dessert(name, calories)<br>  Dessert.new(name, calories)<br>end</pre><pre>def ingredients<br>  desserts.map do |dessert|<br>   dessert.ingredients<br>  end<br>end</pre><pre>def average_calories<br>  Bakery.desserts.all.inject(0) do |sum, dessert| <br>      sum + desserts.calories<br>     end / Bakery.desserts.all.count<br>end</pre><p>So altogether, your Bakery class should look like:</p><pre>class Bakery</pre><pre>attr_reader :location<br>attr_accessor :name, :desserts, :ingredients</pre><pre>@@all = []</pre><pre>def initialize(name, location)<br>  <a href="http://twitter.com/name">@name</a>, <a href="http://twitter.com/location">@location</a>, <a href="http://twitter.com/desserts">@desserts</a> = name, location, desserts</pre><pre>  @@all &lt;&lt; self<br>end</pre><pre>def self.all<br>  @@all<br>end</pre><pre>def desserts<br>  Dessert.all.select do |dessert|<br>   dessert.bakery == self<br>  end<br>end</pre><pre>def new_dessert(name, calories)<br>  Dessert.new(name, calories)<br>end</pre><pre>def ingredients<br>  desserts.map do |dessert|<br>   dessert.ingredients<br>  end<br>end</pre><pre>def average_calories<br>  Bakery.desserts.all.inject(0) do |sum, dessert| <br>      # binding.pry<br>      sum + desserts.calories<br>     end / Bakery.desserts.all.count<br>end</pre><pre>end</pre><p>Dessert should look similar:</p><pre>class Dessert</pre><pre>attr_reader :name, :calories, :ingredients, :bakery</pre><pre>@@all = []</pre><pre>def initialize(name, calories, ingredients)<br>  <a href="http://twitter.com/name">@name</a>, <a href="http://twitter.com/calories">@calories</a>, <a href="http://twitter.com/ingredients">@ingredients</a> = name, calories, ingredients</pre><pre>  @@all &lt;&lt; self<br>end</pre><pre>def self.all<br>  @@all<br>end</pre><pre>def ingredients</pre><pre>Ingredients.all.select do |ingredient|<br>   ingredient.dessert<br>  end<br>end</pre><pre>end</pre><p>And finally Ingredients should look like this:</p><pre>class Ingredient</pre><pre>attr_reader :name</pre><pre>@@all = []</pre><pre>def initialize(name)<br>  <a href="http://twitter.com/name">@name</a> = name</pre><pre>  @@all &lt;&lt; self<br>end</pre><pre>def self.all<br>  @@all<br>end</pre><pre>def dessert<br>  Dessert.all.select do |dessert|<br>   dessert.ingredients == self<br>  end<br>end</pre><pre>def bakery<br>  Bakery.all.select do |bakery|<br>   bakery.ingedients == self<br>  end<br>end</pre><pre>def self.find_all_by_name(ingredient)<br>  Ingredient.all.include? (ingredient)<br>end</pre><pre>end</pre><p>You should notice that within the Bakery class and Dessert class that the shopping_list and ingredients methods are missing. That’s for you to work on!</p><p>Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1bcbe133271" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flatiron School Final Project Day 10 — All the Things are Working!]]></title>
            <link>https://medium.com/@amosshin/flatiron-school-final-project-day-10-all-the-things-are-working-840f131b496e?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/840f131b496e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Tue, 07 May 2019 00:48:53 GMT</pubDate>
            <atom:updated>2019-05-07T00:48:53.829Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flatiron School Final Project Day 10 — All the Things are Working!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*2XVKVxYQYIjuAEmc7kO0YQ.gif" /></figure><h3>It works! It works! It works!</h3><p>After spending the better half of the morning converting my API from XML to JSON, I finally got my project working! Here’s how it works. The camera checks to see if a cup comes into the frame. When it does, it takes a picture. As soon as the picture is taken, it’s saved onto my local storage with the name of the file being the date (YYYYMMDD) and time (HHMMSS). Once it saves, the file is automatically uploaded to AWS. Then the image is deleted from my local storage (so I don’t have a folder with 30,000 images). That’s it for the camera. Next we move onto AWS. When a file is uploaded to AWS, the object’s permission is set to be public. Then my AWS API gets updates with the new image information. That’s it for AWS. From there, the backend of my web app gets the AWS API and converts it to JSON. Then the new API is hosted via a Post class. Then the frontend of my web app (React) fetches the API and pulls the necessary information. Since my AWS image is public, the url will always stay the same, except for the name of the image file. I parse the url into an image tag while adding the new image file name to the end of the url. That in turn renders the new image onto my web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*1lNBS4HxxKlN0S8skmL1-A.gif" /></figure><h3>Languages and Resources</h3><p>Python to script all the functions (camera start, camera capture, image save, image upload, image remove)<br>Google Cloud Vision API for object detection<br>Amazon Web Services S3 for cloud storage<br>s3cmd to communicate with AWS S3 via Python<br>Amazon API Gateway to create custom API for S3 bucket<br>Ruby on Rails for web app backend and parsing XML API to JSON<br>React.js for web app frontend and rendering captured</p><p>So this has been one hell of a learning experience. I’ve learned to implement other’s API’s, create and implement my own API, script automated tasks via Python (a language I was unfamiliar with), and build a web app, all in 10 short days. Paeq still isn’t finished, as I’ll be finishing up my web app side, but the major functionality is all finished. It felt like every single step of the way, I came across major roadblocks preventing me from progressing. At times, I honestly felt like giving up and questioning whether I would be able to complete my project. However, I pushed harder to find the answers, relying on all the resources I had at my disposal, and thanks to helpful suggestions and the wonders of Stack Overflow, I was able to get it done. So without further adieu, here’s Paeq!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fn69jTHs61uc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dn69jTHs61uc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fn69jTHs61uc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a3808d0181e9757c01d52c7094bb8b3/href">https://medium.com/media/2a3808d0181e9757c01d52c7094bb8b3/href</a></iframe><h3>Todo for tomorrow</h3><p>I would like to add some more functionality to my web app. I might add a user sign up/log in feature as well as commenting functionality. I don’t think my app really calls for those functions to be available, but it’s still something nice to add nonetheless. I also have to update my about section, as it’s pretty lacking at the moment.</p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-9-time-to-api-this-apple-pie-96f0a04588e2">See Day 9 — Time to API this Apple Pie</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=840f131b496e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flatiron School Final Project Day 9— Time to API this Apple Pie]]></title>
            <link>https://medium.com/@amosshin/flatiron-school-final-project-day-9-time-to-api-this-apple-pie-96f0a04588e2?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/96f0a04588e2</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Fri, 03 May 2019 19:16:23 GMT</pubDate>
            <atom:updated>2019-05-07T00:49:36.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*KwKrGap3iK4wW2s_" /></figure><p>Looking into AWS CLI, it turns out it’s unable to do what I need it to do, primarily give me the image url for each image in the S3 bucket. After doing more research however, I found I can possibly accomplish this by creating an API for my S3 bucket, with the image url nested within. If this works, that means I can have my web app be server-less and images between my S3 bucket and web app will automatically be synced.</p><p>AWS has their own API generator with Amazon API Gateway, which I’ve been hard at work using. So far, the API is complete, but I’m unable to render it out in a clean JSON format. I’ll be looking to either update the API settings to accomplish this, or possibly create another one, this time using Lambda as an intermediary. Not sure if either will work, but this seems to be my best option. As of now, this is how my API looks:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;ListBucketResult xmlns=&quot;<a href="http://s3.amazonaws.com/doc/2006-03-01/">http://s3.amazonaws.com/doc/2006-03-01/</a>&quot;&gt;&lt;Name&gt;mod-5-cup-images&lt;/Name&gt;&lt;Prefix&gt;&lt;/Prefix&gt;&lt;Marker&gt;&lt;/Marker&gt;&lt;MaxKeys&gt;1000&lt;/MaxKeys&gt;&lt;IsTruncated&gt;false&lt;/IsTruncated&gt;&lt;Contents&gt;&lt;Key&gt;20190425203311.jpg&lt;/Key&gt;&lt;LastModified&gt;2019-05-01T15:11:43.000Z&lt;/LastModified&gt;&lt;ETag&gt;&amp;quot;cfc9bac2ed9e01fc4e8f1963efcfa6f3&amp;quot;&lt;/ETag&gt;&lt;Size&gt;466184&lt;/Size&gt;&lt;Owner&gt;&lt;ID&gt;fd574ac4c2dc21a7dc91f2d73c9cf636857014e0e0a0da24a3c5191dde5fb5e4&lt;/ID&gt;&lt;/Owner&gt;&lt;StorageClass&gt;STANDARD&lt;/StorageClass&gt;&lt;/Contents&gt;&lt;Contents&gt;&lt;Key&gt;20190425203321.jpg&lt;/Key&gt;&lt;LastModified&gt;2019-05-01T15:11:46.000Z&lt;/LastModified&gt;&lt;ETag&gt;&amp;quo...<br>...<br>...&lt;ETag&gt;&amp;quot;ae339f550519ef33225e6c6f54471ca9&amp;quot;&lt;/ETag&gt;&lt;Size&gt;520751&lt;/Size&gt;&lt;Owner&gt;&lt;ID&gt;fd574ac4c2dc21a7dc91f2d73c9cf636857014e0e0a0da24a3c5191dde5fb5e4&lt;/ID&gt;&lt;/Owner&gt;&lt;StorageClass&gt;STANDARD&lt;/StorageClass&gt;&lt;/Contents&gt;&lt;/ListBucketResult&gt;</pre><pre>...&lt;ETag&gt;&amp;quot;ae339f550519ef33225e6c6f54471ca9&amp;quot;&lt;/ETag&gt;&lt;Size&gt;520751&lt;/Size&gt;&lt;Owner&gt;&lt;ID&gt;fd574ac4c2dc21a7dc91f2d73c9cf636857014e0e0a0da24a3c5191dde5fb5e4&lt;/ID&gt;&lt;/Owner&gt;&lt;StorageClass&gt;STANDARD&lt;/StorageClass&gt;&lt;/Contents&gt;&lt;/ListBucketResult&gt;</pre><h3>Todo for tomorrow</h3><p>Return a clean JSON formatted API, and show the image url within.</p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-8-show-me-the-s3-4e6a9092c52f">See Day 8 — Show me the S3!!</a></p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-10-all-the-things-are-working-840f131b496e">See Day 10 — All the Things are Working!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96f0a04588e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flatiron School Final Project Day 8— Show me the S3!!]]></title>
            <link>https://medium.com/@amosshin/flatiron-school-final-project-day-8-show-me-the-s3-4e6a9092c52f?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e6a9092c52f</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Fri, 03 May 2019 14:17:35 GMT</pubDate>
            <atom:updated>2019-05-03T19:16:57.617Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*sDPwnz_oTjiZAJpprOxEzA.gif" /></figure><p>Now that I’m finally working on the web app section of my project, I’m running into issues I know the answer to, or am able to find the answer to relatively quickly.</p><p>Step one of my web app is to build out the backend with Rails. That was done pretty quickly with relative ease. I did forget some methods here and there, but once I started to get back into the groove I started remembering how to write in Rails. It’s almost like riding a bicycle. It may be awkward after not riding for a while, but once I get going, it becomes second nature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irBLZu9N9hgt0DUcRLNfOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPHr_6sviDY6-9JhgE87yw.png" /></figure><p>Step two was to build out the frontend with React. I started my app with Redux since it’s easier to have a Redux app and use mostly React vs starting with React and figuring out down the line that I should’ve used Redux. There isn’t anything in my app as of right now that needs Redux, but I figure it’ll be a good way to future-proof since I do want to get back to this app and build it out further in the future.</p><p>Step three is to get S3 to sync with Rails. I’ve been having a bit of trouble with this one. Why is it always AWS that’s the issue. I thought at first I should set up ActiveStorage since I need a way to display all the images on my S3 bucket. Then I realized that ActiveStorage requires input from the user to upload, then show the image. ActiveStorage (<em>as far as I know</em>) works by attaching an image to an instance with an id which is done when a user uploads an image. Since I need Rails to do this automatically without any user input, ActiveStorage might not work in my case. So I started looking at syncing options, mainly with AWS CLI. It looks like a pretty powerful tool and can be used with Ruby/Rails. So far, the documentation has been pretty great and it seems like it might work for my app. I’ll keep sifting through the documentation though so I can get a better understanding of what it does and how it does it before implementing it into my app, or looking for a solution that works.</p><h3>Todo for tomorrow</h3><p>Get AWS CLI or another option to show all my existing S3 images onto my React App through Rails.</p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-7-its-alive-4587244964ab">See Day 7 — It’s Alive!!</a></p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-9-time-to-api-this-apple-pie-96f0a04588e2">See Day 9 — Time to API this Apple Pie</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e6a9092c52f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flatiron School Final Project Day 7 — It’s Alive!!]]></title>
            <link>https://medium.com/@amosshin/flatiron-school-final-project-day-7-its-alive-4587244964ab?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4587244964ab</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Wed, 01 May 2019 18:32:44 GMT</pubDate>
            <atom:updated>2019-05-03T14:18:43.216Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flatiron School Final Project Day 7 — It’s Alive!!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*k1POA2oW5JC5qT1eAPenjQ.gif" /></figure><p>Einstein discovered the Theory of Relativity. Ghandi paved the way for a peaceful India. Bill Gates created Microsoft. These are all great accomplishments by even greater people. On this day, I conquered AWS and published my images to their S3 server.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMvS4BdTzY3s%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMvS4BdTzY3s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMvS4BdTzY3s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/58deb70e95e7d50100c4f29ce0db9b7d/href">https://medium.com/media/58deb70e95e7d50100c4f29ce0db9b7d/href</a></iframe><p>Oh how magnificent this feels. This marks the end of the Raspberry Pi portion of my project. Now, the web app section kicks in, and compared to what I went through dealing with Python and multiple uncooperative programs, this feels like a breeze.</p><h3>Web App Structure</h3><p>So in terms of my web app, the backend will have four models — Users, Posts, Comments, and Likes. A User will have many Comments, and Comments will have many Likes. Posts will also have many Comments, and Users will also have many Likes.</p><p>User -&lt; Comments &gt;- Post<br>Comments -&lt; Likes</p><p>So that will be the basis of my backend (<em>Ruby on Rails</em>)</p><p>My frontend will be in React/Redux, with the major pages being Home / About, Project, Signup/Login. Each post in Project will have the option for a user to leave a comment or upvote/downvote. The home/about section will have a summary of what the project is all about.</p><p>I’ve started on the backend portion, so hopefully I can flush it out by the end of the week. By next week, I hope to be working on the frontend and styling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*ybe_vVw2e0e5Z-wVIUnJIA.gif" /></figure><h3>Todo for tomorrow</h3><p>Get at least half the backend finished. Possibly start on the frontend to see if data is persisting to the database.</p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-6-rclone-react-redux-rails-f5701c5d3c49">See Day 6 — rclone, React/Redux, &amp; Rails</a></p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-8-show-me-the-s3-4e6a9092c52f">See Day 8 — Show me the S3!!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4587244964ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flatiron School Final Project Day 6— rclone, React/Redux & Rails]]></title>
            <link>https://medium.com/@amosshin/flatiron-school-final-project-day-6-rclone-react-redux-rails-f5701c5d3c49?source=rss-af5958adf2d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5701c5d3c49</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Amos Shin]]></dc:creator>
            <pubDate>Wed, 01 May 2019 13:46:21 GMT</pubDate>
            <atom:updated>2019-05-01T18:33:13.421Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flatiron School Final Project Day 6— rclone, React/Redux, &amp; Rails</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*4vntPtAtpioXL9LtrtbfdQ.gif" /></figure><p>After hours upon hours of thinking about my issue, I came upon a revelation. I’ve been going about the issue the wrong way. In essence, I’ve been trying to defend the North by killing all the wights, when instead I should be focusing on the Night King (<em>yes, I did just watch the third episode of GoT</em>). I’ve been trying to upload a photo to AWS after it takes an image through Python, when I should be syncing my photos folder with AWS instead. Seems so obvious now. In order to accomplish this, I found a few resources to help me, mainly rclone. I’ve been having issues with getting it to work though. I get a failed to configure token and request signature we calculated does not match the signature you provided error with AWS (<em>it’s a token error, which means it’s my key id and secret key id. But they’re correct. Also regions are the same on my AWS with my rclone. So not entirely sure why it’s giving me an error</em>). I’ve been searching for answers everywhere so hopefully I’ll find the answer soon enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*BV_8HZJPEu2vPJr0gXWbvA.gif" /></figure><p>In the meantime, I’ve started my backend and frontend for the web app portion of this project. It’s amazing how much I remember once I get in the groove. It was tough getting started though. I completely forgot how to even create a new React project (<em>short term memory loss ftw!</em>). Once I opened the project and started to code, it’s amazing how everything just came to me. It felt like a superpower actually. I’m a coding master — a guru (<em>not really, I have no idea what I’m doing</em>). Honestly after a week of struggling with learning a new language and interfacing with what seemed like a computer my great-grandparents would’ve used (<em>yeah, the Pi Zero is </em>that<em> slow</em>), it was extremely refreshing to code like a normal person again (<em>honestly though, what is ‘normal’? Normalcy is a social construct</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rKlz-4ytcm4Aep0LSdacFw.gif" /></figure><h3>Todo for tomorrow</h3><p>Get rclone working. Once this is done, complete the Rails backend for my webapp. If all I do tomorrow is get rclone to work, I’d be a happy little sponge.</p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-5-why-622185069f65">See Day 5 — Why…</a></p><p><a href="https://medium.com/@amosshin/flatiron-school-final-project-day-7-its-alive-4587244964ab">See Day 7 — It’s Alive!!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5701c5d3c49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>