<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <atom:link href="https://dhruvraval.dev/site/feed" rel="self" type="application/rss+xml" />
        <title><![CDATA[Blogs by Dhruv Raval on dhruvraval.dev]]></title>
        <link><![CDATA[https://dhruvraval.dev/site/feed]]></link>
        <description><![CDATA[The description of the feed.]]></description>
        <language>en-US</language>
        <pubDate>Thu, 09 Jan 2025 07:32:29 +0000</pubDate>

                    <item>
                <title><![CDATA[How do I get the value of text input field using JavaScript?]]></title>
                <link>https://dhruvraval.dev/how-do-i-get-the-value-of-text-input-field-using-javascript</link>
                <description><![CDATA[<p>You can use <em>onkeyup</em> when you have more than one input field. Suppose you have four or input. Then&nbsp; "<em>document.getElementById('something').value</em>" is annoying. We need to write four lines to fetch the value of an input field.</p><p>So, you can create a function that store value in object on keyup or keydown event.</p><p>Example:</p><pre>&lt;div class="container"&gt;
    &lt;div&gt;
        &lt;label for=""&gt;Name&lt;/label&gt;
        &lt;input type="text" name="fname" id="fname" onkeyup=handleInput(this)&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;label for=""&gt;Age&lt;/label&gt;
        &lt;input type="number" name="age" id="age" onkeyup=handleInput(this)&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;label for=""&gt;Email&lt;/label&gt;
        &lt;input type="text" name="email" id="email" onkeyup=handleInput(this)&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;label for=""&gt;Mobile&lt;/label&gt;
        &lt;input type="number" name="mobile" id="number" onkeyup=handleInput(this)&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;button onclick=submitData()&gt;Submit&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;
<br>&lt;script&gt;
    const data = { };
    
    function handleInput(e){
        data[e.name] = e.value;
    }

    function submitData(){
        console.log(data.fname); // Get the first name from the object
        console.log(data); // return object
    }
&lt;/script&gt;</pre>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Thu, 09 Jan 2025 07:31:41 +0000</pubDate>
                            </item>
                    <item>
                <title><![CDATA[Creating a Rough Chart with Chart.js and Rough.js]]></title>
                <link>https://dhruvraval.dev/creating-a-rough-chart-with-chart-js-and-rough-js</link>
                <description><![CDATA[<p>Chart.js is a popular JavaScript library that enables the creation of various types of charts.</p>
<p>Check this example to explore how to use Rough.js with Chart.js, a library that adds a hand-drawn, sketchy effect to charts. You can also use the custom font for chart. &nbsp;</p>
<p>I am using "Indie Flower" font. You can add your font from google.</p>
<p><strong>HTML</strong></p>
<pre class="language-markup"><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en" &gt;
&lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Indie+Flower"&gt;&lt;link rel="stylesheet" href="./style.css"&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;canvas id="myChart"&gt;&lt;/canvas&gt;

&lt;div class="slidecontainer"&gt;
  &lt;h4&gt;Roughness&lt;/h4&gt;
  &lt;input type="range" min="0" max="10" value="1" class="slider" id="rnSlider"&gt;
&lt;/div&gt;

&lt;script src='https://cdn.jsdelivr.net/npm/chart.js@2.8.0'&gt;&lt;/script&gt;
&lt;script src='https://cdn.jsdelivr.net/npm/roughjs@3.1.0/dist/rough.js'&gt;&lt;/script&gt;
&lt;script src='https://cdn.jsdelivr.net/npm/chartjs-plugin-rough@0.2.0'&gt;&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p><strong>Script</strong></p>
<pre class="language-javascript"><code>Chart.defaults.global.defaultFontFamily = '"Indie Flower", cursive';
Chart.defaults.global.defaultFontSize = 14;

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: ['January', 'February', 'March', 'April', 'May', 'June'],
    datasets: [{
      data: [45, 20, 64, 32, 76, 51],
      backgroundColor: 'rgb(255, 99, 132)',
      borderColor: 'rgb(255, 99, 132)',
      borderWidth: 1,
      label:"Orders"
    }]
  },
  plugins: [ChartRough],
  options:{
    plugins:{
      rough: {
        roughness:1,
      }
    }
  }
});

var slider = document.getElementById("rnSlider");
slider.oninput = function() {
  chart.options.plugins.rough.roughness = this.value;
  chart.update()
}</code></pre>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Thu, 12 Oct 2023 05:53:15 +0000</pubDate>
                            </item>
                    <item>
                <title><![CDATA[JavaScript Substring: The Hidden Gem to Supercharge Your Web Development Skills]]></title>
                <link>https://dhruvraval.dev/javascript-substring-the-hidden-gem-to-supercharge-your-web-development-skills</link>
                <description><![CDATA[<p>JavaScript is a powerful language for web development, but one feature often goes unnoticed: JavaScript substring. In this blog post, we'll explore how JavaScript substring can enhance your web development skills with ease and provide you with practical examples to get started.</p>
<h3 style="text-align: left;"><span style="color: #34495e;"># Extracting a Portion of a String</span></h3>
<p style="text-align: left;">Let's say you have a string variable called sentence with the <em>"Hello, world!"</em>. With JavaScript substring, you can extract a specific portion of this string.</p>
<pre class="language-javascript"><code>/*
This will give you "Hello", which extracts
characters from index 0 to 4 (inclusive).
*/
var sentence = "Hello";
var sub_str = sentence.substring(0, 5)
console.log(sub_str);</code></pre>
<h3 style="text-align: left;"><span style="color: #34495e;"># Example 2: Getting Part of a URL</span></h3>
<p style="text-align: left;">Imagine you have a URL stored in a variable called URL with the value <em>"https://www.example.com/article/12345"</em>. You can easily retrieve the article ID from the URL using a JavaScript substring.</p>
<pre class="language-javascript"><code>/*
This will give you "12345", extracting the portion
of the string after the last "/" character.
*/
var url = "https://www.example.com/article/12345";
var article_id =  url.substring(url.lastIndexOf('/') + 1);
console.log(article_id);
</code></pre>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Fri, 04 Aug 2023 16:55:13 +0000</pubDate>
                            </item>
                    <item>
                <title><![CDATA[Leveraging the Power of the <template> Tag in HTML for Dynamic Content Creation]]></title>
                <link>https://dhruvraval.dev/leveraging-power-template-tag-html-dynamic-content-creation</link>
                <description><![CDATA[<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">HTML, the backbone of the web, has evolved over the years to accommodate modern web development needs. The <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag allows developers to define HTML content that can be easily cloned and used dynamically, enabling the creation of reusable components. In this article, we will explore the benefits of using the <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag, illustrated through an example.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">Consider the following <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag example:</p>
<pre class="language-markup"><code>&lt;template id='optionsRowTemplate'&gt;
    &lt;tr&gt;
        &lt;td&gt;
            &lt;input type="text" class="form-control" data-input="english" required&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input type="text" class="form-control" data-input="hindi" required&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;input type="checkbox" class="form-control ckb-unset" data-input="is_ans"&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;a href="javascript:void(0)" class="remove_button remove_option" title="Remove option"&gt;
                &lt;img src="&lt;?php echo base_url(); ?&gt;/public/images/remove-icon.png" alt="Remove"&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/template&gt;</code></pre>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">Script:</p>
<pre class="language-javascript"><code>let option_temp_id = 1;
$("#add_options").click(function () {
        var new_temp_id = 'new-' + option_temp_id;
        createOptionRow(new_temp_id);
        option_temp_id++;
})

function createOptionRow(id, option_en = '', option_hi = '', is_ans = false) {

    const tbody = document.querySelector("#optionsTbody");
    const template = document.querySelector("#optionsRowTemplate");

    // Clone the new row and insert it into the table
    const clone = template.content.cloneNode(true);

    let option_row = clone.querySelector('tr');
    let input_en = clone.querySelector('[data-input="english"]');
    let input_hi = clone.querySelector('[data-input="hindi"]');
    let input_is_ans = clone.querySelector('[data-input="is_ans"]');

    option_row.dataset.optionId = id;

    input_en.name = `options[${id}][option_en]`;
    input_en.value = option_en;

    input_hi.name = `options[${id}][option_hi]`;
    input_hi.value = option_hi;

    input_is_ans.name = `options[${id}][correct_ans]`;
    input_is_ans.checked = is_ans;

    tbody.appendChild(clone);
}</code></pre>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">In this example, we have a template for an options row in a multi-language quiz application. Each row contains an input field for the English and Hindi translations of an option, a checkbox to mark it as the correct answer, and a remove button to delete the option.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">Now, let's delve into the benefits of using the <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag:</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;"><strong style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; color: var(--tw-prose-bold);">1. Reusability:</strong> The primary advantage of using <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> is reusability. Instead of hard-coding the entire row structure in your JavaScript whenever you need to add a new option dynamically, you can simply clone the template and modify its contents. This reduces redundancy and keeps your code clean and maintainable.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;"><strong style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; color: var(--tw-prose-bold);">2. Performance:</strong> By creating the template beforehand and cloning it, you eliminate the need for repetitive DOM manipulation when adding new options. This leads to improved performance as you're working with lightweight clones instead of constructing elements from scratch every time.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;"><strong style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; color: var(--tw-prose-bold);">3. Readability and Maintainability:</strong> With the template clearly defined in the HTML section, your JavaScript code becomes more readable, focusing on the dynamic aspects rather than constructing HTML elements. Additionally, any changes to the template are reflected instantly across all instances where it is used, making maintenance more straightforward.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;"><strong style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; color: var(--tw-prose-bold);">4. Data Binding:</strong> The template can be customized dynamically by binding data to its elements. In the provided example, the <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">createOptionRow()</code> function takes in data (option_en, option_hi, and is_ans) and populates the cloned template accordingly. This enables data-driven websites, where content can be updated dynamically based on user inputs or fetched data.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;"><strong style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; color: var(--tw-prose-bold);">5. Separation of Concerns:</strong> Using <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> promotes the separation of concerns between HTML structure and JavaScript logic. Designers can focus on the HTML template, while developers handle the dynamic behavior. This division of labor enhances collaboration and streamlines the development process.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">In conclusion, the <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag in HTML is a powerful tool for creating reusable, dynamic content, contributing to better performance, maintainability, and readability of your code. By leveraging the benefits of the <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag, you can enhance the interactivity and user experience of your web applications.</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">So, the next time you find yourself needing to create dynamic elements, consider using the <code style="border: 0px solid #d9d9e3; box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,0.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: 'S&ouml;hne Mono', Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;">&lt;template&gt;</code> tag to unlock its full potential and simplify your development process. Happy coding!</p>
<p style="font-size: 16px; border: 0px solid #d9d9e3; box-sizing: border-box; margin: 1.25em 0px 0px; caret-color: #374151; color: #374151; font-family: S&ouml;hne, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; white-space: pre-wrap;">Remember to include the necessary JavaScript libraries, such as jQuery, if you plan to use the provided example code in your project.</p>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Mon, 21 Aug 2023 06:12:35 +0000</pubDate>
                            </item>
                    <item>
                <title><![CDATA[Managing Old Data in Laravel with Mass Pruning]]></title>
                <link>https://dhruvraval.dev/laravel-mass-pruning-guide</link>
                <description><![CDATA[<p data-pm-slice="1 1 []">As applications grow, so does their data. Managing old, unnecessary records becomes crucial for maintaining database performance and application efficiency. Laravel, with its constant evolution, introduces the powerful <strong>Mass Pruning</strong> feature, making it easier than ever to clean up outdated data.</p>
<p>In this blog post, we&rsquo;ll explore the Mass Pruning feature, its advantages, and how to implement it in your Laravel applications.</p>
<h2 data-pm-slice="1 1 []">Why Prune Old Data?</h2>
<p data-pm-slice="1 3 []">Over time, applications accumulate data that may no longer be needed. Examples include:</p>
<ul data-spread="false">
<li>
<p>Expired user sessions.</p>
</li>
<li>
<p>Old logs or audit trails.</p>
</li>
<li>
<p>Orders or records that exceed a retention period.</p>
</li>
</ul>
<h2 data-pm-slice="1 1 []">Laravel&rsquo;s Mass Pruning</h2>
<p data-pm-slice="1 1 []">Laravel&rsquo;s Mass Pruning simplifies the process of removing old records. By defining a <code>prunable</code> method within your model, you can specify the criteria for data deletion. This method integrates seamlessly with Laravel&rsquo;s task scheduling and queuing system, ensuring efficient and controlled cleanup processes.</p>
<h2 data-pm-slice="1 1 []">Setting Up Mass Pruning</h2>
<h3>Step 1: Add the <code>Prunable</code> Trait</h3>
<p>Use the <code>Prunable</code> trait in your model. This trait provides the necessary functionality for mass pruning.</p>
<h3>Step 2: Define the <code>prunable</code> Method</h3>
<p>In the <code>prunable</code> method, define the query logic for selecting records to delete. For instance, let&rsquo;s prune orders older than one year:</p>
<pre class="language-php"><code>namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;

class Order extends Model
{
    use Prunable;

    /**
     * Get the prunable query.
     */
    protected function prunable()
    {
        return static::where('created_at', '&lt;', now()-&gt;subYear());
    }
}</code></pre>
<h3 data-pm-slice="1 1 []">Step 3: Schedule the Pruning</h3>
<p data-pm-slice="1 1 []">Use Laravel&rsquo;s task scheduling to automate the pruning process. Open the <code>App\Console\Kernel.php</code> file and schedule the pruning job:</p>
<pre class="language-php"><code>protected function schedule(Schedule $schedule)
{
    $schedule-&gt;call(function () {
        Order::prune();
    })-&gt;daily();
}</code></pre>
<p data-pm-slice="1 1 []">This configuration ensures that old orders are deleted daily.</p>
<h3 data-pm-slice="1 1 []">Step 4: Handle Pruning Events (Optional)</h3>
<p>You can handle events during the pruning process, such as logging or notifying administrators. Override the <code>pruning</code> or <code>pruned</code> methods in your model:</p>
<pre class="language-php"><code>protected function pruning()
{
    Log::info('Pruning orders older than a year.');
}

protected function pruned()
{
    Log::info('Pruning completed successfully.');
}</code></pre>
<h2 data-pm-slice="1 3 []">Advantages of Mass Pruning</h2>
<ul data-spread="false">
<li>
<p><strong>Automation:</strong> Set up once and automate the cleanup process.</p>
</li>
<li>
<p><strong>Performance:</strong> Improve query speeds by keeping the database lean.</p>
</li>
<li>
<p><strong>Flexibility:</strong> Define custom pruning criteria tailored to your application&rsquo;s needs.</p>
</li>
<li>
<p><strong>Scalability:</strong> Handle large datasets without manual intervention.</p>
</li>
</ul>
<h2>Use Cases</h2>
<ul data-spread="false">
<li>
<p>Cleaning up old user-generated content.</p>
</li>
<li>
<p>Removing outdated records from logs or caches.</p>
</li>
</ul>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Thu, 02 Jan 2025 06:31:42 +0000</pubDate>
                            </item>
                    <item>
                <title><![CDATA[Unveiling the NVIDIA RTX 50 Series: The Next Frontier in Graphics Technology]]></title>
                <link>https://dhruvraval.dev/nvidia-rtx-50-series-launch-details</link>
                <description><![CDATA[<p data-pm-slice="1 1 []"><strong>Unveiling the NVIDIA RTX 50 Series: The Next Frontier in Graphics Technology</strong></p>
<p>The world of gaming and content creation has just reached a groundbreaking milestone with the launch of NVIDIA&rsquo;s RTX 50 Series graphics cards. Designed to redefine performance, efficiency, and visual fidelity, these cards leverage cutting-edge technologies to deliver an unparalleled experience for gamers, creators, and professionals. Here&rsquo;s everything you need to know about the RTX 50 Series lineup.</p>
<h3><strong>RTX 50 Series Lineup and Specifications</strong></h3>
<h4><strong>1. GeForce RTX 5090</strong></h4>
<p><strong>Price</strong>: $1,999<br /><strong>Key Features</strong>:</p>
<ul data-spread="false">
<li>
<p>21,760 CUDA cores</p>
</li>
<li>
<p>32 GB GDDR7 memory with a 512-bit interface</p>
</li>
<li>
<p>Memory bandwidth: 1,792 GB/s</p>
</li>
<li>
<p>Base clock: 2.01 GHz | Boost clock: 2.41 GHz</p>
</li>
<li>
<p>Up to 2x the performance of the RTX 4090</p>
</li>
</ul>
<p>As the flagship model, the RTX 5090 delivers unmatched performance for ultra-high-resolution gaming, professional-grade rendering, and AI workloads. With the new Blackwell architecture and DLSS 4 technology, it sets a new benchmark for speed and efficiency.</p>
<h4><strong>2. GeForce RTX 5080</strong></h4>
<p><strong>Price</strong>: $999<br /><strong>Key Features</strong>:</p>
<ul data-spread="false">
<li>
<p>10,752 CUDA cores</p>
</li>
<li>
<p>16 GB GDDR7 memory on a 256-bit bus</p>
</li>
<li>
<p>Memory bandwidth: 960 GB/s</p>
</li>
<li>
<p>Base clock: 2.3 GHz | Boost clock: 2.62 GHz</p>
</li>
</ul>
<p>The RTX 5080 is designed for gamers seeking next-level performance without breaking the bank. With advanced ray tracing and AI enhancements, this card excels in 4K gaming and creative workflows.</p>
<h4><strong>3. GeForce RTX 5070 Ti</strong></h4>
<p><strong>Price</strong>: $749<br /><strong>Key Features</strong>:</p>
<ul data-spread="false">
<li>
<p>8,960 CUDA cores</p>
</li>
<li>
<p>16 GB GDDR7 memory with a 256-bit interface</p>
</li>
<li>
<p>Memory bandwidth: 896 GB/s</p>
</li>
<li>
<p>Base clock: 2.3 GHz | Boost clock: 2.45 GHz</p>
</li>
</ul>
<p>Striking a balance between price and performance, the RTX 5070 Ti is perfect for high-performance gaming and demanding creative tasks. It&rsquo;s a great choice for gamers looking to experience next-gen technology at a mid-tier price.</p>
<h4><strong>4. GeForce RTX 5070</strong></h4>
<p><strong>Price</strong>: $549<br /><strong>Key Features</strong>:</p>
<ul data-spread="false">
<li>
<p>6,144 CUDA cores</p>
</li>
<li>
<p>12 GB GDDR7 memory on a 192-bit bus</p>
</li>
<li>
<p>Memory bandwidth: 672 GB/s</p>
</li>
<li>
<p>Base clock: 2.16 GHz | Boost clock: 2.51 GHz</p>
</li>
</ul>
<p>As the entry-level model in the RTX 50 Series, the RTX 5070 provides exceptional value for 1080p and 1440p gaming while still packing enough power for creative projects and productivity tasks.</p>
<h3 data-pm-slice="1 1 []"><strong>Next-Gen Technologies in the RTX 50 Series</strong></h3>
<h4><strong>1. Blackwell Architecture</strong></h4>
<p>The RTX 50 Series introduces the Blackwell GPU architecture, delivering significant improvements in performance, efficiency, and AI processing capabilities. This architecture enables the cards to handle complex workloads with ease, making them ideal for gaming, content creation, and AI research.</p>
<h4><strong>2. DLSS 4</strong></h4>
<p>NVIDIA&rsquo;s latest AI-driven upscaling technology, DLSS 4, takes image quality to new heights. Gamers can enjoy smoother gameplay with higher frame rates, even at ultra-high resolutions, without compromising visual fidelity.</p>
<h4><strong>3. Advanced Ray Tracing</strong></h4>
<p>With improved ray tracing cores, the RTX 50 Series offers more realistic lighting, reflections, and shadows, elevating the immersion in games and 3D applications.</p>
<h4><strong>4. Enhanced Efficiency</strong></h4>
<p>The RTX 50 Series is designed to be more power-efficient, reducing heat output and enabling quieter operation, even under heavy loads. This makes it a great choice for gamers and professionals who need consistent performance during long sessions.</p>
<h3><strong>Release Dates and Availability</strong></h3>
<ul data-spread="false">
<li>
<p><strong>GeForce RTX 5090 and RTX 5080</strong>: Available starting January 30, 2025</p>
</li>
<li>
<p><strong>GeForce RTX 5070 Ti and RTX 5070</strong>: Available in February 2025</p>
</li>
</ul>
<p>These cards will be available through NVIDIA&rsquo;s official website and authorized retailers worldwide.</p>
<p>&nbsp;</p>
<h3 data-pm-slice="1 1 []"><strong>Why Upgrade to the RTX 50 Series?</strong></h3>
<p>If you&rsquo;re a gamer, content creator, or professional looking for the latest and greatest in graphics technology, the RTX 50 Series is a worthy investment. With groundbreaking performance, future-ready features, and improved efficiency, these cards offer something for everyone.</p>
<h3><strong>Conclusion</strong></h3>
<p>The NVIDIA RTX 50 Series is not just an upgrade&mdash;it&rsquo;s a revolution in graphics technology. Whether you&rsquo;re chasing ultra-high frame rates, diving into photorealistic virtual worlds, or tackling demanding professional tasks, the RTX 50 Series has you covered.</p>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Tue, 07 Jan 2025 12:41:55 +0000</pubDate>
                            </item>
                    <item>
                <title><![CDATA[Lazy Load Components with React.lazy: A Beginner’s Guide]]></title>
                <link>https://dhruvraval.dev/lazy-load-components-with-react-lazy</link>
                <description><![CDATA[<p>When building React applications, performance is always a top priority. One powerful technique for improving performance is <strong>lazy loading</strong>&mdash;a method of loading parts of your app only when they are needed, rather than loading everything upfront. This can significantly speed up page load times, especially for larger applications.</p>
<p>In this post, we'll look at how to use <strong>React.lazy</strong> to easily lazy load components and improve your app&rsquo;s performance.</p>
<h3>What is Lazy Loading?</h3>
<p>Lazy loading is a technique where you defer loading certain parts of your app until they are actually required. This is especially useful for large applications that contain many components and libraries. By loading components only when the user interacts with them (such as when they navigate to a certain page), you can reduce the initial loading time of your app.</p>
<h3>How React.lazy Works</h3>
<p><strong>React.lazy</strong> allows you to dynamically import components. Instead of importing components at the top of your file like usual, React will only load them when needed. This can be particularly useful for things like modals, pop-ups, or routes that users may not always visit.</p>
<h3>Example of Lazy Loading a Component</h3>
<p>Let&rsquo;s say you have a large component that you don&rsquo;t want to load immediately, but only when the user interacts with it. Here&rsquo;s how you can use <strong>React.lazy</strong> to load that component on demand:</p>
<pre class="language-javascript"><code>import React, { Suspense } from 'react';

// Lazy load the component
const LazyComponent = React.lazy(() =&gt; import('./LazyComponent'));

function App() {
  return (
    &lt;div&gt;
      &lt;h1&gt;Welcome to my app!&lt;/h1&gt;
      
      {/* Use Suspense to handle the loading state */}
      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;
        &lt;LazyComponent /&gt;
      &lt;/Suspense&gt;
    &lt;/div&gt;
  );
}

export default App;
</code></pre>
<h3>How It Works:</h3>
<ul>
<li>
<p><strong>React.lazy</strong>: This function takes a callback that dynamically imports the component. In this example, the <code>LazyComponent</code> will only be loaded when it is rendered in the UI.</p>
</li>
<li>
<p><strong>Suspense</strong>: Since the component is being loaded lazily, we need to wrap it in <strong>Suspense</strong>. This is a built-in React component that lets you define a fallback UI (like a loading spinner or text) while the lazy-loaded component is being fetched.</p>
</li>
</ul>
<h3>Why Use React.lazy?</h3>
<p>Lazy loading offers several benefits:</p>
<ol>
<li><strong>Faster initial load</strong>: By loading components only when needed, you can reduce the amount of JavaScript loaded initially. This results in a faster loading time for your app.</li>
<li><strong>Better performance</strong>: Lazy loading helps with overall performance by splitting your app into smaller bundles, which can be downloaded as needed.</li>
<li><strong>Improved user experience</strong>: Instead of waiting for the entire app to load, users can start interacting with the parts that are immediately available, while other components load in the background.</li>
</ol>
<h3>When Should You Use React.lazy?</h3>
<p>React.lazy is most beneficial when:</p>
<ul>
<li>You have large components or libraries that aren&rsquo;t critical for the initial render.</li>
<li>Your app has multiple pages or routes, and some pages are less frequently visited.</li>
<li>You want to improve the performance of a large app with many components.</li>
</ul>
<h3>Important Notes:</h3>
<ul>
<li><strong>Error boundaries</strong>: It's a good idea to wrap lazy-loaded components in <strong>Error Boundaries</strong> to handle any loading errors gracefully.</li>
<li><strong>SEO Considerations</strong>: Since React.lazy relies on JavaScript, the content won&rsquo;t be available for search engines to index unless you use server-side rendering (SSR).</li>
</ul>]]></description>
                <author><![CDATA[Dhruv Raval <dhraval99@gmail.com>]]></author>
                
                <pubDate>Thu, 09 Jan 2025 07:32:29 +0000</pubDate>
                            </item>
            </channel>
</rss>
