<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Lukas Mills</title>
    <description>The latest articles on Forem by Lukas Mills (@millsy64).</description>
    <link>https://forem.com/millsy64</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F886303%2F1c7ea59d-834a-420c-823b-85c953e2ebce.jpeg</url>
      <title>Forem: Lukas Mills</title>
      <link>https://forem.com/millsy64</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/millsy64"/>
    <language>en</language>
    <item>
      <title>Basics of Binary Code in Computer Science</title>
      <dc:creator>Lukas Mills</dc:creator>
      <pubDate>Tue, 04 Oct 2022 15:16:24 +0000</pubDate>
      <link>https://forem.com/millsy64/basics-of-binary-code-in-computer-science-1c34</link>
      <guid>https://forem.com/millsy64/basics-of-binary-code-in-computer-science-1c34</guid>
      <description>&lt;h2&gt;
  
  
  What is Binary Code?
&lt;/h2&gt;

&lt;p&gt;For humans, we are able to communicate with one another through our wide range of 7,000+ languages in the world, but the way in which computers communicate to one another is through Binary Code. Any time you go to watch a movie, listen to music, or look up directions, you are giving your device input, and it turns into Binary Code. Binary Code is made up of 2 digits 0's, and 1's, unlike our traditional decimal system that is made up of 10 digits. The 0's and 1's are how computers read, process, and store data. These 0's and 1's can represent any symbol, letter, number, or segment of data. Binary Code can also be broken down further into what is called and Byte, and a Bit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bit
&lt;/h2&gt;

&lt;p&gt;John Tukey, a leading statistician and adviser to five presidents first coined the term in 1946. A single bit is made up of a single 1 or 0. Computers are often classified by the number of bits they can process at one time. Graphics are often described by the number of bits used to represent each pixel, and a certain number of bytes makes up a larger unit called a KiloByte, MegaByte, GigaByte, or a TeraByte.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6h5vwe7xbvq5j1ohim53.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6h5vwe7xbvq5j1ohim53.PNG" alt="byte chart"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Byte
&lt;/h2&gt;

&lt;p&gt;A byte is a unit of storage capable of holding a single character for example those letters, numbers, and symbols, we talked about earlier. One byte is equal to 8 bits (a single 1 or 0)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Byte: This is a single byte composed of 8 bits =&amp;gt; 01100011 = "c"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what if we wanted to used multiple bytes to compose a word or sentence? &lt;/p&gt;

&lt;h2&gt;
  
  
  The Alphabet Using Binary
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsk97esbs5zqg2pddcf0a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsk97esbs5zqg2pddcf0a.png" alt="Binary Alphabet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A word using Binary
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9wtnnck37bck8g65hc9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9wtnnck37bck8g65hc9.PNG" alt="cat binary"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally A Sentence Using Binary
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4oj4ytlq0xo6stzmz0e.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4oj4ytlq0xo6stzmz0e.PNG" alt="ice cream binary"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This gets very long winded, because a single byte doesn't represent one word, it only represents a single character, which is why us humans don't use this as a form of language, but this binary system is what computers use everyday to communicate!&lt;/p&gt;

</description>
      <category>binary</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Imposter Syndrome In Software Engineering</title>
      <dc:creator>Lukas Mills</dc:creator>
      <pubDate>Thu, 15 Sep 2022 12:02:36 +0000</pubDate>
      <link>https://forem.com/millsy64/imposter-syndrome-in-software-engineering-520j</link>
      <guid>https://forem.com/millsy64/imposter-syndrome-in-software-engineering-520j</guid>
      <description>&lt;p&gt;Imposter Syndrome is something that the majority of us have dealt with at one point or another, and if you haven't dealt with this yet you're bound to have this feeling at one point or another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Causes
&lt;/h2&gt;

&lt;p&gt;Imposter Syndrome is very relevant and real in any field of study, but to me at least I feel as though it is more relevant in any type of tech related field especially Software Engineering. One of the main causes Engineers feel this way is because Software Engineering is a fast moving industry, with brand new technologies introduced every day, it is physically and mentally impossible to learn every single framework or language there is out there. Another reason imposter syndrome is so relevant today in Software Engineering is because there is a misconception in this industry that you have to be super smart, like Steve Jobs, Bill Gates, or Elon Musk kind of smart, but you don't have to be that at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing Imposter Syndrome
&lt;/h2&gt;

