<?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"><channel><title><![CDATA[Gaurav Tewari 's blog]]></title><description><![CDATA[This is a tech blog in which Gaurav share small details about the project technologies he knows and works with mostly c++ and javascript. Twitter handler @oyetewari]]></description><link>https://blog.gauravtewari.xyz</link><generator>RSS for Node</generator><lastBuildDate>Sat, 06 Jun 2026 16:56:25 GMT</lastBuildDate><atom:link href="https://blog.gauravtewari.xyz/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Say Hello to anonmsg.fun -  an Anonymous Feedback platform]]></title><description><![CDATA[Hi, Hope you are doing fine...  Gaurav This side, I hope everything is fine, on your side, and if it is not fine, don't worry it would be : ) This article is regarding AnonMsg which you to give and take Anonymous feedback from anyone.
Feedback has al...]]></description><link>https://blog.gauravtewari.xyz/say-hello-to-anonmsgfun-an-anonymous-feedback-platform</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/say-hello-to-anonmsgfun-an-anonymous-feedback-platform</guid><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[side project]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Tue, 12 Apr 2022 13:01:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1649765458096/E9yKiArFE.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi, Hope you are doing fine...  Gaurav This side, I hope everything is fine, on your side, and if it is not fine, don't worry it would be : ) This article is regarding AnonMsg which you to give and take Anonymous feedback from anyone.
Feedback has always been important in Our life to grow and move ahead. Our product AnonMsg helps people to send and receive anonymous Messages... there might be some apps like this.. but I  have completely redesigned the UX/ UI and reduced the friction. AnonMsg offers the best experience among competitors. Plus there is no need to come back and check for messages like another app we will send you to push notifications as soon you will get a message.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649766473806/jEurIi8Gb.png" alt="Screenshot 2022-04-12 at 5.57.48 PM.png" />
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649766485964/onulbZLDh.png" alt="Screenshot 2022-04-12 at 5.58.01 PM.png" /></p>
<p>Earlier the plan was to work on email notifications but.. honestly sending emails is not free and even on the free plan, there is a limit of 100 emails per day... but I want a to build a product to scale and not worry about all these costs and everything so I switched to notifications earlier the plan was to use one signal but it did not work out one signal does not allows you to send notifications to specific users :)
So I switched to FCM (Firebase Cloud Messaging)  it is quite awesome.
So when you will come for the first time to AnonMsg it will ask you whether it can send you notifications or not!  if you want to get a notification every time someone messages you. Then click allow :)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649766337187/23ZnBDARr.png" alt="Screenshot 2022-04-12 at 5.55.34 PM.png" />
And thanks to the service worker running in the background you will always get a notification a detailed article is coming soon on it. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649766858048/gfXeoUksT.png" alt="Screenshot 2022-04-12 at 6.04.13 PM.png" />
and once you have got the message you always read it on the dashboard...
Plus once you clicked on the link icon </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649766939700/bUuDOl6bt.png" alt="Screenshot 2022-04-12 at 6.05.36 PM.png" />
you would be able to get a link that you can share on social media 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649766981636/T-yb6-YDE.png" alt="Screenshot 2022-04-12 at 6.06.18 PM.png" /></p>
<p>and once the user clicks on the link generated by AnonMsg. the user would be redirected to the msg page. once the user sends you a message you would be sent a  notification and if you have disabled the notification then you can later check it on Dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649767138651/L1sHoCCte.png" alt="Screenshot 2022-04-12 at 6.08.53 PM.png" /></p>
<p>Here are a few use cases in which this project can be used -</p>
<p>For Social Media
Some Social Media platforms are full of toxicity and sometimes people get bullied for saying the right things so If you want to say something to someone and don't want to get trolled then AnonMsg is the right for you.</p>
<p>To Have Fun
You can have a lot of fun while using this project just post the URL into your status and people can give feedback, some fun tasks, or even what if someone confesses to you. 😝. In such a situation, you don't want to miss that message just because you didn't check on that website where AnonMsg comes into the picture :) Our instant notifications will keep you on track. (for free)</p>
<p>Challenges I ran into</p>
<p>Push Notifications :-</p>
<p>Implementing push notifications was the hardest part. I was first going with OneSingnal... Later got to know that they do not allow sending notifications to a specific device. so I have to switch it later to firebase cloud messaging. Later I have to implement a service worker to receive notifications in the background. Which was another task. and another challenge in this module was to send notifications. for that, I am using the firebase admin module and triggering notifications for users each time the message is sent.
Plus redirecting the user on notification click was another challenge that I have solved :)</p>
<p>Setting Up DNS &amp; Deployment on Vercel :- </p>
<p>Deployment on Vercel is easy until the other 3rd parties are involved. I have to change the website URL for each and every service I am using to ensure things work as they are expected. Plus buying a domain in the last movement and chaining A and CNAME records we completely level things. I haven't thought I could do so much in so less time</p>
<p>Building Anon msg in Next and chakra : -</p>
<p>So charka has a hook called use media query which allows users to use media query I was using this in the project it makes it responsive. I dev env it was working fine but later in deployment, my UI was breaking... after researching a lot I got to know this is due to SSR later I disabled it and everything is fine now. :)</p>
<p>Project Link - http://anonmsg.fun/
Github - https://github.com/tewarig/anonmsg 
Send me a msg - https://www.anonmsg.fun/message/meow </p>
<p>if you find a bug feel free to report it to me :)</p>
<p>also one thing regarding the stats.... they are quite good for the anonmsg for the past 2 days :)
here it goes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649768153002/-WMUyegdX.png" alt="Screenshot 2022-04-12 at 6.25.49 PM.png" /></p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Bazzi : Promise.all()]]></title><description><![CDATA[Welcome to JavaScript baazi a blog series where we go through common interview questions in JavaScript and understand everything around them.
Firstly What is Promise.all() ?
So... Promise.all() take an array of promises as input and then return a pro...]]></description><link>https://blog.gauravtewari.xyz/javascript-bazzi-promiseall</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/javascript-bazzi-promiseall</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[interview]]></category><category><![CDATA[internships]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Tue, 05 Apr 2022 17:35:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1649180101143/s1rt6MsDn.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome to JavaScript baazi a blog series where we go through common interview questions in JavaScript and understand everything around them.</p>
<h1 id="heading-firstly-what-is-promiseall">Firstly What is Promise.all() ?</h1>
<p>So... Promise.all() take an array of promises as input and then return a promise that resolves to an array of the result of input promises. 
For example, we have the following 3 promises...</p>
<pre><code><span class="hljs-keyword">let</span> promise1 = <span class="hljs-built_in">Promise</span>.resolve(<span class="hljs-number">5</span>);
<span class="hljs-keyword">let</span> promise2 = <span class="hljs-number">30</span>;
<span class="hljs-keyword">let</span> promise3 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
  <span class="hljs-built_in">setTimeout</span>(resolve, <span class="hljs-number">100</span>, <span class="hljs-string">"meow"</span>);
});
</code></pre><p>Now we can pass them as an array into Promise.all() </p>
<pre><code>Promise.all([promise1, promise2, promise3]).then((values) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
  console.log(values);
});
</code></pre><p>this will resolve into </p>
<pre><code> [<span class="hljs-number">5</span>, <span class="hljs-number">30</span>, 'meow']
</code></pre><p>Okay, what if a promise is rejected ?? what will happen then ??  let's check that out...</p>
<pre><code>let promise1 <span class="hljs-operator">=</span> Promise.resolve(<span class="hljs-number">5</span>);
let promise2 <span class="hljs-operator">=</span> <span class="hljs-number">30</span>;
let promise3 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> Promise((resolve, reject) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
  setTimeout(resolve, <span class="hljs-number">100</span>, <span class="hljs-string">"meow"</span>);
});

let promise4 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> Promise((relove, reject) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
  reject(<span class="hljs-string">"server not responded"</span>);
});
Promise.all([promise1, promise2, promise3 ,promise4]).then((values) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
  console.log(values);
});
<span class="hljs-comment">//</span>
</code></pre><p>This will result in...</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649163542965/8m5z9j7fg.png" alt="Screenshot 2022-04-05 at 6.28.55 PM.png" />
so now we know that.. any of the promises does not resolve promise.all() will not resolve instead it will throw that error.
So now we can fire up our terminal and get started :)</p>
<p>Firstly we need to make a function :) that's obvious... and it will take an array as an argument. then it will iterate through all the promises in that array and will store the result of them somewhere and will return it when all promises have been iterated. 
And there is one more thing... we need to throw an error when the promise does not resolve.... </p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">promiseAllPolyFill</span>(<span class="hljs-params">listOfPromises</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
<span class="hljs-comment">// array result to store the resolved value from the promises...</span>
    <span class="hljs-keyword">let</span> result = [];
<span class="hljs-comment">// promise completed to count number of completed promises</span>
    <span class="hljs-keyword">let</span> promiseCompleted = <span class="hljs-number">0</span>;

    listOfPromises.forEach(<span class="hljs-function">(<span class="hljs-params">value, index</span>) =&gt;</span> {

      <span class="hljs-built_in">Promise</span>.resolve(value)
        .then(<span class="hljs-function">(<span class="hljs-params">val</span>) =&gt;</span> {
          result[index] = val;
          promiseCompleted += <span class="hljs-number">1</span>;

          <span class="hljs-keyword">if</span> (promiseCompleted === listOfPromises.length) {
            resolve(result);
          }
        })
<span class="hljs-comment">// if promise doesn't get resolved we need to throw error</span>
        .catch(<span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
          reject(error);
        });
    });
  });
}
</code></pre>
<pre><code class="lang-js">promiseAllPolyFill([promise1, promise2, promise3]).then(<span class="hljs-function">(<span class="hljs-params">values</span>) =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(values);
});
</code></pre>
<p>and here is the output...  it works 🐱🐱🐱🐱</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649179645264/KGX_ylYHK.png" alt="Screenshot 2022-04-05 at 10.57.20 PM.png" /></p>
]]></content:encoded></item><item><title><![CDATA[Building A QR code scanner and generator in Next.js]]></title><description><![CDATA[In this blog, we are going to build a QR code scanner and generator in Next.js.
QR codes are currently powering everything in the world. from payments to id cards, everything has a QR code on it. Here in this small demo we will be building a small de...]]></description><link>https://blog.gauravtewari.xyz/building-a-qr-code-scanner-and-generator-in-nextjs</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/building-a-qr-code-scanner-and-generator-in-nextjs</guid><category><![CDATA[React]]></category><category><![CDATA[app development]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Mon, 28 Mar 2022 16:34:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/i05sF4afLYs/upload/v1648485129240/JCjJeSMrv.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648485186515/9_HXE52TD.png" alt="Screenshot 2022-03-28 at 10.03.03 PM.png" />
In this blog, we are going to build a QR code scanner and generator in Next.js.
QR codes are currently powering everything in the world. from payments to id cards, everything has a QR code on it. Here in this small demo we will be building a small demo of Scanning and Generating QR codes on the Web.</p>
<p>Firstly create the next app </p>
<pre><code>npx create<span class="hljs-operator">-</span>next<span class="hljs-operator">-</span>app qr<span class="hljs-operator">-</span>code
</code></pre><p>Once the installation is done create simply start the local server by going to the project folder </p>
<pre><code><span class="hljs-attribute">ls</span> qr-code
</code></pre><pre><code><span class="hljs-built_in">npm</span> run dev
</code></pre><p>Now you will see the holy welcome next.js screen 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648465632539/k-N6OJnlO.png" alt="Screenshot 2022-03-28 at 4.37.09 PM.png" /></p>
<p>Now just go to the vs code screen and start editing the index.js file on the page 
we will remove the code and make simple it simple and add links to new routes ... Scan and Make codes.
make sure you have modified index.js as follows -</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648485186515/9_HXE52TD.png" alt="Screenshot 2022-03-28 at 10.03.03 PM.png" /></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">Head</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">'next/head'</span>
<span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">Image</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">'next/image'</span>
<span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">styles</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">'../styles/Home.module.css'</span>

