<?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: acw0415</title>
    <description>The latest articles on DEV Community by acw0415 (@acw0415).</description>
    <link>https://dev.to/acw0415</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%2F885316%2Fb91c08fd-b20c-4656-b0f4-546030450e70.png</url>
      <title>DEV Community: acw0415</title>
      <link>https://dev.to/acw0415</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/acw0415"/>
    <language>en</language>
    <item>
      <title>Validations in Ruby on Rails</title>
      <dc:creator>acw0415</dc:creator>
      <pubDate>Thu, 15 Sep 2022 14:49:45 +0000</pubDate>
      <link>https://dev.to/acw0415/validations-in-ruby-on-rails-2j7e</link>
      <guid>https://dev.to/acw0415/validations-in-ruby-on-rails-2j7e</guid>
      <description>&lt;p&gt;Validations are basically used to check and see if the data that is sent through your application is what you expected it to be.&lt;/p&gt;

&lt;p&gt;You can basically think of it like a data filter, and there are many validation helpers you can use. Here are a few that I find useful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Teenager &amp;lt; ApplicationRecord
  validates :age, comparison: { greater_than_or_equal_to:13,
less_than_or_equal_to: 19}
end

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
this is used to compare the data to parameters that you set. In the example above we are validating if someone is considered a teenager by comparing the data we get to the parameters set and if the integer is between 13 and 19 it will pass the validation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Salsa &amp;lt; ApplicationRecord
  validates :spice, inclusion: { in: %w(mild medium hot),
    message: "%{value} is not a valid spice level" }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
