<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhinandan Kushwaha on Medium]]></title>
        <description><![CDATA[Stories by Abhinandan Kushwaha on Medium]]></description>
        <link>https://medium.com/@kushabhi5?source=rss-3cddf7d9d35d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*lzXbO1wdET32uCKiAKvSyw.png</url>
            <title>Stories by Abhinandan Kushwaha on Medium</title>
            <link>https://medium.com/@kushabhi5?source=rss-3cddf7d9d35d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:44:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kushabhi5/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Victory Native for Charts in an Expo React Native Project]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://kushabhi5.medium.com/using-victory-native-for-charts-in-an-expo-react-native-project-bd57d805cb8c?source=rss-3cddf7d9d35d------2"><img src="https://cdn-images-1.medium.com/max/800/1*e_0irLdfBmquNB3kKS9FpA.jpeg" width="800"></a></p><p class="medium-feed-snippet">Victory native is a powerful charting tool for react-native projects. However, the installation and initial setup might be cumbersome&#x2026;</p><p class="medium-feed-link"><a href="https://kushabhi5.medium.com/using-victory-native-for-charts-in-an-expo-react-native-project-bd57d805cb8c?source=rss-3cddf7d9d35d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://kushabhi5.medium.com/using-victory-native-for-charts-in-an-expo-react-native-project-bd57d805cb8c?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd57d805cb8c</guid>
            <category><![CDATA[victory]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[expo]]></category>
            <category><![CDATA[charts]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Fri, 09 May 2025 13:21:27 GMT</pubDate>
            <atom:updated>2025-05-09T13:21:27.450Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Debounce and Throttle in Javascript- oversimplified for intuition and interview]]></title>
            <link>https://kushabhi5.medium.com/debounce-and-throttle-in-javascript-oversimplified-for-intuition-and-interview-8de9e232341c?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8de9e232341c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[debounce]]></category>
            <category><![CDATA[rate-limiting]]></category>
            <category><![CDATA[throttle]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 10:00:49 GMT</pubDate>
            <atom:updated>2025-04-17T10:46:11.562Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YAbYmkWchSRD0uW-4tVUUQ.jpeg" /></figure><p>You’ve probably heard of <strong>debounce</strong> and <strong>throttle</strong> — they’re like the diet and exercise of rate limiting.</p><p>Need to use them in a project? Easy. Just google it or grab lodash.</p><p>In an interview? Uh oh. Time to actually <em>know</em> stuff.</p><p>This article’s got your back. We’ll start with baby versions of debounce and throttle, then evolve them like Pokémon. But first…</p><h3>⚔️ Debounce vs Throttle — The Showdown</h3><p><strong>Debounce:</strong></p><p>“Wait! Let them finish typing!”</p><p>It only runs <em>after</em> you stop calling it for t milliseconds.</p><p>Keep calling it before time’s up? It resets like a snooze button.</p><p><strong>Throttle:</strong></p><p>“I’ll answer once, then ignore you for t milliseconds.”</p><p>Calls immediately, then slaps a cooldown.</p><p>After t ms, it’s ready to go again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoQWR9Wp9yLSOsNyLrTARA.png" /></figure><p>Imagine playing a combat video game. You are armed with a <strong>pistol</strong> to put down the enemies. If you click the fire button, the <em>pistol should fire immediately</em>. Then it’s okay to wait for a few milliseconds before the next fire.</p><p>But, <em>if we used debounce here</em>, the first fire would be delayed. And out of fear, if you immediately hit the button again, this fire will also be delayed. The pistol will fire only when you remain inactive for the given timeout after hitting the fire button.</p><p>Clearly, throttle is the perfect choice for the pistol, <strong>debounce</strong> fits better in the case of a <strong>search bar</strong>.</p><blockquote><strong>Unrelated fact</strong>- throttle literally means to attack or kill someone by choking their throat.</blockquote><p>This analogy of <em>pistol =&gt; throttle</em> and <em>search-bar =&gt; debounce </em>is taken from this <a href="https://stackoverflow.com/a/52192108/7533126"><strong>stack-overflow answer</strong></a>. Please visit this to have a clearer picture.</p><h4>Implementing debounce in JS</h4><p>Here is the simplest implementation of debounce.</p><pre>let timer<br>function debounce(myFunction, delay) {<br>  if(timer) {<br>    clearTimeout(timer)<br>  }<br>  timer = setTimeout(myFunction, delay)<br>}</pre><p>Steps-</p><ol><li>Check if the timer is running (indicating the function was recently called).</li><li>If Yes, clear the timer.</li><li>Re-initialise the timer. In the same step, call the function after given delay.</li></ol><p>In fact, checking for the existence of timer is also redundant. We can call clearTimeout(timer)even if timer is uninitialised.</p><pre>// Open challenge- simplest implementation of debounce 🤓 although incomplete 😭<br><br>let timer<br>function debounce(myFunction, delay) {<br>  clearTimeout(timer)<br>  timer = setTimeout(myFunction, delay)<br>}</pre><p>Now, let’s see this in action.</p><pre>function sayHello() {<br>  console.log(&quot;Hello&quot;)<br>}<br><br>debounce(sayHello,500)<br>debounce(sayHello,500)</pre><p>Output- <em>2 Hellos or 1 Hello?</em></p><p>The first call is dismissed (as expected), and “Hello” is printed only once.<br>But what if the second call was made after 500ms? Let’s see.</p><pre>function sayHello() {<br>  console.log(&quot;Hello&quot;)<br>}<br><br>debounce(sayHello,500)<br><br>setTimeout(() =&gt; {<br>  debounce(sayHello,500)<br>}, 500) // 2nd call made after 500ms</pre><p>This time both calls are made successfully and “Hello” is printed twice (both together after 500 ms).<br>Works pretty well!</p><p><strong><em>So is that it?<br></em></strong>No!!!</p><p>Even a noob can easily spot the below issues-</p><ol><li><em>timer</em> is defined globally, while it should be a part of the debounce utility.</li><li>When calling the function with debounce, we have to pass the <em>delay</em> with each call, while it should be passed once.</li><li>What if <em>sayHello </em>accepts arguments? We can’t pass arguments with the above approach.</li></ol><p>Let’s address these issues one by one.</p><ol><li>Define timer inside debounce utility.</li></ol><pre>function createDebounce() {<br>  let timer<br>  return function debounce(myFunction, delay) {<br>    clearTimeout(timer)<br>    timer = setTimeout(myFunction, delay)<br>  }<br>}<br><br>function sayHello() {<br>  console.log(&quot;Hello&quot;)<br>}<br> <br>const debouncedFunction = createDebounce() // wrapper for debounce<br><br>debouncedFunction(sayHello, 500)<br>debouncedFunction(sayHello, 500)</pre><p>2. <em>delay</em> should not be passed with each call, instead pass it once while wrapping your function with the debounce utility.</p><pre>function createDebounce(delay) {<br>  let timer<br>  return function debounce(myFunction) { // moved the delay param to the 1st line ;)<br>    clearTimeout(timer)<br>    timer = setTimeout(myFunction, delay)<br>  }<br>}<br><br>function sayHello() {<br>  console.log(&quot;Hello&quot;)<br>}<br> <br>const debouncedFunction = createDebounce(500) // passing timeout only once<br><br>debouncedFunction(sayHello)<br>debouncedFunction(sayHello)</pre><p>3. My function <em>sayHello </em>should be able to<em> </em>accept arguments.</p><pre>function createDebounce(delay) {<br>  let timer<br>  return function debounce(myFunction, ...args) { // accept arguments<br>    clearTimeout(timer)<br>    timer = setTimeout(() =&gt; myFunction(...args), delay) // call with arguments<br>  }<br>}<br><br>function sayHello(firstName, lastName) {<br>  console.log(&quot;Hello &quot;+firstName+&quot; &quot;+lastName+&quot;!&quot;)<br>}<br> <br>const debouncedFunction = createDebounce(500) // passing the delay only once<br><br>debouncedFunction(() =&gt; sayHello(&quot;John&quot;,&quot;Doe&quot;))<br>debouncedFunction(() =&gt; sayHello(&quot;Alice&quot;,&quot;Jr&quot;))<br><br>/* notice in the above 2 lines, we passed function definitions<br>(using arrow syntax for readability)<br><br>this is because our implementation of debounce accepts a callback function,<br>and not an actual function call<br>*/</pre><p>Cool! now we have solved all the 3 issues. 😎<br>But this implementation still isn’t good enough.</p><p>But why??? 🥺</p><p>Look at the footnote comment in the above snippet. Ideally we should be able to directly call our function in 1 line, straight and simple, like this-</p><pre>debouncedSayHello(&quot;John&quot;,&quot;Doe&quot;)<br>debouncedSayHello(&quot;Alice&quot;,&quot;Jr&quot;)</pre><p>To achieve this level of simplicity, we should move the myFunction parameter to our wrapper, ie- <em>createDebounce. </em>After all, the function definition is same across all the calls. So why not pass it just once?</p><pre>function createDebounce(myFunction,delay) { // moved myFunction parameter here<br>  let timer<br>  return function (...args) { // made the inner function anonymous<br>    clearTimeout(timer)<br>    timer = setTimeout(() =&gt; myFunction(...args), delay) // call with arguments<br>  }<br>}<br><br>function sayHello(firstName, lastName) {<br>  console.log(&quot;Hello &quot;+firstName+&quot; &quot;+lastName+&quot;!&quot;)<br>}<br><br>const debouncedSayHello = createDebounce(sayHello,500)<br><br>debouncedSayHello(&quot;John&quot;,&quot;Doe&quot;) // -&gt; simply call the debouncedFunction, no additional hacks<br>debouncedSayHello(&quot;Alice&quot;,&quot;Jr&quot;)</pre><p>This is the full and final implementation of debounce, which handles pretty much all ususal scenarios with elegance! 💃</p><blockquote><strong>Add on</strong>- You can pass a default value for the delay in the createDebounce signature like this —function createDebounce(myFunction, delay = 500)</blockquote><h4>Implementing throttle in JS</h4><p>Here is the simplest implementation of throttle</p><pre>// Open challenge- simplest implementation of throttle 🤓 although incomplete 😭<br><br>let timer<br>function throttle(myFunction, delay) {<br>    if(!timer) {<br>        myFunction()<br>    }<br>    timer = setTimeout(()=&gt;{ // initialise the timer<br>      timer = null // empty the timer after given delay<br>    },delay)<br>}</pre><p>Throttle must ensure the first call be made immediately. In the above code, timer will be initially undefined so <em>myFunction() </em>will be called immediately.</p><pre>function sayHello() {<br>  console.log(&quot;Hello&quot;)<br>}<br><br>throttle(sayHello,500) // called immediately<br>throttle(sayHello,500) // dismissed<br><br>throttle(setTimeout(sayHello,500),500) // called after a delay of 500ms</pre><p>Works pretty well!</p><p>But again, it has the same issues as we found in our baby version of the debounce implememntation-</p><ol><li><em>timer</em> is defined globally, while it should be a part of the throttle utility.</li><li>When calling the function with throttle, we have to pass the delay with each call, while it should be passed once.</li><li>What if <em>sayHello </em>accepts arguments? We can’t pass arguments with the above approach.</li></ol><blockquote><strong>Deja vu?</strong></blockquote><p>This time I won’t go through each step individually. Let’s solve all the three issues together.</p><pre>function createThrottle(myFunction, delay) { // moved myFunction parameter here<br>  let timer // timer is no longer global<br>  return function (...args) { // accepts args<br>    if(!timer) myFunction(...args)<br><br>    timer = setTimeout(()=&gt;{<br>      timer = null<br>    },delay)<br>  }<br>}<br><br>// Demo<br><br>function sayHello(firstName, lastName) {<br>  console.log(&quot;Hello &quot;+firstName+&quot; &quot;+lastName+&quot;!&quot;)<br>}<br><br>const throttledSayHello = createThrottle(sayHello,500) // passing delay only once<br><br>throttledSayHello(&quot;John&quot;,&quot;Doe&quot;) // -&gt; simply call the throttledFunction, no additional hacks<br>throttledSayHello(&quot;Alice&quot;,&quot;Jr&quot;)</pre><p>This implementation of throttle handles pretty much all ususal scenarios with elegance! 💃</p><h4><strong>Appendix- </strong>clearTimeout(timer) vs timer=null</h4><p>Above, we have used both- clearTimeout(timer) and timer=null</p><p><strong>✅ clearTimeout(timer)</strong></p><p>• <strong>Purpose</strong>: Cancels the scheduled function set by setTimeout().<br>• <strong>Effect</strong>: If the timer is still pending, it will not execute.<br>• <strong>Example</strong>:</p><pre>const timer = setTimeout(() =&gt; console.log(&quot;Hello&quot;), 1000);<br>clearTimeout(timer); // Prevents &quot;Hello&quot; from being logged</pre><p><strong>🟡 timer = null</strong></p><p>• <strong>Purpose</strong>: Just reassigns the variable to null.<br>• <strong>Effect</strong>: It doesn’t cancel the actual timeout.<br>• <strong>Example</strong>:</p><pre>let timer = setTimeout(() =&gt; console.log(&quot;Hello&quot;), 1000);<br>timer = null; // &quot;Hello&quot; will still be logged after 1s</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8de9e232341c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This explanation of Monty Hall problem will convince your intuition]]></title>
            <link>https://kushabhi5.medium.com/this-explanation-of-monty-hall-problem-will-convince-your-intuition-ce54fabd4eb2?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce54fabd4eb2</guid>
            <category><![CDATA[monty-hall-problem]]></category>
            <category><![CDATA[puzzle]]></category>
            <category><![CDATA[monty-hall]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[paradox]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Tue, 01 Aug 2023 18:16:26 GMT</pubDate>
            <atom:updated>2023-08-01T18:16:26.331Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oz_rtY5kwcAiM6H_v6pbOw.jpeg" /><figcaption>Goats may have horns, but cars have horsepower!</figcaption></figure><p>I too had a hard time digesting the answer to the Monty Hall problem. I found some convincing explanations on the internet, but deep inside, my intuition kept revolting. Until finally I came up with a very convincing explanation.</p><h3>Problem statement-</h3><p>I assume you already know the problem statement as well as the answer. If not, here’s the problem statement quoted from <a href="https://en.wikipedia.org/wiki/Monty_Hall_problem"><strong>Wikipedia</strong></a>-</p><blockquote>Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No 1, and the host, who knows what’s behind the doors, opens another door, say No 3, which has a goat. He then says to you, “Do you want to pick door No 2?” Is it to your advantage to switch your choice?</blockquote><p>Most people have an intuition that switching is of no advantage, (neither loss). Since one of the doors which has a goat behind has been opened, the remaining two have a 50–50 chance of having a car or a goat.</p><p>But the correct answer is- switching always improves your chance of winning the car.</p><h3>My explanation-</h3><p>Let’s say the game rules are changed a bit- now the host does not open a door for you, instead, he does this-</p><p>After you choose one of the doors, he gives you 2 options-</p><ol><li>Stick with your current door.</li><li>Abandon your chosen door and get a chance to open both of the remaining doors, inspect what’s behind them, and pick the one you like.</li></ol><p>Would you still go with option 1?<br>Definitely not.</p><p>The original problem is exactly the same, except, instead of you seeing what’s behind the remaining two doors, the host sees them and does a favour by picking one of them which has <strong>always a goat</strong> behind.</p><p>Either <strong>you see</strong> what’s behind the doors and pick the profitable option<br>OR<br>the <strong>host sees</strong> what’s behind the doors and picks the lossy option (goat) leaving behind the profitable one for you. Both are the same, <em>right?</em></p><p>Switching in Monty Hall problem is just like going with option 2 above.</p><p>That was my explanation. If I missed something or got something wrong or if my analogy doesn’t make sense, please let me know in the comments.</p><p>By the way, here’s a fun fact from the <a href="https://en.wikipedia.org/wiki/Monty_Hall_problem">Monty Hall problem Wikipedia page</a>-</p><blockquote>Pigeons repeatedly exposed to the problem show that they rapidly learn to always switch, unlike humans.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce54fabd4eb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A step-by-step guide to integrating Microsoft Appcenter and Codepush to React Native app (Part 2)]]></title>
            <link>https://kushabhi5.medium.com/a-step-by-step-guide-to-integrating-microsoft-appcenter-and-codepush-to-react-native-app-part-2-83fc7b99c393?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/83fc7b99c393</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[appcenter]]></category>
            <category><![CDATA[code-push]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Sun, 23 May 2021 11:31:43 GMT</pubDate>
            <atom:updated>2021-05-24T09:18:45.141Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BIm78ksacBPi2R0Wd93Mvw.png" /></figure><p><strong>CodePush</strong> is a cloud service that enables Cordova and React Native developers to deploy mobile app updates directly to their users’ devices. With just a few simple steps, you will be able to make changes in your React Native app and ship them instantly to your users’ iPhones. For integrating with Android, please refer to <a href="https://kushabhi5.medium.com/a-step-by-step-guide-to-integrating-microsoft-appcenter-and-codepush-to-react-native-app-part-1-32951b7bc8d1"><strong>Part 1</strong></a>. In this part, I will only cover the iOS-specific steps, as the common steps are already covered in Part 1.</p><blockquote><strong><em>Note-</em></strong><em> </em>You can not publish the first version of your app via Appcenter. The first version must be published through App Store Connect.</blockquote><h3>1. Create app on Appcenter</h3><ol><li>Make sure that the app is already published on App Store.</li><li>Open <a href="https://appcenter.ms/">appcenter.ms</a> and click on <em>Add new app.</em></li><li>Enter your app name. Under the OS section, select <em>iOS</em>. Under Platform, select <em>React Native</em>. Click on <em>Add New App</em>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*It_MS6IVbOqQr4scE3ly1A.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>4. As we have already integrated the appcenter analytics and crashes, in Part 1, we just need to follow Step 2 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*03FW0ghwOOczpClwM6OXZA.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>5. Select <em>Distribute -&gt; CodePush </em>in the left section of the Appcenter website.</p><p>6. Now you see something like this. Click on <em>Create standard deployments.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VIZgi1YO3ezwMarWw8ykVQ.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>7. On the next screen, click on the Settings icon in the top-right corner. You may change the Staging environment to Production from here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F1y2ChEw3GJZOq5TIGk-Ew.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>8. As you click on the settings icon, the keys for production and staging will be exposed. Copy the desired key, it will be needed in Step 12.</p><h3>2. Install and integrate react native codepush</h3><p>9. I assume react-native-codepush is already installed in your project (in Part 1). If not, you can install it from <a href="https://www.npmjs.com/package/react-native-code-push"><strong>here</strong></a>.</p><p>10. Integrate the react-native-codepush package into your iOS app with the steps from <a href="https://github.com/microsoft/react-native-code-push/blob/HEAD/docs/setup-ios.md"><strong>this link</strong></a>.</p><p>11. In the above link, you will come across something like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*kXUmWPV3IFLQho7BvpCxXw.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>12. Remember the key you copied in <em>Step 8?</em> Yes, you have to use that key here. Codepush integration is now complete!</p><p>13. Next we edit the App.js file in our React native app. The steps are given in Part 1.</p><h3>3. Connect Appcenter to App Store</h3><p>14. In the Appcenter console, click on <em>Stores </em>under the <em>Distribute</em> section. Then click on <em>Connect to Store</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_K6t5ls0syqweMbuCKXfPQ.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>15. Next, select <em>App Store Connect</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*r7rWaeNCNmpxfcNcKDIT0A.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>16. In the next step, you will see a list of iOS apps associated with your Apple developer account. Choose your app and click <em>Assign</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmUMZAbvl1mUBr8kt0jqVg.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>17. As you click on assign, you may encounter this error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*0FIFatjSwliK3tDP7pdLyA.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>18. To resolve this error, you will need to generate App-specific password from your Apple developer account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mUV3oZo1MdqEBo-QPnyUxg.png" /></figure><p>19. Copy the app-specific password you just generated and paste it in appcenter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*PAfu3xTD-YEPs092N3W87Q.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>20. Next click on <em>Stores </em>under the <em>Distribute</em> section, select production. You see the following screen. Click on <em>Publish to App Store</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6FMcIiV2vXQkxemLVHDJXw.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>21. Now generate an ipa for production from Xcode and upload the ipa file here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-qlMhHTOYJBE9yUpcUsdw.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>22. In the next step enter release notes. Click <em>Next</em> and finally click <em>Publish</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*Rot1tnI85Y9Uo4EjvEUzjQ.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>23. Celebrate! you have successfully integrated Appcenter and Codepush into your iOS app. The screen now appears like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vrJLck3yrTtZAOlctz3Hcw.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>Apple will now review your app (as an update). It will take a few hours. Once approved, you can make changes in your app and run the command given in Step 4 below. As you run this command, your changes will be shipped to the end-users, within a few minutes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*-KnRI4NUAIh4ItGkI7K5TA.png" /></figure><p>If you are releasing an update through Codepush in production, don’t forget to insert the mandatory flag ‘-m’. I was stuck with this problem for 2 days. I released updates, but the changes were not reflecting in the users’ devices. Then I ran the release command like below, and it worked!</p><pre>appcenter codepush release-react -a &lt;YourName&gt;/&lt;AppName&gt; -d Production -m --description &#39;&lt;Description&gt;&#39;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83fc7b99c393" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A step-by-step guide to integrating Microsoft Appcenter and Codepush to React Native app (Part 1)]]></title>
            <link>https://kushabhi5.medium.com/a-step-by-step-guide-to-integrating-microsoft-appcenter-and-codepush-to-react-native-app-part-1-32951b7bc8d1?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/32951b7bc8d1</guid>
            <category><![CDATA[appcenter]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[code-push]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Thu, 20 May 2021 11:25:03 GMT</pubDate>
            <atom:updated>2021-05-23T15:37:48.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*s1eNT9MUlkmP_jNx9Oac3Q.png" /><figcaption>Image form appcenter.ms</figcaption></figure><p>Live reload and Hot reload make React Native awesome. But, what if a <em>Live update</em> could be done in production? This is like you make a change in your app but you don’t want to release updates on the App stores and wait for their approval. The solution is <strong>Codepush. </strong>Codepush, earlier an independent service, has now moved to Appcenter.</p><p><strong>App Center</strong> is an integrated mobile development lifecycle solution for iOS, Android, Windows, and <strong>macOS</strong> apps.</p><p>Let’s directly start with integrating them into our app. In part 1, we will be integrating Appcenter and Codepush with an Android app. For iOS, please refer to <a href="https://kushabhi5.medium.com/a-step-by-step-guide-to-integrating-microsoft-appcenter-and-codepush-to-react-native-app-part-2-83fc7b99c393"><strong>Part 2</strong></a>.</p><blockquote><strong>Note-</strong> <em>You can not publish the first version of your app via Appcenter. The first version must be published through Google Play Console. </em>(I mean, obviously the Store listings and all cannot be done through Appcenter).</blockquote><h3>1. Create app on Appcenter</h3><ol><li>Make sure that the app is already published on Play Store.</li><li>Create an account on Microsoft Appcenter.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDZj3WPCU6AsTvagDY0b-A.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>3. Click on <em>Add new app.</em></p><p>4. Write your app name and Select OS <em>Android</em>, and Platform <em>React Native</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*t_Wb46DqR83IdMAWMmLgyQ.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>5. The next screen tells you the steps to integrate <em>appcenter-analytics</em> and <em>appcenter-crashes. </em>Follow Steps 1 and 2 as shown here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*Zqf2vSDKHHiCf1iG6aeRyw.png" /><figcaption>Screenshot from appcenter.ms</figcaption></figure><p>6. Select <em>Distribute</em> in the left-navigation-section. Then select CodePush.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*HkoUK-GJr4dxnGnDJQkt9g.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>7. Now you see something like this. Click on <em>Create standard deployments.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INQGULupQg2Ujia-8gwNyA.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>8. On the next screen, click on the Settings icon in the top-right corner. You may change the Staging environment to Production from here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rVSLAd12wyxg1bSvFFJR1w.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>9. As you click on the settings icon, the keys for production and staging will be exposed. Copy the desired key, it will be needed in Step 13.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*CfU3IalkCeZPrbxirUvN9Q.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><h3>2. Install and integrate react native codepush</h3><p>10. Install <a href="https://www.npmjs.com/package/react-native-code-push"><strong>react-native-code-push</strong></a> in your project.</p><p>11. Now, you need to manually do the Android set-up for Codepush in your Android project. For this, open your project in Android Studio and follow the instructions from <a href="https://github.com/microsoft/react-native-code-push/blob/HEAD/docs/setup-android.md"><strong>this link</strong></a>.</p><p>12. In the above link, you will come across something like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*ZnSPI2jnHIM5BkkmANhTWw.png" /><figcaption>Screenshot form github.com</figcaption></figure><p>13. Remember the key you copied in <em>Step 9?</em> Yes, you have to use that key here. Codepush integration is now complete!</p><h3>3. Make changes in your React native app</h3><p>14. Now, you need to make some changes in our React native code. Open the App.js file and import Codepush</p><p><em>import CodePush from ‘react-native-code-push’;</em></p><p>15. Next define Codepush options. You can customize the options as per your need.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04f9108280e6e6d95cdb941b88b79342/href">https://medium.com/media/04f9108280e6e6d95cdb941b88b79342/href</a></iframe><p>16. In the useEffect hook in App.js, write-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc962c10fb5842fc63487a5aea252315/href">https://medium.com/media/dc962c10fb5842fc63487a5aea252315/href</a></iframe><p>So, a sample App.js file after integrating with Codepush looks like this-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2943dc4035f20a002532d74cda12851c/href">https://medium.com/media/2943dc4035f20a002532d74cda12851c/href</a></iframe><p>17. The next step is to make .aab or .apk file. Make sure to increment the <strong><em>versionCode </em></strong>in your app-level build.gradle file before generating the signed bundle/apk.</p><h3>4. Connect Appcenter to Play Store</h3><p>18. In the Appcenter console, click on <em>Stores </em>under the <em>Distribute</em> section. Then click on <em>Connect to Store</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xY4I8yTSVUxbKKJc4roRBw.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>19. In the next step, you will need to upload a .json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*0XZ3zXikoPufZRCI9iwQ9g.png" /><figcaption>Screenshot form appcenter.ms</figcaption></figure><p>20. To get the .json file you need to follow a series of steps. Open Google play console. Goto <em>Settings -&gt; Developer Account -&gt; API access.</em> Click on <em>Choose a project to link.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ONlKGDjjN9b8nGgmNC4uSA.png" /><figcaption>Screenshot from <a href="https://play.google.com/console/">https://play.google.com/console/</a></figcaption></figure><p>21. As you click on <em>Choose a project to link, </em>you will see a popup. Select <strong>I agree.</strong></p><p>22. On the next screen, select <strong><em>Create new project.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xDyXNtxg40BVTWPqt8a15A.png" /><figcaption>Screenshot from <a href="https://play.google.com/console/">https://play.google.com/console/</a></figcaption></figure><p>23. After creating a new project, you need to <strong><em>Create new service account.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-qAPmn8VEMJmoWT5Z7NgA.png" /><figcaption>Screenshot from <a href="https://play.google.com/console/">https://play.google.com/console/</a></figcaption></figure><p>24. Next you see a popup like this. Click on the <strong>Google Cloud Platform </strong>link in the popup window<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o8llgBgzGYiwvG_2Dw7Naw.png" /><figcaption>Screenshot from <a href="https://play.google.com/console/">https://play.google.com/console/</a></figcaption></figure><p>25. Now you will land on the GCP page. Here, click on <strong>Create Service account</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cow-a1S-nzxv6GqESgXPmQ.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></figcaption></figure><p>26. On the next page, Fill in the form. Enter app name. Then add a role. Finally, click on <strong>Done</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9yoJCoC6faB1zwx6vyNpw.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></figcaption></figure><p>27. On the next screen, a table showing the list of service accounts appears. Currently, it shows a single entry. Click the menu button under the actions column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BIXF6qbzztXNzs3AgZGQEQ.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></figcaption></figure><p>28. Select the <strong>Manage keys</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zl3X4RBOcQmRm2Rpc2aUfA.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></figcaption></figure><p>29. On the next screen, click on <strong>Add key</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StOJ-lJhcgU0G9sgZM_9cw.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></figcaption></figure><p>30. As you click on the Add key button, a popup appears. Select <strong>JSON</strong> and click on <strong>Create. </strong>The key is now downloaded. You needed to upload this key in step 19. Now, if you open the <em>Settings -&gt; Developer Account -&gt; API access</em> in your Google Play console, this key should appear there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0pFrl9aKID0faW1_qV-Yw.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></figcaption></figure><p>31. Now come back to the Appcenter console and upload the key you just downloaded. In the next step enter the package name of your Android app and click on <strong>Assign</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZPDusVhNXhovvJqHtMmWg.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">a</a>ppcenter.ms</figcaption></figure><h3>5. Upload your app to Appcenter</h3><p>32. Next, go to <em>Distribute -&gt; Releases</em>. Click on Create new release. Here upload your .aab or .apk file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KW3VUllDpUJujCT6tejxGQ.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">a</a>ppcenter.ms</figcaption></figure><p>33. Follow the consequent steps. In the end, you see a screen like this. Click on <strong>Publish</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bIawruBB4Nebbm0zcOuzTQ.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">a</a>ppcenter.ms</figcaption></figure><p>34. Celebrate! you have successfully integrated Appcenter and Codepush to your Android app. The screen now appears like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2VovnMedsRWAum2Of7XIg.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">a</a>ppcenter.ms</figcaption></figure><p>Google will now review your app (as an update). It will take a few hours. Once approved, you can make changes in your app and run the command given in Step 4 below. As you run this command, your changes will be shipped to the end-users, within a few minutes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*ecILj-26uMDucXzRh1OtZw.png" /><figcaption>Screenshot from <a href="https://console.cloud.google.com/">a</a>ppcenter.ms</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32951b7bc8d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crossword game using React and Firebase]]></title>
            <link>https://kushabhi5.medium.com/crossword-game-using-react-and-firebase-f5aa88fe45f1?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5aa88fe45f1</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[crossword-puzzles]]></category>
            <category><![CDATA[crossword]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Sun, 26 Jul 2020 08:11:43 GMT</pubDate>
            <atom:updated>2020-07-26T08:29:00.666Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-DaoRKVixJSFMmunVQJJQ.png" /></figure><blockquote><strong>Words, like nature, half reveal and half conceal the soul within. </strong>— <a href="https://www.thoughtco.com/alfred-lord-tennyson-poems-2831354">Alfred, Lord Tennyson</a></blockquote><p>Remember the word game we used to play in school?<br>In each turn, a player adds a single letter and tries making the biggest possible word horizontally, vertically, or diagonally. The one reaching the target score first wins the game.</p><figure><img alt="“By words we learn thoughts, and by thoughts we learn life.”" src="https://cdn-images-1.medium.com/max/600/1*AXSS4VlP1HVgn9IK3zbo5Q.gif" /></figure><p>I tried making a web version of this board game using React<em> </em>and<em> </em>Firebase. You can give it a try here- <a href="http://crosswordgame.web.app/"><strong>https://crosswordgame.web.app/</strong></a></p><p>I will be discussing here the key features of the game and the algorithms behind them. <strong><em>To read this article, you don’t need to know </em>React<em>, </em>Firebase<em>, or even </em>web development<em>.</em></strong> I will be just creating a picture of how the game works.</p><h3>Steps before the game starts -</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2vlC1skO4Nf1aQ5mROskA.png" /></figure><h3>List of Words</h3><p>It is a word game, where we need to check all the words formed with a combination of letters, so the first thing I needed was a list of all (<em>or</em> <em>most commonly used</em>) words.</p><p>I downloaded some <strong>3000 most commonly used words</strong> from the Internet.<br> Then, I realized that the list had some words which were more than 9 characters long.<br> Since the maximum grid size I allow is 9 X 9, the largest word that can be made will be 9 characters long. Also, the probability of a player making a word of 9 characters is extremely low. So, I removed all words of length greater than or equal to 8.</p><p><strong>Next, I had 2 options,-</strong></p><ul><li>Keep the words on the server and make a query to fetch the words formed at every move.</li><li>Store the words at the client-side</li></ul><p>Making a query on every move would make the game slow, so I decided to keep the words at the client-side.</p><h3>Detecting possible words</h3><p>The basic feature of this game is that it allows the user to make words in all possible directions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*dNL-SfpFsUwU6xFaRR5uxA.png" /></figure><p>So each time a player types a letter, it checks all the words formed in every direction. And the real challenge is, the words can start and end at any position in any direction, the only condition is that they should contain the latest entered letter.</p><p>Consider the situation below-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*vetv4pjG4kBueVkpdPq3Kg.png" /></figure><p>If the player fills the gap between the <strong>‘T’</strong> and the <strong>‘F’</strong> with an <strong>‘I’, </strong>the possible words will be-</p><ol><li><strong>IT </strong>(vertically upwards)</li><li><strong>IF </strong>(vertically downwards)</li><li><strong>IN</strong> (towards the upper left side)</li><li><strong>INN</strong> (towards the upper left side)</li><li><strong>FIT </strong>(taking 1 letter from below and 1 from up)</li></ol><p>The game lets the player decide which word he wants. Hence, the player sees a popup like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*2sJc82R0Anj5tX-xsPCr3A.png" /></figure><p>Obviously, anyone would choose from the biggest ones- “<strong>fit”</strong> or “<strong>inn”.<br></strong>But the game gives an option, in case the player is too strategic…</p><h4>The quest for meaningful words</h4><p>My approach to finding the words included the following steps-</p><p>First look around the last entered letter in each direction- up, down, left, right, up-left, up-right, down-left, and down-right, and check if there is a letter. If a letter is present, save it in a variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f180af6bd9da4d67d0df1a1d3a69000b/href">https://medium.com/media/f180af6bd9da4d67d0df1a1d3a69000b/href</a></iframe><p>Then, in each direction, keep traversing until you get an empty cell or reach the border of the table. Here is the code to traverse in the upward direction-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32b67a7f992903ad6ce35e217bf0117e/href">https://medium.com/media/32b67a7f992903ad6ce35e217bf0117e/href</a></iframe><p>This would just find the longest vertical string formed after a player enters a letter.</p><p>The next step is to find all the contiguous substrings in this string that contain the letter last entered (In the above example, the letter ‘<strong>I</strong>’). For each substring check whether it is a meaningful word or not. I have defined a function named <strong><em>isMeaningfulWord(word). </em></strong>It uses <strong>Binary Search</strong> and checks whether the string passed as the parameter is present in the list of meaningful words. Here is the code perform these operations-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c889eb337491421938bb3bca82d79d93/href">https://medium.com/media/c889eb337491421938bb3bca82d79d93/href</a></iframe><p>Each meaningful word found by the above code segment is stored in an array named <strong><em>meaningfulWords.</em></strong>This array stores the meaningful words, their starting indices, and their orientations in the table.</p><p>Similarly, we find meaningful words in all remaining directions, and the player is allowed to choose one of them.</p><h4>Comments and remarks by the Bot</h4><p>To make the game more engaging and lively, the Bot keeps passing comments, compliments, and remarks every now and then. It won’t hesitate to mock at you if there was a bigger word and you missed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*7zHBbEavQOxQW4HMxJjz0A.png" /></figure><p>Wondering how it passes comments and remarks? <br>Simple. It’s just selecting the right one from a list of pre-defined sentences and speaking it at the right time. Yes, it speaks. For this, I have used the <strong>Web Speech API.</strong> <em>(The Web Speech API enables you to incorporate voice data into web apps.)</em> As soon as the player enters a letter, it checks whether a bigger word was possible. If yes, it mocks at the player and if the player has already selected the biggest one, it passes a random compliment.</p><h3>Multiplayer mode</h3><p>The player who creates the room enters the configuration details in a series of steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*ys8isPOhTIICrzB2aWwQPA.png" /></figure><h4>Creating the room</h4><ol><li>At step 5, a room is created in the Firestore database and the room code is returned.</li><li>This room code is then displayed in step 6.</li><li>As other players join using the room code, the Firestore document representing the room is updated with their details.</li><li>When the number of people in the room equals the number of players selected in step 2, the game starts. This is achieved through Firebase listeners.</li></ol><h4>Playing the game</h4><p>The player who creates the room is assigned the number 1 and we call him <em>Player 1</em>. The next player joining the room will be <em>Player 2</em> and so on.<br>The Firestore document for the room has a variable named <strong>turn </strong>which denotes whose turn it is. Initially, its value is 1.</p><p>When <em>Player 1 </em>has played his turn, following things happen-</p><ol><li>The <strong>turn</strong> variable is updated to <strong>2</strong></li><li>There is a variable in the Firestore document named <strong>recentUpdate. </strong>It is an object that stores the data about the most recent change in the game.</li><li>The <strong>recentUpdate</strong> object has these fields- <em>letter, letterIndex, word, wordOrientation, wordStartIndex, and timestamp</em>.<br>With these details, we can know the last letter entered, the last word formed, and its position in the table. Whenever a player makes a move, every player’s screen is updated. This is achieved with the help of Firebase listeners.</li><li>In each turn, we check whether the score of any player has reached the target score. If it happens, the game halts and everyone is informed with the position of each player.</li></ol><p>The game celebrates the victory of the player with dazzling firecrackers. So, the player holding the first position will see colorful crackers bursting on his screen.</p><h3>Bonus- Messages, Emojis, and word-meanings</h3><p>While playing a game online with your friends, you would definitely like to send comments and reactions (like the Bot did 😂). You would love showing off your smartness 😎 or laughing at a dumb move made by your friend😀</p><p>And hence, in a game like this, chat and emoji feature is a must.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*MqNkNLDH16bAdkvxaSYXmg.png" /></figure><p>Sending and receiving messages is a piece of cake with Firebase. And the emojis can be easily made fancier with animations.</p><h4>Word meanings</h4><p>The word-meaning feature would be an icing on the cake, making the game informative besides entertaining.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*bFO5xRWpoit_F1qwop5lJg.png" /></figure><p>Suppose one of the players makes a word you are not familiar with. You can just click on the word and get its meaning as well as pronunciation.</p><p>The meaning is fetched from <a href="https://rapidapi.com/dpventures/api/wordsapi"><strong>WordsAPI</strong></a>. It is a powerful tool for word meanings, definitions usage, etc. For the pronunciation, I have used the same <strong>Web Speech API </strong>that I mentioned earlier.</p><p>The game is designed in a lucid chocolate-wooden theme, garnished with smooth animations. I am sharing the link to the game again, in case you missed it in the beginning- <a href="https://crosswordgame.web.app/"><strong>https://crosswordgame.web.app/</strong></a></p><p>The journey through its development helped me learn UI and animations in React and real-time applications of Firebase.</p><p>Thanks for bearing with me.</p><p>PS- The mobile version of the game is coming soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5aa88fe45f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bursting colourful crackers with react-native-fireworks]]></title>
            <link>https://kushabhi5.medium.com/bursting-colourful-crackers-with-react-native-fireworks-23aa2ee84edf?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/23aa2ee84edf</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-animation]]></category>
            <category><![CDATA[fireworks]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Thu, 14 May 2020 23:31:40 GMT</pubDate>
            <atom:updated>2020-05-17T11:31:58.022Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>“Don’t let anyone ever dull your sparkle .” </em>― Unknown ✨✨</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*kcIC_hr2dlDTLNLFv3AcDw.png" /><figcaption>image source- VectorStock</figcaption></figure><p>Ever felt a need to burst colourful fireworks 🎆 in your mobile app, like when there’s something to celebrate? Here’s an npm package I created for that.</p><p>To use it in your react native project, you can install it from <a href="https://npmjs.com/package/react-native-fireworks"><strong>here</strong></a><strong>.</strong></p><p>Using it as a component is as simple as -</p><pre>import Fireworks from &#39;react-native-fireworks&#39;;</pre><pre>...</pre><pre><strong>&lt;Fireworks/&gt;</strong></pre><p>This component accepts a total of 8props, all of which are optional. Below is a demonstration that uses all the 8 props-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f52abc63b679233ce1d25cc50b6c9e8b/href">https://medium.com/media/f52abc63b679233ce1d25cc50b6c9e8b/href</a></iframe><h4>Behind the scenes</h4><p>This is my first package on npm. I created it using Animated class that comes with react-native. For creating firework-like object I designed colourful circles of small radii moving in all the directions randomly and fading away.</p><p>So basically, a single firecracker consists of some 30 small circles of different colours. These circles are initially positioned at the centre of a square of width 200.</p><h4>Step 1. Drawing a single firecracker 🎇</h4><p>We begin with a square box that will contain the colourful light balls-</p><pre>&lt;View style={styles.explosionBoundary}&gt;</pre><pre>    {/*&lt;code to draw the light balls&gt;*/}</pre><pre>&lt;/View&gt;</pre><p>The box with style <strong>explosionBoundary </strong>has a fixed height and width of 200 each. The coloured light balls will move within this boundary.</p><pre>const styles = StyleSheet.create({<br>  explosionBoundary: {<br>    position: &#39;absolute&#39;,<br>    height: 200,<br>    width: 200,<br>  },<br>});</pre><p>Next, we draw some balls say 30 balls and fill them with random colours. These balls are positioned at the centre of the square box that we made above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17f7b79a0a542895ab86558fb51a4285/href">https://medium.com/media/17f7b79a0a542895ab86558fb51a4285/href</a></iframe><p>At this point, we can only see a small circle because all the balls are positioned at the same point and they all overlap. So, we need to move them in different directions to be able to see them.</p><h4>Step 2. Bursting the cracker 🧨</h4><p>To move the balls we will use Animated class from react-native. We start by creating two variables that will control the opacity and position of the light balls.</p><pre>  this.fadingOpacity = new Animated.Value(1);<br>  this.movingBall = new Animated.Value(0);</pre><p>Now we use Animated.timing with these variables and create functions that will actually animate the objects.</p><pre>animateOpacity() {<br>  this.fadingOpacity.setValue(1);<br>  Animated.timing(this.fadingOpacity, {<br>    toValue: 0,<br>    duration: 700,<br>    easing: Easing.ease,<br>    useNativeDriver: false,<br>  }).start();<br>}</pre><pre>animateBall() {<br>  this.movingBall.setValue(0);<br>  Animated.timing(this.movingBall, {<br>    toValue: 1,<br>    duration: 700,<br>    easing: Easing.ease,<br>    useNativeDriver: false,<br>  }).start();<br>}</pre><p>We use thee variables <em>this.fadingOpacity </em>and <em>this.movingBall to </em>move the balls in all the directions and fade them simultaneously. At this point, our code looks like-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cff7100007991b36b682855a32be82b/href">https://medium.com/media/6cff7100007991b36b682855a32be82b/href</a></iframe><p>The above code is enough to burst a single firecracker, and here it does!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*KnjoNYZNGGTVb0WBmqQNXA.gif" /></figure><p>Notice that the initial positions- <em>top and left </em>of all the balls are the same, i.e. 100, but the final positions are randomly set. So the distances travelled by each ball will be different. Also, the time taken by each ball to move from the initial position to the end position is the same. <em>Different distances and same time result in different velocities</em>. So the light balls move in all different directions with different velocities.</p><blockquote>But single firecracker is boring.</blockquote><p>For celebrations, we would love to burst many crackers in a series. Also, at least 4 or 5 should burst simultaneously to cover up the empty space.</p><h4>Step 3. Bursting many at a time 🧨🧨🎆🎇</h4><p>We use a variable called <strong>density</strong> that denotes the number of crackers that will burst simultaneously. The x and y coordinates <em>(top and left positions) </em>of each cracker are set randomly. We have two arrays x and y declared as state variables. Their values change at the end of every explosion, so every new explosion takes place at a new location on the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35b5f3c50804f073f27278e8c71b2ea6/href">https://medium.com/media/35b5f3c50804f073f27278e8c71b2ea6/href</a></iframe><p><strong><em>voilà</em></strong>! the amazing fireworks animation is ready-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*V5EeHQ0rfR_Kh429DQnITw.gif" /></figure><h4>Bonus- Circular firecrackers</h4><p>Crackers are more elegant when they burst into a circular path. The above code can be modified a bit to produce circular crackers.</p><p>We used random values between 0 and 200 for the final x and y positions of the light balls, putting the initial position at the centre (100,100) of the explosion box. This made the balls to move in random directions.</p><p>To make their path circular we need to calculate the x and y positions of the balls with the help of a simple equation <strong>x² +y² = r²</strong>. This is the equation for a circle in the simplest form when the centre of the circle lies at the origin. In our case, we have a square box (200 x 200) where we will make the circular path of explosion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*kAgCmFVcYLY-rAjKWqblkw.png" /></figure><p>We use the above illustration to draw the circular path. The radius of the circle is 100 and the centre lies at (100,100).</p><p>So our equation will now become -</p><p><strong>(x-100)² + (y-100)² = 100².</strong></p><p>Using this equation we plot some 20 points in a circular path. At these points, we will draw our light balls. Also, we make the balls bigger as they explode.</p><p>This results in -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*aJwtz7Uzm0xXOCD8KB-mog.gif" /></figure><p>The complete code with several customization props is available on Github <a href="https://github.com/Abhinandan-Kushwaha/Fireworks">here</a>.</p><p>Thanks a lot for stopping by and being patient. ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23aa2ee84edf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What strange dream did you see that shook you from within?]]></title>
            <link>https://kushabhi5.medium.com/what-strange-dream-did-you-see-that-shook-you-from-within-713f99c61152?source=rss-3cddf7d9d35d------2</link>
            <guid isPermaLink="false">https://medium.com/p/713f99c61152</guid>
            <category><![CDATA[short-story]]></category>
            <dc:creator><![CDATA[Abhinandan Kushwaha]]></dc:creator>
            <pubDate>Fri, 05 Jul 2019 16:10:02 GMT</pubDate>
            <atom:updated>2020-03-02T11:51:56.427Z</atom:updated>
            <content:encoded><![CDATA[<p>I was in 11th standard in CHS, Varanasi. The exams had just finished and I was in a mood to have a long walk alone. Strolling barefoot on the banks of Ganges had a soothing effect on my tired body and soul.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*0fNIISjKpaDzcCyA" /></figure><p>That day I had walked too far. It was about 9 pm and I was in no mood to return back to the hostels. I had decided to stay out the whole night.</p><p>I continued walking. The touch of cold sand grains and smooth pebbles healed my weary soul. The surrounding was alone and peaceful- far from the hustle and bustle of the city. Not a single human soul could be seen around.</p><p>At about midnight I felt drowsy. I had walked very far from the city- at least a dozen kilometres. It was impossible to return back to the hostel. Now I felt worried about where to spend the night.</p><p>Soon I spotted a small hut at some distance. I heaved a sigh of relief. As I went closer, I discovered it was a hermitage. There was a beautiful orchid beside the hut.</p><p>The owner of the hut lived alone. He had the looks of a typical Indian saint with large white beards. There was an unusual gleam in his eyes- characteristic of a fanatic. He offered me a glass of water. Tired as I was, I dozed off soon.</p><p>In my sleep, I heard a voice calling me. It said-</p><blockquote>“My child, I have been living here alone for years. I have shunned the worldly desires and I avoid human contacts. Whoever happens to visit this abandoned hermitage, is certainly sent here by holy powers. Only those who are in a consistent search of truth and wisdom have been able to reach this place.</blockquote><blockquote>I never let my visitors leave without offering them some gifts of God. My son, go ahead and ask for anything, it will be yours. Think of it as a wish. The only difference is, the wish will not be granted for free. The price must be paid.”</blockquote><p>I remember, I replied instantly, without much thinking, that I want the answers to three questions that have been bothering me since childhood. This was my wish.</p><p>He said- <em>“Okay my child, ask your questions.”</em></p><p>I asked the following three questions-</p><ul><li><strong>“Who is our creator?”</strong></li><li><strong>“What is the purpose of our life?”</strong></li><li><strong>“What happens after death?”</strong></li></ul><p>The voice said-<em> “My child, your questions shall be answered, but as I said, the price must be paid. You will have to travel to the </em><strong><em>Horizon</em></strong><em>- the place where sky and earth meet, there, my son, you will meet your answers.”</em></p><p>Saying thus, the voice disappeared.</p><p>Sweating in excitement, I got up, went straight to the saint and told him everything- the dream, the voice, the wish and my questions. I asked him to lead me to the Horizon where my questions shall be answered.</p><p>The saint smiled and said- “My dear, I will show you the place. Follow me.”</p><p>We came out of the small hut. It was dawn. The sun had yet not risen. Birds chirped. Butterflies sat on flowers. Grass and leaves were washed with dew. It was a bliss walking in that beautiful orchid with that elderly saint. For a moment, I forgot about the questions, about the horizon, and was lost in the beauty of the place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*QnHNj8JUNyzmttzG" /></figure><p>I was following the saint happily. <em>We would reach the Horizon- how beautiful would that place be where the sky touches the earth!!</em></p><p>The saint stopped near a tree. Its branches were quite low trying to embrace the earth. On one of the branches was a nest. It had small baby birds making shrill chirps. Soon the mother arrives with food. The babies open their beaks wide and the mother feeds them.</p><p>The saint says calmly- “<strong><em>My dear, here is the answer to your first question. It is no one but our parents who created us. They made us, they fed us, they taught us, they brought us up.</em></strong>”</p><p>I was satisfied with the perfect way he tried to answer my question. I could not let that sight go off. However, we moved further.</p><p>Soon we reached the city with skyscrapers, traffic, expensive cars, big malls, extravagant restaurants, people rushing to offices, children- well dressed, merrily heading to schools. It was one of the richest areas in the town.</p><p>Next, the saint led me to a slum area. Densely populated, narrow streets, houses made of mud, cloth, plastic or just anything. Children trying to clean their bodies with water that looked black- as if they brought it from the gutter. Some of them were preparing to leave for the day’s work with large plastic bags to collect the rags. Some mother had cooked rice in small dirty pots. The babies surrounded her eating the rice with nothing but salt- flies buzzing all around.</p><p>Now the saint says- <strong>“My dear, the sky and the earth never meet. There is a very vast gap between the two. I hope you understand what I mean.”</strong></p><p>I was speechless. This man was intimidating. He had just shown me the two faces of our world. I wondered, why can’t the sky lower a bit to embrace the earth, like the branches of that tree.</p><p>The saint continues- <strong><em>“If you reflect my son, you will know, that here lies the answer to your second question. The purpose of our lives is to clear the gap that exists between the sky and the earth- the rich and the poor.”</em></strong></p><p>I was sweating, my lips parched, throat dried. I was facing such immense, dark truths of life in front of my eyes. But then, I remembered, I had one more question still unanswered. This was rather a mysterious one- “What happens after death.” As I tried to speak with my parched lips, I felt someone shaking me. And there I was, lying on the bed in my hostel room.</p><p>This dream had shaken me from within. That day and today, the memory of that dream is crystal clear with each scene carved vividly in my head.</p><p>I have shared this experience on Quora also. Here is the link to that- <a href="https://qr.ae/TWhdmT">https://qr.ae/TWhdmT</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=713f99c61152" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>