<span class="hljs-title">export</span> <span class="hljs-title">default</span> <span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">Home</span>() {
  <span class="hljs-title"><span class="hljs-keyword">return</span></span> (
    <span class="hljs-operator">&lt;</span><span class="hljs-title">div</span> <span class="hljs-title">className</span><span class="hljs-operator">=</span>{<span class="hljs-title">styles</span>.<span class="hljs-title">container</span>}<span class="hljs-operator">&gt;</span>
      <span class="hljs-operator">&lt;</span><span class="hljs-title">Head</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-title">title</span><span class="hljs-operator">&gt;</span><span class="hljs-title">Qr</span> <span class="hljs-operator">-</span> <span class="hljs-title">Code</span><span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span><span class="hljs-title">title</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-title">meta</span> <span class="hljs-title">name</span><span class="hljs-operator">=</span><span class="hljs-string">"description"</span> <span class="hljs-title">content</span><span class="hljs-operator">=</span><span class="hljs-string">"Generated by create next app"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-title">link</span> <span class="hljs-title">rel</span><span class="hljs-operator">=</span><span class="hljs-string">"icon"</span> <span class="hljs-title">href</span><span class="hljs-operator">=</span><span class="hljs-string">"/favicon.ico"</span> <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
      <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span><span class="hljs-title">Head</span><span class="hljs-operator">&gt;</span>

      <span class="hljs-operator">&lt;</span><span class="hljs-title">main</span> <span class="hljs-title">className</span><span class="hljs-operator">=</span>{<span class="hljs-title">styles</span>.<span class="hljs-title">main</span>}<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-title">h1</span> <span class="hljs-title">className</span><span class="hljs-operator">=</span>{<span class="hljs-title">styles</span>.<span class="hljs-title">title</span>}<span class="hljs-operator">&gt;</span>
          <span class="hljs-title">Welcome</span> <span class="hljs-title">to</span> <span class="hljs-title">Qr</span> <span class="hljs-title">Labs</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span><span class="hljs-title">h1</span><span class="hljs-operator">&gt;</span>


        <span class="hljs-operator">&lt;</span><span class="hljs-title">div</span> <span class="hljs-title">className</span><span class="hljs-operator">=</span>{<span class="hljs-title">styles</span>.<span class="hljs-title">grid</span>}<span class="hljs-operator">&gt;</span>
          <span class="hljs-operator">&lt;</span><span class="hljs-title">a</span> <span class="hljs-title">href</span><span class="hljs-operator">=</span><span class="hljs-string">"/scan"</span> <span class="hljs-title">className</span><span class="hljs-operator">=</span>{<span class="hljs-title">styles</span>.<span class="hljs-title">card</span>}<span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span><span class="hljs-title">h2</span><span class="hljs-operator">&gt;</span><span class="hljs-title">Scan</span> <span class="hljs-title">a</span> <span class="hljs-title">qr</span> <span class="hljs-title">code</span><span class="hljs-operator">&amp;</span><span class="hljs-title">rarr</span>;<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h2<span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span>p<span class="hljs-operator">&gt;</span>Scan a qr code with your camera<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>p<span class="hljs-operator">&gt;</span>
          <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>a<span class="hljs-operator">&gt;</span>

          <span class="hljs-operator">&lt;</span>a href<span class="hljs-operator">=</span><span class="hljs-string">"/generate"</span> className<span class="hljs-operator">=</span>{styles.card}<span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span>h2<span class="hljs-operator">&gt;</span> Generate a qr code<span class="hljs-operator">&amp;</span>rarr;<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h2<span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span>p<span class="hljs-operator">&gt;</span> Generate a qr code with text or a link<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>p<span class="hljs-operator">&gt;</span>
          <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>a<span class="hljs-operator">&gt;</span>




        <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
      <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>main<span class="hljs-operator">&gt;</span>

      <span class="hljs-operator">&lt;</span>footer className<span class="hljs-operator">=</span>{styles.footer}<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>a
          href<span class="hljs-operator">=</span><span class="hljs-string">"https://vercel.com?utm_source=create-next-app&amp;utm_medium=default-template&amp;utm_campaign=create-next-app"</span>
          target<span class="hljs-operator">=</span><span class="hljs-string">"_blank"</span>
          rel<span class="hljs-operator">=</span><span class="hljs-string">"noopener noreferrer"</span>
        <span class="hljs-operator">&gt;</span>
          Powered by{<span class="hljs-string">' '</span>}
          <span class="hljs-operator">&lt;</span>span className<span class="hljs-operator">=</span>{styles.logo}<span class="hljs-operator">&gt;</span>
            <span class="hljs-operator">&lt;</span>Image src<span class="hljs-operator">=</span><span class="hljs-string">"/vercel.svg"</span> alt<span class="hljs-operator">=</span><span class="hljs-string">"Vercel Logo"</span> width<span class="hljs-operator">=</span>{<span class="hljs-number">72</span>} height<span class="hljs-operator">=</span>{<span class="hljs-number">16</span>} <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
          <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>span<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>a<span class="hljs-operator">&gt;</span>
      <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>footer<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
  )
}
</code></pre><p>and then also add scan and generate a page in the next js pages directory. </p>
<pre><code><span class="hljs-comment">//scan.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Scan</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Scan;<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Scan;
</code></pre><pre><code><span class="hljs-comment">//generate.js</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Generate</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Generate<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Generate
</code></pre><p>Now we would be working on the Generate Qr Code first...
firstly to generate the QR code we would be using React QR code 
use </p>
<pre><code>npm i react<span class="hljs-operator">-</span>qr<span class="hljs-operator">-</span>code
</code></pre><p>to install react-qr-code</p>
<p>after installing go to the generate.js file .. firstly we need to make a text input where we can take input from the user and store that string value in our QR code. after that we will pass that value to QRCode from react-qr-code . That's it. to do that we would be using the useState hook from React.</p>
<pre><code><span class="hljs-comment">// generate.js</span>
<span class="hljs-keyword">import</span> <span class="hljs-title">React</span>, { <span class="hljs-title">useState</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-title">QRCode</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"react-qr-code"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-title">styles</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"../styles/Home.module.css"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Generate</span>(<span class="hljs-params"></span>) </span>{
  const [qrCodeValue, setQrCodeValue] <span class="hljs-operator">=</span> useState(<span class="hljs-string">""</span>);

  <span class="hljs-keyword">return</span> (
    <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span>{styles.main}<span class="hljs-operator">&gt;</span>
          <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span>{styles.card}<span class="hljs-operator">&gt;</span>Generate QR<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>

      {qrCodeValue <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-string">""</span> <span class="hljs-operator">&amp;</span><span class="hljs-operator">&amp;</span> (
        <span class="hljs-operator">&lt;</span>QRCode value<span class="hljs-operator">=</span>{qrCodeValue} className<span class="hljs-operator">=</span>{styles.containerColumn} <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
      )}
      <span class="hljs-operator">&lt;</span>input
        className<span class="hljs-operator">=</span>{styles.card}
        onChange<span class="hljs-operator">=</span>{(e) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
          setQrCodeValue(e.target.<span class="hljs-built_in">value</span>);
        }}
      <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
  );
}

export default Generate;
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648481265913/rIeorvJPa.gif" alt="Screen-Recording-2022-03-28-at-8.55.12-PM.gif" /></p>
<p>To read the QR code from the file we would be using React Qr code scan just install it using </p>
<pre><code>npm i react<span class="hljs-operator">-</span>qr<span class="hljs-operator">-</span>reader
</code></pre><p>now we will focus on reading the QR code... we can directly import QRCODE from react-qr-reader form the react package and </p>
<pre><code><span class="hljs-comment">//scan.js</span>

