<?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>DEV Community: arthurvfain</title>
    <description>The latest articles on DEV Community by arthurvfain (@arthurvfain).</description>
    <link>https://dev.to/arthurvfain</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%2F641142%2Fe26339ae-f55e-4836-92ca-e926a1ac7148.png</url>
      <title>DEV Community: arthurvfain</title>
      <link>https://dev.to/arthurvfain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arthurvfain"/>
    <language>en</language>
    <item>
      <title>Things I learned from my Flatiron Capstone Project</title>
      <dc:creator>arthurvfain</dc:creator>
      <pubDate>Fri, 08 Oct 2021 05:13:47 +0000</pubDate>
      <link>https://dev.to/arthurvfain/things-i-learned-from-my-flatiron-capstone-project-12eb</link>
      <guid>https://dev.to/arthurvfain/things-i-learned-from-my-flatiron-capstone-project-12eb</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;So here I am, 12 weeks into one of the craziest plunges of my life and it is time to finally jump from the nest, spread my wings, and see what the past four Phases of Flatiron School have taught me, if it was all worth it, and I decided that the best way to find out was to create the App that got me interested in software engineering. If anyone has read my previous blog posts, you may have seen there was a time when I realized I wanted to build things: namely the app that I can say (although in its infancy) has truly come to life. Looking back, I am proud to say that yes, throughout my experience here at Flatiron, I have learned enough to have the basics of my app come to life, but more importantly I have been able to (for the most part) learn how to learn what I need to make my visions real.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rack-CORS gem
&lt;/h2&gt;

&lt;p&gt;So this all started with a dream of setting out my first web app, from scratch from the ground up, in a way that would be accessible to the outside world. I wanted to this in a way that would mimic my own startup as closely as possible. Thus I decided that the best idea was to deploy from the beginning, and test only through deployed frontend and backend. Without any experience this was a huge mistake, as I encountered issue after issue after issue of things that I have never encountered before. It was very much a trial by fire, and unfortunately sucked quite a large chunk of time (that should have been utilized building out features on the app). &lt;/p&gt;

&lt;p&gt;So, one of the things I ran into was this what felt like incessant issue running into CORS errors. Although I haven't been able to fix all the bugs that allow seamless communication between my independently hosted frontend and backend environments, one of the main things that allowed the most basic of communication was the Rack-CORS gem for ruby on rails. All I had to do was add &lt;code&gt;gem 'rack-cors'&lt;/code&gt; to my backend gemfile and run &lt;code&gt;bundle install&lt;/code&gt; from my terminal. Then, I was free to create my &lt;code&gt;cors.rb&lt;/code&gt; file in &lt;code&gt;config/initializers/cors.rb&lt;/code&gt; and add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert_before&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Rack&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cors&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;allow&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;origins&lt;/span&gt; &lt;span class="s1"&gt;'http://localhost:3000'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'http://localhost:3001'&lt;/span&gt;

    &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="ss"&gt;headers: :any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="ss"&gt;expose: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'access-token'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'expiry'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'token-type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'uid'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'client'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="ss"&gt;methods: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:put&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:patch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:delete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:head&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="ss"&gt;credentials: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
      &lt;span class="ss"&gt;exposedHeaders: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Set-Cookie"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And things started to work ! I stopped getting the CORS errors.&lt;/p&gt;

&lt;p&gt;Unfortunately, it revealed a larger problem, that I still have yet to find a solution to regarding the saving of session cookies on the browser and then sending them to the backend server, which I am extremely willing to get help with. (please add in the comments if you are knowledgable with that) but ultimately my CORS errors were no longer a problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom routes with cool params
&lt;/h2&gt;

