<?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: Sidhartha Mallick</title>
    <description>The latest articles on DEV Community by Sidhartha Mallick (@ahtrahdis7).</description>
    <link>https://dev.to/ahtrahdis7</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%2F525310%2F60d49905-722c-414b-97e4-5efae7d57d69.jpeg</url>
      <title>DEV Community: Sidhartha Mallick</title>
      <link>https://dev.to/ahtrahdis7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahtrahdis7"/>
    <language>en</language>
    <item>
      <title>"Magic" using React Hooks. Yes, you read it right.</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Mon, 07 Feb 2022 17:07:24 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/magic-using-react-hooks-yes-you-read-it-right-17e5</link>
      <guid>https://dev.to/ahtrahdis7/magic-using-react-hooks-yes-you-read-it-right-17e5</guid>
      <description>&lt;h3&gt;
  
  
  First things first, What are hooks ?
&lt;/h3&gt;

&lt;p&gt;Hooks are the new feature introduced in the React 16.8 version. It allows you to use state and other React features without writing a class. Hooks are the functions which "&lt;strong&gt;hook into&lt;/strong&gt;" React state and lifecycle features from function components.&lt;/p&gt;

&lt;h3&gt;
  
  
  When would I use a Hook?
&lt;/h3&gt;

&lt;p&gt;If you write a function component and realize you need to add some state to it, previously you had to convert it to a class. Now you can use a Hook inside the existing function component. We’re going to do that right now!&lt;/p&gt;

&lt;h3&gt;
  
  
  What all Hooks are there ?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; useState&lt;/li&gt;
&lt;li&gt;useEffect&lt;/li&gt;
&lt;li&gt;useContext&lt;/li&gt;
&lt;li&gt;useRef&lt;/li&gt;
&lt;li&gt;useReducer&lt;/li&gt;
&lt;li&gt;useMemo&lt;/li&gt;
&lt;li&gt;useCallback&lt;/li&gt;
&lt;li&gt;useLayoutEffect&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes, the name of the hooks always start with &lt;code&gt;use&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's learn more about these hooks, later in this blog.&lt;br&gt;
Here is a github repo and webpage demonstrating the usage of all the hooks.&lt;/p&gt;