<span class="hljs-keyword">import</span> <span class="hljs-title">React</span>, { <span class="hljs-title">useState</span>, <span class="hljs-title">useRef</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { <span class="hljs-title">QrReader</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"react-qr-reader"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-title">styles</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"../styles/Home.module.css"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Scan</span>(<span class="hljs-params"></span>) </span>{
  const [data, setData] <span class="hljs-operator">=</span> useState(<span class="hljs-string">"No result"</span>);

  <span class="hljs-keyword">return</span> (
    <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span>{styles.container}<span class="hljs-operator">&gt;</span>
      <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span>{styles.container}<span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>QrReader
          onResult<span class="hljs-operator">=</span>{(result, <span class="hljs-function"><span class="hljs-keyword">error</span>) =&gt; </span>{
            <span class="hljs-keyword">if</span> (<span class="hljs-operator">!</span><span class="hljs-operator">!</span>result) {
              setData(result?.text);
            }

            <span class="hljs-keyword">if</span> (<span class="hljs-operator">!</span><span class="hljs-operator">!</span><span class="hljs-function"><span class="hljs-keyword">error</span>) </span>{
              console.info(<span class="hljs-function"><span class="hljs-keyword">error</span>)</span>;
            }

          } 
        }
<span class="hljs-comment">//this is facing mode : "environment " it will open backcamera of the smartphone and if not found will </span>
<span class="hljs-comment">// open the front camera</span>
        constraints    <span class="hljs-operator">=</span>{{ facingMode:  <span class="hljs-string">"environment"</span>  }}
          style<span class="hljs-operator">=</span>{{ width: <span class="hljs-string">"40%"</span>, height: <span class="hljs-string">"40%"</span> }}
        <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>p<span class="hljs-operator">&gt;</span>{data}<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>p<span class="hljs-operator">&gt;</span>
      <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
  );
}

export default Scan;
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648484161498/2aajOrVr8.gif" alt="qrDemo.gif" />
here we are passing facing mode so basically while accessing the camera if we want to access the back camera of the device we can set the facing mode to the environment which will by default open the back camera in the user's phone and will open the web camera in PC.  if you want to know more about facing mode <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode">check Mozilla's docs</a></p>
<p>So here are resource materials for the docs
<a target="_blank" href="https://github.com/tewarig/react-qrcode">Github</a>
<a target="_blank" href="http://qrcode.gauravtewari.xyz/">Live Deployment</a></p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Baazi: How to flatten an array in javaScript?]]></title><description><![CDATA[Welcome to JavaScript baazi a blog series where we go through common interview questions in JavaScript and understand everything around them.
Hmm... So what is the flattening of an array?
basically in flattening we reduce the dimension of an array.ba...]]></description><link>https://blog.gauravtewari.xyz/javascript-baazi-how-to-flatten-an-array-in-javascript</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/javascript-baazi-how-to-flatten-an-array-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[array]]></category><category><![CDATA[interview]]></category><category><![CDATA[internships]]></category><category><![CDATA[vanilla-js]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sat, 12 Feb 2022 20:55:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1644699768685/ad-sW5OUW.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome to JavaScript baazi a blog series where we go through common interview questions in JavaScript and understand everything around them.</p>
<h1 id="heading-hmm-so-what-is-the-flattening-of-an-array">Hmm... So what is the flattening of an array?</h1>
<p>basically in flattening we reduce the dimension of an array.<br />basically, let's say if we have a 2d array while doing the flattening we will convert that 2d array into a 1d array. </p>
<pre><code><span class="hljs-attr">example:</span> <span class="hljs-number">1</span>
<span class="hljs-string">//before</span> <span class="hljs-string">flattening</span>
<span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>],  [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>],[<span class="hljs-number">5</span>, <span class="hljs-number">6</span>]]<span class="hljs-string">;</span>
<span class="hljs-string">//after</span> <span class="hljs-string">flattening</span>
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
</code></pre><p>also, there is one more thing the depth of flattening that basically means how much the array should be flattened basically ...</p>
<p>let's say you have a 2-d array then you will flatten it into 1-d then depth is 1. here you reduce the array size by 1.</p>
<p>now let's say you have a 4-d array then you flatten it into a 2-d array then the depth is 2.</p>
<h1 id="heading-so-how-to-do-flattening-of-an-array">So how to do flattening of an array?</h1>
<p>You can use  <code>Array.prototype.flat()</code></p>
<p>example:- </p>
<pre><code><span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>],  [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>],[<span class="hljs-number">5</span>, <span class="hljs-number">6</span>]]<span class="hljs-string">;</span>
<span class="hljs-string">console.log(array.flat());</span>
</code></pre><p>this will flatten the array into [1,2,3,4,5,6];
let 's try another example</p>
<pre><code><span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [
  [[<span class="hljs-number">1</span>], [<span class="hljs-number">2</span>]],
  [[<span class="hljs-number">3</span>], [<span class="hljs-number">4</span>]],
  [[<span class="hljs-number">5</span>], [<span class="hljs-number">6</span>]]
]<span class="hljs-string">;</span>
<span class="hljs-string">console.log(array.flat());</span>
</code></pre><p>this will flatten the array into [[1],[2],[3],[4]] ;
oohh wait... I didn't want to do that... I want it to be more flattened ...
how to do that?
so basically by default the depth to be flattened in flat() is 1.. we can increase it by passing the desired value into the flat() function so..</p>
<pre><code><span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [
  [[<span class="hljs-number">1</span>], [<span class="hljs-number">2</span>]],
  [[<span class="hljs-number">3</span>], [<span class="hljs-number">4</span>]],
  [[<span class="hljs-number">5</span>], [<span class="hljs-number">6</span>]]
]<span class="hljs-string">;</span>
<span class="hljs-string">console.log(array.flat(2));</span>
</code></pre><p>Okay that works but what if I want to don't know to want to give the depth and want to convert any array of any dimension into a 1d array ???  how can I achieve that?
Simple just pass Infinity :) that will flat any depth of array into 1d</p>
<pre><code><span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [
  [[<span class="hljs-number">1</span>], [<span class="hljs-number">2</span>]],
  [[<span class="hljs-number">3</span>], [<span class="hljs-number">4</span>]],
  [[<span class="hljs-number">5</span>], [<span class="hljs-number">6</span>]]
]<span class="hljs-string">;</span>
<span class="hljs-string">console.log(array.flat(Infinity));</span>
</code></pre><h1 id="heading-hmm-thats-cool-can-we-flat-array-without-using-flat">Hmm.. that's cool can we flat array without using Flat () ??</h1>
<p>Yess....</p>
<p>the logic:- 
firstly we are sure we need to iterate the array  ...
and concat the array inside it...</p>
<pre><code>
<span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [
  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>],
  [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>],
  [<span class="hljs-number">5</span>, <span class="hljs-number">6</span>] 
]<span class="hljs-string">;</span>
<span class="hljs-string">function</span> <span class="hljs-string">flat(array){</span>
    <span class="hljs-string">let</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> []<span class="hljs-string">;</span>
    <span class="hljs-string">for(let</span> <span class="hljs-string">data</span> <span class="hljs-string">of</span> <span class="hljs-string">array){</span>
      <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">result.concat(data);</span>
    <span class="hljs-string">}</span>
    <span class="hljs-string">return</span> <span class="hljs-string">result</span>
<span class="hljs-string">}</span>
<span class="hljs-string">console.log(flat(array));</span>
<span class="hljs-string">//output</span> 
[ <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span> ]
</code></pre><p>that look's fine for now.. but what if .. we change the input ?</p>
<pre><code><span class="hljs-string">const</span> <span class="hljs-string">array</span> <span class="hljs-string">=</span> [
  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>],
  [<span class="hljs-number">3</span>, [<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,[<span class="hljs-number">10</span>]]],
  [<span class="hljs-number">5</span>, [<span class="hljs-number">6</span>]] 
]<span class="hljs-string">;</span>
<span class="hljs-string">function</span> <span class="hljs-string">flat(array){</span>
    <span class="hljs-string">let</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> []<span class="hljs-string">;</span>
    <span class="hljs-string">for(let</span> <span class="hljs-string">data</span> <span class="hljs-string">of</span> <span class="hljs-string">array){</span>
      <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">result.concat(data);</span>
    <span class="hljs-string">}</span>
    <span class="hljs-string">return</span> <span class="hljs-string">result</span>
<span class="hljs-string">}</span>
<span class="hljs-string">console.log(flat(array));</span>
<span class="hljs-string">//output</span>
[ <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, [ <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, [ <span class="hljs-number">10</span> ] ], <span class="hljs-number">5</span>, [ <span class="hljs-number">6</span> ] ]
</code></pre><p> hm... now how can we implement infinite flattening into this flat function?
so before concatenation, we just need to check whether the element is the array or not? 
if  it is then loop through it and repeat the entire process otherwise just merge it.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flat</span>(<span class="hljs-params">array</span>)</span>{
    let result <span class="hljs-operator">=</span> [];
    <span class="hljs-keyword">if</span>(<span class="hljs-operator">!</span>Array.isArray(array)){
        <span class="hljs-keyword">return</span> array;
    }
    <span class="hljs-keyword">for</span>(let data of array){
      result <span class="hljs-operator">=</span> result.concat(flat(data));
    }
    <span class="hljs-keyword">return</span> result
}
console.log(flat(array));
</code></pre>]]></content:encoded></item><item><title><![CDATA[Introducing MeowForms 🐈 -Build Custom forms with no backend code for free 🐱 (my first SaaS product)]]></title><description><![CDATA[Hello 👋

Gaurav This side, I hope everything is fine, on your side, and if it is not fine, don't worry it would be : ) This article is regarding MeowForms which allows you to build custom back endless for free. I have made my small side projects in ...]]></description><link>https://blog.gauravtewari.xyz/introducing-meowforms-build-custom-forms-with-no-backend-code-for-free-my-first-saas-product</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/introducing-meowforms-build-custom-forms-with-no-backend-code-for-free-my-first-saas-product</guid><category><![CDATA[React]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Auth0Hackathon]]></category><category><![CDATA[Auth0]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sun, 29 Aug 2021 11:11:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1630233404063/DbuZgE7BX.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Hello 👋
</strong></p>
<p>Gaurav This side, I hope everything is fine, on your side, and if it is not fine, don't worry it would be : ) This article is regarding MeowForms which allows you to build custom back endless for free. I have made my small side projects in past but this is the first time I have purchased a domain for a project, set up servers for it, and thought of branding it.I had a lot of fun and sleepless nights while building meowform. Meowform is my submission to the <a target="_blank" href="https://townhall.hashnode.com/auth0-hackathon">Auth0xHashnode</a> hackathon. Can't wait to show you all what I have cooked </p>
<p><strong> MeowForms 🐈 BackStory
</strong></p>
<p>Forms have been an important part of a website and always will be but when it comes to building and saving responses from them it's not that easy for beginners. I still have that mailto: in my contract me section of my portfolio website. but for such a small but important form setting up firebase or a backend would be kind of overkill. not only that what if  I am a beginner and don't know how to code my own backend.  Also, as a lazy developer I wanted a service that can handle all my forms in the future without any hazle. that's where MeowForms kick in.</p>
<p><strong> Introducing MeowForms 🐱 meow!
</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630221206759/JfVD7cCE1.gif" alt="ezgif.com-gif-maker (10).gif" /></p>
<ul>
<li>Meow form allows you to make your forms functional in a snap. you just have to add as low as one line of code and your form is functional</li>
<li>Ones you have integrated meowform in your application it will send you an email notification every time someone fills your form</li>
<li>You also get a cool dashboard to view all your responses and forms in a place </li>
<li>It supports each and every framework out there, whether it is on the web, mobile, and desktop, so No worries </li>
<li>All features are complete <em>free</em> without any limit, no subscription. you can support it on buy me a coffe. </li>
</ul>
<p><strong> ⚙️How I build it ?</strong></p>
<p>  I  have user MERN stack to build it (MongoDb, Express, React, and Nodejs) apart from that auth is powered by auth0 , and emails are handled by mailgun , although first I was of using node mailler with Zoho it had a limit of 50 emails per day which was a bottleneck for meowform then I have decided to switch to mail gun. After that, while building deploying it was a pretty hard task first I thought of used Heroku but it does not support HTTPS with the custom domain so it was a problem. later I ended up deploying the backend on Digital ocean. </p>
<p><strong>🐱  The story of design and cheese  </strong></p>
<p>Where the whole design of the website revolves around a cat whose name is Cheese :)  well if you have watched that anime you know! (tell me in the comment section )
I have used Chakra UI for building the front end of the site. and between those UI components, you will find cheese chilling, In the meowfrom the whole design of the website revolves around yellow and orange color. I tried to keep the whole design of meow from uniform.  :) all the illustrations in meowforms have been taken from icons8.  </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630217536815/Bq_8Q-lq5.png" alt="Screenshot from 2021-08-29 11-35-24.png" />
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630217483970/5eTk0msdM.png" alt="Screenshot from 2021-08-29 11-33-12.png" />
not only that to connect with the user even when the user would be getting email notifications from cheese. and the subject would look like this UvU
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630167386657/TQoq9inJkS.jpeg" alt="WhatsApp Image 2021-08-28 at 21.37.49.jpeg" />
don't worry the main body would contain the data.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630167506154/y5sYn9aIs.jpeg" alt="WhatsApp Image 2021-08-28 at 21.47.51.jpeg" />
apert from cheese Dasboard of meowform do contains features to check responses and have a look on how many people have responded to your forms .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630234990442/ufbqQ8nYM.png" alt="Screenshot from 2021-08-29 16-29-50.png" />
not only that you can also have look of what people have responded in your forms from dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1630235067452/ix7NINEzi.png" alt="Screenshot from 2021-08-29 16-27-41.png" />
I have tried to keep the UI of meowforms clean and cheesy :)</p>
<p><strong> How to use meow forms ❓ </strong></p>
<p>if you are using meowform in just plain HTML and CSS the rules are pretty much simple you just need to add meowform's server URL in the action attribute of form and do specify the method="POST"  well that's it. rest would be taken care of by cheese :)  and do remember to sign up in meowforms beforehand otherwise cheese would be sad and your forms will not work.</p>
<pre><code>&lt;form
  action="https://server.meowform.xyz/page/[yourEmail]&amp;[formName]"
  <span class="hljs-type">name</span>="form"
  <span class="hljs-keyword">method</span>="POST"
&gt;
</code></pre><p>well if want a detailed documentation checkout  <a target="_blank" href="https://docs.meowform.xyz/docs/intro">Moewforms docs</a> 
currently, I have added examples of using meowforms with HTML, React and ReactNative along with codebase so,  I would be adding more examples for frameworks soon. or you can even contribute to it</p>
<p><strong> Live Demo </strong></p>
<p><iframe width="640" height="360" src="https://www.loom.com/embed/c8cdc167f9b0405ca37e0b8a6f7ffe13"></iframe>
*my i3 machine was making a lot of noise so sorry for it . plus as a developer it is pretty hard to make videos :( kudos to all awesome YouTubers out there.</p>
<p><strong> How things work under the hood ? </strong> </p>
<p>well, whenever you are making a request to the form server, the data of the request is in the body of it. so I can easily get the response of the body but I need to parse it and arrange it in a proper way to mail it and send it to the user and store it in MongoDB to show in the dashboard later.  this is how meowFom get's gata from every request</p>
<pre><code>  <span class="hljs-keyword">let</span> incommingData = req.body;

   incommingData =  <span class="hljs-built_in">JSON</span>.stringify(incommingData);  
   incommingData = incommingData.replace(<span class="hljs-regexp">/{/g</span>,<span class="hljs-string">" "</span>);
   incommingData = incommingData.replace(<span class="hljs-regexp">/}/g</span>,<span class="hljs-string">" "</span>);
   incommingData= incommingData.split(<span class="hljs-string">","</span>);
   <span class="hljs-keyword">let</span> title = [];
   <span class="hljs-keyword">let</span> entry = [];
   <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>;i&lt;temp.length;i++){
       incommingData[i] = incommingData[i].replace(<span class="hljs-regexp">/"/g</span>,<span class="hljs-string">""</span>);
       <span class="hljs-keyword">let</span> mainArray = incommingData[i].split(<span class="hljs-string">":"</span>);
        title.push(mainArray[<span class="hljs-number">0</span>]);
        entry.push(mainArray[<span class="hljs-number">1</span>]);

   }
</code></pre><p>not only that if you are using meow from in HTML you can see it see the go back button that was I didn't know for a while you send user back to the site from which user is coming to yours by using </p>
<pre><code><span class="hljs-selector-tag">history</span><span class="hljs-selector-class">.back</span>()
</code></pre><p>And for sending emails earlier I was using nodemailer along with my zoho's mail server but I might need to send emails in bulk here so I switched to mail gun and start using mailgun js. 
this is how the mail function works in MeowForms . Cheese 🐱</p>
<pre><code><span class="hljs-keyword">const</span> mg = mailgun({<span class="hljs-attr">apiKey</span>: api_key, <span class="hljs-attr">domain</span>: DOMAIN});
   mg.messages().send( {  
    <span class="hljs-attr">from</span>: <span class="hljs-string">'Cheese 🐱&lt;cheese@meowform.xyz&gt;'</span>,
    <span class="hljs-attr">to</span>: email,
    <span class="hljs-attr">subject</span>: <span class="hljs-string">`You have got a new Response in <span class="hljs-subst">${formName}</span> Meow!  UvU `</span>,
    <span class="hljs-attr">html</span>: <span class="hljs-string">`<span class="hljs-subst">${mailBody}</span>     &lt;br/&gt; &lt;a href="https://www.buymeacoffee.com/tewarig"&gt; buy Cheese some cat food 🐟 &lt;/a&gt;`</span>
  } , <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">error, body</span>) </span>{

    <span class="hljs-keyword">if</span>(error){
      <span class="hljs-built_in">console</span>.log(error);
    }<span class="hljs-keyword">else</span>{
      <span class="hljs-built_in">console</span>.log(body);
    }
    });
</code></pre><p><strong> Up Comming in MeowForm </strong> </p>
<ul>
<li>Well having an option to export responses in excel  sheet</li>
<li>Adding examples for more frameworks and projects.</li>
</ul>
<p><strong>Support</strong> </p>
<p>⭐ <a target="_blank" href="https://github.com/tewarig/MeowForm/">Star on Github</a></p>
<p>☕  <a target="_blank" href="https://buymeacoffee.com/tewarig">Buy Me a coffe</a></p>
<p><strong> Project Links</strong></p>
<p><a target="_blank" href="https://www.meowform.xyz">MeowForm</a></p>
<p><a target="_blank" href="https://docs.meowform.xyz">MeowForm Docs</a></p>
<p><a target="_blank" href="https://github.com/tewarig/MeowForm">Github</a></p>
<p><strong> 👀 FeedBack</strong></p>
<blockquote>
<p>Hey, what are your thoughts on meowform ? how I can improve it ? did you like it ? I would love to hear your thoughts on meowform</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Introducing Torii ⛩️  Making participation to open source easy for everyone]]></title><description><![CDATA[Hello 👋 
 Gaurav This side, I hope everything is fine, on your side and if it is not fine, don't worry it would be : )
 This article is regarding my project which I build during   Clerk Hackathon 
It was a fun ride for me doing a project and getting...]]></description><link>https://blog.gauravtewari.xyz/introducing-torii-making-participation-to-open-source-easy-for-everyone</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/introducing-torii-making-participation-to-open-source-easy-for-everyone</guid><category><![CDATA[Clerk.dev]]></category><category><![CDATA[The Clerk Hackathon on Hashnode]]></category><category><![CDATA[Open Source]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sun, 25 Jul 2021 14:52:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1627222131697/VaCkvR9TZ.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Hello 👋 </strong></p>
<p> Gaurav This side, I hope everything is fine, on your side and if it is not fine, don't worry it would be : )
 This article is regarding my project which I build during   <a target="_blank" href="https://townhall.hashnode.com/a-new-hackathon-the-clerk-and-hashnode-hackathon">Clerk Hackathon</a> 
