<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dushyant Pathak</title>
    <description>The latest articles on DEV Community by Dushyant Pathak (@dkp1903).</description>
    <link>https://dev.to/dkp1903</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F248234%2Ff3cfd475-8a09-4992-a8dc-b84a5106566f.jpg</url>
      <title>DEV Community: Dushyant Pathak</title>
      <link>https://dev.to/dkp1903</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dkp1903"/>
    <language>en</language>
    <item>
      <title>Damn Docker don't fire up on Windows? Here's a shortcut</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Fri, 25 Dec 2020 11:55:21 +0000</pubDate>
      <link>https://dev.to/dkp1903/damn-docker-don-t-fire-up-on-windows-here-s-a-shortcut-2g4d</link>
      <guid>https://dev.to/dkp1903/damn-docker-don-t-fire-up-on-windows-here-s-a-shortcut-2g4d</guid>
      <description>&lt;p&gt;If you see a dizzyingly dismal error like this when you fire up Docker Desktop&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker: error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/create: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
See 'docker run --help'.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you're not the first one. &lt;/p&gt;

&lt;p&gt;And unfortunately, a lot of Stack Overflow answers don't work. Here's something that worked for me on Windows 10.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Powershell as Administrator&lt;/li&gt;
&lt;li&gt;Run -
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PS C:\WINDOWS\system32&amp;gt;cd "C:\Program Files\Docker\Docker"
PS C:\WINDOWS\system32&amp;gt;./DockerCli.exe -SwitchDaemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember, make sure you spell the stuff right, and that Docker is installed in the directory as mentioned in the command.&lt;/p&gt;

&lt;p&gt;This is just meant to be a quick hack - an explanation about what happens coming soon.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>windows</category>
      <category>errors</category>
    </item>
    <item>
      <title>CORS error hack</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Sat, 06 Jun 2020 05:59:35 +0000</pubDate>
      <link>https://dev.to/dkp1903/cors-error-hack-pef</link>
      <guid>https://dev.to/dkp1903/cors-error-hack-pef</guid>
      <description>&lt;p&gt;Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. &lt;/p&gt;

&lt;p&gt;A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own.&lt;/p&gt;

&lt;p&gt;An example of a cross-origin request: the front-end JavaScript code served from &lt;a href="https://a.com"&gt;https://a.com&lt;/a&gt; uses XMLHttpRequest to make a request for &lt;a href="https://b.com/data.json"&gt;https://b.com/data.json&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;More details on CORS can be found &lt;a href="//developer.mozilla.org/en-US/docs/Web/HTTP/CORS"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Most noobs, who are starting with Back-End development, will often see this error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DfFoixhC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/nzH9mMN/cors-error.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DfFoixhC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/nzH9mMN/cors-error.png" alt="CORS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step would be to use the CORS package, when working with NPM.&lt;br&gt;
&lt;/p&gt;

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

//In index.js file,
var cors = require('cors');
app.use('cors');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some deployments may still cause the CORS error in some cases, wherein this particular Chrome extension comes handy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chrome.google.com/webstore/detail/cross-domain-cors/mjhpgnbimicffchbodmgfnemoghjakai?utm_source=chrome-ntp-icon"&gt;CORS Extension&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You just have to Enable and save, and it should solve the CORS error for you.&lt;/p&gt;

&lt;p&gt;However, do note that some sites, usually third party API services, such as &lt;a href="https://newsapi.org"&gt;Newsapi&lt;/a&gt; restrict only localhost sites to be able to access their free plan APIs, and will block access requests from deployed websites. &lt;/p&gt;

&lt;p&gt;Cheers! Have a CORS-Free day!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>angular</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Teach state to a 5 year old</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Fri, 05 Jun 2020 11:21:17 +0000</pubDate>
      <link>https://dev.to/dkp1903/teach-state-to-a-5-year-old-3mom</link>
      <guid>https://dev.to/dkp1903/teach-state-to-a-5-year-old-3mom</guid>
      <description>&lt;p&gt;State is an often tricky concept for noobs, and here is an attempt to simplify it through a real life example.&lt;/p&gt;

&lt;p&gt;State is a snapshot of how things were at a particular point of time. In a web page. Period.&lt;/p&gt;

&lt;p&gt;The background might have been blue, the variable hello might have had the value 10, the array might have had 15 elements. All these are part of state at a particular time.&lt;/p&gt;

&lt;p&gt;Let's say we have to make a simple counter app, which can just increment and decrement a number on the screen. The click of a particular button will increment, and the other will decrement.&lt;/p&gt;

&lt;p&gt;Everytime any of the buttons is clicked, the state of the number visible on the screen changes, and the same is reflected on the screen. &lt;/p&gt;