&lt;p&gt;Github Repository : &lt;a href="https://github.com/ahtrahdis7/react-hooks-usage-demo"&gt;github-link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Demo : &lt;a href="https://ahtrahdis7.github.io/react-hooks-usage-demo/"&gt;demo-link&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  useState :
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const [count, setCount] = useState(0);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It declares a “state variable”. Our variable is called count but we could call it anything else, like banana. This is a way to “preserve” some values between the function calls — useState is a new way to use the exact same capabilities that this.state provides in a class. Normally, variables “disappear” when the function exits but state variables are preserved by React.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';
export default function FunctionUsingUseState(){
    const [count, setCount] = useState(0);
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;
            Count : {count}
            &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useEffect
&lt;/h3&gt;

&lt;p&gt;It does the work of &lt;code&gt;componentDidMount&lt;/code&gt; as is in &lt;code&gt;React.Component&lt;/code&gt; class. By using this Hook, you tell React that your component needs to do something after render. React will remember the function you passed (we'll refer to it as our “effect”), and call it later after performing the DOM updates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from 'react';
export default function UseStateUseEffect(){
    const [count, setCount] = useState(0);
    useEffect(() =&amp;gt; {
        console.log('Use Effect is called');
    }, [count]);
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;
                Count : {count}
            &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useContext
&lt;/h3&gt;

&lt;p&gt;This hook is used to create common data that can be accessed throughout the component hierarchy without passing the props down manually to each level.&lt;br&gt;
&lt;/p&gt;

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

const MoodContext = createContext(moods);

export default function FunUseContext(){
    const [mood, setMood] = useState('😁');
    return (
        &amp;lt;MoodContext.Provider value={mood}&amp;gt;
            &amp;lt;div&amp;gt;
                &amp;lt;button onClick={() =&amp;gt; setMood('🤬')}&amp;gt;Angry&amp;lt;/button&amp;gt;
                &amp;lt;button onClick={() =&amp;gt; setMood('😁')}&amp;gt;Happy&amp;lt;/button&amp;gt;
                &amp;lt;button onClick={() =&amp;gt; setMood('😔')}&amp;gt;Sad&amp;lt;/button&amp;gt;
                &amp;lt;p&amp;gt;I am in &amp;lt;i&amp;gt;Parent&amp;lt;/i&amp;gt; Function : {mood}&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;MoodEmoji/&amp;gt;
        &amp;lt;/MoodContext.Provider&amp;gt;
    );
}

function MoodEmoji(){
    const mood = useContext(MoodContext);
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;p&amp;gt;I am Inside &amp;lt;i&amp;gt;useContext&amp;lt;/i&amp;gt; Function : {mood}&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt; 
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useRef
&lt;/h3&gt;

&lt;p&gt;It's a way to create a reference to a value in the component, and use it in the component's lifecycle.&lt;br&gt;
It is Mutable, but, it doesn't re-render UI. It is mainly used to grab DOM Elements.&lt;br&gt;
More common usecase of useRef is to grab native HTML elements from JSX.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRef } from 'react';
export default function FunctionUsingUseRef(){
    const myBtn = useRef(null);

    const clickIt = () =&amp;gt; myBtn.current.click();
    const helloButtonClicked = () =&amp;gt; console.log('hello button clicked');

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;p&amp;gt;Check the console.&amp;lt;/p&amp;gt;
            &amp;lt;button ref={myBtn} onClick={helloButtonClicked}&amp;gt;Hello Button&amp;lt;/button&amp;gt;
            &amp;lt;button onClick={clickIt}&amp;gt;Click Me! When You Click Me, You Indirectly Click 'Hello Button', Isn't that interesting.&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt; 
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useReducer
&lt;/h3&gt;

&lt;p&gt;Redux type of functionality, to &lt;strong&gt;useReducer&lt;/strong&gt; to update &lt;strong&gt;state&lt;/strong&gt; in &lt;strong&gt;Functional Components&lt;/strong&gt; in React.&lt;br&gt;
&lt;/p&gt;

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

function reducer(state, action) {
    switch(action.type) {
        case 'INCREMENT':
            return state + 1;
        case 'DECREMENT':
            return state - 1;
        default:
            return state;
    }
}

export default function FunctionUsingUseState(){
    const [count, dispatch] = useReducer(reducer, 0);
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h3&amp;gt;{count}&amp;lt;/h3&amp;gt;
            &amp;lt;button onClick={() =&amp;gt; dispatch({type: 'DECREMENT'})}&amp;gt;-&amp;lt;/button&amp;gt;
            &amp;lt;button onClick={() =&amp;gt; dispatch({type: 'INCREMENT'})}&amp;gt;+&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useMemo
&lt;/h3&gt;

&lt;p&gt;This hook is a higher-order component that takes a function as an argument and returns a memoized version of that function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useMemo, useState } from 'react';
export default function FunUseMemo(){
    const [count, setCount] = useState(60);

    // useMemo is a higher-order component that takes a function as an argument
    // and returns a memoized version of that function.

    const expensiveCount = useMemo(() =&amp;gt; {
        return count ** 2;
    }, [count]);

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;
            Count : {count}
            &amp;lt;/button&amp;gt;
            &amp;lt;p&amp;gt;Expensive Count : {expensiveCount}&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useCallback
&lt;/h3&gt;

&lt;p&gt;In order to Memoize a whole function, &lt;strong&gt;useCallback&lt;/strong&gt; is used.&lt;br&gt;
The showCount function is called from multiple childs in the same DOM Tree, they will help prevent un-necessary re-renders of the same object as they will be using the same function object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ahtrahdis7/react-hooks-usage-demo/blob/main/src/hooks/use_callback.js"&gt;Code for &lt;strong&gt;useCallback&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  useLayoutEffect
&lt;/h3&gt;

&lt;p&gt;It is similar to useEffect with a small difference. &lt;br&gt;
It runs after render but before it it is visually updated. &lt;br&gt;
It blocks visual updates until the Callback exection is finished.&lt;/p&gt;

&lt;p&gt;Reach Out to Me @&lt;a href="//mailto:%20mallicksidhartha7@gmail.com"&gt;mallicksidhartha7@gmail.com&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/ahtrahdis7"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/mallicksidhartha7"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React : Class vs Function Components</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Thu, 13 Jan 2022 10:44:12 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/react-class-vs-function-components-j85</link>
      <guid>https://dev.to/ahtrahdis7/react-class-vs-function-components-j85</guid>
      <description>&lt;p&gt;In the last post, we learned about &lt;strong&gt;components&lt;/strong&gt;. Here, We will learn about types of components.&lt;/p&gt;

&lt;p&gt;So, there are 2 types of components as you would have guessed by now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Class&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Functional&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;You can do everything in using either of them. But, &lt;strong&gt;functional components&lt;/strong&gt; are preferred, for obvious reasons.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A simple comparision, why functional component ?&lt;/p&gt;

&lt;p&gt;We will write a simple counter, which increments the count value when clicked.&lt;/p&gt;

&lt;p&gt;using &lt;strong&gt;Function Component&lt;/strong&gt;, the code 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;const FunctionalComponent=()=&amp;gt;{
    const[count , setCount]=useState(0);
    return
        &amp;lt;div style={{margin:'10px'}}&amp;gt;
          &amp;lt;h2&amp;gt;{count}&amp;lt;/h2&amp;gt;
          &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;+&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    )
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While using &lt;strong&gt;Class Component&lt;/strong&gt;, ... i will leave it upto you to judge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ClassComponent extends React.Component{
   constructor(){
        super();
        this.state={
            count :0
        };
        this.increment=this.increment.bind(this);
   } 
   increment(){
       this.setState({count : this.state.count +1});
   }
   render(){
        return (
            &amp;lt;div style={{margin:'10px'}}&amp;gt;
               &amp;lt;h2&amp;gt; {this.state.count}&amp;lt;/h2&amp;gt; 
               &amp;lt;button onClick={this.increase}&amp;gt;+&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
        )
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and &lt;strong&gt;React.Component&lt;/strong&gt; class comes with a lot of predefined baggage, which are not necessary all the time. &lt;/p&gt;

&lt;p&gt;Whereas, by using &lt;strong&gt;Functional Components&lt;/strong&gt; you can customise stuffs as per your need with the help of &lt;code&gt;React Hooks&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Hooks are my favourites in the whole React library. And one of my fav. hooks in &lt;code&gt;useMemo&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The hooks come in handy when you are dealing with frequent changes in the data stream. &lt;/p&gt;

&lt;p&gt;I found a great use of &lt;code&gt;useMemo&lt;/code&gt; during pagination. It can memoize the component based on the page based on it's parameters. A network call might happen in the background, but it sure hell doesn't concern the user. Hence, improving the UX.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect&lt;/code&gt; hook is used instead of &lt;code&gt;componentDidMount&lt;/code&gt; in a class component.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;NOTE&lt;/strong&gt; : You cannot use hooks inside class components. Hooks are exclusive to function components only.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;TIP&lt;/strong&gt; : Learn to harness the power of custom hooks. They are on a whole different level.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Resources :
&lt;/h3&gt;

&lt;p&gt;Read more about their differences at &lt;a href="https://www.geeksforgeeks.org/differences-between-functional-components-and-class-components-in-react/"&gt;gfg&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Read more about hooks at &lt;a href="https://ahtrahdis7.hashnode.dev/magic-using-react-hooks-yes-you-read-it-right"&gt;@this is my blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How does React Work ?</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Wed, 12 Jan 2022 07:55:02 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/how-does-react-work--d58</link>
      <guid>https://dev.to/ahtrahdis7/how-does-react-work--d58</guid>
      <description>&lt;p&gt;&lt;strong&gt;React&lt;/strong&gt; uses the concept of &lt;code&gt;virtual dom&lt;/code&gt; to present contents to the user. &lt;/p&gt;

&lt;p&gt;So, What is this &lt;strong&gt;Virtual DOM&lt;/strong&gt; ?&lt;/p&gt;

&lt;p&gt;You can think of it as the skeleton of the webapp. It helps react push updated in a faster and optimised manner without disturbing the existing components of the actual dom. &lt;/p&gt;

&lt;p&gt;For every update, React first updates the virtual dom. Everything is in JavaScript, so, it's much more faster and efficient that way. It then compares the previous virtual dom with the updated version and only updates the components that are actually changes and doesn't disturb the others.&lt;/p&gt;

&lt;p&gt;This makes it extremely &lt;strong&gt;efficient&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Components : *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;oh Okay, I forgot to tell you about &lt;strong&gt;React Components&lt;/strong&gt; .&lt;br&gt;
So, What are they ?&lt;/p&gt;

&lt;p&gt;These are the building blocks of the React. Every react app is a collection of components arranged in a hierarchy. All kinds of branching and chaining takes place here. And everything is highly customisable.  &lt;/p&gt;

&lt;p&gt;React Components consist of business login with some UI rendering code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ReactComp(props) { 
    // some business logic goes here

    return (
        &amp;lt;div&amp;gt;component content goes here... ui codes.&amp;lt;/div&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key Points about Components :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every Component starts with a Capital Letter&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;&lt;/code&gt; this represents an empty component.&lt;/li&gt;
&lt;li&gt;You cannot chain two elements without a parent element inside &lt;code&gt;()&lt;/code&gt;. i.e.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(
  &amp;lt;div&amp;gt;hello&amp;lt;/div&amp;gt;
  &amp;lt;div&amp;gt;world&amp;lt;/div&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is not allowed. It will throw you an error. You can at least enclose them with &lt;code&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;&lt;/code&gt; this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can enclose other components in another component. Like this, &lt;code&gt;&amp;lt;TestComponent &amp;lt;- you can pass props here -&amp;gt; /&amp;gt;&lt;/code&gt;. For example, &lt;code&gt;&amp;lt;TestComponent name={'sidhartha'} age={22} /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How Props Work ?&lt;/strong&gt; , we will learn more about that in the next blog...&lt;/p&gt;

&lt;p&gt;React out to me &lt;a href="https://dev.tomailto:%20TestComponent"&gt;@mallicksidhartha7@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is React ?</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Wed, 12 Jan 2022 07:11:07 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/what-is-react--19m8</link>
      <guid>https://dev.to/ahtrahdis7/what-is-react--19m8</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;React is a free and open-source front-end JavaScript library for building user interfaces based on UI components.&lt;br&gt;
...blah...blah...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But, &lt;strong&gt;What the fuck is React ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is used to create single page applications just by using a single &lt;code&gt;index.html&lt;/code&gt; file with meta tags and a &lt;code&gt;&amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; which basically contains the whole application. No More bunch of html files for creating websites and manually linking them... blah blah... It's all made so easy with webpack. &lt;/p&gt;

&lt;p&gt;Oh wait !! &lt;code&gt;Webpack&lt;/code&gt; ? What role does it play here ?&lt;/p&gt;

&lt;p&gt;So, Webpack is kind of the mastermind behind all of this. It helps in bundling the react codebase and compiles the whole codebase into javascript chunks, which are easy to serve when requested. It helps optimise bundle size for faster serving webapps.&lt;/p&gt;

&lt;p&gt;and yes, Routing pages is possible in React apps. With the help of &lt;code&gt;react-router&lt;/code&gt;, you can easily route components to where they belong.&lt;/p&gt;

&lt;p&gt;So, is that it ? i.e.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;SPA ( Single Page Application )&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Faster Serving WebApps&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Better Organization for Pages and Linking&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hell NO, We are just getting started folks. &lt;br&gt;
Follow this whole series to learn more about react.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;React&lt;/code&gt; out to me @&lt;a href="mailto:mallicksidhartha7@gmail.com"&gt;mallicksidhartha7@gmail.com&lt;/a&gt; &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>MongoDb : stuffs you should to know - Part 1</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Fri, 07 Jan 2022 13:31:24 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/mongodb-stuffs-you-should-to-know-part-1-287o</link>
      <guid>https://dev.to/ahtrahdis7/mongodb-stuffs-you-should-to-know-part-1-287o</guid>
      <description>&lt;h2&gt;
  
  
  What is MongoDB ?
&lt;/h2&gt;

&lt;p&gt;MongoDb is a NoSQL document database where data is stored as documents inside collections.&lt;br&gt;
A document is a way to organise data as a set of &lt;code&gt;key-value&lt;/code&gt; pairs.&lt;br&gt;
A bunch of documents organised under certain rules or specs is called a collection.&lt;br&gt;
In MongoDb, all data is stored in BSON (Binary JSON). &lt;/p&gt;

&lt;h2&gt;
  
  
  How does MongoDB Work ?
&lt;/h2&gt;

&lt;p&gt;A hosted mongodb instance is a part of a cluster which contains multiple such servers/instances called as replica-set.&lt;/p&gt;

&lt;p&gt;They follow the &lt;code&gt;master-slave&lt;/code&gt; architecture as it's internal working. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Working of the master-slave:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In short, a master instance interacts with the outside world to serve any kind of data related requests and the syncs up with the slave instances. In case the master goes down, from the remaining slaves, one instance gets elected to be the master instance and the work continues. It's like, no instance ever went down.&lt;/p&gt;

&lt;p&gt;Then, the master instance interacts with a mongo server, which actually talks to all the requests coming it's way. Kind of a proxy, more of a controller of all requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why BSON ?
&lt;/h2&gt;

&lt;p&gt;It is optimised for &lt;code&gt;speed&lt;/code&gt;, &lt;code&gt;space&lt;/code&gt; and &lt;code&gt;flexibility&lt;/code&gt;. BSON’s binary structure encodes type and length information, which allows it to be parsed much more quickly.&lt;/p&gt;

&lt;p&gt;BSON supports non-JSON-native data types, like &lt;code&gt;dates&lt;/code&gt; and &lt;code&gt;binary data&lt;/code&gt;. &lt;a href="https://www.mongodb.com/json-and-bson"&gt;read more about it&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Import/Export
&lt;/h2&gt;

&lt;p&gt;For this, you need to know 4 different commands, two for each.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mongodump&lt;/code&gt; : Upon successful execution, it outputs the data in BSON format.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongodump --uri="atlas cluster uri"
--collection="coll-name" 
--out="output-file"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mongoexport&lt;/code&gt; : It outputs the data in JSON format.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoexport --uri="atlas cluster uri" 
--collection="coll-name" 
--out="output_file.json"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mongorestore&lt;/code&gt; : It is used to load bson data dump into a mongodb database.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongorestore --uri="atlas cluster uri" 
--drop="path to dump"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mongoimport&lt;/code&gt;: It is used to load json data export into a mongodb database.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongorestore --uri="atlas cluster uri" 
--drop="path to json file"
--collection="coll-name"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data Types in MongoDB
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.mongodb.com/manual/reference/operator/query/type/"&gt;datatypes in mongodb - link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apart from the standard datatypes, mongodb has some special datatypes which enables a lots of features in it.&lt;/p&gt;

&lt;p&gt;Especially, &lt;a href="https://docs.mongodb.com/manual/reference/method/ObjectId/"&gt;ObjectId&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, The question comes to mind, What is a ObjectId datatype in mongodb ?&lt;/p&gt;

&lt;p&gt;Let's see what it is.&lt;br&gt;
It returns a new ObjectId value. The 12-byte ObjectId value consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4-byte timestamp value&lt;/li&gt;
&lt;li&gt;5-byte random value generated once per process&lt;/li&gt;
&lt;li&gt;3-byte incrementing counter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A special objectid is &lt;code&gt;_id&lt;/code&gt; :&lt;/strong&gt; &lt;br&gt;
In every document, it's like the primary key equivalent for the documents or sub-documents, in the mongodb database.&lt;/p&gt;

&lt;p&gt;Every document in a collection has to have a unique &lt;code&gt;_id&lt;/code&gt; value. It has a special place in the whole mongodb database architecture.&lt;/p&gt;

&lt;p&gt;It's been a lot of information in a single blog. Will continue this in the next part. Until then, Kudos to you, You have learn't the internal workings of mongodb.&lt;/p&gt;

&lt;p&gt;Signing Off, ! Happy Coding !&lt;/p&gt;

&lt;p&gt;Reach out to me @&lt;a href="//mailto:mallicksidhartha7@gmail.com"&gt;mallicksidhartha7@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>database</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Node.js Scalable REST API Architecture</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Thu, 06 Jan 2022 05:55:03 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/node-scalable-architecture-384b</link>
      <guid>https://dev.to/ahtrahdis7/node-scalable-architecture-384b</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;server setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;server/index.js&lt;/code&gt; file and add this &lt;a href="https://github.com/ahtrahdis7/node-rest-api-template/blob/master/server/index.js" rel="noopener noreferrer"&gt;code&lt;/a&gt; to it. This function creates a server object and preserves it using a javascript property called a &lt;code&gt;closure&lt;/code&gt;. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Import the server in the main &lt;code&gt;index.js&lt;/code&gt; file of your rest-api and pass the config into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const server = require('./server')();
const config = require('./configs');
const db = require('./configs/db');

server.create(config, db);
server.start(); // this kickstarts your server.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;you should use &lt;code&gt;nodemon&lt;/code&gt; for development purposes. It monitors your code changes and restarts the server with the recent updates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Follow the given directory structure. It consists of dirs like, routes, api-versions, controllers, services and configs. &lt;/p&gt;

&lt;p&gt;This is made this way to make the node-app &lt;code&gt;scalable&lt;/code&gt; i.e. when supposedly developing a newer version on top of the older version, it makes it easy to integrate it with the existing up and running server.&lt;/p&gt;

&lt;p&gt;Then, there is the configs dir to store all the required configs of the node-app. to reflect changes to every variable, incase needed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk5nl5iljx48ibfv6q0ti.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%2Fk5nl5iljx48ibfv6q0ti.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;api version setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The routes dir contains &lt;a href="https://github.com/ahtrahdis7/node-rest-api-template/blob/master/server/routes/apis/v1.js" rel="noopener noreferrer"&gt;&lt;code&gt;apis/v1.js&lt;/code&gt;&lt;/a&gt;, which contains all the existing routes for the version1 of the node-rest-api, the controllers of which are inside &lt;code&gt;controllers/v1/*.js&lt;/code&gt;. They make the development process less messy and easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;router setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's talk about how to setup the routers in here. Ergo, it goes like this &lt;code&gt;routes.init(server);&lt;/code&gt; in the &lt;code&gt;server/index.js&lt;/code&gt; create function. But why ?&lt;/p&gt;

&lt;p&gt;Let's look into the &lt;a href="https://github.com/ahtrahdis7/node-rest-api-template/blob/master/server/routes/index.js" rel="noopener noreferrer"&gt;&lt;code&gt;routes/index.js&lt;/code&gt;&lt;/a&gt; file, the answer lies in there. It is made that way to make the life of the developers easier. It's more informative.&lt;/p&gt;

&lt;p&gt;It keeps track of the sequence of the routes, which would be a necessity when the project grows big.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;middlewares&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The middlewares reside in the &lt;a href="https://github.com/ahtrahdis7/node-rest-api-template/blob/master/server/index.js" rel="noopener noreferrer"&gt;&lt;code&gt;server/index.js&lt;/code&gt;&lt;/a&gt; file, before the routes initiation. Why ? Because, they are called the middlewares, they are supposed to be there by design. There is no use to place them anywhere else, they won't serve their true purpose, i.e. all the requests are supposed to pass through them.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;custom middlewares&lt;/code&gt; will be placed in the other parts of the routes based on their requirement, for example, &lt;code&gt;caching&lt;/code&gt; middlewares, &lt;code&gt;auth&lt;/code&gt; middlewares, or any kind of &lt;code&gt;pre-request processing&lt;/code&gt; middlewares and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.use('/dashboard', authMiddleware, dashboardController);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.use('/v1', xyzMiddleware, v1ApiController);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Middlewares follow certain specific format. It goes 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;function xyzMiddleware(req, res, next){
    // stuffs to do
    // add stuffs to request, or change req paramaters, 
    // do whatever you want with those objects, 
    // but once the task is done, call `next()`
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;controller setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Why is there a controller here ? What is a controller ? What does it do ? Well, let's answer there question here ...&lt;/p&gt;

&lt;p&gt;A controller is a piece of code where you start assigning/ defining tasks that is to be done if a request is made to that route, whether GET, PUT, POST or whatever. You will have to define tasks for everything in here, if you want it to act that way. &lt;/p&gt;

&lt;p&gt;It is where the true purpose of the request is served. You split the major routes into smaller ones and start writing actions for all the routes, testing them ( most probably using postman or any custom script ) and documenting them. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;services setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;What does services do them ? Well, when controller starts assigning/defining tasks, most of the times, there are many common tasks for a lot of routes, this is where services come-up. &lt;br&gt;
We identify the tasks, for example, &lt;code&gt;fetching the active user data from the db&lt;/code&gt;, is a very common task. So, we write down the codes for it into a function as a service and just use it when required. This makes maintenance of the server a hell of a lot easier. &lt;br&gt;
Otherwise, every time we need to make some changes, we would have to go all the way to find all such functions and methods and actions to make that specific change and it will make the life of a developer a lot harder. &lt;br&gt;
This whole process is called &lt;code&gt;refactoring&lt;/code&gt;. There are courses for these.&lt;/p&gt;

&lt;p&gt;That's all for setting up a scalable node architecture. If you have any doubts or issues. Reach out to me at : &lt;a href="//mailto:%20mallicksidhartha7@gmail.com"&gt;mallicksidhartha7@gmail.com&lt;/a&gt;. &lt;/p&gt;

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

</description>
      <category>node</category>
      <category>javascript</category>
      <category>express</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Deep Copy vs Shallow Copy in JavaScript</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Wed, 05 Jan 2022 04:29:02 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/deep-copy-vs-shallow-copy-in-javascript-d02</link>
      <guid>https://dev.to/ahtrahdis7/deep-copy-vs-shallow-copy-in-javascript-d02</guid>
      <description>&lt;h2&gt;
  
  
  Shallow Copy
&lt;/h2&gt;

&lt;p&gt;A new object is created that has an exact copy of the values in the original object. If the original object points to another object, a separate copy of that object is not created, rather a reference to that object is passed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = {
    name: 'S. Sahu',
    addr:  {
        city: 'Behrampur',
    }
}
const b = {...a}; // shallow copy using spread operator
b.addr.city = "Sambalpur"; // Shallow Copy

b.name = "A. Panda"; // Deep Copy

console.log(a.name, b.name); // separate references for name is created here
console.log(a.addr, b.addr); // a.addr and b.addr point to the same object reference
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Output&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sambalpur Sambalpur
S. Sahu A. Panda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deep Copy
&lt;/h2&gt;

&lt;p&gt;A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = {
    name: 'S. Sahu',
    addr:  {
        city: 'Behrampur',
    }
}

const b = {
    name: a.name,
    addr: {
        city: a.city
    }
};

b.addr.city = "Sambalpur";
b.name = "A. Panda";

console.log(a.addr.city, b.addr.city);
console.log(a.name, b.name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Output&lt;/em&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Behrampur Sambalpur
S. Sahu A. Panda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Reference
&lt;/h2&gt;

&lt;p&gt;A reference of the original object is created. Any changes made in the new object is reflected in the original object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = {
    name: 'S. Sahu',
    addr:  {
        city: 'Behrampur',
    }
}

const b = a;

b.addr.city = "Sambalpur";
b.name = "A. Panda";

console.log(a.addr.city, b.addr.city);
console.log(a.name, b.name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Output&lt;/em&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sambalpur Sambalpur
A. Panda A. Panda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>deepcopy</category>
      <category>shallowcopy</category>
      <category>web</category>
    </item>
    <item>
      <title>Random Cropping/Scaling Images to Fit the Required Specs or Dimensions for Any kind of Uploads</title>
      <dc:creator>Sidhartha Mallick</dc:creator>
      <pubDate>Tue, 04 Jan 2022 06:35:22 +0000</pubDate>
      <link>https://dev.to/ahtrahdis7/random-croppingscaling-images-to-fit-the-required-specs-or-dimensions-for-any-kind-of-uploads-4kic</link>
      <guid>https://dev.to/ahtrahdis7/random-croppingscaling-images-to-fit-the-required-specs-or-dimensions-for-any-kind-of-uploads-4kic</guid>
      <description>&lt;p&gt;A simple Python Script with ffmpeg would do wonders.&lt;br&gt;
&lt;/p&gt;

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

def generate_ffmpeg_command_scale(path, w, h):
    input_path = path.split('/')
    output_path = '/'.join(input_path[:-1]) + '/out-' + input_path[-1];
    ffmpeg_cmd = 'ffmpeg -i {} -vf scale={}:{} {}'.format(path, w, h, output_path);
    return ffmpeg_cmd

def generate_ffmpeg_command_crop(path, w, h):
    input_path = path.split('/')
    output_path = '/'.join(input_path[:-1]) + '/out-' + input_path[-1];
    ffmpeg_cmd = 'ffmpeg -i {} -vf crop={}:{}:0:0 {}'.format(path, w, h, output_path);
    return ffmpeg_cmd

WIDTH = int(input("width = "));
HEIGHT = int(input("height = "))
PATH = input("path = ")

scale_command = generate_ffmpeg_command_scale(PATH, WIDTH, HEIGHT)
crop_command = generate_ffmpeg_command_crop(PATH, WIDTH, HEIGHT)
print(scale_command);
print(crop_command);

os.system(scale_command);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s go through the script, _what is does ? How it does ?&lt;br&gt;
_&lt;br&gt;
This script accepts 3 parameters, the expected dims (HxW) and the path to the file in the local system. You can get the path to the file by simply dragging the file into the terminal and copy the path that appears.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;generate_ffmpeg_command()&lt;/em&gt; function generates the command for processing the image and specifies the output location of the file to the dame directory but changes the filename as &lt;em&gt;&lt;strong&gt;out-&amp;lt;filename&amp;gt; .&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The function returns the command requires and the &lt;strong&gt;os&lt;/strong&gt; module in python executes the shell command in your terminal and gets you the requires image.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;scale&lt;/strong&gt; parameter of the ffmpeg command scales your input image to the required dimensions.&lt;/p&gt;

&lt;p&gt;Try it on &lt;a href="https://replit.com/@SidharthaMallic/random-crop-images" rel="noopener noreferrer"&gt;replit.com&lt;/a&gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ghpr9wexefe2d6uv3rk.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%2F6ghpr9wexefe2d6uv3rk.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Modifications :
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;To crop the image uniformly from the middle, just replace the scale parameter by crop, that would be enough for it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To crop the image from the top-left corner, update line no. 6 to : &lt;code&gt;ffmpeg_cmd = ffmpeg -i {} -vf crop={}:{}:0:0 {}'.format(path, w, h, output_path);&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;mail me at: &lt;em&gt;&lt;a href="//mailto:%20mallicksidhartha7@gmail.com"&gt;mallicksidhartha7@gmail.com&lt;/a&gt;&lt;/em&gt; , for any kind of customisations, be it Image Processing, Video Processing, Cropping, Compression or so using ffmpeg.&lt;/p&gt;

&lt;p&gt;!! Happy Coding !! 😋 &lt;/p&gt;

</description>
      <category>python</category>
      <category>ffmpeg</category>
      <category>imageprocessing</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
