<?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: Mohammad Abdul Alim</title>
    <description>The latest articles on DEV Community by Mohammad Abdul Alim (@alim1496).</description>
    <link>https://dev.to/alim1496</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%2F641955%2F02940f5e-848d-4028-860d-ef32ff783717.jpeg</url>
      <title>DEV Community: Mohammad Abdul Alim</title>
      <link>https://dev.to/alim1496</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alim1496"/>
    <language>en</language>
    <item>
      <title>Explaining Maximum Subarray Sum problem with Kadane's Algorithm</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Fri, 07 Oct 2022 10:30:48 +0000</pubDate>
      <link>https://dev.to/alim1496/explaining-maximum-subarray-sum-problem-with-kadanes-algorithm-11im</link>
      <guid>https://dev.to/alim1496/explaining-maximum-subarray-sum-problem-with-kadanes-algorithm-11im</guid>
      <description>&lt;p&gt;There is no alternative of solving dynamic programming related problems in order to get a job in &lt;strong&gt;FAANG&lt;/strong&gt; or big companies and also be a very good programmer. We developers often try to ignore problem solving and focus on only development but we need to remember that in order to solve real life big production problems or optimize something we need to be a very good problem solver. This will help us a lot in solving problems in our day to day career.&lt;/p&gt;

&lt;p&gt;So keeping this thing in mind I started solving dynamic programming related problems and in the very beginning I came to know about The &lt;strong&gt;Maximum Subarray Sum&lt;/strong&gt; problem which can be solved easily with &lt;strong&gt;Kadane's Algorithm&lt;/strong&gt;. Today I would like to discuss about this algorithm and solving the problem with it.&lt;/p&gt;

&lt;p&gt;At first let us know the description of the problem. It says that &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We are given an integer array, we need to find the contiguous subarray that has the largest sum and return that sum. For example: [-2,1,-3,4,-1,2,1,-5,4] is an array. Here the subarray [4,-1,2,1] has the largest sum which is 6.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now let us see what Kadane's Algorithm says&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize 2 variables as &lt;code&gt;current_sum&lt;/code&gt; to 0 and &lt;code&gt;max_sum&lt;/code&gt; to minimum negative value which represent the sum in the current position and maximum sum in that array.&lt;/li&gt;
&lt;li&gt;Assign the maximum between the current array element and the sum of that element with the &lt;code&gt;current_sum&lt;/code&gt; as the &lt;code&gt;current_sum&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Assign the maximum between &lt;code&gt;max_sum&lt;/code&gt; and the &lt;code&gt;current_sum&lt;/code&gt; as the &lt;code&gt;max_sum&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Repeat steps 2 and 3 for all the elements of the array.&lt;/li&gt;
&lt;li&gt;Return the &lt;code&gt;max_sum&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here I would like to solve the problem in C++ but you have the liberty of choosing any language.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int findMaxSum(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
    int max_sum = INT_MIN;
    int current_sum = 0;

    for(int n:nums) {
        current_sum = max(n, current_sum + n);
        max_sum = max(max_sum, current_sum);
    }

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

&lt;/div&gt;



&lt;p&gt;The running time complexity is O(n) as there is a single loop which runs for n times which is the total number of elements in the aaray. In the same time, the space complexity is O(1) since we do not need any external data structures.&lt;/p&gt;

&lt;p&gt;Thus we have solved the maximum subarray sum problem using Kadane's algorithm. Now let us see how our approach resembles with a dynamic programming one. In dynamic programming approach, the main problem is divided into a group of smaller problems and each solution of those small problems are utilised again so that they are not needed to be calculated again which is called memoization. Here we have calculated the maximum between each array element and the current sum and assign that maximum as the current sum in that element index. After that we have compared the current and maximum sum in that position and assigned the maximum between them as the maximum sum. Thus in every step we have solved the problem and also used the previously calculated result to be utilized again. Thus we have used dynamic programming approach in our solution.&lt;/p&gt;

&lt;p&gt;Understanding and implementing dynamic programming approach is really very hard but with regular practice and a bit hard work we can achieve it. I hope we start solving problems in order to be a very good developer.&lt;/p&gt;

&lt;p&gt;Happy coding!!!&lt;/p&gt;

</description>
      <category>dynamicprogramming</category>
      <category>kadanealgorithm</category>
      <category>problemsolving</category>
    </item>
    <item>
      <title>Developing a simple URL shortener with node, express, ejs and mysql</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Fri, 17 Dec 2021 00:40:33 +0000</pubDate>
      <link>https://dev.to/alim1496/developing-a-simple-url-shortener-with-node-express-ejs-and-mysql-3o44</link>
      <guid>https://dev.to/alim1496/developing-a-simple-url-shortener-with-node-express-ejs-and-mysql-3o44</guid>
      <description>&lt;p&gt;A URL shortener is a pretty simple system that shortens longer URLs. On hitting the short URL, a user is automatically redirected to the actual URL. The main advantage of this is a user can share a short form of a very long URL. Today I would like to develop a simple URL shortener with node, express, ejs and mysql. &lt;/p&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;p&gt;Our web app will have the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shorten lonnger URLs&lt;/li&gt;
&lt;li&gt;Redirect to main URL upon clicking the shorter one&lt;/li&gt;
&lt;li&gt;Copy the shorter URL to use anywhere&lt;/li&gt;
&lt;li&gt;Show the number of time a particular URL has been shorten&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Project Setup
&lt;/h3&gt;

&lt;p&gt;We will need the followings for this project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node&lt;/a&gt; runtime environment&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.mysql.com/" rel="noopener noreferrer"&gt;MySQL&lt;/a&gt; as a database which also be obtained by using &lt;a href="https://www.apachefriends.org/" rel="noopener noreferrer"&gt;XAMPP&lt;/a&gt; or similar packages&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;express&lt;/a&gt; application framework&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/ejs" rel="noopener noreferrer"&gt;ejs&lt;/a&gt; to generate HTML template views&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/shortid" rel="noopener noreferrer"&gt;shortid&lt;/a&gt; to generate unique and short ids for URLs&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/nodemon" rel="noopener noreferrer"&gt;nodemon&lt;/a&gt; as a watcher to obtain auto reloading the project on each save&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Project Description
&lt;/h3&gt;

&lt;p&gt;At first lets create a folder named &lt;code&gt;url-shortener&lt;/code&gt; in our local machine and go to that folder. Now its time to create the &lt;code&gt;package.json&lt;/code&gt; file and install necessary packages. Following commands will do so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
npm i express ejs mysql shortid
npm i --save-dev nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to update the script property with &lt;code&gt;"dev": "nodemon index.js"&lt;/code&gt; which means on running &lt;code&gt;npm run dev&lt;/code&gt; nodemon will run our entry file. So our &lt;code&gt;package.json&lt;/code&gt; file will look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "url-shortener",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "mysql": "^2.18.1",
    "shortid": "^2.2.16"
  },
  "devDependencies": {
    "nodemon": "^2.0.15"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets create the &lt;code&gt;index.js&lt;/code&gt; file in our root directory along with two directories named &lt;code&gt;public&lt;/code&gt; and &lt;code&gt;views&lt;/code&gt; to store assets and ejs files respectively.&lt;/p&gt;

&lt;p&gt;Lets describe the &lt;code&gt;index.js&lt;/code&gt; file gradually. At first we import all the packages and start the express server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const shortid = require("shortid");
const mysql = require("mysql");
const app = express();

app.listen(3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we run the &lt;code&gt;npm run dev&lt;/code&gt; command then in &lt;strong&gt;&lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&gt;&lt;/strong&gt; of our browser express will run but we need to specify routes. Before that we specify the view engine and static file path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));
app.use(express.urlencoded({ extended: false }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we define our home route like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/", (req, res) =&amp;gt; {
    res.render("home.ejs");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here it says whenever a request is created to the root path, it will show the home template file as the response. So inside the &lt;code&gt;views&lt;/code&gt; directory we create the &lt;code&gt;home.ejs&lt;/code&gt; file and write the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;URL Shortener&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="/styles/home.css" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;h2&amp;gt;URL Shortener&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;Convert long URL to shorter one with a single click. Its easy, simple and absolutely free!&amp;lt;/p&amp;gt;
        &amp;lt;form action="/shortUrl" method="post"&amp;gt;
            &amp;lt;input type="url" placeholder="Enter the URL" name="fullUrl" required /&amp;gt;
            &amp;lt;input type="submit" value="Convert" /&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have added a css file named &lt;code&gt;home.css&lt;/code&gt; which should remain in a folder named &lt;code&gt;styles&lt;/code&gt; of the &lt;code&gt;public&lt;/code&gt; directory. This means we have to create the &lt;code&gt;styles&lt;/code&gt; directory inside &lt;code&gt;public&lt;/code&gt; directory and create &lt;code&gt;home.css&lt;/code&gt; inside it. Then we write the follwing css code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    width: 50%;
    margin: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
}

h2 {
    margin: 0;
}

p {
    max-width: 350px;
}

input[type="url"] {
    height: 28px;
    width: 250px;
    padding-left: 8px;
    border-radius: 4px;
    border: 1px solid #000;
}

input[type="submit"] {
    padding: 10px 20px;
    color: #fff;
    background-color: #349ded;
    border: none;
    border-radius: 4px;
    margin-left: 5px;
}

input[type="submit"]:hover {
    cursor: pointer;
    opacity: 0.85;
}

.span-link {
    padding: 10px 20px;
    border-radius: 4px;
    background-color: #349ded;
    color: #fff;
}

.result-container {
    background-color: #dddcdc;
    padding: 10px;
    min-width: 200px;
    display: flex;
    justify-content: space-around;
}

a {
    text-decoration: none;
}

.copy-span:hover {
    cursor: pointer;
    opacity: 0.75;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now upon saving our code our browser should look like this:&lt;br&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%2Fzbpwkzo7vgrp7n61xe88.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbpwkzo7vgrp7n61xe88.PNG" alt="Image description" width="641" height="245"&gt;&lt;/a&gt;&lt;br&gt;
Now if we add a URL in the input section and click &lt;code&gt;Convert&lt;/code&gt;, it will not work because we have not defined our route &lt;code&gt;/shortUrl&lt;/code&gt; for &lt;code&gt;&amp;lt;form action="/shortUrl" method="post"&amp;gt;&lt;/code&gt;. In order to create this route we need to create our database and table at first. I have used &lt;code&gt;XAMPP&lt;/code&gt; to do so. After running &lt;code&gt;Apache&lt;/code&gt; and &lt;code&gt;MySQL&lt;/code&gt; processes of XAMPP control panel we go to &lt;strong&gt;&lt;a href="http://localhost/phpmyadmin/" rel="noopener noreferrer"&gt;http://localhost/phpmyadmin/&lt;/a&gt;&lt;/strong&gt; and create a database named &lt;code&gt;url_shortener&lt;/code&gt;. Then we create a table named &lt;code&gt;url&lt;/code&gt; which has the following structure:&lt;br&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%2Fyy2xcapopju53xbty18z.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyy2xcapopju53xbty18z.PNG" alt="Image description" width="800" height="194"&gt;&lt;/a&gt;&lt;br&gt;
We can see that the table has four properties namely an auto increment id, fullUrl, shortUrl and counts which stores the number of times a particular URL gets shortened. Now its time to connect our database. We add the followings in our index file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const db = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "url_shortener"
});

