<?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: Bhartee Rameshwar Sahare</title>
    <description>The latest articles on DEV Community by Bhartee Rameshwar Sahare (@bhartee_sahare).</description>
    <link>https://dev.to/bhartee_sahare</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%2F1026436%2Fb3aae211-6080-4a55-8175-9aca705bc1bb.jpg</url>
      <title>DEV Community: Bhartee Rameshwar Sahare</title>
      <link>https://dev.to/bhartee_sahare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhartee_sahare"/>
    <language>en</language>
    <item>
      <title># Setting up Impression Tracking with Rails using the Impressionist Gem</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Mon, 06 Nov 2023 13:24:12 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/-setting-up-impression-tracking-with-rails-using-the-impressionist-gem-53oc</link>
      <guid>https://dev.to/bhartee_sahare/-setting-up-impression-tracking-with-rails-using-the-impressionist-gem-53oc</guid>
      <description>&lt;p&gt;Impression tracking is a valuable feature for many web applications as it allows you to keep a count of how many times a specific resource, like a post or a page, has been viewed. In this blog post, we will walk through the process of setting up impression tracking in a Ruby on Rails application using the Impressionist gem. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Creating a New Rails Application
&lt;/h3&gt;

&lt;p&gt;To get started, let's create a new Rails application. You can do this with the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails new impressionist_1_gem
&lt;span class="nb"&gt;cd &lt;/span&gt;impressionist_1_gem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Creating the Question Model
&lt;/h3&gt;

&lt;p&gt;In our example, let's assume that we want to track impressions on a &lt;code&gt;Question&lt;/code&gt; model. We'll create a &lt;code&gt;Question&lt;/code&gt; model and set up the necessary associations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails generate model Question title content:text
rake db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Adding the Impressionist Gem
&lt;/h3&gt;

&lt;p&gt;Now, let's add the Impressionist gem to your Rails application. Include it in your &lt;code&gt;Gemfile&lt;/code&gt; and run the following commands:&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;gem&lt;/span&gt; &lt;span class="s1"&gt;'impressionist'&lt;/span&gt;
&lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bundle &lt;span class="nb"&gt;install
&lt;/span&gt;rails generate impressionist
rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Setting Up the Impressionist Table
&lt;/h3&gt;

&lt;p&gt;The Impressionist gem generates a migration to create an &lt;code&gt;impressions&lt;/code&gt; table. Here's an example of what the migration might look like:&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="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateImpressionsTable&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;7.0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;up&lt;/span&gt;
    &lt;span class="n"&gt;create_table&lt;/span&gt; &lt;span class="ss"&gt;:impressions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:force&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:impressionable_type&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;integer&lt;/span&gt; &lt;span class="ss"&gt;:impressionable_id&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;integer&lt;/span&gt; &lt;span class="ss"&gt;:user_id&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:controller_name&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:action_name&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:view_name&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:request_hash&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:ip_address&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:session_hash&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt; &lt;span class="ss"&gt;:message&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt; &lt;span class="ss"&gt;:referrer&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt; &lt;span class="ss"&gt;:params&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timestamps&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="c1"&gt;# Add necessary indexes&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;down&lt;/span&gt;
    &lt;span class="n"&gt;drop_table&lt;/span&gt; &lt;span class="ss"&gt;:impressions&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;h3&gt;
  
  
  Step 5: Making the Question Model "Impressionable"
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;Question&lt;/code&gt; model, you need to make it "impressionable" by adding the &lt;code&gt;is_impressionable&lt;/code&gt; method:&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="c1"&gt;# app/models/question.rb&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Question&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;is_impressionable&lt;/span&gt;
  &lt;span class="c1"&gt;# ...&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Using Impression Tracking in the Questions Controller
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;QuestionsController&lt;/code&gt;, you can use Impressionist to track impressions on specific actions. For example, to track impressions on the &lt;code&gt;show&lt;/code&gt; and &lt;code&gt;index&lt;/code&gt; actions:&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="c1"&gt;# app/controllers/questions_controller.rb&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;QuestionsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="n"&gt;impressionist&lt;/span&gt; &lt;span class="ss"&gt;:actions&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:show&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# ...&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7: Displaying Impression Counts
&lt;/h3&gt;

&lt;p&gt;To display the impression counts in your view, you can use the &lt;code&gt;impressionist_count&lt;/code&gt; method provided by the Impressionist gem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;All Questions&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;thead&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Id&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Title&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Content&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Views&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&lt;/span&gt; &lt;span class="na"&gt;colspan=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Actions&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/thead&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tbody&amp;gt;&lt;/span&gt;
    &lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="vi"&gt;@questions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;impressionist_count&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;
          &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;link_to&lt;/span&gt; &lt;span class="s1"&gt;'Show'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt; |
          &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;link_to&lt;/span&gt; &lt;span class="s1"&gt;'Destroy'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="ss"&gt;method: :delete&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt; |
          &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;link_to&lt;/span&gt; &lt;span class="s1"&gt;'Edit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edit_question_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tbody&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;This blog post provides a step-by-step guide on setting up impression tracking in a Ruby on Rails application using the Impressionist gem. It covers the installation of necessary gems, creating models, and configuring impression tracking. With this setup, you can keep track of views on specific resources in your application.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Troubleshooting SSH Connection Issues with AWS EC2 Instances</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Thu, 02 Nov 2023 13:35:30 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/troubleshooting-ssh-connection-issues-with-aws-ec2-instances-2n47</link>
      <guid>https://dev.to/bhartee_sahare/troubleshooting-ssh-connection-issues-with-aws-ec2-instances-2n47</guid>
      <description>&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%2Fmsbbv0v9cgi7awhrasfk.jpg" 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%2Fmsbbv0v9cgi7awhrasfk.jpg" alt="AWS issue when we connect(Language: Ruby)"&gt;&lt;/a&gt;&lt;strong&gt;Problem 1: Connection Timed Out&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt;&lt;br&gt;