&lt;p&gt;If you came here looking for a fix for imposter syndrome I am afraid I cannot give that answer to you, because it is something that will always stick with you. There is always going to be someone smarter than you no matter what, unless you are the upper echelon of Engineers. One of the most important things to remember, as Software Engineers it isn't always important to know the most things or be the smartest in the room, it's easier and much more important in our industry to have the ability to learn a new language or framework very quickly, and to have very good problem solving skills.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Basics of Building a Functional API Using Active Record and Sinatra</title>
      <dc:creator>Lukas Mills</dc:creator>
      <pubDate>Thu, 25 Aug 2022 16:06:00 +0000</pubDate>
      <link>https://forem.com/millsy64/the-basics-of-building-a-functional-api-using-active-record-and-sinatra-2lk9</link>
      <guid>https://forem.com/millsy64/the-basics-of-building-a-functional-api-using-active-record-and-sinatra-2lk9</guid>
      <description>&lt;p&gt;Quite often when building projects during Phase 1 and Phase 2 I ran into a lot of API issues where not a single API that I could find had all of the correct data that I wanted to use for my website. Now, that I have learned Sinatra, and Active Record I can build my own API so I can have all of the data I've ever dreamed of using. Hopefully, after you're done reading this you'll be able to build your own API as well!&lt;/p&gt;

&lt;h2&gt;
  
  
  Starter Code:
&lt;/h2&gt;

&lt;p&gt;To get started building your own API let's first get some starter code! Fork and clone this down to your machine. &lt;a href="https://github.com/learn-co-curriculum/phase-3-sinatra-react-project"&gt;https://github.com/learn-co-curriculum/phase-3-sinatra-react-project&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this example today we will be building an API for a movie review website!&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundle Install
&lt;/h2&gt;

&lt;p&gt;Open up and new terminal and type this into your console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does is it installs every single Gem in our Gemfile to help us create our API. Some of the more important Gem's include: sinatra, rake, sqlite3, faker, and activerecord-reset-pk-sequence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--efCq2chc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgku5hjnrrkzur4mbm7q.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--efCq2chc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgku5hjnrrkzur4mbm7q.PNG" alt="Image description" width="542" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating our Models
&lt;/h2&gt;

&lt;p&gt;Go into your App &amp;gt;&amp;gt; Models folder, and create new files called movie.rb, review.rb, and user.rb. Creating our models not only gives us the opportunity to create customs methods to do whatever we want with our data, but it allows us to get proper associations (relationships) which will play a vital role in building our database.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J3pvHxL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86w42tbz9865zfj2jb8b.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J3pvHxL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86w42tbz9865zfj2jb8b.PNG" alt="Image description" width="201" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you have created our models, let's give them some class names!&lt;/p&gt;

&lt;p&gt;movie.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Movie &amp;lt; ActiveRecord::Base

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;review.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Review &amp;lt; ActiveRecord::Base

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;user.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might be wondering what does "ActiveRecord::Base" do? This essentially provide an interface and binding between the tables in our relational database and the Ruby program code that manipulates database record.&lt;/p&gt;

&lt;h2&gt;
  
  
  Giving Our Models Associations With One Another:
&lt;/h2&gt;

&lt;p&gt;Before we jump into the code it's important to think about our domain model. A domain model is essentially, for a lack of a better term a way of "whiteboarding" our associations between models.&lt;/p&gt;

&lt;p&gt;Our domain model: &lt;code&gt;movie —--&amp;lt;reviews&amp;gt;-------user&lt;/code&gt;&lt;br&gt;
Looking at our domain model we can begin to think about their associations between one another in pseudocode.&lt;br&gt;
&lt;code&gt;A movie has many reviews&lt;/code&gt;&lt;br&gt;
&lt;code&gt;A movie has many users, through reviews&lt;/code&gt;&lt;br&gt;
&lt;code&gt;A user has many reviews&lt;/code&gt;&lt;br&gt;
&lt;code&gt;A user has many movies, through reviews&lt;/code&gt;&lt;br&gt;
&lt;code&gt;A review belongs to a movie&lt;/code&gt;&lt;br&gt;
&lt;code&gt;A review belongs to a user&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's jump into our code and let's start creating those associations!&lt;/p&gt;

