<?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: Dylan Rhinehart</title>
    <description>The latest articles on Forem by Dylan Rhinehart (@darealdyl).</description>
    <link>https://forem.com/darealdyl</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%2F988445%2Feafcc412-067d-41ab-9366-dd3dc303dfa6.jpeg</url>
      <title>Forem: Dylan Rhinehart</title>
      <link>https://forem.com/darealdyl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/darealdyl"/>
    <language>en</language>
    <item>
      <title>Ruby On Rails : Encryption With BCrypt</title>
      <dc:creator>Dylan Rhinehart</dc:creator>
      <pubDate>Mon, 06 Mar 2023 07:51:21 +0000</pubDate>
      <link>https://forem.com/darealdyl/ruby-on-rails-encryption-with-bcrypt-4l5p</link>
      <guid>https://forem.com/darealdyl/ruby-on-rails-encryption-with-bcrypt-4l5p</guid>
      <description>&lt;p&gt;Keeping user data safe is crucial when developing web applications. In Ruby on Rails, bcrypt is a built-in gem that lets developers secure their applications by encrypting passwords. In this blog, we'll talk about how to use bcrypt in Ruby on Rails to beef up your app's security.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is bcrypt?
&lt;/h2&gt;

&lt;p&gt;Bcrypt is a password hashing function that uses a salted key derivation function to secure passwords. It's designed to be slow and computationally expensive, making it difficult for attackers to perform brute-force attacks on hashed passwords. Bcrypt is widely used in web applications to store and authenticate user passwords.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Bcrypt in Ruby on Rails
&lt;/h2&gt;

&lt;p&gt;To get started with bcrypt, you need to add the bcrypt gem to your Rails application by adding this line to your Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'bcrypt'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding the bcrypt gem to your application, you can use it to hash user passwords by calling the bcrypt method in your Rails model. For example, say you have a User model with an email and password field. To hash the password before saving it to the database, you can use this code:&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; ApplicationRecord
  has_secure_password
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The has_secure_password method automatically hashes and stores the password in the database when a new user is created.&lt;/p&gt;

&lt;p&gt;To authenticate users, you can use the authenticate method provided by the has_secure_password method. For example, say you have a SessionsController that handles user authentication. You can authenticate a user by checking their email and password against the hashed password in the database like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class SessionsController &amp;lt; ApplicationController
  def create
    user = User.find_by(email: params[:email])
    if user &amp;amp;&amp;amp; user.authenticate(params[:password])
      # User is authenticated
    else
      # Authentication failed
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The authenticate method checks the provided password against the hashed password stored in the database. If the passwords match, the user is authenticated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using bcrypt is a powerful way to secure your Ruby on Rails web application. It protects your users' data from attackers and reduces the risk of data breaches. The has_secure_password method provided by Rails makes it easy to use bcrypt in your application. This lets you focus on other aspects of your app while keeping your users' data safe.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>An Introduction to Classes in Ruby: A Guide to Object-Oriented Programming</title>
      <dc:creator>Dylan Rhinehart</dc:creator>
      <pubDate>Mon, 13 Feb 2023 15:04:10 +0000</pubDate>
      <link>https://forem.com/darealdyl/an-introduction-to-classes-in-ruby-a-guide-to-object-oriented-programming-1l56</link>
      <guid>https://forem.com/darealdyl/an-introduction-to-classes-in-ruby-a-guide-to-object-oriented-programming-1l56</guid>
      <description>&lt;p&gt;&lt;strong&gt;Ruby&lt;/strong&gt; is an &lt;em&gt;object-oriented programming language&lt;/em&gt;, and &lt;strong&gt;classes&lt;/strong&gt; play a crucial role in this paradigm. A &lt;strong&gt;class&lt;/strong&gt; is a blueprint that defines objects and their behavior. In this article, we'll dive into the basics of classes in Ruby and how they can help you organize and manage your code.&lt;/p&gt;