&lt;p&gt;Similarly, an event happening can also be a state change, such as the change in window size of the browser.&lt;/p&gt;

&lt;p&gt;State management is complex because changing state the incorrect way can lead to unexpected results, and is often very hard to debug, since there is no actual syntactic error.&lt;/p&gt;

&lt;p&gt;Angular uses libraries like NgRX for state management, and React uses Redux. &lt;/p&gt;

&lt;p&gt;Mutating state means to make changes to the existent state, and it is good practice in React to not modify state directly, as it leads to unexpected views. More info &lt;a href="https://daveceddia.com/why-not-modify-react-state-directly/#:~:text=Mutating%20state%20directly%20can%20lead,its%20parent%20re%2Drenders"&gt;here&lt;/a&gt;.)&lt;/p&gt;

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

</description>
      <category>react</category>
      <category>webdev</category>
      <category>angular</category>
    </item>
    <item>
      <title>Deleting a node in a Linked list, when you have access to only that node.</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Tue, 02 Jun 2020 19:02:31 +0000</pubDate>
      <link>https://dev.to/dkp1903/deleting-a-node-in-a-linked-list-when-you-have-access-to-only-that-node-1e14</link>
      <guid>https://dev.to/dkp1903/deleting-a-node-in-a-linked-list-when-you-have-access-to-only-that-node-1e14</guid>
      <description>&lt;p&gt;Deleting a node in a Linked list is a standard problem, until you are given the root of the LL, and the node that you want to delete. What if you want to delete that node?&lt;/p&gt;

&lt;p&gt;Thought process:&lt;br&gt;
Deleting a node requires a knowledge of the node before, to set the correct next link, and is not possible otherwise. So, how do we get a link to the node before?&lt;/p&gt;

&lt;p&gt;Well, we have a link to the node, and we have a link to the next node. So, we can delete the next node. So, let's just shift the value of the next node here, and delete the next node!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;del(Node* node)
{
    // Shifting the value
    node-&amp;gt;val = node-&amp;gt;next-&amp;gt;val;
    // Removing the next node from the LL
    node-&amp;gt;next = node-&amp;gt;next-&amp;gt;next;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, although it is the next node that has been kicked out of the Linked List, the value of the node that was to actually be deleted no longer exists! So, this works, as long as you are not asked to delete the actual node!&lt;/p&gt;

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

</description>
      <category>linkedlist</category>
      <category>competitiveprogramming</category>
      <category>algorithms</category>
      <category>dsa</category>
    </item>
    <item>
      <title>Quick way to make an image responsive</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Sat, 30 May 2020 12:19:45 +0000</pubDate>
      <link>https://dev.to/dkp1903/quick-way-to-make-an-image-responsive-4nke</link>
      <guid>https://dev.to/dkp1903/quick-way-to-make-an-image-responsive-4nke</guid>
      <description>&lt;p&gt;Add the following to your image's style attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img style = "width: 100%; height: auto;" src = "some-image-source"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to set a max-width,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img style = "width: 100%; height: auto; max-width: 200px;" src = "some-image-source"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

</description>
      <category>css</category>
      <category>responsive</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Solving Typescript-TensorflowJS incompat issues</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Sat, 30 May 2020 06:46:58 +0000</pubDate>
      <link>https://dev.to/dkp1903/solving-typescript-tensorflowjs-incompat-issues-4f80</link>
      <guid>https://dev.to/dkp1903/solving-typescript-tensorflowjs-incompat-issues-4f80</guid>
      <description>&lt;p&gt;If you're trying to use &lt;a href="https://tensorflow.org/js"&gt;Tensorflow.js&lt;/a&gt; with Angular, which uses Typescript, you might run into an error that looks something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/@types/webgl2/index.d.ts:582:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; readonly ACTIVE_UNIFORMS: number; readonly ALIASED_LINE_WIDTH_RANGE: number; ... 554 more ...; readonly WAIT_FAILED: number; }', but here has type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; readonly ACTIVE_UNIFORMS: number; readonly ALIASED_LINE_WIDTH_RANGE: number; ... 555 more ...; readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: number; }'.