&lt;p&gt;movie.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Movie &amp;lt; ActiveRecord::Base
    has_many :reviews
    has_many :users, through: :reviews
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;user.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base
    has_many :reviews
    has_many :movies, through: :reviews
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;review.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Review &amp;lt; ActiveRecord::Base
    belongs_to :movie
    belongs_to :user 
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you haven't been able to tell already, we just put into our code what we wrote out in pseudocode, just with some syntax!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating migrations:
&lt;/h2&gt;

&lt;p&gt;The next step of our journey is creating our migrations! Migrations give us a way of essentially creating columns and keys in our database!&lt;/p&gt;

&lt;p&gt;Open up a new terminal and type these lines in one at a time and hit enter!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rake db:create_migration NAME="create_movies"

rake db:create_migration NAME="create_users"

rake db:create_migration NAME="create_reviews"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you've created these migrations go into your db &amp;gt;&amp;gt; migrate folder and you should see something similar to what I have: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pqok9Ji1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu5ojqjit3dfbs7u72bg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pqok9Ji1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu5ojqjit3dfbs7u72bg.PNG" alt="Image description" width="302" height="110"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! We've created these migrations for our tables, but how do we create new columns for our table?&lt;/p&gt;

&lt;p&gt;create_movies.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateMovies &amp;lt; ActiveRecord::Migration[6.1]
  def change
    create_table :movies do |t|
      t.string :title
      t.string :image
      t.integer :release_date
      t.string :genre
    end
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WOAH! That's a lot of information to take in let's break it down step by step:&lt;br&gt;
&lt;code&gt;class CreateMovies&lt;/code&gt;: Gives us a class name of our migration&lt;br&gt;
&lt;code&gt;ActiveRecord::Migration[6.1]&lt;/code&gt;: Some rake magic that allows us to create migrations for our tables.&lt;br&gt;
&lt;code&gt;def change&lt;/code&gt;: Creating a method&lt;br&gt;
&lt;code&gt;create_table :movies&lt;/code&gt;: Creates a table with the name of movies.&lt;br&gt;
&lt;code&gt;t.string&lt;/code&gt;: Allows us to apply a datatype to the column we are creating.&lt;br&gt;
&lt;code&gt;:title&lt;/code&gt;: Creates a name for our data that we want represented in our table or frontend. Here so one of our movie titles will be: 'Interstellar'&lt;/p&gt;

&lt;p&gt;Now let's go ahead and create every migration for each model:&lt;/p&gt;

&lt;p&gt;create_users.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateUsers &amp;lt; ActiveRecord::Migration[6.1]
  def change
    create_table :users do |t|
      t.string :name
    end
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;create_reviews.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateReviews &amp;lt; ActiveRecord::Migration[6.1]
  def change
    create_table :reviews do |t|
      t.integer :movie_id
      t.integer :user_id
      t.string :comment
      t.integer :rating

    end
  end
end


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at our create_reviews.rb migration can you tell what the difference is?&lt;/p&gt;

&lt;p&gt;When we refer back to our domain model and our pseudocode &lt;code&gt;movie —--&amp;lt;reviews&amp;gt;-------user&lt;/code&gt; we can see that our reviews belong to a movie and a user. By creating columns for our &lt;code&gt;movie_id&lt;/code&gt; and our &lt;code&gt;user_id&lt;/code&gt; we are putting in the final puzzle piece to create associations between our models.&lt;/p&gt;

&lt;p&gt;After creating our migrations let's actually migrate them to our database!&lt;/p&gt;

&lt;p&gt;In your terminal type this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rake db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great we have our columns appropriately applied to our tables, but now how can we add data to them?&lt;/p&gt;