&lt;p&gt;Sticking with the backend theme, I would like to highlight something I learned and enjoyed using between my frontend and my backend for some interesting fetches. I realized that multiple params can be passed by dynamically creating the path that a fetch would be sent to, in ways that many different values can be passed to the backend without adding anything to the body. for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`http://localhost:3000/reflect/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;currentUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, this fetch has two pieces of data string interpolated into the address, that in this case send the information about the logged in user as well as who in the database they are forming a relationship with.&lt;/p&gt;

&lt;p&gt;This is handled in the backend by the route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/reflect/:user/:mirror'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s1"&gt;'reflections#create'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then processed by the create method in the controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;reflection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Reflection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;user_id: &lt;/span&gt;&lt;span class="n"&gt;reflection_params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;mirror_id: &lt;/span&gt;&lt;span class="n"&gt;reflection_params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:mirror&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, neither of those id's needed to be sent as part of the POST request body, but are available to the backend controller through params just the same. Any number of simple  pieces of data can be passed using a custom route like that. Perhaps it isn't a necessity, but nonetheless I definitely found it cool that this could be done. &lt;/p&gt;

&lt;h2&gt;
  
  
  #pluck method
&lt;/h2&gt;

&lt;p&gt;When calling up a new entry into my database up, and needing to process it, every time I did a .where to find entries associated with a particular user, all I could get back was ActiveRecord::Relation that I couldn't really work with for my purposes, as my unit of data is a hash composed of keys and integer values. To make things more complicated, my .where could return an ActiveRecord::Relation that may be composed of potentially thousands of entries that all need to be processed to yield a neat one-dimensional array that can be served to the frontend for rendering.&lt;/p&gt;

&lt;p&gt;I was at a loss until.... I read about the #pluck method !&lt;/p&gt;

&lt;p&gt;#pluck is a ruby on rails method that takes as many arguments as you want, &lt;em&gt;these are the keys that correspond to the desired values to be plucked in the same order the keys (symbols) are passed as arguments to the #pluck method,&lt;/em&gt; and returns an array of either the values that correspond to the keys, or a two-dimensional array that contains the desired values nested in an array of arrays, each inner array corresponding to the values &lt;em&gt;plucked&lt;/em&gt; from one particular entry in the database, leaving behind all the extra information that is impertinent to the calculations or whatever processing that needs to be done. &lt;/p&gt;

&lt;p&gt;More can be read on pluck &lt;a href="https://apidock.com/rails/ActiveRecord/Calculations/pluck"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #transpose method
&lt;/h2&gt;

&lt;p&gt;The last thing I want to talk about, which I think is the simplest, coolest, and single-handedly most useful, straight-forward, (and dare I say slick) method I have found for my uses was the #transpose method.&lt;/p&gt;

&lt;p&gt;So: having used #pluck to generate a two-dimensional array that contains an x amount of arrays structured in such a way that all the first integers correspond to each other, all the second integers correspond to each other, and so on... and ultimately each column has to be compiled into an average. Instead of figuring out how to pull the first member out of each array, average all of them, and then push them into a new array, I fortuitously stumbled upon the #transpose method, that takes an array and &lt;em&gt;magically&lt;/em&gt; converts it from&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[ 1, 2, 3, 4, 5 ],
 [ 3, 4, 5, 6, 7 ],
 [ 5, 6, 7, 8, 9 ]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[ 1, 3, 5 ],
 [ 2, 4, 6 ],
 [ 3, 5, 7 ],
 [ 4, 6, 8 ],
 [ 5, 7, 9 ]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which now automatically "combined like terms" and allowed me to quickly map over the outer array and return an array that contains only the averages of the inner arrays, which is what I wanted all along.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 3, 4, 5, 6, 7 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This may be small, but I can't even imagine how much work it saved me, all with one simple built-in method. &lt;/p&gt;

&lt;p&gt;Overall, however small, these are all different little lessons that I never would have learned if I had not embarked on my own independent project. I feel happy, accomplished, and just that much more ready to take on challenges in the future, knowing that I can ask the right questions and utilize resources (such as this one) and feel part of the software development community, where people are extremely helpful and knowledgable, and have all of the collective knowledge at my finger tips.&lt;/p&gt;

&lt;p&gt;Fellow coder, you are never alone.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Keeping things safe, using React Router !</title>
      <dc:creator>arthurvfain</dc:creator>
      <pubDate>Mon, 02 Aug 2021 17:59:50 +0000</pubDate>
      <link>https://dev.to/arthurvfain/keeping-things-safe-using-react-router-kop</link>
      <guid>https://dev.to/arthurvfain/keeping-things-safe-using-react-router-kop</guid>
      <description>&lt;p&gt;Cybersecurity is extremely important, and when writing apps, keeping things water-tight is harder than ever, with different ways of finding backdoors and other methods of accessing unauthorized information more prevalent, protecting our resources is as important as ever. One of these methods that I encountered is protected routes, through the use of React Router Dom. &lt;/p&gt;

&lt;p&gt;At it's most basic level, implementing a protected route is simply placing every component that needs special authorizations in another component that accesses state from  the parent and only renders those pages if the parent's state is set to true for a log in. &lt;/p&gt;

&lt;p&gt;In order to do this, we must first have all the resources that we want to protect made into components that are passed into our "protector" component as props using a render functionality.&lt;/p&gt;

&lt;p&gt;I see this protector component as a "ghost" component almost, as it doesn't have a set shape and takes the place of whatever component is passed to it as props. &lt;/p&gt;

&lt;p&gt;See the example below for a boilerplate Protector component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { Route, useHistory } from 'react-router-dom';

function Protector ({ component: Component, user, ...rest })
{
const history = useHistory()

  return (
    &amp;lt;Route {...rest} render={props =&amp;gt; {
        if (user) 
        {
          return &amp;lt;Component {...rest} {...props} /&amp;gt;
        } else {
          history.push(/logIn)
        }
    }} /&amp;gt;
  )
}

export default Protector;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order for this to work, there must be a few things to understand and implement elsewhere in the app.&lt;/p&gt;

&lt;p&gt;First thing that was new to me, was the use of the render prop for the Route. This is key, because just as previously we passed things to Route using the component prop, it would evaluate only once. This does not work, as we need the route to update each time a new prop is passed to it, and this is only done with render. As a side effect, authentication and authorization are checked each time a new component is rendered through the Protector component through its Route.&lt;/p&gt;

&lt;p&gt;Next, what else was new to me, was the use of "...rest" in prop syntax. I have never seen this before and I'm glad that I encountered this. It is a .js keyword that automatically fills in all the props from a component being passed in and passes them to the next child in the hierarchy. This is particularly useful here, as it is used to pass everything passed into the Protector into the render in Route.&lt;/p&gt;

&lt;p&gt;Finally, there need to be all the helper methods added in App.js, including all the handleLogIn's and handleLogOut's that will interface with the backend to make sessions that will then set the state in app that will satisfy the "user" conditional in the Protector's ternary render, and will not allow any of the protected pages to be shown unless "user" or "session" return truthy.&lt;/p&gt;

&lt;p&gt;All in all, although there are a few new things to learn to make Protected routes work with React Router, it really is a clean, flexible, and fairly safe way to make resources inaccessible unless the necessary conditions are met.&lt;/p&gt;

&lt;p&gt;Learning about this tool and all the necessary implementations has been interesting and I look forward to using them in my future projects.&lt;/p&gt;

&lt;p&gt;Cheers.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>security</category>
    </item>
    <item>
      <title>What if we want to be friends ?</title>
      <dc:creator>arthurvfain</dc:creator>
      <pubDate>Wed, 14 Jul 2021 18:02:15 +0000</pubDate>
      <link>https://dev.to/arthurvfain/what-if-we-want-to-be-friends-5gp8</link>
      <guid>https://dev.to/arthurvfain/what-if-we-want-to-be-friends-5gp8</guid>
      <description>&lt;p&gt;Throughout my coding journey, when learning something new, I always wondered how something I am learning now as a new software engineer has implications on what I already know as someone who has been on the internet practically my whole life. It blew my mind to be able think that I understand where something that I couldn't even fathom a few months ago, I can now see how different websites accomplish their goals.&lt;/p&gt;

&lt;p&gt;Now, currently learning and working with creating my own back-end databases, a conversation with a friend on the matter led me to ask myself: "Now that I'm working with databases, do I know how social media giants such as Facebook and Twitter work ? How do databases of hundreds of millions of users keep track of who is friends with who ?"&lt;/p&gt;

&lt;p&gt;Just these past few weeks I have starting about relational databases and the kinds of relationships different table of information have with one another. Usually by having a table of one kind of Data, for example "grocery items" and another table with a different kind of data, for example "customers" joined with a third kind of table that "joins" two different kinds of "Class instances" and creates a "many to many" relationship. See figure below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iRAY3TzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/PhPWrfp/aww-board.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iRAY3TzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/PhPWrfp/aww-board.png" alt="many to many"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each "order" belongs to a "grocery item" and to a "customer" while each "customer" has many "orders" and through "orders" has many "grocery items" and similarly, each "grocery item" has many "orders" it can be in, and through the many "order" has many "customers" as well.&lt;/p&gt;

&lt;p&gt;This naturally brought up the question for me, what if I want to be friends with a human, and not a Jicama ? Do we need a second table of humans, just for me to be friends with them ? Would they be anti-humans ? Food for thought.&lt;/p&gt;

&lt;p&gt;Thankfully we can have something completely different !&lt;/p&gt;

&lt;p&gt;Using ActiveRecord, we can make a join table model that joins two instances of the same class, allowing for human-to-human friendships in this case. The power behind this is obvious as  it creates the opportunity to create relationships between two instances of the same class, without much issue. &lt;/p&gt;

&lt;p&gt;The domain model would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y0ZTv5HG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/cX0mvMq/aww-board-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y0ZTv5HG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/cX0mvMq/aww-board-3.png" alt="self-join"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have a model where a "friendship" belongs to two instances of "human" and each "human" has many "friendships" and through them has many other "humans". The syntax for setting this kind of relationship is a little different than usual, and has some nuances depending on the kind of relationship between to "humans" that will be the subject of future posts. This just serves to provide some insight into what is possible and some food for thought.&lt;/p&gt;

&lt;p&gt;Happy databasing.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How I got into Software Engineering (Every good Villain needs an origin story)</title>
      <dc:creator>arthurvfain</dc:creator>
      <pubDate>Tue, 22 Jun 2021 18:29:01 +0000</pubDate>
      <link>https://dev.to/arthurvfain/how-i-got-into-software-engineering-every-good-villain-needs-an-origin-story-27al</link>
      <guid>https://dev.to/arthurvfain/how-i-got-into-software-engineering-every-good-villain-needs-an-origin-story-27al</guid>
      <description>&lt;h3&gt;
  
  
  Hi Everyone,
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Just thought it may be interesting for myself to reflect back on the life that brought me here as well as tell my story for anyone interested as well as maybe in a similar situation I was in and needing that final push to dive into something new. (chances are, if you are on this website, it has something to with computers) but hopefully my message can inspire someone to do something they have always wanted to but never really felt like they could. I hope you enjoy.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1994, Moscow, Russian Federation
&lt;/h4&gt;

&lt;p&gt;I was born to Vitaliy and Assia, Vitaliy being a PhD in applied mathematics focusing on facial recognition software for the KGB and Assia being an orthodontist PhD on a cleft-palate team at one of the major hospitals in Moscow. My first word was Tractor. I loved watching the garbage trucks around our neighborhood use their robotic arms to lift enormous metal dumpsters so high overhead to dump their contents, doing the work of 20 men in one fell swoop. I rode camels at the park, went sledding in the snow with my dad, and dragged a small trailer with my bike when grandma and I would go shopping- normal two year old Moscovite things. In 1997 my family emigrated to the United States, leaving everything behind in search of a new life.&lt;/p&gt;

&lt;h4&gt;
  
  
  1997-2012, Worcester, Massachusetts, United States of America
&lt;/h4&gt;

&lt;p&gt;Growing up in a new environment was not easy, not only were my family language, customs, and cuisine so different from everyone else, but also the pressure I felt and imposed on myself as the child of such accomplished first generation immigrants was unlike anyone I knew- I always believed that if my parents were able to accomplish so much under such an oppressive government as in the USSR, living in the country they only dreamed of for their whole lives, I was to exceed their accomplishments tenfold. For the longest time I believed that this was the only way to have their approval, and it pervaded almost all decisions I made through this time period.&lt;br&gt;
&lt;em&gt;This pressure I put on myself is something I still deal with today, but thanks to the choices I've made, I have been able to not let it affect me as much as it used to.&lt;/em&gt;&lt;br&gt;
In Middle School, the pressure became too much and I began to resent school and went entire months without doing any schoolwork, and thus completely fell behind in most of my classes. I learned here, that if I counted myself out and didn't apply myself at all, any failures could not be attributed to me- when I failed, I could always tell myself the story that it was because I didn't try and not because I wasn't smart enough or ____ enough, and if I did try things would be different but I didn't feel like trying. This relieved some of the pressure. Looking back, I just didn't want to be compared to anyone. Strangely enough, I found some respite in classes such as Biology and Chemistry, they came rather naturally and I felt like I was learning all about the coolest story ever told, kinda like a learning about the Star Wars or Halo universe, except it was &lt;em&gt;my universe&lt;/em&gt;. I really enjoyed learning about these things and didn't feel pressure as they were outside of &lt;em&gt;my parents shadow&lt;/em&gt;. For the most part, this attitude only got worse through my high-school years, especially when it came to anything having to do with Math and Computer Science because of the direct comparison to my dad it allowed for.&lt;br&gt;
Throughout High School, my mom had progressed her Dental Career (for which she had to re-complete dental school in the USA) to the point of acquiring her own private practice, and had begun growing it and slowly giving me opportunities to contribute to her business. I began doing basic IT things and taught myself how to run wires through commercial property as well as tried my hand as a dental assistant for a few root canals and fillings and it seemed easy enough of work, appeared to make decent money, was a straightforward path, and seemed to make my mom happy.&lt;br&gt;
The time had come to apply for college and I believed I had found what I wanted to do with my life- be a dentist and take over my mom's practice.&lt;br&gt;
I didn't try applying to too many places, but the minute I was accepted to a university with an accelerated 7-year dental program, my college search was over and I committed to Adelphi University in Long Island, NY.&lt;/p&gt;

&lt;h4&gt;
  
  
  2012-2020 Long Island, NY, United States of America
&lt;/h4&gt;

&lt;p&gt;I started college and declared myself a Biology Major as it was the default major for the fast-track to becoming a dentist. Everything was going fairly well, I slowly began to apply myself even towards classes that I was not interested in. I began believing in myself and caring more about what would make me happy rather than trying to impress anyone. At this time I prepared for and scored well on the DAT exam for dental school, but when it became time to apply for dental school, I took a hard look at myself, and realized how much debt I would be in, with the only feasible way of paying it back being either becoming the next Pablo Escobar, or actually waking up every day and looking into people's mouths. (up until this point it never actually occurred to me that if I were to become a dentist I would have to work as a dentist) Neither of those seemed appealing to me, so much to the chagrin of my parents, my pursuit of dentistry had come to an end. What else is there for a Biology major in their third year of undergrad to do ? Of course to pursue Medicine.&lt;br&gt;
It didn't take too long after taking the MCAT that I realized I backed myself into the same exact place I did almost exactly a year prior with dentistry. I realized that I wanted to be a Doctor to be accepted by others, and not because I wanted to work as one. At this point, I fell into what I can now identify as a depression, and dropped out of school because I had lost purpose, and became a full time Starbucks Barista not only because I liked free coffee, but also because I didn't have to try to be anyone anymore. &lt;em&gt;Just a humble Barista.&lt;/em&gt; On the side I started realizing that I have an eye for seeing automation and started seeing ideas for websites and apps that my hands couldn't make, but was not ready or willing to believe in myself enough to commit to learning a new skill to bring what I envisioned to life. After a few years, seeing everyone I knew graduating, getting real jobs, moving on in life, the pain of staying the same overcame the fear of change, and I re-enrolled back at Adelphi, except this time, as a Biochemistry Major. (Molecular biology and biochemistry were what I realized I found the most interest in and was easiest to put time into) I spent hours working in a Synthetic Chemistry Lab, wrote papers, and TA'd my old Physical Chemistry lab. The next step for a Biochemist, however, is almost certainly a PhD program in graduate school. I'm sure everyone here will sense a pattern, but I took the GRE to apply to Graduate Schools with Biochemistry PhD programs, but did not go through applying as they are all somewhere between a 5-8 year endeavors. I decided to take some time to work in industry, to see what working in the Chemistry field was like, and after 20 months working raw material QA for a multinational cosmetics manufacturer, I realized I hate it. I was finally ready to overcome my fears of not measuring up to my dad, and with my son due to be born in two months, became willing to finally take on something that I never thought I could.&lt;/p&gt;

&lt;h4&gt;
  
  
  2021 Flatiron School, New York, NY United States of America
&lt;/h4&gt;

&lt;p&gt;Here we are.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>I Talk to my Computer (how do you code a website?)</title>
      <dc:creator>arthurvfain</dc:creator>
      <pubDate>Tue, 01 Jun 2021 17:06:32 +0000</pubDate>
      <link>https://dev.to/arthurvfain/i-talk-to-my-computer-how-do-you-code-a-website-131g</link>
      <guid>https://dev.to/arthurvfain/i-talk-to-my-computer-how-do-you-code-a-website-131g</guid>
      <description>&lt;h1&gt;
  
  
  Creating Interactive Websites with JavaScript
&lt;/h1&gt;

&lt;h2&gt;
  
  
  (A How-To Guide)
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Opening up index.html for the first time in a project and seeing a blank white page is definitely daunting, but taking things one step at a time really helps me organize a work-flow that after practicing a few times has become repeatable, almost with my eyes closed....not really.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Set Up
&lt;/h2&gt;

&lt;p&gt;First, I look at the deliverables, or what actually is to be accomplished through my work - knowing where I am headed is the first step for figuring out a plan on how to get there. In order for me to do this, I usually keep a description of the functionality needed open on one screen, while at the same time I have open the blank index.html with my Developer Tools Console open to check my work in progress and splitting my main monitor with the code I am working on.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3BHI_sZZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rgj6rjm1w85hsca2nwj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3BHI_sZZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rgj6rjm1w85hsca2nwj.png" alt="Typical WorkSpace"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  You talk to your computer ?
&lt;/h2&gt;

&lt;p&gt;All the time. This is a quick description of what kind of conversations I have with it, asking how it can do what I want it to do as well as asking it what it needs from me in order to do that. &lt;/p&gt;
&lt;h2&gt;
  
  
  A Quick Side Note
&lt;/h2&gt;

&lt;p&gt;I &lt;strong&gt;cannot&lt;/strong&gt; emphasize enough the utility of using &lt;code&gt;console.log(anything)&lt;/code&gt; for testing &lt;em&gt;everything&lt;/em&gt;. Whether it be making sure I'm grabbing the right HTML element or verifying that a function I'm writing has access to the all the variables I need it to in order to work I start by console logging to make sure it works.&lt;/p&gt;
&lt;h3&gt;
  
  
  Selecting HTML Elements for Ease of Use
&lt;/h3&gt;

&lt;p&gt;In my experience, most often all the HTML elements and the CSS styling has already been put in place, leaving the only work for me to use JavaScript in order to make them interactive and work as intended.&lt;/p&gt;
&lt;h4&gt;
  
  
  Assigning Elements to Variables
&lt;/h4&gt;

&lt;p&gt;Targeting elements using &lt;code&gt;document.querySelector()&lt;/code&gt; on either a class of elements (using .className) or a specific element (using #idTagName) and assigning them to a clear variable name makes keeping track of and adding elements or features such as eventListeners much easier in the long run.&lt;br&gt;
(note: I find it helpful to add event listeners to static HTML elements here too)&lt;/p&gt;
&lt;h3&gt;
  
  
  Establishing Communication with the Server
&lt;/h3&gt;

&lt;p&gt;This is where I usually make my first Fetch request just to see what kind of communication the server sends me. If my fetch request is to a database stored locally &lt;a href="https://github.com/typicode/json-server"&gt;&lt;em&gt;(shoutout json-server by typicode)&lt;/em&gt;&lt;/a&gt;, my first fetch will look something like this: &lt;code&gt;fetch('http://localhost:3000).then(res=&amp;gt;res.json()).then(console.log)&lt;/code&gt;&lt;br&gt;
Thanks to my console.log, I know exactly what kind of info I am receiving back, and I can plan how to integrate it into where I trying to go based on the deliverables required of me.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LEtqSxzA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7t5lk0xilivqxkln6pea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LEtqSxzA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7t5lk0xilivqxkln6pea.png" alt="Fetch Request"&gt;&lt;/a&gt;&lt;br&gt;
In this case, thanks to my console.log, I can see exactly that the response to my fetch is &lt;em&gt;an array of objects.&lt;/em&gt; and now I know &lt;em&gt;exactly&lt;/em&gt; how to proceed and what I want the fetch's callback function to be.&lt;/p&gt;
&lt;h3&gt;
  
  
  Rendering The DOM
&lt;/h3&gt;

&lt;p&gt;Here is where it becomes extremely important to keep track of functions and particularly the parameters that they take. In my experience, I have often been required here to make a JavaScript 'template' function that will be called many times as the response to my get request is iterated on. Depending on how much HTML is provided, I can either use rendering functions such as this to populate parts of a webpage or create entire elements altogether. I usually do this in a series of functions, starting with the function that accepts the response of the fetch and then iterates over it in the prescribed way (usually by passing individual elements to another function)&lt;br&gt;
(Pro tip: if I think I'm going to want to access a specific element for a function, I've found that I like manually adding an attribute called dataset, and usually making an id attribute to it, and assigning it the value from the object the function is currently handling:&lt;br&gt;
&lt;code&gt;deleteButton.dataset.id = thingObject.id&lt;/code&gt;&lt;br&gt;
this allows me to access that value later on in the event listeners section through target)&lt;/p&gt;
&lt;h3&gt;
  
  
  Event Listeners
&lt;/h3&gt;

&lt;p&gt;Throughout rendering to the DOM, depending on the functionality desired, I will add Event Listeners for the desired functionality to the individual elements as they are being generated. Part of making event listeners is adding what happens at the event, and almost always I will make it a callback function: &lt;code&gt;deleteButton.addEventListener('click', deleteThing)&lt;/code&gt; When declaring the function, based on js knowledge, I know that a function called by an eventListener will have its first parameter be the actual event, so when building the event listener callback function, I start with console.logging the event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function deleteThing(e)
{
    console.log(e)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Examining the event in the Developer Tools console, I can find target, and drilling down to dataset, I can access the same id I added for each element in the Rendering the DOM section ! and now any server communication that I do as a result of these events will be targeted specifically to just that object !&lt;br&gt;
(Pro Tip: that same id value in the dataset attribute is stored as a string, so parseInt() the id, otherwise it may not work as indexes for accessing objects in another fetch  are often int's)&lt;br&gt;
&lt;code&gt;idInt = parseInt(e.target.dataset.id, 10)&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Server Communication
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Setting up
&lt;/h3&gt;

&lt;p&gt;Up until this point, the only interaction made was a fetch to retrieve data, now armed with everything including the element id's, I can easily make my POST/PATCH/DELETE fetches!&lt;br&gt;
I tend to put these in the functions that their respective event listeners call [i.e. deleteButton calls deleteThing(), likeButton calls likeThing()]. When making PATCH or POST requests, I construct the object that I will eventually stringify in the request early on in the function pulling together data from the event as well as some processing whether it be to add to an existing value of attribute or to add some data from a form if my function is acting from a form submit event.&lt;/p&gt;
&lt;h3&gt;
  
  
  Rendering the Changes from an Event
&lt;/h3&gt;

&lt;p&gt;In my experience I have found that the .then() function can be extremely useful, because in the case of POST and PATCH fetches, &lt;em&gt;the resolved promise returns the changed made to the server !&lt;/em&gt; This is crucial for two reasons. First, anything done in a .then() by definition will only happen after successful updating of the server's data, and second, after processing using .json, (and a console.log to review the kind of contents returned) can be directly passed into a rendering function that is already made ! I put an example of this entire process below !&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function submitNewObjectFromForm(e)
{
    e.preventDefault()
    let newObject =
    {
        firstAttribute: `${e.target.first.value}`,
        secondAttribute: `${e.target.second.value}`
    }
    fetch('http://localhost:3000/objects',
    {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'accept': 'application/json'
        },
        body: JSON.stringify(newObject)
    })
    .then(resp=&amp;gt;resp.json()).then(data=&amp;gt;renderObject(data))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  At this point, by setting myself up for my next tasks, as well as breaking everything down into little steps, I was able to smoothly set up my basic framework and thought processes for making interactive webpages through communication with a rudimentary server !
&lt;/h2&gt;

&lt;h2&gt;
  
  
  TL:DR
&lt;/h2&gt;

&lt;p&gt;When facing a challenge, break it down into steps ! These are the general steps I take to go from a blank index.html page to a fully functional website!&lt;/p&gt;

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