It was a fun ride for me doing a project and getting back to my developer life. Thanks, Hashnode for this awesome opportunity. Here in this article, I am going to give a little brief about my project.</p>
<p><strong>⛩️Torii - Backstory </strong></p>
<p>Last few months all I did was binge-watched anime  and regarding development I did nothing, I didn't have any project idea or motivation. So I browsed all popular GitHub repos and started contributing to them.  Some of my PR's got merge and I was quite happy,  Then I came to know about Red Hat Open Source Program and participated in it, and had an awesome experience. Now I have started attending meetups of various open-source originations.  But   It is quite hard to find projects I can contribute, Plus is Open Source Events and Programs provide awesome experience, but they are quite a little bit hard to find for beginners like me. Here Torii comes to the Help  : )</p>
<p><strong> Torii - Introduction ✨️ </strong></p>
<iframe width="640" height="313" src="https://www.loom.com/embed/ae32c6f65ce34bac93fddd0f135fc23b"></iframe>
Most of the features of Torii could be access from the homepage and the navbar itself, I tried to keep the UI decent so most students like me use it(I tried to give my best at UI designing for the app) Plus adding dark mode was one the most important feature of it. keep the UI aside
moving on to the next part.. torii has 3 important features: - 

Open Souce Events since it is a little bit hard to find what open source events are happing this month you see easily see events happenings this month and attend them, and if you about a event not listed in Torii feel free to add it : )


<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627221223469/aEtRTyHjH.png" alt="Screenshot from 2021-07-25 19-22-42.png" />
<iframe width="640" height="313" src="https://www.loom.com/embed/ea0c52f8e1f142ba85ef0fec6e8dc292"></iframe>
Also, you can get an overview of various open-source programs by selecting the month in which they are happing.. the one you click more info you will get the list of blogs and youtube videos related to that event. 

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627221842329/mOZEOxrMi.png" alt="Screenshot from 2021-07-25 19-24-10.png" />

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627221431097/HTOpkodbw.png" alt="Screenshot from 2021-07-25 19-24-24.png" />
<iframe width="640" height="313" src="https://www.loom.com/embed/a2633c776b1342e4abc8b64c749603b7"></iframe>
Not only that if are looking to new contributions just checkout the Advanced GitHub issue search in torii.. 

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627222010482/6Ow9z5YwH.png" alt="Screenshot from 2021-07-25 19-35-42.png" />
<iframe width="640" height="313" src="https://www.loom.com/embed/83667877404046938382ae34b3967d7e"></iframe>

<p>well, you can always add new Organizations, Events, Open Source Programs to Torii by clicking the plus button on the right corner but.. you need to sign in to the application, which is powered by Clerk.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627220665681/d3gNQwCJj.png" alt="Screenshot from 2021-07-25 19-12-27.png" />
Apart this.. torii also have </p>
<p>🌙 Dark Mode/🌞 light Mode </p>
<p>🇷Responsive </p>
<p>📧 Newsletter
Adding a newsletter was also important since, The user might not be able to come to the app every month, but a monthly newsletter would help to remind them about all the events.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627223478038/uifSgJCJh.png" alt="Screenshot from 2021-07-25 19-59-44.png" /></p>
<p><strong>  😌 Problems Faced </strong></p>
<p> Well, I faced a lot of problems but I would like to mention problems which could help others. </p>
<p> While browsing the webpage I was facing a problem the next page was not loading from the top, it was either loading from the end or middle (I know it's a small issue but as a user, it can be a little bit bad experience), so I wrote my own component for that, maybe  would be publishing a new npm package for that.</p>
<pre><code><span class="hljs-keyword">import</span> {useLocation} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router-dom'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ScrollToTop</span>(<span class="hljs-params">props</span>) </span>{

    <span class="hljs-keyword">const</span>  {pathname} = useLocation();
    React.useEffect(<span class="hljs-function">()=&gt;</span>{
        <span class="hljs-built_in">window</span>.scrollTo(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>);
    },[pathname])

    <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
}
</code></pre><p>Also, there was a problem with the clerk Components, they were not supporting Dark mode...  I got a really lot of help from the clerk discord server. You can easily get help if you are stuck at a place.
I notice the clerk signs and SignUp component were loading after a while so added a class to them. 
So later I ended up checking whether the user has selected the dark mode or not. and after 2sec I am adding dark mode class.</p>
<p><strong> JS </strong> </p>
<pre><code> const {colorMode , toggleColorMode }= useColorMode();
    const isDark = colorMode === <span class="hljs-string">'dark'</span>;

    const addDarkClass= <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        <span class="hljs-keyword">if</span>(isDark){
        <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function"><span class="hljs-params">()</span>=&gt;</span>{
          var x = <span class="hljs-built_in">document</span>.getElementsByClassName(<span class="hljs-string">'cl-component'</span>)[<span class="hljs-number">0</span>];
          x.classList.add(<span class="hljs-string">'dark'</span>);
        },<span class="hljs-number">2000</span>);
    }<span class="hljs-keyword">else</span>{
        <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function"><span class="hljs-params">()</span>=&gt;</span>{
            var x = <span class="hljs-built_in">document</span>.getElementsByClassName(<span class="hljs-string">'cl-component'</span>)[<span class="hljs-number">0</span>];
            x.classList.remove(<span class="hljs-string">'dark'</span>);
          },<span class="hljs-number">2000</span>);

    }
    }

    React.useEffect(addDarkClass,[isDark]);
</code></pre><p><strong> CSS </strong>
 Instead of targeting every class of clerk component I target the main class and inverted the whole hue and ended up writing one line of CSS. </p>
<pre><code><span class="hljs-selector-class">.dark</span> {
  <span class="hljs-attribute">filter</span>: <span class="hljs-built_in">invert</span>(<span class="hljs-number">1</span>) <span class="hljs-built_in">hue-rotate</span>(<span class="hljs-number">180deg</span>);
}
</code></pre><p>;) dark mode in one line 
If you are using clerk, you can solve the issue by using following snippet in a snap </p>
<p><strong> 💻 Built with </strong></p>
<ul>
<li>Reactjs</li>
<li>Nodejs</li>
<li>Express</li>
<li>MongoDB</li>
<li>Clerk</li>
<li>React-Hot-Toast</li>
<li>Charka UI</li>
</ul>
<p><strong> My Learnings</strong></p>
<ul>
<li>Tried to make this Web App's UI as good as possible since I want more and more people to use it. I tried that every feature of this app can be accessed by the user in just three clicks (I read it somewhere it's a good practice) also, I did use the Same style illustrations and Components through the web app.Also, I did try to add some micro Interactions. </li>
<li>Another Learning was Whenever you are stuck trying to find ask your peers, I was stuck with the Clerk components do not support the dark and light themes, I did ask my friends and Clerk's team. everyone helped me and it got fixed. </li>
<li>Last and not least I  implemented my sorting in the project according to the date, filter functions, Search functions. </li>
</ul>
<p><strong> Future RoadMap </strong></p>
<p>I would be working on this project on weekends, I have to add a lot of information to toriii yet.</p>
<ul>
<li>Add to calendar feature (⏰ very soon)</li>
<li>Share on social media 
much more....</li>
</ul>
<p><strong>Project Link </strong></p>
<p>Live Link : - http://toriii.vercel.app/</p>
<p>Github : - https://github.com/tewarig/torii</p>
<p><strong> Project update </strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627302500668/GH88RJT6A.png" alt="Screenshot from 2021-07-26 17-56-52.png" /></p>
]]></content:encoded></item><item><title><![CDATA[My Red Hat Open Source Contest 2021 journey]]></title><description><![CDATA[Hello 👋 
In this article, I would be sharing my journey in the Red Hat Open Source Contest.   I would be showcasing what I worked on, what I  learned throughout the journey, and challenges-faced. 
But before I start there might be a question in your...]]></description><link>https://blog.gauravtewari.xyz/my-red-hat-open-source-contest-2021-journey</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/my-red-hat-open-source-contest-2021-journey</guid><category><![CDATA[Open Source]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[journal]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Fri, 02 Jul 2021 10:27:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1625028862508/jrR0demOL.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Hello 👋 </strong></p>
<p>In this article, I would be sharing my journey in the Red Hat Open Source Contest.   I would be showcasing what I worked on, what I  learned throughout the journey, and challenges-faced. </p>
<p><em>But before I start there might be a question in your mind. 
</em>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625028913657/tGIp6mWiY.png" alt="Project - Drawing 11864893409644223144.png" /></p>
<ul>
<li><strong>  What is Red Hat Open Source Contest ❓
</strong></li>
</ul>
<p> <a target="_blank" href="https://research.redhat.com/red-hat-open-source-contest/">Red Hat Open Source Contest</a>  is organized by World's biggest open source company Red Hat . This year it started in April and ended on the 1st of July.  You can select an open-source project of your choice and contribute to it.  You get feedback on your code and it even gets included in a real project. </p>
<p>Also, you get to contribute to open source under the supervision of an experienced mentor from Red Hat. if you ever get stuck while contributing your mentors are always there to help you out.<br />While contributing you will learn a lot about various technologies and you will learn about various factors involved while building a product. it would also improve your communication skills. </p>
<blockquote>
<p>💡 Selecting projects is one of the most important parts, while selecting projects make sure you select a project in a domain you are interested in.  </p>
</blockquote>
<p>I was quite interested in web development. so I was looking for web development projects and I found out  <a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT">Fodger's DHT</a>   which is a Decentralized peer to peer cloud storage platform. You can use Fodger's DHT to store your photos 📷 ,  videos🎥 , and other data 📁. </p>
<blockquote>
<p>If I could describe the project in one word it would be  <a target="_blank" href="http://www.piedpiper.com/">pied piper</a> : )</p>
</blockquote>
<p>This was an idea and project of  <a target="_blank" href="https://www.linkedin.com/in/prajith-kesava-prasad-ab9544107/">Prajith Kesava Prasad</a>  Who was also my mentor. 
Previously, I have done web development in javascript, but the world of python was a little bit new to me.  Thanks to my mentor for helping me and introducing a whole new world of python. he helped me a lot while solving issues, I learned a lot from my mentor.</p>
<p>Currently, Fodger's DHT is in the stage of Implementation and was able to handle only one file at a request,  so my first task was to make new  API endpoints so that it could handle multiple requests. I solved this by introducing new endpoints in the backend. so every time a new file is uploaded it would send shards of the file to new endpoints of other nodes. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625028944264/wllPAQRC0.jpeg" alt="Notes_210629_233250_1.jpg “Explanation of new endpoints”" /></p>
<p>ohk now the problem of files was solved but.. suppose even if the user uploaded an image or a file how would the user know it got uploaded? we didn't have a gallery for that.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625077170989/eeMP_jLkH.gif" alt="ezgif.com-gif-maker (9).gif" /></p>
<p>so we need to redesign and reimplement the upload flow for the user. this was <strong>one of the major updates for the project.
</strong>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625028958022/WS1bhDkaV.jpeg" alt="Notes_210629_233250_2.jpg" />
it Included </p>
<ul>
<li>new animated side navigation.</li>
<li>new entirely redesigned upload flow. </li>
<li>new image gallery for showing uploaded images.
it was easy to loop through the folder and display the files. but we do need a display them properly so users can really enjoy the app. we do need a feature to full screen an image, next image, and previous image.
later I implemented this feature using   <a target="_blank" href="https://lokeshdhakar.com/projects/lightbox2/">Lightbox</a> </li>
</ul>
<blockquote>
<p>here is a sneak peek of what it looks like now </p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625052058357/4T4iD3KXYp.gif" alt="ezgif.com-gif-maker (7).gif" /></p>
<blockquote>
<p>fun fact those images we click by  <a target="_blank" href="https://www.linkedin.com/in/prajith-kesava-prasad-ab9544107/">Prajith Kesava Prasad</a>  </p>
</blockquote>
<p>not only that I did add a preview dialog so users can preview files before uploading them.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625077688002/OBwlZxZbq.png" alt="Screenshot from 2021-06-30 23-55-03.png" /></p>
<p>now since the upload part was done!! 
Now after these updates we do need a UX/UI through the app, but also the homepage should explain the idea of Fodger's DHT . 
this was my next task. Initially, the idea was to go with 
 <a target="_blank" href="https://vincentgarreau.com/particles.js/">Partilce js</a>  to make a list of nodes, then insert images in them and display them. but particle js don't have support to multiple images.
 Then we shifted to  <a target="_blank" href="https://particles.js.org/">Ts particles</a>  the community support for ts particles was so good that the maintainer of Ts particles   <a target="_blank" href="https://github.com/matteobruni">Matteo Bruni</a> 
 helped us out. and later I  was able to implement that. later we added animations also. but the home page has too many things on it. so wasn't up to the mark. Later while having our project discussion, I told my mentor about it. and we came with a completely new implementation of the home page. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1625073667725/kP7HZYzIQ.gif" alt="ezgif.com-gif-maker (8).gif" /></p>
