<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sankhadip Samanta on Medium]]></title>
        <description><![CDATA[Stories by Sankhadip Samanta on Medium]]></description>
        <link>https://medium.com/@sankhadip?source=rss-e7ab02b108a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IDIODqlEvX100HvCw4AFBg.jpeg</url>
            <title>Stories by Sankhadip Samanta on Medium</title>
            <link>https://medium.com/@sankhadip?source=rss-e7ab02b108a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:32:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sankhadip/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Firebase With Angular CRUD Operations]]></title>
            <link>https://sankhadip.medium.com/firebase-with-angular-crud-operations-ba91ddf1dcc4?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba91ddf1dcc4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Mon, 29 Nov 2021 07:55:27 GMT</pubDate>
            <atom:updated>2021-11-30T02:48:45.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_p-xSamqef71sErIbqhJlA.png" /><figcaption>Firebase 9 with Angular 13</figcaption></figure><p><strong>Firebase</strong> is a Backend-as-a-Service. It provides developers and organizations with a variety of tools and services to help them develop quality apps, grows their user base, and earn profit. It is built on Google’s infrastructure. Firebase is a NoSQL database, which stores data in JSON-like documents.</p><p>In Firebase, a document is a set of key-value pairs defined by a schema. A group of documents makes up a collection.</p><p>Key features of Firebase are</p><ul><li>Authentication</li><li>Realtime Database</li><li>Hosting</li><li>Notifications</li></ul><p>In this article, we will be integrating Firebase with Angular and performing basic CRUD operations. We will fetch data from Firebase in real-time.</p><p>We will create a basic UI where we can enter students’ names &amp; ages, fetch a student list, delete a student and update their details.</p><blockquote><strong>Create Project</strong></blockquote><p>Create an angular project using the below command.</p><p>ng new firebase9 and install the following module</p><p>npm i firebase</p><p>I’ll be using visual studio code.</p><blockquote><strong>Code</strong></blockquote><p>Remove the content of app.component.html</p><p>Create a component using the below command</p><p><strong>ng g c firebase-crud — skip-tests</strong></p><p>Place below code in firebase-crud.component.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb95a6f24d2d3aec226810e52ac6a321/href">https://medium.com/media/fb95a6f24d2d3aec226810e52ac6a321/href</a></iframe><p>And below code in firebase-crud.component.ts</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ac8e4c753fa35085cb76b7bdbe61da6/href">https://medium.com/media/0ac8e4c753fa35085cb76b7bdbe61da6/href</a></iframe><p>In HTML and TS files, I have added simple add, delete, get and update functions which will call firebase functions later to perform CRUD.</p><p>Create a service using the below command where we will call firebase functions to perform CRUD operations.</p><p><strong>ng g s firebase — skip-tests</strong></p><p>Now, navigate to this <a href="https://console.firebase.google.com/u/0/">URL</a> to create a firebase project.</p><p>Grab the firebase configuration object from Project Settings-&gt;General and place it in environment.ts like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0e2e7d0506ab6977599e0d25605e28f/href">https://medium.com/media/f0e2e7d0506ab6977599e0d25605e28f/href</a></iframe><p>Then create a Firebase database and a collection named <strong>students</strong>.</p><p>Place below code in firebase.service.ts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67af92e0fc850f7b978a23481beddb17/href">https://medium.com/media/67af92e0fc850f7b978a23481beddb17/href</a></iframe><p>In this service, we are performing the below operations.</p><ul><li>Inside constructor, initialize firebase app with firebase configurations, fetch Firebase database, and above created <strong>students</strong> collection. We are also subscribing to data changes of <strong>students </strong>collection so that we can get real-time updates and show updated data in UI.</li><li>getStudents:- fetches all students data.</li><li>deleteStudent:- delete a single student based on document ID.</li><li>updateStudent:- update a single student based on document ID.</li><li>addStudent:- add new student to <strong>students </strong>collection.</li></ul><p>Now, let’s update firebase-crud.component.ts so that it can call firebase.service.ts crud functions. Place below code in firebase-crud.component.ts</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77159cfa2d9cc53d4a2c0028a0ebc092/href">https://medium.com/media/77159cfa2d9cc53d4a2c0028a0ebc092/href</a></iframe><p>Now, run npm start or ng serve command, go to <a href="http://localhost:4200/">http://localhost:4200</a> and perform amazing crud operations with firebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*e14qjklZDZYtwxY0Zg6G_g.png" /><figcaption>UI</figcaption></figure><p>If you are having any questions, leave a comment.</p><p>Check out the Github repository for source code.</p><p><a href="https://github.com/dev-sankhadip/CRUD-operations-in-Firebase-Angular">GitHub - dev-sankhadip/CRUD-operations-in-Firebase-Angular</a></p><h3>Sankhadip Samanta</h3><p><em>Software Engineer, Mirra | Tech Writer</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba91ddf1dcc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Store File’s Binary  in MySQL Database and View using Vanilla JS and Node.JS]]></title>
            <link>https://sankhadip.medium.com/store-files-binary-in-mysql-database-and-view-using-vanilla-js-and-node-js-95a227002b85?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a227002b85</guid>
            <category><![CDATA[ejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Thu, 13 May 2021 07:01:17 GMT</pubDate>
            <atom:updated>2021-05-14T00:34:14.725Z</atom:updated>
            <content:encoded><![CDATA[<h3>Store File in MySQL Database and View using Vanilla JS and Node.JS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*EDmJC4QbV1c5GC195Cs2rQ.png" /></figure><p>There are several methods for uploading files and saving them on the Server. In this tutorial, we will implement how to read files using <strong>Vanilla Javascript</strong>, save file’s binary data in <strong>MySQL DB using Node.JS</strong>, and view them.</p><p>JS code implementation will be the same for all JS frameworks. I assume you have <strong><em>Node.JS</em></strong> basic development knowledge and <strong><em>phpMyAdmin</em></strong> installed in your system.</p><p>Let’s dive into implementation.</p><blockquote><strong>Create Project</strong></blockquote><p>Install following modules.</p><p>npm i express ejs mysql</p><p>npm i -D nodemon</p><p>The project Structure should be like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*F21-5oV-B8b3QTAZ7UezZg.png" /></figure><blockquote><strong>Implementation</strong></blockquote><p>Run the following SQL command in phpMyAdmin to create a table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/265ec5b3a3951cc3968d9515af275f1e/href">https://medium.com/media/265ec5b3a3951cc3968d9515af275f1e/href</a></iframe><p>We will use the LONGBLOB data type to store the file’s binary data. LONGBLOB is a type of BLOB(Binary Large Object) with a maximum length of 4294967295 characters.</p><p>Let’s setup API code for rendering HTML pages and saving file’s data in DB;</p><p>Place below code in server.js file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98979bcff568af8ac45a585b2e96cb7b/href">https://medium.com/media/98979bcff568af8ac45a585b2e96cb7b/href</a></iframe><p>In the config object, place your MySQL user, password, and concerned database name.</p><ul><li><strong>GET “/”:- </strong>It will render the page for uploading files.</li><li><strong>POST “/store”:- </strong>It will extract the file’s data from Request Body and store it in the Database.</li><li><strong>GET “/image/:id”:- </strong>It will fetch file data from Database using id from params and send to UI to show.</li></ul><p>Let’s implement UI side code.</p><p>Place below code in index.ejs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3312d1b66bfd3146b61152e32978eb4b/href">https://medium.com/media/3312d1b66bfd3146b61152e32978eb4b/href</a></iframe><p>Let’s see what’s happening in the above code.</p><p>I have attached an onchange event to file input field which trigerrs upon loading files.</p><p><strong>FileReader</strong> object lets web application to read the file or raw data buffers asynchronously from user’s computer which can be retrieved from <strong>File</strong> or <strong>Blob</strong> object.</p><p><strong>File</strong> object may be obtained from <strong>FileList</strong> object returned as a result of selecting the file from input element.</p><p><strong>FileReader</strong> can only access the contents of files that the user has loaded through the Input field or drag and drop. It can’t access files via a pathname.</p><p>It has a couple of event handlers and methods, here we are using three of them.</p><ul><li><strong>FileReader.onload:- </strong>This event is triggered each time the reading operation is successfully completed.</li><li><strong>FileReader.onerror:- </strong>This event is triggered each time the reading operation encounter an error.</li><li><strong>FileReader.readAsDataURL():- </strong>Starts reading of the specified Blob or File, once finished, the result attribute data: URL which represents file’s data.</li></ul><p>After receiving the saved file id response from the server, we are removing the input field and redirecting the user to “/image/{fileid}” where the user will be able to view the loaded image.</p><p>Place below code in imageView.ejs</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85ef79edab04419f72faf5fa671e5b91/href">https://medium.com/media/85ef79edab04419f72faf5fa671e5b91/href</a></iframe><p>In this file, we recieve <strong>&lt;%= name %&gt; </strong>data from /<strong>image<em>/</em>:id</strong> route.</p><p>Now do npm start, go to <a href="http://localhost:3000/">http://localhost:3000</a>.</p><p>Upload a file and you will be redirected to another page where you will be able to view the uploaded image.</p><p>You can open <strong><em>phpMyAdmin</em></strong> and check for stored records like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*0Im5XRmTsc-or1-Q9SPaTw.png" /><figcaption>phpMyAdmin</figcaption></figure><p>If you are having any questions, leave a comment.</p><p>Check out the Github repository for source code.</p><p><a href="https://github.com/dev-sankhadip/Store-File-Database-and-View-in-Vanilla-JS-Node.JS-and-MySQL">dev-sankhadip/Store-File-Database-and-View-in-Vanilla-JS-Node.JS-and-MySQL</a></p><h3>Sankhadip Samanta</h3><p><em>Software Developer, Code Quotient | Tech Writer</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a227002b85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Encryption and Decryption in C#]]></title>
            <link>https://sankhadip.medium.com/encryption-and-decryption-in-c-f2de3d802e1d?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2de3d802e1d</guid>
            <category><![CDATA[decryption]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Mon, 07 Dec 2020 06:33:18 GMT</pubDate>
            <atom:updated>2020-12-08T01:13:57.799Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yYwDkpypD1aW0lVk3kvWMA.png" /><figcaption>Credit to Cloudsoft Zone</figcaption></figure><p>In this article, I am going to discuss various <strong>Encryption and Decryption</strong> technique.</p><p>There are basically two types of algorithms that are used for Encryption and Decryption.</p><blockquote><strong>Symmetric Encryption</strong></blockquote><p>In this algorithm, a single key is used for both Encryption and Decryption. It’s comparatively faster than its equivalent Asymmetric Encryption.</p><p>Symmetric Encryption is a kind of computerized algorithm that uses a specific key to secure an electronic message. Its conversion technique follows certain mathematical steps along with a private key, which makes it difficult for a hacker to decrypt. It’s a two-way algorithm where we can decrypt the cipher text using the same private key.</p><p>In this type of encryption, both sender and receiver need to know the secret key which may have some security problems.</p><p>Example of Symmetric Encryption</p><ul><li>Blowfish</li><li>AES (Advanced Encryption Standard)</li><li>RC4 (Rivest Cipher 4)</li><li>DES (Data Encryption Standard)</li><li>RC5 (Rivest Cipher 5)</li><li>RC6 (Rivest Cipher 6)</li></ul><blockquote><strong>Asymmetric Encryption</strong></blockquote><p>We have studied that Symmetric Encryption has a security concern. Here comes Asymmetric Encryption which will help to solve security concern as two different key is used for both Encryption and Decryption. One is the Public key which is used for Encryption and another is the Private key which is used for Decryption.</p><p>Asymmetric encryption is slower than symmetric encryption due to the longer key lengths and the complexity of the encryption algorithms used. In order to maintain security, asymmetric encryption must make it too difficult for a hacker to crack the public key and discover the private key.</p><p>Example of Asymmetric Encryption</p><ul><li>RSA (Ron <strong>R</strong>ivest, Adi <strong>S</strong>hamir, and Leonard <strong>A</strong>dleman)</li><li>DSA (<strong>D</strong>igital <strong>S</strong>ignature <strong>A</strong>lgorithm)</li></ul><p>Now, Let’s dive into coding how both these Encryption techniques will work.</p><blockquote><strong>DES Data Encryption Standard</strong></blockquote><p>DES has been an old traditional way for encryption and decryption. It’s also vulnerable to hackers, therefore its demand has been in decline. Also, the key used to encrypt is very short in length.</p><p>It’s not best where data flows over the network.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfae251b5b108f9a3ec94d676f42e5ab/href">https://medium.com/media/dfae251b5b108f9a3ec94d676f42e5ab/href</a></iframe><blockquote><strong>AES Advanced Encryption Standard</strong></blockquote><p>The enhancement was a must need as <strong>DES</strong> has not been best due to its vulnerability and its updated version <strong>3DES </strong>is relatively slow.</p><p>The Advanced Encryption Standard, or AES, is also called the <strong>Rijndael</strong> cipher.</p><p>AES-128 uses a 128-bit key length to encrypt and decrypt a block of messages, while AES-192 uses a 192-bit key length and AES-256 a 256-bit key length to encrypt and decrypt messages. Each cipher encrypts and decrypts data in blocks of 128 bits using cryptographic keys of 128, 192, and 256 bits, respectively.</p><p>Symmetric, also known as secret keys, ciphers use the same key for encrypting and decrypting, so the sender and the receiver must both know and use the same secret key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebd07d5f8f9946b48c0973bf3ddb7616/href">https://medium.com/media/ebd07d5f8f9946b48c0973bf3ddb7616/href</a></iframe><p>That’s all I have for today. I will be looking forward to putting a more detailed explanation and implementation.</p><h3>Sankhadip Samanta</h3><p><em>Software Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2de3d802e1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload files in Node.JS and React.JS]]></title>
            <link>https://sankhadip.medium.com/upload-files-in-node-js-and-react-js-4708f98e858b?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4708f98e858b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Tue, 29 Sep 2020 06:46:38 GMT</pubDate>
            <atom:updated>2020-09-29T12:33:38.018Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*HjR1IqyGb4NpVOhPviYijQ.jpeg" /><figcaption>Credit: medium.com</figcaption></figure><p>Uploading files in <strong>Single Page Application</strong>(SPA) sometimes becomes challenging. Today we will be implementing how to upload files in the Node.JS server from React.JS.</p><p>It doesn’t matter what framework you are using in the client-side, as far it is JS framework Code Implementation will be the same with some basic knowledge. I hope you have Node.JS’s and React.JS&#39;s basic development knowledge.</p><p>I have already written the same on .NET core web API and React. Please find the following link for that article.</p><p><a href="https://medium.com/nerd-for-tech/how-to-upload-files-in-net-core-web-api-and-react-36a8fbf5c9e8">How to Upload Files in .NET core Web API and React</a></p><blockquote><strong>Create Project</strong></blockquote><p>To create a Node.JS and React project and install the following modules.</p><p><em>In Node.JS</em></p><p>npm i express cors express-fileupload</p><p>npm i -D nodemon</p><p><em>In React</em></p><p>npm i axios</p><p>We will be using Visual Studio Code for both React and Node.JS</p><blockquote><strong>Code</strong></blockquote><p>Let’s setup server API for uploading files from React. Place the below code in your server.js file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9156e0d3185c14afd3cdef4072edec6b/href">https://medium.com/media/9156e0d3185c14afd3cdef4072edec6b/href</a></iframe><p>We are importing all required modules and initialize the express server.</p><p>Then we are setting up our middleware.</p><ul><li><strong>cors</strong> for allowing access to our server from another one.</li><li>file upload for uploading files in the server</li><li><strong>express.static(‘files)</strong> is setting the <strong>public </strong>server’s <strong>files</strong> folder for storing images and enable them to show in front-end.</li></ul><p>Set the app to listen on port 3000</p><p>Now we are creating a post route “/upload” for uploading files into the file system.</p><ul><li><strong>__dirname</strong> returns the root path of our project. We are appending with “/files/” where files will get stored</li><li>We are extracting our files and filename from <strong>req.files.file</strong> where .<strong>file</strong> is the name in your <strong>form body</strong> in React</li><li>Now we are storing the file in the file system using <strong>“express-fileupload”</strong> in-built function <strong>mv </strong>to move the file elsewhere in the server.</li><li>On the basis of the result, we are sending back a response to the front-end.</li></ul><p>Now let’s move to React. Place the following code in App.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d05bcf9b1613b0f7d84107ef5d8460b/href">https://medium.com/media/1d05bcf9b1613b0f7d84107ef5d8460b/href</a></iframe><p>A brief overview of <strong>FormData</strong> here,</p><p>When we make an Ajax request and if that Request contains files, the <strong>FormData</strong> object favors developers a lot. It’s the object to represent HTML form data.</p><p>If we use <strong>HtmlForm</strong> element the for file upload, we do mention <strong>enctype=”multipart/form-data”</strong> in form tag which explicitly specifies it will contain data and files.</p><p>The special features of <strong>FormData</strong> is that network methods can accept <strong>FormData </strong>object as the body and it’s encoded, sent out with <strong>Content-Type: multipart/form-data </strong>which should be while uploading file and data together in ajax request or HtmlForm element.</p><p>And now do <strong>npm start </strong>and go to <a href="http://localhost:3000/"><strong>http://localhost:3000</strong></a>, select file, and upload file. You will find that file inside the <strong>files </strong>folder in the server.</p><p>If you are having any questions, leave a comment.</p><p>Check out the Github repository for source code.</p><p><a href="https://github.com/dev-sankhadip/Node.JS-React-File-Upload">dev-sankhadip/Node.JS-React-File-Upload</a></p><h3>Sankhadip Samanta</h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4708f98e858b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debouncing in React.JS]]></title>
            <link>https://medium.com/swlh/debouncing-in-react-js-83befe93a5ee?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/83befe93a5ee</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[debouncing]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Mon, 14 Sep 2020 03:52:05 GMT</pubDate>
            <atom:updated>2020-09-14T14:26:02.099Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x0d41ns8PTQZz4a3VbMrBg.png" /><figcaption>From <a href="https://dev.to/">https://dev.to/</a></figcaption></figure><p><strong>Debouncing </strong>in Javascript is an exercise to enhance browser performance during any time-consuming computations. If such a method is invoked frequently then it may degrade our web app performance. Debouncing is a programming practice used to ensure that a time-consuming task does not fire so often. In other words, it limits rates at which functions get invoked.</p><blockquote><strong>Application</strong></blockquote><ul><li>Debouncing can be implemented where searching works like when the user will be typing in the search box and the search results will come from the server. There we can hit server API after the user stops typing(after a certain delay). Here if on every change there is frequent server API hit then it will degrade our server performance very much.</li><li>Another application of debouncing is in content-loading webpages like Facebook and Twitter where the user keeps on scrolling. In these scenarios, if the scroll event is fired too frequently, there might be a performance impact, as it contains lots of videos and images. Thus the scroll event must make use of debouncing.</li></ul><blockquote><strong>Implementation</strong></blockquote><p>Let’s go ahead and create a React Project.</p><p>Open the App.js file and replace the following code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/348a2a7e0d3d56ecca9671af6e0c1f65/href">https://medium.com/media/348a2a7e0d3d56ecca9671af6e0c1f65/href</a></iframe><blockquote><strong>Explanation</strong></blockquote><ul><li>debounce function which will do the actual work of delaying invoking function.</li><li>OnChange of the input field, we get event and pass it to the update function as an argument.</li><li>Update calls debounce function with passing 2 arguments (a function and seconds)</li><li>We do <strong>e.persist()</strong> in OnChange because when we will try to access an event inside callback, event’s reference will be nullified and we get undefined. If you try out the above code without <strong>e.persist()</strong>, then you will realize what particular error appears in the console.</li></ul><p>For more information on <strong>e.persist(),</strong> please visit</p><p><a href="https://reactjs.org/docs/events.html">https://reactjs.org/docs/events.html</a></p><ul><li>The general idea for debouncing is:<br> 1. Start with 0 timeout<br> 2. If the debounced function is called again, reset the timer to the specified delay<br> 3. In case of timeout, call the debounced function<br> Thus every call to a debounce function resets the timer and delays the call.</li></ul><p>Here in the above code, after every 1 sec of typing pause, callback function will get executed and will set the value to state, and in between 1 sec if the user types again the timer will be reset again to 0.</p><p>Few points are taken from GeeksForGeeks.</p><p>Check out GitHub repository for source code.</p><p><a href="https://github.com/dev-sankhadip/Debouncing-in-React">dev-sankhadip/Debouncing-in-React</a></p><h3>Sankhadip Samanta</h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83befe93a5ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/debouncing-in-react-js-83befe93a5ee">Debouncing in React.JS</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallel Asynchronous API Call in Python]]></title>
            <link>https://medium.com/swlh/parallel-asynchronous-api-call-in-python-f6aa663206c6?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6aa663206c6</guid>
            <category><![CDATA[asyncio]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[requests-library]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Mon, 17 Aug 2020 04:46:05 GMT</pubDate>
            <atom:updated>2020-09-17T20:58:51.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*6R6elwexUmNnLc1EJJ-t9g.jpeg" /><figcaption>From The Programming Arsenal</figcaption></figure><p>A <strong>synchronous program</strong> is executed one step at a time. Even with conditional branching, loops and function calls, you can still think about the code in terms of taking one execution step at a time. When each step is complete, the program moves on to the next one.</p><p>An <strong>asynchronous program</strong> behaves differently. It still takes one execution step at a time. The difference is that the system may not wait for an execution step to be completed before moving on to the next one.</p><p>Although here we will implement asynchronous program that will execute 15 different instance parallelly rather than waiting for every instance to be completed.</p><p>Let’s jump to the implementation.</p><p>First, we will see how <strong>synchronous </strong>program reacts</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08d4c03df93b66dabeafe3704cdccc10/href">https://medium.com/media/08d4c03df93b66dabeafe3704cdccc10/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*tZt7QJ31xKureoVfccaClw.png" /><figcaption>Sync Program Output</figcaption></figure><p>Here we are calling a API 15 times one by one . One API call starts only after previous API call finishes. If you look at output, it takes 16.67 secs to complete 15 API calls. This is synchronous approach where next process starts when previous process ends. This type approach sometime costs heavy in real time project.</p><p>Now same we will implement same using async approach where we will make 15 API calls parallelly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a226097ddcc6f07743c6e7b0428b087/href">https://medium.com/media/7a226097ddcc6f07743c6e7b0428b087/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*k880BtawjljUNpKa9wR7jA.png" /><figcaption>Async ProgramOutput</figcaption></figure><p>The max time taken to complete 2.45 secs.</p><p>The main advantage of using parallel execution is that code runs more efficiently and saves time.</p><p>This is it. If you are having any doubts, have a comment below</p><p>Check GitHub Repo for source code</p><p><a href="https://github.com/dev-sankhadip/Python-sync-async-task">dev-sankhadip/Python-sync-async-task</a></p><h3>Sankhadip Samanta</h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6aa663206c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/parallel-asynchronous-api-call-in-python-f6aa663206c6">Parallel Asynchronous API Call in Python</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Onion Architecture in Node.JS with Typescript]]></title>
            <link>https://sankhadip.medium.com/onion-architecture-in-node-js-with-typescript-5508612a4391?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5508612a4391</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[repository-pattern]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Tue, 21 Jul 2020 08:45:00 GMT</pubDate>
            <atom:updated>2020-09-17T02:31:36.639Z</atom:updated>
            <content:encoded><![CDATA[<h3>Onion Architecture in Node.jS with Typescript</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jw9V__6jYhm2amP74D_0lw.png" /><figcaption>From Wikipedia</figcaption></figure><h3>What is Onion Architecture ?</h3><p>Onion Architecture is a project structural pattern that favors us with maintainable and testable code for enterprise systems. It enables us to have a different layer for a different level like Model, DA, Service, Controller, View.</p><h3><strong>Advantage :</strong></h3><ul><li><strong>Loose Coupling</strong></li><li><strong>Better maintainability at a different layer</strong></li><li><strong>Better testability as projects are divided into layers</strong></li><li><strong>Modulour concept</strong></li></ul><h3><strong>The Layers :</strong></h3><ul><li><strong>DA Layer: </strong>DataAccess Layer which will specifically deal with Database operation like Read, Insert, Update, and Delete.</li><li><strong>Service Layer: </strong>This layer will contain our business logic for every api.</li><li><strong>Controller Layer: </strong>This layer will have all routes defined and call to a specific service layer’s function.</li><li><strong>Types: </strong>This layer will have all types, interface defined.</li></ul><p>We will be implementing <strong>Onion Architecture</strong> in <strong>Node.JS</strong> having an approach towards the OOPs concept. We will use <strong>Typescript </strong>here as it provides many more features for OOPs.</p><h3><strong>Database Setup :</strong></h3><p>As we will be using MySQL database, you should have phpMyAdmin installed then open</p><ul><li>Create a database named <strong>onion</strong></li><li>Inside <strong>onion </strong>create a table named <strong>student </strong>with the following query</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cb8943efa85d2c80ec82fd4cfdd3846/href">https://medium.com/media/7cb8943efa85d2c80ec82fd4cfdd3846/href</a></iframe><h3><strong>Project Setup :</strong></h3><p>Install <strong>Typescript </strong>globally in your system with this command</p><p><strong>npm i -g typescript</strong></p><p>Open your command prompt, go to the project directory, and do <strong>tsc –init. </strong>This will create a <strong>tsconfig.json </strong>file which contains a Typescript configuration for this project.</p><p>Place the following code in <strong>tsconfig.json</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93ddfa47345067fb92c57dc9c40a6b57/href">https://medium.com/media/93ddfa47345067fb92c57dc9c40a6b57/href</a></iframe><p>Now do <strong>npm init </strong>and let’s install couple of package.</p><p><strong>npm i dotenv express mysql shortid</strong></p><p><strong>npm i -D @types/express @types/mysql @types/shortid typescript</strong></p><p>As we are using typescript, <strong>@types/package </strong>will have types defined of all specified packages. Now install <strong>ts-node-dev</strong>, it will watch changes in the project.</p><p><strong>npm i -D ts-node-dev</strong></p><p>Change scripts command to following twos</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*sSx3lq8HURoE7V3uPdHsBA.png" /><figcaption>package.json scripts</figcaption></figure><ul><li><strong>npm run dev</strong> will start the server and watch for file changes</li><li><strong>npm run build </strong>will build the production version of our project in es5 as the Node.JS engine doesn’t understand typescript.</li></ul><p>We will use <strong>MySql </strong>Database. So, create a <strong>.env</strong> file and have database server’s <strong>USER</strong>, <strong>HOST</strong>, <strong>PASSWORD, </strong>and <strong>DATABASE </strong>defined like the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/748b6b791b4cc87fddda54f121f4673a/href">https://medium.com/media/748b6b791b4cc87fddda54f121f4673a/href</a></iframe><p>Now create a folder named <strong>src, </strong>inside create folders named <strong>DA, routes, service, types, </strong>and create a file <strong>server.ts</strong>, our project entry file. The structure will be like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*FYwMcWIf8T23J5wwfB9dAw.png" /><figcaption>File Structure</figcaption></figure><p>Here we finish our project setup, now let’s move to the implementation part.</p><blockquote><strong>Implementation</strong></blockquote><ul><li>Let’s create <strong>DBManager.ts</strong> and <strong>DBConnection.ts</strong> inside <strong>DA</strong> folder</li><li>Create <strong>types.ts</strong> inside <strong>types </strong>inside types folder.</li></ul><p>Define an interface <strong>IDBManager, IStudent, </strong>and type <em>MySqlType </em>inside <strong>types.ts.</strong> <strong>IDBManager</strong> will have our DBManager’s function’s types defined. Place the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50be9614be39c4dfc1f9d1bf4c09a96a/href">https://medium.com/media/50be9614be39c4dfc1f9d1bf4c09a96a/href</a></iframe><p>All these functions will receive a <strong>query</strong> of <em>string </em>type and <strong>paramCollection</strong> as <strong>Array</strong> of the <em>number</em>, <em>string</em>, <em>boolean </em>and <em>undefined </em>type as argument and returns <strong>Promise</strong> of <em>MySqlError </em>or <em>any </em>type. Although <strong>ReadData </strong>function will have paramCollection as Optional Parameter because it may have a select query without where clause.</p><p>Now go to <strong>DBConnection.ts</strong>, place the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc502f66ae19594e3d6549a710ef0549/href">https://medium.com/media/dc502f66ae19594e3d6549a710ef0549/href</a></iframe><p>Now go to <strong>DBManager.ts</strong>, place the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0edf8d96561b05846fbfc5f924c63a4/href">https://medium.com/media/b0edf8d96561b05846fbfc5f924c63a4/href</a></iframe><p>These functions will <strong>reject</strong> if there is any <em>error </em>otherwise <strong>resolve</strong> if the query successfully executes. In this project, we will implement a simple CRUD operation for the student database.</p><p>Create a file <strong>StudentDA.ts</strong> inside the <strong>DA </strong>folder and have the following code. Let me describe what this file contains instead of code. Although you will get Code Implementation in my GitHub repo.</p><p>We will have a class named <strong>StudentDA</strong> which will extend <strong>DBManager</strong> class. The followings are functions defined in StudentDA class. DBManager’s functions return a promise, we will use <em>async/await</em> with <em>try/catch</em> in the calling function. On successful execution of a query, <strong>StudentDA’s </strong>will return a result or on error, it will throw an error to it’s calling function or service layer.</p><ul><li><strong>GetStudents: </strong>This function will fetch all students’ records. It passes a SQL query to the ReadData method of DBManager class. On successful execution of a query, it will return the result, and or on error, it will throw an error to it’s calling function or service layer.</li><li><strong>GetStudent(id) : </strong>This function will fetch single student’s record. It receives the id of <em>string </em>type from the service layer or it’s calling function. It passes SQL query with the student’s id as paramColection as Array to ReadData method DBManager class.</li><li><strong>CreateStudent(data:IStudent)</strong> <strong>:</strong> This function will create student record. It receives a student’s records as <em>IStudent </em>type. It passes SQL query with student’s details as paramCollection as Array to InsertOrUpdateData method of DBManager class.</li><li><strong>UpdateStudent(data:IStudent) : </strong>This function will update record of a single student. It receives a student’s record of <em>IStudent </em>along with id. It passes SQL query with student’s details as paramCollection as Array to InsertOrUpdate method of DBManager class.</li><li><strong>DeleteStudent(id:string) : </strong>This function will delete a single student record. It receives the student’s id. It passes SQL query with student’s id as paramCollection as Array to DeleteData method of DBManager class.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/664ad801a5ce8008b71565d014e08efd/href">https://medium.com/media/664ad801a5ce8008b71565d014e08efd/href</a></iframe><p>Now Create <strong>index.ts</strong> file inside the DA folder which will be our root or common file for exporting all modules from the DA folder. Import <strong>StudentDA </strong>class and export it from <strong>index.ts</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*q19WU5Nn0mgPLWgaqShh_g.png" /><figcaption>index.ts in DA folder</figcaption></figure><p>Now create <strong>student.service.ts </strong>inside the service folder. This file will contain all business logic. Here we will not write any business logic although we will use it for taking data from routes and passing to the <strong>DA </strong>layer. Following is the code for <strong>student.service.ts.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cdb1ff4a2e7dec03d94c802cc4915e1/href">https://medium.com/media/8cdb1ff4a2e7dec03d94c802cc4915e1/href</a></iframe><p>Now create <strong>index.ts</strong> inside the service folder, import <strong>student.service.ts,</strong> and export it. Any file you will create inside the service folder import in index.ts and export fro here. It is applicable for the DA and routes folder also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*6PJIGBe1VmgW_Pp4iseoaw.png" /><figcaption>index.ts inside service folder</figcaption></figure><p>Now create <strong>student.routes.ts</strong> inside the routes folder and paste the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b16c1905a2ac1d1f04aad033e0f670f5/href">https://medium.com/media/b16c1905a2ac1d1f04aad033e0f670f5/href</a></iframe><p>What it does actually it receives two parameters <strong>route</strong> and <strong>studentService</strong> object and defines all routes accordingly. From every route, we call their corresponding service function and get the result.</p><p>Now open <strong>server.ts</strong>, main entry file of server. Paste the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4179c355e791dd80914e0d20927d701e/href">https://medium.com/media/4179c355e791dd80914e0d20927d701e/href</a></iframe><p>We are importing all required packages and modules in <strong>server.ts</strong>.</p><p>Here we will be using dependency injection by passing <strong>DA </strong>and service to <strong>service </strong>and <strong>controller </strong>layer. By this process, all the modules stay in loose coupled. Modules are not dependent on one another.</p><p>In the <strong>StudentRouter </strong>function, we are passing the router and <strong>studentService</strong> object which again takes the <strong>StudentDA </strong>object in the constructor.</p><p>Our project is setup. Open the command prompt and navigate to the project directory.</p><p>There is two scripts to run <strong>dev</strong> and <strong>build.</strong></p><p>When we will be developing our project, we will use <strong>npm run dev.</strong></p><p>When we will deploy our project to production, we will use <strong>npm run build</strong></p><p>Now run <strong>npm run dev</strong>, hit every API from POSTMAN. You will get the respective result.</p><p>And that’s the end.</p><p>I have tried the best to explain. Although if you guys have any doubts please comment down or connect me.</p><p>Check put GitHub repo for source code</p><p><a href="https://github.com/dev-sankhadip/Onion-architecture-in-node.js">dev-sankhadip/Onion-architecture-in-node.js</a></p><h3>Sankhadip Samanta</h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5508612a4391" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LINQ API in C#]]></title>
            <link>https://sankhadip.medium.com/linq-api-in-c-44fb9618447c?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/44fb9618447c</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[linq]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Fri, 10 Jul 2020 04:42:50 GMT</pubDate>
            <atom:updated>2020-09-19T09:15:51.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*colH3sd-reoTGOmxFDED8g.jpeg" /><figcaption>LINQ API</figcaption></figure><p><strong>Language-Integrated Query (LINQ)</strong> is a powerful query language introduced with .Net 3.5 &amp; Visual Studio 2008.</p><h3><strong>What is LINQ</strong></h3><p><strong>LINQ </strong>API is a query syntax kit at the language level in C# and VB.NET to retrieve data from different sources(database). If we are using LINQ API, we don’t need to worry about data sources like ADO.NET, SQL, and many other databases. LINQ Query results in objects. Specifically, it lets us stay in an Object-Oriented Approach irrespective of Data Sources.</p><h3>Standard Query Operators</h3><p>Standard Query Operators are methods defined for IEnumerable and IQueryable types. There are more than 50 operators available in the LINQ API list which make code more concise and readable.</p><p>While using the LINQ API, we have two ways to implement them</p><ul><li>Query</li><li>Method</li></ul><p>Although syntax written in Query is converted in Method Syntax at compile time. Today we will look into some Query Operator to get familiar with LINQ API implementation.</p><p>For more detailed information about LINQ API visit</p><p><a href="https://docs.microsoft.com/en-us/dotnet/standard/using-linq">https://docs.microsoft.com/en-us/dotnet/standard/using-linq</a></p><blockquote><strong>Implementation</strong></blockquote><ol><li><strong>Where</strong></li></ol><ul><li><em>Query</em>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*_TKDLel8PfFvdkVknA3cZg.png" /><figcaption>Where in Query Syntaxt</figcaption></figure><ul><li><em>Method:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*F9sKaTi1yoHxyBFCnOFIBg.png" /><figcaption>Where in Method Syntax</figcaption></figure><p>2. <strong>OfType</strong></p><ul><li><em>Query:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*4ej3aoxX5cppo3qL55MoKg.png" /><figcaption>OfType in Query Syntax</figcaption></figure><ul><li><em>Method:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*FR6MOkPH7h130hgCw_dQbQ.png" /><figcaption>OfType in Method Syntax</figcaption></figure><p>3. <strong>OrderBy</strong></p><ul><li><em>Query:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*gowwNZyjrwAgCCliEuzGLQ.png" /><figcaption>OrderBy in Query Syntax</figcaption></figure><ul><li><em>Method:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*Y7v1LN5sl32Fb9p04c0KIg.png" /><figcaption>OrderBy in Method Syntax</figcaption></figure><p>4. <strong>All</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*fpb4D8WToJpBItzYDPcWhA.png" /><figcaption>All Operator Implementation</figcaption></figure><p>5. <strong>Any</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*ZpTMrKLjqA9mblBo3Eyrog.png" /><figcaption>Any Operator Implementation</figcaption></figure><p>6. <strong>Count</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*s0Zz3oimxioq9HG1a9wukg.png" /><figcaption>Count Operator</figcaption></figure><p>7. <strong>Intersect</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*BeY73hbCVlhNRt_7-B1HWg.png" /><figcaption>Intersect Operator</figcaption></figure><p>I have not imported System, System.Collections.Generic and System.Linq in the last couple of operators. But do write it, otherwise, it will throw compile-time error.</p><p>So, that’s some LINQ API implementation in C#. LINQ has been a great way to write code in a more concise, readable, and maintainability manner in C#.</p><p>If you are having any questions, leave a comment.</p><p>Also find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><h3>Sankhadip Samanta</h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44fb9618447c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Upload Files in .NET core Web API and React]]></title>
            <link>https://sankhadip.medium.com/how-to-upload-files-in-net-core-web-api-and-react-36a8fbf5c9e8?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/36a8fbf5c9e8</guid>
            <category><![CDATA[net-core-3]]></category>
            <category><![CDATA[single-file-component]]></category>
            <category><![CDATA[webapi]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[file-upload-in-net-core]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 06:47:16 GMT</pubDate>
            <atom:updated>2020-09-12T03:04:21.814Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Upload Files in .NET core Web API and React</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VsfOU78JZ2XyMEp-cgj-iQ.jpeg" /></figure><p>File Upload in <strong>SPA</strong>(Single Page Application) sometimes raises more stubborn than usual. Today we will be implementing how to upload files in .NET core Web API from React.</p><p>It doesn’t matter which framework you use in the client-side, as far it’s a <strong>JS </strong>Framework code implementation will be the same with little basic knowledge. Although we will be uploading files synchronously in .NET core.</p><blockquote><strong>Create Project</strong></blockquote><p>Do create a .NET core Web API project and React project.</p><p>We will be using Visual Studio Code for React and Visual Studio for .NET core.</p><blockquote><strong>Code</strong></blockquote><p>First let’s setup <strong>CORS </strong>in .NET core for allowing making <strong>HttpRequest </strong>from<strong> </strong>React.</p><p>In <strong>startup.cs</strong> file, inside <strong>ConfigureServices </strong>method add this following service which will create <strong>CORS </strong>policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*qIm308t_F0zd_xq1I2IxOg.png" /><figcaption>CORS Policy</figcaption></figure><p>Now use this CORS policy inside the <strong>Configure</strong> method. Place <strong>UseCors</strong> in correct sequence otherwise, it will not work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*XDN82ZucI6TAdzq1C7eltw.png" /></figure><p>Now Create a Model <strong>FileModel.cs</strong> inside the Model folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*_KkaQFxzl27cP97OEi9TEA.png" /><figcaption>Model</figcaption></figure><p>We will be able to access values sent through HttpRequest using Model Binding. Here we are using <strong>IFormFile</strong> interface to access file sent in <strong>HttpRequest</strong>. Model Binding in ASP.NET core automatically maps data in specified model from <strong>HttpRequest.</strong></p><ul><li>For uploading single file</li></ul><pre>public IFormFile FormFile { get; set; }</pre><ul><li>For uploading multiple files</li></ul><pre>public List&lt;IFormFile&gt; FormFiles { get; set; }</pre><p>Check out for more information about Model Binding</p><p><a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-3.1">Model Binding in ASP.NET Core</a></p><p>Here we are going for Single File Upload. Now Create a Controller <strong>FileController.cs</strong> and place following code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*sqWpjyNIzI2QYnjKSNoHAQ.png" /><figcaption>FileController.cs</figcaption></figure><p>Create <strong>wwwroot</strong> folder inside project folder where we will put our uploaded files.</p><p>We are using <strong>FromForm</strong> because it will have <strong>Content-Type : multipart/form-data </strong>or <strong>application/x-www-form-urlencoded</strong></p><p>Now let’s move to React Part</p><p>Create a file <strong>FileUpload.js </strong>inside <strong>src</strong> folder. This file will contain all our GUI and file uploading logic.</p><p>Install <strong>axios</strong> for making <strong>HttpRequest</strong> to server and place following code inside <strong>FileUpload.js .</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*II3FrEHYZH-s0_IVxnas2w.png" /><figcaption>FileUpload.js</figcaption></figure><p>A brief overview about <strong>FormData</strong> here,</p><p>When we make Ajax request and if that Request contains files, <strong>FormData</strong> object favors developers a lot. It’s the object to represent HTML form data.</p><p>If we use <strong>HtmlForm</strong> element the for file upload, we do mention <strong>enctype=”multipart/form-data”</strong> in form tag which explicitly specifies it will contain data and files.</p><p>The special features of <strong>FormData</strong> is that network methods can accept <strong>FormData </strong>object as body and it’s encoded, sent out with <strong>Content-Type : multipart/form-data </strong>which should be while uploading file and data together in ajax request or HtmlForm element.</p><p>Now import <strong>FileUpload</strong> component inside App.js and use it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*u7SAi8RYJIORa3E8KsQ5ow.png" /><figcaption>App.js</figcaption></figure><p>And now do <strong>npm start </strong>and go to <a href="http://localhost:3000/"><strong>http://localhost:3000</strong></a> , select file and upload file. You will find that file inside <strong>wwwroot </strong>folder in server.</p><p>If you are having any questions, leave a comment.</p><p>Check out the Github repository for source code</p><p><a href="https://github.com/dev-sankhadip/.NET-core-and-React-File-Upload">dev-sankhadip/.NET-core-and-React-File-Upload</a></p><h3>Sankhadip Samanta</h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36a8fbf5c9e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Simple Notepad in Electron.JS]]></title>
            <link>https://sankhadip.medium.com/build-a-simple-notepad-in-electron-js-b6f84e5601c4?source=rss-e7ab02b108a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6f84e5601c4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[notepad]]></category>
            <category><![CDATA[desktop-app]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[electronjs]]></category>
            <dc:creator><![CDATA[Sankhadip Samanta]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 15:27:34 GMT</pubDate>
            <atom:updated>2020-09-18T02:54:09.366Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQ6uO-UzGs6HFLKIekS15Q.png" /></figure><h3><strong>“If You Can Build a Website, You Can Build a Desktop App”</strong></h3><blockquote><strong>Required</strong></blockquote><ul><li>Basic knowledge of HTML, CSS, JS, Node.JS, Electron.JS</li></ul><p>Today we are going to develop a Simple Notepad in Electron which will be having the following features</p><ul><li>Open a file, change and save it in the same path</li><li>Open recent files — Keeps record of previously opened files</li></ul><blockquote><strong>Create Project</strong></blockquote><p>Let’s do <strong>npm init</strong> and do the following. It will create a <strong>package.json</strong> file which will contain out project’s information.</p><p>We will be using <strong>electron </strong>and<strong> fs-extra </strong>modules. We will be using <strong>fs-extra</strong> instead of <strong>fs </strong>node.js built-in module because it favors us with more features.</p><p>So let’s install the <strong>electron</strong> and <strong>fs-extra.</strong></p><ul><li><strong>npm i -D electron</strong></li><li><strong>npm i fs-extra</strong></li></ul><p>Open <strong>package.json</strong> and inside scripts remove <strong>test</strong> command add to <strong>start</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*riTqxt_Xq-FFDHMjeH_gCw.png" /><figcaption>package.json file</figcaption></figure><p>Our folder structure should be like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*h8o9IgtGtTFyfNSJLHVAmQ.png" /><figcaption>Folder Structure</figcaption></figure><p><strong>index.js</strong> is our project’s main entry file. The <strong>asset</strong> folder will contain HTML, CSS, and JS files for GUI. the <strong>lib</strong> folder will contain our logic for opening, saving, keeping open files records, opening dialog box, etc.</p><p>Open <strong>index.js</strong>, our main entry file, and import the following modules</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*s8moSmBsQ8oQbxYa7jG_AQ.png" /><figcaption>Import Module</figcaption></figure><p>Then we will add a listener to the app which will create a browser instance and render the HTML file as GUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*vYcyCXm60--1Mt-swiF_IA.png" /></figure><p>When the app will be ready <strong>build_app</strong> function will execute which we will create by ourselves.</p><p>Now inside the <strong>asset</strong> folder,</p><ul><li>Create a file <strong>index.html</strong> which will contain our view for <strong>Notepad</strong></li><li>Create a folder named <strong>JS</strong> and create a file <strong>script.js</strong> inside the <strong>JS</strong> folder which will contain logic for printing file content in HTML, Fire event on save call.</li></ul><p>Now place following code inside <strong>index.html</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IPpYWiIy-Q1rshYIpOkZAA.png" /><figcaption>index.html file</figcaption></figure><p>Folder structure till now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*GRKv6ONTm2EaiKZUbVcq2g.png" /><figcaption>Folder Structure</figcaption></figure><p>Now open index.js, create <strong>build_app</strong> function which will make browser instance and render <strong>HTML</strong> files. Place the following code inside the <strong>build_app</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*9BEadrobOscqRlq8UFOX8Q.png" /></figure><p>Go to the project directory, run <strong>npm start, </strong>and certainly you have basic knowledge of developing Desktop App in electron.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvVEtdI5eROxWvyBmNlylw.png" /></figure><p>Now we will be adding our custom menu instead of existing or default one that you can use in the above image<strong>( File, Edit, View, Window, Help ).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*HbnIBBEOoD9VaTL7XxiLjQ.png" /></figure><p>Now do <strong>npm start</strong>, you will notice menu <strong>File</strong> and on click of it you will notice <strong>Open File… and Open recent…</strong></p><p>Onclick of that there is console.log in command prompt. So it’s working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gr5Yx7OHGDPeNuy3qG_nTQ.png" /></figure><p>Now we will be implementing <strong>Open File</strong> functionality. Open <strong>script.js, </strong>place the following code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*B0Dg20KYjQ8rO9Xe7WTO1g.png" /></figure><p>What it does basically, it imports <strong>ipcRenderer</strong> from <strong>electron</strong> which will keep listening for the event from the main process for getting file data and it will set file data in textarea and also set file path in <strong>path</strong> variable.</p><p>Inside <strong>lib</strong> folder, create a file <strong>FileManager.js</strong> which will contain logic for file open dialog, open a recent file, saving history, read files. Import the following modules inside <strong>FileManager.js </strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*XQ-sT9nXaGR8Q6-0KXgSQg.png" /></figure><p>Now create a class <strong>FileManager, </strong>add a constructor which will receive <strong>app_window</strong> object from <strong>index.js</strong> file. Initialize <strong>app_window, homeDirectory, historyPath, username</strong> to class level like following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*sdPs1FpjyFRf_cG4jK8eAg.png" /></figure><p>Now create a function <strong>saveHistory</strong> inside <strong>FileManager</strong> class which will take file path as an argument and save all opened files inside <strong>historyPath </strong>as JSON data. Place the following code inside <strong>saveHistory</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*dpZjtfn8yCK_pDXsK4A_vA.png" /></figure><p>Now create another function <strong>openFileWindow</strong> which will actually open a window for selecting a file. Place the following code inside <strong>openFileWindow</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*gLsmeMFQS7pUMDB8ktqGbg.png" /></figure><p>Now go to <strong>index.js</strong>, import <strong>FileManager</strong> class from <strong>FileManager.js,</strong> and create an object passing <strong>app_window</strong> object. After this, update the menu_list array with the following code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*pNAN39vdpd6UVj6WtdXfzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*pQc37myeYGW9K1xIpc2QQA.png" /></figure><p>Now do <strong>npm start</strong> and click on <strong>File</strong> then <strong>Open File…</strong> label and select a file from the file system. You can now see file content in our brand new Notepad.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*NXusjHF9RVsa0fC-XK2urg.png" /></figure><p>Now we will implement saving files after changing content. Add the following code in <strong>script.js</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*Qu3dc9wQjqeR6GCZf5P8_A.png" /></figure><p>It will fire event to the main process when the <strong>ctrl+s </strong>button clicked for saving data after changing.</p><p>Let’s add a listener in the main process to listen above event in <strong>index.js</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*Ce_uCqUmQ-KDZTnROB1_MQ.png" /></figure><p>Now open a file, change content, and save it. You will see changes next time you open it again.</p><p>After the above one, we will fetch all recently opened files and add them in <strong>Open recent files… </strong>submenu.</p><p>Open <strong>FileManager.js</strong>, add <strong>readHistory</strong> function with the following code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*jBeFuhLq3jYCLbXUGAgLfw.png" /></figure><p>Now open <strong>index.js</strong> get open recent files Join data from which we will create a submenu of <strong>Open Recent Files… </strong>Add the following code inside the <strong>build_app</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFRg1XhU-X6gD1iFwcLBDw.png" /></figure><p>Add <strong>async</strong> before <strong>build_app</strong> function. Update <strong>menu_list</strong> with the following code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*l2ttYkhFhDL2ZztOCs2UTw.png" /></figure><p>Now do <strong>npm start</strong> and there will be a recently opened file’s path in the submenu of Open Recent Files.</p><p>After this, we will be implementing on click of any history in the submenu that a particular file should open in our Notepad pro. For that create a function <strong>openRecentFile</strong> in FileManager class inside FileManager.js. Place the following code inside <strong>openRecentFile</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*02Lp7MQ-EBo2aLBcKhy-HA.png" /></figure><p>This function will be executed when we will click on historical record in the submenu. It will take the file path as an argument, read that file’s content, save that in history, and fires event with the file’s content to renderer process means to GUI <strong>script.js</strong> file.</p><p>Now do <strong>npm start </strong>and test with the following features</p><ul><li>Open file</li><li>Save file after changing content</li><li>History in Open Recent File submenu</li><li>Onclick of any path history, that file’s content opens</li></ul><p>And our brand new Notepad is working perfectly.</p><p>Check out the Github repository for Source Code</p><p><a href="https://github.com/dev-sankhadip/ElectronNotepad">https://github.com/dev-sankhadip/ElectronNotepad</a></p><p>So, if you guys are having any doubts at any point in this tutorial, please comment down. I will give you a quick reply.</p><p>Also, visit my blog. If you want to publish your article, <strong>BlogMarch </strong>is an option.</p><p><a href="https://blogmarch.com/"><strong>https://blogmarch.com/</strong></a></p><h3><strong>Sankhadip Samanta</strong></h3><p><em>Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch</em></p><p>Find me on <a href="https://www.linkedin.com/in/sankhadip-samanta-7bb891180/">Linkedin</a> 😃 and <a href="https://github.com/dev-sankhadip">Github</a> 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6f84e5601c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>