&lt;p&gt;To start, let's take a look at a simple &lt;strong&gt;class in Ruby&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog
  def initialize(name, breed)
    @name = name
    @breed = breed
  end

  def bark
    puts "Woof!"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we've created a &lt;strong&gt;class&lt;/strong&gt; called Dog with two attributes: name and breed. The initialize &lt;strong&gt;method&lt;/strong&gt; is a special &lt;strong&gt;method&lt;/strong&gt; that is called when a new &lt;em&gt;instance&lt;/em&gt; of the class is created. This is where you can set the initial state for the object. In our example, we are setting the name and breed attributes when a new Dog instance is created.&lt;/p&gt;

&lt;p&gt;Creating an instance of the class is simple. Just use the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dog = Dog.new("Fido", "Labrador")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And to call the bark method on the dog object, use the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dog.bark
# Output: Woof!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition to the initialize method, Ruby has other special methods that make it easy to define getters and setters for class attributes. For example, you can use &lt;strong&gt;attr_reader&lt;/strong&gt;, &lt;strong&gt;attr_writer&lt;/strong&gt;, and &lt;strong&gt;attr_accessor&lt;/strong&gt; to access and modify the state of an object.&lt;/p&gt;

&lt;p&gt;Here's an example of using &lt;strong&gt;attr_reader&lt;/strong&gt; and &lt;strong&gt;attr_writer&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog
  attr_reader :name
  attr_writer :breed

  def initialize(name, breed)
    @name = name
    @breed = breed
  end

  def bark
    puts "Woof!"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;strong&gt;attr_reader&lt;/strong&gt; and &lt;strong&gt;attr_writer&lt;/strong&gt;, you can access the name and breed attributes directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dog = Dog.new("Fido", "Labrador")
puts dog.name
# Output: Fido

puts dog.breed
# Output: Labrador

dog.breed = "Golden Retriever"
puts dog.breed
# Output: Golden Retriever
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you want both getter and setter methods, you can use &lt;strong&gt;attr_accessor&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog
  attr_accessor :name, :breed

  def initialize(name, breed)
    @name = name
    @breed = breed
  end

  def bark
    puts "Woof!"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the &lt;strong&gt;basics of classes in Ruby&lt;/strong&gt;, but they will give you a solid foundation to build upon. By using classes in your Ruby programs, you'll be able to create objects, manage their state, and define their behavior, making your code easier to organize and maintain.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Creating a CRUD Application with React: Mastering useState and useEffect</title>
      <dc:creator>Dylan Rhinehart</dc:creator>
      <pubDate>Thu, 19 Jan 2023 17:09:17 +0000</pubDate>
      <link>https://forem.com/darealdyl/creating-a-crud-application-with-react-mastering-usestate-and-useeffect-441h</link>
      <guid>https://forem.com/darealdyl/creating-a-crud-application-with-react-mastering-usestate-and-useeffect-441h</guid>
      <description>&lt;p&gt;&lt;strong&gt;CRUD&lt;/strong&gt;, which stands for &lt;strong&gt;Create, Read, Update, and Delete&lt;/strong&gt;, is a fundamental aspect of any web application. In this blog post, we will explore how to implement the &lt;strong&gt;CRUD&lt;/strong&gt; operations using React's &lt;strong&gt;useState&lt;/strong&gt; and &lt;strong&gt;useEffect&lt;/strong&gt; hooks. These hooks allow us to manage state and side effects in functional components, making our code more readable and maintainable.&lt;/p&gt;

&lt;p&gt;We will start by using &lt;strong&gt;useState&lt;/strong&gt; to create a state variable for our data, which will be an array of items. We will also create a setter function to update the state, which will be used to add, edit, and delete items 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;import { useState, useEffect } from 'react';