<p>Since almost every part of the project was updated only the signup and signing part was left  so it also got redesigned and reimplemented. 
<img src="https://user-images.githubusercontent.com/54894783/120357617-442cf200-c323-11eb-8962-318fd977788f.png" alt="Screenshot from 2021-06-01 21-48-10" />
<img src="https://user-images.githubusercontent.com/54894783/120226902-c5be4a80-c265-11eb-8a61-ff4b1ffcf7b1.png" alt="Screenshot from 2021-05-31 23-01-07" /></p>
<p>So, Now Fodger's DHT is almost ready for users with its design and awesome features. </p>
<blockquote>
<p>Here is a list of the Issues and solutions I have provided. </p>
<ul>
<li><a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/issues/31">Update homepage with new design</a> 
 :: <a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/pull/43">new homepage ui</a> </li>
<li><a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/issues/34">Implement a new UI for signup/sign </a>
:: <a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/pull/37">Sign in and Sign Up ui implemented</a></li>
<li><a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/issues/33">Upload feature</a> :: <a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/pull/41">Upload page redesigned and re implemented</a></li>
<li><a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/issues/20">Develop API endpoints to send shards of the file to multiple nodes in the network</a>  ::
<a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT/pull/23">API endpoints to send file to multiple nodes in the network</a></li>
</ul>
</blockquote>
<p>During my whole journey while contributing to the project I got to learn a lot about Python and flask. Plus as a developer, my front-end and backend skills were tested and improved a lot.
 Redesigning the entire project writing  CSS for the project. and the upload feature was one of the challenging parts.</p>
<p>In the end, my grip on Font end improved, I end up learning more advanced git (no more afraid of rebasing and merge conflicts  😅)  My code is more readable now. </p>
<blockquote>
<p>My whole experience of Red Hat Open Source Contest in one word !! Subarashī   (wonderful !!)</p>
</blockquote>
<p>Do not forget to visit the project repo  and Give it is a star   <a target="_blank" href="https://github.com/Prajith007007/Fodgers_DHT">Fodger's DHT</a><br />if you wanted to start your open source journey, you can also participate in  <a target="_blank" href="https://research.redhat.com/red-hat-open-source-contest/">Red Hat Open Source Contest</a><br />If you have any other doubt related to RHOSC please leave a comment. I would be glad to resolve them. </p>
]]></content:encoded></item><item><title><![CDATA[What is exactly Dom and Dom manipulation in a snap]]></title><description><![CDATA[In this article, we will go through the dom and dom manipulation.
what is exactly dom?
DOM (document object model ) is basically a programming API for HTML and XML documents, with dom you can specify how your document should be structured.
with dom, ...]]></description><link>https://blog.gauravtewari.xyz/what-is-exactly-dom-and-dom-manipulation-in-a-snap</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/what-is-exactly-dom-and-dom-manipulation-in-a-snap</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[DOM]]></category><category><![CDATA[interview]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Tue, 01 Jun 2021 15:05:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1622559794471/jMN1Y7hDS.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, we will go through the dom and dom manipulation.</p>
<h1 id="what-is-exactly-dom">what is exactly dom?</h1>
<p>DOM (document object model ) is basically a programming API for HTML and XML documents, with dom you can specify how your document should be structured.
with dom, we can easily manipulate the elements of our document.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622558791388/Mflhz9jSV.jpeg" alt="Dom_210601_193748_1.jpg" /></p>
<p>According to the dom model, every element is an object, and even the nested tags are the objects and chile of the enclosing one. HTML dome basically looks like a tree. it is also called a tree.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622558821751/Q_XCHL7Qx.jpeg" alt="Dom_210601_193748_2.jpg" /></p>
<h1 id="try-is-yourself">try is yourself</h1>
<p>open the console of your browser right now. 
<strong>press ctrl + shift + j
</strong>
enter this in the console of your browser.</p>
<pre><code><span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">document</span>);
</code></pre><p>what do you get?
you will get the entire HTML document returned.
here the document object represents the entire web page.</p>
<p>if we want to access any element in the web page we need to start accessing that with the help of the document object.</p>
<p>for example, if you want to get the domain of the page ...  just type </p>
<pre><code>console.log(document.<span class="hljs-keyword">domain</span>)
</code></pre><h1 id="how-can-i-manipulate-dom">How can I manipulate dom?</h1>
<p>well, there are many many ways to do that...
you can use query selectors, getElement by class, or id</p>
<pre><code> <span class="hljs-built_in">document</span>.<span class="hljs-built_in">querySelector</span>(<span class="hljs-string">".myclass"</span>);
<span class="hljs-keyword">var</span> x = <span class="hljs-built_in">document</span>.<span class="hljs-built_in">querySelectorAll</span>(<span class="hljs-string">".myclasses"</span>);

<span class="hljs-comment">// if I want to change the background...</span>
x.style.backgroundColor = <span class="hljs-string">"dark"</span> ;
</code></pre><p>this is how you can easily manipulate dom.</p>
<h1 id="wrap-up">wrap up</h1>
<p>This is just a beginner article of my javascript series. where I would be sharing everything I am learning to prepare for interviews. positive or negative please leave your feedback.</p>
<p>you can connect with me on  <a target="_blank" href="https://twitter.com/OyeTewari">Twitter</a> </p>
<p>you can support me on.
<a target="_blank" href="https://www.buymeacoffee.com/tewarig0">buymeacoffe</a></p>
]]></content:encoded></item><item><title><![CDATA[A  guide on how to start building AR filters for various Social Platforms]]></title><description><![CDATA[So recently my Snapchat filters have crossed more than a million views 🥳 🥳. In this article, I would be sharing my views and experience on various AR platforms and also  we would be building Hashonde filter in the end. 
- What is an AR filter by th...]]></description><link>https://blog.gauravtewari.xyz/a-guide-on-how-to-start-building-ar-filters-for-various-social-platforms</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/a-guide-on-how-to-start-building-ar-filters-for-various-social-platforms</guid><category><![CDATA[AR]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[guide]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sun, 04 Apr 2021 10:21:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1617531643474/f7QEPlzyR.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So recently my Snapchat filters have crossed more than a million views 🥳 🥳. In this article, I would be sharing my views and experience on various AR platforms and also  we would be building Hashonde filter in the end. </p>
<p><strong>- What is an AR filter by the way? </strong></p>
<p>well Augmented reality (AR) filters are basically various graphical effects are superimposed on Real Images. After seeing these effects you will argue about things that are not present in the Image.</p>
<p>for example:- </p>
<p> Some Instagram / Snapchat filters make you look so good that you argue in your mind.. is that really me? 🃏</p>
<p>or you ever met someone who looks completely different in their social media profiles as compared in real life and that completely creates an argument in your mind about how is it possible ? that is the magic of AR my friend.💔 😢</p>
<p><iframe src="https://giphy.com/embed/xT0xezVFidHVHxe2oE" width="480" height="270" class="giphy-embed"></iframe></p><p><a href="https://giphy.com/gifs/savageimag-love-dancing-xT0xezVFidHVHxe2oE"></a></p><p></p>
<p><strong> Does it really need to learn to code for creating Filters </strong></p>
<p> Well, no most of the time.. in case if you are creating a complex filter you might need to write few lines of code (in case if you are building an ar based game or something like that .) but 99% of the time you don't need to code to make a filter for Snapchat or Facebook.</p>
<p><strong> How   to get started ?</strong></p>
<p>Well there are various tools out there if you want to make Ar cool  experiences but as a beginner, you need to be careful  about what you choose well in my case I found
  <a target="_blank" href="https://sparkar.facebook.com/ar-studio/">Spark AR</a>  😃 </p>
<p> Spark ar is the tool by Facebook it allows you to create awesome filters and effects and then publish them on Facebook and Instagram the best part is you can even use your AR filters in  a Reel, in a Video call (while using ig or messenger)
  <a target="_blank" href="https://lensstudio.snapchat.com/">Lens Studio</a> 🥰</p>
<p>Lens Studio is by Snapchat it allows you to create filters and effects for Snapchat. The best part is using a Snap camera you can use this effect on a video call while streaming or doing anything. </p>
<p>These two are the best for getting started as an AR creator as you can directly share with your friends what you are building and they can try it very easily. plus you will get all that swag to brag about on social media. </p>
<p><strong> SparkAr vs lens Studio </strong></p>
<p>Spark Ar is quite cool but the updates are too fast as compared to the lens studio. Plus in lens studio, your effects are published in 15-30 min.😃 (yes your effect will go live in just 30 min) but in spark ar, it will take around 14-15 days to publish a filter. 🥺
That's why I prefer Lens studio.. but you can go with whatever you want.  (why do I sound like my parents)</p>
<p>but  in this blog, we would be going through how to publish filters on lens  studio....(i  have planned to write a  detailed blog on Spark ar ....  )</p>
<p><strong> building a Hashnode lens </strong></p>
<p><iframe src="https://giphy.com/embed/naiatn5LxTOsU" width="480" height="480" class="giphy-embed"></iframe></p><p><a href="https://giphy.com/gifs/head-hero-boku-naiatn5LxTOsU">via GIPHY</a></p><p></p>
<p>so hash node doesn't have a filter so let's make one ... you can use this on pc using lens studio.. or on Snapchat. </p>
<p>Firstly Install and Open install lens studio. 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1617530621660/zl4zt3-WN.png" alt="Lens Studio 04-04-2021 15_20_48.png" /></p>
<p>Now just look at the Right side of the screen you will see an inspector panel. you can choose the type of Segmentation you want from here. 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1617526048519/MCyIwhSrS.png" alt="Segmentation_ - Lens Studio 04-04-2021 13_44_40 (2).png" />
I am going to choose a portrait background since I am going to make a background segmentation here.</p>
<p>Now look at the left corner of your screen .. click on the segmentation controller
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1617526360979/uP5_rcwS5.png" alt="Segmentation_ - Lens Studio 04-04-2021 14_21_02 (2).png" /></p>
<p>now from here, you can see various options to make changes </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1617526912158/9xZGEGkvO.png" alt="Segmentation_ - Lens Studio 04-04-2021 14_30_44 (2).png" />
 I would be changing the image from heart to hash node logo. and voila it is done. 
Now publishing this lens is quite easy. 
Just to the publish lens section on the top corner of the lens studio. but before publishing make sure you fill in the project details in the project info section. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1617527809195/n2acGSlJw.png" alt="publish.png" /></p>
<ul>
<li>Well scan this to access the lens we just created. </li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1617529191894/QX0DfrtZO.png" alt="snapcode.png" /></p>
<p>Well by the way I am looking for ideas to create more Snapchat filters and tutorials if you have any ideas or query feel free to leave your comment. 
In case you like my work:- 
https://www.buymeacoffee.com/tewarig</p>
]]></content:encoded></item><item><title><![CDATA[SiteSheet - Convert Google Sheet into API or  Website in a Snap.]]></title><description><![CDATA[SiteSheet is a simple web app that allows you to convert google sheets instantly into API or you can make websites out of Site Sheet. 
 Inspiration 🦾 
Well, a few days back I shared a trick to easily use google sheet as an API, but there was a lot o...]]></description><link>https://blog.gauravtewari.xyz/sitesheet-convert-google-sheet-into-api-or-website-in-a-snap</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/sitesheet-convert-google-sheet-into-api-or-website-in-a-snap</guid><category><![CDATA[Vercel Hashnode Hackathon]]></category><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[coding]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sat, 06 Feb 2021 14:03:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1612620361814/bEjTlQm44.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>SiteSheet is a simple web app that allows you to convert google sheets instantly into API or you can make websites out of Site Sheet. </p>
<p><strong> Inspiration 🦾 </strong></p>
<p>Well, a few days back I shared a trick to easily use google sheet as an API, but there was a lot of hard work involved in that, I just want that trick available to every developer just two clicks away...</p>
<p>But later I got more deeply devoted to this and thought why not make I could make an instant website builder out of this, there are many people who don't know how to code, even editing JSON or  HTML files is quite difficult for them(one year back I was the same). 
so, I thought let's build a  tool that allows you to make a website out of google sheet and for developers the possibilities are unlimited.</p>
<p><strong> Demo 🧐 </strong>  </p>
<p>Converting a google sheet into API </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612546465015/whaQZ0B5Z.gif" alt="ezgif.com-gif-maker (4).gif" /></p>
<p>Converting a google sheet into a website</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612547300084/jo8EW6L4e.gif" alt="ezgif.com-gif-maker (6).gif" /></p>
<p>just make sure your google sheet is published on the web before converting it into a website or API. </p>
<p>well, I will recommend you to try it ones yourself... 
 https://sitesheet.vercel.app/</p>
