<?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: Marcos Nikel</title>
    <description>The latest articles on DEV Community by Marcos Nikel (@marcossnikel).</description>
    <link>https://dev.to/marcossnikel</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%2F1093967%2F6d0509f2-0d49-4c7a-90b6-498ac858871a.jpeg</url>
      <title>DEV Community: Marcos Nikel</title>
      <link>https://dev.to/marcossnikel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcossnikel"/>
    <language>en</language>
    <item>
      <title>Understanding insertion sort algorithm</title>
      <dc:creator>Marcos Nikel</dc:creator>
      <pubDate>Mon, 05 Jun 2023 14:50:05 +0000</pubDate>
      <link>https://dev.to/marcossnikel/understanding-the-insertion-sort-algorithm-4pic</link>
      <guid>https://dev.to/marcossnikel/understanding-the-insertion-sort-algorithm-4pic</guid>
      <description>&lt;p&gt;In our day-to-day JavaScript programming, when we use the &lt;strong&gt;.sort()&lt;/strong&gt; method, there's a whole algorithm running behind the scenes. However, it's unlikely that Insertion Sort is the algorithm being used. But why is that?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are various sorting algorithms available, such as &lt;em&gt;Insertion Sort, Quick Sort, Merge Sort, Selection Sort, Bubble Sort, and many others&lt;/em&gt;. Each of them has different time and space complexities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Insertion Sort happens to be one of the less efficient ones, but why?&lt;/p&gt;

&lt;p&gt;In terms of complexity, Insertion Sort has a time complexity of &lt;strong&gt;O(n²) in most cases&lt;/strong&gt; and a &lt;strong&gt;space complexity of O(1)&lt;/strong&gt;, which is good. However, considering a time complexity of this magnitude, there are sorting algorithms that achieve a time complexity of O(n log n), which is better than O(n²).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;So, how does this algorithm work?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initially, we consider the first element of the list as a sorted list with a single element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, we move on to the next element in the unsorted list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We compare the current element with the elements in the sorted list, from right to left, until we find the correct position to insert the element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;During the comparison, if an element in the sorted list is greater than the current element, it is shifted one position to the right to make space for the insertion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We repeat steps 3 and 4 until all elements in the unsorted list are inserted into the sorted part of the list.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;This process continues until all elements are in the sorted list, resulting in a completely ordered list. Insertion Sort is an efficient sorting algorithm for small lists or partially sorted lists. However, its performance significantly deteriorates for very large lists.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below, I provide an example implementation of this algorithm, including an auxiliary function called &lt;strong&gt;swap()&lt;/strong&gt; responsible for swapping elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gKZVSd_Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zuxtjj4awe1czknzypwf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gKZVSd_Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zuxtjj4awe1czknzypwf.png" alt="Code example" width="800" height="639"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>sorting</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Contact form with react-hook-form and emailjs</title>
      <dc:creator>Marcos Nikel</dc:creator>
      <pubDate>Fri, 02 Jun 2023 02:02:36 +0000</pubDate>
      <link>https://dev.to/marcossnikel/contact-form-with-react-hook-form-and-emailjs-4jhh</link>
      <guid>https://dev.to/marcossnikel/contact-form-with-react-hook-form-and-emailjs-4jhh</guid>
      <description>&lt;h1&gt;
  
  
  What I Wanted to Do
&lt;/h1&gt;

&lt;p&gt;Today, I started developing my portfolio, and one thing I really wanted to do was create a contact form through which people could reach out to me via email. Since I had never done this before, I found myself wondering, "How can I do this?"&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;Then, I remembered a library that I had been eager to learn, react-hook-form. I thought it was the perfect opportunity to learn it because it provides amazing control over form data. However, I had no idea how to send the data to my email. After conducting a brief search, I came across various possibilities, but one that caught my eye was the &lt;strong&gt;emailjs&lt;/strong&gt; library. It was user-friendly and only required a &lt;strong&gt;public key&lt;/strong&gt;, an &lt;strong&gt;email template ID&lt;/strong&gt;, and a &lt;strong&gt;service ID&lt;/strong&gt; from emailjs. Additionally, I had to make some minor configurations in VSCode. In this article, &lt;strong&gt;&lt;em&gt;I will provide an example of how to configure emailjs.&lt;/em&gt;&lt;/strong&gt;&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%2Fhieg067r00fgi5zknd85.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%2Fhieg067r00fgi5zknd85.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; In the image above, you can see that I call the &lt;strong&gt;register&lt;/strong&gt; method from the hook form, which is responsible for keeping track of the form data. In the next image, you will see that I call the same method in my inputs to assign a name to the input.&lt;/p&gt;

&lt;p&gt;-&amp;gt; The &lt;strong&gt;handleSubmit&lt;/strong&gt; method, also from hook form, handles the form submission. We pass our other function, &lt;em&gt;onSubmit&lt;/em&gt;, to this method so that it can be executed. The &lt;em&gt;reset&lt;/em&gt; function is used to reset the input's state, setting the values back to empty strings (" ").&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;onSubmit&lt;/strong&gt; function, you need to set the template to send to the emailjs email template mentioned earlier. The keys &lt;strong&gt;from&lt;/strong&gt;, &lt;strong&gt;name&lt;/strong&gt;, &lt;strong&gt;fromEmail&lt;/strong&gt;, and &lt;strong&gt;message&lt;/strong&gt; are important, as you will see shortly.&lt;/p&gt;

&lt;p&gt;We call emailjs, passing the SERVICE_ID and TEMPLATE_ID that you select in your emailjs dashboard. I create two variables to store the values for me, and the third parameter represents your template parameters, which I define in the onSubmit function.&lt;/p&gt;

&lt;p&gt;In the image below, you can see the register method for the inputs mentioned earlier, as well as the form validations. That's pretty much all you need to do in your code.&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%2Fcxwm900wiku8v3c4zvge.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%2Fcxwm900wiku8v3c4zvge.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last important thing is to ensure that the variables' names in your onSubmit function match the keys in the object within the email template on the emailjs dashboard, as shown below:&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%2Fywvrt0ywsvofpt0lm5e1.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%2Fywvrt0ywsvofpt0lm5e1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I used the same names for my keys in the object. This is how emailjs recognizes the data when it is sent to the emailjs API.&lt;/p&gt;

&lt;p&gt;That's it for today, guys! You can learn more about react-hook-form and emailjs in their respective documentation. I will provide the links below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;emailjs: &lt;a href="https://www.emailjs.com/" rel="noopener noreferrer"&gt;https://www.emailjs.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;react-hook-form: &lt;a href="https://react-hook-form.com/" rel="noopener noreferrer"&gt;https://react-hook-form.com/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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