<?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: Joe Lee</title>
    <description>The latest articles on Forem by Joe Lee (@joe_lee90).</description>
    <link>https://forem.com/joe_lee90</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%2F837720%2F0df1e9a2-b700-4fde-a734-34ad9a013e04.jpg</url>
      <title>Forem: Joe Lee</title>
      <link>https://forem.com/joe_lee90</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joe_lee90"/>
    <language>en</language>
    <item>
      <title>Rails Basic Flow</title>
      <dc:creator>Joe Lee</dc:creator>
      <pubDate>Wed, 01 Jun 2022 19:10:26 +0000</pubDate>
      <link>https://forem.com/joe_lee90/rails-basic-flow-e5b</link>
      <guid>https://forem.com/joe_lee90/rails-basic-flow-e5b</guid>
      <description>&lt;p&gt;Workflow for basic Ruby on Rails app:&lt;/p&gt;

&lt;p&gt;A. Establish model relations and associations&lt;/p&gt;

&lt;p&gt;B. Create models, migrations, associations, validations&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g model Cheese name price:integer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this command will also make the create_cheeses migration table&lt;br&gt;
name is defaulted as a string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;belongs_to :cheese
has_many :stores, through: :cheeses, dependent: :destroy
validates :name, presence: true, uniqueness: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;syntax for associations and validations, both are done in the model.rb files&lt;/p&gt;

&lt;p&gt;then run&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;There's also db:seed:replant to refresh your database seeds&lt;/p&gt;

&lt;p&gt;C. Routes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :cheeses, only: [:index, :show, :create, :update, :destroy]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;syntax for using resource routes and only with the conventional names for the 5 CRUD functions. Note that only wouldn't technically be used here because it's including all of them.&lt;/p&gt;

&lt;p&gt;D. CRUD&lt;/p&gt;

&lt;p&gt;Now write the 5 CRUD functions:.&lt;br&gt;
:index and :create don't need ID, all other 3 will need syntax 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;Cheese.find(params[:id])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.find will throw ActiveRecord::RecordNotFound, and using create! and update! will throw ActiveRecord::RecordInvalid, so we can rescue from those throws 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;rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the :render_not_found_response function should be in the private section of the model, along with a wrapper for the 'find-by-id' code, as well as strong params:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;params.permit(:name, :price)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which I will be using for :create and :update functions to make sure I get the proper data for the object. &lt;/p&gt;

&lt;p&gt;remember to use these statuses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;status: :created, :not_found, :unprocessable_entity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Intro to RegEx</title>
      <dc:creator>Joe Lee</dc:creator>
      <pubDate>Wed, 11 May 2022 08:20:56 +0000</pubDate>
      <link>https://forem.com/joe_lee90/intro-to-regex-10kc</link>
      <guid>https://forem.com/joe_lee90/intro-to-regex-10kc</guid>
      <description>&lt;p&gt;Regular expressions, or RegEx, are versatile and powerful string patterns that are often used to match against strings for operations such as find, find and replace, and input validation. Another crucial aspect is that RegEx is widely supported by many languages.&lt;/p&gt;

&lt;p&gt;However, it's infamous for its crazy syntax.&lt;/p&gt;

&lt;p&gt;For example, this is the RegEx for a valid email address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/^[a-zA-Z0-9.!#$%&amp;amp;’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Almost enough to make Siri wince   ._.'&lt;/p&gt;

&lt;p&gt;Good thing this is an intro!&lt;/p&gt;

&lt;p&gt;RegEx uses '/' as delimiters, so /a/ would detect all of the 'a's in a string for you to then manipulate further. Note that it is case-sensitive.&lt;/p&gt;

&lt;p&gt;If you wanted to look for multiple characters, then simply wrap them in brackets like so: /[abc]/&lt;/p&gt;

&lt;p&gt;Or perhaps you want to look for a specific order of characters instead, then the RegEx would be like: /[h][i]/ for all instances of an 'h' followed by an 'i'. &lt;/p&gt;

&lt;p&gt;To cast a wider net: /[abc][def]/ for any 'a', 'b', or 'c' that is then followed by any 'd', 'e', 'f'. &lt;/p&gt;

&lt;p&gt;You can put in a range like so: /[a-c][1-3]/&lt;/p&gt;

&lt;p&gt;For multiple consecutive characters try: /[abc]{2}/  which is the same as /[abc][abc]/&lt;/p&gt;

&lt;p&gt;Which you can also put in a range: /[abc]{2-5}/ for [abc] 2-5 consecutive times, or simply {2,} for 2 or more occurrences.&lt;/p&gt;

&lt;p&gt;There is a lot more you can do to build RegEx's as you can tell from the email example, but now what do we actually do with them?&lt;/p&gt;

&lt;p&gt;Typically, they are paired with methods like .match, .replaceAll, and .search. &lt;/p&gt;

&lt;p&gt;You can find more information here: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, this site is a great interactive resource if you would like to dive right in: &lt;a href="https://regexr.com/"&gt;https://regexr.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Conditional rendering in React</title>
      <dc:creator>Joe Lee</dc:creator>
      <pubDate>Wed, 20 Apr 2022 16:08:37 +0000</pubDate>
      <link>https://forem.com/joe_lee90/conditional-rendering-in-react-396n</link>
      <guid>https://forem.com/joe_lee90/conditional-rendering-in-react-396n</guid>
      <description>&lt;p&gt;Here are a few ways to conditionally render your React components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;For multiple components, use a useState hook to decide which component will render and put the setState logic where the user would be making that decision, like clicking a button on a navigation header or choosing an option from a scrolldown.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you're trying to decide whether or not to render just one component, you can use the in line &amp;amp;&amp;amp; syntax. For example, true/false &amp;amp;&amp;amp;  will render the component if the truthy expression evaluates to true, and will not render if it's false. It's good for toggling displays and making sure the component shows only if it has data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is also the inline ? : operator that works as a shorthand for an if-else statement. It first evaluates a truthy expression before the ? and then will run the code after the ? for true, or the code after the : for false. This allows for a quick and easy way to conditionally render two different components that are mutually exclusive.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>.append vs .appendChild in JS</title>
      <dc:creator>Joe Lee</dc:creator>
      <pubDate>Tue, 29 Mar 2022 03:38:01 +0000</pubDate>
      <link>https://forem.com/joe_lee90/append-vs-appendchild-in-js-50mj</link>
      <guid>https://forem.com/joe_lee90/append-vs-appendchild-in-js-50mj</guid>
      <description>&lt;p&gt;What's the difference between .append and .appendChild?&lt;br&gt;
The distinction has robbed me of a couple of hours so here's to hopefully saving you a little bit of time.&lt;/p&gt;

&lt;p&gt;First of all, we can see the full functions at MDN:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Element.append(), inserts a set of Node objects or DOMString objects after the last child of the Element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node.appendChild(), adds a node to the end of the list of children of a specified parent node&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;.append can work with multiple Node or DOMString objects and must be called on an element, whereas .appendChild can only add a single Node to a parent Node and cannot work with DOMstrings.&lt;/p&gt;

&lt;p&gt;Another distinction is that .appendChild actually returns the child element so it cannot be used in a function chain, while .append returns nothing and thus can be chained.&lt;/p&gt;

&lt;p&gt;Lastly, .append is the more general method and can produce the same functionality as .appendChild, which serves a more specific purpose.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