<p><strong>How does it work?? 🤔  </strong></p>
<p> well ... every google sheet has a unique id/name ( a long random string after sheets.google.com) this app is extracting that from the URL the user is inputting and using that it is generating the API endpoint.  once we have the API endpoint everything is done.   (you can API  as the waiter in a cafe or restaurant it basically helps to get data from the server. just like a waiter helps you to place an order and get your food from the chef ) 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612551157424/khzxf2vIN.png" alt="Untitled.png" /></p>
<p>also here every time the website is rendered on the client site, and if any change is done in the google sheet, it would be reflected immediately.</p>
<p><strong>How I create it 🤓</strong></p>
<p><em>warning this part might be boring</em></p>
<iframe src="https://giphy.com/embed/l0MYu38R0PPhIXe36" width="480" height="472" class="giphy-embed"></iframe>

<p>Well, firstly I am a beginner with web dev so I decided to go with React,  I am taking URLs in input from the user and have made few functions to extract the unique id of google sheet. In all the web templates the unique id is passed through the URL Parameters and to handle API's I am using Axios,  also Funnies is also included so that users have a great mood while the website is loading.
All errors are handled using React - Toasty. There are great packages, maybe you can use these in your own project.</p>
<p>I am using React for this project, and some awesome npm packages such as Axios to handle API requests, funnies to make users laugh when the data is being fetched.  React Router to handle routing and react-toasty to handle all errors.</p>
<p><strong> Features  🍨</strong></p>
<ul>
<li>It can convert any google sheet into API instantly. </li>
<li>Make your own portfolio faster than instant noodles.</li>
<li>Well you can link all your social media from an excel file.. yes you can.
-Currently, it has 5 templates you can choose from ...
you can make  <a target="_blank" href="https://sitesheet.vercel.app/me/1DW-wXUQnugLow2ErcfFhBu9P2i7CsVIHu-DPyWrOZgM">your own personal website</a>,  <a target="_blank" href="https://sitesheet.vercel.app/cafe/1x4JYGlzvRYmFI9D-iGo24qNiqlMXrc1-pOtFSkxWjC4">the website for your cafe</a>, <a target="_blank" href="https://sitesheet.vercel.app/connect/1fMBs73r8iA0BsamfHFEKlCTx2h9b9R9xtu3jF5RJZao">Your own page with all your social media profiles,</a>
,  <a target="_blank" href="https://sitesheet.vercel.app/youtube/17RSJzuUES3mWUuqD_7QTD-aC06TbQbFGl4Ih_Ulknyc">Share a list of youtube, Facebook, and other social media links in style</a> and also <a target="_blank" href="https://sitesheet.vercel.app/random/1caxj3cZpLYdISJI4WB2zgMwCuZjOI6JYIe9kae5Qiqo/">select a random user from excel file</a>. </li>
<li>Easy to use. </li>
<li>Have a great UI (I think so..  😅)</li>
<li>Saves a lot of time.</li>
<li>Mobile Friendly </li>
<li>what else you need? (comment it I will try to add that to the project )</li>
</ul>
<p><strong> Future Roadmap🔮 </strong></p>
<p>So, building this project was fun but it's not the end.</p>
<ul>
<li>I will be adding more templates. </li>
<li>Support for google from (in google from the response can be extracted into a google sheet, so it can work )</li>
</ul>
<ul>
<li>Support for custom domains </li>
<li>Much Much more...... (please give me more ideas in the comment section )</li>
</ul>
<p>The whole project is open source, Please contribute to it.   (if you find any bug free to report it.)</p>
<p>Github Repo Link:- https://github.com/tewarig/SiteSheet</p>
<p>Project Link:- https://sitesheet.vercel.app/</p>
<p>Also, thanks to Hashnode and Vercel for organizing such an awesome event. 
🤞Wish me luck.</p>
]]></content:encoded></item><item><title><![CDATA[Using Google sheets as an API For your next app]]></title><description><![CDATA[Yup, you can use google sheets as an API for your next app .. yes it is possible. Google already provides an API that you can use to read and write data in google sheets also there is  an npm package to do the same. so you can basically do all basic ...]]></description><link>https://blog.gauravtewari.xyz/using-google-sheets-as-an-api-for-your-next-app</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/using-google-sheets-as-an-api-for-your-next-app</guid><category><![CDATA[Productivity]]></category><category><![CDATA[coding]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[technology]]></category><category><![CDATA[General Programming]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sun, 24 Jan 2021 13:13:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1611493939671/75ULZ9Vt9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yup, you can use google sheets as an API for your next app .. yes it is possible. Google already provides an API that you can use to read and write data in google sheets also there is  <a target="_blank" href="https://www.npmjs.com/package/google-spreadsheet">an npm package</a> to do the same. so you can basically do all basic function in google sheets. </p>
<p><strong>But this post is not about that.. 
</strong></p>
<p><iframe src="https://giphy.com/embed/3o7TKuhdVACy1tsjGU" width="480" height="338" class="giphy-embed"></iframe></p><p><a href="https://giphy.com/gifs/southparkgifs-3o7TKuhdVACy1tsjGU">via GIPHY</a></p><p></p>
<p>This blog is about a trick which I recently discovered, It makes work a lot easy if you just need to display data from google sheet in your App.
Imagine a scenario in which you need to display data from a google sheet list of students, list of all important Contract numbers in case of emergency. or something like that If you only need to display data and you are in a hurry.</p>
<p>Firstly go to a google sheet and publish the web.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1611490304178/JIFYqQspv.gif" alt="ezgif.com-gif-maker (1).gif" /></p>
<p>once it is done now take a look at the URL of your google sheet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1611492047096/vqu5crUha.png" alt="Screenshot from 2021-01-24 17-59-03.png" />
now just copy this unique URL and </p>
<pre><code>https://spreadsheets.google.com/feeds/worksheets/{<span class="hljs-keyword">Unique</span> URL }/<span class="hljs-built_in">public</span>/basic?alt=<span class="hljs-type">json</span>
</code></pre><p>now just hit this URL in your browser or in postman.
now look a the response of the API.. just search for the entry array in the link object.. here you will find the various link to your google sheet .. but they will arrange data in a different format.. one will give you data in a list format and another will just throw data in a cell wise format. just go with format you are comfortable with. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1611492664095/i1RcVu1pr.png" alt="Screenshot from 2021-01-24 18-19-53.png" /></p>
<p>but if you hit that URL directly it will not give you data in the desired format. just remember to add a query argument (alt=json)</p>
<p>you can take this URL as an example</p>
<pre><code><span class="hljs-attribute">https</span>://spreadsheets.google.com/feeds/list/<span class="hljs-number">1</span>cXItNrEtnHRBIAo<span class="hljs-number">612</span>LImhjnsFMSbgli-R<span class="hljs-number">94</span>T<span class="hljs-number">2</span>SPhHE/od<span class="hljs-number">6</span>/public/basic?alt=json
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1611493237732/pi5mC8Wci.png" alt="Screenshot from 2021-01-24 18-29-36.png" /></p>
<p><strong>just remember to add ?alt=json at the last of the URL.
</strong>
Hope you like my articles if I can improve my writing more please let me know in the comment section. Also do react and share if it helped you.</p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with React Native: Handling Images]]></title><description><![CDATA[So, I am going to continue my series of Getting Started with React native in this section we would learn how to use images in the bare workflow of react-native. well, I would not be using Expo here since it has its own expo camera.
just fire up your ...]]></description><link>https://blog.gauravtewari.xyz/getting-started-with-react-native-handling-images</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/getting-started-with-react-native-handling-images</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[React Native]]></category><category><![CDATA[React]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sat, 02 Jan 2021 18:00:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1609647391638/DfQabEfYW.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So, I am going to continue my series of Getting Started with React native in this section we would learn how to use images in the bare workflow of react-native. well, I would not be using Expo here since it has its own expo camera.</p>
<p>just fire up your terminal and 
```npx react-native init cameraApp</p>
<pre><code>
also, remember to <span class="hljs-keyword">install</span> react <span class="hljs-keyword">native</span> camera

<span class="hljs-string">``</span><span class="hljs-string">`npx i react-native-camera</span>
</code></pre><p>now since everything is ready .. just set up your Rn app.
the basic idea here is that I would be using State to store the image and React-native-camera to click that image.</p>
<pre><code><span class="hljs-keyword">const</span>[image,setImage] = useState(<span class="hljs-literal">null</span>) ;
</code></pre><p>now I will define a function takeimage which will take camera as a input and set state of our image to the image URL also this function  will decide the quality of our image .</p>
<pre><code><span class="hljs-keyword">const</span> takePicture = <span class="hljs-keyword">async</span> (camera) =&gt; {
    <span class="hljs-keyword">try</span>{
      <span class="hljs-keyword">const</span> options = {quality: <span class="hljs-number">0.7</span> , base64:<span class="hljs-keyword">false</span>};
     <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> camera.takePictureAsync(options);
     setImage(data.uri);
    }
    <span class="hljs-keyword">catch</span>(error)
    {
      console.warn(error);
    }
  }
</code></pre><p>now in my app function, I would be using Conditional Rendering in the image if the image is present I would be displaying the image and if the image is not present then the camera would open and it would prompt the user to take an image.
also, I would be using various props of RNcamera  component  like </p>
<ul>
<li>flashMode which allows us to set the flash option of the camera.</li>
<li>captureAudio which allow us to capture audio (remember to set it to false otherwise it would give warning or errors)</li>
<li>androidCameraPermissionOptions helps us to customize the condition message so you can tell user why you need that permission.</li>
</ul>
<p>the code for this looks like this....</p>
<pre><code>{image ? (
    <span class="hljs-tag">&lt;&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.preview}</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Text</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.camText}</span>&gt;</span>Here is your new profile image.<span class="hljs-tag">&lt;/<span class="hljs-name">Text</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Image</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.clicked}</span> <span class="hljs-attr">source</span>=<span class="hljs-string">{{uri:image,width:</span> '<span class="hljs-attr">90</span>%',<span class="hljs-attr">height:</span>'<span class="hljs-attr">50</span>%'}}/&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">View</span>&gt;</span>
  <span class="hljs-tag">&lt;/&gt;</span>
  ) : 
  (<span class="hljs-tag">&lt;<span class="hljs-name">RNCamera</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.preview}</span> 
    <span class="hljs-attr">type</span>=<span class="hljs-string">{RNCamera.Constants.Type.front}</span>
     <span class="hljs-attr">captureAudio</span>=<span class="hljs-string">{false}</span> 
     <span class="hljs-attr">flashMode</span>=<span class="hljs-string">{RNCamera.Constants.FlashMode.on}</span> 
     <span class="hljs-attr">androidCameraPermissionOptions</span>=<span class="hljs-string">{{</span>
      <span class="hljs-attr">title:</span>"<span class="hljs-attr">Permission</span> <span class="hljs-attr">to</span> <span class="hljs-attr">use</span> <span class="hljs-attr">camera</span>",
      <span class="hljs-attr">message:</span>"<span class="hljs-attr">longer</span> <span class="hljs-attr">text</span> <span class="hljs-attr">to</span> <span class="hljs-attr">display</span> <span class="hljs-attr">msg</span>",
      <span class="hljs-attr">buttonPositive:</span> "<span class="hljs-attr">Hola</span>",
      <span class="hljs-attr">buttonNegative:</span> "<span class="hljs-attr">Nopa</span>",     }}
  &gt;</span>
    {({camera,status})=&gt;{
      if(status !=="READY") return <span class="hljs-tag">&lt;<span class="hljs-name">PendingView</span>/&gt;</span>
      return(
        <span class="hljs-tag">&lt;<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{flex:0,flexDirection:</span>"<span class="hljs-attr">row</span>",<span class="hljs-attr">justifyContent:</span>"<span class="hljs-attr">center</span>"}}&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.capture}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>(takePicture(camera))}&gt;<span class="hljs-tag">&lt;<span class="hljs-name">Text</span>&gt;</span>Capture<span class="hljs-tag">&lt;/<span class="hljs-name">Text</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">View</span>&gt;</span>
      )

    }}
  <span class="hljs-tag">&lt;/<span class="hljs-name">RNCamera</span>&gt;</span>)}