You try to SSH into your AWS EC2 instance using a command like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s2"&gt;"pem_file_name.pem"&lt;/span&gt; ubuntu@ec2-here_is_your_ip.ap-south-1.compute.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you encounter the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh: connect to host ec2-here_is_your_ip.ap-south-1.compute.amazonaws.com port 22: Connection timed out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Restart Your EC2 Instance:&lt;/strong&gt;&lt;br&gt;
Sometimes, instances can become unresponsive. In such cases, a simple solution is to restart the instance through the AWS Management Console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Inbound Security Group Configuration:&lt;/strong&gt;&lt;br&gt;
Make sure your EC2 instance's inbound security group allows SSH traffic from your IP address. To do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the AWS Management Console.&lt;/li&gt;
&lt;li&gt;Navigate to the EC2 dashboard.&lt;/li&gt;
&lt;li&gt;Select your instance.&lt;/li&gt;
&lt;li&gt;In the "Security groups" section, click on the associated security group.&lt;/li&gt;
&lt;li&gt;In the "Inbound rules" tab, add a rule that allows SSH (port 22) traffic from your computer's IP address. Select "My IP" instead of "Custom" or "Any location" for the source.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Problem 2: Bad Permissions on Private Key File&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt;&lt;br&gt;
You attempt to SSH into your EC2 instance using the private key file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s2"&gt;"pem_file_name.pem"&lt;/span&gt; ubuntu@ec2-here_is_your_ip_name.ap-south-1.compute.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, you encounter an error warning about unprotected private key file and bad permissions, and you are denied permission to access the instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The issue is related to the permissions on the private key file. To fix this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open a terminal on your local machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the directory containing your private key file (pem_file_name.pem).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the following command to change the permissions of the key file:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;chmod &lt;/span&gt;400 pem_file_name.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command restricts the file's permissions so that it is not accessible by others.&lt;/p&gt;




&lt;p&gt;These troubleshooting steps should help you resolve common SSH connectivity issues with AWS EC2 instances. Make sure to follow security best practices when managing your private key files and ensure that your security group configurations allow the necessary traffic for SSH access.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ruby</category>
      <category>softwaredevelopment</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is JSON?</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Sun, 12 Mar 2023 10:49:41 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/what-is-json-1cj6</link>
      <guid>https://dev.to/bhartee_sahare/what-is-json-1cj6</guid>
      <description>&lt;p&gt;&lt;em&gt;Javascript object notation (JSON) is a standard text-based data format used in web development to send and receive data.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;API is an application programming interface designed for lightweight data interchange (text-based data exchange format) between two computer applications operating on the same hardware device or between different computers in different geographical areas.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The format is to transfer data from client to server and server to client.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;I am login with the Facebook application (client side), when I click my profile page, that time the application sends a request to the Facebook server(server side) and gives me the response in a format like JSON.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantage:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;It is supported by all programming languages.&lt;/li&gt;