this is used to give a specific piece of data that must be included. In the example above the data enter must include mild, medium, or hot or it will not pass the validation. (a side note: the %w(data) used above is the same as [data] in ruby.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class EmployeeDinner &amp;lt; ApplicationRecord
  validates :name, length: { minimum: 2 }
  validates :employee_number, length: { is: 9 }
  validates :menu, length: { maximum: 1000 }
  validates :times_attended, length: { in: 1..15 }

end

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
this is used to give a specific length for whatever you are validating. In the example above the name has a minimum of 2 so the string must be longer than 2 characters, the employee_number is setting a specific value of 9 so it cannot be anything more or less that 9 characters, the menu is setting a maximum character limit of 1000, and times_attended is giving a range of anywhere between 1 and 15.&lt;/p&gt;

&lt;p&gt;There are many different options for validations and they are all useful and unique it is worth taking the time to learn what each of them can do. I have only included 3 here, but there are many more. I have included a link below that goes over validations in far more detail. Hope this is helpful!&lt;/p&gt;

&lt;p&gt;source: &lt;a href="https://guides.rubyonrails.org/active_record_validations.html"&gt;https://guides.rubyonrails.org/active_record_validations.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
    </item>
    <item>
      <title>NPM</title>
      <dc:creator>acw0415</dc:creator>
      <pubDate>Wed, 24 Aug 2022 21:36:18 +0000</pubDate>
      <link>https://dev.to/acw0415/npm-157p</link>
      <guid>https://dev.to/acw0415/npm-157p</guid>
      <description>&lt;p&gt;Npm stands for Node Package Manager. It is a manager for packages on the Node JavaScript platform. Developers all over the world use npm to publish and share their code and it is known as the world's largest software registry.&lt;/p&gt;

</description>
      <category>opensource</category>
    </item>
    <item>
      <title>A Brief Overview of useState</title>
      <dc:creator>acw0415</dc:creator>
      <pubDate>Sun, 31 Jul 2022 23:38:18 +0000</pubDate>
      <link>https://dev.to/acw0415/a-brief-overview-of-usestate-348j</link>
      <guid>https://dev.to/acw0415/a-brief-overview-of-usestate-348j</guid>
      <description>&lt;h2&gt;
  
  
  What is useState()?
&lt;/h2&gt;

&lt;p&gt;So useState() creates a javascript object which you can use to dynamically update your web page asynchronously (not relying on information from elsewhere). It is similar to props with one key difference: state is handled within the component it is passed to.&lt;/p&gt;

&lt;h2&gt;
  
  
  How is it used?
&lt;/h2&gt;

&lt;p&gt;When implementing state in your function it must first be imported from the react library.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import {useState} from "react"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once it has been imported you can then use it by declaring it. The first item it returns will be the variable you are trying to set the state for, and the second item it returns will be a function for setting the value of that variable whatever it may be. Typically the naming convention for this function is the variable name you set preceded by the word "set" this helps to avoid confusion.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [variable, setVariable] = useState()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, whatever is inside of the parentheses of useState will be the default value until it is "set" with the setter function that you named. You can make this an empty version of whatever value you expect your variable to be (i.e. [], {}, "") whether it's an array, an object, or a string.&lt;/p&gt;

&lt;h2&gt;
  
  
  When should I use it?
&lt;/h2&gt;

&lt;p&gt;React utilizes state fairly heavily, due to the fact that it is so versatile, you will probably find yourself using it a lot. However when is it appropriate to use props instead? You may be asking. Well basically you should use state until the complexity increases (i.e. passing props down to child components) to the point where props seem to be required.&lt;/p&gt;

&lt;p&gt;This is a brief, high level, overview of state as a concept. For more detail on how state actually works, and what it can be used for I would recommend you refer to react's documentation: &lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://reactjs.org/docs/faq-state.html" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--zsQScK7q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://reactjs.org/logo-og.png" height="462" class="m-0" width="880"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://reactjs.org/docs/faq-state.html" rel="noopener noreferrer" class="c-link"&gt;
          Component State – React
        &lt;/a&gt;
      &lt;/h2&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--QGThkwG4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://reactjs.org/favicon.ico" width="64" height="64"&gt;
        reactjs.org
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
 

&lt;p&gt;I hope this helps a bit with understanding the concept!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to get information of an Element to the console on click in JS</title>
      <dc:creator>acw0415</dc:creator>
      <pubDate>Sat, 09 Jul 2022 20:24:08 +0000</pubDate>
      <link>https://dev.to/acw0415/how-to-get-information-of-an-element-on-click-in-js-1n9c</link>
      <guid>https://dev.to/acw0415/how-to-get-information-of-an-element-on-click-in-js-1n9c</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;code&gt;document.addEventListener("click", (e) =&amp;gt; console.log(e.target))&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So let me begin with this: I am by no means an expert on javaScript(&lt;em&gt;not yet anyway&lt;/em&gt;), this is simply a neat little trick I learned and found useful, so if I don't make something clear or don't use the right verbiage I apologize, I'm still learning and this explanation here is to help me better understand how everything works and hopefully you. Now that being said, I'll try and explain what this code is doing. &lt;/p&gt;

&lt;p&gt;First, "document" is simply setting the scope of the command, basically within your whole document you want the command to happen.&lt;/p&gt;

&lt;p&gt;Next, we use "addEventListener" which is one of the commands javaScript uses to interact with events in the real world, it "listens" for the event that you specify and runs the code you set in response. &lt;/p&gt;

&lt;p&gt;The next part within the parentheses is "click" in quotations, here you are setting what event your addEventListener function is listening for (i.e. "submit","keydown","mouseover", ect.) followed by a "," which separates one parameter from another.&lt;/p&gt;

&lt;p&gt;Next, we add an anonymous function with "e" as a variable within parentheses, normally these could be empty if you just want to run your code on click or whatever you set for your event but we need to reference the event variable later, this function variable could be named anything we want "e" is just short for event in this case. &lt;/p&gt;

&lt;p&gt;Then, we use arrow function syntax to target the last bit of the code, which is console.log(), console.log simply outputs whatever you specify in the parentheses to the console (usually a variable or a string) this is very useful for debugging. &lt;/p&gt;

&lt;p&gt;Finally, in console.log we have "e.target" which is the variable we just set in the anonymous function followed by "target" using dot notation, which is just saying to target whatever event is pointing to when the event is triggered (whatever you click on). &lt;/p&gt;

&lt;p&gt;Lastly, so what this code is saying is "Within the scope of my document, listen for a click and when that click is triggered, whatever was clicked on we want its information printed to the console". &lt;/p&gt;

&lt;p&gt;I have found this pretty useful for locating the spot I want something to show up on my webpage within the HTML code without having to scroll through each element until it highlights or for just finding an ID of an element without having to search for it.&lt;/p&gt;

&lt;p&gt;I hope this helps!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>So I'm in a bootcamp...</title>
      <dc:creator>acw0415</dc:creator>
      <pubDate>Fri, 01 Jul 2022 03:36:47 +0000</pubDate>
      <link>https://dev.to/acw0415/so-im-in-a-bootcamp-5ne</link>
      <guid>https://dev.to/acw0415/so-im-in-a-bootcamp-5ne</guid>
      <description>&lt;p&gt;I've been feeling pretty overwhelmed during the first week of the new coding bootcamp I'm attending. My cohort mirrors my sentiments, it just seems like we're getting bombarded with a sort of esoteric shotgun approach and it's pretty difficult sometimes to not give in to stress and have a breakdown. However, even with all of these feelings I've never been more excited, challenged, or hopeful. I honestly can't wait to learn more.&lt;/p&gt;

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