</code></pre><p>also now i want to add a change profile image option so i would can use a button here use call back to call setImage function which would set image to null thus conditional rendering will come into play and it would reopen the camera option. </p>
<pre><code> <span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"Click new pic"</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{setImage(null)}} &gt;<span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span>
</code></pre><p>In case you want the whole code here </p>
<p> <a target="_blank" href="https://github.com/tewarig/React-native_camera-Example/tree/master">Github Repo link </a> </p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with React Native: Taking input from the user]]></title><description><![CDATA[Here in this blog, I would be discussing how to take input from the user and how I build a simple currency converter in react native.
So, let's open our snack powered by the expo, now in this project, I would be using Alert, SafeAearView, and ScrollV...]]></description><link>https://blog.gauravtewari.xyz/getting-started-with-react-native-taking-input-from-the-user</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/getting-started-with-react-native-taking-input-from-the-user</guid><category><![CDATA[Expo]]></category><category><![CDATA[React Native]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[learning]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sun, 27 Dec 2020 18:23:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1609093365960/Mcke8nimF.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here in this blog, I would be discussing how to take input from the user and how I build a simple currency converter in react native.
So, let's open our snack powered by the expo, now in this project, I would be using Alert, SafeAearView, and ScrollView.
The alert helps us to notify the user,  SafeAreaView places our content in such a way that it is safe from the notch and cuts of the fancy screens. and why ScrollAreaView? well, we would be taking input from the user here, SafeAreaView has a special prop keyboardDismissMode which when set to true m, helps to exit the keyboard when the user taps anywhere on the screen. </p>
<p>Also, we would be taking input from the user and using the state to update that input in one go.  So we would be using the useState hook here as well.</p>
<pre><code><span class="hljs-keyword">import</span> React ,{useState} <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { StyleSheet, <span class="hljs-type">Text</span>, <span class="hljs-keyword">View</span> ,SafeAreaView ,ScrollView ,TextInput, TouchableOpacity ,Alert} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;
</code></pre><p>now since it is a currency converter app we need to get values from somewhere, so I would be making an object and later mapping through each value.</p>
<pre><code>  {<span class="hljs-built_in">Object</span>.keys(currencyPerRuppe).map(<span class="hljs-function">(<span class="hljs-params">currency</span>)=&gt;</span>(
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{currency}</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.currencyButton}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>buttonPress(currency)}
    &gt;<span class="hljs-tag">&lt;<span class="hljs-name">Text</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.currencyText}</span>&gt;</span>{currency}<span class="hljs-tag">&lt;/<span class="hljs-name">Text</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span></span>
  ))}
</code></pre><p>now, I would be working on the input part, I have used the use of the state hook and set the initial value to 0. now I would be taking value from the TextInput and finally updating the value to using setState. Also, text input provides us the option to change the keyboard type, and do remember to set the keyboard to dismiss mode as true in the scroll view.</p>
<pre><code>  <span class="hljs-tag">&lt;<span class="hljs-name">TextInput</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.inputValue}</span> <span class="hljs-attr">keyboardType</span>=<span class="hljs-string">"numeric"</span> 
          <span class="hljs-attr">placeholderTextColor</span>=<span class="hljs-string">"#c1c1c1"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Value"</span>
          <span class="hljs-attr">value</span>=<span class="hljs-string">{inputValue}</span> <span class="hljs-attr">onChangeText</span>=<span class="hljs-string">{(inputValue)</span>=&gt;</span> setInputValue(inputValue)}          
          &gt;<span class="hljs-tag">&lt;/<span class="hljs-name">TextInput</span>&gt;</span>
</code></pre><p>now finally we just need to calculate the converted value of the currency on the button press, so I would be making a function to do that also we need to handle an expectation what if the user pressed the button without entering any value?
well, we can check that and give an alert to the user.</p>
<pre><code>const buttonPress = <span class="hljs-function"><span class="hljs-params">(currency)</span> =&gt;</span> {
    <span class="hljs-keyword">if</span>(!inputValue){

      Alert.alert(
        <span class="hljs-string">"Please enter a correct value"</span>,
        <span class="hljs-string">"Enter a numeric value"</span>,
        [

          { text: <span class="hljs-string">"OK"</span>, onPress: <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"OK Pressed"</span>) }
        ],
      );
    }
    let result = <span class="hljs-built_in">parseFloat</span>(inputValue) * currencyPerRuppe[currency] ;
     setResultValue(result.toFixed(<span class="hljs-number">2</span>));
   }
</code></pre><p>here the  <a target="_blank" href="https://snack.expo.io/@tewarig0/currency-app">snack of this app</a>, if you want to check the whole app or code.</p>
<p>wow! so you read the whole article man!! who does that.. get a life man. </p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with React Native: Using Sound in project]]></title><description><![CDATA[Here in this article as in the previous one I would be making a small xylophone app and would be using some new components of react-native in this project.
I have built this same app in Flutter building it in React Native is quite fun.
Here  I would ...]]></description><link>https://blog.gauravtewari.xyz/getting-started-with-react-native-using-sound-in-project</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/getting-started-with-react-native-using-sound-in-project</guid><category><![CDATA[React]]></category><category><![CDATA[React Native]]></category><category><![CDATA[Expo]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sat, 26 Dec 2020 12:57:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1608987315060/JyqLuOgYg.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here in this article as in the previous one I would be making a small xylophone app and would be using some new components of react-native in this project.</p>
<p>I have built this same app in Flutter building it in React Native is quite fun.</p>
<p>Here  I would be using  StyleSheet, TouchableOpacity, Dimensions, and StatusBar in my app so I would be importing them into my project.</p>
<pre><code><span class="hljs-keyword">import</span> { StyleSheet, TouchableOpacity , Dimensions ,StatusBar} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;
</code></pre><p>now since this app would be containing sound files I would be making an array and would be accessing those sound files using the index. </p>
<pre><code><span class="hljs-keyword">const</span> soundList = [
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note1.wav'</span>),
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note2.wav'</span>),
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note3.wav'</span>),
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note4.wav'</span>),
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note5.wav'</span>),
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note6.wav'</span>),
  <span class="hljs-keyword">require</span>(<span class="hljs-string">'./assets/note7.wav'</span>),



];
</code></pre><p>now for playing sound I would be using  <a target="_blank" href="https://docs.expo.io/versions/latest/sdk/av/">Expo av</a> it is an awesome package in react native also the documentation is very good here I modified the final function to take arguments.</p>
<pre><code><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [sound, setSound] = React.useState();
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">playSound</span>(<span class="hljs-params">voice</span>) </span>{

    <span class="hljs-keyword">const</span> { sound } = <span class="hljs-keyword">await</span> Audio.Sound.createAsync(voice);
    setSound(sound);

    <span class="hljs-keyword">await</span> sound.playAsync(); }

  React.useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">return</span> sound
      ? <span class="hljs-function">() =&gt;</span> {
          sound.unloadAsync(); }
      : <span class="hljs-literal">undefined</span>;
  }, [sound]);
</code></pre><p> and at the last, I only have to do one thing that is to finally style the app and button I have finally taken the height of the full device and then divided it by the number of buttons. so my app works for all screen sizes.
this is what the final code looks like.</p>
<pre><code><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { StyleSheet, TouchableOpacity , Dimensions ,StatusBar} <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;
<span class="hljs-comment">// import Sound from 'react-native-sound';</span>
<span class="hljs-keyword">import</span> { Audio } <span class="hljs-keyword">from</span> <span class="hljs-string">'expo-av'</span>;
<span class="hljs-keyword">import</span> { Colors } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native/Libraries/NewAppScreen'</span>;


<span class="hljs-keyword">const</span> soundList = [
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note1.wav'</span>),
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note2.wav'</span>),
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note3.wav'</span>),
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note4.wav'</span>),
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note5.wav'</span>),
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note6.wav'</span>),
  <span class="hljs-built_in">require</span>(<span class="hljs-string">'./assets/note7.wav'</span>),



];
<span class="hljs-keyword">const</span> buttonHeight = Dimensions.get(<span class="hljs-string">'window'</span>).height ;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [sound, setSound] = React.useState();
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">playSound</span>(<span class="hljs-params">voice</span>) </span>{

    <span class="hljs-keyword">const</span> { sound } = <span class="hljs-keyword">await</span> Audio.Sound.createAsync(voice);
    setSound(sound);

    <span class="hljs-keyword">await</span> sound.playAsync(); }

  React.useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">return</span> sound
      ? <span class="hljs-function">() =&gt;</span> {
          sound.unloadAsync(); }
      : <span class="hljs-literal">undefined</span>;
  }, [sound]);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">StatusBar</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button1}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[0])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button2}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[1])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button3}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[2])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button4}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[3])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button5}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[4])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button6}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[5])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.Button7}</span> <span class="hljs-attr">onPress</span>=<span class="hljs-string">{()</span>=&gt;</span>{playSound(soundList[6])}}&gt;
   <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
      <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
<span class="hljs-comment">// console.log(soundList[]);</span>
<span class="hljs-keyword">const</span> styles = StyleSheet.create({

 <span class="hljs-attr">Button1</span>:{
   <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
   <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#EE3F0C"</span>,
 },
 <span class="hljs-attr">Button2</span>:{
  <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
  <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#EE870C"</span>,
},
<span class="hljs-attr">Button3</span>:{
  <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
  <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#FCDC0F"</span>,
},
<span class="hljs-attr">Button4</span>:{
  <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
  <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#69CF0E"</span>,
},
<span class="hljs-attr">Button5</span>:{
  <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
  <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#31B072"</span>,
},
<span class="hljs-attr">Button6</span>:{
  <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
  <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#34A7C8"</span>,
},
<span class="hljs-attr">Button7</span>:{
  <span class="hljs-attr">height</span>: buttonHeight/<span class="hljs-number">7</span>,
  <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#0f4c75"</span>,
},
});
</code></pre><p> <a target="_blank" href="https://snack.expo.io/@tewarig0/xylophone">Here is the link of Snack for this project</a> 
Hope this article was useful.</p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with React Native: Using Images in project]]></title><description><![CDATA[So, Here I would be discussing how to handle Images In React Native we would be using the Image Component, images, including network images, static resources, temporary local images, and images from local disks, such as the camera roll.
you  need to ...]]></description><link>https://blog.gauravtewari.xyz/getting-started-with-react-native-using-images-in-project</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/getting-started-with-react-native-using-images-in-project</guid><category><![CDATA[React]]></category><category><![CDATA[React Native]]></category><category><![CDATA[Expo]]></category><category><![CDATA[JSX]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sun, 20 Dec 2020 11:13:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1608486444680/b_m1Af4MG.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So, Here I would be discussing how to handle Images In React Native we would be using the Image Component, images, including network images, static resources, temporary local images, and images from local disks, such as the camera roll.
you  need to import the Image component in your code and then need to give the image component it's the source (where the image is located) </p>
<pre><code><span class="hljs-comment">// for loading images from a URL</span>
      &lt;Image source={{ <span class="hljs-attr">uri</span>: <span class="hljs-string">'https://reactnative.dev/img/tiny_logo.png'</span>, }} /&gt;
<span class="hljs-comment">//for loading Images from assets in app</span>
       <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Image</span> <span class="hljs-attr">source</span>=<span class="hljs-string">{require(</span>'<span class="hljs-attr">.</span>/<span class="hljs-attr">assets</span>/<span class="hljs-attr">IamgeName.png</span>')}/&gt;</span></span>
<span class="hljs-comment">/*aslo you can directly add style  in Image component like any other component*/</span>
     <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Image</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.ImageStyle}</span> <span class="hljs-attr">source</span>=<span class="hljs-string">{require(</span>'@<span class="hljs-attr">expo</span>/<span class="hljs-attr">snack-static</span>/<span class="hljs-attr">react-native-logo.png</span>')} /&gt;</span></span>
</code></pre><p>So now get started with the project we would be building a Dice Roller app.. for assets of dice you can  <a target="_blank" href="https://github.com/tewarig/Dice_IMG">download them from here</a> .</p>
<p>now either you can use Expo or React Native on your pc or  <a target="_blank" href="https://snack.expo.io/">use snack in the browser.</a>
remember to download assets  <a target="_blank" href="https://github.com/tewarig/Dice_IMG">from here</a>  and upload them in the assets folder if you are using expo in the browser or place them in your project if you are coding on pc. 
so now we would be using StyleSheet, View, Image, TouchableOpacity so remember to import them in your project. also, we would be using useState to change state and update the dice image.</p>
<pre><code><span class="hljs-keyword">import</span> React ,{useState}<span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { StyleSheet, <span class="hljs-keyword">View</span>,Image ,TouchableOpacity } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;
</code></pre><p>also import all images from the assets folder.. </p>
<pre><code><span class="hljs-keyword">import</span> Img1 <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/1.png'</span>;
<span class="hljs-keyword">import</span> Img2 <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/2.png'</span>;
<span class="hljs-keyword">import</span> Img3 <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/3.png'</span>;
<span class="hljs-keyword">import</span> Img4 <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/4.png'</span>;
<span class="hljs-keyword">import</span> Img5 <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/5.png'</span>;
<span class="hljs-keyword">import</span> Img6 <span class="hljs-keyword">from</span> <span class="hljs-string">'./assets/6.png'</span>;
</code></pre><p>now inside the function component, we just need to add an image component and wrap it with touchableOpacity. </p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.container}</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> &gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">StatusBar</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"auto"</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Image</span> <span class="hljs-attr">source</span>=<span class="hljs-string">{Img1}/</span>&gt;</span>

      <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">View</span>&gt;</span>