&lt;h2&gt;
  
  
  Seeding our data:
&lt;/h2&gt;

&lt;p&gt;For our API to display any information we have to give it some type of value, one of the easiest ways to do this is to seed our data! Looking at our file directory we will see a starter seeds.rb file. &lt;/p&gt;

&lt;p&gt;Once you are in there let's create our very first movie!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;m1 = Movie.create( 
    title: 'Harry Potter and the Goblet of Fire',
    image: 'https://m.media-amazon.com/images/I/71opdcUCGjL.jpg',
    release_date: 2005,
    genre: 'Fantasy'
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at this, you can already get a sense of what is going on here! We are creating an instance of a movie and giving our keys like &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;image&lt;/code&gt; some value in our database! But what about users, and reviews? &lt;/p&gt;

&lt;h2&gt;
  
  
  Faker:
&lt;/h2&gt;

&lt;p&gt;In this case, Faker is a ruby gem that allows us to randomly generate names for our Users so we don't have to continuously have to create new instances of our Users ourselves.&lt;/p&gt;

&lt;p&gt;Users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5.times do 
    User.create(name: Faker::Name.name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is creating 5 Users, and each giving them a randomly generate name!&lt;/p&gt;

&lt;p&gt;Reviews:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r1 = Review.create(comment:"I liked this film very much. It is much darker than the previous outings, but not as faithful to the source material. The only thing I didn't like so much about the book, was the subplot about Hermione trying to help house elves. It was cute, but interfered too much with the dark overtones of the narratives. The film looks dazzling, especially the ballroom scene. Speaking of that scene, I adored that dress that Hermione was wearing, Emma Watson looked unrecognisable in that scene.Also the music by Patrick Doyle this time was beautiful." , rating: 5 , user_id: User.ids.sample , movie_id: m1.id)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately for us there isn't a Faker for creating reviews, so we must hard code our own reviews!&lt;/p&gt;

&lt;p&gt;After you have done all of the steps go into your terminal and type in &lt;br&gt;
&lt;code&gt;rake db:seed&lt;/code&gt;&lt;br&gt;
We now have all of the essential data to fetch on the frontend! But how are we able to tie in this data and use a fetch call to display it on the front end?&lt;/p&gt;
&lt;h1&gt;
  
  
  Controllers
&lt;/h1&gt;

&lt;p&gt;Controllers act as a middle man that allows us to create custom routes when fetching on the frontend. &lt;/p&gt;

&lt;p&gt;The first step we must do is go into our app &amp;gt;&amp;gt; controllers &amp;gt;&amp;gt; application_controller.rb file and create a class that inherits Sinatra.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base
set :default_content_type, 'application/json'

end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's create our custom routes for the data we want displayed!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/movies" do
    movies = Movie.all
    movies.to_json
  end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what does all of this do? &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/&lt;/code&gt;:specifies the route path we want to create.&lt;br&gt;
&lt;code&gt;movies = Movie.all&lt;/code&gt;: creates a variable holding all of our Movie data.&lt;br&gt;
&lt;code&gt;movies.to_json&lt;/code&gt;: Converts all of the data we have on movies to json.&lt;/p&gt;

&lt;p&gt;Now what if we wanted to include our users and our reviews with our movies?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/movies" do
    movies = Movie.all
    movies.to_json(include: { reviews: {include: :user} }) 
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you start your rake server in your terminal with &lt;code&gt;rake server&lt;/code&gt; and type &lt;code&gt;http://localhost:9292/movies&lt;/code&gt; in your browser, you should we something similar to what I have! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M7wEPWwo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g98zfk00919x17cznlaq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M7wEPWwo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g98zfk00919x17cznlaq.PNG" alt="Image description" width="880" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have just built your first local API! Congragulations!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Hooks For Beginners : useState</title>
      <dc:creator>Lukas Mills</dc:creator>
      <pubDate>Mon, 01 Aug 2022 15:52:00 +0000</pubDate>
      <link>https://forem.com/millsy64/react-hooks-use-state-28b</link>
      <guid>https://forem.com/millsy64/react-hooks-use-state-28b</guid>
      <description>&lt;p&gt;The useState hook allows us to create state variables in a React function component, also useState allows us to access and update certain values in our components over time. Finally, whenever we do create our useState hook we must give it a default value, and this can be any data type.&lt;/p&gt;

&lt;p&gt;Before we start working with useState we must import it from React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like that you have access to all of the wonderful things that useState has to offer. But now what if we wanted to use our useState hook in a real world scenario? &lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'

function favoriteAvengers() {

const [avenger, setAvenger] = useState('Spider-man')

// avenger: a variable that stores the current value of our favorite avenger 'Spider-man'
// setAvenger: allows us to update or change the value of our avenger variable over time.
// useState('Spider-man'): is our default value of our variable 'avenger'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now let's add a button that changes our state to a different avenger when it's clicked:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'

function favoriteAvengers() {

const [avenger, setAvenger] = useState('Spider-man')

return (

&amp;lt;h1&amp;gt;My favorite Avenger is {avenger}!&amp;lt;/h1&amp;gt;

&amp;lt;button
type ='button'
onClick={() =&amp;gt; setAvenger('Thor')}
&amp;gt;Change Avenger&amp;lt;/button&amp;gt;
)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this is just the tip of the iceberg on what you can do with state, but this gives you a basic and fundamental understanding of how useState works!&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Basic Array Methods</title>
      <dc:creator>Lukas Mills</dc:creator>
      <pubDate>Wed, 13 Jul 2022 03:11:34 +0000</pubDate>
      <link>https://forem.com/millsy64/basic-array-methods-2d97</link>
      <guid>https://forem.com/millsy64/basic-array-methods-2d97</guid>
      <description>&lt;p&gt;I have always had interest in data structures ever since I started going to school for Computer Science, but one thing that I could never remember were array methods. Hopefully, you're like me and want to refer back to simple documentation explaining how array methods work!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. shift()
&lt;/h2&gt;

&lt;p&gt;The shift method allows us, as the user to remove the first element from an array, returns the first element and modifies the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let videoGames = ['Minecraft', 'Among Us', 'Valorant', 'GTA']
videoGames.shift() // returns Minecraft
console.log(videoGames) // ['Among Us', 'Valorant', 'GTA']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. pop()
&lt;/h2&gt;

&lt;p&gt;The pop method acts in the same way as shift, the only difference being is that it removes the last element of any array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sports = ['basketball', 'baseball', 'football', 'soccer']
sports.pop() //returns soccer
console.log(sports) // ['basketball', 'baseball', 'football']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. splice()
&lt;/h2&gt;

&lt;p&gt;The splice method has the ability to add or remove elements from an array. The first argument is the index location where the elements are to be removed or added. The second argument is the number of elements that you want to remove from the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let avengers = ['Hawkeye', 'Thor', 'Spider-Man', 'Hulk', 'Iron Man', 'Captain America']
avengers.splice(1,3) // returns ['Thor', 'Spider-Man', 'Hulk']
console.log(avengers) // ['Hawkeye', 'Iron Man', 'Captain America']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we wanted to remove an index, and add a different value you it would look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let avengers = ['Hawkeye', 'Thor', 'Spider-Man', 'Hulk', 'Iron Man', 'Captain America']
avengers.splice(1,1, 'Ant-Man') // returns Thor and replaces Thor with Ant-Man
console.log(avengers) // ['Hawkeye', 'Ant-Man', 'Spider-Man', 'Hulk', 'Iron Man', 'Captain America']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4.) slice()
&lt;/h2&gt;

&lt;p&gt;This slice method is used to remove elements from an array without modifying the original array. Also with this method, with what elements you do remove a brand new array is created with those elements. When specifying the range of elements that you want to remove just like our other methods you first want to define was element you want to start with, and the second argument is what you want to end with (the ending index is not included in the new array).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let codeLanguages = ['Python', 'JavaScript', 'Java', 'TypeScript', C++]
codLanguages.slice(1,3) // returns ['JavaScript', 'Java'] and creates a new array
console.log(codeLanguages) // ['Python', 'JavaScript', 'Java', 'TypeScript', C++]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>flatiron</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
