<?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 Charchithowitzer on Medium]]></title>
        <description><![CDATA[Stories by Charchithowitzer on Medium]]></description>
        <link>https://medium.com/@charchithowitzer?source=rss-a43c98085610------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FnxVfUlXqrlo4Khj</url>
            <title>Stories by Charchithowitzer on Medium</title>
            <link>https://medium.com/@charchithowitzer?source=rss-a43c98085610------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:47:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@charchithowitzer/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[My Internship Experience At FASAL — GROW MORE GROW BETTER]]></title>
            <link>https://charchithowitzer.medium.com/my-internship-experience-at-fasal-grow-more-grow-better-f3dd3a28efd7?source=rss-a43c98085610------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3dd3a28efd7</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[internships]]></category>
            <dc:creator><![CDATA[Charchithowitzer]]></dc:creator>
            <pubDate>Mon, 01 May 2023 11:40:36 GMT</pubDate>
            <atom:updated>2023-05-01T11:40:36.328Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Internship Experience At FASAL — GROW MORE GROW BETTER</h3><p>I still remember when companies were coming to college in the placement drives and I was not interested in placements because none of the organizations didn’t arouse my interest. I was even debarred from the placement drive for not applying in any of the drives. But then my roommate and one of my friends got placed. This made me start applying for placements. Then came FASAL for the placement for a position of Product Engineer, I was not sure about the profile but I still applied as it was not a developer profile. I didn’t hate being a developer but I did not have the right skills for the profile or the interviews that’s why till now I have avoided any Developer profiles. But what I liked about FASAL is that they are not just another service-based company, they are solving a real-world problem, and that’s what gave me the KICK! So I applied for the job position.</p><h3>A long waiting period</h3><p>I applied for the post in April, I also applied for one more company. Then May 20th was our last day at college and to this day there was not a single E-mail from the placement cell. I still remember it was the 4th of June when a mail arrived from the Placement cell that we need to create a simple movie search website for the shortlisting….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*87-l7dSIo7tq574HH64lzw.jpeg" /></figure><p>Yet another profile that wants me to make a web application and here I am who has never written a single line in Javascript or HTML in my entire college years. I mainly worked with Python, C++, and embedded C for Microcontrollers. This was a big bummer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VU8CxHekouFJwyqd3CUEmg.png" /></figure><p>But let us face it this was my only chance of getting placed in an organization that I wanted to work in. So I decided that whatever it takes I had to get this one cracked. I started learning about basic web development and in just 5 days, I learned, built, and delivered my website.</p><h3>The BIG Announcement</h3><p>Finally, the E-mail arrived that I was shortlisted for the Interview and technical rounds. I prepared for them very rigorously and learned everything about Javascript from blogs, and JS Confs. I successfully cleared all the interview rounds and got selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2F_vUY-JDP0VEXjbx3xUuQ.jpeg" /></figure><p>Now it has been 5 months since I started working at FASAL and I already developed some important features like Bulk Upload Operation, User session and Page Tracking, and Farm Management, and fixed many bugs in this internship period. My Internship is extended from December to May and I will be working as a Full Time Employ very soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3dd3a28efd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Requests, Routing and Middlewares Explained | Guide to NodeJS Basics — Part 2]]></title>
            <link>https://medium.com/fasal-engineering/requests-routing-and-middlewares-explained-guide-to-nodejs-basics-part-2-f6b0674c8cb5?source=rss-a43c98085610------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6b0674c8cb5</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Charchithowitzer]]></dc:creator>
            <pubDate>Tue, 13 Sep 2022 12:16:10 GMT</pubDate>
            <atom:updated>2022-09-13T12:18:17.957Z</atom:updated>
            <content:encoded><![CDATA[<h3>Types of Middleware, Next() and Body Parser Explained | Guide to NodeJS Basics — Part 2</h3><p>In the <a href="https://medium.com/fasal-engineering/requests-routing-and-middlewares-explained-guide-to-nodejs-basics-part-1-4af59de88355">previous article</a>, we already learned about Requests, Routing and Middleware. In this part let&#39;s get a quick understanding of <strong><em>next()</em></strong>, <strong><em>body-parser,</em></strong> and types of middleware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzFijwjllhQog9ylOZx85A.png" /></figure><h3>NEXT(), as the name indicates…</h3><p><strong>next() </strong>function executes the <strong>next</strong> piece of middleware <strong>inline</strong>. So just as we performed next earlier can we also pass next in the controller action middleware (that actually sends the response), but we really don’t use next() in those as there is no point in using the <strong>req res</strong> after the request is fulfilled. <em>P.S. You can do that if you really want to run another middleware and perform some action.</em></p><p>All the middleware run in the order that you define them. It&#39;s time to tinker with the code once more.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8a6a43032893765ee3df39e1789ca26/href">https://medium.com/media/e8a6a43032893765ee3df39e1789ca26/href</a></iframe><p>save, reload, refresh.</p><p><em>Note two things here, </em><strong><em>1:</em></strong><em> our home page route now has an argument </em><strong><em>next</em></strong><em> and we are calling it in line 8. </em><strong><em>2</em></strong><em>: the middleware is now being called at line 16</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*sDGQ1_UGpJibPYniqVkPAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ncZ-Z5CGfVxAA72lHR74LQ.png" /></figure><p>The homepage route is being called first and now the next() is allowing our script to execute the next available middleware which is in line 16 ( <strong><em>app.use (myMiddleware)</em></strong><em> </em>). It clears the fact that middlewares are called in the sequence in which they are defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*s7xaBWWrKuxb4I745Gp9Sw.png" /></figure><p>Let&#39;s do something interesting with middleware now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db2a511360204796d1e010e1890b9558/href">https://medium.com/media/db2a511360204796d1e010e1890b9558/href</a></iframe><p>Here our home page routing function takes an extra parameter <strong>checkAuthentication</strong> function. As this function is passed before the home page response function (arrow function just next to it in the arguments). It gets called first and inside the <strong>checkAuthentication </strong>we are again calling<strong> next(), </strong>this enables the next function to be invoked which in this case is the<strong> arrow function. The output</strong> looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*c8ovwZv7UdskqUHjSWKvzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YxmYKobwWCuLwGosSMn4KQ.png" /></figure><p>And it was the expected outcome.</p><p><em>Notice that we are still calling the myMiddleware before anything. This is because any global middleware that we would like to run before anything else happens must be executed first (what is the use? we will learn about this with an example later)</em></p><h3>One common misconception</h3><p>One very common misconception is that the <strong>next()</strong> calls the next inline middleware and just exits from the current function. That is not the case, let&#39;s understand with the same example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf0865bee32b8dd8ce5dd1a56ce28b3f/href">https://medium.com/media/cf0865bee32b8dd8ce5dd1a56ce28b3f/href</a></iframe><p>In the <strong>checkAuthentication</strong> middleware we have deleted the else block and written something to the console, with the response still there, so if <em>query.user = true</em> then we are exiting from this callback and entering into the next middleware, no?</p><h4>save, reload, refresh</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*ExUyezxNaslc6LLN95gL9Q.png" /></figure><p><em>What the actual F… Hehe.</em></p><p>So <strong>next()</strong> does not work as we expected. Sure, it does move the program counter to the next middleware but once the next function finishes execution, the program counter (it is a pointer that points to the next executing function) returns to the previous middleware and continues its execution. And that’s what we are seeing here. How to prevent that?</p><p>Just return from the function and call <strong>next(). </strong>Modify your <strong>checkAuthentication</strong> like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1d4b23d8b5242a96debce17747b022a/href">https://medium.com/media/b1d4b23d8b5242a96debce17747b022a/href</a></iframe><p>save, reload, refresh and see the result by yourself.</p><p>Remember how I said that we are keeping our original <em>myMiddleware</em> at the top of the execution stack and why we would want it with some global middleware? Now we are going to understand it with an example.</p><p>By the do check out the below article as well,</p><p><a href="https://medium.com/fasal-engineering/how-does-a-web-api-works-understanding-and-usage-4ef1c457a5de">How does a Web API works ?| Understanding and Usage</a></p><h3>bodyParser()</h3><p>First I want you to create 2 files <em>mypage.html</em> and <em>mypage.js</em>, they should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c09d8163ccb7b50ab4c4631d203ed655/href">https://medium.com/media/c09d8163ccb7b50ab4c4631d203ed655/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c908ad76af6abff2d0492f1a08d16a15/href">https://medium.com/media/c908ad76af6abff2d0492f1a08d16a15/href</a></iframe><p>In our HTML we are getting <strong>Axios</strong> (learn more <a href="https://axios-http.com/docs/intro">here</a>) for sending our HTTP requests to the server</p><p>Install <strong>‘cors’ </strong>(learn more <a href="https://expressjs.com/en/resources/middleware/cors.html">here</a>)<strong> </strong>using the command,</p><pre>npm i cors</pre><p>Then edit your <strong>index.js</strong> (which were using earlier) like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4e2ab4ebb2963e391e4880b7c050b1e/href">https://medium.com/media/e4e2ab4ebb2963e391e4880b7c050b1e/href</a></iframe><p>For now, ignore lines 2 and 5 (we will learn more about them later). Reload your <strong>index.js</strong> and refresh your webpage. See the output on the console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*xK1hnQYtOaczLsTPLCgGGw.png" /></figure><p>Where is the body of the request that I sent with it? And why is it undefined? Clearly, the body was set in the request. Let’s use a middleware called <strong>bodyparser. </strong>To install it just type,</p><pre>npm i bodyparser</pre><p>And now modify your <strong>index.js</strong> like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce2da1732c22fd621d74b88f590f9274/href">https://medium.com/media/ce2da1732c22fd621d74b88f590f9274/href</a></iframe><p>Now save, reload, refresh anddd…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*2Eo-_hu2WDZBMsHo5gpxuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmtnZxMCDA7U8KEsmzMfEA.png" /></figure><p>Before reading about the utilities of body-parser do check out this amazing browser API,</p><p><a href="https://medium.com/fasal-engineering/image-lazy-loading-using-browsers-intersection-observer-api-a-step-by-step-guide-with-examples-b1a867614e8">Image Lazy Loading Using Browser’s Intersection Observer API — A Step by Step Guide with Examples</a></p><h4>What does body-parser middleware do?</h4><p><a href="https://expressjs.com/en/resources/middleware/body-parser.html"><strong><em>body-parser</em></strong></a><strong><em> extracts the entire body portion of an incoming request stream and exposes it on </em></strong><strong><em>req.body.</em></strong></p><p>And what did cors do? Actually, we are not hosting our client on the same server and this is a security issue that prohibits websites to fetch something from a different URL.</p><p>This can easily be overcome by setting <strong>origin and credentials flags to true, </strong>this makes our server thinks that the request is made by a website that is using its own hosted <strong>URL (</strong>and not an external URL)<strong> </strong>and it accepts the request (learn more about cors and origin, credentials flag <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">here</a>)<strong>.</strong></p><h4><strong>Types of Middlewares</strong></h4><p>There are 5 types of middleware in Express that you can utilize, namely:</p><ol><li>Application Level Middleware</li><li>Router Level Middleware</li><li>Error Handling Middleware</li><li>Built-in Middleware</li><li>Third-Party Middleware</li></ol><h4>Application-Level Middleware</h4><p>Application-level middlewares as the name suggest works for all the requests throughout the application HTTP requests. Take a look at the <strong><em>app.use() </em></strong>method that we already used previously for <strong><em>MyMiddleware CORS</em></strong> and <strong><em>body-parser </em></strong>because we wanted these middlewares to execute no matter the nature of the incoming HTTP request, i.e. throughout all the application requests.</p><h4>Router-Level Middleware</h4><p>Like application-level middleware, we have also already used router-level middleware. Have a look at all <strong><em>app.get(‘/xxx’) app.post(‘/xxx’), </em></strong>the<strong><em> </em></strong>type of middlewares that we used in our code. All these middlewares belong to router-level middleware. As the name indicates, it is used to create and manage routes, which means simply responding to requests arriving at a particular routing endpoint.</p><h4>Error Handling Middleware</h4><p>It is also an application-level (global) middleware that is generally executed at the last (in order to catch any errors) of the req-res cycle, mainly to handle the errors that are generated in the cycle.</p><h4>Built-in Middleware</h4><p>Built-in middlewares are the middlewares that are bundled with the express installation (written by express developers) and can be directly used within our express app. One example of built-in middleware is <strong><em>express.json([]), </em></strong>which functions exactly like bodyParser but on one hand where we have to import bodyParser (third party), <strong><em>express.json([]) </em></strong>is available by default. Learn more about express Built-in middleware <a href="https://expressjs.com/en/4x/api.html#express.json">here</a>.</p><h4>Third-Party Middleware</h4><p>We have already used third-party middleware — bodyParser and CORS. Third-party middlewares are those written by a third-party developer (they are not built-in or scripted by you) and can be used by simply importing them (after downloading/installing helper files) into your script and using them as normal middleware.</p><blockquote>Voila You have learnt everything about requests, routing, middlewares. Share this with your friends and feel free to ask any questions below. Have a nice day!….</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6b0674c8cb5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/requests-routing-and-middlewares-explained-guide-to-nodejs-basics-part-2-f6b0674c8cb5">Requests, Routing and Middlewares Explained | Guide to NodeJS Basics — Part 2</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Requests, Routing and Middlewares Explained | Guide to NodeJS Basics — Part 1]]></title>
            <link>https://medium.com/fasal-engineering/requests-routing-and-middlewares-explained-guide-to-nodejs-basics-part-1-4af59de88355?source=rss-a43c98085610------2</link>
            <guid isPermaLink="false">https://medium.com/p/4af59de88355</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Charchithowitzer]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 05:21:06 GMT</pubDate>
            <atom:updated>2022-09-07T05:21:06.969Z</atom:updated>
            <content:encoded><![CDATA[<h3>Requests, Routing and Middlewares Explained | Guide to NodeJS Basics — Part 1</h3><p>Before getting right into requests, routing and middleware, and whatnot, let’s get a quick understanding of what <a href="https://nodejs.org/en/">NodeJs</a> and <a href="https://expressjs.com/">Express</a> are and how they both are very crucial in your application or website development story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxKC5j-bQyUSRCuOmiN07A.png" /></figure><h3>What is NodeJS?</h3><p>We all are familiar with our favorite JavaScript (JS), but it’s not just limited to client-side scripting to run in the browser. When it was released in 1990 it was just for client-side scripting. But due to the rise of the web, JS also evolved with it. Till 2009 it was almost impossible to run JavaScript on the server and most of the server-side scripting and logic was written in PHP, ASP.NET, JAVA, RUBY, etc. with PHP as the market leader.</p><h4>Why it was a BIG deal?</h4><p>When NodeJs was released, it revolutionized development because now a developer can use a single language throughout the whole stack (backend and front-end). NodeJs is not a programming language but an <strong><em>‘event-driven non-blocking asynchronous JS run-time’ </em></strong>that allows JavaScript to run on a server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*62n2FOOyFEM5sXgj.png" /></figure><p><strong>JS</strong> on Node is on steroids, here you have a lot more functionality and features (all the client-side related features are not here (like DOM), but you don’t even need them here anyways) which you can use like file-system, memory management, load-balancing and a lot more.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FGRSnxyhJnPsaQy9YLn%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FTOEIAnimationUK-dbz-dragon-ball-z-GRSnxyhJnPsaQy9YLn&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNnZhdGx0ODd6aDhyOWVncGZrNm5zZGJ6bTUyanh3ZGE5NHA2MnV0OCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FGRSnxyhJnPsaQy9YLn%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ffe7dc63c1c1d6a40cefd6cbd9da8bc/href">https://medium.com/media/7ffe7dc63c1c1d6a40cefd6cbd9da8bc/href</a></iframe><blockquote>So, in short, it is a <strong><em>High-level Single-threaded Interpreted JIT Compiled Prototype based Multi-Paradigm language with a Non-blocking Event loop Concurrency model</em></strong>.</blockquote><p>Ok, that’s a lot about Node let’s get forward.</p><h3>What is ExpressJS</h3><p>Express is a web framework for JS that runs on the node on the server side. It provides a set of features specifically tailored and maintained for web app development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ETcaw-gA1dYW4EFxqGK3w.png" /></figure><h4>Why it is useful?</h4><p>The biggest advantage of the express framework is the simplification of writing complex code when developing a scaling website or application, which otherwise would have been a lot more difficult to handle if all were written in vanilla NodeJS using inbuilt methods.</p><p>It handles complex routing, easier handling of requests, adding middlewares(which we are going to learn), server-side rendering, etc.</p><h3>Requests and Routing</h3><p>Whenever we load a website or press a button on the webpage the page sends a request to the server which in turn recognizes the request and responds with the corresponding information.</p><p>Let’s see how it’s done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*M09G7MHjvfrQdO4LFRNzPA.png" /></figure><p>So, I assume that you already know how to set up a server and run it, I also assume that you have express installed.</p><h4>Setup the app listener</h4><p>Suppose now we send a request to a server hosted at my localhost and port 3000, my node file index.js should look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90cbca2c8b6251f68ceb5ddeb1809524/href">https://medium.com/media/90cbca2c8b6251f68ceb5ddeb1809524/href</a></iframe><p>Here we are importing the express library which gives us access to all the express features and commands inside this file, also in line three we are running the express function(notice that we are assigning the variable app with express and also running it (see the parenthesis after express).</p><h4>What the above code does,</h4><p>Now in line 5, we are assigning a port to our express app, to make it simple think of it as an address inside our machine, so the whole URL to my website will look like <strong><em>http://localhost:3000/</em> </strong>This is where our server is running.</p><p>Quickly run this file and you should see the message “Now starting the port”. Now our express app(server) is Up and running.</p><h4>Request Listener</h4><p>We will now want to add a request listener to our server script that will listen to the request generated from the webpage and will respond with a corresponding response. Let’s see how</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a49bd44a70656205eead0f25c13d7947/href">https://medium.com/media/a49bd44a70656205eead0f25c13d7947/href</a></iframe><p>Here in line 5, we are listening to a ‘get’ request which means any request that will come from <strong>http://localhost:3000/</strong> will be listened to and responded to here. Go to this link and see what is being displayed on the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0A3aurbe-VmKlv1G4AFHQ.png" /></figure><h4>Routing</h4><p>Now let’s add a new route or address to our server. It is as simple as.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2b4c2d2669281d48486490c21148785/href">https://medium.com/media/a2b4c2d2669281d48486490c21148785/href</a></iframe><p><em>Notice in line 9 we have added a new request route. Just see what happens when we go to the address </em><strong><em>http://localhost:3000/profile.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tru9eM_inm7S9Ad_Cj_mdw.png" /></figure><p>We get a different response this time which is on the route <strong><em>/profile </em></strong>in our server. That is the desired behavior, exactly like we wanted. Routes are helpful for enabling websites to have different request listeners for performing different tasks on the server and fetching a corresponding output for each of our requests/routes.</p><p><strong>Read about Promises, Async/Await in Javascript,</strong></p><p><a href="https://medium.com/fasal-engineering/promise-async-await-understanding-and-implementation-6b73d62561a4">Promise, Async, Await— Understanding and Implementation</a></p><h3><strong>Middlewares — what is it and how to implement</strong></h3><p>Finally, we are going to learn about “middlewares”. In simple language, middleware is a function/script/program that is going to run between when you send a request to your browser and when you receive it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*u4kUddDyRmV4hX99DKpBbA.png" /></figure><p>In <em>image 2 </em>functions on lines 5 and 9 are middlewares, because when you send the request to the server both two functions execute and reply with a response to our website.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/011cce5e7452526939f1a486fa5e3b67/href">https://medium.com/media/011cce5e7452526939f1a486fa5e3b67/href</a></iframe><p>In line 7 you can see we have used the method <strong>app.use()</strong> the special thing about the <strong>app.use()</strong> is that it takes a function as a parameter and executes it for each and every request that we send to the server. Here is a callback for the function myMiddleware that we have defined in line 17.</p><p>Now run our script and reload our webpage <strong>http://localhost:3000/</strong> on the browser, one more time and see what’s happening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*8kHf1ZBsZVlVR3o55zFo9A.png" /></figure><p>We see this on our node console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GLvQcJ_lggRpaudAc3pPjA.png" /></figure><p><strong><em>Aaannnndd. WTH just happened there? Where is our homepage? We will get it back.</em></strong></p><h4>Analyzing the code</h4><p>Now we will analyze our code. So our <strong><em>app.use</em></strong> is successfully calling the function <strong><em>myMiddleware </em></strong>which is reflected in the console, but line 8 is not printing anything into the console which means the route function at line 7 is not getting invoked, and that’s why we can’t see any response. How to get it running then?</p><p>You see, the callback function in <strong><em>app.use() </em></strong>accepts 3 arguments namely<strong><em> req,res,next() </em></strong>we are familiar with<strong><em> req </em></strong>and<strong><em> res </em></strong>but what is<strong><em> next()?</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d71d9389f94e0ef9e3e2a955d86dc83/href">https://medium.com/media/1d71d9389f94e0ef9e3e2a955d86dc83/href</a></iframe><p><em>now pass the arguments </em><strong><em>res, res, next</em></strong><em> to the myMiddleware function, reload the script, and refresh the page. (comment next() for now we will learn about it).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*A_7DXZLPLCjgvwB1H6Wc7Q.png" /><figcaption>console</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VEIWvDgOjsdw-WNiPTn5w.png" /><figcaption>browser</figcaption></figure><p>This is the output on the webpage as well as the console. So, our middleware has access to the <strong><em>req</em></strong> and <strong><em>res</em></strong> and we are able to send responses from here too. Now uncomment the line executing the function <strong><em>next(),</em></strong> i.e., line <strong>25</strong>. Save and execute and refresh the page. Let us see the output.</p><p>We get an error,</p><pre><em>Now starting the port<br>This is in the Middleware<br>I am in the home page route<br></em><strong><em>Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client<br> at new NodeError (node:internal/errors:387:5)</em></strong></pre><p>This indicates that we actually get into the homepage route: <em>this was not the case before. </em>Now <strong><em>comment on the 23rd</em></strong> line and see the behavior. Save, reload, refresh just like before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*YtdQ9GVsmYs-wYSFo9tj4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2GR6eJeEyoTqnuXSeshyw.png" /></figure><p>We can see in the console output that our script ran and it executed the <strong><em>myMiddleware() </em></strong>function first and then it moved to the function where we defined our homepage route with the actual response being sent to the website. The error says <strong>Cannot set headers after they are sent to the client </strong>which means that once the response is already sent we cannot perform any other action, which means we cannot respond to the same request more than once. That is why we commented on the response in the middleware function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*m4U3L5C5J_q2oj3x5ibDZg.png" /></figure><p><strong>Read about GeoSpatial Location Filtering in Node JS,</strong></p><p><a href="https://medium.com/fasal-engineering/location-filtering-in-node-using-mongodb-geospatial-queries-56540489585c">Location Filtering in Node Using MongoDB Geospatial Queries</a></p><h3>How middlewares are useful?</h3><p>Now suppose we want to do something with our data before sending the response or we want to send a totally another response to the user depending upon the parameters of the request, how can it be performed?</p><p>Something amazing with middlewares is that we can access the <strong>res,req</strong> in them and that allows us to perform any required task.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de01e606c8f5038c6ad073a870d1d788/href">https://medium.com/media/de01e606c8f5038c6ad073a870d1d788/href</a></iframe><p><em>In line 22 we are checking if the query in the request sent by the client is true, if yes then we are executing the </em><strong><em>next() </em></strong><em>(the next middleware i.e the arrow function), if not then send the user a response.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*_5f7VlqHR32-Z0MWJwhRng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58t74302LyITr60de8zyzQ.png" /></figure><p><em>notice here we are also sending a query </em><strong><em>user=true</em></strong><em> with the request and if this is true then we are calling the next middleware. Now try it yourself with </em><strong><em>user=false </em></strong><em>and see the result</em><strong><em> (I am leaving it for you to check the result).</em></strong></p><p>Sometimes we would want to send some data from our current middleware to the next executing middleware. As we know that all the middleware have access to the <strong>req</strong> and <strong>res, </strong>we can easily bind our data with them before calling the next middleware, let&#39;s see how.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d10c7042c89604173878e44d7c36be46/href">https://medium.com/media/d10c7042c89604173878e44d7c36be46/href</a></iframe><p>In line 25 we are adding another field with the request which is <strong>isUserFlag </strong>and setting its value as true then we are calling our next middleware where it is being printed in the console. Have a look</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMmE82796hnLaDXPaKIklg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*m7Ew5pA2b4vlOw_pSsJJrQ.png" /></figure><p>Hurray!!, we can see that we actually have access to the <strong><em>isUserFlag</em></strong> inside our homepage route.</p><p>So this was it, for now, I hope I was able to explain the concepts to you in a very simple manner. If you have any questions you can comment about that, I will be very happy to address those. In the next article I will talk about different types of middleware, next() and body-parser.</p><p>If you are starting with Node JS then you might need to learn SASS as well (in order to scale your application), here’s a great piece on SASS —</p><p><a href="https://medium.com/fasal-engineering/what-is-sass-a-comprehensive-guide-sass-learning-series-part-1-introduction-to-sass-8aa1d52eff15">SASS Learning Series Part 1: Introduction to SASS</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4af59de88355" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasal-engineering/requests-routing-and-middlewares-explained-guide-to-nodejs-basics-part-1-4af59de88355">Requests, Routing and Middlewares Explained | Guide to NodeJS Basics — Part 1</a> was originally published in <a href="https://medium.com/fasal-engineering">Fasal Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Summer Internship]]></title>
            <link>https://charchithowitzer.medium.com/the-summer-internship-e80bf4ad13e4?source=rss-a43c98085610------2</link>
            <guid isPermaLink="false">https://medium.com/p/e80bf4ad13e4</guid>
            <category><![CDATA[full-stack-developer]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[summer-intenship]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Charchithowitzer]]></dc:creator>
            <pubDate>Thu, 25 Aug 2022 04:58:25 GMT</pubDate>
            <atom:updated>2022-08-25T04:58:25.537Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Q9T7aiY35QJkVTsiE7rTw.png" /></figure><p>‘Full Stack Developer’ you may have heard this term many times but that is a full stack developer after all. A full-stack developer works with all the technologies that are required to create a website or a mobile application. A full-stack developer is responsible for developing the front-end part of an application as well as the back-end part. The front-end part usually consists of HTML, CSS (for webpage design), and JAVASCRIPT for client-side logic. Apart from these, many front-end frameworks also exist, making the whole development process much more systematic. These frameworks provide prewritten modules and components that can be simply included in the application. Some of these frameworks are VueJS and React JS. These frameworks are also very crucial in creating single-page applications. After the front-end part comes the server-side scripting. Server-side scripting is the logic that you want to run on your servers this can be written in many languages like Python, Java, and PHP but the most prominent of all the server-side languages is NodeJS. Not only the coding part but a Full_Satck developer is also responsible for documenting the project and for the Dev-Ops.</p><h3>HTML</h3><p>HTML is used for writing content (markup) that a browser can understand. It is not a programming language because it runs no logic, but it’s a different way of writing the content of a webpage that the browser and a scripting language can understand and changes can be made to the content of the app dynamically. It consists of many tags that are used to define the type of content it is holding, use of correct tags is very crucial in creating a website whose skeleton (markup) can be understood easily and is very easy to manipulate.</p><blockquote><strong>&lt;h1&gt;</strong> The heading tag is used to write a heading on the webpage. It ranges from h1 to h6 there can be only 1 h1 in the webpage that corresponds to the main heading of the webpage but any number of h2-h6 heading tags.</blockquote><blockquote><strong>&lt;p&gt;</strong> The paragraph tag, as the name says, it is used to write the content itself.</blockquote><blockquote><strong>&lt;img&gt;</strong> Image tag is used to embed an image.</blockquote><blockquote><strong>&lt;a&gt;</strong> The hyperlink tag is used to embed links into text.</blockquote><blockquote><strong>&lt;ul&gt; &lt;ol&gt;</strong> the unordered list and ordered list tags used to define lists and contains <strong>&lt;li&gt;</strong> tags that represent a single list item.</blockquote><h3><strong>CSS</strong></h3><p>CSS stands for cascading style sheets and it enables us to make the markup look in the desired way the developer wanted. We can target the parts of markup very precisely and change their appearance. All this styling is possible through the use of cascading style sheets.</p><h4>how to target markup?</h4><p>The tags can be directly targeted in the CSS or the tags can be given Class names and IDs, many elements can have the same class name but the ID is unique</p><h4>Some Properties</h4><blockquote><strong>background-color</strong>: used to change the background color of any element</blockquote><blockquote><strong>color:</strong> used to change the color of content of any element.</blockquote><blockquote><strong>border-radius:</strong> borders of any element can be made rounded</blockquote><blockquote><strong>z-index:</strong> used to set the z-axial position (direction which goes into your screen) of an element.</blockquote><h3>JAVASCRIPT</h3><p>JS is used to handle events and logic that you want to perform on the client side. It includes performing HTTP requests, changing the CSS properties of elements, and manipulating the content of the page itself. JS is very vast in itself and all these years it existed everywhere in the development stack be it front end or back end. JAVA script is very easy and complex at the same time and its variety in the application made it very much popular in the stacks. As it is said that something that can be written in javascript will eventually be written in JS.</p><h3>A few projects in vanilla HTML, CSS, and JS</h3><p>A conference app layout:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZulLjklIwgS7XSVhJYVJiA.png" /></figure><p>An app that spits out random cat-fact on button click.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*vIirtu6xHjRHYr5WxfrjZg.png" /></figure><p>An app that fetches the current crypto-currencies trends and displays them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dG2LbT2cgTszpupVLb_qig.png" /></figure><p>There is always more to learn, more to achieve more to explore. So don’t stop where you are, learn new things, and keep yourself in front of the crowd.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e80bf4ad13e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Matrix Multiplication-Why is it a big deal?]]></title>
            <link>https://charchithowitzer.medium.com/matrix-multiplication-why-is-it-a-big-deal-cc8ef7490008?source=rss-a43c98085610------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc8ef7490008</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[matrix-multiplication]]></category>
            <dc:creator><![CDATA[Charchithowitzer]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 17:26:41 GMT</pubDate>
            <atom:updated>2021-03-23T11:21:06.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HjcZkViYtPKg-Wm2o7DFDg.png" /></figure><p>When I took my first school course on matrices, the teacher wasn’t big on explanation. He showed us how to multiply matrices but didn’t say why.</p><p>My first reaction was, “You’re kidding us, right?”</p><p>The rule seemed so bizarre and arbitrary that it must have come to some theoretical mathematician in a drug-induced nightmare. Surely there had to be a more rational approach.</p><p>But guess what? There isn’t. The rule makes perfect sense, when you see where it came from. My goal here is to give you an understandable rationale for why we do it the way we do. It’ll still take you a little while to get used to the idea, and even longer to be comfortable with it. But I hope that, after my explanation, you’ll at least see that it’s not an arbitrary convention. To explain the rule, let me begin with the set of linear equations</p><p>Matrix multiplication is a symbolic way of substituting one linear change of variables into another one. If <em>x′=ax+byx′=ax+by</em> and <em>y′=cx+dyy′=cx+dy</em>, and <em>x′′=a′x′+b′y′x″=a′x′+b′y′</em> and <em>y′′=c′x′+d′y′y″=c′x′+d′y′</em> then we can plug the first pair of formulas into the second to express <em>x′′x″</em> and <em>y′′y″</em> in terms of xx and yy:</p><p><em>x′′=a′x′+b′y′=a′(ax+by)+b′(cx+dy)=(a′a+b′c)x+(a′b+b′d)yx″=a′x′+b′y′=a′(ax+by)+b′(cx+dy)=(a′a+b′c)x+(a′b+b′d)y</em></p><p>and</p><p><em>y′′=c′x′+d′y′=c′(ax+by)+d′(cx+dy)=(c′a+d′c)x+(c′b+d′d)y.y″=c′x′+d′y′=c′(ax+by)+d′(cx+dy)=(c′a+d′c)x+(c′b+d′d)y.</em></p><p>It can be tedious to keep writing the variables, so we use arrays to track the coefficients, with the formulas for <em>x′x′</em> and <em>x′′x″</em> on the first row and for <em>y′y′</em> and <em>y′′y″</em> on the second row. The above two linear substitutions coincide with the matrix product</p><p><em>(a′c′b′d′)(acbd)=(a′a+b′cc′a+d′ca′b+b′dc′b+d′d).(a′b′c′d′)(abcd)=(a′a+b′ca′b+b′dc′a+d′cc′b+d′d)</em>.</p><p>So matrix multiplication is just a <em>bookkeeping</em> device for systems of linear substitutions plugged into one another (order matters). The formulas are not intuitive, but it’s nothing other than the simple idea of combining two linear changes of variables in succession.</p><p>Matrix multiplication was first defined explicitly in print by Cayley in 1858, in order to reflect the effect of composition of linear transformations.</p><p>However, the idea of tracking what happens to coefficients when one linear change of variables is substituted into another (which we view as matrix multiplication) goes back further. For instance, the work of number theorists in the early 19th century on binary quadratic forms <strong><em>ax2+bxy+cy2ax2+bxy+cy2</em></strong> was full of linear changes of variables plugged into each other (especially linear changes of variable that we would recognize as coming from SL2(Z)SL2(Z)). For more on the background, see the paper by Thomas Hawkins on matrix theory in the 1974 ICM. Google “ICM 1974 Thomas Hawkins” and you’ll find his paper among the top 3 hits.</p><h3><strong>Matrix Multiplication in Computer Science</strong></h3><p>Among the most common tools in electrical engineering and computer science are rectangular grids of numbers known as matrices. The numbers in a matrix can represent data, and they can also represent mathematical equations. In many time-sensitive engineering applications, multiplying matrices can give quick but good approximations of much more complicated calculations.</p><p>Matrices arose originally as a way to describe systems of linear equations, a type of problem familiar to anyone who took grade-school algebra. “<a href="https://news.mit.edu/newsoffice/2010/explained-linear-0226.html">Linear</a>” just means that the variables in the equations don’t have any exponents, so their graphs will always be straight lines.</p><p>The equation x — 2y = 0, for instance, has an infinite number of solutions for both x and y, which can be depicted as a straight line that passes through the points (0,0), (2,1), (4,2), and so on. But if you combine it with the equation x — y = 1, then there’s only one solution: x = 2 and y = 1. The point (2,1) is also where the graphs of the two equations intersect.</p><p>The matrix that depicts those two equations would be a two-by-two grid of numbers: The top row would be [1 -2], and the bottom row would be [1 -1], to correspond to the coefficients of the variables in the two equations.</p><p>In a range of applications from image processing to genetic analysis, computers are often called upon to solve systems of linear equations — usually with many more than two variables. Even more frequently, they’re called upon to multiply matrices.</p><p>Matrix multiplication can be thought of as solving linear equations for particular variables. Suppose, for instance, that the expressions t + 2p + 3h; 4t + 5p + 6h; and 7t + 8p + 9h describe three different mathematical operations involving temperature, pressure, and humidity measurements. They could be represented as a matrix with three rows: [1 2 3], [4 5 6], and [7 8 9].</p><p>Now suppose that, at two different times, you take temperature, pressure, and humidity readings outside your home. Those readings could be represented as a matrix as well, with the first set of readings in one column and the second in the other. Multiplying these matrices together means matching up rows from the first matrix — the one describing the equations — and columns from the second — the one representing the measurements — multiplying the corresponding terms, adding them all up, and entering the results in a new matrix. The numbers in the final matrix might, for instance, predict the trajectory of a low-pressure system.</p><p>Of course, reducing the complex dynamics of weather-system models to a system of linear equations is itself a difficult task. But that points to one of the reasons that matrices are so common in computer science: They allow computers to, in effect, do a lot of the computational heavy lifting in advance. Creating a matrix that yields useful computational results may be difficult, but performing matrix multiplication generally isn’t.</p><p>One of the areas of computer science in which matrix multiplication is particularly useful is graphics, since a digital image is basically a matrix to begin with: The rows and columns of the matrix correspond to rows and columns of pixels, and the numerical entries correspond to the pixels’ color values. Decoding digital video, for instance, requires matrix multiplication; earlier this year, MIT researchers were able to build one of the <a href="https://news.mit.edu/newsoffice/2013/mit-researchers-build-quad-hd-tv-chip-0220.html">first chips </a>to implement the new high-efficiency video-coding standard for ultrahigh-definition TVs, in part because of patterns they discerned in the matrices it employs.</p><p>In the same way that matrix multiplication can help process digital video, it can help process digital sound. A digital audio signal is basically a sequence of numbers, representing the variation over time of the air pressure of an acoustic audio signal. Many techniques for filtering or compressing digital audio signals, such as the <a href="https://news.mit.edu/newsoffice/2012/faster-fourier-transforms-0118.html">Fourier transform</a>, rely on matrix multiplication.</p><p>Another reason that matrices are so useful in computer science is that <a href="https://news.mit.edu/newsoffice/2012/explained-graphs-computer-science-1217.html">graphs</a> are. In this context, a graph is a mathematical construct consisting of nodes, usually depicted as circles, and edges, usually depicted as lines between them. Network diagrams and family trees are familiar examples of graphs, but in computer science they’re used to represent everything from <a href="https://news.mit.edu/newsoffice/2012/making-web-applications-more-efficient-0831.html">operations performed</a> during the execution of a computer program to the relationships characteristic of <a href="https://news.mit.edu/newsoffice/2013/algorithm-extends-artificial-intelligence-technique-1114.html">logistics problems</a>.</p><p>Every graph can be represented as a matrix, however, where each column and each row represents a node, and the value at their intersection represents the strength of the connection between them (which might frequently be zero). Often, the most efficient way to analyze graphs is to convert them to matrices first, and the solutions to problems involving graphs are frequently solutions to systems of linear equations.</p><h3><strong>The Problem and its history</strong></h3><p>In 1968, Winograd made the discovery that, by using a different method of calculating the inner product, one could find the product of two n × n matrices, which, while using a similar number of overall operations, shifted the emphasis more on addition than on multiplication.</p><p>This was important as addition was computationally less demanding than multiplication. The same year, Strassen provided an explicit algorithm which could multiply two 2^n × 2^n matrices in less than 6.7^n operations, where using Winograd or the trivial algorithm, we would have had approximately 8^n operations. Using this, it is shown that ω ≤ log2 (7) &lt; 2.81.</p><p>In 1978, Pan found explicit algorithms to further reduce ω by means of the technique of trilinear aggregation. This technique uses the fact that computing the trace of the product of three n×n matrices is equivalent to the problem of multiplying two n × n matrices (in terms of the total number of multiplications). By defining a function on the indices of the entries in the matrices A, B and C to be multiplied, we may define an aggregate to do all the required multiplications, plus some extra terms. We unite terms to remove these extra terms in as few calculations as possible. Using this technique, Pan shows that we can multiply two 70 × 70 matrix multiplications in 143640 operations. This gives ω ≤ log70 143640 &lt; 2.79512, and further, we can perform a 46 × 46 matrix multiplication in 41952 operations, giving ω ≤ 2.78017.</p><p>In 1980, Bini et al. showed that the number of operations required to perform a matrix multiplication could be reduced by considering approximate algorithms. If we change our underlying field k to be the field of polynomials of λ, a variable which, if k is R can be assumed to be just a small number (allowing negative powers of λ) with coefficients in k, we may obtain, using fewer operations, an approximation of the required matrix multiplication (in the sense that each entry will be “out” by a power of λ). Using this method (which is similar to trilinear aggregation), they obtain ω ≤ 2.7799.</p><p>In 1981, Schönhage showed that an algorithm which could approximately compute multiple independent matrix multiplications could be used to further reduce ω. This is the result of his asymptotic sum inequality- using it, he shows that ω ≤ 2.5479. Using similar techniques, Coppersmith and Winograd showed that one can take an algorithm (of a certain type) that can perform multiple disjoint matrix multiplications and square it. The resulting algorithm will be capable of multiplying larger matrices than expected. This method gives ω ≤ 2.4955480.</p><p>In 1986 Strassen showed that one could start with an algorithm that was not a matrix product: we have a series of blocks, where the blocks can themselves be seen as elements of a matrix multiplication, and the blocks themselves are matrix multiplications. Raising this original algorithm to a large power, we may set some blocks to zero to obtain a large number of independent matrix products: we then use Schönhage to find a value for ω. This method yields ω ≤ 2.4785.</p><p>In 1987, Coppersmith and Winograd used this method to great effect to provide the current record for ω. They start with an algorithm, raise it to the Nth power and show that setting certain variables as being zero will lead to the algorithm calculating a large number of independent matrix products of a certain size: using Schönhage, we get that ω ≤ 2.376.</p><p>In 2005, Cohn and Umans placed the matrix multiplication in a group theoretic context: while they were unable to find new bounds for ω, the group-theoretic context provides new conjectures, which, if proved, will show that ω = 2. A related problem is determining the rank of Matrix Multiplication. The rank is the total number of non-scalar multiplications required to evaluate a Matrix product (including scalar multiplications this becomes the Multiplicative Complexity).</p><h3>The Main Problem</h3><p>Matrices have long been the subject of much study by many Mathematicians. However, the rise of computers in the late 20th century has led to new problems, the main one being the problem of Matrix Multiplication. Computers are required to do many Matrix Multiplications at a time, and hence it is desirable to find algorithms to reduce the number of steps required to multiply two matrices together. Until 1968, we had only the Trivial Algorithm to multiply matrices together. This is as follows:</p><p><strong>Algorithm 1</strong>. If we have two n × n matrices, n ∈ N, A and B, with entries in a field <em>k</em>, such that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QU2CoSgsg9Cs2IAjiQgvUw.png" /></figure><p>where multiplication is defined as in the field <em>k</em>.</p><p>We see that this algorithm requires 2n^3 − n^2 operations in k to multiply two n × n matrices, of which n 3 are multiplications and n^3 − n^2 are additions. However in 1968, Winograd showed that one could take the inner product of two vectors using fewer multiplications, but with more additions. We consider finding the inner product of two vectors (x1, .., x n) and (y1, .., y n). Set</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*7BkgYb5AS_CcCJqm1Y4EYA.png" /></figure><p>Since matrix multiplication can be regarded as taking multiple inner products, we get that the total number of multiplications required to multiply an n×n matrix by another matrix of the same size is about (n^3)/2 and the number of additions required is about (3/2)n^3 , improving slightly on the trivial algorithm. Denote by Mk(n) the total number of operations required by a bilinear algorithm to multiply two n × n matrices over k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*EtLDsmdJb41Yj5x_fnd-_g.png" /></figure><p>We see from the trivial algorithm that ω(k) has an upper limit of 3. Since there must be an output of n^2 entries, there cannot be any fewer operations than this in total matrix multiplication, so hence ω(k) ∈ [2, 3]. We see that the total number of operations in Winograd’s algorithm implies that the least upper bound for ω is 3. However, in the same year, Strassen managed to find an improvement for ω.</p><h3><strong>Strassen’s Algorithm</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eNfC3eKR9_M5nJw7NWQhlg.jpeg" /></figure><p>For a long time it was assumed that (N3) was required for matrix multiplication. However, in the late sixties, Strassen showed how to break the (N^3) barrier. The basic idea of Strassen’s algorithm is to divide each matrix into four quadrants. This strategy is called Divide and Conquer. We then use these results to compute C’s submatrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*ZCiQdu2fIe_JR8_O_rgfKw.png" /></figure><p>we see that T(N) = O(N3), so we do not have an improvement. As we saw with integer multiplication, we must reduce the number of subproblems below 8. Strassen used a strategy similar to the integer multiplication divide-and-conquer algorithm and showed how to use only seven recursive calls by carefully arranging the computations. The seven multiplications are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*NdW3I-ynLcEs-LnkPSMB4w.png" /></figure><blockquote>For detailed explanation refer to <strong><em>Introduction to Algorithms</em></strong> by Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein.</blockquote><h3>There’s a catch</h3><p>As usual, there are details to consider, such as the case when N is not a power of 2, but these are basically minor nuisances. Strassen’s algorithm is worse than the straight forward algorithm until N is fairly large. It does not generalize for the case where the matrices are sparse (contain many zero entries), and it does not easily parallelize. When run with floating-point entries, it is less stable numerically than the classic algorithm. Thus, until recently it had only limited applicability. Nevertheless, it has always represented an important theoretical milestone and certainly shows that in computer science, as in many other fields, even though a problem seems to have an intrinsic complexity, nothing is certain until proven.</p><p>Strassen’s method is<strong> “asymptotically”</strong> faster than the straightforward SQUAREMATRIX-MULTIPLY procedure.</p><p>Divide-and-conquer as a technique for designing algorithms dates back to at least 1962 in an article by Karatsuba and Ofman . It might have been used well before then, however; according to Heideman, Johnson, and Burrus , C. F. Gauss devised the first fast Fourier transform algorithm in 1805, and Gauss’s formulation breaks the problem into smaller subproblems whose solutions are combined.</p><p>Strassen’s algorithm caused much excitement when it was published in 1969. Before then, few imagined the possibility of an algorithm asymptotically faster than the basic SQUARE-MATRIX-MULTIPLY procedure. The asymptotic upper bound for matrix multiplication has been improved since then. The most asymptotically efficient algorithm for multiplying n n matrices to date, due to Coppersmith and Winograd , has a running time of O(n^(2.376)). The best lower bound known is just the obvious O(n²) bound (obvious because we must fill in n^2 elements of the product matrix).</p><p>From a practical point of view, Strassen’s algorithm is often not the method of choice for matrix multiplication, for four reasons:</p><ol><li>The constant factor hidden in the ⊝(n^log 7) running time of Strassen’s algorithm is larger than the constant factor in the ⊝(n³) -time SQUARE-MATRIXMULTIPLY procedure.</li></ol><p>So if you take constant term as three and try to equate 3 n^log 7 = n³ the value of n comes to be about 1.483489 x 10⁷(check <a href="https://www.dcode.fr/intersection-point">here</a>),that&#39;s insane, yes I heard you saying HARDWARE ACCELARATION.</p><ol><li>When the matrices are sparse, methods tailored for sparse matrices are faster.</li><li>Strassen’s algorithm is not quite as numerically stable as SQUARE-MATRIXMULTIPLY. In other words, because of the limited precision of computer arithmetic on non-integer values, larger errors accumulate in Strassen’s algorithm than in SQUARE-MATRIX-MULTIPLY.</li><li>The submatrices formed at the levels of recursion consume space.</li></ol><blockquote>So if you can find a better matrix multiplication algorithm it will be better for HUMANITY. well unless you use hardware acceleration</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxnsuM6G3Nkwg7QYIBwXyA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc8ef7490008" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Your own Voice Based Home-Automation system]]></title>
            <link>https://charchithowitzer.medium.com/create-your-own-voice-based-home-automation-system-b104090cf002?source=rss-a43c98085610------2</link>
            <guid isPermaLink="false">https://medium.com/p/b104090cf002</guid>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[voice-assistant]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Charchithowitzer]]></dc:creator>
            <pubDate>Sun, 15 Nov 2020 06:24:38 GMT</pubDate>
            <atom:updated>2020-11-15T09:16:48.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Ez7-_pI30zkJx6gqZNNJg.jpeg" /></figure><p>Today voice recognition has reached a very high accuracy and speed on various devices from computers to smartwatches. Google’s assistant, Anki’s Vector, and Amazon Alexa uses very advanced and accurate machine learning models, Natural language understanding in recognizing the voice as well as the intent of the user and can perform various actions according to the need. <br>Before we dive into the code and implementation part let us have a look over what is voice recognition and how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKxsQITAqDC2esFbdYWwKA.jpeg" /><figcaption>Anki Vector, Amazon Alexa ,Google Home mini</figcaption></figure><p>I wanted to use this technology to make an equally effective and full-fledged smart home device which can cater to the needs of a normal user, from turning-on appliances to real-time surveillance and monitoring system. But I wanted to give it voice control like other solutions available in the market, at the same time keeping it cheap, simple, and equally effective.</p><h3><strong>Motivation : Why I choose home-automation?</strong></h3><p>The last thing which I would want to add to my home is a simple home automation system that would control my appliances according to my need. Although the market is filled with many home automation solutions, all of them work online and need some kind of internet connectivity to work, they also need special smart appliances that are compatible with home automation devices like Alexa or G-Home. My goal was to create a voice-controlled home assistant that works completely offline and is fast and accurate enough to be used as a reliable assistant. Paired with a mobile application for controlling the appliances over the internet from anywhere around the world and real-time monitoring and surveillance(future release).</p><p>Lets see how speech recognition works.</p><h3><strong>How do speech recognition works?</strong></h3><p>Let’s assume we want to detect Hey!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*m_CWqZmLX6WNsUJoOUFgsA.png" /><figcaption>Human voice Spectrogram</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lwvHlOVU83xcrn-H54v-yg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oamvCC-UeBUGjlOoOq6bMA.png" /><figcaption>Converting Raw audio to Text using RNN</figcaption></figure><p>The raw audio is captured from the microphone and a spectrogram (visual representation of spectrum)of the audio input is generated, next the slices of the spectrogram are fed into a Recurrent Neural Network, This model is trained to predict the probability of the most matching alphabets. What wake word detection engines do is they don’t predict the intent of the user they just detect if a previously trained word is detected or not. The detection trigger can be used to invoke a particular code script to perform various tasks(user implementation of intent). This functionality of wake word detection engines enables them to work even offline and very fast.</p><p>There are several libraries which utilizes such deep learning models to detect the voice commands, Porcupine, Snowboy, Pocket-Sphinix are some of them.</p><ul><li><a href="https://github.com/Picovoice/porcupine">Picovoice/porcupine</a></li><li><a href="https://github.com/Kitt-AI/snowboy">GitHub - Kitt-AI/snowboy: Future versions with model training module will be maintained through a forked version here: https://github.com/seasalt-ai/snowboy</a></li><li><a href="https://github.com/cmusphinx/pocketsphinx">cmusphinx/pocketsphinx</a></li></ul><p>This project is based upon Porcupine engine because it is the fastest among all of the offline solutions and its low on resources.</p><h3>Tutorial</h3><p>In this tutorial we will have a look on how to make custom wake-words and implement them in your code.</p><h4>Step 1 : Generating Wake words</h4><p>Open command prompt and move to main directory of cloned project. For me I have my project in Downloads folder in C drive, so on opening Command prompt enter</p><blockquote>cd Documents\porcupine</blockquote><p>Now enter into bash mode by typing</p><blockquote>bash</blockquote><p>Enter the following command to make your wake word and command respectively.</p><blockquote>tools/optimizer/windows/amd64/pv_porcupine_optimizer -r resources/ -w “your wake-word” \-p windows -o “your output directory where you want to save file”</blockquote><p>In my case the wake word is Alexa and I want to store my wake word file in a folder named ppn in D drive.</p><p>Create command file for wake word</p><blockquote>tools/optimizer/windows/amd64/pv_porcupine_optimizer -r resources/ -w “Hey Christina” -o “D:\ppn”</blockquote><p>Create command file for assistant commands</p><blockquote>tools/optimizer/windows/amd64/pv_porcupine_optimizer -r resources/ -w “lights on” \-p linux -o “D:\ppn”</blockquote><p>and</p><blockquote>tools/optimizer/windows/amd64/pv_porcupine_optimizer -r resources/ -w “lights off” \-p linux -o “D:\ppn”</blockquote><h3>Setting up the detection engine — CODE</h3><p>The above three commands create three .ppn files. Now move these files to your main project folder, I have moved mine to [main project folder]/resources/keyword_files/home-auto (note that I have passed the same in line 20 and 26).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/899bc7b9630f593f5885610f35b5d4cd/href">https://medium.com/media/899bc7b9630f593f5885610f35b5d4cd/href</a></iframe><p>Similarly you can train your own wake words models and implement your code for different commands. Just generate the ppn files and add them to to declaration list.</p><h3>MY IMPLEMENTATION</h3><p>I made a separate python script to control Arduino board over serial USB connection. When the command is detected a sound is played and a control string is sent to Arduino board which pulls up or pulls down a particular digital GPIO pin that controls the relays. Separate Arduino script needs to be uploaded to a Arduino board(mine included in project under folder (<em>@rduino_code</em>). You can also use <a href="https://www.arduino.cc/en/Reference/Firmata">firmata</a> library for Arduino control. Have a look on my GitHub for full code.</p><p>Note : You may need to reconfigure the pins that need to turned off or on through a particular voice command.</p><h3>GITHUB -</h3><p><a href="https://github.com/HowitzerGitHub/assist-nt_h0m3">HowitzerGitHub/assist-nt_h0m3</a></p><h3>Thank you for reading my Blog. Now you are all set to make your own voice assistant.</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b104090cf002" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>