&lt;li&gt;It can be used on all platforms.&lt;/li&gt;
&lt;li&gt;It is a lightweight database standard, so data transmission is fast.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Where JSON Is Used:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Web Application&lt;/li&gt;
&lt;li&gt;API's&lt;/li&gt;
&lt;li&gt;Mobile application&lt;/li&gt;
&lt;li&gt;Gaming Api's&lt;/li&gt;
&lt;li&gt;IOT&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Data Type Supported:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Array&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  JSON Syntax and Datatype:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Every piece of JSON data is enclosed in curly brackets.&lt;/li&gt;
&lt;li&gt;Key-value pairs are used to describe JSON data.&lt;/li&gt;
&lt;li&gt;Always surround the word "key" in double quotes.&lt;/li&gt;
&lt;li&gt;Keys and values must always be separated by a comma (:).&lt;/li&gt;
&lt;li&gt;Values should be expressed correctly; double quotes for Strings are&lt;/li&gt;
&lt;li&gt;preferred over Boolean quotes for Numbers.&lt;/li&gt;
&lt;li&gt;Commas (,) should be used to divide text.&lt;/li&gt;
&lt;li&gt;Curly braces should be used for objects and collection square brackets.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  {
      "id": 1,
      "name": "test",
      "email": "test@gmail.com",
      "status": "active",
      "class": {
          "id": 1,
          "name": "1st",
          "sub_class": {
              "id": 1,
              "name": "A"
          }
      }
  },
    {
      "id": 1,
      "name": "test",
      "email": "test@gmail.com",
      "status": "active",
      "class": {
          "id": 1,
          "name": "1st",
          "sub_class": {
              "id": 1,
              "name": "A"
          }
      }
  }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JSON Array Declaration:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  "computer_science", "mechanical_engineer", "electrical_engineer"
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JSON Object Declaration:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": 1,
  "name": "test",
  "class": "1st",
  "dob": "1970-02-15"
  "certicate_achieve": ["rest_api", "json", "ruby"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Converting JSON Text to a JavaScript Object:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;JSON.parse(): Take the JSON string and convert it into a javascript object.&lt;/li&gt;
&lt;li&gt;JSON.stringify(): convert JavaScript object(JSON) into JSON string(useful while sending over the network)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// JSON.stringify()
obj = {"id":1, "name": "test"}
{id: 1, name: 'test'}
JSON.stringify(obj)
'{"id":1,"name":"test"}'

// JSON.parse()
data = JSON.stringify(obj)
'{"id":1,"name":"test"}'
JSON.parse(data)
{id: 1, name: 'test'}

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

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Ruby Built-in Data type.</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Sun, 12 Mar 2023 10:35:54 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/ruby-built-in-data-type-ph7</link>
      <guid>https://dev.to/bhartee_sahare/ruby-built-in-data-type-ph7</guid>
      <description>&lt;h2&gt;
  
  
  Float:
&lt;/h2&gt;

&lt;p&gt;In Ruby, a float is a data type used to represent decimal numbers.&lt;/p&gt;

&lt;p&gt;Floats are used to store numbers with a decimal point or numbers that are very large or very small.&lt;/p&gt;

&lt;p&gt;Floats can also be created using exponential notation, where a number is represented as a base and an exponent.&lt;/p&gt;

&lt;p&gt;The float is represented using a 64-bit format and can store numbers up to approximately 1.8 x 10³⁰⁸ with a precision of about 15 digits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num = 2.05
=&amp;gt; 2.05

num = 2.5e-3
=&amp;gt; 0.0025
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Date:
&lt;/h2&gt;

&lt;p&gt;The date is a data type that represents dates.&lt;/p&gt;

&lt;p&gt;The Date class is part of the Ruby standard library and provides a set of methods for working with dates.&lt;/p&gt;

&lt;p&gt;Ruby using the Date.new method, specifying the year, month, and day as arguments.&lt;/p&gt;

&lt;p&gt;We can also do arithmetic operations using date also.&lt;/p&gt;

&lt;p&gt;To use the DateTime class in Ruby, you need to require it first by adding the following line at the beginning of your script.&lt;/p&gt;

&lt;p&gt;date = DateTime.new(year, month, day)&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  DateTime:
&lt;/h2&gt;

&lt;p&gt;DateTime is a datatype in Ruby. It is a built-in class in the Ruby Standard Library and provides methods for working with dates and times.&lt;/p&gt;

&lt;p&gt;Ruby using the DateTime.new method, specifying the year, month, day, hour, minutes, second, offset&lt;/p&gt;

&lt;p&gt;To use the DateTime class in Ruby, you need to require it first by adding the following line at the beginning of your script.&lt;/p&gt;

&lt;p&gt;date_time = DateTime.new(year, month, day, hour, minute, second, offset)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;date_time = DateTime.new(2023, 3, 9, 15, 30, 0, Rational(-5, 24))

month = date_time.month
=&amp;gt; 3

year = date_time.year
=&amp;gt; 2023

day = date_time.day
=&amp;gt; 9

hour = date_time.hour
=&amp;gt; 15

minute = date_time.minute
=&amp;gt; 30

sec = date_time.second
=&amp;gt; 0

offset = date_time.offset
=&amp;gt; (-5/24)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Text:
&lt;/h2&gt;

&lt;p&gt;Text is a data type. The text data type stores any kind of text data.&lt;/p&gt;

&lt;p&gt;It can contain both single-byte and multibyte characters that the locale supports.&lt;/p&gt;

&lt;p&gt;The term simple large object refers to an instance of a text type.&lt;/p&gt;

&lt;p&gt;Use Text for larger content, comments, content, and paragraphs.&lt;/p&gt;

&lt;p&gt;The official rule is 255 for a string. So, if your string is more than 255 characters, go for text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blob:
&lt;/h2&gt;

&lt;p&gt;Blob is used to represent binary data in the Ruby environment that is stored as a blob type in the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  JSON:
&lt;/h2&gt;

&lt;p&gt;The JSON data type is used to store JSON (JavaScript Object Notation) data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'json'
=&amp;gt; true

json_string = '{"name": "John", "age": 30, "city": "New York"}'
 =&amp;gt; "{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}"

# The JSON.parse method is used to convert a JSON string into a Ruby data structure
 json_data = JSON.parse(json_string)
 =&amp;gt; {"name"=&amp;gt;"John", "age"=&amp;gt;30, "city"=&amp;gt;"New York"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array:
&lt;/h2&gt;

&lt;p&gt;Arrays are like bags that contain things&lt;/p&gt;

&lt;p&gt;An Array is an object that stores other objects.&lt;/p&gt;

&lt;p&gt;The array is created by separating values by commas and enclosing this list with square brackets, such as:&lt;/p&gt;

&lt;p&gt;[1, 2, 3]&lt;/p&gt;

&lt;p&gt;Arrays are created by listing objects, separated by commas, and enclosed by square brackets.&lt;/p&gt;

&lt;p&gt;Arrays can contain all kinds of things:&lt;/p&gt;

&lt;p&gt;[“A string”, 1, true, :symbol, 2]&lt;/p&gt;

&lt;p&gt;Arrays can contain all kinds of objects.&lt;/p&gt;

&lt;p&gt;Arrays have a defined order and can store all kinds of objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Punctuation (such as square brackets) has different meanings in different contexts.
# Arrays start with the index 0, not 1.
# Retrieving an element from an Array:
number = ["one", "two", "three"]
puts number[1]
=&amp;gt; two

# Appending an element to an Array:
number = ["one", "two", "three"]
number &amp;lt;&amp;lt; "four"
puts number[3]
=&amp;gt; four

# Setting an element to a position:
number = ["one", "two", "three"]
number[3] = "four"
puts number[3]
=&amp;gt; four

# You could also overwrite existing elements the same way. For example this would set the word "uno" to the position 0 (i.e. overwrite "one"):
# Remark: there are no spaces inside the square brackets, and there’s one space after each comma.

number = ["one", "two", "three"]
number[0] = "eno"
puts number[0]
=&amp;gt; eno

# Missing elements:
# if we try to retrieve an element that does not exist
["one", "two", "three"]
 =&amp;gt; ["one", "two", "three"]
words[3]
 =&amp;gt; nil

#Things you can do with Arrays
# You can add Arrays:
[1, 2] + [3, 4]
 =&amp;gt; [1, 2, 3, 4]

#  Subtract them from each other:
[:one, :two, :three, :four] - [:three, :four]
 =&amp;gt; [:one, :two]

#  Multiply with a number:
["Ruby", "Monstas"] * 3
 =&amp;gt; ["Ruby", "Monstas", "Ruby", "Monstas", "Ruby", "Monstas"]

# AND find the intersection:
[1, 2, 3] &amp;amp; [2, 3, 4]
 =&amp;gt; [2, 3]

["Ruby", "Monstas"].first
 =&amp;gt; "Ruby"

 ["Ruby", "Monstas"].last
 =&amp;gt; "Monstas"

 ["Ruby", "Monstas"].length
 =&amp;gt; 2

# the sort method is provided by the Array class and is used to sort the elements of an array in ascending order.
 [3, 1, 2].sort
 =&amp;gt; [1, 2, 3]

# remove the nil value
 [1, nil, 2, 3, nil].compact
 =&amp;gt; [1, 2, 3]

# is used to find the index of the first occurrence of a specified element in an array.
# If the element is not found, it returns nil.
 [1, 2, 3].index(3)
 =&amp;gt; 2

# it rotates the array by one position to the left.
# If a negative argument is provided, it rotates the array to the right.
# If the argument is greater than the length of the array, it performs multiple rotations.
 [1, 2, 3, 4].rotate(2)
 =&amp;gt; [3, 4, 1, 2]

# the transpose method works only on rectangular arrays, i.e., arrays where all rows have the same number of elements. If the array is not rectangular, transpose will raise an IndexError.
[[1, 2, 3], [4, 5, 6], [7, 8, 9]].transpose
 =&amp;gt; [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hash:
&lt;/h2&gt;

&lt;p&gt;Hashes are another very useful and widely used kind of thing that can be used to store other objects.&lt;/p&gt;

&lt;p&gt;Real-time example:&lt;/p&gt;

&lt;p&gt;Imagine a real dictionary that translates from English to German. When you look up the English word “hello” then you’ll find the German “Hallo”.When you look up “one” then you’ll find “eins”, and so on. The authors of this dictionary have assigned a German word (a value) to an English word (the key).&lt;/p&gt;

&lt;p&gt;Hash assigns values to keys so that values can be looked up by their key.&lt;/p&gt;

&lt;p&gt;A hash is created by listing key/value pairs, separated by hash rockets, and enclosed by curly braces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# Define hash below ways:

{ one: "eins", two: "zwei", three: "drei" } # new syntax
{ 1 =&amp;gt; "one", 2 =&amp;gt; "two", 3 =&amp;gt; "three" }
{ :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
{ "weights" =&amp;gt; ["pound", "kilogram"], "lengths" =&amp;gt; ["meter", "mile"] }
{ :one =&amp;gt; { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating a Hash
dictionary = { "one" =&amp;gt; "1", "two" =&amp;gt; "2", "three" =&amp;gt; "3" }
=&amp;gt; { "one" =&amp;gt; "1", "two" =&amp;gt; "2", "three" =&amp;gt; "3" }
dictionary["zero"] = "null"
=&amp;gt; "null"
puts dictionary["zero"]
null
 =&amp;gt; nil


# Merge the two hash:
number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }.merge({ :four =&amp;gt; 4 })
 =&amp;gt; {:one=&amp;gt;"one", :two=&amp;gt;"two", :three=&amp;gt;"three", :four=&amp;gt;4}


#  Fetch the hash:
 number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 =&amp;gt; { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 number.fetch(:one)
 =&amp;gt; "one"
 number.fetch(:four)
 =&amp;gt; # (irb):45:in `fetch': key not found: :four (KeyError)


#  Returns an Array with all the keys and values:
 number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 =&amp;gt; {:one=&amp;gt;"one", :two=&amp;gt;"two", :three=&amp;gt;"three"}
 number.keys
 =&amp;gt; [:one, :two, :three]
 number.values
 =&amp;gt; ["one", "two", "three"]


#  length and size both tell how many key/value pairs the Hash has:
number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 =&amp;gt; {:one=&amp;gt;"one", :two=&amp;gt;"two", :three=&amp;gt;"three"}
number.size
 =&amp;gt; 3
number.length
 =&amp;gt; 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Ruby Built-in Data type.</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Thu, 09 Mar 2023 18:28:56 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/ruby-built-in-data-type-1i9f</link>
      <guid>https://dev.to/bhartee_sahare/ruby-built-in-data-type-1i9f</guid>
      <description>&lt;h2&gt;
  
  
  Float:
&lt;/h2&gt;

&lt;p&gt;In Ruby, a float is a data type used to represent decimal numbers.&lt;/p&gt;

&lt;p&gt;Floats are used to store numbers with a decimal point or numbers that are very large or very small.&lt;/p&gt;

&lt;p&gt;Floats can also be created using exponential notation, where a number is represented as a base and an exponent.&lt;/p&gt;

&lt;p&gt;The float is represented using a 64-bit format and can store numbers up to approximately 1.8 x 10³⁰⁸ with a precision of about 15 digits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num = 2.05
=&amp;gt; 2.05

num = 2.5e-3
=&amp;gt; 0.0025
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Date:
&lt;/h2&gt;

&lt;p&gt;The date is a data type that represents dates.&lt;/p&gt;

&lt;p&gt;The Date class is part of the Ruby standard library and provides a set of methods for working with dates.&lt;/p&gt;

&lt;p&gt;Ruby using the Date.new method, specifying the year, month, and day as arguments.&lt;/p&gt;

&lt;p&gt;We can also do arithmetic operations using date also.&lt;/p&gt;

&lt;p&gt;To use the DateTime class in Ruby, you need to require it first by adding the following line at the beginning of your script.&lt;/p&gt;

&lt;p&gt;date = DateTime.new(year, month, day)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'date'
 =&amp;gt; true

date = Date.new(2023,02,05)
 =&amp;gt; #&amp;lt;Date: 2023-02-05 ((2459981j,0s,0n),+0s,2299161j)&amp;gt;

year = date.year
 =&amp;gt; 2023

month = date.month
 =&amp;gt; 2

 day = date.day
 =&amp;gt; 5

 new_date = date + 7
 =&amp;gt; #&amp;lt;Date: 2023-02-12 ((2459988j,0s,0n),+0s,2299161j)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  DateTime:
&lt;/h2&gt;

&lt;p&gt;DateTime is a datatype in Ruby. It is a built-in class in the Ruby Standard Library and provides methods for working with dates and times.&lt;/p&gt;

&lt;p&gt;Ruby using the DateTime.new method, specifying the year, month, day, hour, minutes, second, offset&lt;/p&gt;

&lt;p&gt;To use the DateTime class in Ruby, you need to require it first by adding the following line at the beginning of your script.&lt;/p&gt;

&lt;p&gt;date_time = DateTime.new(year, month, day, hour, minute, second, offset)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;date_time = DateTime.new(2023, 3, 9, 15, 30, 0, Rational(-5, 24))

month = date_time.month
=&amp;gt; 3

year = date_time.year
=&amp;gt; 2023

day = date_time.day
=&amp;gt; 9

hour = date_time.hour
=&amp;gt; 15

minute = date_time.minute
=&amp;gt; 30

sec = date_time.second
=&amp;gt; 0

offset = date_time.offset
=&amp;gt; (-5/24)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Text:
&lt;/h2&gt;

&lt;p&gt;Text is a data type. The text data type stores any kind of text data.&lt;/p&gt;

&lt;p&gt;It can contain both single-byte and multibyte characters that the locale supports.&lt;/p&gt;

&lt;p&gt;The term simple large object refers to an instance of a text type.&lt;/p&gt;

&lt;p&gt;Use Text for larger content, comments, content, and paragraphs.&lt;/p&gt;

&lt;p&gt;The official rule is 255 for a string. So, if your string is more than 255 characters, go for text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blob:
&lt;/h2&gt;

&lt;p&gt;Blob is used to represent binary data in the Ruby environment that is stored as a blob type in the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  JSON:
&lt;/h2&gt;

&lt;p&gt;The JSON data type is used to store JSON (JavaScript Object Notation) data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'json'
=&amp;gt; true

json_string = '{"name": "John", "age": 30, "city": "New York"}'
 =&amp;gt; "{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}"

# The JSON.parse method is used to convert a JSON string into a Ruby data structure
 json_data = JSON.parse(json_string)
 =&amp;gt; {"name"=&amp;gt;"John", "age"=&amp;gt;30, "city"=&amp;gt;"New York"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array:
&lt;/h2&gt;

&lt;p&gt;Arrays are like bags that contain things&lt;/p&gt;

&lt;p&gt;An Array is an object that stores other objects.&lt;/p&gt;

&lt;p&gt;The array is created by separating values by commas and enclosing this list with square brackets, such as:&lt;/p&gt;

&lt;p&gt;[1, 2, 3]&lt;/p&gt;

&lt;p&gt;Arrays are created by listing objects, separated by commas, and enclosed by square brackets.&lt;/p&gt;

&lt;p&gt;Arrays can contain all kinds of things:&lt;/p&gt;

&lt;p&gt;[“A string”, 1, true, :symbol, 2]&lt;/p&gt;

&lt;p&gt;Arrays can contain all kinds of objects.&lt;/p&gt;

&lt;p&gt;Arrays have a defined order and can store all kinds of objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Punctuation (such as square brackets) has different meanings in different contexts.
# Arrays start with the index 0, not 1.
# Retrieving an element from an Array:
number = ["one", "two", "three"]
puts number[1]
=&amp;gt; two

# Appending an element to an Array:
number = ["one", "two", "three"]
number &amp;lt;&amp;lt; "four"
puts number[3]
=&amp;gt; four

# Setting an element to a position:
number = ["one", "two", "three"]
number[3] = "four"
puts number[3]
=&amp;gt; four

# You could also overwrite existing elements the same way. For example this would set the word "uno" to the position 0 (i.e. overwrite "one"):
# Remark: there are no spaces inside the square brackets, and there’s one space after each comma.

number = ["one", "two", "three"]
number[0] = "eno"
puts number[0]
=&amp;gt; eno

# Missing elements:
# if we try to retrieve an element that does not exist
["one", "two", "three"]
 =&amp;gt; ["one", "two", "three"]
words[3]
 =&amp;gt; nil

#Things you can do with Arrays
# You can add Arrays:
[1, 2] + [3, 4]
 =&amp;gt; [1, 2, 3, 4]

#  Subtract them from each other:
[:one, :two, :three, :four] - [:three, :four]
 =&amp;gt; [:one, :two]

#  Multiply with a number:
["Ruby", "Monstas"] * 3
 =&amp;gt; ["Ruby", "Monstas", "Ruby", "Monstas", "Ruby", "Monstas"]

# AND find the intersection:
[1, 2, 3] &amp;amp; [2, 3, 4]
 =&amp;gt; [2, 3]

["Ruby", "Monstas"].first
 =&amp;gt; "Ruby"

 ["Ruby", "Monstas"].last
 =&amp;gt; "Monstas"

 ["Ruby", "Monstas"].length
 =&amp;gt; 2

# the sort method is provided by the Array class and is used to sort the elements of an array in ascending order.
 [3, 1, 2].sort
 =&amp;gt; [1, 2, 3]

# remove the nil value
 [1, nil, 2, 3, nil].compact
 =&amp;gt; [1, 2, 3]

# is used to find the index of the first occurrence of a specified element in an array.
# If the element is not found, it returns nil.
 [1, 2, 3].index(3)
 =&amp;gt; 2

# it rotates the array by one position to the left.
# If a negative argument is provided, it rotates the array to the right.
# If the argument is greater than the length of the array, it performs multiple rotations.
 [1, 2, 3, 4].rotate(2)
 =&amp;gt; [3, 4, 1, 2]

# the transpose method works only on rectangular arrays, i.e., arrays where all rows have the same number of elements. If the array is not rectangular, transpose will raise an IndexError.
[[1, 2, 3], [4, 5, 6], [7, 8, 9]].transpose
 =&amp;gt; [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hash:
&lt;/h2&gt;

&lt;p&gt;Hashes are another very useful and widely used kind of thing that can be used to store other objects.&lt;/p&gt;

&lt;p&gt;Real-time example:&lt;/p&gt;

&lt;p&gt;Imagine a real dictionary that translates from English to German. When you look up the English word “hello” then you’ll find the German “Hallo”.When you look up “one” then you’ll find “eins”, and so on. The authors of this dictionary have assigned a German word (a value) to an English word (the key).&lt;/p&gt;

&lt;p&gt;Hash assigns values to keys so that values can be looked up by their key.&lt;/p&gt;

&lt;p&gt;A hash is created by listing key/value pairs, separated by hash rockets, and enclosed by curly braces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# Define hash below ways:

{ one: "eins", two: "zwei", three: "drei" } # new syntax
{ 1 =&amp;gt; "one", 2 =&amp;gt; "two", 3 =&amp;gt; "three" }
{ :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
{ "weights" =&amp;gt; ["pound", "kilogram"], "lengths" =&amp;gt; ["meter", "mile"] }
{ :one =&amp;gt; { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Creating a Hash
dictionary = { "one" =&amp;gt; "1", "two" =&amp;gt; "2", "three" =&amp;gt; "3" }
=&amp;gt; { "one" =&amp;gt; "1", "two" =&amp;gt; "2", "three" =&amp;gt; "3" }
dictionary["zero"] = "null"
=&amp;gt; "null"
puts dictionary["zero"]
null
 =&amp;gt; nil


# Merge the two hash:
number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }.merge({ :four =&amp;gt; 4 })
 =&amp;gt; {:one=&amp;gt;"one", :two=&amp;gt;"two", :three=&amp;gt;"three", :four=&amp;gt;4}


#  Fetch the hash:
 number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 =&amp;gt; { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 number.fetch(:one)
 =&amp;gt; "one"
 number.fetch(:four)
 =&amp;gt; # (irb):45:in `fetch': key not found: :four (KeyError)


#  Returns an Array with all the keys and values:
 number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 =&amp;gt; {:one=&amp;gt;"one", :two=&amp;gt;"two", :three=&amp;gt;"three"}
 number.keys
 =&amp;gt; [:one, :two, :three]
 number.values
 =&amp;gt; ["one", "two", "three"]


#  length and size both tell how many key/value pairs the Hash has:
number = { :one =&amp;gt; "one", :two =&amp;gt; "two", :three =&amp;gt; "three" }
 =&amp;gt; {:one=&amp;gt;"one", :two=&amp;gt;"two", :three=&amp;gt;"three"}
number.size
 =&amp;gt; 3
number.length
 =&amp;gt; 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://dev.to/bhartee_sahare/built-in-data-type-in-ruby-140k"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Built In Data Type in Ruby</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Mon, 06 Mar 2023 18:16:46 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/built-in-data-type-in-ruby-140k</link>
      <guid>https://dev.to/bhartee_sahare/built-in-data-type-in-ruby-140k</guid>
      <description>&lt;p&gt;&lt;em&gt;Data types are types of “things” that are mainly used to represent data, such as numbers, text, and other values.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We will discusss the following data types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numbers&lt;/li&gt;
&lt;li&gt;Strings (texts)&lt;/li&gt;
&lt;li&gt;True, False, and Nil&lt;/li&gt;
&lt;li&gt;Symbols&lt;/li&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Hashes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Number:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;A number is defined by a series of digits, using a dot as a decimal mark, and optionally an underscore as a thousands separator.&lt;/li&gt;
&lt;li&gt;Mathematical operations result in a floating point number except if all number
s used are integer numbers.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 0.1 + 2
# =&amp;gt; 2.1
# 3.0/2
# =&amp;gt; 1.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  String:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The String, in programming languages, is text.&lt;/li&gt;
&lt;li&gt;Strings can be defined by enclosing any text with single or double quotes.&lt;/li&gt;
&lt;li&gt;These last few examples are examples of “calling methods on objects that are Strings”. Methods are “behaviour” that objects are capable of.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"This is one String!"
'And this is another one.'

# Here are a few things you can do with Strings:
"bhartee" + "sahare"
=&amp;gt; "bharteesahare"

"hi" + "hello" + "hey"
=&amp;gt; "hihellohey"

"hey" * 2
=&amp;gt; "heyhey"

"1"+"1"+"1"
=&amp;gt; "111"

"1"* 5
=&amp;gt; "11111"

"hello".upcase
=&amp;gt; "HELLO"

 "hello".capitalize
 =&amp;gt; "Hello"

 "hello".reverse
 =&amp;gt; "olleh"

 "hello".length
 =&amp;gt; 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  True, False, and Nil:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The object true represents “truth”, while false represents the opposite of it.&lt;/li&gt;
&lt;li&gt;The object nil represents “nothing”.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Symbols:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Symbols are like strings, except they are code.&lt;/li&gt;
&lt;li&gt;A symbol is created by adding a colon in front of a word.&lt;/li&gt;
&lt;li&gt;A symbol is written like this:= :name&lt;/li&gt;
&lt;li&gt;Symbols are unique identifiers that are considered code, not data.&lt;/li&gt;
&lt;li&gt;Symbols are a special, limited variation of Strings.
The technical difference:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# even though the 3 Strings created are exactly the same, every new String created has a different object_id: They’re actually different objects, even though they contain the same text.

"a".object_id
 =&amp;gt; 460
 "a".object_id
 =&amp;gt; 480
 "a".object_id
 =&amp;gt; 500

We now get the same object_id for each of the Symbols, meaning they’re referring to the exact same object.

:test.object_id
 =&amp;gt; 380188
3.0.0 :002 &amp;gt; :test.object_id
 =&amp;gt; 380188
3.0.0 :003 &amp;gt; :test.object_id
 =&amp;gt; 380188
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Array and Hash Cover in Next Post......&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Ruby Variable</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Mon, 06 Mar 2023 17:57:02 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/ruby-variable-3co8</link>
      <guid>https://dev.to/bhartee_sahare/ruby-variable-3co8</guid>
      <description>&lt;h2&gt;
  
  
  Definition:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A name on the left side of the assignment operator = is assigned to the object on the right side.&lt;/li&gt;
&lt;li&gt;A variable itself is not a “thing”. It’s just a name for a thing (an object).&lt;/li&gt;
&lt;li&gt;You can pick whatever variable names you want, they’re just names, like post-it notes stuck onto actual objects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;number = 1
puts number

a = 1
puts a

large_number = 1
puts large_number

apples = 1
puts apples
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reusing variable names:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variable names can be re-used, and re-assigned.&lt;/li&gt;
&lt;li&gt;Using variable names can be useful to break up long lines and make code more expressive and readable.&lt;/li&gt;
&lt;li&gt;There are spaces around the assignment operator &lt;code&gt;=&lt;/code&gt; as well as the arithmetical operators &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;number = 4 #On the first line Ruby creates the number (object) 4.
number = (number * 3) #on the second line, Ruby first looks at the stuff on the right side, and evaluates the expression number * 3. Doing so it will create the number (object) 3 and multiply it with the object that currently has the name number, which is 4. This operation results in a new number (object) 12
puts number + 2 #On the third line Ruby will, again, first look at the expression number + 2 on the right. It creates the object 2 and adds it to the object that currently has the name number. This results in a new number (object) 14.
#Finally Ruby passes this object 14 to puts, which outputs it to the screen.

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things on the right go first:
&lt;/h2&gt;

&lt;p&gt;Ruby evaluates the expression on the right first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;number = 2 + 3 * 4
puts number

number = 3 * 6  + 2
puts number
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>ruby</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Ruby Introduction</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Mon, 06 Mar 2023 17:43:45 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/ruby-introduction-1ihd</link>
      <guid>https://dev.to/bhartee_sahare/ruby-introduction-1ihd</guid>
      <description>&lt;h2&gt;
  
  
  Defination:
&lt;/h2&gt;

&lt;p&gt;Ruby is a high-level interpreted programming language that has been developed with an emphasis on simplicity and readability. It was created in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan.&lt;/p&gt;

&lt;p&gt;Ruby is commonly used for web development, data analysis, and script. It is also a popular language for the development of desktop apps and system utilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key features of Ruby:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Object-oriented programming:&lt;/strong&gt; Ruby is a fully object-oriented language, which means that everything within Ruby is an object, including variables, classes, and functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dynamic Typing:&lt;/strong&gt; Ruby supports dynamic typing, which means that the type of a variable can change dynamically during execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blocks and Procs:&lt;/strong&gt; Ruby has powerful block and proc (procedure) support, allowing for flexible, reusable code that can be passed around as objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt; Ruby’s syntax is recognized for its simplicity and legibility. It is often said to resemble “executable pseudocode.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gems:&lt;/strong&gt; Ruby has a large and dynamic community, and one of her strengths is the vast collection of libraries and tools available via the RubyGems package manager.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interoperability:&lt;/strong&gt; Ruby can be easily integrated into other programming languages, like C, Java, and Python, making it a great choice for use in a variety of software projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Metaprogramming:&lt;/strong&gt; Ruby has powerful metaprogramming abilities, allowing developers to write code that writes code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some of the Popular Companies that used Ruby on Rails:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Shopify:&lt;/strong&gt; Shopify is a Canadian-owned conglomerate and e-commerce organization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; GitHub offers access control and a variety of collaborative features including feature requests, project management, project wikis, and bug tracking. The company uses Git for ease of versioning and development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Netflix:&lt;/strong&gt; Netflix is a subscription-based streaming service that allows our members to watch TV shows and movies on an internet-connected device.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hulu:&lt;/strong&gt; This is a video streaming platform currently available just in the United States. It isn’t as big as HBO GO or Netflix, but it is growing quickly and releasing great new shows every month.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Airbnb:&lt;/strong&gt; Airbnb, as in “Air Bed and Breakfast,” is a service that lets property owners rent out their spaces to travelers looking for a place to stay.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ruby</category>
      <category>oop</category>
      <category>programming</category>
    </item>
    <item>
      <title>Introduction to Rspec (Testing)</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Sat, 25 Feb 2023 10:02:08 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/introduction-to-rspec-testing-4h1</link>
      <guid>https://dev.to/bhartee_sahare/introduction-to-rspec-testing-4h1</guid>
      <description>&lt;h2&gt;
  
  
  What is the testing framework:
&lt;/h2&gt;

&lt;p&gt;A testing framework automates the test code that executes and verifies bug checks (= operation checks). In other words, a testing framework is a framework that makes it easy to implement tests.&lt;/p&gt;

&lt;p&gt;A software framework that provides functions such as creating automatic execution programs for software tests, intuitive judgement, and automatic aggregation of test results.&lt;/p&gt;

&lt;p&gt;Testing framework in Ruby:&lt;br&gt;
There are mainly three testing frameworks in Ruby, and the order of usage is as follows&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;RSpec&lt;/li&gt;
&lt;li&gt;Minitest&lt;/li&gt;
&lt;li&gt;test-unit .&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  What is the Rspec:
&lt;/h2&gt;

&lt;p&gt;RSpec is one of Ruby’s testing frameworks and the most used language among Ruby developers.&lt;/p&gt;

&lt;p&gt;RSpec’s R stands for Ruby and Spec stands for test code.&lt;/p&gt;

&lt;p&gt;As a feature, RSpec is created based on the Ruby language, so it has the advantage that anyone who understands Ruby to some extent can easily implement it.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to install:
&lt;/h2&gt;

&lt;p&gt;Add the code below to the Gemfile and after that, run the command “bundle install”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
  # this is for the test case for rspec
  gem 'rspec-rails'
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next are the RSpec settings:&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 rspec:install # this command type in our project folder terminal and it is create the below files
# this above command generate the four files 
create  .rspec # file genrated
create  spec # file generated
create  spec/spec_helper.rb # file generated
create  spec/rails_helper.rb # file generated

rspec --format d # type this commnd in bash terminal

No examples found.

Finished in 0.00024 seconds (files took 0.05174 seconds to load)
0 examples, 0 failures


Note: --format d =&amp;gt; is an option to make the test output results easier to read.

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Regarding the above, I will upload the next post soon…&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>aws</category>
      <category>support</category>
    </item>
    <item>
      <title>Materialized View on Rails (Postgres)</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Thu, 23 Feb 2023 15:47:01 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/materialized-view-on-rails-postgres-29d4</link>
      <guid>https://dev.to/bhartee_sahare/materialized-view-on-rails-postgres-29d4</guid>
      <description>&lt;h2&gt;
  
  
  Definition:
&lt;/h2&gt;

&lt;p&gt;By proactively computing the outcomes and saving them in a “virtual” table, a materialized view takes the standard view mentioned above and materializes it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;Create a new rails application with the PostgreSQL database.&lt;br&gt;
here we create the directory which name denote the rails_application&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir rails_applications 

# go to the directory
cd rails_applications
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here we create a new rails application with postgresql database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new demo_api --api --database=postgresql

cd demo_api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;create a rails migration&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 migration add-customer-address-table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AddCustomerAddressTable &amp;lt; ActiveRecord::Migration[7.0]

  def change
    # here we create the table for customers
    create_table :customers do |t|
      t.string :first_name, null: false
      t.string :last_name, null: false
    end
    # here we create the table for addresses
    create_table :addresses do |t|
      t.references :customer, null: false
      t.string :street
      t.string :city
    end

  end

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why did we use a materialized view?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;If you want to use the data from 5 different tables with the help of join.5 different tables having a huge amount of data then we used the materialized view.&lt;br&gt;
create the cache amount of data in our disk.&lt;br&gt;
So rails are managed through the disk, in rails, we do not store the data in the database the data is available in the disk when the new row is created or modified the disk will be managed.&lt;br&gt;
when you hit the query and search for particular data, it is searched from the disk and not from the database&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Drawbacks of materialized view:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Disk space&lt;br&gt;
I have 5 tables and each table contains 1 lakh data total amount of data is 5 lakh in the future it will be 10 lahk and 15 lahk. More data inserts than disk space errors occur disk overloaded&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;create the materialized view&lt;br&gt;
create a one migration then in this migration add the code below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AddCustomerDetailsMaterializedView &amp;lt; ActiveRecord::Migration[7.0]
  # this method is responsible for create the customer details view
  def up
    # this query is responsible for creating the materialized view
    execute %{
      CREATE MATERIALIZED VIEW customer_details AS
        SELECT
          customers.id as customer_id,
          customers.first_name as first_name,
          customers.last_name as last_name,
          addresses.street as street,
          addresses.city as city
        FROM
          customers
        JOIN addresses ON
          customers.id = addresses.customer_id
    }
    # this query is responsible for the create the unique index
    execute %{
      CREATE UNIQUE INDEX
        customer_details_customer_id
      ON
        customer_details(customer_id)
    }
  end

  #this method is responsible for the drop the customer details view.
  def down
    execute "DROP MATERIALIZED VIEW customer_details"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;insert into customers (first_name, last_name) values ('bhartee', 'sahare');
insert into addresses (customer_id, street, city) values (1, 'dabha', 'nagpur');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this command is refresh the data of materialized view&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REFRESH MATERIALIZED VIEW customer_details;

select * from customer_details

demo_development-# ;
 customer_id | first_name | last_name | street |  city  
-------------+------------+-----------+--------+--------
           1 | bhartee    | sahare    | Dabha  | Nagpur
(1 row)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mcp</category>
      <category>figma</category>
      <category>devhandoff</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Different Ways to Fetch Data in React Js:</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Sun, 19 Feb 2023 08:59:13 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/different-ways-to-fetch-data-in-react-js-4eok</link>
      <guid>https://dev.to/bhartee_sahare/different-ways-to-fetch-data-in-react-js-4eok</guid>
      <description>&lt;h2&gt;
  
  
  Fetch Method:
&lt;/h2&gt;

&lt;p&gt;The fetch() method in js is used to request the server and load the information in the web pages. The request can be any API that returns the date of the format JSON or XMLDocument. This method is returned as a Promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
    useEffect(() =&amp;gt; {
        fetch('https://site.com/')
        .then(response =&amp;gt; response.json())
        .then(json =&amp;gt; console.log(json))
    }, []);

    return(
        &amp;lt;div&amp;gt; Fetch method used for fetching the data&amp;lt;/div&amp;gt;
    );

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Async-Await:
&lt;/h2&gt;

&lt;p&gt;This is the preferred way of fetching the data from an API as it enables us to remove our .then() callback and return asynchronously resolved data. For the async block, we can use the await function to wait for the Promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
    useEffect(() =&amp;gt;{
        (async () =&amp;gt; {
            try {
                const result = await.axiox.get('https://site.com/')
                console.log(result.data)
            } catch (error){
                console.error(error)
            }
        })()
    })
    return &amp;lt;div&amp;gt; Async-Await method used for fetch the data&amp;lt;/div&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Axios library:
&lt;/h2&gt;

&lt;p&gt;With axiox, we can easily send an asynchronous HTTP request to REST APIs &amp;amp; perform create, read, update, and delete operations. Axios can be imported in plain javascript or with any library accordingly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App(){
     useEffect(() =&amp;gt; {
        axiox.get('https://site.com/')
        .then((response) =&amp;gt; console.log(response.data));
     }, [])
     return(
        &amp;lt;div&amp;gt; Axios library used for fetch the data&amp;lt;/div&amp;gt;
     )
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Custom Hook:
&lt;/h2&gt;

&lt;p&gt;It is basically a react component whose name will start with use like useFetch. One or more React hooks can be used inside them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const useFetch =(url) =&amp;gt; {

    const [isLoading, setIsLoading] = useState(false)
    const [apiData, setApiData] = useState(null)
    const [ serverError, setServerError] = useState(null)

    useEffect(() =&amp;gt; {
        setIsLoading(true)
        const fetchData = async () =&amp;gt; {
            try {
                const resp = await.axiox.get(url)
                const data = await resp? data
                setApiData(data)
                setIsLoading(false)
            } catch(error){
                setServerError(error)
                setIsLoading(false)
            }
        }
        fetchData()
    }, [url])
    return { isLoading, apiData, serverError}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage of the component:
&lt;/h2&gt;

&lt;p&gt;Import the UseFetch hook and pass the URL of the API endpoint from where you want to fetch data.Now, just like any react hook, we can directly use our Custom hook to fetch the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import useFetch from './useFetch';

const App = () {
    const {isLoading, serverError, apiData} = useFetch('https://site.com')

    return(
        &amp;lt;div&amp;gt;
            &amp;lt;h2&amp;gt;Api Data&amp;lt;/h2&amp;gt;
            { isLoading &amp;amp;&amp;amp; &amp;lt;span&amp;gt;Loading......&amp;lt;/span&amp;gt;}
            {isLoading  &amp;amp;&amp;amp; serverError ? (
                &amp;lt;span&amp;gt;Error in fetching data...&amp;lt;/span&amp;gt;
            ) : (
                &amp;lt;span&amp;gt;{JSON.stringify{apiData}}&amp;lt;/span&amp;gt;
            )}
        &amp;lt;/div&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Request Query library:
&lt;/h2&gt;

&lt;p&gt;With this, we can achieve a lot more than just fetching data. It provides support for catching and re-fetching, which impacts the overall user experience by preventing irregularities and ensuring our app feels faster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from "axios";
import {useQuery}  from 'react-query'

function App() {
    const { isLoading, error, data} =
    useQuery('posts', () =&amp;gt; axios('https://site.com'))
    console.log(data)
    return &amp;lt;div&amp;gt; Request query library to fetch the data&amp;lt;/div&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>reactnative</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Array clone and dup method in Ruby.</title>
      <dc:creator>Bhartee Rameshwar Sahare</dc:creator>
      <pubDate>Sun, 19 Feb 2023 07:38:43 +0000</pubDate>
      <link>https://dev.to/bhartee_sahare/array-clone-and-dup-method-in-ruby-3o22</link>
      <guid>https://dev.to/bhartee_sahare/array-clone-and-dup-method-in-ruby-3o22</guid>
      <description>&lt;h2&gt;
  
  
  clone:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;This method is a shallow copy of the object. Be aware that your attributes are unique.&lt;/li&gt;
&lt;li&gt;Changing the attributes of the clone will also change the original.&lt;/li&gt;
&lt;li&gt;create a new object with the same id, so all the changes made to that new object will overwrite the original record if hit .save.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; user = User.first
  User Load (0.2ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
 =&amp;gt; #&amp;lt;User:0x0000563e2b9b3268 id: 1, name: "Jane Doe", dob: nil, gender: nil, created_at: Tue, 14 Feb 2023 12:45:36.528000000 UTC +00:00, updated_at: Tue, 14 Feb 2023 12:45:36.528000000 UTC +00:00&amp;gt;

 new_user = user.clone
 =&amp;gt; #&amp;lt;User:0x0000563e2bb8a0f0 id: 1, name: "Jane Doe", dob: nil, gender: nil, created_at: Tue, 14 Feb 2023 12:45:36.528000000 UTC +00:00, updated_at: Tue, 14 Feb 2023 12:45:36.528000000 UTC +00:00&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  dup:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Duped objects have no ID assigned and are treated as new records.&lt;/li&gt;
&lt;li&gt;This is a “shallow” copy as it copies the object’s attributes.&lt;/li&gt;
&lt;li&gt;create a new object without its ID being set, so you can save a new object to the database by hitting. save.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user = User.last
User Load (0.1ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT ?  [["LIMIT", 1]]
=&amp;gt; #&amp;lt;User:0x0000563e2b9b1008 id: 3, name: "bhartee", dob: nil, gender: nil, created_at: Tue, 14 Feb 2023 12:45:57.223000000 UTC +00:00, updated_at: Tue, 14 Feb 2023 12:45:57.223000000 UTC +00:00&amp;gt;

new_user = user.dup
=&amp;gt; #&amp;lt;User:0x0000563e2c18a180 id: nil, name: "bhartee", dob: nil, gender: nil, created_at: nil, updated_at: nil&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Difference:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;clone copies of the singleton class, while dup does not.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o = Object.new
=&amp;gt; #&amp;lt;Object:0x0000563e2c319a78&amp;gt;

&amp;gt; def o.foo
&amp;gt;   42
&amp;gt; end

=&amp;gt; :foo

&amp;gt; o.dup.foo
(irb):31:in `&amp;lt;main&amp;gt;': undefined method `foo' for #&amp;lt;Object:0x0000563e2bbd2508&amp;gt; (NoMethodError)

&amp;gt; o.clone.foo
=&amp;gt; 42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;clone preserves the frozen state, while dup does not.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Foo
  attr_accessor :bar
end
o = Foo.new
o.freeze

o.dup.bar = 10
=&amp;gt; 10

o.clone.bar = 10
(irb):39:in `&amp;lt;main&amp;gt;': can't modify frozen Foo: #&amp;lt;Foo:0x0000563e2b9e8e18&amp;gt; (FrozenError)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>news</category>
      <category>energy</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