function MyComponent() {
  const [items, setItems] = useState([]);

  const addItem = (item) =&amp;gt; {
    setItems([...items, item]);
  }

  const editItem = (index, item) =&amp;gt; {
    const newItems = [...items];
    newItems[index] = item;
    setItems(newItems);
  }

  const deleteItem = (index) =&amp;gt; {
    const newItems = [...items];
    newItems.splice(index, 1);
    setItems(newItems);
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; addItem({ name: "New Item" })}&amp;gt;Add Item&amp;lt;/button&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;tbody&amp;gt;
          {items.map((item, index) =&amp;gt; (
            &amp;lt;tr key={item.name}&amp;gt;
              &amp;lt;td&amp;gt;{item.name}&amp;lt;/td&amp;gt;
              &amp;lt;td&amp;gt;
                &amp;lt;button onClick={() =&amp;gt; editItem(index, { name: "Edited Item" })}&amp;gt;Edit&amp;lt;/button&amp;gt;
                &amp;lt;button onClick={() =&amp;gt; deleteItem(index)}&amp;gt;Delete&amp;lt;/button&amp;gt;
              &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
          ))}
        &amp;lt;/tbody&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have created 3 functions addItem, editItem, and deleteItem which will update the state of the items. In the render function, we have mapped through the items and displayed them in a table. We have also added buttons to edit and delete items.&lt;/p&gt;

&lt;p&gt;Next, we will use &lt;strong&gt;useEffect&lt;/strong&gt; to fetch data from an API and update our state. &lt;strong&gt;useEffect&lt;/strong&gt; takes two arguments: a function that will run when the component is rendered, and an array of dependencies, which determine when the effect should be run. In this case, we want to fetch data when the component is first rendered, so we will pass an empty array as the second argument.&lt;br&gt;
&lt;/p&gt;

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

function MyComponent() {
  const [items, setItems] = useState([]);

  useEffect(() =&amp;gt; {
    fetch('https://my-api.com/items')
      .then(response =&amp;gt; response.json())
      .then(data =&amp;gt; setItems(data))
  }, []);

  // ...rest of the component remains the same

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

&lt;/div&gt;



&lt;p&gt;In the example above, when the component is first rendered, the useEffect function will run and fetch data from the API. It will then update the state with the data&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>cloud</category>
      <category>serverless</category>
      <category>discuss</category>
    </item>
    <item>
      <title>DOM Manipulation Basics: Vanilla JS</title>
      <dc:creator>Dylan Rhinehart</dc:creator>
      <pubDate>Thu, 22 Dec 2022 18:16:51 +0000</pubDate>
      <link>https://forem.com/darealdyl/dom-manipulation-basics-vanilla-js-3n5o</link>
      <guid>https://forem.com/darealdyl/dom-manipulation-basics-vanilla-js-3n5o</guid>
      <description>&lt;p&gt;The Document Object Model &lt;strong&gt;(DOM)&lt;/strong&gt; is an essential part of web development, and JavaScript allows us to manipulate the DOM in powerful ways. The DOM is a tree-like structure that represents the HTML of a web page, and by using JavaScript, we can add, remove, and modify elements in the DOM to create dynamic and interactive web pages.&lt;/p&gt;

&lt;p&gt;One common way to manipulate the DOM is through the document object, which is a global object in JavaScript that represents the HTML document. Using the document object, we can select elements on the page, access their properties, and modify their content or style.&lt;/p&gt;

&lt;p&gt;For example, to select an element by its unique ID, we can use the &lt;strong&gt;document.getElementById&lt;/strong&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const element = document.getElementById('my-element');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use &lt;strong&gt;document.querySelector&lt;/strong&gt; method, this method can prove more useful at times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//To get an element by ID
const element = document.querySelector('#my-element-id');

//To get an element by Class
const element = document.querySelector('.my-element-class');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note the difference between ID and Class. To find an ID you must use &lt;strong&gt;'#myId'&lt;/strong&gt;. To find a Class you must use &lt;strong&gt;'.myClass'&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once we have selected an element, we can modify its content using the &lt;strong&gt;innerHTML&lt;/strong&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.innerHTML = 'Hello, world!';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also modify the style of an element using the &lt;strong&gt;style&lt;/strong&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.style.color = 'red';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition to these basic techniques, we can use methods such as &lt;strong&gt;createElement&lt;/strong&gt; and &lt;strong&gt;appendChild&lt;/strong&gt; to add new elements to the DOM, and &lt;strong&gt;removeChild&lt;/strong&gt; to remove elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.createElement("div");
element.appendChild(aChild);
element.removeChild(aChild);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Overall, the DOM is a powerful tool for interacting with web pages, and learning to manipulate it is an important part of becoming a proficient JavaScript developer. Whether we are building simple websites or complex applications, the ability to manipulate the DOM is an essential skill that every JavaScript developer should have in their toolkit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction"&gt;&lt;strong&gt;MDN&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

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