<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kanak</title>
    <description>The latest articles on DEV Community by Kanak (@kanak22).</description>
    <link>https://dev.to/kanak22</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F864659%2F8815ad55-5dfb-4e7d-9ac6-cace41a61613.png</url>
      <title>DEV Community: Kanak</title>
      <link>https://dev.to/kanak22</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kanak22"/>
    <language>en</language>
    <item>
      <title>Step-by-Step Guide to Applying for GitHub Sponsor</title>
      <dc:creator>Kanak</dc:creator>
      <pubDate>Mon, 27 Feb 2023 15:53:33 +0000</pubDate>
      <link>https://dev.to/kanak22/step-by-step-guide-to-applying-for-github-sponsor-ij</link>
      <guid>https://dev.to/kanak22/step-by-step-guide-to-applying-for-github-sponsor-ij</guid>
      <description>&lt;p&gt;Are you one of those who love open source and equally love getting paid? If yes, then you are at the right place!! 🎉&lt;/p&gt;

&lt;p&gt;Recently, GitHub introduced a new feature called "GitHub Sponsor," which allows developers to receive financial support from their community of users, thus enabling them to continue working on their open source projects. In this article, we will discuss what GitHub Sponsor is, why one should apply for it, and how to apply for it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foq8ynj35zrnb2nsa82de.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foq8ynj35zrnb2nsa82de.png" alt=" " width="273" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of content :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is GitHub Sponsor?🤔&lt;/li&gt;
&lt;li&gt;Why should you apply for GitHub Sponsor?🤗&lt;/li&gt;
&lt;li&gt;
How to apply for GitHub Sponsor?😳

&lt;ul&gt;
&lt;li&gt;Step 1 :Create your GitHub Sponsors profile&lt;/li&gt;
&lt;li&gt;&lt;a href="//###Submit%20your%20contact%20information%20and%20bank%20information."&gt;Step 2 :Submit your contact information and bank information&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Step 3 :Enable two-factor authentication&lt;/li&gt;
&lt;li&gt;Step 4 :Request for approval and get paid!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Wrapping up&lt;/li&gt;

&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;Let's get started! 🥳&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;em&gt;What is GitHub Sponsor?🤔&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;It is a feature that enables developers to receive financial support from their community of users. It's a way for developers to monetize their open source projects, allowing them to continue working on them while being compensated for their efforts. The support comes in the form of recurring monthly payments, which can be as low as $1 or as high as the donor wants to give.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;em&gt;Why should you apply for GitHub Sponsor?🤗&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Sponsor provides financial assistance to you in order to keep your projects active and up to date.&lt;/li&gt;
&lt;li&gt;Recurring monthly payments help provide you with a stable income.&lt;/li&gt;
&lt;li&gt;Sponsorship strengthens your relationship with your community.&lt;/li&gt;
&lt;li&gt;Feeling valued and appreciated will motivate you to continue contributing to the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Since we know the What and Why, let's see How!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;em&gt;How to apply for GitHub Sponsor? 😳&lt;/em&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Before applying, you need to create a GitHub account if you do not already have one. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you have created an account, you need to navigate to the GitHub Sponsor page, which can be found at github.com/sponsors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F74do2k9pgyab6xa69c65.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F74do2k9pgyab6xa69c65.PNG" alt="Website Page" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://github.com/sponsors" rel="noopener noreferrer"&gt;Github Sponsor Page&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click on the "Get Sponsored" button.&lt;/li&gt;
&lt;li&gt;Then click on "Join the waitlist" for your desired account.&lt;/li&gt;
&lt;li&gt;Select your region.&lt;/li&gt;
&lt;li&gt;Choose your payment method. &lt;/li&gt;
&lt;li&gt;Click on the "Join waitlist" button.&lt;/li&gt;
&lt;li&gt;After that, you will be redirected to a screen saying, "Thank you for applying to GitHub Sponsors!"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, you need to wait for approval. GitHub will review your application and let you know if you are accepted into the program. This may take a few days or weeks, depending on the volume of applications they receive.&lt;/p&gt;

&lt;p&gt;After that you will receive a mail with a subject of &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"You're in! Welcome to GitHub Sponsors 💖".&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz1als0sp2mg7iqe2kbsz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz1als0sp2mg7iqe2kbsz.PNG" alt=" " width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you just have to configure 4 small steps. &lt;/p&gt;