db.connect(err =&amp;gt; {
    if(err) {
        console.log("Error connecting to DB");
        return;
    }
    console.log("Connceted to DB");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this its time to create our &lt;code&gt;/shorturl&lt;/code&gt; post route. Here our logic is pretty much simple. Our request body contains a parameter named &lt;code&gt;fullUrl&lt;/code&gt; that is given as an input by the user. At first we query to the db with that parameter whether an entry exists. If not then we create a new entry with that fullUrl, its generated shortid and counts 1. Then we pass &lt;code&gt;shortUrl&lt;/code&gt; and &lt;code&gt;counts&lt;/code&gt; as object to a new view named &lt;code&gt;result.ejs&lt;/code&gt;. If the entry exists then we simply increase its counts by 1 and pass &lt;code&gt;shortUrl&lt;/code&gt; and &lt;code&gt;counts&lt;/code&gt; as object to the view. Lets see our route now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post("/shorturl", (req, res) =&amp;gt; {
    const fullUrl = req.body.fullUrl;
    if (!fullUrl) {
        return res.sendStatus(404);
    }
    db.query('SELECT * FROM `url` WHERE `fullUrl` = ?', [fullUrl], (error, results) =&amp;gt; {
        if (error) {
            console.log("we got error");
            return;
        }

        if (results.length === 0) {
            const short = shortid.generate();
            const url = { fullUrl: req.body.fullUrl, shortUrl: short, counts: 1 };
            db.query('INSERT INTO `url` SET ?', url, (err, res) =&amp;gt; {
                if (err) {
                    console.log("Error creating table");
                    return;
                }
            });
            res.render("result.ejs", { shortUrl: short, times: 1 });
        } else {
            const _short = results[0].shortUrl;
            const _counts = results[0].counts;
            db.query('UPDATE `url` SET `counts` = ? WHERE `shortUrl` = ?', [_counts + 1, _short], (err, res) =&amp;gt; {
                if (err) {
                    console.log("Error updating table");
                    return;
                }
            });
            res.render("result.ejs", { shortUrl: _short, times: _counts + 1 });
        }
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the same time we create &lt;code&gt;result.ejs&lt;/code&gt; file inside &lt;code&gt;views&lt;/code&gt; directory and add following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;URL Shortener&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="/styles/home.css" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;h2&amp;gt;URL Shortener&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;Your shortened URL is&amp;lt;/p&amp;gt;
        &amp;lt;div class="result-container"&amp;gt;
            &amp;lt;span&amp;gt;&amp;lt;a id="short-url" href="&amp;lt;%= `/${shortUrl}` %&amp;gt;" target="_blank"&amp;gt;&amp;lt;%= shortUrl %&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;span onclick="copyUrl()" class="copy-span" id="copy-action"&amp;gt;Copy&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;p&amp;gt;It has been converted &amp;lt;%= times %&amp;gt; times&amp;lt;/p&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;a href="/"&amp;gt;&amp;lt;span class="span-link"&amp;gt;Try Another&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script&amp;gt;
        const copyUrl = () =&amp;gt; {
            const copyTextarea = document.getElementById("short-url").href;
            navigator.clipboard.writeText(copyTextarea);
            document.getElementById("copy-action").innerHTML = "Copied";
        };
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now upon saving our files lets copy &lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=dwKSRsmpYjc&amp;amp;ab_channel=INSIDE" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=dwKSRsmpYjc&amp;amp;ab_channel=INSIDE&lt;/a&gt;&lt;/strong&gt;, paste it to our input field and click &lt;code&gt;Convert&lt;/code&gt;. We see something like this:&lt;br&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%2Fm34nwwdfkucxf93bhmll.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm34nwwdfkucxf93bhmll.PNG" alt="Image description" width="555" height="257"&gt;&lt;/a&gt;&lt;br&gt;
Here by clicking the &lt;code&gt;Copy&lt;/code&gt; field we can copy our short URL and clicking the short URL we can go to a new tab but unfortunately it will not redirect to the actual URL because we have not defined our corresponding route yet. So lets define it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/:shortUrl", (req, res) =&amp;gt; {
    db.query('SELECT * FROM `url` WHERE `shortUrl` = ?', [req.params.shortUrl], (error, results) =&amp;gt; {
        if (error) {
            return res.sendStatus(404);
        }

        if (results.length === 0) {
            res.render("error.ejs");
        } else {
            res.redirect(results[0].fullUrl);
        }
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are sending a dynamic parameter with our route path and looking for an entry with that short URL in our database. If an entry exists then we simply redirect to the &lt;code&gt;fullUrl&lt;/code&gt; of it. Otherwise we render an &lt;code&gt;error.ejs&lt;/code&gt; page that shows an error page and asks to visit the home page. Its code is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Error Page&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="/styles/home.css" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;h2&amp;gt;URL Shortener&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;The URL you entered does not exist!&amp;lt;/p&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;a href="/"&amp;gt;&amp;lt;span class="span-link"&amp;gt;Visit Home Page&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus we have developed a simple URL Shortener website very easily. The full code can be found &lt;a href="https://github.com/alim1496/url-shortener-express" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Please feel free to share your thoughts rerarding it.&lt;/p&gt;

&lt;p&gt;Happy coding 😀😀😀&lt;/p&gt;

</description>
      <category>node</category>
      <category>mysql</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My first react native app from scratch</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Wed, 08 Dec 2021 06:47:04 +0000</pubDate>
      <link>https://dev.to/alim1496/my-first-react-native-app-from-scratch-fm8</link>
      <guid>https://dev.to/alim1496/my-first-react-native-app-from-scratch-fm8</guid>
      <description>&lt;p&gt;React has been a very popular javascript library for developing user intefaces basically the front end of web applications. In the similar way react native is also a very popular library for building cross platform mobile applications. It means by writing javascript code we can generate both android and ios applications separately. An interesting thing is that if someone has a good knowledge over react then he has almost 80% knowledge of react native. So the react developers should give it a try. Today I would like to discuss about a react native app that can be built easily with all the knowledge of react plus some new knowledge of react native. So those who are familiar with react and also want to start learning react native are encouraged to go through this post.&lt;/p&gt;

&lt;p&gt;Today I will build a ToDo app with react native and will run it in an android device. It will have the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a task&lt;/li&gt;
&lt;li&gt;Show all tasks&lt;/li&gt;
&lt;li&gt;Mark a task as done&lt;/li&gt;
&lt;li&gt;Delete a task&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Project setup
&lt;/h3&gt;

&lt;p&gt;At first we will setup the environment for react native using &lt;a href="https://reactnative.dev/docs/environment-setup"&gt;this doc&lt;/a&gt; as per our OS. After successfully setting up the environment we will initiate a react native project using the following command and go to that directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native init TodoApp
cd TodoApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will be using two third party libraries for &lt;a href="https://www.npmjs.com/package/@react-native-async-storage/async-storage"&gt;Async Storage&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/react-native-vector-icons"&gt;vector icons&lt;/a&gt; using the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @react-native-async-storage/async-storage react-native-vector-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Description
&lt;/h3&gt;

&lt;p&gt;We will be editing inside the &lt;code&gt;src&lt;/code&gt; directory. We will add four components in our project. These are the main &lt;code&gt;App&lt;/code&gt;, &lt;code&gt;Delete Modal&lt;/code&gt;, &lt;code&gt;Add Modal&lt;/code&gt; and &lt;code&gt;Todo Item&lt;/code&gt;. Each of these components are &lt;a href="https://reactjs.org/docs/components-and-props.html"&gt;functional component&lt;/a&gt; with &lt;a href="https://reactjs.org/docs/hooks-state.html"&gt;hooks&lt;/a&gt; and will have a stylesheet associated with them. Let us describe them one by one.&lt;/p&gt;

&lt;h4&gt;
  
  
  Add Modal
&lt;/h4&gt;

&lt;p&gt;This component is mainly a &lt;a href="https://reactnative.dev/docs/modal"&gt;Modal&lt;/a&gt; that will be popped up on clicking an add button to add a todo task. It will contain two &lt;a href="https://reactnative.dev/docs/textinput"&gt;TextInput&lt;/a&gt; for task title and timestamp. It will also have two &lt;a href="https://reactnative.dev/docs/touchableopacity"&gt;TouchableOpacity&lt;/a&gt; for adding the task and discarding it. Inside &lt;code&gt;src&lt;/code&gt; directory we will create a js file named &lt;code&gt;TaskModal&lt;/code&gt; and write the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';
import { View, Text, StyleSheet, Modal, TouchableOpacity, TextInput } from 'react-native';
import Icon from 'react-native-vector-icons/AntDesign';
import { COLORS } from './App';

const TaskModal = ({ isOpen, onClose, onSuccess }) =&amp;gt; {
    const [title, setTitle] = useState('');
    const [date, setDate] = useState('');

    const addData = () =&amp;gt; {
        if(title &amp;amp;&amp;amp; date) {
            onSuccess(title, date);
            setDate('');
            setTitle('');
        }
    };

    const closeModal = () =&amp;gt; {
        onClose();
        setTitle('');
        setDate('');
    };

    return (
        &amp;lt;Modal
            visible={isOpen}
            onRequestClose={onClose}
            transparent={true}
        &amp;gt;
            &amp;lt;View style={styles.centeredView}&amp;gt;
                &amp;lt;View style={styles.modalView}&amp;gt;
                    &amp;lt;TextInput
                        placeholder="Add a task"
                        style={styles.input}
                        value={title}
                        onChangeText={(value) =&amp;gt; setTitle(value)}
                    /&amp;gt;
                    &amp;lt;TextInput
                        placeholder="dd-mm-yyyy hh:mm"
                        style={styles.input}
                        value={date}
                        onChangeText={(value) =&amp;gt; setDate(value)}
                    /&amp;gt;
                    &amp;lt;View style={styles.actionHolder}&amp;gt;
                        &amp;lt;TouchableOpacity
                            onPress={addData}&amp;gt;
                            &amp;lt;Icon name="checkcircleo" size={30} color={COLORS.blue} /&amp;gt;
                        &amp;lt;/TouchableOpacity&amp;gt;
                        &amp;lt;TouchableOpacity onPress={closeModal}&amp;gt;
                            &amp;lt;Icon name="closecircleo" size={30} color={COLORS.red} /&amp;gt;
                        &amp;lt;/TouchableOpacity&amp;gt;
                    &amp;lt;/View&amp;gt;
                &amp;lt;/View&amp;gt;
            &amp;lt;/View&amp;gt;
        &amp;lt;/Modal&amp;gt;
    );
};

const styles = StyleSheet.create({
    centeredView: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center"
      },
      modalView: {
        backgroundColor: "white",
        borderRadius: 20,
        padding: 16,
        alignItems: "center",
        shadowColor: "#000",
        shadowOffset: {
          width: 0,
          height: 2
        },
        shadowOpacity: 0.25,
        shadowRadius: 4,
        elevation: 5
      },
      input: {
        height: 40,
        width: 250,
        margin: 12,
        borderWidth: 1,
        padding: 10,
        borderRadius: 6,
      },
      actionHolder: {
          flexDirection: 'row',
          justifyContent: 'space-around',
          width: 100,
      }
});

export default TaskModal;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completing the rest of the code and successfully building this component will look as following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EnTTktYB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jv30kka8ww8768oiegi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EnTTktYB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jv30kka8ww8768oiegi.jpg" alt="Image description" width="617" height="374"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Todo Item
&lt;/h4&gt;

&lt;p&gt;This component will render a todo task row. Here we will have the title of the task and a timestamp of doing it along with a check and delete button. Inside &lt;code&gt;src&lt;/code&gt; directory we will create a js file named &lt;code&gt;TaskItem&lt;/code&gt; and write the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import Icon from 'react-native-vector-icons/AntDesign';
import { View, StyleSheet, Text, TouchableOpacity } from 'react-native';
import { COLORS } from './App';

const TaskItem = ({ task, onDelete, onCheck }) =&amp;gt; (
    &amp;lt;View style={styles.parentHolder}&amp;gt;
        &amp;lt;View style={styles.mainHolder}&amp;gt;
            &amp;lt;View style={styles.itemHolder}&amp;gt;
                &amp;lt;Text style={{...styles.itemText, ...styles.largeText}}&amp;gt;{task.title}&amp;lt;/Text&amp;gt;
                &amp;lt;Text style={{...styles.itemText, ...styles.smallText}}&amp;gt;{task.time}&amp;lt;/Text&amp;gt;
            &amp;lt;/View&amp;gt;
            &amp;lt;View style={styles.actionHolder}&amp;gt;
                &amp;lt;TouchableOpacity onPress={() =&amp;gt; onDelete(task.id)}&amp;gt;
                    &amp;lt;Icon name="delete" size={18} color={COLORS.red} /&amp;gt;
                &amp;lt;/TouchableOpacity&amp;gt;
                &amp;lt;TouchableOpacity style={styles.spaced} onPress={() =&amp;gt; onCheck(task.id)}&amp;gt;
                    &amp;lt;Icon name={task.completed ? `checkcircle` : `checkcircleo`} size={18} color="#2b5fed" /&amp;gt;
                &amp;lt;/TouchableOpacity&amp;gt;
            &amp;lt;/View&amp;gt;
        &amp;lt;/View&amp;gt;
    &amp;lt;/View&amp;gt;
);

const styles = StyleSheet.create({
    actionHolder: {
        flexDirection: 'row',
    },
    spaced: {
        marginStart: 16,
        marginEnd: 4,
    },
    parentHolder: {
        padding: 16,
        borderBottomWidth: 1,
        borderBottomColor: '#fff',
    },
    mainHolder: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
    },
    itemHolder: {
        flexDirection: 'column',
    },
    itemText: {
        color: '#1f1b1b',
    },
    largeText: {
        fontSize: 16,
        fontWeight: '500', 
    },
    smallText: {
        fontSize: 14,
    },
    blueText: {
        color: '#2b5fed',
    },
    fadeBlueText: {
        color: '#c7d2f2',
    }
});

export default TaskItem;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the add task modal if we add title &lt;strong&gt;Attend office meeting&lt;/strong&gt; and timestamp &lt;strong&gt;14-12-2021 9:30 AM&lt;/strong&gt; and press the check button then a new todo task will be created which will look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Eln5_l8f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82ny05ndhctw0ba2sbbu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Eln5_l8f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82ny05ndhctw0ba2sbbu.jpg" alt="Image description" width="720" height="146"&gt;&lt;/a&gt;&lt;br&gt;
On clicking the check button the task will be checked and look like following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PvDv0BET--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kee47v3usw0btusux125.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PvDv0BET--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kee47v3usw0btusux125.jpg" alt="Image description" width="720" height="148"&gt;&lt;/a&gt;&lt;br&gt;
On clicking the delete button a delete confirm modal will pop up. For this we need to create a js file named &lt;code&gt;ConfirmDelete&lt;/code&gt; in &lt;code&gt;src&lt;/code&gt; directory of the root folder and write following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { View, Text, StyleSheet, Modal, TouchableOpacity, TextInput } from 'react-native';
import Icon from 'react-native-vector-icons/AntDesign';
import { COLORS } from './App';

const ConfirmDelete = ({ isOpen, onClose, onDelete }) =&amp;gt; {
    return (
        &amp;lt;Modal
            visible={isOpen}
            onRequestClose={onClose}
            transparent={true}
        &amp;gt;
            &amp;lt;View style={styles.centeredView}&amp;gt;
                &amp;lt;View style={styles.modalView}&amp;gt;
                    &amp;lt;Text style={styles.content}&amp;gt;Are you sure you want to delete this task from your task list?&amp;lt;/Text&amp;gt;
                    &amp;lt;View style={styles.actionHolder}&amp;gt;
                        &amp;lt;TouchableOpacity onPress={onDelete}&amp;gt;
                            &amp;lt;Icon name="checkcircleo" size={30} color={COLORS.red} /&amp;gt;
                        &amp;lt;/TouchableOpacity&amp;gt;
                        &amp;lt;TouchableOpacity onPress={onClose}&amp;gt;
                            &amp;lt;Icon name="closecircleo" size={30} color={COLORS.blue} /&amp;gt;
                        &amp;lt;/TouchableOpacity&amp;gt;
                    &amp;lt;/View&amp;gt;
                &amp;lt;/View&amp;gt;
            &amp;lt;/View&amp;gt;
        &amp;lt;/Modal&amp;gt;
    );
};

const styles = StyleSheet.create({
    centeredView: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center"
      },
      modalView: {
        backgroundColor: "white",
        borderRadius: 20,
        padding: 20,
        alignItems: "center",
        shadowColor: "#000",
        shadowOffset: {
          width: 0,
          height: 2
        },
        shadowOpacity: 0.25,
        shadowRadius: 4,
        elevation: 5
      },
      content: {
          width: 200,
          textAlign: 'center',
          marginBottom: 10,
          color: '#1f1b1b',
          fontSize: 16,
      },
      actionHolder: {
          flexDirection: 'row',
          justifyContent: 'space-around',
          width: 100,
      }
});

export default ConfirmDelete;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will look like following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XlzKo-2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4ty3e6e1t4hsuvw54y6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XlzKo-2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4ty3e6e1t4hsuvw54y6.jpg" alt="Image description" width="546" height="358"&gt;&lt;/a&gt;&lt;br&gt;
On clicking the check button the task will be deleted and on clicking the cross button the delete action will be discarded.&lt;/p&gt;
&lt;h4&gt;
  
  
  App
&lt;/h4&gt;

&lt;p&gt;Now we are left with our final and main component. In this &lt;code&gt;App&lt;/code&gt; component we will render discussed three components along with &lt;a href="https://reactnative.dev/docs/flatlist"&gt;FlatList&lt;/a&gt; which will contain all the tasks. The wrapping component will be a &lt;a href="https://reactnative.dev/docs/safeareaview"&gt;SafeAreaView&lt;/a&gt;. At the very beginning the app will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kanzytwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tnqym9ysv84yr33k2sn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kanzytwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tnqym9ysv84yr33k2sn.jpg" alt="Image description" width="720" height="754"&gt;&lt;/a&gt;&lt;br&gt;
The code of &lt;code&gt;App&lt;/code&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import Icon from 'react-native-vector-icons/AntDesign';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {
  FlatList,
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  TouchableOpacity,
  useColorScheme,
  View,
} from 'react-native';

import {
  Colors,
  DebugInstructions,
  Header,
  LearnMoreLinks,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import TaskItem from './TaskItem';
import TaskModal from './TaskModal';
import ConfirmDelete from './ConfirmDelete';

export const COLORS = { white: '#fff', main: '#1f1b1b', blue: '#2b5fed', grey: '#f2f2f2', red: '#e3360b', fadeBlue: '#c7d2f2' };


const App = () =&amp;gt; {
  const [modalOpen, setModalOpen] = useState(false);
  const [confirmOpen, setConfirmOpen] = useState(false);
  const [deleteTaskId, setDeleteTaskId] = useState(0);
  const [tasks, setTasks] = useState([]);

  useEffect(() =&amp;gt; {
    if (tasks.length !== 0) {
      AsyncStorage.setItem('todos', JSON.stringify(tasks));
    }
  }, [tasks]);

  useEffect(() =&amp;gt; {
    fetchData();
  }, []);

  const fetchData = async () =&amp;gt; {
    try {
      const todos = await AsyncStorage.getItem('todos');
      if (todos != null) {
        setTasks(JSON.parse(todos));
      }
    } catch (error) {
      console.log(error);
    }
  };

  const openConfirmModal = (id) =&amp;gt; {
    setConfirmOpen(true);
    setDeleteTaskId(id);
  }

  const deleteTask = () =&amp;gt; {
    const newTasks = tasks.filter((task) =&amp;gt; task.id !== deleteTaskId);
    setTasks(newTasks);
    setDeleteTaskId(0);
    setConfirmOpen(false);
  };

  const checkTask = (id) =&amp;gt; {
    const newTasks = [...tasks];
    const _tasks = newTasks.map((task) =&amp;gt; (
      task.id === id ? {...task, completed: !task.completed} : task
    ));
    setTasks(_tasks);
  };

  const addTask = (title, date) =&amp;gt; {
    const task = {
      id: new Date().getTime(),
      title,
      time: date,
      completed: false,
    };
    setTasks(prevTasks =&amp;gt; ([task, ...prevTasks]));
    setModalOpen(false);
  };

  return (
    &amp;lt;SafeAreaView style={styles.background}&amp;gt;
      &amp;lt;TaskModal isOpen={modalOpen} onClose={() =&amp;gt; setModalOpen(false)} onSuccess={addTask} /&amp;gt;
      &amp;lt;ConfirmDelete isOpen={confirmOpen} onClose={() =&amp;gt; setConfirmOpen(false)} onDelete={deleteTask} /&amp;gt;
      &amp;lt;View style={styles.header}&amp;gt;
        &amp;lt;Text style={styles.headerText}&amp;gt;TODO APP&amp;lt;/Text&amp;gt;
        &amp;lt;TouchableOpacity onPress={() =&amp;gt; setModalOpen(true)}&amp;gt;
          &amp;lt;Icon name="pluscircle" size={30} color={COLORS.blue} /&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
      &amp;lt;/View&amp;gt;
      &amp;lt;FlatList
        data={tasks} 
        renderItem={({item}) =&amp;gt; ( &amp;lt;TaskItem task={item} onDelete={openConfirmModal} onCheck={checkTask} /&amp;gt;)} 
        /&amp;gt;
    &amp;lt;/SafeAreaView&amp;gt;
  );
};

const styles = StyleSheet.create({
  background: {
    flex: 1,
    backgroundColor: COLORS.grey,
  },
  header: {
    padding: 16,
    backgroundColor: COLORS.white,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
  },
  headerText: {
    fontSize: 20,
    fontWeight: 'bold',
    color: COLORS.main,
  },
  bottomView: {
    position: 'absolute',
    bottom: 20,
    right: 20,
  },
  addContainer: {
    width: 50,
    height: 50,
    borderRadius: 25,
    backgroundColor: COLORS.blue,
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  addIcon: {
    fontSize: 32,
    color: COLORS.white,
  },
});

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On clicking the plus button in the top right corner then add task modal will be opned i.e. &lt;code&gt;&amp;lt;TaskModal isOpen={modalOpen} onClose={() =&amp;gt; setModalOpen(false)} onSuccess={addTask} /&amp;gt;&lt;/code&gt; this will be rendered. Here two functions are passed as props to the modal component which indicates &lt;a href="https://reactjs.org/docs/lifting-state-up.html"&gt;lifting the state up&lt;/a&gt;. If we have a look at the &lt;code&gt;addTask&lt;/code&gt; method which will be called when the user will add a task and press the check button in &lt;code&gt;TaskModal&lt;/code&gt; component, it takes title and time from user input, creates a unique id and by default false for then completed field. Then the task will be prepended to the tasks state. The tasks are being rendered in a &lt;code&gt;flatlist&lt;/code&gt; which takes two props &lt;code&gt;data&lt;/code&gt; as array of data to display and &lt;code&gt;renderItem&lt;/code&gt; which takes a method that tells how to display each row.&lt;/p&gt;

&lt;p&gt;The final task is to save the todo tasks in device. We are using &lt;code&gt;Async Storage&lt;/code&gt; for this purpose. We have used two &lt;code&gt;useState&lt;/code&gt; hook one will be invoked when the app component is mounted then we will retrieve the data in form of string from the storage. The other will be invoked whenever the tasks state changes.&lt;/p&gt;

&lt;p&gt;To run the project in an android device we will use the following command after connecting our android device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native run-android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding four tasks our app should look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BY-L-4cA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfxyppm0j0urgj58orfk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BY-L-4cA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfxyppm0j0urgj58orfk.jpg" alt="Image description" width="720" height="832"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thus we have built a simple Todo App with react native. The project codebase can be found &lt;a href="https://github.com/alim1496/todo-app-react-native"&gt;here&lt;/a&gt;. Feel free to share your thoughts.&lt;/p&gt;

&lt;p&gt;Happy coding 😀😀😀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>reactnative</category>
      <category>beginners</category>
      <category>mobile</category>
    </item>
    <item>
      <title>React with Typescript</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Tue, 19 Oct 2021 07:58:29 +0000</pubDate>
      <link>https://dev.to/alim1496/react-with-typescript-1gp5</link>
      <guid>https://dev.to/alim1496/react-with-typescript-1gp5</guid>
      <description>&lt;p&gt;At present react js has been a very popular library to build beautiful and scalable user interfaces. Today I would like to build a demo react project with typescript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project setup
&lt;/h3&gt;

&lt;p&gt;We would like to use the &lt;code&gt;create-react-app&lt;/code&gt; environment built by facebook developer team to create our project. Our project will have a form to add favorite tv series and show the list. It will be a single page website. At first we will run the following command&lt;/p&gt;

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

npx create-react-app --template typescript fav-tv-series
cd fav-tv-series
npm run start


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

&lt;/div&gt;

&lt;p&gt;The first command will create a react app named &lt;code&gt;fav-tv-series&lt;/code&gt; having typescript template. Then after going to that directory we will run the third command which will create a process running on port number 3000 and look like this&lt;br&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%2Fbkdawy8q5lugx5uiskch.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkdawy8q5lugx5uiskch.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Interface
&lt;/h3&gt;

&lt;p&gt;In typescript our main concern will be defining strict type to every data that will be used. &lt;code&gt;interface&lt;/code&gt; is a pretty good way to define a data and use that as a type in ts. In the &lt;code&gt;src&lt;/code&gt; folder of the root folder we will create a directory named &lt;code&gt;interfaces&lt;/code&gt; and inside it we will create a file named &lt;code&gt;SeriesProps.tsx&lt;/code&gt;. Here we will create an interface named &lt;code&gt;SeriesProps&lt;/code&gt; like following&lt;/p&gt;

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

export interface SeriesProps {
    seriesList: {
        name: string;
        imdb: number;
        cover: string;
        seasons: number;
        genre: string;
      }[]
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Updating App
&lt;/h3&gt;

&lt;p&gt;At first we will update the existing &lt;code&gt;App.tsx&lt;/code&gt; file by removing the existing code. Our single page web application will contain two components. One is a form where a user will give necessary inputs about his favourite series and another is a list containing those serieses. The data will be stored in a state named &lt;code&gt;seriesList&lt;/code&gt; and updated with the help of &lt;code&gt;setSeriesList&lt;/code&gt; method.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React, { useState } from 'react';
import { SeriesProps } from './interfaces/SeriesProps';
import './App.css';
import List from './components/List';
import Form from './components/Form';

function App() {
  const [seriesList, setSeriesList] = useState&amp;lt;SeriesProps["seriesList"]&amp;gt;([]);

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;My Favourite TV Series&amp;lt;/h1&amp;gt;
      &amp;lt;Form seriesList={seriesList} setSeriesList={setSeriesList} /&amp;gt;
      &amp;lt;List seriesList={seriesList} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;



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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Creating List
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;src&lt;/code&gt; directory of root folder we will create a directory named &lt;code&gt;components&lt;/code&gt; and there we will create the &lt;code&gt;List.tsx&lt;/code&gt; file. Our component will look like below&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React, { FC } from "react";
import { SeriesProps } from "../interfaces/SeriesProps";

const List:FC&amp;lt;SeriesProps&amp;gt; = ({seriesList}) =&amp;gt; (
    &amp;lt;div className="series-list"&amp;gt;
        {seriesList.map((series) =&amp;gt; (
            &amp;lt;div className="series-item"&amp;gt;
                &amp;lt;img src={series.cover} alt="Series-cover" /&amp;gt;
                &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;{series.name}&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;
                &amp;lt;p&amp;gt;{series.genre}&amp;lt;/p&amp;gt; 
                &amp;lt;p&amp;gt;{series.seasons} seasons&amp;lt;/p&amp;gt;
                &amp;lt;p&amp;gt;★★★★★ {series.imdb}&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
        ))}
    &amp;lt;/div&amp;gt;
);

export default List;


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

&lt;/div&gt;

&lt;p&gt;Here we can have a look at &lt;code&gt;FC&lt;/code&gt; which means Functional Component and it guides us with types. Here we have passed &lt;code&gt;SeriesProps&lt;/code&gt; as props and finally we have used &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;map&lt;/a&gt; function to render tv series list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Form
&lt;/h3&gt;

&lt;p&gt;Now we are left with creating the form element where we will give necessary inputs. Here we will use &lt;a href="https://reactjs.org/docs/forms.html" rel="noopener noreferrer"&gt;controlled components&lt;/a&gt; to build input elements. For simplicity we will create a state object where the necessary input values will be kept. We will use &lt;code&gt;useState&lt;/code&gt; for this.&lt;/p&gt;

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

const [input, setInput] = useState({
        name: "",
        genre: "",
        cover: "",
        imdb: 0,
        seasons: 0
    });


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

&lt;/div&gt;

&lt;p&gt;Now we will render the components. Here we will have five input fields having three text and two number type inputs.&lt;/p&gt;

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

return (
        &amp;lt;div className="form-container"&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="name"&amp;gt;Name&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" name="name" id="name" value={input.name} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="genre"&amp;gt;Genre&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" name="genre" id="genre" value={input.genre} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="cover"&amp;gt;Cover Link&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" name="cover" id="cover" value={input.cover} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="imdb"&amp;gt;IMDB Rating&amp;lt;/label&amp;gt;
                &amp;lt;input type="number" name="imdb" id="imdb" value={input.imdb} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="seasons"&amp;gt;Total Seasons&amp;lt;/label&amp;gt;
                &amp;lt;input type="number" name="seasons" id="seasons" value={input.seasons} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;button type="button" onClick={handleClick}&amp;gt;Add Series&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    );


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

&lt;/div&gt;

&lt;p&gt;Here we can see that the value of each input field will be stored to the state object. We can see that all input fields have a function named &lt;code&gt;handleChange&lt;/code&gt; which will be invoked as an &lt;code&gt;onChange&lt;/code&gt; listener and the button has an &lt;code&gt;onClick&lt;/code&gt; listener named &lt;code&gt;handleClick&lt;/code&gt;. We will implement these two methods now. The handleChange method is quite straight forward. Here we destructure the &lt;code&gt;input&lt;/code&gt; state and update the particular state element needed to be updated. One important thing to notice is that the type of event we are passing to that function. Here the type is &lt;code&gt;ChangeEvent&amp;lt;HTMLInputElement&amp;gt;&lt;/code&gt; which means our handleChange method will only accept html input element change event. One thing to notice is that we have kept the name and value of each input same for which we can use &lt;code&gt;[name]: value&lt;/code&gt; statement.&lt;/p&gt;

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

const handleChange = (e: ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) =&amp;gt; {
        const { value, name } = e.target;
        setInput({
            ...input,
            [name]: value
        });
    };


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

&lt;/div&gt;

&lt;p&gt;Before implementing the handleClick method we need to define a props which will be used to update and store the series list. As we have already defined a state in our &lt;code&gt;App.tsx&lt;/code&gt; using &lt;code&gt;useState&lt;/code&gt;, we need to pass those in this &lt;code&gt;Form&lt;/code&gt; component and use in our handleClick method. Lets have a look at the following interface.&lt;/p&gt;

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

interface Props {
    seriesList: SeriesProps["seriesList"],
    setSeriesList: Dispatch&amp;lt;SetStateAction&amp;lt;SeriesProps["seriesList"]&amp;gt;&amp;gt;
}


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

&lt;/div&gt;

&lt;p&gt;Now we will implement our handleClick method.&lt;/p&gt;

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

const handleClick = (e: MouseEvent&amp;lt;HTMLButtonElement&amp;gt;) =&amp;gt; {
        const { name, genre, cover, imdb, seasons } = input;
        if(!name &amp;amp;&amp;amp; !genre &amp;amp;&amp;amp; !cover &amp;amp;&amp;amp; !imdb &amp;amp;&amp;amp; !seasons) return;
        const series = { name, genre, cover, imdb, seasons };
        setSeriesList([...seriesList, series]);
        setInput({
            name: "",
            genre: "",
            cover: "",
            imdb: 0,
            seasons: 0
        });
    };


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

&lt;/div&gt;

&lt;p&gt;Our method only accepts a mouse event coming from an html button element. At first we have destructured our input state. Then we have checked whether any input field is empty. If so then we won't move further. Otherwise we have created a series object and appended it to the series list. After that we have made all fields empty. So our complete &lt;code&gt;Form.tsx&lt;/code&gt; looks like this&lt;/p&gt;

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

import React, { FC, useState, ChangeEvent, MouseEvent, Dispatch, SetStateAction } from "react";
import { SeriesProps } from "../interfaces/SeriesProps";

interface Props {
    seriesList: SeriesProps["seriesList"],
    setSeriesList: Dispatch&amp;lt;SetStateAction&amp;lt;SeriesProps["seriesList"]&amp;gt;&amp;gt;
}

const Form: FC&amp;lt;Props&amp;gt; = ({ seriesList, setSeriesList }) =&amp;gt; {

    const [input, setInput] = useState({
        name: "",
        genre: "",
        cover: "",
        imdb: 0,
        seasons: 0
    });

    const handleChange = (e: ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) =&amp;gt; {
        const { value, name } = e.target;
        setInput({
            ...input,
            [name]: value
        });
    };

    const handleClick = (e: MouseEvent&amp;lt;HTMLButtonElement&amp;gt;) =&amp;gt; {
        const { name, genre, cover, imdb, seasons } = input;
        const series = { name, genre, cover, imdb, seasons };
        if(!name &amp;amp;&amp;amp; !genre &amp;amp;&amp;amp; !cover &amp;amp;&amp;amp; !imdb &amp;amp;&amp;amp; !seasons) return;
        setSeriesList([...seriesList, series]);
        setInput({
            name: "",
            genre: "",
            cover: "",
            imdb: 0,
            seasons: 0
        });
    };

    return (
        &amp;lt;div className="form-container"&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="name"&amp;gt;Name&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" name="name" id="name" value={input.name} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="genre"&amp;gt;Genre&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" name="genre" id="genre" value={input.genre} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="cover"&amp;gt;Cover Link&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" name="cover" id="cover" value={input.cover} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="imdb"&amp;gt;IMDB Rating&amp;lt;/label&amp;gt;
                &amp;lt;input type="number" name="imdb" id="imdb" value={input.imdb} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="form-div"&amp;gt;
                &amp;lt;label htmlFor="seasons"&amp;gt;Total Seasons&amp;lt;/label&amp;gt;
                &amp;lt;input type="number" name="seasons" id="seasons" value={input.seasons} onChange={handleChange} /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;button type="button" onClick={handleClick}&amp;gt;Add Series&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    );
};

export default Form;


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

&lt;/div&gt;

&lt;p&gt;Now we are only left with adding css styles. For simplicity we have made change only in the &lt;code&gt;App.css&lt;/code&gt; files which looks like&lt;/p&gt;

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

.form-container {
  width: 400px;
  margin: auto;
}

h1 {
  text-align: center;
}

.form-div {
  margin-bottom: 10px;
}

input[type='text'],
input[type='number'] {
  float: right;
  width: 70%;
  padding: 3px;
}

input[type='checkbox'] {
  margin-left: 110px;
}

button {
  margin: 10px 0;
  padding: 10px 0;
  width: 100%;
  cursor: pointer;
  font-weight: bold;
  text-transform: uppercase;
  font-size: 16px;
}

p {
  line-height: 5px;
}

.series-list {
  display: flex;
  flex-flow: wrap;
  margin: 50px auto;
  width: 90%;
}

.series-item {
  padding: 0 20px 20px 0;
  width: 300px;
}


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

&lt;/div&gt;

&lt;p&gt;After we are finished with all coding, we can have a look at our browser's &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&gt; link. After adding some data it should look like following&lt;br&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%2Fj6tbsdnr8ux7kkfdjjj9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6tbsdnr8ux7kkfdjjj9.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The whole project is in github. You can very well have a look in it &lt;a href="https://github.com/alim1496/react-with-typescript" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy Coding 😀😀😀😀😀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/alim1496" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.buymeacoffee.com%2Fbuttons%2Fdefault-orange.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>typescript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Its time to learn Typescript</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Tue, 12 Oct 2021 05:57:41 +0000</pubDate>
      <link>https://dev.to/alim1496/its-time-to-learn-typescript-2a11</link>
      <guid>https://dev.to/alim1496/its-time-to-learn-typescript-2a11</guid>
      <description>&lt;p&gt;Javascript has been a very popular language. From being a scripting language that used to run in a browser to having node runtime environment has taken it to another level. At present we can build scalable website with js libraries like &lt;code&gt;react&lt;/code&gt; and also build cross platform mobile applications with &lt;code&gt;react-native&lt;/code&gt;. In the backend we can develop highly scalable api with &lt;code&gt;express&lt;/code&gt; and so on. That means we can do everything with javascript. &lt;/p&gt;

&lt;p&gt;Despite of being very popular javascript has got some drawbacks. In order to overcome these Microsoft introduced an open source language named Typescript which is a superset of javascript. It has got a good number of benefits over javascript. Lets point out those in brief here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As ts is a superset of js, we can easily start learning ts in an existing js project. We can start by simply replacing &lt;code&gt;.js&lt;/code&gt; extions to &lt;code&gt;.ts&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The main purpose of ts is &lt;code&gt;Type Safety&lt;/code&gt; which means we must assign types to a data. This has made the life of every js developer easier by thousand times. Javascript has &lt;a href="https://dev.to/alim1496/some-interesting-facts-about-javascript-1apg"&gt;many weird functionalities&lt;/a&gt; and almost all of these can be eradicated by assigning scrict type to each data.&lt;/li&gt;
&lt;li&gt;Typescript supports classes, inheritances and interfaces. This feature ease all object oriented programmers a lot.&lt;/li&gt;
&lt;li&gt;We can detect type errors in compile time with the help of ts. In larger projects this saves a lot of time and work. IDEs like &lt;strong&gt;VS Code&lt;/strong&gt;, &lt;strong&gt;atom&lt;/strong&gt; etc have excellent support of ts.&lt;/li&gt;
&lt;li&gt;We can use ES6 and beyond features in ts and compiler will convert it to ES5 or our required version. This means all the latest features of js are fully supported by ts.&lt;/li&gt;
&lt;li&gt;Day by day the popularity of ts is increasing. Tech giants are using it and the number of contributors is also increasing. This yields a large community to get support from.&lt;/li&gt;
&lt;li&gt;Another very big advantage of ts is that we can use it with almost all popular js frameworks and libraries. We can use it with react, react-native and also in node js development.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So without any hesitation and delay we should learn this beautiful language and bring our skillset to another level.&lt;/p&gt;

&lt;p&gt;Happy Learning!!!!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>An overview of TypeORM</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Mon, 04 Oct 2021 20:13:24 +0000</pubDate>
      <link>https://dev.to/alim1496/an-overview-of-typeorm-1cp2</link>
      <guid>https://dev.to/alim1496/an-overview-of-typeorm-1cp2</guid>
      <description>&lt;p&gt;One of the most popular Object Relational Mapping or ORM is TypeORM. At first lets talk a bit about ORM. As the name suggests, ORM is a programming technique that relates or maps object oriented model to relational database model. In a nutshell, you can craete or query data from a relational database using object oriented way with ORM. Almost all of the object oriented programming languages support ORM and their frameworks use ORM e.g. &lt;code&gt;django&lt;/code&gt; in python, &lt;code&gt;laravel&lt;/code&gt; in php, &lt;code&gt;nestjs&lt;/code&gt; in node etc. ORM helps us in many ways. It helps us by revoking the direct use of writing sql queries. &lt;/p&gt;

&lt;p&gt;Some of the main benefits of using ORM includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It speeds up the development by eliminating repetitive usage of SQL code&lt;/li&gt;
&lt;li&gt;It reduces development time a lot&lt;/li&gt;
&lt;li&gt;It overcomes all the vendor spicific SQL differences because it knows how to convert to vendor SQL code&lt;/li&gt;
&lt;li&gt;It can be used with both relational databases like mysql, oracle, postgresql, maria db and nosql like mongodb&lt;/li&gt;
&lt;li&gt;It abstracts things like caching and indexing&lt;/li&gt;
&lt;li&gt;It can catch general issues like input validations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now lets go to our main topic &lt;code&gt;TypeORM&lt;/code&gt;. The official documentation says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;p&gt;Lets find out some basic features of typeORM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;entities and columns&lt;/li&gt;
&lt;li&gt;database-specific column types&lt;/li&gt;
&lt;li&gt;entity manager&lt;/li&gt;
&lt;li&gt;repositories and custom repositories&lt;/li&gt;
&lt;li&gt;clean object relational model&lt;/li&gt;
&lt;li&gt;associations (relations)&lt;/li&gt;
&lt;li&gt;eager and lazy relations&lt;/li&gt;
&lt;li&gt;uni-directional, bi-directional and self-referenced relations&lt;/li&gt;
&lt;li&gt;supports multiple inheritance patterns&lt;/li&gt;
&lt;li&gt;cascades&lt;/li&gt;
&lt;li&gt;indices&lt;/li&gt;
&lt;li&gt;transactions&lt;/li&gt;
&lt;li&gt;migrations and automatic migrations generation&lt;/li&gt;
&lt;li&gt;connection pooling&lt;/li&gt;
&lt;li&gt;replication&lt;/li&gt;
&lt;li&gt;using multiple database connections&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More features can be found in the &lt;a href="https://typeorm.io/"&gt;official documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;We can install TypeORM from &lt;code&gt;npm&lt;/code&gt; registry very easily with the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g typeorm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;i&lt;/code&gt; is the alias for &lt;code&gt;install&lt;/code&gt; and &lt;code&gt;-g&lt;/code&gt; means we are installing it globally in our machine. In order to use it in a project we need to omit &lt;code&gt;-g&lt;/code&gt;. In addition we can install two optional modules named &lt;code&gt;reflect-metadata&lt;/code&gt; and &lt;code&gt;@types/node&lt;/code&gt; as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i reflect-metadata @types/node 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now according to the database you would like connect, just install its module. Suppose I would like to connect to mysql db so I will do the following&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Connection
&lt;/h3&gt;

&lt;p&gt;In order to interact to a database we need to create connection of TypeORM with that particular database. This connection can be created in several ways. One way to achieve this is using &lt;code&gt;createConnection&lt;/code&gt; method. Let us suppose that we would like to connect to a mysql db which can be achieved in the following way&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createConnection } from "typeorm";

const connection = await createConnection({
    type: "mysql",
    host: "localhost",
    port: 3306,
    username: "admin",
    password: "12345",
    database: "blog-world"
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can connect with multiple databases using &lt;code&gt;createConnections&lt;/code&gt; method which takes an array of object as input where we can use our different databases.&lt;/p&gt;

&lt;p&gt;Another way of connecting to a database is to use &lt;code&gt;ormconfig.json&lt;/code&gt; file where all those object key value prperties will be stored as json format and exported when needed. I personally prefer this way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Entity
&lt;/h3&gt;

&lt;p&gt;Entity is a class which will represent a table of our database or document in case of mongodb. This means all the properties of an entity get converted to columns of a table. Entity supports all basic types like &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;, &lt;code&gt;array&lt;/code&gt; and even an object of other entity. Lets build a &lt;code&gt;writer&lt;/code&gt; entity for our &lt;code&gt;blog-world&lt;/code&gt; database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";

@Entity() 
export class Writer {
    @PrimaryGeneratedColumn() 
    id: number;

    @Column()  
    name: string;

    @Column() 
    phone: string;

    @Column() 
    isFeatured: boolean;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here each property tagged with &lt;code&gt;@Column&lt;/code&gt; represents a column in db table. There can be different types of columns based on its nature. A model must have a Primary Column which will represent that row. If it is auto incremented then &lt;code&gt;@PrimaryGeneratedColumn&lt;/code&gt; needs to be used. We can also use &lt;code&gt;@PrimaryGeneratedColumn("uuid")&lt;/code&gt; to generate unique id everytime. In that case type of id will be string instead of number. There can be other columns like &lt;code&gt;@CreateDateColumn&lt;/code&gt; which automatically sets entity's insertion date. Based on different databases &lt;code&gt;Spatial Columns&lt;/code&gt; can be used too. We can use &lt;code&gt;enum&lt;/code&gt; as type of a column. Let us add a column named gender to our above entity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export enum Gender {
    MALE = "male",
    FEMALE = "female",
    OTHER = "other" 
}

@Entity 
export class Writer {
    // other properties will remain same

    @Column({
        type: "enum",
        enum: Gender
    })
    gender: Gender;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Relations
&lt;/h3&gt;

&lt;p&gt;In order to add reference of another entity to an entity we need to use relations. Relations can be &lt;code&gt;one-to-one&lt;/code&gt;, &lt;code&gt;one-to-many&lt;/code&gt;, &lt;code&gt;many-to-one&lt;/code&gt; and &lt;code&gt;many-to-many&lt;/code&gt;. TypeORM has support for all of these relations using &lt;code&gt;@OneToOne&lt;/code&gt;, &lt;code&gt;@OneToMany&lt;/code&gt;, &lt;code&gt;@ManyToOne&lt;/code&gt; and &lt;code&gt;@ManyToMany&lt;/code&gt; respectively. Lets see its implementation with code. At first we create an &lt;code&gt;Avatar&lt;/code&gt; entity. Here each writer can have a single avatar and we would like to assign one avatar to a single writer which represents a &lt;code&gt;one-to-one&lt;/code&gt; relation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";

@Entity()
export class Avatar {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    url: string;

    @Column()
    text: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in our Writer entity we need to add this Avatar property along with necessary relation decorator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, OneToOne, JoinColumn} from "typeorm";
import {Avatar} from "./Avatar";

@Entity 
export class Writer {
    // other properties will remain same

    @OneToOne(() =&amp;gt; Avatar)
    @JoinColumn()  
    avatar: Avatar;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to establish &lt;code&gt;one-to-many&lt;/code&gt; and &lt;code&gt;many-to-one&lt;/code&gt; relations we will create a new entity named Blog. A writer can have many blogs but one blog will be written by one writer only which satisfies our requirement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, PrimaryGeneratedColumn, Column, ManyToOne} from "typeorm";
import {Writer} from "./Writer";

@Entity()
export class Blog {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    title: string;

    @Column()
    cover: string;

    @Column() 
    content: string;

    @ManyToOne(() =&amp;gt; Writer, writer =&amp;gt; writer.blogs)
    writer: Writer;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we update Writer entity as follows to establish &lt;code&gt;one-to-many&lt;/code&gt; relation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, OneToMany} from "typeorm";
import {Blog} from "./Blog";

@Entity 
export class Writer {
    // other properties will remain same

    @OneToMany(() =&amp;gt; Blog, blog =&amp;gt; blog.writer)  
    blogs: Blog[];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are left with &lt;code&gt;many-to-many&lt;/code&gt; relation which can be established by adding another entity named Category. A blog can have multiple categories and a category can be assigned to multiple blogs too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";

@Entity()
export class Category {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will update Writer entity as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Entity, ManyToMany, JoinTable} from "typeorm";
import {Category} from "./Category";

@Entity 
export class Writer {
    // other properties will remain same

    @ManyToMany(() =&amp;gt; Category)  
    @JoinTable()
    categories: Category[];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@JoinTable()&lt;/code&gt; is required for &lt;code&gt;@ManyToMany&lt;/code&gt; relations. We need to put &lt;code&gt;@JoinTable&lt;/code&gt; on one (owning) side of relation.&lt;/p&gt;

&lt;h3&gt;
  
  
  CRUD Operations
&lt;/h3&gt;

&lt;p&gt;In TypeORM we can perform CRUD operations using &lt;strong&gt;EntityManager&lt;/strong&gt;, &lt;strong&gt;Repository&lt;/strong&gt; and &lt;strong&gt;Query Builder&lt;/strong&gt;. EntityManager and Repository are quite similar in syntax while performing necessary operations. The difference is that an Entity Manager handles all entities, while Repository handles a single entity which means that when using an Entity Manager we need to specify the Entity we are working with for each method call. Let us explain it with an example. Suppose we would like to fetch a Writer with a id given.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {getManager} from "typeorm";
import {Writer} from "./entity/Writer";

// using entity manager
const entityManager = getManager();
const writer = await entityManager.findOne(Writer, 1);

// using repository
const writerRepository = getRepository(Writer); 
const writer = await writerRepository.findOne(1);

// now lets update writer's name
writer.name = "Zlatan Ibrahimovic";

await entityManager.save(writer);
await writerRepository.save(writer);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple task performed but other tasks like joining and complex operations can also be performed with the help of both entity manager and repository. Now lets talk a bit about query builder. According to the documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;QueryBuilder is one of the most powerful features of TypeORM - it allows you to build SQL queries using elegant and convenient syntax, execute them and get automatically transformed entities.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So we can have an idea that how powerful query builder is. Its time for some coding examples again. We perform the above query i.e. find out the first writer using query builder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const firstWriter = await connection
    .getRepository(Writer)
    .createQueryBuilder("writer")
    .where("writer.id = :id", { id: 1 })
    .getOne();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also perform join queries using query builder very easily. Almost all sql queries we perform can be done in TypeORM but in many cases like very complex queries, it can be difficult.&lt;/p&gt;

&lt;p&gt;In this post I have tried to discuss the basic topics of TypeORM briefly. Advanced topics like &lt;strong&gt;Migration&lt;/strong&gt;, &lt;strong&gt;Indices&lt;/strong&gt;, &lt;strong&gt;Transactions&lt;/strong&gt;, &lt;strong&gt;Listeners&lt;/strong&gt;, &lt;strong&gt;Subscribers&lt;/strong&gt; etc have not been discussed here. &lt;a href="https://typeorm.io/"&gt;The official document&lt;/a&gt; is very elaborative and nicely explained with lots of examples. You are highly encouraged to have a look at it.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>database</category>
      <category>beginners</category>
      <category>orm</category>
    </item>
    <item>
      <title>Some interesting facts about javascript</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Wed, 28 Jul 2021 10:23:17 +0000</pubDate>
      <link>https://dev.to/alim1496/some-interesting-facts-about-javascript-1apg</link>
      <guid>https://dev.to/alim1496/some-interesting-facts-about-javascript-1apg</guid>
      <description>&lt;p&gt;We all know that javascript is one of the most popular programming languages now-a-days. Javascript is a very strange language in deed. One reason is it has got syntax similar to &lt;code&gt;C&lt;/code&gt;, &lt;code&gt;C++&lt;/code&gt; and &lt;code&gt;Java&lt;/code&gt; but semantically this is not similar which makes developers confused. Another weird thing to mention is its &lt;code&gt;prototype inheritance&lt;/code&gt; which can be achieved similarly using es6 class. Let us discuss some interesting facts about this very language.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Many programming languages use semi colon at the end of a statement. Javascript does so but you can also use semi colon at the beginning of a statement.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;;var a = 2
;console.log(a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code snippet will display 2 in the console without throwing any error!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In javascript you can add a number with a string. The result will be a string without any error.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var b = 5 + '9';
console.log(b);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code snippet will display "59" in the console!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In javascript the comparison operators act really weird in many cases. Lets see some examples:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NaN == NaN // -&amp;gt; false
NaN === NaN // -&amp;gt; false
[] == true // -&amp;gt; false
[] === true // -&amp;gt; false
[] == false // -&amp;gt; true
[] === false // -&amp;gt; false
{} == {} // -&amp;gt; false
{} === {} // -&amp;gt; false
{} &amp;gt;= {} // -&amp;gt; true
{} &amp;gt; {} // -&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Things got a bit messed up, right? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Javascript has a nice feature named &lt;strong&gt;Immediately Invoked Function Expression&lt;/strong&gt; where a function can be executed just after it has been defined without being called explicitly.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(function() {
  console.log('works well');
})();

function() {
  console.log('generates syntax error');
}();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the first function works fine as it is a &lt;strong&gt;IIFE&lt;/strong&gt; but the second one generates &lt;code&gt;SyntaxError&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In javascript the difference in parenthesis position can make two functions different.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function f1() {
   return
   {
      grade: 'A+'
   }
}
function f2() {
   return {
      grade: 'A+'
   }
}
typeof f1() === typeof f2(); // -&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In javascript &lt;code&gt;undefined&lt;/code&gt; is not a reserved word although it a has a special meaning. This is the only way to determine whether a variable is undefined but the following code snippet looks quite weird.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;undefined = "I am defined now!";
var c;
console.log(c == undefined); // -&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Avoid using inline css styles</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Tue, 20 Jul 2021 11:18:05 +0000</pubDate>
      <link>https://dev.to/alim1496/avoid-using-inline-css-styles-5b6p</link>
      <guid>https://dev.to/alim1496/avoid-using-inline-css-styles-5b6p</guid>
      <description>&lt;p&gt;While developing a website we can add styles in various ways. We can write css styles in a css file and import it in html file, write in &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag of &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; or write inline style within each element of the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;. I would like to share some problems with inline styling.&lt;/p&gt;

&lt;h4&gt;
  
  
  Lack of reusability
&lt;/h4&gt;

&lt;p&gt;Using the same css class multiple times should be one of the major aim in adding style to a website. As our project gets larger if we do not use same class for same type of styles, there is a good possibility of writing redundant styles which unnecessarily makes the project larger. If we write inline style, we can never use it multiple times which breaks the &lt;code&gt;DRY&lt;/code&gt; principle.&lt;/p&gt;

&lt;h4&gt;
  
  
  Inability to use css selectors
&lt;/h4&gt;

&lt;p&gt;We cannot use css selectors while writing inline styles. Selectors like &lt;code&gt;before&lt;/code&gt;, &lt;code&gt;after&lt;/code&gt;, &lt;code&gt;hover&lt;/code&gt;, &lt;code&gt;focus&lt;/code&gt; etc are very much useful for styling which we simply cannot use in inline styling.&lt;/p&gt;

&lt;h4&gt;
  
  
  Difficulty in code readability
&lt;/h4&gt;

&lt;p&gt;In a large html file there will be a lot of elements. If in addition there is inline styles then it becomes very much difficult for someone to read and understand that html code. Inline style hampers code readability a lot.&lt;/p&gt;

&lt;h4&gt;
  
  
  Lack of writing media queries
&lt;/h4&gt;

&lt;p&gt;Web developers now-a-days must make the website responsive. In order to make the site responsive writing &lt;code&gt;media queries&lt;/code&gt; is a must where different css rules are applied based on screen width. Inline style does never allow us do that.&lt;/p&gt;

&lt;h4&gt;
  
  
  Maintenance problem
&lt;/h4&gt;

&lt;p&gt;Suppose you are dealing with an html file containing inline css styles. In that case you have to face difficulties in debugging and adding new codes which can be recovered by simply going to the element class in css stylesheet very easily.&lt;/p&gt;

&lt;h4&gt;
  
  
  No scope of caching
&lt;/h4&gt;

&lt;p&gt;Browsers cache external stylesheets so that those can be loaded easily for further rendering but inline styles cannot be cached since those are with the html code segment. So everytime you visit a webpage inline styles need to be loaded with html.&lt;/p&gt;

&lt;p&gt;All of these issues are seen while using inline styles. If the project is larger, using inline styles is not a good idea. Inline styles can load css faster which is negligible. We can use inline styles in smaller projects though.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>VS Code Thunder Client: An awesome alternative to Postman</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Sun, 04 Jul 2021 20:20:50 +0000</pubDate>
      <link>https://dev.to/alim1496/vs-code-thunder-client-an-awesome-alternative-to-postman-1a02</link>
      <guid>https://dev.to/alim1496/vs-code-thunder-client-an-awesome-alternative-to-postman-1a02</guid>
      <description>&lt;p&gt;Suppose you are working on the front end of a project. You are using a &lt;code&gt;VS Code&lt;/code&gt; editor. You have successfully designed the user interfaces and now its time to bind data from back end api. You are given a collection of rest api endpoints. So at first you want to test these. What if you could test these in the editor without opening another app like &lt;code&gt;Postman&lt;/code&gt;? This is absolutely possible now if your &lt;code&gt;VS Code&lt;/code&gt; is having the latest version (1.57).&lt;/p&gt;

&lt;p&gt;You can test the endpoints using a &lt;code&gt;VS Code&lt;/code&gt; extension named &lt;strong&gt;Thunder Client&lt;/strong&gt; which is a lightweight rest client. You can have it from its official &lt;a href="https://www.thunderclient.io/"&gt;website&lt;/a&gt; or from the extensions section of &lt;code&gt;VS Code&lt;/code&gt;. Once you have added the extension to your editor and hit the &lt;code&gt;New Request&lt;/code&gt; button, it should look like following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CDUnv3c5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-image-container.s3.ap-southeast-1.amazonaws.com/thunder.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CDUnv3c5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://public-image-container.s3.ap-southeast-1.amazonaws.com/thunder.png" alt="Alt text of image" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see initially an endpoint is given and if you send a &lt;code&gt;GET&lt;/code&gt; request to it, you will get the initial info about &lt;code&gt;Thunder Client&lt;/code&gt; as json response. Now lets discuss the features of this very extension:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All the major http requests like &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PATCH&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;, &lt;code&gt;OPTIONS&lt;/code&gt;, &lt;code&gt;HEAD&lt;/code&gt; can be sent.&lt;/li&gt;
&lt;li&gt;Query parameters can be added like key value pair or if you add these in the url then those can be seen automatically in the section as pairs.&lt;/li&gt;
&lt;li&gt;There are separate sections to add &lt;code&gt;Basic Auth&lt;/code&gt;, &lt;code&gt;Bearer Token&lt;/code&gt; and &lt;code&gt;OAuth2.0&lt;/code&gt; which is pretty cool.&lt;/li&gt;
&lt;li&gt;A separate section for adding necessary http headers as key value pairs.&lt;/li&gt;
&lt;li&gt;A body section where data can be sent using &lt;code&gt;json&lt;/code&gt;, &lt;code&gt;xml&lt;/code&gt;, &lt;code&gt;text&lt;/code&gt;, &lt;code&gt;form&lt;/code&gt;, &lt;code&gt;form-encoded&lt;/code&gt;, &lt;code&gt;graphql&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Another cool feature call &lt;code&gt;Tests&lt;/code&gt; where you can add your necessary conditions for testing like you want the response code to be equal to 200 or you want the response body to contain a fixed value.&lt;/li&gt;
&lt;li&gt;In the response section you can see the &lt;code&gt;headers&lt;/code&gt;, &lt;code&gt;cookies&lt;/code&gt; and &lt;code&gt;test results&lt;/code&gt; along with the response. The response being marked up with colors looks beautiful along with &lt;code&gt;status&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;time&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;There are some demo codes to make request in different languages along with third party libraries.&lt;/li&gt;
&lt;li&gt;You can creat a collection, add an activity to a collection, import collections and even import postman collections.&lt;/li&gt;
&lt;li&gt;You can also create environment, define secrets like tokens and use those in sending requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All these features together make &lt;code&gt;Thunder Client&lt;/code&gt; a great choice to test restful api endpoints. If you are a newbie or work in a project that is not very complex or don't want to run extra processes to test api then you should definitely give it a try.&lt;/p&gt;

</description>
      <category>api</category>
      <category>postman</category>
      <category>restful</category>
      <category>testing</category>
    </item>
    <item>
      <title>Managing external libraries in AWS lambda functions</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Sat, 03 Jul 2021 18:01:17 +0000</pubDate>
      <link>https://dev.to/alim1496/managing-external-libraries-in-aws-lambda-functions-1g0m</link>
      <guid>https://dev.to/alim1496/managing-external-libraries-in-aws-lambda-functions-1g0m</guid>
      <description>&lt;p&gt;The popularity of microservices is increasing everyday. The main reason behind this is that we do not need to take care of the server related configurations. Just write down your code and see the magic. Definitely &lt;a href="https://aws.amazon.com/lambda/" rel="noopener noreferrer"&gt;aws lambda&lt;/a&gt; is one of the best microservices to perform varieties of tasks.&lt;/p&gt;

&lt;p&gt;When we write a lambda function, it is quite obvious that we may need third party modules and those will not be present in that environment. So we need to add them to lambda. Now the question comes &lt;strong&gt;how we can manage them properly?&lt;/strong&gt; The best answer would be &lt;strong&gt;using lambda layers&lt;/strong&gt;. According to aws document:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Lambda layer is a .zip file archive that can contain additional code or data. A layer can contain libraries, a custom runtime, data, or configuration files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the idea is that we can create a lambda layer and keep other third party libraries in a zipped file. We can create multiple layers as per our requirements and use the same layer to multiple lambda functions. Let us create lambda layers in both node &amp;amp; python runtime &amp;amp; use it in respective lambda functions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Lambda layer using node
&lt;/h4&gt;

&lt;p&gt;In order to add a node lambda layer we will have to keep the installed dependencies and files in a folder named &lt;code&gt;nodejs&lt;/code&gt;. Here the folder name has to be &lt;code&gt;nodejs&lt;/code&gt; so that aws lambda can identify the dependencies. Let us now build a layer which contains the &lt;code&gt;node-fetch&lt;/code&gt; module that creates http requests with node js. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a folder named &lt;code&gt;nodejs&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Go inside that folder.&lt;/li&gt;
&lt;li&gt;Open the path in terminal.&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;package.json&lt;/code&gt; file using &lt;code&gt;npm init -y&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Then install required dependencies. Here only &lt;code&gt;node-fetch&lt;/code&gt; will be installed using &lt;code&gt;npm i node-fetch&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Inside the &lt;code&gt;nodejs&lt;/code&gt; folder there will be one folder named &lt;code&gt;node_modules&lt;/code&gt; and two files named &lt;code&gt;package.json&lt;/code&gt; &amp;amp; &lt;code&gt;package-lock.json&lt;/code&gt;. Compress the &lt;code&gt;nodejs&lt;/code&gt; folder to a zipped file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now we are ready to create our lambda layer. Just go to the aws console &lt;strong&gt;Create layer&lt;/strong&gt; section like the following screenshot. Name your layer, choose a runtime like &lt;code&gt;Node.js 14.x&lt;/code&gt; &amp;amp; upload the zipped file created. Thus our lambda layer will be created.&lt;br&gt;&lt;br&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%2F7jh1e4u4k5ymynix4fo9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jh1e4u4k5ymynix4fo9.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will use this layer in our lambda function. Assuming that you know how to create a lambda function ( if you don't, no worries coz its quite simple), just add the layer you created to your lambda function. In our lambda function we will make a &lt;code&gt;GET&lt;/code&gt; request to an api &amp;amp; show the response in a &lt;code&gt;json&lt;/code&gt; format. Our lambda function code is:&lt;/p&gt;

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

const fetch = require("node-fetch");

exports.handler = async (event) =&amp;gt; {
    try {
        const response = await fetch(event.url);
        const json = response.json();
        return json;
    } catch(e) {
        return e;
    }
};


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

&lt;/div&gt;

&lt;p&gt;We will create a test event containing:&lt;/p&gt;

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

{
  "url": "https://reqres.in/api/users"
}


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

&lt;/div&gt;

&lt;p&gt;Now if we hit the &lt;code&gt;Test&lt;/code&gt; button we should see a response like following:&lt;/p&gt;

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

{
  "page": 1,
  "per_page": 6,
  "total": 12,
  "total_pages": 2,
  "data": [
    {
      "id": 1,
      "email": "george.bluth@reqres.in",
      "first_name": "George",
      "last_name": "Bluth",
      "avatar": "https://reqres.in/img/faces/1-image.jpg"
    },
    {
      "id": 2,
      "email": "janet.weaver@reqres.in",
      "first_name": "Janet",
      "last_name": "Weaver",
      "avatar": "https://reqres.in/img/faces/2-image.jpg"
    },
    {
      "id": 3,
      "email": "emma.wong@reqres.in",
      "first_name": "Emma",
      "last_name": "Wong",
      "avatar": "https://reqres.in/img/faces/3-image.jpg"
    },
    {
      "id": 4,
      "email": "eve.holt@reqres.in",
      "first_name": "Eve",
      "last_name": "Holt",
      "avatar": "https://reqres.in/img/faces/4-image.jpg"
    },
    {
      "id": 5,
      "email": "charles.morris@reqres.in",
      "first_name": "Charles",
      "last_name": "Morris",
      "avatar": "https://reqres.in/img/faces/5-image.jpg"
    },
    {
      "id": 6,
      "email": "tracey.ramos@reqres.in",
      "first_name": "Tracey",
      "last_name": "Ramos",
      "avatar": "https://reqres.in/img/faces/6-image.jpg"
    }
  ],
  "support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
  }
}


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Lambda layer using python
&lt;/h4&gt;

&lt;p&gt;Now we will create a lambda layer to perform the similar functionality in python. We will be installing necessary modules for &lt;code&gt;requests&lt;/code&gt; to make http request and fetch data from remote api. Now we have to do as following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create directories like this &lt;code&gt;build/python/lib/python3.8/site-packages&lt;/code&gt;. We must not make any spelling mistake otherwise we will encounter error while running the lambda. Another important thing is the version of python. You must use the same version of python everywhere. Here I am using 3.8 so while selecting runtime I must select Python 3.8 to avoid errors.&lt;/li&gt;
&lt;li&gt;Now go inside the &lt;code&gt;site-packages&lt;/code&gt; folder and install &lt;code&gt;requests&lt;/code&gt; using pip like this where &lt;code&gt;-t .&lt;/code&gt; means install everything inside this folder.&lt;/li&gt;
&lt;li&gt;Now come back to the &lt;code&gt;build&lt;/code&gt; folder &amp;amp; compress the &lt;code&gt;python&lt;/code&gt; folder to a zipped file.&lt;/li&gt;
&lt;li&gt;Now create a lambda layer like previous way &amp;amp; upload the zipped file. Select &lt;code&gt;Python 3.8&lt;/code&gt; as runtime.
```
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;mkdir build/python/lib/python3.8/site-packages&lt;br&gt;
cd build/python/lib/python3.8/site-packages&lt;br&gt;
pip install requests -t .&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Now its time to write down the lambda function. After creating the lambda, code will be as following:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;import json&lt;br&gt;
import requests&lt;/p&gt;

&lt;p&gt;def lambda_handler(event, context):&lt;br&gt;
    response = requests.get(event['url'])&lt;br&gt;
    data = response.json()&lt;br&gt;
    return data&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Our test event will be same as before &amp;amp; after running the lambda we will get similar json response as output.


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

&lt;/div&gt;

</description>
      <category>aws</category>
      <category>lambda</category>
      <category>serverless</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Should I start using a CSS preprocessor?</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Fri, 25 Jun 2021 14:57:32 +0000</pubDate>
      <link>https://dev.to/alim1496/should-i-start-using-a-css-preprocessor-41dn</link>
      <guid>https://dev.to/alim1496/should-i-start-using-a-css-preprocessor-41dn</guid>
      <description>&lt;p&gt;If you want to be a good web developer then having a sound knowledge in &lt;code&gt;css&lt;/code&gt; is a must. It is &lt;code&gt;css&lt;/code&gt; which makes a website look so beautiful. In small projects where there will be a few &lt;code&gt;html&lt;/code&gt; files, writing pure css codes does not bother us much. When we start working on a large project then managing every files in a structured way is a must. If we continue writing pure css in such projects then there is a good chance that we have to write same css rules or codes in multiple files. As the number of css file increases, we will be losing our control over them. In order to get rid of such problem and gaining more control over css we should definitely use a css preprocessor.&lt;/p&gt;

&lt;p&gt;Now the question is, what is a css preprocessor? According to Mozilla Developers org:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A CSS preprocessor is a program that lets you generate CSS from the preprocessor's own unique syntax.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means that css preprocessors let us write css rules in a structured way which get converted to pure css by any compiler or loader. &lt;a href="https://sass-lang.com/"&gt;saas&lt;/a&gt;, &lt;a href="https://lesscss.org/"&gt;less&lt;/a&gt; and &lt;a href="https://stylus-lang.com/"&gt;stylus&lt;/a&gt; are the most popular css preprocessors.&lt;/p&gt;

&lt;p&gt;Now let us discuss some reasons for using css preprocessors in web developement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Preprocessors let us use variables and functions that makes our developement easier.&lt;/li&gt;
&lt;li&gt;We can join multiple stylesheets into one by importing all of them into a main css file.&lt;/li&gt;
&lt;li&gt;Repititions can be avoided by writing the common rules together and using that as a mixin or function.&lt;/li&gt;
&lt;li&gt;Introduction of Darken and Lighten functionality.&lt;/li&gt;
&lt;li&gt;Introduction of nesting class which will give a style unique identity like having a class with similar name will not override the design if one is nested inside a particular class.&lt;/li&gt;
&lt;li&gt;All of this features together helps us writing css with less effort and time but efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we should really start learning and using any css preprocessor to achieve an awesome developement experience. It will really be cool.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>preprocessor</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>CSS preloaders from scratch</title>
      <dc:creator>Mohammad Abdul Alim</dc:creator>
      <pubDate>Mon, 21 Jun 2021 11:40:04 +0000</pubDate>
      <link>https://dev.to/alim1496/css-preloaders-from-scratch-n92</link>
      <guid>https://dev.to/alim1496/css-preloaders-from-scratch-n92</guid>
      <description>&lt;p&gt;Most of the websites now-a-days fetch data from remote server and then display it to the user. This very fetching of data being an asynchronous task it takes some times to be displayed. In the meantime preloader or loader is shown to the user. Using css &lt;code&gt;selectors&lt;/code&gt; and &lt;code&gt;animations&lt;/code&gt; we can design a lot of preloaders easily. Lets have a look at some simple preloaders developed with css.&lt;/p&gt;

&lt;h4&gt;
  
  
  Circular Loader 1
&lt;/h4&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/alim1496/embed/mdWLZrZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you have a look at the css code, the &lt;code&gt;border-top&lt;/code&gt; property is the bluish portion on the cirular path. If &lt;code&gt;animation&lt;/code&gt; property is not used then it will remain fixed on the top of whitish cirular path. The &lt;code&gt;animation&lt;/code&gt; does the trick here. This is &lt;code&gt;linear&lt;/code&gt; means its speed will be uniform &amp;amp; it will continue &lt;code&gt;infinite&lt;/code&gt; times and take &lt;code&gt;1s&lt;/code&gt; to complete one cycle.&lt;/p&gt;

&lt;h4&gt;
  
  
  Circular Loader 2
&lt;/h4&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/alim1496/embed/MWpXaWJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This very code is similar to that of Loader 1 just have a look at the &lt;code&gt;border-right-color&lt;/code&gt; and &lt;code&gt;border-left-color&lt;/code&gt; properties. Instead of &lt;code&gt;border-top&lt;/code&gt; those two properties have been added and made &lt;code&gt;transparent&lt;/code&gt; what did the trick. &lt;/p&gt;

&lt;h4&gt;
  
  
  Circular Wave Loader
&lt;/h4&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/alim1496/embed/eYvQKLQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here we can see that the circular loader is loading like wave. This wave effect has been created with the help of &lt;code&gt;before&lt;/code&gt; and &lt;code&gt;after&lt;/code&gt; selectors along with &lt;code&gt;transform: scale()&lt;/code&gt; property. This very &lt;code&gt;scale&lt;/code&gt; property along with the animation is creating the wave effect continuously.&lt;/p&gt;

&lt;h4&gt;
  
  
  Circular Dot Loader
&lt;/h4&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/alim1496/embed/MWpRWXG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here there are total 8 dots. Initially without &lt;code&gt;animation&lt;/code&gt; property three dots will be visible. Each dot has been created with the help of &lt;code&gt;box-shadow&lt;/code&gt; property. The &lt;code&gt;dotSpin&lt;/code&gt; keyframe is divided into 8 percentage areas representing each dot. Each percentage area's &lt;code&gt;box-shadow&lt;/code&gt; has 8 values 3 of which are &lt;code&gt;bluish&lt;/code&gt; colored and rest 5 are white or invisible. Thus the animation has been created.&lt;/p&gt;

&lt;h4&gt;
  
  
  Ellipsis Loader
&lt;/h4&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/alim1496/embed/RwpOOvZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We know about the &lt;code&gt;text-overflow: ellipsis&lt;/code&gt; property that shows &lt;code&gt;...&lt;/code&gt; when text is overflowed. Here such ellipsis has been used as a loader. Here the ASCII code of ellipsis &lt;code&gt;\2026&lt;/code&gt; has been added at &lt;code&gt;after&lt;/code&gt; selector and the &lt;code&gt;width&lt;/code&gt; property is varying in the &lt;code&gt;keyframe&lt;/code&gt; which does the trick for the animation.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>preloader</category>
      <category>html</category>
    </item>
  </channel>
</rss>