582 declare var WebGL2RenderingContext: {
                ~~~~~~~~~~~~~~~~~~~~~~

  node_modules/typescript/lib/lib.dom.d.ts:16450:13
    16450 declare var WebGL2RenderingContext: {
                      ~~~~~~~~~~~~~~~~~~~~~~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a compatibility issue between the existing version of WebGL2(0.0.4) and Typescript 3.6. &lt;/p&gt;

&lt;p&gt;To solve this, just type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i --save @types/webgl2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and rerun the application. &lt;/p&gt;

&lt;p&gt;TF.js should now work without a glitch.&lt;/p&gt;

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

</description>
      <category>typescript</category>
      <category>tensorflow</category>
      <category>npm</category>
      <category>angular</category>
    </item>
    <item>
      <title>Making Google Charts responsive</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Sat, 30 May 2020 04:59:31 +0000</pubDate>
      <link>https://dev.to/dkp1903/making-google-charts-responsive-17ob</link>
      <guid>https://dev.to/dkp1903/making-google-charts-responsive-17ob</guid>
      <description>&lt;p&gt;I used the npm package for google charts, called &lt;a href="https://www.npmjs.com/package/angular-google-charts"&gt;angular-google-charts&lt;/a&gt;, to display charts in my Angular app. &lt;/p&gt;

&lt;p&gt;Setting the width and height as percentages does not make the graph responsive. Moreover, wrapping the chart element in a div and making that div responsive also doesn't work. &lt;/p&gt;

&lt;p&gt;Here's a hack I developed to make it work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--mycomponent.component.html file --&amp;gt;
&amp;lt;!-- This is the container element of your chart--&amp;gt;
&amp;lt;div (window:resize) = "resetWindowSize($event)"&amp;gt;
    &amp;lt;google-chart&amp;gt;
    ....
    &amp;lt;/google-chart&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an event listener that will listen for changes to window size, and on an event capture, will call the resetWindowSize() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//mycomponent.component.ts file
//setting state variables for chart parameters


width = document.documentElement.ClientWidth;
height = document.documentElement.ClientHeight;
....
resetWindowSize(event){
    //Reset the width and height based on current window size
    this.width = event.target.innerWidth;
    this.height = event.target.innerHeight;
    makeGraph();
}

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

&lt;/div&gt;



&lt;p&gt;Thus, on changing window size, the resetWindowSize function is triggered, and sets the width and height based on the current window size.&lt;/p&gt;

&lt;p&gt;Note that you might have to re-call the function that makes the graph. That's the way it works for me.&lt;/p&gt;

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

</description>
      <category>googlecharts</category>
      <category>angular</category>
      <category>responsive</category>
      <category>eventlistener</category>
    </item>
    <item>
      <title>PrimeNG setup</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Wed, 27 May 2020 03:04:50 +0000</pubDate>
      <link>https://dev.to/dkp1903/primeng-setup-n6i</link>
      <guid>https://dev.to/dkp1903/primeng-setup-n6i</guid>
      <description>&lt;p&gt;PrimeNG is a UI library for Angular. It has a list of components that we can use in our Angular applications. &lt;/p&gt;

&lt;p&gt;A lot of devies get this error when they try to add PrimeNG:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p-card is not a known Angular component
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note here, that p-card is just an example, and the error could be for any PrimeNG component one might be using. To solve that, make sure you have followed ALL the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing the packages.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install primeng --save
npm install primeicons --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure the following dependencies are added in the package.json file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"dependencies": {
  //...
  "primeng": "^8.0.0",
  "primeicons": "^2.0.0"
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Import the necessary modules in the app.module.ts file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {CardModule} from 'primeng/card';   
import {MenuItem} from 'primeng/api'; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the imports below, add the corresponding module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you still get the same error, add this to the angular.json file, in the styles:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"styles": [
  "node_modules/primeicons/primeicons.css",
  "node_modules/primeng/resources/themes/nova-light/theme.css",
  "node_modules/primeng/resources/primeng.min.css",
  //...
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should do the job! &lt;/p&gt;

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

</description>
      <category>primeng</category>
      <category>angular</category>
      <category>design</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Netlify reload 404 error resolved</title>
      <dc:creator>Dushyant Pathak</dc:creator>
      <pubDate>Mon, 25 May 2020 17:50:58 +0000</pubDate>
      <link>https://dev.to/dkp1903/netlify-reload-404-error-resolved-14og</link>
      <guid>https://dev.to/dkp1903/netlify-reload-404-error-resolved-14og</guid>
      <description>&lt;p&gt;Netlify is a popular website that can be used to host your websites/web apps. &lt;/p&gt;

&lt;p&gt;However, here is a possible error that you might see when you happen to reload your netlify page. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bnY_YkIm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/snosjmrav9c8g42ltka5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bnY_YkIm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/snosjmrav9c8g42ltka5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's an easy hack: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the folder which is published to netlify. &lt;/li&gt;
&lt;li&gt;Create a new file called netlify.toml. &lt;/li&gt;
&lt;li&gt;Copy and paste the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[redirects]]
from = "/*"
to = "/index.html"
status = 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note here, it doesn't matter if you don't have an index.html page in your web app. This just works. &lt;/p&gt;

&lt;p&gt;Cheers, and happy coding. &lt;/p&gt;

</description>
      <category>netlify</category>
      <category>deployment</category>
      <category>webdev</category>
      <category>tips</category>
    </item>
  </channel>
</rss>