</code></pre><p>now we need to add a state to change the image so I will use the useState hook ..</p>
<pre><code>  <span class="hljs-keyword">const</span> [ImgAddress , setImgAddress]= useState(Img1);
</code></pre><p>also, time to replace the Img1 in the image source with ImgAddress.
now I will use it onPress Prop of  touchableOpacity to call a function diceRoll which will generate a random number and set a value of imgAddress between a  number 1 to 6.</p>
<pre><code>switch(randomNumber){
      <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        setImgAddress(Img1);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
        setImgAddress(Img2);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
        setImgAddress(Img3);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:
        setImgAddress(Img4);
        <span class="hljs-keyword">break</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-number">5</span>:
        setImgAddress(Img5);
        <span class="hljs-keyword">break</span>;
![Black <span class="hljs-keyword">and</span> Yellow Modern Social Media Marketing Trends Presentation.png](<span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/cdn.hashnode.com/res</span><span class="hljs-regexp">/hashnode/image</span><span class="hljs-regexp">/upload/v</span>1608462785964/ZHKSC8zOx.png)
      <span class="hljs-keyword">case</span> <span class="hljs-number">6</span>:
        setImgAddress(Img6);
        <span class="hljs-keyword">break</span>;
    }
</code></pre><p>If you want to view the full link here is the link to  <a target="_blank" href="https://snack.expo.io/@tewarig0/82bca2">snack on the expo.</a> </p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with React Native: Using the state hook]]></title><description><![CDATA[So, This blog is all about getting started with  React Native I am planning to write while series about building with react native and expo so this blog is the first part of that series.
 In case you don't know what react native is?  
Also, If you wa...]]></description><link>https://blog.gauravtewari.xyz/getting-started-with-react-native-using-the-state-hook</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/getting-started-with-react-native-using-the-state-hook</guid><category><![CDATA[React]]></category><category><![CDATA[React Native]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Expo]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Sat, 19 Dec 2020 17:40:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1608399546868/n1S7gzBfp.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So, This blog is all about getting started with  React Native I am planning to write while series about building with react native and expo so this blog is the first part of that series.</p>
<p> <a target="_blank" href="https://medium.com/@thinkwik/react-native-what-is-it-and-why-is-it-used-b132c3581df">In case you don't know what react native is? </a> </p>
<p>Also, If you want to try out React Native, Expo is the best tool, it provides the best react native developer experience.
You can  <a target="_blank" href="https://docs.expo.io/get-started/installation/">install expo </a> on your pc or use it  <a target="_blank" href="https://snack.expo.io/">online in the browser</a>.</p>
<p>Now, let's start with the basics...
<strong>What is Hook in react?
</strong>
Hooks were first introduced by the React community in 2018(I started coding in 2020, what a year to start code), Hooks allow us to use  <a target="_blank" href="https://reactjs.org/docs/faq-state.html">state </a> state and other react features without writing class, with functional components.</p>
<p><strong>What is the 'state'?</strong>
well, you might get this question in mind what is a state in React. A state is a built-in object in react that is used to contain data or information about the component. The component's state can change with time and if the state of the component changes react re-renders that Component. We can easily set how the state will change according to the user's response or any other event we set. The state component can store multiple properties.
you can use this.setState() to change the state, and setState()function merges the new and the previous state.</p>
<p>Well Well, I Know state it a little more complicated and make code a little bit bigger... That's why Hooks we introduced in React.. They make our work easy and makes code more readable. </p>
<p><strong>useState</strong> Hook allows us to use state easily.</p>
<p>I think that is enough for the theory part and  let's  <a target="_blank" href="https://snack.expo.io/">open snack in our Browser</a>,</p>
<p>In This example, we would be building a simple app with a Random Background color,  In case You are a beginner Here is the boilerplate code for the expo.</p>
<pre><code> <span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { Text, View, StyleSheet } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;




<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.container}</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">Text</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">Text</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">View</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">const</span> styles = StyleSheet.create({
  <span class="hljs-attr">container</span>: {
    <span class="hljs-attr">flex</span>: <span class="hljs-number">1</span>,
    <span class="hljs-attr">alignItems</span>: <span class="hljs-string">'center'</span>,
    <span class="hljs-attr">justifyContent</span>: <span class="hljs-string">'center'</span>
  },

});
</code></pre><p>we would be using  StyleSheet, Text, View, TouchableOpacity in this project so let's have an overview of them.</p>
<p>Text =&gt; Well you can't write text directly in React Native,In case if you want to render text in react native you need to wrap it inside 
text tag.
 have you use  p or h1 tags in HTML, we can say Text is a similar component for Text in react native.
View=&gt;The most fundamental component for building a UI, View is a container that supports layout with flexbox, style, some touch handling, and accessibility controls. The view is Just like </p><div>element in Html.
StyleSheet=&gt; A StyleSheet is an abstraction similar to CSS StyleSheets. You can also Inline styling to define the style of an object but Stylesheet make it easy for us to manage the style of whole pages in React Native
TouchableOpacity=&gt;A wrapper for making views respond properly to touches. Well, we can say it is similar to buttons that respond to touches.<p></p>
<p>now since I have given a brief of these components remember to give import them into your code.</p>
<pre><code> <span class="hljs-keyword">import</span> { StyleSheet, <span class="hljs-type">Text</span>, <span class="hljs-keyword">View</span>, TouchableOpacity } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-native'</span>;
</code></pre><p>also, we would be using the useState hook so.. import if as well</p>
<pre><code><span class="hljs-keyword">import</span> React , {useState} <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
</code></pre><p>now we can use our hook here in our function but remember to use it before the return statement in our App function.</p>
<pre><code>  <span class="hljs-keyword">const</span> [randomColor, setRandomColor] = useState(<span class="hljs-string">"rgb(0,0,0)"</span>);
</code></pre><p>now this hook will set the random color to "rgb(0,0,0)" as will keep a watch on it. if it changes react native will re-render it.
well, I am trying to make a random background generator so, I would be using RGB values it would be easy for me to edit string value.
now we will set but little bit styling and views in out code.</p>
<pre><code><span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{[styles.container,{backgroundColor:</span> <span class="hljs-attr">randomColor</span>} ]}&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">TouchableOpacity</span> &gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">Text</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.text}</span>&gt;</span>{randomColor}<span class="hljs-tag">&lt;/<span class="hljs-name">Text</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">TouchableOpacity</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">View</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
<span class="hljs-keyword">const</span> styles = StyleSheet.create({
  <span class="hljs-attr">container</span>: {
    <span class="hljs-attr">flex</span>: <span class="hljs-number">1</span>,
    <span class="hljs-attr">alignItems</span>: <span class="hljs-string">'center'</span>,
    <span class="hljs-attr">justifyContent</span>: <span class="hljs-string">'center'</span>,
  },
  <span class="hljs-attr">text</span>:{
    <span class="hljs-attr">fontSize</span>:<span class="hljs-number">30</span>,
    <span class="hljs-attr">backgroundColor</span>:<span class="hljs-string">"#0078d7"</span>,
    <span class="hljs-attr">paddingVertical</span>:<span class="hljs-number">10</span>,
    <span class="hljs-attr">paddingHorizontal</span>:<span class="hljs-number">40</span>,
    <span class="hljs-attr">color</span>:<span class="hljs-string">"#FFFFFF"</span>,
    <span class="hljs-attr">borderRadius</span>:<span class="hljs-number">15</span>,

  }
});
</code></pre><p>ahh now our app looks great and but its background does now change.. to make that works we have to make some changes...
well now since we are using Touchable Opacity it has a property onPress .. so we would use onPress to call a function change background will change the background of our app.
In the change background function, we would a random function of javascript to generate a random number.. also the set random color will help us to change the state of our color, and react native will re-render that background of our app..</p>
<pre><code>const changeBackground = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
   let color = <span class="hljs-string">"rgb("</span>+
   <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">256</span>) + 
   <span class="hljs-string">" , "</span> +
   <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">256</span>)+
   <span class="hljs-string">","</span>+ <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">256</span>) +<span class="hljs-string">")"</span>;
   setRandomColor(color);
  };
</code></pre><p> In case You want the whole code here is the link  <a target="_blank" href="https://snack.expo.io/@tewarig0/bd73e4">Snack in expo</a> </p>
</div>]]></content:encoded></item><item><title><![CDATA[Building a Random Password generator without using the random function in JavaScript.]]></title><description><![CDATA[hello guys, so I was on my quest to learn javascript and master it, I was just curious I could create my own random password generator without using the random function? well finally I was able to do the show, in this blog, I will tell how I was able...]]></description><link>https://blog.gauravtewari.xyz/building-a-random-password-generator-without-using-the-random-function-in-javascript</link><guid isPermaLink="true">https://blog.gauravtewari.xyz/building-a-random-password-generator-without-using-the-random-function-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[code]]></category><category><![CDATA[coding]]></category><category><![CDATA[learn coding]]></category><dc:creator><![CDATA[Gaurav Tewari]]></dc:creator><pubDate>Fri, 11 Dec 2020 18:31:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1607711756280/-VxphB6-J.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>hello guys, so I was on my quest to learn javascript and master it, I was just curious I could create my own random password generator without using the random function? well finally I was able to do the show, in this blog, I will tell how I was able to build that in my small project. </p>
<p>So javascript already has a Math. random() which returns a floating-point number a number between 0 and 1 (eg:-0.9343450435664102 ) .</p>
<pre><code>console.log(Math.random());
</code></pre><p>for generating a random value between 1 to 10 you can use</p>
<pre><code><span class="hljs-attribute">Math</span>.floor(Math.random() * (<span class="hljs-number">10</span> - <span class="hljs-number">1</span>)) + <span class="hljs-number">1</span>
</code></pre><p>things get tricky when I decided to create my own function(s) to generate random numbers.</p>
<p>my idea is not perfect it might generate the same numbers sometimes if you are generating numbers too fast but what decided to do was...
I thought to generate a random number I should take as many numbers of variables which keep changing according to the user. so I took the sum of date, time, month, seconds, milliseconds, UTC milliseconds even with color depth and pixel depth of the user's device, the chance of getting some of these things the same two times are very very low, later I named this as <strong>dateSum.</strong>
but I also decided to create another variable called <strong>timeSum</strong> , which would be the sum of hours, min, seconds, milliseconds.
now also the craziness does not end no.
so I took another variable megaNumber which would be dateSum % timeSum;
finally, I will get my number but I can't guarantee that is it a single-digit number, double, or even more.. since I am taking too many variables here...
so rest of the code to extract the number at the unit place and return it. (i wanted to use the inbuild function as little as possible here. but please comment the shortest code possible )</p>
<pre><code>getrandom(number) {
    <span class="hljs-keyword">var</span> today = <span class="hljs-keyword">new</span> Date();
    dateSum +=
      today.getFullYear() +
      today.getMonth() +
      today.getDate() +
      today.getSeconds() +
      today.getMilliseconds() +
      today.getUTCMilliseconds() +
      screen.width +
      screen.colorDepth +
      screen.pixelDepth;

    timeSum +=
      today.getHours() +
      today.getMinutes() +
      today.getSeconds() +
      today.getMilliseconds();
    <span class="hljs-keyword">var</span> megaNumber = dateSum % timeSum;
    <span class="hljs-keyword">var</span> numberoflength = megaNumber.toString().length;
    <span class="hljs-keyword">var</span> divide = <span class="hljs-number">1</span>;
    <span class="hljs-keyword">while</span> (numberoflength - <span class="hljs-number">1</span> &gt; <span class="hljs-number">0</span>) {
      divide *= <span class="hljs-number">10</span>;
      numberoflength--;
    }

    <span class="hljs-keyword">var</span> <span class="hljs-built_in">num</span> = megaNumber % divide;
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">num</span> &gt; <span class="hljs-number">9</span>) {
      <span class="hljs-keyword">while</span> (<span class="hljs-built_in">num</span> &gt; <span class="hljs-number">9</span>) {
        <span class="hljs-built_in">num</span> = <span class="hljs-built_in">num</span> % <span class="hljs-number">10</span>;
      }
    }
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">num</span> == <span class="hljs-number">0</span>) {
      <span class="hljs-built_in">num</span> = <span class="hljs-number">1</span>;
    }

    <span class="hljs-keyword">return</span> <span class="hljs-built_in">num</span>;
  }
</code></pre><p>so now I am able to generate random functions what I need to do is quite easy, now if want to generate random alphabets, symbols what I will do is create a simple string with all the alphabets and symbols I want and then generate a random number and return the alphabet at that index of string. </p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomBigWord</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> alphabet = <span class="hljs-string">"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"</span>;

  <span class="hljs-keyword">return</span> alphabet[<span class="hljs-built_in">Math</span>.floor((g1.getrandom() * alphabet.length) / <span class="hljs-number">10</span>)];
}
</code></pre><p>so finally my building blocks are ready..later I just created different big numbers, small numbers, and symbol functions so my random password generator can at least make a strong password.
here is what the final small project looks like.
if you want to generate your next password using my  <a target="_blank" href="https://tewarig.github.io/RandomPasswordGenerator/">project here is the link.
</a>
 <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1607710353917/opoxPkrcR.png" alt="Screenshot from 2020-12-11 23-40-18.png" />
here is the  <a target="_blank" href="https://github.com/tewarig/RandomPasswordGenerator/tree/main">repo link if you want to deep dive  into code</a> </p>
]]></content:encoded></item></channel></rss>