&lt;p&gt;Step 1: Create your GitHub Sponsors profile &lt;br&gt;
Step 2: Submit your contact information and bank information.&lt;br&gt;
Step 3: Enable two-factor authentication.&lt;br&gt;
Step 3: Request for approval and get paid! 💰&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go to your GitHub profile, and then click on "Your sponsors."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8thgn0ctjqklngcitl1.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8thgn0ctjqklngcitl1.webp" alt="Website Page" width="394" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then you will see a list of eligible accounts; click on "Dashboard."&lt;/li&gt;
&lt;li&gt;Then set up your GitHub sponsor profile, add your bio and featured work ( which includes repositories),and&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember to provide clear and concise information about your project, its goals, and how contributions will benefit the community.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-9524%2Fmw-1000%2Fimages%2Fhelp%2Fsponsors%2Fshort-bio.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-9524%2Fmw-1000%2Fimages%2Fhelp%2Fsponsors%2Fshort-bio.webp" alt="Bio" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After filling in the details, click on "Update profile."&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2 :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-8255%2Fmw-1000%2Fimages%2Fhelp%2Fsponsors%2Fcreate-stripe-connect-account.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-8255%2Fmw-1000%2Fimages%2Fhelp%2Fsponsors%2Fcreate-stripe-connect-account.webp" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create your Stripe Connect account by following the Stripe instructions.&lt;/li&gt;
&lt;li&gt;Add your PAN card or required documentation.&lt;/li&gt;
&lt;li&gt;Submit your tax information; if you are a non-US resident, fill out Form W-8BEN (&lt;a href="https://www.irs.gov/pub/irs-pdf/iw8ben.pdf/" rel="noopener noreferrer"&gt;https://www.irs.gov/pub/irs-pdf/iw8ben.pdf/&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 3 :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add 2FA to your account by downloading any authenticator application (like Microsoft Authenticator) and scanning the QR code.&lt;/li&gt;
&lt;li&gt;Then verify the code by entering it and your 2FA is done! &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-95672%2Fmw-1000%2Fimages%2Fhelp%2F2fa%2F2fa-wizard-app-click-code.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-95672%2Fmw-1000%2Fimages%2Fhelp%2F2fa%2F2fa-wizard-app-click-code.webp" alt="2fa" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4 :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In your dashboard, you must see a button that says "Request approval" as the last step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-7121%2Fmw-1000%2Fimages%2Fhelp%2Fsponsors%2Frequest-approval-button.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.github.com%2Fassets%2Fcb-7121%2Fmw-1000%2Fimages%2Fhelp%2Fsponsors%2Frequest-approval-button.webp" alt="Website Page" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the button and relaxxxx now!🤭&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your profile has been submitted. Github will review your application, and it might take some days. Your profile will be live on Github Sponsor as soon as you are approved.&lt;/p&gt;

&lt;p&gt;The mail will look like this, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt9hlik2rtii4dm2wagi.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt9hlik2rtii4dm2wagi.PNG" alt=" " width="713" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By following the steps you can increase your chances of making money while doing open-source. &lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;I hope you found this article helpful.&lt;/p&gt;

&lt;p&gt;If you liked this post, follow me for more of these 🙂&lt;/p&gt;

&lt;p&gt;Also, share your Github Sponsor's profile! 👇🏻&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>productivity</category>
      <category>workflow</category>
    </item>
    <item>
      <title>Trapping Rainwater 🌊</title>
      <dc:creator>Kanak</dc:creator>
      <pubDate>Sat, 03 Sep 2022 07:44:39 +0000</pubDate>
      <link>https://dev.to/kanak22/trapping-rainwater-5f0b</link>
      <guid>https://dev.to/kanak22/trapping-rainwater-5f0b</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Today's Question:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It's a rainy day, and you are given n bars, each of 1 unit in width. How will you calculate the amount of water trapped between them? 🌧️ &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;First try to solve the problem here: &lt;a href="https://leetcode.com/problems/trapping-rain-water/" rel="noopener noreferrer"&gt;https://leetcode.com/problems/trapping-rain-water/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Stuck? 🤔 &lt;/p&gt;

&lt;p&gt;No worries, I've got you covered!!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Let's think on it&lt;/strong&gt;💭 
&lt;/h3&gt;

&lt;p&gt;We need to figure out how many water units will be trapped after it rains...How can we do this?&lt;/p&gt;

&lt;p&gt;Total water means we can calculate the individual water stored by each bar and sum it up. Sounds right?&lt;/p&gt;

&lt;p&gt;Yes, so to calculate the individual water stored, we must know from which bar to which bar the water is being stored ... Can we find the maximum bar on both sides of the element?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YES! leftMax &amp;amp; rightMax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But water won't be trapped up to the height of the larger one among the leftMax &amp;amp; rightMax.&lt;/p&gt;

&lt;p&gt;So, we need to get the minimum (leftMax, rightMax).&lt;/p&gt;

&lt;p&gt;And since we are trying to find the amount of water trapped, we need to know the remaining height for each bar for which the water will be trapped.&lt;/p&gt;

&lt;p&gt;Therefore, we will subtract the height of the bar from &lt;strong&gt;minimum (leftMax, rightMax) for each bar and then sum it&lt;/strong&gt; up to get the total water.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Algorithm:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Take maximum of left and side parts of a given bar.&lt;/li&gt;
&lt;li&gt;Get the water for each bar by min(leftMax, rightMax) - bar[i].&lt;/li&gt;
&lt;li&gt;Sum up the water.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int trap(vector&amp;lt;int&amp;gt;&amp;amp; height) {

        int n = height.size(); 
        int waterSum = 0;
        for(int i=0; i&amp;lt;n; i++){

            int leftMax = 0, rightMax = 0;
            for(int j=i; j&amp;gt;=0; j--){
                leftMax = max(leftMax,height[j]);
            }

            for(int j=i; j&amp;lt;n; j++){
                rightMax = max(rightMax,height[j]);
            }

            int h = min(leftMax,rightMax); 
            waterSum+=h-height[i];
        }

        return waterSum;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; Time: O(N*N) Space: O(1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Time complexity is increasing in this solution. To reduce this, we can store the &lt;strong&gt;leftMax and rightMax in separate arrays&lt;/strong&gt; as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int trap(vector&amp;lt;int&amp;gt;&amp;amp; height) {

        int n = height.size();
        vector&amp;lt;int&amp;gt; water;

        vector&amp;lt;int&amp;gt; l(n);
        vector&amp;lt;int&amp;gt; r(n);
        l[0]=height[0];
        r[n-1]=height[n-1];

        for(int i=1; i&amp;lt;n; i++){
            l[i]=max(l[i-1],height[i]);
        }

        for(int i=n-2; i&amp;gt;=0; i--){
            r[i]=max(r[i+1],height[i]);
        }

        for(int i=0; i&amp;lt;n; i++){
            int a = min(l[i],r[i]);
            water.push_back(a-height[i]);
        }

        int x = accumulate(water.begin(),water.end(),0);
        return x;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; Time: O(N) Space: O(N)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To further optimize this, we can make the space complexity O(1) from O(N).&lt;/p&gt;

&lt;h3&gt;
  
  
  How will we do this?
&lt;/h3&gt;

&lt;p&gt;Well, we can use &lt;strong&gt;Two-Pointer Approach&lt;/strong&gt;. In this, left pointer will be at the start of the array and right pointer will be at the end.&lt;/p&gt;

&lt;p&gt;Whenever the left element is small or equal to the right one, we have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check if it is the maximum on the left side. If so, update the leftMax. Else,&lt;/li&gt;
&lt;li&gt;Because there will always be a bar on the right side that is greater than height [left], we can sum it up in ans by subtracting height [left].&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And if the right element is smaller than the left one, we can do the same two options but for the right side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; int trap(vector&amp;lt;int&amp;gt;&amp;amp; height) {

        int n = height.size();
        int leftMax = 0, rightMax = 0, left=0, right=n-1, ans=0;

        while(left&amp;lt;=right){

            if(height[left]&amp;lt;=height[right]){
                if(leftMax&amp;lt;= height[left]){
                    leftMax= height[left];
                } else{
                    ans +=leftMax-height[left];
                }
                left++;
            } 
            else{
                if(height[right]&amp;gt;=rightMax){
                    rightMax = height[right];
                } else{
                    ans +=rightMax-height[right];
                }
                 right--;
            }
        }
        return ans;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; Time: O(N) Space: O(1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's all for this one! Thankyou for reading till the end. 😃&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Synopsis:&lt;/p&gt;

&lt;p&gt;For brute force, find the maximum of both sides and sum it for each bar.&lt;/p&gt;

&lt;p&gt;A better approach would be to store the left and right maximums in separate arrays.&lt;/p&gt;

&lt;p&gt;Two-pointer is the best approach.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  ✒ New to my blog?
&lt;/h4&gt;

&lt;p&gt;Hey! I am Kanak.&lt;/p&gt;

&lt;p&gt;I am a MERN stack developer and an open-source enthusiast. I write on data structures and algorithms and develop cheat-sheets on DSA topics. I have also documented my DSA journey on Twitter for the last 2 months.&lt;/p&gt;

&lt;p&gt;Follow me for more such content. 🎉&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>cpp</category>
      <category>leetcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Adding Voice Assistant to React Apps with Alan AI</title>
      <dc:creator>Kanak</dc:creator>
      <pubDate>Fri, 27 May 2022 10:18:52 +0000</pubDate>
      <link>https://dev.to/kanak22/adding-voice-assistant-to-react-apps-with-alan-ai-5f37</link>
      <guid>https://dev.to/kanak22/adding-voice-assistant-to-react-apps-with-alan-ai-5f37</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Have you used Cortana? Is Siri your best friend? Is it your go-to assistant whenever you face an obstacle?💭&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If yes, then you would know how the development of voice assistants in our lives has made it easier since it requires minimal effort. Forecasts suggest that by 2024, the number of digital voice assistants will reach 8.4 billion units, a number higher than the world’s population, and 31% of smartphone users worldwide use voice search at least once a week.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A voice assistant is a digital assistant that uses voice recognition, language processing algorithms, and voice synthesis to listen to specific voice commands and return relevant information or perform specific functions as requested by the user.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Voice assistants are integrated into many of the devices we use daily, such as cell phones, computers, and smart speakers. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Would you like to have a voice assistant in your apps too? 💬&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You might be thinking that to add an Intelligent Voice Interface to your app, you'll need to delve deep into machine learning and natural language processing, which will take a long time. &lt;/p&gt;

&lt;p&gt;Here, &lt;strong&gt;Alan AI&lt;/strong&gt; comes to your rescue. Alan AI is a B2B Voice AI platform for developers to deploy and manage voice interfaces for enterprise apps. It provides an AI-based backend as a service tool to add conversational AI to your apps. &lt;/p&gt;

&lt;p&gt;It also recognizes user context and learns about the UI of your app to develop workflows and gets trained on your app's vocabulary. &lt;/p&gt;

&lt;p&gt;With its developer-friendly console and documentation, it is easier for anyone to integrate it into their app. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;So let's integrate Alan AI voice assistant into a React App.🎉&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What we will be building?🤔&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We will be building a &lt;strong&gt;QuoteBook 📚 React app&lt;/strong&gt; with Alan AI's voice assistant integration. This QuoteBook project will simply have quotes and we will customize the voice assistant to tell us the quotes of a specific speaker. It will look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6itx82bq57xg49o1z8r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6itx82bq57xg49o1z8r.png" alt="QuoteBook React App" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Project setup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a react app using npx &lt;code&gt;create-react-app&lt;/code&gt; command.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app quoteBook
cd quoteBook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run the react app using &lt;code&gt;npm start&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create components and the file structure should be like this
,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstb3v6eykqzke6g1hicj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstb3v6eykqzke6g1hicj.PNG" alt="Fil structure for Alan AI integration" width="267" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now install &lt;strong&gt;Alan AI Web SDK&lt;/strong&gt; to the app, we will be using the npm package to install the dependency.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install @alan-ai/alan-sdk-web 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Import alanBtn to your React component
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import alanBtn from "@alan-ai/alan-sdk-web";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now let’s add code in the components and App.jsx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;App.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useEffect } from "react";
import Header from "./Header";
import Footer from "./Footer";
import Quote from "./Quote";
import { Quotes } from "./Quotes";
import alanBtn from "@alan-ai/alan-sdk-web";

function App() {

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Header /&amp;gt;
      {Quotes.map((quoteItem, index) =&amp;gt; {
        return (
          &amp;lt;Quote
            key={index}
            id={index}
            quote={quoteItem.quote}
            author={quoteItem.author}
          /&amp;gt;
        );
      })}
      &amp;lt;Footer /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Header.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

function Header() {
  return (
    &amp;lt;header&amp;gt;
      &amp;lt;h1&amp;gt;QuoteBook&amp;lt;/h1&amp;gt;
    &amp;lt;/header&amp;gt;
  );
}

export default Header;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Footer.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

function Footer() {
  const year = new Date().getFullYear();
  return (
    &amp;lt;footer&amp;gt;
      &amp;lt;p&amp;gt;Copyright ⓒ {year}&amp;lt;/p&amp;gt;
    &amp;lt;/footer&amp;gt;
  );
}

export default Footer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Quote.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

function Quote(props) {

  return (
    &amp;lt;div className="quote"&amp;gt;
      &amp;lt;div className="box"&amp;gt;
        &amp;lt;h1&amp;gt;{props.quote}&amp;lt;/h1&amp;gt;
        &amp;lt;p&amp;gt;{props.author}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default Quote;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now let's add some content and styles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quotes.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const Quotes = [
    {
        id: 1,
        quote: "“The purpose of our lives is to be happy.”",
        author: "— Dalai Lama"
    },
    {
        id: 2,
        quote: "“Life is what happens when you’re busy making other plans.” ",
        author: "— John Lennon"
    },
    {
        id: 3,
        quote: "“Get busy living or get busy dying.” ",
        author: "— Stephen King"
    },
    {
        id: 4,
        quote: "“Many of life’s failures are people who did not realize how close they were to success when they gave up.”",
        author: "– Thomas A. Edison"
    },
    {
        id: 5,
        quote: "“If life were predictable it would cease to be life, and be without flavor.” ",
        author: "– Eleanor Roosevelt"
    },
    {
        id: 6,
        quote: "“The whole secret of a successful life is to find out what is one’s destiny to do, and then do it.” ",
        author: "– Henry Ford"
    },
    {
        id: 7,
        quote: " “In order to write about life first you must live it.” ",
        author: "– Ernest Hemingway"
    },
    {
        id: 8,
        quote: "“The big lesson in life, baby, is never be scared of anyone or anything.”",
        author: "– Frank Sinatra"
    },
    {
        id: 9,
        quote: " “Life is a succession of lessons which must be lived to be understood.”",
        author: " — Helen Keller"
    },
    {
        id: 10,
        quote: "“Be yourself; everyone else is already taken.”",
        author: "― Oscar Wilde"
    },

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Styles.css&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  /* overflow-y: hidden; */
}
html {
  font-family: "Montserrat", sans-serif;
}
body {
  background: #BDE6F1;
  padding: 0 16px;
  background-image: url("https://www.transparenttextures.com/patterns/always-grey.png");;
}

header {
  background-color: #0AA1DD;
  margin: auto -16px;
  padding: 16px 32px;
  text-align: center;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.3);
}

header h1 {
  color: #fff;
  font-family: "McLaren", cursive;
  font-weight: 200;
}

footer {
  position: absolute;
  text-align: center;
  bottom: 0;
  width: 100%;
  height: 2.5rem;
}

footer p {
  color: #ccc;
}
.quote {
  background: #fff;
  border-radius: 7px;
  box-shadow: 0 2px 5px #ccc;
  padding: 30px 25px;
  width: 240px;
  height: 240px;
  margin: 20px;
  float: left;
}
.quote div{
  margin: auto;
}
.quote h1 {
  text-align: center;
  font-size: 1.1em;
  margin-bottom: 6px;
}
.quote p {
  text-align: center;
  font-size: 1em;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add alanBtn to App.js via useEffect.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  alanBtn({
    key: 'YOUR_KEY_FROM_ALAN_STUDIO_HERE',
    onCommand: (commandData) =&amp;gt; {
      if (commandData.command === 'go:back') {
        // Call the client code that will react to the received command
      }
    }
  });
}, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Generate key from Alan Studio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To integrate Alan AI voice assistant into your app, a key will be required. To generate this key head over to &lt;a href="https://studio.alan.app/register" rel="noopener noreferrer"&gt;Alan Studio&lt;/a&gt; and Sign up. You will be redirected to a page that will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgp2todk3bjgndk1mmqc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgp2todk3bjgndk1mmqc.png" alt="Alan AI project landing page" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Create voice assistant, and create an empty project by giving it a name, for this project name it QuoteBook:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3f2jsed6yt9lps5ri90k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3f2jsed6yt9lps5ri90k.png" alt="Alan AI Project types" width="800" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is an Integrations tab in the menu bar on top, click on it. You will find your Alan SDK Key, copy it and paste in your code above the comment.&lt;/p&gt;

&lt;p&gt;Till now you have integrated your project with Alan AI voice assistant. Now, let’s add some scripts to customize the voice assistant according to the app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;intent('What does this app do?', 'What can I do here?', 
      reply('This app is your quote book, it keeps a collection of your favourite quotes'));

const CATEGORIES = ['dalai lama','john lennon','stephen king','thomas edison','eleanor roosevelt','henry ford','ernest hemingway','frank sinatra','helen keller','oscar wilde'];
const CATEGORIES_INTENT = `${CATEGORIES.map((category) =&amp;gt; `${category}~${category}`).join('|')}`;
intent(`(go to|show|open) (the|) $(C~ ${CATEGORIES_INTENT})`,(p)=&amp;gt;{
        p.play({command:'goto',category:p.C.value.toLowerCase()})
})

intent(`(show|what is|tell me about|what's|what are|what're|read) (the|) $(C~ ${CATEGORIES_INTENT})`,(p)=&amp;gt;{
    if(p.C.value.toLowerCase()=='dalai lama'){
        p.play('The purpose of our lives is to be happy.')
    } else if(p.C.value.toLowerCase()=='john lennon'){
        p.play('Life is what happens when you're busy making other plans.')
    }else if(p.C.value.toLowerCase()=='stephen king'){
        p.play('Get busy living or get busy dying.')
    }else if(p.C.value.toLowerCase()=='thomas edison'){
        p.play('Many of life's failures are people who did not realize how close they were to success when they gave up.')
    }else if(p.C.value.toLowerCase()=='eleanor roosevelt'){
        p.play('If life were predictable it would cease to be life, and be without flavor.')
    }else if(p.C.value.toLowerCase()=='henry ford'){
        p.play('The whole secret of a successful life is to find out what is one's destiny to do, and then do it.')
    }else if(p.C.value.toLowerCase()=='ernest hemingway'){
        p.play('In order to write about life first you must live it.')
    }else if(p.C.value.toLowerCase()=='frank sinatra'){
        p.play('The big lesson in life, baby, is never be scared of anyone or anything.')
    }else if(p.C.value.toLowerCase()=='helen keller'){
        p.play('Life is a succession of lessons which must be lived to be understood.')
    }else if(p.C.value.toLowerCase()=='oscar wilde'){
        p.play('Be yourself; everyone else is already taken.')
    }
})

intent('(go|) back', (p) =&amp;gt; {
    p.play('Sure, nice talking to you!');
})

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

&lt;/div&gt;



&lt;p&gt;In this script, we are giving the assistant three custom features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Answer questions like what does this app do?&lt;/li&gt;
&lt;li&gt;Tell you the quote by the author’s name&lt;/li&gt;
&lt;li&gt;If you say bye, it says nice talking to you!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So this is how you can add a simple voice assistant to your React app.&lt;/p&gt;

&lt;p&gt;After this you can test the assistant and further customize it by adding more features to it according to your liking. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Voice assistants can be a great tool to integrate and play around with your apps. It was informative and useful building this QuoteBook React App. Feel free to refer to the entire source code &lt;a href="https://github.com/kanak22/Quote-Book" rel="noopener noreferrer"&gt;here&lt;/a&gt; and explore &lt;a href="https://alan.app/docs/" rel="noopener noreferrer"&gt;Alan docs&lt;/a&gt; to understand and further develop your application. &lt;br&gt;
Have a great day!🎇&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
