<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Shravani Roy]]></title><description><![CDATA[Product Developer with a demonstrated history of working in the information technology and services industry. shravaniroy.netlify.app]]></description><link>https://www.shravaniroy.in</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 19:56:04 GMT</lastBuildDate><atom:link href="https://www.shravaniroy.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Spring Beans Demystified — Scopes, Lifecycle, and Lazy Injection in a Credit Card Eligibility Microservice]]></title><description><![CDATA[💡 Introduction
Working on a credit card eligibility microservice recently taught me a lot about Spring’s bean system. I had to make design choices that ensured thread-safety, clean state management, and efficient memory use — especially when dealing...]]></description><link>https://www.shravaniroy.in/spring-beans-demystified-scopes-lifecycle-and-lazy-injection-in-a-credit-card-eligibility-microservice</link><guid isPermaLink="true">https://www.shravaniroy.in/spring-beans-demystified-scopes-lifecycle-and-lazy-injection-in-a-credit-card-eligibility-microservice</guid><category><![CDATA[Java]]></category><category><![CDATA[Springboot]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Microservices]]></category><category><![CDATA[Scope]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Wed, 18 Jun 2025 14:54:51 GMT</pubDate><content:encoded><![CDATA[<p>💡 Introduction</p>
<p>Working on a credit card eligibility microservice recently taught me a lot about Spring’s bean system. I had to make design choices that ensured thread-safety, clean state management, and efficient memory use — especially when dealing with stateful evaluations per user.</p>
<p>In this post, I’ll walk through:</p>
<ul>
<li><p>What Spring beans are</p>
</li>
<li><p>Their lifecycle</p>
</li>
<li><p>Different scopes</p>
</li>
<li><p>Lazy injection and why it’s a lifesaver</p>
</li>
<li><p>Real examples from a credit card eligibility context</p>
</li>
</ul>
<hr />
<h3 id="heading-what-is-a-spring-bean">☕ What is a Spring Bean?</h3>
<p>A <strong>bean</strong> in Spring is simply an object that is managed by the Spring container. When you annotate a class with <code>@Component</code>, <code>@Service</code>, or define it using <code>@Bean</code>, Spring takes care of:</p>
<ul>
<li><p>Instantiating it</p>
</li>
<li><p>Injecting its dependencies</p>
</li>
<li><p>Managing its lifecycle</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-java"><span class="hljs-meta">@Component</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CreditScoreService</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getScore</span><span class="hljs-params">(String userId)</span> </span>{
        <span class="hljs-comment">// Dummy logic</span>
        <span class="hljs-keyword">return</span> <span class="hljs-number">720</span>;
    }
}
</code></pre>
<p>Spring creates and manages a <code>CreditScoreService</code> bean.</p>
<hr />
<h3 id="heading-bean-lifecycle-simplified">🔄 Bean Lifecycle (Simplified)</h3>
<ol>
<li><p><strong>Instantiation</strong> – Spring creates the object.</p>
</li>
<li><p><strong>Dependency Injection</strong> – Injects all required fields/constructors.</p>
</li>
<li><p><strong>PostConstruct</strong> – Runs any method annotated with <code>@PostConstruct</code>.</p>
</li>
<li><p><strong>Bean is ready to use.</strong></p>
</li>
<li><p><strong>PreDestroy</strong> – If it's a singleton and being destroyed, <code>@PreDestroy</code> methods are called.</p>
</li>
</ol>
<pre><code class="lang-java"><span class="hljs-meta">@Component</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EligibilityLogger</span> </span>{

    <span class="hljs-meta">@PostConstruct</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span> </span>{
        System.out.println(<span class="hljs-string">"Logger initialized"</span>);
    }

    <span class="hljs-meta">@PreDestroy</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">destroy</span><span class="hljs-params">()</span> </span>{
        System.out.println(<span class="hljs-string">"Cleaning up logger"</span>);
    }
}
</code></pre>
<hr />
<h3 id="heading-bean-scopes-singleton-vs-prototype">📦 Bean Scopes — Singleton vs Prototype</h3>
<h4 id="heading-singleton-default">🔹 Singleton (default)</h4>
<ul>
<li><p>Only <strong>one instance</strong> is created per Spring context.</p>
</li>
<li><p>Shared across the entire application.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-java"><span class="hljs-meta">@Service</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EligibilityService</span> </span>{
    <span class="hljs-comment">// Singleton by default</span>
}
</code></pre>
<p>✅ Good for stateless services, utilities, or shared components.</p>
<hr />
<h4 id="heading-prototype">🔹 Prototype</h4>
<ul>
<li><p>A <strong>new instance</strong> is created <strong>every time the bean is requested</strong>.</p>
</li>
<li><p>Ideal when the bean holds <strong>request-specific data or state</strong>.</p>
</li>
</ul>
<hr />
<h3 id="heading-example-from-credit-card-eligibility">🧪 Example from Credit Card Eligibility</h3>
<p>Let’s say we have a service that evaluates whether a user is eligible for a credit card based on credit score and income.</p>
<h4 id="heading-step-1-define-a-stateful-bean">✅ Step 1: Define a stateful bean</h4>
<pre><code class="lang-java"><span class="hljs-meta">@Component</span>
<span class="hljs-meta">@Scope("prototype")</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EligibilityEvaluationContext</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> eligible;
    <span class="hljs-keyword">private</span> String rejectionReason;
    <span class="hljs-keyword">private</span> Map&lt;String, Object&gt; debugInfo = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();

    <span class="hljs-comment">// Getters &amp; Setters</span>
}
</code></pre>
<blockquote>
<p>Why prototype? Because this context is <strong>specific to each request</strong> and shouldn't be shared.</p>
</blockquote>
<hr />
<h4 id="heading-step-2-inject-it-using-objectfactory-lazy-injection">✅ Step 2: Inject it using <code>ObjectFactory</code> (Lazy Injection)</h4>
<pre><code class="lang-java"><span class="hljs-meta">@Service</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EligibilityService</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> CreditScoreService scoreService;

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> ObjectFactory&lt;EligibilityEvaluationContext&gt; contextFactory;

    <span class="hljs-function"><span class="hljs-keyword">public</span> EligibilityEvaluationContext <span class="hljs-title">evaluate</span><span class="hljs-params">(String userId)</span> </span>{
        <span class="hljs-keyword">int</span> score = scoreService.getScore(userId);
        EligibilityEvaluationContext context = contextFactory.getObject();

        <span class="hljs-keyword">if</span> (score &lt; <span class="hljs-number">650</span>) {
            context.setEligible(<span class="hljs-keyword">false</span>);
            context.setRejectionReason(<span class="hljs-string">"Low credit score"</span>);
            context.getDebugInfo().put(<span class="hljs-string">"score"</span>, score);
        } <span class="hljs-keyword">else</span> {
            context.setEligible(<span class="hljs-keyword">true</span>);
        }

        <span class="hljs-keyword">return</span> context;
    }
}
</code></pre>
<p>👉 <code>ObjectFactory.getObject()</code> ensures we get a <strong>fresh</strong> <code>EligibilityEvaluationContext</code> every time — this avoids bugs due to shared state and keeps our service thread-safe.</p>
<hr />
<h3 id="heading-why-not-inject-prototype-directly">⚠️ Why Not Inject Prototype Directly?</h3>
<pre><code class="lang-java"><span class="hljs-meta">@Autowired</span>
<span class="hljs-keyword">private</span> EligibilityEvaluationContext context;
</code></pre>
<p>This would only create one instance — during startup — and reuse it everywhere. Totally defeats the point of <code>@Scope("prototype")</code>.</p>
<hr />
<h3 id="heading-bonus-lazy-initialization-with-lazy">🧊 Bonus: Lazy Initialization with <code>@Lazy</code></h3>
<p>If a bean is <strong>expensive to create</strong> and might <strong>not be used right away</strong>, you can delay its creation:</p>
<pre><code class="lang-java"><span class="hljs-meta">@Autowired</span>
<span class="hljs-meta">@Lazy</span>
<span class="hljs-keyword">private</span> ExternalScoringClient scoringClient;
</code></pre>
<p>Now, <code>scoringClient</code> will only be created <strong>when it's first accessed</strong> — not during app startup.</p>
<hr />
<h3 id="heading-key-takeaways">🧠 Key Takeaways</h3>
<ul>
<li><p><strong>Use Singleton</strong> for stateless services and utilities.</p>
</li>
<li><p><strong>Use Prototype</strong> for stateful, request-specific objects.</p>
</li>
<li><p>Use <code>ObjectFactory</code> or <code>Provider</code> to inject prototype beans into singleton services safely.</p>
</li>
<li><p>Use <code>@Lazy</code> to defer expensive bean creation until needed.</p>
</li>
</ul>
<hr />
<h3 id="heading-conclusion">📌 Conclusion</h3>
<p>Understanding how Spring manages beans is crucial for designing clean, safe microservices — especially in user-facing financial applications like credit card approvals.</p>
<p>If you're ever storing per-user evaluation data or debugging context, don’t rely on singletons. Prototype + lazy injection is your friend.</p>
]]></content:encoded></item><item><title><![CDATA[How I Solved an Image Compression Issue in the Open-Tacos Project and Got My PR Merged]]></title><description><![CDATA[Contributing to open-source projects is one of the best ways to learn, grow, and connect with the developer community. Recently, I had the opportunity to work on an interesting issue in the Open-Tacos project — implementing client-side image compress...]]></description><link>https://www.shravaniroy.in/how-i-solved-an-image-compression-issue-in-the-open-tacos-project-and-got-my-pr-merged</link><guid isPermaLink="true">https://www.shravaniroy.in/how-i-solved-an-image-compression-issue-in-the-open-tacos-project-and-got-my-pr-merged</guid><category><![CDATA[React]]></category><category><![CDATA[Next.js]]></category><category><![CDATA[Open Source]]></category><category><![CDATA[Image Compression]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 28 Mar 2025 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>Contributing to open-source projects is one of the best ways to learn, grow, and connect with the developer community. Recently, I had the opportunity to work on an interesting issue in the <a target="_blank" href="https://github.com/OpenBeta/open-tacos">Open-Tacos</a> project — implementing client-side image compression. In this post, I’ll walk you through how I tackled the problem, handled feedback, and finally got my pull request merged. 🙌</p>
<hr />
<h2 id="heading-the-problem">The Problem</h2>
<p>The issue seemed simple on the surface: <strong>compress uploaded images on the client before sending them to the server</strong>. This would help optimize upload speeds and reduce bandwidth usage, especially useful for high-res climbing photos.</p>
<hr />
<h2 id="heading-the-approach">The Approach</h2>
<p>After some research and community discussion, I chose to use <a target="_blank" href="https://github.com/fengyuanchen/compressorjs"><code>compressorjs</code></a> — a lightweight library that does exactly what I needed with minimal fuss.</p>
<p>I created a utility function that:</p>
<ul>
<li><p>Took a file input from the user</p>
</li>
<li><p>Compressed it based on the desired size/quality</p>
</li>
<li><p>Returned the new compressed file to be used in the upload workflow</p>
</li>
</ul>
<p>The initial code looked like this:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> Compressor <span class="hljs-keyword">from</span> <span class="hljs-string">'compressorjs'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> compressImage = (file: File): <span class="hljs-built_in">Promise</span>&lt;File&gt; =&gt; {
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =&gt;</span> {
    <span class="hljs-keyword">new</span> Compressor(file, {
      quality: <span class="hljs-number">0.6</span>,
      maxWidth: <span class="hljs-number">2000</span>,
      success(result) {
        resolve(result <span class="hljs-keyword">as</span> File);
      },
      error(err) {
        reject(err);
      }
    });
  });
};
</code></pre>
<p>Then I integrated this logic into the photo upload flow so that every image would be compressed automatically before upload.</p>
<hr />
<h2 id="heading-reviewer-feedback-and-revisions">Reviewer Feedback and Revisions</h2>
<p>When I raised the PR, the maintainers appreciated the effort, but also had <strong>constructive feedback</strong>. Here are a few things they asked me to revise:</p>
<h3 id="heading-1-error-handling-edge-cases">1. <strong>Error Handling Edge Cases</strong></h3>
<p>The reviewer reminded that compression must cover an important edge case — like images larger than 30 MB must not be compressed, instead throw an error.</p>
<p>✅ I added specific file size validation logic before initiating compression.</p>
<h3 id="heading-2-improving-file-type-checks">2. <strong>Improving File Type Checks</strong></h3>
<p>I was initially compressing any file that came through. The reviewer asked me to <strong>limit compression to image file types only</strong>.</p>
<p>✅ I updated the logic to skip non-image files using simple MIME type checks.</p>
<h3 id="heading-3-linting-amp-formatting">3. <strong>Linting &amp; Formatting</strong></h3>
<p>My pre-commit hook failed due to some ESLint rules. I also had to align with the project’s usage of <code>ts-standard</code>.</p>
<p>✅ I fixed all lint issues and even contributed to the <code>.lintstagedrc</code> setup discussion.</p>
<hr />
<h2 id="heading-the-final-pr">The Final PR</h2>
<p>After addressing the feedback and thoroughly testing the changes, a reviewer suggested optimised code, which not only reduced the number of lines in the code but also made so much sense regarding how clean the code must look. I pushed the updates and waited. A few hours later... 🎉</p>
<blockquote>
<p><strong>My</strong> <a target="_blank" href="https://github.com/OpenBeta/open-tacos/pull/1290"><strong>pull request</strong></a> <strong>was merged!</strong></p>
</blockquote>
<p>This small win meant a lot. Not only did I contribute meaningful code, but I also learned:</p>
<ul>
<li><p>How to accept and implement technical feedback</p>
</li>
<li><p>How to use image compression libraries</p>
</li>
<li><p>How to work with linting tools and pre-commit hooks</p>
</li>
<li><p>How to write cleaner and optimised code</p>
</li>
</ul>
<hr />
<h2 id="heading-key-takeaways">Key Takeaways</h2>
<ul>
<li><p>I learned how to write clean, optimised, and better code that avoids side effects.</p>
</li>
<li><p>Open source is a collaborative process — reviewers are there to help us improve.</p>
</li>
<li><p>Contributing to real-world projects teaches you what tutorials can't.</p>
</li>
</ul>
<hr />
<p>If you're thinking about contributing to open source — <strong>do it</strong>. You’ll learn more than you expect, and your confidence as a developer will grow with every line of code you contribute.</p>
<p>Happy coding! 💻✨</p>
]]></content:encoded></item><item><title><![CDATA[Behavioural round in an interview.]]></title><description><![CDATA[“It is frustrating to code sometimes. You spend the whole day or two to solve a problem and then finally solve it knowing a small semicolon was missed. How do you handle such situations?”
This happened in an interview recently, where a project head f...]]></description><link>https://www.shravaniroy.in/behavioural-round-in-an-interview</link><guid isPermaLink="true">https://www.shravaniroy.in/behavioural-round-in-an-interview</guid><category><![CDATA[interview]]></category><category><![CDATA[behaviorial interview questions]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Thu, 09 Jan 2025 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p><em>“It is frustrating to code sometimes. You spend the whole day or two to solve a problem and then finally solve it knowing a small semicolon was missed. How do you handle such situations?”</em></p>
<p>This happened in an interview recently, where a project head from Optum took the behavioural round to evaluate my skills. While I answered most of the questions honestly, I also found myself repeating that I am an optimistic person who believes any bug can be fixed. Errors are not as bad as they seem to be, but only give us another opportunity to learn a new thing that day. I was expecting to have some technical questions and was least prepared for this kind of question. It was obvious that anyone would share positive experiences in such an interview, and my mind only kept on track to give honest answers from my experience.</p>
<p>In this post, I will share a few questions that came my way. For every question, I will share how I answered it and how it could be answered differently.</p>
<ol>
<li><p>How does your day look like, starting from getting your story assigned? I answered that we discuss in the team who picks what and work accordingly. We then have a daily Scrum call for all projects of the POD and a separate call for the project team to discuss progress and blockers. He further asked if we had grooming sessions for the stories.</p>
</li>
<li><p>Any challenge that you faced and are proud of solving it?</p>
</li>
<li><p>Any examples of having a hard time with lead?</p>
</li>
<li><p>Any examples of bad code that you found from juniors?</p>
</li>
<li><p>Any examples of suggestions that you made implemented? I answered that we have strict guidelines in the current organization. Instead, I should have mentioned that the CI/CD implementation that I suggested in the previous organization was accepted and approved.</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Reflecting on 2024]]></title><description><![CDATA[It’s that time of the year. I didn’t write much in 2024. I wanted to write only when I had done something worth writing about.
Jan and Feb went by office work e-champs project POC, all by myself. For error handling, I proposed to use the postMessage ...]]></description><link>https://www.shravaniroy.in/reflecting-on-2024</link><guid isPermaLink="true">https://www.shravaniroy.in/reflecting-on-2024</guid><category><![CDATA[reflection]]></category><category><![CDATA[Career]]></category><category><![CDATA[Java]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 03 Jan 2025 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>It’s that time of the year. I didn’t write much in 2024. I wanted to write only when I had done something worth writing about.</p>
<p>Jan and Feb went by office work e-champs project POC, all by myself. For error handling, I proposed to use the postMessage API of the browser. This required support from a legacy application that we were integrating into the current application using iframe. Unfortunately, my lead was unaware of this work and dismissed it due to various limitations. Eventually leading to the dismissal of the project I guess. Working and managing my home were taking 100% of my time. Any leisure time went into practising dance form for my first-ever performance in a temple. I wanted to dedicate my devotion in the form of dance for my beloved lord Shiva. Honestly, it wasn’t a good experience and I got clarity on many things about myself.</p>
<p>I focused on work and tried to reflect and revise my plans for the year. I realised Terraform or Cloud is not my thing yet. Instead, I started feeling comfortable with Java. I need to keep working using Java to push into my secondary memory. I watched related videos sometimes and mostly focused on work.</p>
<p>We had planned for a month-long stay in Goa this year. I had this fantasy of slow living in Goa, which most people could only dream of. I read a few articles on how people moved to Goa for a year or worked from there for so many reasons like, the affordability it offers, its cuisine, and most importantly living with nature alongside city life. The idea was to make the most of Rihu’s holidays and be close to nature. And a road trip it was. I could write an entire article just describing the road trip experience. We started at the end of April and returned by the last week of May. The Airbnb we booked surprised us with its view and the community space was amazingly peaceful. The Cola beach was just 400mtrs from the place. And besides all this, the Airbnb was inside a gated community with security and a wonderful swimming pool. What more could I have asked? A perfect summer vacation for my child and a lovely experience for us.</p>
<p>I had a perfect plan of how I was going to make it a perfect budget-friendly trip. 1BHK in Airbnb and cooking all the weekdays. We executed as planned. We could manage Rihu with some free games in the daytime, swimming twice a day, and some screen time during our work calls. What a wonderful trip it was. Ah, we made many memories. Met new people, and hung out with some. Explored plenty of restaurants. Amazing trip. However, it wasn’t all roses. We were comfortable and it was going all good for the first two weeks. As I managed to cook as much as possible none of us got sick too. The following weeks got a little dry as we were just three and were missing friends. I tried my best to adapt to slow living. We made sure to visit beaches over weekends. Didn’t miss sunsets. It was for sure a beautiful experience. But if you ask me if I will do it again, I would say not any sooner, maybe after a few years in a different place.</p>
<p>At the beginning of the year, I set a goal to acquire a new skill in either arts or psychology. Rihu had a few more weeks before he returned to school. I did some research and found an online art class that we could join together. It is a great way to develop a strong bond with your child, by learning a hobby together. We had two classes every week. We learned sketching and painting. The best takeaway was perspective. Although Rihu just enjoyed painting classes, he wasn’t much interested in theory or sketching. So we stopped as soon as school reopened to make it less hectic.</p>
<p>I came across a parenting workshop and soon enrolled on it. August and September went to attend these classes. This was much needed for my parenting journey. I became a better person to become a better parent. I must say, it changed me for good and I see my child much happier than ever before. I couldn’t have asked anything more. I started cherishing my child and the time we spent together. The institute certified me as a parent coach. Initially, I was sure that I would be using this knowledge for my benefit. However, I see there is a lot of unawareness in the world. There is this one part of the world struggling to get pregnant and have a child, and there is another part of the world that has kids but is not sure what to do with them and ends up frustrated and unknowingly unintentionally doing a lot of harm for their child and their bond with their child. As I have a full-time job and a family to take care of, I decided not to go with one-to-one coaching. After giving it a lot of thought, I started a new blog and a social media channel to post my thoughts and knowledge. I believe that practising as a coach would keep me updated.</p>
<p>Back in May, I applied for a CFP at pyConf India. The topic I chose was non-technical. I proposed a topic in lifestyle - Integrating a hobby for better work-life balance. In August I got a confirmation that my talk got shortlisted and I would need to do a couple of rehearsals and can buy a speaker ticket. Unfortunately, due to some personal reasons, I have decided to withdraw my proposal. Soon in October I gave a couple of webinars and did a workshop for teachers at a school, only to realise coding and solving technical problems is much easier than solving real personal issues for people. My strengths were in technology and not people. I have around 60 plus posts in that IG account. And I have been posting whenever possible.</p>
<p>In November, I revised my goals again and got back to revising Java Spring, DSA, and Open Source. I got an issue from open-tacos, however, it was already assigned to someone else. I couldn’t stop myself and tried to reproduce the issue on my machine. I also solved the issue and raised a PR, that got merged by the end of the month. It was simple but is my first ever PR that got approved. I have written a detailed article on this, you can check <a target="_blank" href="https://www.shravaniroy.in/contributing-to-open-tacos">here</a>.</p>
<p>This felt like encouragement and I picked up another issue, which I am hoping to close soon. I was busy with family in Dec and the first two weeks of Jan. Hoping to resume work as soon as possible.</p>
<p>Thanks for reading so far. Happy Learning!</p>
]]></content:encoded></item><item><title><![CDATA[Contributing to open-tacos]]></title><description><![CDATA[The back story from 2023 :
I came across this project OpenBeta. I liked the project and the fact that they are building on top of open-street maps, which we tried to use in our projects back in the logistics company I worked with. It is an open-sourc...]]></description><link>https://www.shravaniroy.in/contributing-to-open-tacos</link><guid isPermaLink="true">https://www.shravaniroy.in/contributing-to-open-tacos</guid><category><![CDATA[Open Source]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Next.js]]></category><category><![CDATA[coding]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 06 Dec 2024 07:05:49 GMT</pubDate><content:encoded><![CDATA[<p>The back story from 2023 :</p>
<p>I came across this project OpenBeta. I liked the project and the fact that they are building on top of open-street maps, which we tried to use in our projects back in the logistics company I worked with. It is an open-source project and I got lost in the code for quite some time. Later I looked for issues and felt overwhelmed. As a first-time contributor, I wanted to take a safe bet and pick a ‘good first issue’ usually meant for first-timers.</p>
<p>I managed to get a small setting issue assigned to me, where I had to update an API key.</p>
<p>In order to set up the project, I forked the repo (only develop branch) and then cloned it on the local machine as I wanted to start with the front end of the project.</p>
<p>Installed yarn and tried to install dependencies. That's when it kept saying that the node version was incompatible.</p>
<p>I tried to solve it for some time and then thought, maybe I must go with docker to avoid such incompatibilities.</p>
<p>Installed Docker.</p>
<p>Opened the project in VS Code. Launched a terminal in the IDE and then ran below code to start the container</p>
<p><code>docker compose up</code></p>
<p>This got stuck at step 5 for quite some time. Although I could see the container on the docker desktop, it still didn't work. So I terminated it and used the below command.</p>
<p><code>docker compose up --build</code></p>
<p>This time it successfully ran and showed a message that the application is running at localhost:3000</p>
<p>I raised a PR. I was hoping to get it approved until the next morning when I found that it had a migration of data involved and needed backend work. This blocked my PR and the author closed my PR.</p>
<p>PRESENT</p>
<p>I have not been that busy during the last two months of the year since the pandemic. I got back to check if I could contribute to the open-source. I found a new issue and this time, I didn’t think before working on it. I resolved the issue on my local machine and then commented on the issue about raising the PR.</p>
<p>I explored the project code a little deeper this time and I found it really interesting. Although I don’t climb, I like how they work to help the community. It made me feel happy that I could do something outside my regular work, (which actually doesn’t make a great impact, I will talk about it in detail some other time).</p>
<p>I raised a <a target="_blank" href="https://github.com/OpenBeta/open-tacos/pull/1232">PR</a> and it got approved within hours. It is a simple change, where the base URL had an extra ‘/’ in the path. This was causing the URL to have double slash in the copied URL link.</p>
<p>It is a minor contribution, but it gave me confidence and motivation to do more for the community. I have got another issue assigned to me yesterday. Looking forward to share about that too very soon.</p>
<p>Thank you for reading so far. Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Reflecting on 2023 - Quite a rollercoaster.]]></title><description><![CDATA[I wish every one of you a happy new year. It is time to reflect on the year that has ended with a lot of memories. I started with good plans for my career and personal growth. I took up a course in Java Backend just before the year began. And signed ...]]></description><link>https://www.shravaniroy.in/reflecting-on-2023-quite-a-rollercoaster</link><guid isPermaLink="true">https://www.shravaniroy.in/reflecting-on-2023-quite-a-rollercoaster</guid><category><![CDATA[reflection]]></category><category><![CDATA[Developer]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Java]]></category><category><![CDATA[Career]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Sat, 06 Jan 2024 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>I wish every one of you a happy new year. It is time to reflect on the year that has ended with a lot of memories. I started with good plans for my career and personal growth. I took up a course in Java Backend just before the year began. And signed up for another course in classical dance form - Kuchipudi, for various reasons I will be sharing in this post.</p>
<p>I have been performing classical dance once a year at my dad's office for their annual day function. We had this routine every summer, where we would rehearse with other kids of officers/employees from the same office as Dad's. This happened until I graduated my Intermediate(Plus 2), approximately 11 years. And then boom, I never looked back at my interest in pursuing dance as a skill. As part of taking care of myself being one of my goals for 2023, I decided to take up a course. I pitched it as a physical fitness goal to my partner and got full support to proceed. Although I knew most people around me wouldn't approve of it, I took it as a challenge. Unfortunately, people think that being in their 30s is not the right time to take up such a hobby. When I shared my interest with one of my friends, she claimed that I could not do it with my schedule and my health(she referred to my knee pains), and asked me to drop my thought. Huh! Not surprised, I dropped hanging out with her instead. It was exactly one year that I took the course, and I chose not to give up no matter what. Although I had ups and downs during this journey, I am quite a favorite student for my teacher.</p>
<p>I am forever grateful for my teacher. I was a bit lazy in the beginning but felt like a blessing to be able to wake up and do something I like, both personally and professionally. Just about 10 days into the year, my little one - Rihu had a viral attack, and around 10 days went in coping from fever, cold, and stuff. During this time I thought of going to a temple in the city. So as he recovered we visited Naga Devatha temple and offered "thulabaram" - it is a Hindu practice to weigh the kid opposite Rice and some staples, or Jaggery, at the temple by the end of the month.</p>
<p>Feb went quite fast as we planned a trip. Did a lot of shopping for Rihu for the staycation. Meanwhile, I had a bad time catching up with the Java cohort I took up in Dec. I wasn't finding the instructor relevant. I realized that the course was more for people who already practiced the backend in Java. I put it aside for some time and prepared myself to dive into some nature in March.</p>
<p>The 15-day trip to Goa was memorable. Took off for a few days and worked for a few more from the beautiful villa, that I cannot get over. 10 Adults and 10 kids together for half a month in a house, which was quite memorable. Time wasn't that blissful all the time, but being an introvert, I never thought I could get along with so many people. I found myself capable of learning on the go. My partner has helped in my low times. So I managed. The only thing I missed on the trip was to work from a shack. Will try next time for sure.</p>
<p>It was always clear that I can not do multi-tasking. So, I decided that I would focus on spending as much time as possible with my little one in his holidays. This was the time when I realised that life is too short to give up on anything but taking a break for a fresh start isn't a bad idea. One of the reasons to go easy with the break was that I did not like Java at all after attending the classes from the GFG instructor. It felt hard to believe that I could ever crack it. So, took it slow for two months. I think it is okay after all it is a break and not the end of the world, as it seemed from my Twitter feed :)</p>
<p>Do you have a favorite month as such? Like, usually it is your birthday month or of your loved ones. I am sure for most moms, it is June. As the schools here in India resume in this amazing time of the year, which allows us to finally get some air. We opted to go with the school bus this year, after going through a series of episodes where we returned home with the kid from school even before he stepped in. Like literally, I wake up to prep his lunch, and breakfast and get him ready, only to find out that he doesn't want to go. The poor kid had a tough time going to school, and so did we. But in contrast, this year was so good to see him make friends, and comfortable to start his day. Grateful for the new school, which makes it interesting for the kids to look forward to the next day. Every kid deserves such a school.</p>
<p>I struck off my side-project list to come up with a problem-solving approach instead, after speaking to my mentor. He had a point. Started my DSA journey instead, with the Colt Steele course, and was able to progress smoothly.</p>
<p>The next couple of months went into tackling my work at the office and Rihu's assignments. His first research paper on germs and kinds of germs was exciting for me. Found entry requests for a tech talk on functional programming for 'jsfoo - hasgeek.com'. Thought I could try it once and submitted a talk. Didn't get through. However, got my first tattoo. In the middle of all this chaos, I found out that I was pregnant. It was extremely hard until 2nd week of August. I never imagined to undergo an abortion. I cannot explain in words how painful the process was. I had no clue about it and felt terrible experiencing it. Every day passed by painfully, so I decided that I would take as much rest as possible and avoid learning as well to be sane and recover peacefully. This alone could be a post in itself. There was so much that I couldn't do, but I had to take this unexpected second break in the year.</p>
<p>As I started to recover and feel better, I made some achievable todo list for myself. Tried to tweet more often. And in the process of getting addicted to this social media platform, something interesting popped up in my feed. I have registered for pyconf Hyderabad, for the 30th and 1st Oct. I was so excited. Meanwhile, booked a session with Aman(an SDE2 from Microsoft) to get some feedback and learning path for my DSA course and progress. It turned out well and got some good feedback. I understood where I was lacking and picked up pace.</p>
<p>And then the day came. I was happy to be at Pycon India. Great meeting community volunteers from across the world. Tried to get Pyladies hyd handles, but found out that the owners did not want to give up, as I seemed new and thought I could not handle it. Could not convince Vandana enough. Meanwhile, attended another coffee morning at Rihu's school, where the central idea was 'conservation of water, water pollution, and preventive measures'. Applied to many remote jobs and got rejection emails. Progressed well on node js, express js, typescript, mono repo for frontend, and Postgres SQL. Posted an article on the pyconf experience. And did not get any update from pyladies, on the talk I submitted. I have had 10 more days this month, where I wanted to focus on office work and also learn production-level coding for the backend.</p>
<p>I couldn't make it to the speaker list of pyLadies. Applied for the React conference in Mumbai. Tried to solve a bug for open-tacos an open-source project, but couldn't get my PR merge as it had other dependencies. Started backend project for reward-your-child. Going good with middleware, error handling, and security using session tokens. Started spring course alongside DSA. Colt's course made it sound easy and now I have confidence that I can pull it off. Later got to know that didn't get through the ReactMumbai speaker list either. I have got my increment at work. Pretty happy with the hike and now I feel financially sorted and hope to get a good project to work on. November ended good with this news. Took up peer learning with Phani on the Spring framework.</p>
<p>Sometimes it is good to be spontaneous to have fun. So, we took a short trip to a resort with friends so that Rihansh(LO) could have fun. It paid off as a good weekend for the little one. No regrets! The next 3 days went into spending the monthly subscription to rest alongside planning the big day for the little one. Also completed Spring Core from the Udemy course that I took up last month. Peer learning kind of worked well in coping with the course.</p>
<p>There are some things that I thought would be nice to pick up but after brainstorming with my partner regarding my priorities and how I should be spending my time and energy to be sane, I decided to let go few deals. Masters in USA being one of the projects I wanted to pick up, I had got this offer from my previous employer to be part of his next startup. My previous employer is one of the founders of a logistics business. The products that they need to build for their business, were fascinating to me as they need some good machine learning and data engineering work. I thought I would be working on the products on the side, while my focus would still be on my work and upskilling I believe that my god Vinayaka(Ganesh ji) always shows me the right path in my career and learning. Henceforth I believe in my husband who helps me sort things in life.</p>
<p>During this time we had to travel 1000km up and down for my partner's uncle's funeral. That is when I decided to slow down and not continue with joining the startup idea. Phani has been very patient with me and so helped me catch up with the Spring course. I finally finished SpringBoot fundamentals and Hibernate (JPA).</p>
<p>This is the section where I set some goals for the next year 2024. I am happy and extremely grateful for the year 2023 has been. With that, I carry some of the ongoing courses that I started in the year 2023. So, I will continue with the Spring course, and anticipate getting some work on it by the middle of the year. As my employer insists on taking some real certification from a board on a skill that I like, I will explore a couple of new technologies(thinking of Terraform and AWS) and learn the one that seems feasible to fit into my work and schedule. Learning Java(backend) and getting work on it being the priority for the next year, I would try to do some side projects on it. In regards to personal growth, I would continue to learn Kuchipudi, and hopefully give my first performance with this academy. Also, planning to pick up a new skill to learn. I will be choosing from Art and Child Psychology. Whatever fits best with me and my little one. After all, the world revolves around our loved ones.</p>
<p>Looking forward!</p>
<p>Thanks for reading so far! Wish you the best!</p>
]]></content:encoded></item><item><title><![CDATA[What is learning for me?]]></title><description><![CDATA[Background: It started as an ordinary workday, filled with conversations among colleagues. One of my frustrated colleagues reached out to me and posed an intriguing question: "Would you be content working solely on HTML+CSS for the rest of your caree...]]></description><link>https://www.shravaniroy.in/what-is-learning-for-me</link><guid isPermaLink="true">https://www.shravaniroy.in/what-is-learning-for-me</guid><category><![CDATA[learning]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[engineering]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 01 Dec 2023 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>Background: It started as an ordinary workday, filled with conversations among colleagues. One of my frustrated colleagues reached out to me and posed an intriguing question: "Would you be content working solely on HTML+CSS for the rest of your career if it came with generous compensation and frequent performance evaluations?" I offered a reassuring "yes" to alleviate their concerns, yet deep down, I felt a sense of dissatisfaction with our current project. It seemed devoid of exciting challenges, leaving no room for personal growth. The next day, my mentor asked me to articulate what learning truly meant to me.</p>
<p>I am a person who continuously craves new challenges through which I can learn and grow. I get a dopamine hit when I solve problems. I find immense joy in even the smallest victories, such as fixing the tiniest bug or making a static web application come to life. Integrating APIs and manipulating data to achieve specific outcomes, exploring and applying new tools and libraries to tackle fresh challenges – all these experiences bring me great satisfaction. My love for programming languages and the tools that allow me to create magic is indescribable.</p>
<p>Let's explore different methods of learning:</p>
<ol>
<li><p><strong>Mentorship</strong>: Finding a mentor who can guide you in your career journey is invaluable. Platforms like Twitter can provide spaces to connect with potential mentors.</p>
</li>
<li><p><strong>Full-time courses:</strong> Pursuing a master's degree allows for ample time to experiment and conduct research in your chosen field. However, this may not align with my personal life at the moment.</p>
</li>
<li><p><strong>Project-based learning:</strong> Engaging in projects that solve interesting problems using technology exposes you to new challenges regularly. Sometimes, it can be challenging for me to identify unique problems in the tech world. However, I'm eager to tackle more stimulating challenges than mere alignment issues on a website.</p>
</li>
<li><p><strong>Brainstorming sessions:</strong> Regularly conversing with fellow engineers in the community is a great way to share knowledge and insights. An application like <a target="_blank" href="http://coffeemug.ai">coffeemug.ai</a> facilitates such collaborative experiences.</p>
</li>
<li><p><strong>Workshops</strong>: Participating in hackathons or similar workshops allows for rapid learning by exploring different tech stacks to solve problems. However, such events may not currently align with my personal life.</p>
</li>
<li><p><strong>Open-source contributions:</strong> Getting involved in an interesting open-source project and contributing to its development is an excellent way to learn and apply skills effectively.</p>
</li>
</ol>
<p>I am an aspiring engineer eager to learn and grow. I am looking for opportunities that can impact large-scale users.</p>
<p>(Edit- Dec 2024) In this journey, I have also found a couple of applications codingame.com that throw coding challenges in a gamified way which has been helpful.</p>
<p>Thanks for reading so far.</p>
<p>Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[useLayoutEffect - when to use it?]]></title><description><![CDATA[I recently attended an interview for React JS and the one question that I answered without actually ever implementing it was about the useLayoutEffect hook. I have heard about it from my colleague who had mentioned using it for some animation. I just...]]></description><link>https://www.shravaniroy.in/uselayouteffect-when-to-use-it</link><guid isPermaLink="true">https://www.shravaniroy.in/uselayouteffect-when-to-use-it</guid><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[hooks]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Sun, 12 Nov 2023 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>I recently attended an interview for React JS and the one question that I answered without actually ever implementing it was about the useLayoutEffect hook. I have heard about it from my colleague who had mentioned using it for some animation. I just looked for its definition then and it never occurred to me to implement it or to play around it until the day of the interview, where I could only answer what I read and couldn't really code to put out an example of it. So, after spending a good two hours on it, I am sharing the code snippets and explaining them here for an insight into the useLayoutEffect hook and how it is different from the useEffect hook, with examples.</p>
<p><code>useLayoutEffect</code> is a React Hook that is similar to the <code>useEffect</code> Hook, but it runs synchronously immediately after all DOM mutations before the browser has a chance to paint those changes on the screen. This is useful for performing actions that depend on the layout or dimensions of the DOM elements, such as animating transitions or calculating measurements.</p>
<p>The signature <code>useLayoutEffect</code> is the same as <code>useEffect</code>: it takes two arguments, a function and an optional array of dependencies. The function argument will be executed after the initial render and after every update to the component, while the dependency array determines whether or not the effect should be re-run based on changes to its dependencies.</p>
<p>Here is an example of using <code>useLayoutEffect</code> to perform a simple animation:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState, useLayoutEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [show, setShow] = useState(<span class="hljs-literal">false</span>);

  useLayoutEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> el = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'box'</span>);
    el.style.opacity = <span class="hljs-string">'1'</span>;
    el.style.transform = <span class="hljs-string">'translateX(0)'</span>;
  }, [show]);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setShow(!show)}&gt;Toggle Box<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      {show &amp;&amp; <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"box"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">opacity:</span> <span class="hljs-attr">0</span>, <span class="hljs-attr">transform:</span> '<span class="hljs-attr">translateX</span>(<span class="hljs-attr">-50px</span>)' }}&gt;</span>This is a box.<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>In this example, we are using <code>useLayoutEffect</code> to update the styles of the <code>#box</code> element when the <code>show</code> state changes. The <code>useLayoutEffect</code> hook runs synchronously after every update, so the DOM changes will be immediately reflected in the browser, allowing for smooth animations without flickering or delays.</p>
<p>It is important to note that because <code>useLayoutEffect</code> runs synchronously, it can potentially cause performance issues or jank if the effect takes too long to execute. In these cases, it may be better to use the <code>useEffect</code> Hook instead, which runs asynchronously after the browser has painted the changes on the screen. However, for certain use cases such as animations or layout-dependent effects, <code>useLayoutEffect</code> can be a useful tool for achieving a smooth and responsive user experience.</p>
<ol>
<li>Updating CSS Styles</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState, useEffect, useLayoutEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [color, setColor] = useState(<span class="hljs-string">'red'</span>);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> el = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'box'</span>);
    el.style.backgroundColor = color;
  }, [color]);

  useLayoutEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> el = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'box'</span>);
    el.style.borderColor = color;
  }, [color]);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"box"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">width:</span> '<span class="hljs-attr">100px</span>', <span class="hljs-attr">height:</span> '<span class="hljs-attr">100px</span>', <span class="hljs-attr">border:</span> '<span class="hljs-attr">5px</span> <span class="hljs-attr">solid</span> <span class="hljs-attr">black</span>' }}&gt;</span>
      This is a box.
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>In this example, we are using <code>useEffect</code> to update the background colour of the <code>#box</code> element whenever the <code>colour</code> state changes, and we are using <code>useLayoutEffect</code> to update the border colour of the same element. Because <code>useLayoutEffect</code> runs synchronously before the browser has a chance to paint the changes, the border colour will be updated before the background colour, resulting in a brief flicker where the border colour is visible before the background colour is updated.</p>
<ol>
<li>Measuring Element Dimensions</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState, useEffect, useLayoutEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [width, setWidth] = useState(<span class="hljs-literal">null</span>);

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> el = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'box'</span>);
    setWidth(el.clientWidth);
  }, []);

  useLayoutEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> el = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'box'</span>);
    setWidth(el.clientWidth);
  }, []);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"box"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">width:</span> '<span class="hljs-attr">50</span>%' }}&gt;</span>
      This is a box. Its width is {width}px.
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>In this example, we are using both <code>useEffect</code> and <code>useLayoutEffect</code> to measure the width of the <code>#box</code> element and update the <code>width</code> state accordingly. Because <code>useEffect</code> runs asynchronously after the browser has painted the changes, it may not always reflect the most up-to-date measurements of the element. In contrast, <code>useLayoutEffect</code> runs synchronously before the browser paints the changes, ensuring that the <code>width</code> state is always up-to-date with the latest measurements.</p>
<p>Overall, the choice between <code>useEffect</code> and <code>useLayoutEffect</code> depends on the specific use case and the desired behavior of the effect. If the effect relies on the layout or dimensions of DOM elements or needs to perform synchronous updates to the DOM, <code>useLayoutEffect</code> may be more appropriate. Otherwise, <code>useEffect</code> is generally a safer and more performant choice.</p>
]]></content:encoded></item><item><title><![CDATA[PyConf India 2023 - Reflection]]></title><description><![CDATA[It has been over 10 days since I attended the conference, but the memories remain fresh. I made some notes after returning from the conference to not miss anything I experienced in the post. This is my very first conference in person, which makes it ...]]></description><link>https://www.shravaniroy.in/pyconf-india-2023-reflection</link><guid isPermaLink="true">https://www.shravaniroy.in/pyconf-india-2023-reflection</guid><category><![CDATA[Python]]></category><category><![CDATA[PyCon2023]]></category><category><![CDATA[PyConIndia2023]]></category><category><![CDATA[pyladies]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 13 Oct 2023 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>It has been over 10 days since I attended the conference, but the memories remain fresh. I made some notes after returning from the conference to not miss anything I experienced in the post. This is my very first conference in person, which makes it special. I have missed many due to last-minute changes in plans or family commitments, etc. Pyconf popped up in my feed a little late but I didn't want to miss this opportunity. I bought a late bird ticket and you can imagine how enthusiastic I was. I would still say that my Twitter feed has gotten better over time. The community is active there and I get to consume information from all verticles. Coming back to the conference, another reason that I was excited about is that this day was meant to be spent for myself. I had a chance to be by myself for an entire day without worrying and with no guilt. Which made me a little nervous but I was sure I wanted to go for it. I was sure that being alone in a crowd sounded a little scary but better than attending some drama with family and friends. So, by all means, I was set for the day.</p>
<p>The Day:</p>
<p>I made breakfast and lunch for little one and my husband and took a cab to JNTU, where the conference was held. I had mixed thoughts, and so I recited to myself in my head, "It is okay", "they can manage and so I will not think about them", "I will grab a chair and stay there for the rest of the day", "I hope someone comes and talk to me and that way I'll have a company", "its okay either way", "Maybe I'll return after lunch". And with these flooded thoughts, I forgot to wish my mom for her birthday.</p>
<p>As I reached the venue, the helpdesk directed me to attend the keynote. I was a bit overwhelmed looking at the crowd, took a deep breath, and then I stepped to find a chair that was empty on either side and sat. I made myself comfortable and listened to Jessica's keynote. She was amazing and made open source sound simple. Her journey from a volunteer to leading Pyladies Berlin and being a board member has inspired me in many ways. Her talk made me rethink why I should contribute to open source and community. She had repeatedly emphasized on code-of-conduct which ensured me that I was in a safe space. It felt like a great start, up until they gave a refreshment break.</p>
<p>Made friends:</p>
<p>Everyone started moving and I felt a little confused. I observed there were a few women in the hall who were alone too and thought to meet them. As I got close to a woman, her friends came and I turned and walked to the cafeteria. I picked up some tea and looked around. Then found some young girls talking and I could sense that they were introducing themselves to each other. I immediately pitched in and asked if I could join them. Being an introvert is hard until this point. Here on they asked and I had to just answer. Navya, Prachi, Pooja and Bhavna. These girls are way ahead of me. They were kind to talk to me. Navya and Bhavna were from Delhi, in their 2nd year of college. Navya had been sponsored to speak on 3rd track the next day, while Bhavya accompanied her. Prachi is a game developer and has come to network with people. Pooja is an R developer in Deloitte working as a Research Analyst and has been part of the RSE Pune chapter.</p>
<p>After the break, Pooja and Prachi left to attend talks on different tracks in other auditoriums, while I accompanied Navya and Bhavna for a talk on Scratch using ChatGpt. Oh, it was so much fun watching the speaker (sorry I forgot the name of the speaker) build a pyramid in Scratch using solutions suggested by ChatGpt. He had set settings in ChatGpt to add funny comments while sharing code for the pyramid. That made the talk funny and interactive. Post this session, we looked for more such talks in the brochure. As we stepped out of the auditorium, we found Jessica talking to some girls. I remembered that she mentioned in the keynote that she was looking for volunteers from Pune to organize the Pyladies event, as one of her board members Anvesha was leading it by her pocket. Navya and Prachi encouraged me to talk to her, as I said that I was interested in organizing such meetups in Hyderabad. As I shared my interest in mentoring juniors and young girls, and how we can achieve it by starting to motivate girls from school to code in the most fun way possible, Jessica acknowledged and said that we could do that by finding the leads of Pyladies Hyderabad chapter who could help me in this initiative.</p>
<p>Lunch and Open Space Conversations:</p>
<p>Our conversations continued and then we moved to pyladies open space. Where everyone shared their journey and experience with Python. This is where I could hear from Abirami Sukumaran, Vandana, Vaibhavi Singh, and Bowrna Prabhakaran. Each had a wonderful journey and interestingly some of to the community. It is inspiring.</p>
<p>We cut the cake, had lunch, shared some thoughts, and dispersed.</p>
<p>At stalls</p>
<p>I wanted to head back home but Pooja said that we could just check the stalls once. So I got to know that these stalls have some interesting games curated for the attendees. I started with a wordle puzzle and won a keychain. An AI question that I lost. Answered a couple of cloud questions and won Google Cloud hats. Met Swetha at Certa stall and applied for the job. Answered an AI question correctly this time. Won a water bottle, and now my son takes it to school.</p>
<p>Day well spent!</p>
<p>Returned home with a joyful heart. ❤️</p>
]]></content:encoded></item><item><title><![CDATA[map-my-doodhwaala]]></title><description><![CDATA[A new project idea. I thought of this as I am facing issues finding a local doodh-waala. An application that allows users to list milk-procuring places in their locality and search for them. Let me start with basic code implementation.
Here is the ba...]]></description><link>https://www.shravaniroy.in/map-my-doodhwaala</link><guid isPermaLink="true">https://www.shravaniroy.in/map-my-doodhwaala</guid><category><![CDATA[ideas]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 15 Sep 2023 18:51:36 GMT</pubDate><content:encoded><![CDATA[<p>A new project idea. I thought of this as I am facing issues finding a local doodh-waala. An application that allows users to list milk-procuring places in their locality and search for them. Let me start with basic code implementation.</p>
<p>Here is the backend</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask, request, jsonify
<span class="hljs-keyword">from</span> flask_sqlalchemy <span class="hljs-keyword">import</span> SQLAlchemy

app = Flask(__name__)
app.config[<span class="hljs-string">'SQLALCHEMY_DATABASE_URI'</span>] = <span class="hljs-string">'your_database_url_here'</span>
db = SQLAlchemy(app)
</code></pre>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MilkProcurer</span>(<span class="hljs-params">db.Model</span>):</span>
    id = db.Column(db.Integer, primary_key=<span class="hljs-literal">True</span>)
    name = db.Column(db.String(<span class="hljs-number">100</span>), nullable=<span class="hljs-literal">False</span>)
    address = db.Column(db.String(<span class="hljs-number">200</span>), nullable=<span class="hljs-literal">False</span>)
    contact = db.Column(db.String(<span class="hljs-number">15</span>), nullable=<span class="hljs-literal">False</span>)
    <span class="hljs-comment"># Add more fields as needed</span>

<span class="hljs-meta">@app.route('/create_doodh_waala', methods=['POST'])</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_doodh_waala</span>():</span>
    data = request.get_json()
    name = data.get(<span class="hljs-string">'name'</span>)
    address = data.get(<span class="hljs-string">'address'</span>)
    contact = data.get(<span class="hljs-string">'contact'</span>)
    <span class="hljs-comment"># Validate and save the milk-procurer data</span>
    milk_procurer = MilkProcurer(name=name, address=address, contact=contact)
    db.session.add(milk_procurer)
    db.session.commit()
    <span class="hljs-keyword">return</span> jsonify({<span class="hljs-string">'message'</span>: <span class="hljs-string">'Milk-procurer created successfully'</span>}), <span class="hljs-number">201</span>

<span class="hljs-meta">@app.route('/get_doodh_waala', methods=['GET'])</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_doodh_waala</span>():</span>
    milk_procurers = MilkProcurer.query.all()
    result = []
    <span class="hljs-keyword">for</span> milk_procurer <span class="hljs-keyword">in</span> milk_procurers:
        result.append({
            <span class="hljs-string">'name'</span>: milk_procurer.name,
            <span class="hljs-string">'address'</span>: milk_procurer.address,
            <span class="hljs-string">'contact'</span>: milk_procurer.contact,
            <span class="hljs-comment"># Include more fields here</span>
        })
    <span class="hljs-keyword">return</span> jsonify(result)
</code></pre>
<p>React component for listing doodh-waala</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MilkProcuringPlaces</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [places, setPlaces] = useState([]);

    useEffect(<span class="hljs-function">() =&gt;</span> {
        <span class="hljs-comment">// Fetch milk-procuring places from the backend and update the 'places' state.</span>
        <span class="hljs-comment">// You may use the Fetch API or a library like Axios for this.</span>
    }, []);

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Milk Procuring Places<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
                {places.map((place) =&gt; (
                    <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{place.id}</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>{place.name}<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Address: {place.address}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Contact: {place.contact}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                        {/* Add more fields as needed */}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                ))}
            <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> MilkProcuringPlaces;
</code></pre>
<p>To allow users to add a milk-procuring place (Doodhwaala) along with uploading photos and providing a rating, you can create a React component as follows:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">AddDoodhwaala</span>(<span class="hljs-params">{ onAddDoodhwaala }</span>) </span>{
    <span class="hljs-keyword">const</span> [name, setName] = useState(<span class="hljs-string">''</span>);
    <span class="hljs-keyword">const</span> [address, setAddress] = useState(<span class="hljs-string">''</span>);
    <span class="hljs-keyword">const</span> [contact, setContact] = useState(<span class="hljs-string">''</span>);
    <span class="hljs-keyword">const</span> [rating, setRating] = useState(<span class="hljs-number">0</span>);
    <span class="hljs-keyword">const</span> [photos, setPhotos] = useState([]);
    <span class="hljs-keyword">const</span> [photoUrls, setPhotoUrls] = useState([]);

    <span class="hljs-keyword">const</span> handleNameChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
        setName(e.target.value);
    };

    <span class="hljs-keyword">const</span> handleAddressChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
        setAddress(e.target.value);
    };

    <span class="hljs-keyword">const</span> handleContactChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
        setContact(e.target.value);
    };

    <span class="hljs-keyword">const</span> handleRatingChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
        setRating(e.target.value);
    };

    <span class="hljs-keyword">const</span> handlePhotoUpload = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> selectedPhotos = <span class="hljs-built_in">Array</span>.from(e.target.files);

        <span class="hljs-comment">// Display selected photo names to the user</span>
        <span class="hljs-keyword">const</span> selectedPhotoUrls = selectedPhotos.map(<span class="hljs-function">(<span class="hljs-params">photo</span>) =&gt;</span> URL.createObjectURL(photo));

        setPhotos([...photos, ...selectedPhotos]);
        setPhotoUrls([...photoUrls, ...selectedPhotoUrls]);
    };

    <span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function">() =&gt;</span> {
        <span class="hljs-comment">// Prepare the data to send to the parent component</span>
        <span class="hljs-keyword">const</span> doodhwaalaData = {
            name,
            address,
            contact,
            rating,
            photos,
        };

        <span class="hljs-comment">// Pass the data to the parent component for further processing</span>
        onAddDoodhwaala(doodhwaalaData);

        <span class="hljs-comment">// Clear the form fields after submission</span>
        setName(<span class="hljs-string">''</span>);
        setAddress(<span class="hljs-string">''</span>);
        setContact(<span class="hljs-string">''</span>);
        setRating(<span class="hljs-number">0</span>);
        setPhotos([]);
        setPhotoUrls([]);
    };

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Add Doodhwaala<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{handleSubmit}</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"name"</span>&gt;</span>Name:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"name"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{name}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleNameChange}</span> <span class="hljs-attr">required</span> /&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"address"</span>&gt;</span>Address:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"address"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{address}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleAddressChange}</span> <span class="hljs-attr">required</span> /&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"contact"</span>&gt;</span>Contact:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"contact"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{contact}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleContactChange}</span> <span class="hljs-attr">required</span> /&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"rating"</span>&gt;</span>Rating:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"number"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"rating"</span> <span class="hljs-attr">min</span>=<span class="hljs-string">"0"</span> <span class="hljs-attr">max</span>=<span class="hljs-string">"5"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{rating}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleRatingChange}</span> <span class="hljs-attr">required</span> /&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"photos"</span>&gt;</span>Upload Photos:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"photos"</span> <span class="hljs-attr">accept</span>=<span class="hljs-string">"image/*"</span> <span class="hljs-attr">multiple</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handlePhotoUpload}</span> /&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                    {photoUrls.map((url, index) =&gt; (
                        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{url}</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">{</span>`<span class="hljs-attr">Photo</span> ${<span class="hljs-attr">index</span>}`} <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">maxWidth:</span> '<span class="hljs-attr">100px</span>', <span class="hljs-attr">maxHeight:</span> '<span class="hljs-attr">100px</span>' }} /&gt;</span>
                    ))}
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> AddDoodhwaala;
</code></pre>
<p>I will soon make this up and running and then share the git repo here.</p>
<p>Thanks for reading this far. Happy learning!!</p>
]]></content:encoded></item><item><title><![CDATA[Open source projects to contribute in javascript]]></title><description><![CDATA[Contributing to open-source projects is a great way to learn and improve your programming skills. Here are some open-source JavaScript projects that are relatively beginner-friendly and could be good places to start contributing:

FreeCodeCamp (GitHu...]]></description><link>https://www.shravaniroy.in/open-source-projects-to-contribute-in-javascript</link><guid isPermaLink="true">https://www.shravaniroy.in/open-source-projects-to-contribute-in-javascript</guid><category><![CDATA[Open Source]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[contribution to open source]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Wed, 30 Aug 2023 04:07:39 GMT</pubDate><content:encoded><![CDATA[<p>Contributing to open-source projects is a great way to learn and improve your programming skills. Here are some open-source JavaScript projects that are relatively beginner-friendly and could be good places to start contributing:</p>
<ol>
<li><p><strong>FreeCodeCamp (GitHub Repository:</strong> <a target="_blank" href="https://github.com/freeCodeCamp/freeCodeCamp"><strong>https://github.com/freeCodeCamp/freeCodeCamp</strong></a><strong>):</strong> This project is focused on helping people learn to code for free. It includes challenges, certifications, and a large community. Contributions could involve fixing bugs, improving documentation, or adding new coding challenges.</p>
</li>
<li><p><strong>Node.js (GitHub Repository:</strong> <a target="_blank" href="https://github.com/nodejs/node"><strong>https://github.com/nodejs/node</strong></a><strong>):</strong> If you're interested in server-side JavaScript, Node.js is a popular runtime. You can contribute by improving documentation, fixing bugs, or even working on small features.</p>
</li>
<li><p><strong>Hoodie (GitHub Repository:</strong> <a target="_blank" href="https://github.com/hoodiehq/hoodie"><strong>https://github.com/hoodiehq/hoodie</strong></a><strong>):</strong> Hoodie is a framework for building offline-first applications. It's designed to be beginner-friendly and encourages contributions from newcomers.</p>
</li>
<li><p><strong>JavaScript30 (GitHub Repository:</strong> <a target="_blank" href="https://github.com/wesbos/JavaScript30"><strong>https://github.com/wesbos/JavaScript30</strong></a><strong>):</strong> This project offers 30 small JavaScript projects that help you practice and improve your skills. Contributions could involve adding new projects, improving existing ones, or fixing issues.</p>
</li>
<li><p><strong>React (GitHub Repository:</strong> <a target="_blank" href="https://github.com/facebook/react"><strong>https://github.com/facebook/react</strong></a><strong>):</strong> React is a widely used JavaScript library for building user interfaces. Contributing to its documentation, working on issues labeled as "beginner-friendly," or helping with tests could be a good start.</p>
</li>
<li><p><strong>Atom (GitHub Repository:</strong> <a target="_blank" href="https://github.com/atom/atom"><strong>https://github.com/atom/atom</strong></a><strong>):</strong> Atom is a popular text editor developed by GitHub. You can contribute by fixing bugs, improving the user interface, or developing new features.</p>
</li>
<li><p><strong>Ghost (GitHub Repository:</strong> <a target="_blank" href="https://github.com/TryGhost/Ghost"><strong>https://github.com/TryGhost/Ghost</strong></a><strong>):</strong> Ghost is a professional publishing platform. You could contribute by fixing bugs, improving themes, or enhancing the core platform.</p>
</li>
<li><p><strong>Vue.js (GitHub Repository:</strong> <a target="_blank" href="https://github.com/vuejs/vue"><strong>https://github.com/vuejs/vue</strong></a><strong>):</strong> Vue.js is another popular JavaScript framework for building user interfaces. Contributing could involve improving documentation, fixing bugs, or adding new features.</p>
</li>
<li><p><strong>P5.js (GitHub Repository:</strong> <a target="_blank" href="https://github.com/processing/p5.js"><strong>https://github.com/processing/p5.js</strong></a><strong>):</strong> P5.js is a creative coding library that makes coding visuals and animations easier. You could contribute by improving examples, fixing bugs, or helping with documentation.</p>
</li>
<li><p><strong>TensorFlow.js (GitHub Repository:</strong> <a target="_blank" href="https://github.com/tensorflow/tfjs"><strong>https://github.com/tensorflow/tfjs</strong></a><strong>):</strong> If you're interested in machine learning, TensorFlow.js brings machine learning and deep learning to JavaScript. Contributions could involve improving examples, documentation, or fixing issues.</p>
</li>
</ol>
<p>Remember that contributing to open-source projects involves more than just coding. You can contribute by improving documentation, creating tutorials, testing software, designing user interfaces, and more. Before you start contributing, make sure to read the project's contribution guidelines and code of conduct. It's also a good idea to engage with the community through forums, chat rooms, or mailing lists to get a sense of ongoing discussions and priorities.</p>
<p>Here are some less popular javascript open-source projects:</p>
<ol>
<li><p><strong>Choo (GitHub Repository:</strong> <a target="_blank" href="https://github.com/choojs/choo"><strong>https://github.com/choojs/choo</strong></a><strong>):</strong> Choo is a small and focused framework for building user interfaces. It's designed to be simple and could be a great place to contribute if you're interested in front-end development.</p>
</li>
<li><p><strong>Feathers (GitHub Repository:</strong> <a target="_blank" href="https://github.com/feathersjs/feathers"><strong>https://github.com/feathersjs/feathers</strong></a><strong>):</strong> Feathers is a web framework for building real-time applications. Contributions might involve improving documentation, fixing bugs, or working on plugins.</p>
</li>
<li><p><strong>Preact (GitHub Repository:</strong> <a target="_blank" href="https://github.com/preactjs/preact"><strong>https://github.com/preactjs/preact</strong></a><strong>):</strong> Preact is a fast 3kB alternative to React with the same modern API. You could contribute by improving performance, fixing issues, or enhancing the library.</p>
</li>
<li><p><strong>Rambda (GitHub Repository:</strong> <a target="_blank" href="https://github.com/ramda/ramda"><strong>https://github.com/ramda/ramda</strong></a><strong>):</strong> Rambda is a functional programming library for JavaScript. Contributions could involve adding new functions, improving existing ones, or writing tests.</p>
</li>
<li><p><strong>Gatsby Themes (GitHub Repository:</strong> <a target="_blank" href="https://github.com/gatsbyjs/themes"><strong>https://github.com/gatsbyjs/themes</strong></a><strong>):</strong> Gatsby Themes allow you to package up reusable functionality, like a sidebar or analytics integration, as a theme. Contributing might involve creating or enhancing themes, improving the documentation, or fixing bugs.</p>
</li>
<li><p><strong>Smoothie Charts (GitHub Repository:</strong> <a target="_blank" href="https://github.com/joewalnes/smoothie"><strong>https://github.com/joewalnes/smoothie</strong></a><strong>):</strong> Smoothie Charts is a JavaScript charting library for streaming data. You could contribute by improving chart types, adding new features, or enhancing performance.</p>
</li>
<li><p><strong>Vuido (GitHub Repository:</strong> <a target="_blank" href="https://github.com/mimecorg/vuido"><strong>https://github.com/mimecorg/vuido</strong></a><strong>):</strong> Vuido allows you to create native desktop applications using Vue.js. Contributions might involve improving cross-platform compatibility, adding new features, or optimizing performance.</p>
</li>
<li><p><strong>Greenlet (GitHub Repository:</strong> <a target="_blank" href="https://github.com/developit/greenlet"><strong>https://github.com/developit/greenlet</strong></a><strong>):</strong> Greenlet is a small utility library for moving an async function into its own thread. You could contribute by improving documentation, optimizing the library, or fixing issues.</p>
</li>
<li><p><strong>ECharts (GitHub Repository:</strong> <a target="_blank" href="https://github.com/apache/echarts"><strong>https://github.com/apache/echarts</strong></a><strong>):</strong> ECharts is a powerful charting and visualization library. Contributions could involve improving documentation, adding new chart types, or enhancing existing features.</p>
</li>
<li><p><strong>Mithril (GitHub Repository:</strong> <a target="_blank" href="https://github.com/MithrilJS/mithril.js"><strong>https://github.com/MithrilJS/mithril.js</strong></a><strong>):</strong> Mithril is a lightweight JavaScript framework for building single-page applications. You could contribute by working on performance improvements, fixing bugs, or enhancing the documentation.</p>
</li>
</ol>
<p>Remember that the popularity of a project doesn't necessarily reflect its value or the impact of your contributions. Less popular projects often have smaller, more tight-knit communities where your efforts can have a significant impact. Before you start contributing, make sure to explore the project's repository, issues, and contribution guidelines to get a sense of how you can best contribute.</p>
]]></content:encoded></item><item><title><![CDATA[Streamlit: Empowering Data Scientists with Python-Powered Web Apps]]></title><description><![CDATA[As the world of data science continues to expand, the need for efficient and accessible tools to showcase data analysis projects becomes paramount. This is where Streamlit shines - a Python library that transforms data scripts into interactive web ap...]]></description><link>https://www.shravaniroy.in/streamlit-empowering-data-scientists-with-python-powered-web-apps</link><guid isPermaLink="true">https://www.shravaniroy.in/streamlit-empowering-data-scientists-with-python-powered-web-apps</guid><category><![CDATA[Data Science]]></category><category><![CDATA[Python]]></category><category><![CDATA[streamlit]]></category><category><![CDATA[#data visualisation]]></category><category><![CDATA[python libraries]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Wed, 19 Jul 2023 04:09:34 GMT</pubDate><content:encoded><![CDATA[<p>As the world of data science continues to expand, the need for efficient and accessible tools to showcase data analysis projects becomes paramount. This is where Streamlit shines - a Python library that transforms data scripts into interactive web applications with ease. Streamlit offers a range of compelling features that make it an indispensable asset in any data scientist's toolkit.</p>
<h3 id="heading-1-pythonic-simplicity"><strong>1. Pythonic Simplicity:</strong></h3>
<p>One of the standout features of Streamlit is its Pythonic simplicity. The clean and intuitive API allows us to create impressive web apps with just a few lines of code. This eliminates the need to know web development languages like HTML, CSS, or JavaScript; instead, we can focus solely on crafting compelling data visualizations and applications. Let me share how you could get started by importing streamlit in your project:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> streamlit <span class="hljs-keyword">as</span> st

<span class="hljs-comment"># Simple Streamlit app to display a title and plot a chart</span>
st.title(<span class="hljs-string">"Hello, Streamlit!"</span>)
st.write(<span class="hljs-string">"Let's create a basic line chart."</span>)
chart_data = {<span class="hljs-string">'x'</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>], <span class="hljs-string">'y'</span>: [<span class="hljs-number">10</span>, <span class="hljs-number">5</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">12</span>]}
st.line_chart(chart_data)
</code></pre>
<h3 id="heading-2-rapid-prototyping-and-real-time-iteration"><strong>2. Rapid Prototyping and Real-time Iteration:</strong></h3>
<p>Time is of the essence in any data project, and Streamlit helps us make the most of it. Rapid prototyping is where Streamlit truly shines, as we can transform our ideas into functional web apps within minutes. The real-time feedback loop facilitates quick iterations, allowing us to fine-tune our apps on the fly and present our results with the latest updates. This seamless workflow enhances productivity and reduces development time significantly.</p>
<h3 id="heading-3-widgets-for-interactivity"><strong>3. Widgets for Interactivity:</strong></h3>
<p>Interactivity is a crucial aspect of data communication, and Streamlit's wide array of widgets makes it a breeze to create interactive elements in our web apps. Whether it's sliders, buttons, text inputs, or date pickers, Streamlit provides a simple interface to add these widgets, making our apps engaging and user-friendly. This level of interactivity enhances the user experience and encourages exploration of the underlying data. Here is a code snippet to use a slider:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> streamlit <span class="hljs-keyword">as</span> st

<span class="hljs-comment"># Simple Streamlit app to demonstrate interactivity with sliders</span>
age = st.slider(<span class="hljs-string">"Select your age:"</span>, min_value=<span class="hljs-number">0</span>, max_value=<span class="hljs-number">100</span>, value=<span class="hljs-number">25</span>)
st.write(<span class="hljs-string">"The square of"</span>, number, <span class="hljs-string">"is"</span>, result, <span class="hljs-string">"."</span>)
<span class="hljs-comment">#we could also write the same as below</span>
st.write(<span class="hljs-string">"The square of {} is {}."</span>.format(number, result))
</code></pre>
<h3 id="heading-4-seamless-library-integration"><strong>4. Seamless Library Integration:</strong></h3>
<p>In the realm of data science, we rely heavily on various libraries for data manipulation, analysis, and visualization. Streamlit plays well with the popular libraries in the Python ecosystem, including Pandas, Matplotlib, Plotly, and more. This seamless integration allows us to leverage our existing codebase and ensures that we can smoothly transition our data projects into interactive web apps. Let's see how:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> streamlit <span class="hljs-keyword">as</span> st
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">import</span> plotly.express <span class="hljs-keyword">as</span> px

<span class="hljs-comment"># Simple Streamlit app to load data and create a scatter plot</span>
data = pd.read_csv(<span class="hljs-string">"data.csv"</span>)
st.write(data)
<span class="hljs-comment">#which is st.write(pd.read_csv("data.csv"))</span>

fig = px.scatter(data, x=<span class="hljs-string">'x'</span>, y=<span class="hljs-string">'y'</span>, color=<span class="hljs-string">'category'</span>)
st.plotly_chart(fig)
</code></pre>
<h3 id="heading-5-sharing-and-collaboration"><strong>5. Sharing and Collaboration:</strong></h3>
<p>Streamlit is not just about personal productivity; it's about collaboration and sharing as well. The ease of sharing our web apps with colleagues, stakeholders, or the broader community cannot be overstated. Whether deploying on Streamlit Sharing or cloud platforms like Heroku, we can quickly showcase our work to the world, fostering knowledge exchange and collaboration. It is as simple as shown below:</p>
<pre><code class="lang-python">streamlit share -- -app your_streamlit_app.py
</code></pre>
<p>Streamlit is a game-changer for data scientists looking to elevate their projects beyond static visualizations. If you're a data scientist looking to amplify your impact and communicate your findings effectively, Streamlit is undoubtedly a tool worth exploring. Embrace the power of Python-powered web apps and unlock a new dimension in your data storytelling journey.</p>
<p>I hope this was helpful. Thank you! Happy learning.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Unlocking Efficiency with the Sliding Window Technique:]]></title><description><![CDATA[Introduction: Efficient algorithms are the backbone of modern software development. In this blog post, we will explore the sliding window technique—an algorithmic approach that can dramatically improve efficiency in certain scenarios. We will delve i...]]></description><link>https://www.shravaniroy.in/unlocking-efficiency-with-the-sliding-window-technique</link><guid isPermaLink="true">https://www.shravaniroy.in/unlocking-efficiency-with-the-sliding-window-technique</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[DSA]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[data structures]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 07 Jul 2023 17:56:59 GMT</pubDate><content:encoded><![CDATA[<p>Introduction: Efficient algorithms are the backbone of modern software development. In this blog post, we will explore the sliding window technique—an algorithmic approach that can dramatically improve efficiency in certain scenarios. We will delve into how this technique works, and its efficiency benefits, and showcase a real-world use case in a banking application.</p>
<p>Understanding the Sliding Window Technique: The sliding window technique involves maintaining a "window" of elements within a data structure and iteratively sliding the window to solve a specific problem efficiently. By optimizing the way we process data, we can often achieve better time complexity compared to brute-force approaches.</p>
<p>Efficiency Benefits:</p>
<ol>
<li><p>Reduced Computation: The sliding window technique avoids unnecessary recomputations by reusing previously computed results within the window. This leads to improved time complexity and faster execution.</p>
</li>
<li><p>Linear Complexity: In many cases, the sliding window technique allows us to solve problems with linear time complexity (O(n)), which is far more efficient than quadratic or exponential complexity.</p>
</li>
</ol>
<p>Use Case 1: Banking Application: Consider a banking application that needs to identify the longest consecutive sequence of transactions above a certain threshold amount. The sliding window technique is a perfect fit for this scenario. By maintaining a window of transaction amounts and sliding it through the data, we can efficiently identify the longest sequence without checking every possible subarray.</p>
<p>Let's look at a JavaScript implementation of the sliding window technique for this use case:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">findLongestSequence</span>(<span class="hljs-params">transactions, threshold</span>) </span>{
  <span class="hljs-keyword">let</span> maxLength = <span class="hljs-number">0</span>;
  <span class="hljs-keyword">let</span> currentLength = <span class="hljs-number">0</span>;

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; transactions.length; i++) {
    <span class="hljs-keyword">if</span> (transactions[i] &gt; threshold) {
      currentLength++;
    } <span class="hljs-keyword">else</span> {
      maxLength = <span class="hljs-built_in">Math</span>.max(maxLength, currentLength);
      currentLength = <span class="hljs-number">0</span>;
    }
  }

  <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.max(maxLength, currentLength);
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> transactions = [<span class="hljs-number">120</span>, <span class="hljs-number">140</span>, <span class="hljs-number">200</span>, <span class="hljs-number">80</span>, <span class="hljs-number">100</span>, <span class="hljs-number">250</span>, <span class="hljs-number">300</span>, <span class="hljs-number">320</span>, <span class="hljs-number">200</span>, <span class="hljs-number">180</span>];
<span class="hljs-keyword">const</span> threshold = <span class="hljs-number">150</span>;
<span class="hljs-keyword">const</span> longestSequence = findLongestSequence(transactions, threshold);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Longest sequence above <span class="hljs-subst">${threshold}</span>: <span class="hljs-subst">${longestSequence}</span>`</span>);
</code></pre>
<p>In this example, we define the <code>findLongestSequence</code> function that takes an array of transactions and a threshold amount. The function iterates over the transactions, maintaining the current length of consecutive amounts above the threshold. When a transaction falls below the threshold, the current length is compared with the maximum length encountered so far. Finally, the function returns the longest sequence length.</p>
<p>Use Case 2: Fraud Detection - Anomaly Detection Detecting anomalies and potential fraud in banking transactions is critical. The sliding window technique can be used to identify unusual patterns in transaction amounts.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">detectAnomalies</span>(<span class="hljs-params">transactions, windowSize, threshold</span>) </span>{
  <span class="hljs-keyword">const</span> anomalies = [];

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; transactions.length; i++) {
    <span class="hljs-keyword">if</span> (i &gt;= windowSize) {
      <span class="hljs-keyword">const</span> <span class="hljs-built_in">window</span> = transactions.slice(i - windowSize, i);
      <span class="hljs-keyword">const</span> average = <span class="hljs-built_in">window</span>.reduce(<span class="hljs-function">(<span class="hljs-params">sum, amount</span>) =&gt;</span> sum + amount, <span class="hljs-number">0</span>) / windowSize;

      <span class="hljs-keyword">if</span> (transactions[i] &gt; threshold * average) {
        anomalies.push({ <span class="hljs-attr">transaction</span>: transactions[i], <span class="hljs-attr">index</span>: i });
      }
    }
  }

  <span class="hljs-keyword">return</span> anomalies;
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> transactionAmounts = [<span class="hljs-number">100</span>, <span class="hljs-number">150</span>, <span class="hljs-number">200</span>, <span class="hljs-number">120</span>, <span class="hljs-number">180</span>, <span class="hljs-number">900</span>, <span class="hljs-number">120</span>, <span class="hljs-number">250</span>, <span class="hljs-number">300</span>, <span class="hljs-number">80</span>];
<span class="hljs-keyword">const</span> windowSize = <span class="hljs-number">5</span>;
<span class="hljs-keyword">const</span> anomalyThreshold = <span class="hljs-number">2</span>;
<span class="hljs-keyword">const</span> detectedAnomalies = detectAnomalies(transactionAmounts, windowSize, anomalyThreshold);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Detected Anomalies:'</span>, detectedAnomalies);
</code></pre>
<p>In this example, we detect anomalies in transaction amounts by comparing each transaction to the average of the previous window. If a transaction exceeds a certain threshold (e.g., twice the average), it is flagged as an anomaly. By using a sliding window, we can efficiently analyze transaction patterns and identify potential fraud.</p>
<p>Another example with strings: Longest Substring with K Distinct Characters Given a string, you can use the sliding window technique to find the length of the longest substring that contains at most K distinct characters.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">findLongestSubstringWithKDistinct</span>(<span class="hljs-params">str, k</span>) </span>{
  <span class="hljs-keyword">let</span> longestLength = <span class="hljs-number">0</span>;
  <span class="hljs-keyword">let</span> start = <span class="hljs-number">0</span>;
  <span class="hljs-keyword">const</span> charMap = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> end = <span class="hljs-number">0</span>; end &lt; str.length; end++) {
    <span class="hljs-keyword">const</span> currentChar = str[end];
    charMap.set(currentChar, (charMap.get(currentChar) || <span class="hljs-number">0</span>) + <span class="hljs-number">1</span>);

    <span class="hljs-keyword">while</span> (charMap.size &gt; k) {
      <span class="hljs-keyword">const</span> leftChar = str[start];
      charMap.set(leftChar, charMap.get(leftChar) - <span class="hljs-number">1</span>);
      <span class="hljs-keyword">if</span> (charMap.get(leftChar) === <span class="hljs-number">0</span>) {
        charMap.delete(leftChar);
      }
      start++;
    }

    longestLength = <span class="hljs-built_in">Math</span>.max(longestLength, end - start + <span class="hljs-number">1</span>);
  }

  <span class="hljs-keyword">return</span> longestLength;
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> inputString = <span class="hljs-string">'aabacbebebe'</span>;
<span class="hljs-keyword">const</span> k = <span class="hljs-number">3</span>;
<span class="hljs-keyword">const</span> longestLength = findLongestSubstringWithKDistinct(inputString, k);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Length of the longest substring with <span class="hljs-subst">${k}</span> distinct characters: <span class="hljs-subst">${longestLength}</span>`</span>);
</code></pre>
<p>Thanks for reading so far. Happy Learning !!</p>
]]></content:encoded></item><item><title><![CDATA[5 commonly used react hooks]]></title><description><![CDATA[I have 5 plus years of experience in using React js in real-time applications. I started with component life cycle methods in class components and gradually moved to functional components. I have found functional components easy to use and manage. On...]]></description><link>https://www.shravaniroy.in/5-commonly-used-react-hooks</link><guid isPermaLink="true">https://www.shravaniroy.in/5-commonly-used-react-hooks</guid><category><![CDATA[React]]></category><category><![CDATA[hooks]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Tue, 21 Mar 2023 05:38:51 GMT</pubDate><content:encoded><![CDATA[<p>I have 5 plus years of experience in using React js in real-time applications. I started with component life cycle methods in class components and gradually moved to functional components. I have found functional components easy to use and manage. Once, I got a task to migrate some old project's codebase into functional components, which build muscle memory around the react hooks. In this post, I have shared the 5 most commonly used react hooks with some simple examples.</p>
<ol>
<li><p>useState :</p>
<p> The useState hook is used for managing the state within a functional component. Here's an example of how to use it to display a simple form:</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Form</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [formData, setFormData] = useState({ <span class="hljs-attr">name</span>: <span class="hljs-string">''</span>, <span class="hljs-attr">email</span>: <span class="hljs-string">''</span>, <span class="hljs-attr">message</span>: <span class="hljs-string">''</span> });

  <span class="hljs-keyword">const</span> handleInputChange = <span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> { name, value } = event.target;
    setFormData(<span class="hljs-function">(<span class="hljs-params">prevFormData</span>) =&gt;</span> ({ ...prevFormData, [name]: value }));
  };

  <span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
    event.preventDefault();
    <span class="hljs-built_in">console</span>.log(formData);
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{handleSubmit}</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{formData.name}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleInputChange}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{formData.email}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleInputChange}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"message"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{formData.message}</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleInputChange}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span></span>
  );
}
</code></pre>
<p>In this example, <code>useState</code> is used to manage the state of a form. The <code>formData</code> object contains the current values of the form inputs and is updated via the <code>handleInputChange</code> function. The <code>handleSubmit</code> function logs the form data to the console when the form is submitted.</p>
<ol>
<li><p>useEffect :</p>
<p> The useEffect hook is used for performing side effects within a component, such as fetching data from an API. Here's an example of how to use it to fetch data from a fake API:</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

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

  useEffect(<span class="hljs-function">() =&gt;</span> {
    fetch(<span class="hljs-string">'https://jsonplaceholder.typicode.com/posts'</span>)
      .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
      .then(<span class="hljs-function"><span class="hljs-params">json</span> =&gt;</span> setData(json))
  }, []);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      {data.map(item =&gt; (
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{item.id}</span>&gt;</span>{item.title}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span></span>
  );
}
</code></pre>
<ol>
<li><p>useContext :</p>
<p> The useContext hook is used for accessing context within a component. Here's an example of how to use it to change the theme of an app:</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useContext } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> ThemeContext = React.createContext(<span class="hljs-string">'light'</span>);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Theme</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> theme = useContext(ThemeContext);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{</span>`<span class="hljs-attr">theme-</span>${<span class="hljs-attr">theme</span>}`}&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Current theme: {theme}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">ThemeContext.Provider</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"dark"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Theme</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ThemeContext.Provider</span>&gt;</span></span>
  );
}
</code></pre>
<ol>
<li><p>useRef :</p>
<p> The useRef hook is used for creating a reference to a component or element within a component. Here's an example of how to use it to focus on an input element:</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useRef } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Input</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> inputRef = useRef(<span class="hljs-literal">null</span>);

  <span class="hljs-keyword">const</span> handleClick = <span class="hljs-function">() =&gt;</span> {
    inputRef.current.focus();
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{inputRef}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{handleClick}</span>&gt;</span>Focus<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<ol>
<li><p>useCallback :</p>
<p> The useCallback hook is used for memoizing a function within a component. Here's an example of how to use it to memorize a handler function:</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useCallback, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Counter</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);

  <span class="hljs-keyword">const</span> handleIncrement = useCallback(<span class="hljs-function">() =&gt;</span> {
    setCount(<span class="hljs-function">(<span class="hljs-params">prevCount</span>) =&gt;</span> prevCount + <span class="hljs-number">1</span>);
  }, []);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Count: {count}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{handleIncrement}</span>&gt;</span>Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>In this example, <code>useCallback</code> is used to memoize the <code>handleIncrement</code> function. Since <code>handleIncrement</code> does not depend on any variables outside of its scope, it is only created once when the component is mounted, rather than being recreated on every render. This can help improve performance, particularly for expensive calculations or when passing functions down as props to child components.</p>
<p>I hope this was helpful. Thank you! Happy learning.</p>
]]></content:encoded></item><item><title><![CDATA[Optimizing the Performance of a React JS App]]></title><description><![CDATA[React is a developer-friendly and lightweight JavaScript library for building user interfaces. However, as your app grows in complexity, it's important to ensure that it runs efficiently and provides a smooth user experience. In this post, we'll expl...]]></description><link>https://www.shravaniroy.in/optimizing-the-performance-of-a-react-js-app</link><guid isPermaLink="true">https://www.shravaniroy.in/optimizing-the-performance-of-a-react-js-app</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[optimization]]></category><category><![CDATA[Developer]]></category><category><![CDATA[UX]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 17 Feb 2023 06:20:58 GMT</pubDate><content:encoded><![CDATA[<p>React is a developer-friendly and lightweight JavaScript library for building user interfaces. However, as your app grows in complexity, it's important to ensure that it runs efficiently and provides a smooth user experience. In this post, we'll explore some of the key steps you can take to optimize the performance of your React app.</p>
<ol>
<li>Minimize the Number of Components</li>
</ol>
<p>One of the most important ways to improve the performance of your React app is to minimize the number of components. Every component in your app requires memory and processing power to render, so reducing the number of components can have a significant impact on performance. Consider the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> MyComponent = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      {data.map(item =&gt; (
        <span class="hljs-tag">&lt;<span class="hljs-name">MyChildComponent</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{item.id}</span> <span class="hljs-attr">item</span>=<span class="hljs-string">{item}</span> /&gt;</span>
      ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>In this code, we have a parent component <code>MyComponent</code> that renders a list of <code>MyChildComponent</code> components. To reduce the number of components, we can replace <code>MyChildComponent</code> with a functional component and use <code>React.memo</code> to memorize it:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> MyChildComponent = React.memo(<span class="hljs-function">(<span class="hljs-params">{ item }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{item.value}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
});

<span class="hljs-keyword">const</span> MyComponent = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      {data.map(item =&gt; (
        <span class="hljs-tag">&lt;<span class="hljs-name">MyChildComponent</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{item.id}</span> <span class="hljs-attr">item</span>=<span class="hljs-string">{item}</span> /&gt;</span>
      ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>With this optimization, <code>MyChildComponent</code> will only re-render when its props change, which can significantly reduce the number of times it needs to be rendered.</p>
<ol start="2">
<li>Use Lazy Loading: Lazy loading is another important technique for optimizing the performance of your React app. With lazy loading, you can load components only when they're needed, instead of loading everything at once. This can significantly improve the initial loading time of your app. Small example of how to use lazy loading in React:</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> MyComponent = React.lazy(<span class="hljs-function">() =&gt;</span> <span class="hljs-keyword">import</span>(<span class="hljs-string">'./MyComponent'</span>));

<span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Suspense</span> <span class="hljs-attr">fallback</span>=<span class="hljs-string">{</span>&lt;<span class="hljs-attr">div</span>&gt;</span>Loading...<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>}&gt;
        <span class="hljs-tag">&lt;<span class="hljs-name">MyComponent</span> /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Suspense</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>In this code, <code>MyComponent</code> is loaded using the <code>React.lazy</code> function. The <code>Suspense Component</code> is used to display a loading message while <code>MyComponent</code> is being loaded.</p>
<ol start="3">
<li>Use Pure Components: Pure components are components that only re-render when the props they receive change. Use pure components instead of regular components to avoid unnecessary re-rendering, which can significantly improve the performance of your app. Let us create a pure component in React:</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> MyPureComponent = React.memo(<span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{data}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
});

<span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [data, setData] = React.useState(<span class="hljs-string">'Initial data'</span>);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">MyPureComponent</span> <span class="hljs-attr">data</span>=<span class="hljs-string">{data}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setData('Updated data')}&gt;Update Data<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>With this code, <code>MyPureComponent</code> will only re-render when the <code>data</code> prop changes, which can significantly improve the performance of your app.</p>
<ol start="4">
<li>Use the Right Data Structures: Using the right data structures can also have a significant impact on the performance of your app(developed using any framework). For example, if you need to display a large list of items, using an array of objects can be slow compared to using a more optimized data structure like a hash table. I tried the below to implement a hash table in react application.</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> hashTable = {};
<span class="hljs-keyword">const</span> data = [{ <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'Item 1'</span> }, { <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'Item 2'</span> }];

data.forEach(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> {
  hashTable[item.id] = item;
});

<span class="hljs-keyword">const</span> MyComponent = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      {Object.values(hashTable).map(item =&gt; (
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{item.id}</span>&gt;</span>{item.value}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};
</code></pre>
<p>By following these best practices, you can significantly improve the performance of your React app. Remember to regularly monitor the performance of your app and make optimizations as needed to ensure that it runs smoothly and provides a great user experience.</p>
<p>I hope this was helpful. Thank you! Happy learning.</p>
]]></content:encoded></item><item><title><![CDATA[Managing Complex State in Your React App using Redux]]></title><description><![CDATA[In a basic React app, state management can quickly become a headache as the app grows. The state updates in one component can trigger updates in another, leading to complex, hard-to-debug interactions.
Solution: Redux provides a centralized store to ...]]></description><link>https://www.shravaniroy.in/managing-complex-state-in-your-react-app-using-redux</link><guid isPermaLink="true">https://www.shravaniroy.in/managing-complex-state-in-your-react-app-using-redux</guid><category><![CDATA[React]]></category><category><![CDATA[Redux]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Developer]]></category><category><![CDATA[Programming Tips]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 06 Jan 2023 08:29:37 GMT</pubDate><content:encoded><![CDATA[<p>In a basic React app, state management can quickly become a headache as the app grows. The state updates in one component can trigger updates in another, leading to complex, hard-to-debug interactions.</p>
<p><strong>Solution:</strong> Redux provides a centralized store to manage the state of your application. The state is updated using actions and reducers, and the updated state is available to all components that need it. This eliminates the need to pass props through multiple components and eliminates complex state updates.</p>
<p>In this post let us explore how we can use it in a react application. The app will be a simple expense-tracking application where users can add expenses and view a list of all the expenses they've added. The user will be able to add the name and amount of the expense, and the date it was incurred. Let's take a look at how we can use Redux in our expense tracking app.</p>
<p>First, we need to install the redux library.</p>
<p><code>npm install redux</code></p>
<p>Next, we need to set up the Redux store. The store is the central repository of all the state in our application.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { createStore } <span class="hljs-keyword">from</span> <span class="hljs-string">'redux'</span>;

<span class="hljs-keyword">const</span> initialState = {
  <span class="hljs-attr">expenses</span>: []
};

<span class="hljs-keyword">const</span> reducer = <span class="hljs-function">(<span class="hljs-params">state = initialState, action</span>) =&gt;</span> {
  <span class="hljs-keyword">switch</span> (action.type) {
    <span class="hljs-keyword">case</span> <span class="hljs-string">'ADD_EXPENSE'</span>:
      <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">expenses</span>: [...state.expenses, action.payload] };
    <span class="hljs-keyword">default</span>:
      <span class="hljs-keyword">return</span> state;
  }
};

<span class="hljs-keyword">const</span> store = createStore(reducer);
</code></pre>
<p>Next, we'll create a component for the form where the user can add expenses. This component will dispatch an action to add an expense to the Redux store when the form is submitted.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { useDispatch } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-redux'</span>;

<span class="hljs-keyword">const</span> AddExpenseForm = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [name, setName] = useState(<span class="hljs-string">''</span>);
  <span class="hljs-keyword">const</span> [amount, setAmount] = useState(<span class="hljs-string">''</span>);
  <span class="hljs-keyword">const</span> [date, setDate] = useState(<span class="hljs-string">''</span>);
  <span class="hljs-keyword">const</span> dispatch = useDispatch();

  <span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function"><span class="hljs-params">e</span> =&gt;</span> {
    e.preventDefault();
    dispatch({
      <span class="hljs-attr">type</span>: <span class="hljs-string">'ADD_EXPENSE'</span>,
      <span class="hljs-attr">payload</span>: { name, amount, date }
    });
    setName(<span class="hljs-string">''</span>);
    setAmount(<span class="hljs-string">''</span>);
    setDate(<span class="hljs-string">''</span>);
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{handleSubmit}</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
        <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Name"</span>
        <span class="hljs-attr">value</span>=<span class="hljs-string">{name}</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setName(e.target.value)}
      /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
        <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Amount"</span>
        <span class="hljs-attr">value</span>=<span class="hljs-string">{amount}</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setAmount(e.target.value)}
      /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
        <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Date"</span>
        <span class="hljs-attr">value</span>=<span class="hljs-string">{date}</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setDate(e.target.value)}
      /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Add Expense<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> AddExpenseForm;
</code></pre>
<p>Finally, we'll create a component to display the list of expenses. This component will be connected to the Redux store and will receive the expenses from the store as props.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { connect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-redux'</span>;

<span class="hljs-keyword">const</span> ExpenseList = <span class="hljs-function">(<span class="hljs-params">{ expenses }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span>(
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"container"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        {expenses.map((expense, index) =&gt; (
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"listContainer"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"expenseText"</span>&gt;</span>{expense.text}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"expenseAmount"</span>&gt;</span>${expense.amount}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        ))}
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
)};

<span class="hljs-keyword">const</span> mapStateToProps = <span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> ({
  <span class="hljs-attr">expenses</span>: state.expenses
});

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> connect(mapStateToProps)(ExpenseList);
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f5f5f5</span>;
}

<span class="hljs-selector-class">.listContainer</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-direction</span>: row;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#cccccc</span>;
  <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-selector-class">.expenseText</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">18px</span>;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#444444</span>;
}

<span class="hljs-selector-class">.expenseAmount</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">18px</span>;
  <span class="hljs-attribute">margin-left</span>: auto;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#444444</span>;
}
</code></pre>
<p>Benefits:</p>
<p>Let me summarise the benefits of using the Redux library so that you can opt to use it in your next react application.</p>
<ul>
<li><p>Centralized state management</p>
</li>
<li><p>Predictable state updates</p>
</li>
<li><p>Easy debugging</p>
</li>
<li><p>Reusable code</p>
</li>
<li><p>Improved performance</p>
</li>
</ul>
<p>In conclusion, Redux is a must-have tool for any React app that needs to manage complex state updates. It makes our app more scalable, maintainable, and predictable.</p>
<p>I hope this was helpful. Thank you! Happy learning.</p>
]]></content:encoded></item><item><title><![CDATA[Keyboard - Instrument using javascript.]]></title><description><![CDATA[In this blog, I will describe how I developed a mini-application, where we can play the keyboard instrument. 
Background:
My husband is a musician and uses plenty of software to produce his tracks. These applications are quite expensive and sometimes...]]></description><link>https://www.shravaniroy.in/keyboard-instrument-using-javascript</link><guid isPermaLink="true">https://www.shravaniroy.in/keyboard-instrument-using-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[projects]]></category><category><![CDATA[100DaysOfCode]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Mon, 21 Nov 2022 08:26:22 GMT</pubDate><content:encoded><![CDATA[<p>In this blog, I will describe how I developed a mini-application, where we can play the keyboard instrument. </p>
<h3 id="heading-background">Background:</h3>
<p>My husband is a musician and uses plenty of software to produce his tracks. These applications are quite expensive and sometimes he needs only a few features of them to make his work better. Never too late, it occurred to me to explore and see if I can build them for him. So, this is my first step to trying out the instruments first. And the plan is to build an app around instruments. I will keep sharing the developed parts in this series. </p>
<h3 id="heading-prerequisites-of-the-project">Prerequisites of the project:</h3>
<p>Let us get started with this mini-app. In order to get started, we need all the key sounds. We could either use sound files or generate them using a synthesizer. In this project, I am using downloaded sound files from the internet and you can download them from my <a target="_blank" href="https://github.com/ShravaniRoy/piano-keyboard-javascript">git-repo</a>. I am sure you can find better files, please do your research if you don't like the sounds <a target="_blank" href="https://github.com/ShravaniRoy/piano-keyboard-javascript">here</a>.</p>
<h3 id="heading-folder-structure">Folder structure:</h3>
<p>We start by creating three files in the root directory - index.html, index.js, and styles.css. Open index.html and type the exclamation mark and hit enter to get the boilerplate code for html file. We can then add the link tag for styles.css file and the script tag for index.js file. We could hold all the sound files in a folder in the root directory, as shown in the below screenshot. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1669013838585/T_6XZs25_.png" alt="Screenshot 2022-11-21 at 12.27.05 PM.png" /></p>
<h3 id="heading-ui-of-the-keyboard">UI of the Keyboard:</h3>
<p>We would need a container and then 7 white keys with 5 black keys(representing the flat keys) in between. You can find the code below. We would use data attributes to link to respective sound files. In order to access sound files, we shall use the audio tags and each of those would hold the id attribute the same as data-note of the respective keys. </p>
<pre><code>  &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"keys"</span>&gt;        
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"C"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"Db"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key black"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"D"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"Eb"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key black"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"E"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"F"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"Gb"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key black"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"G"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"Ab"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key black"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"A"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"Bb"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key black"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-note</span>=<span class="hljs-string">"B"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"key white"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
   &lt;/div&gt;

      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"C"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/C.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Db"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/Db.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"D"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/D.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Eb"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/Eb.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"E"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/E.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"F"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/F.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Gb"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/Gb.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"G"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/G.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Ab"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/Ab.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"A"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/A.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Bb"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/Bb.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"B"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"sounds/B.mp3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span></span>
</code></pre><h3 id="heading-styling">Styling:</h3>
<p>We can start with setting the border-box for the entire layout. Width of the key is different for white keys and black ones, so we use a variable for width and calculate it for the key.
In order to get the black keys on top of the white ones, we set the margin-left and margin-right of the black keys to a negative value. This would let the black keys on top of one white key, and to get them on top of both white keys on either of their sides, set the z-index to 2.</p>
<pre><code>*, *::before, *::after {
    box-sizing: border-box;
  }

  body {
    background-color: #d3ebe6fc;
    margin: <span class="hljs-number">0</span>;
    min-height: <span class="hljs-number">100</span>vh;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .keys {
    <span class="hljs-attr">display</span>: flex;
  }

  .key {
    <span class="hljs-attr">height</span>: calc(<span class="hljs-keyword">var</span>(--width) * <span class="hljs-number">4</span>);
    width: <span class="hljs-keyword">var</span>(--width);
  }

  .white {
    --width: <span class="hljs-number">100</span>px;
    background-color: white;
    border: <span class="hljs-number">1</span>px solid #<span class="hljs-number">333</span>;
  }

  .white.active {
    background-color: #CCC;
  }

  .black {
    --width: <span class="hljs-number">60</span>px;
    background-color: black;
    margin-left: calc(<span class="hljs-keyword">var</span>(--width) / <span class="hljs-number">-2</span>);
    margin-right: calc(<span class="hljs-keyword">var</span>(--width) / <span class="hljs-number">-2</span>);
    z-index: <span class="hljs-number">2</span>;
  }

  .black.active {
    background-color: #<span class="hljs-number">333</span>;
  }
</code></pre><p>Here's the final output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1669015242570/vv6h7tWFj.png" alt="Screenshot 2022-11-21 at 12.50.31 PM.png" /></p>
<h3 id="heading-fun-part-javascript">Fun part - javascript:</h3>
<p>Here is where all the magic is created. In order to get started, we shall get all the keys as DOM elements. And for each of these keys add an event listener to play the respective sound. Find the function playNoteSound from below code snippet.</p>
<pre><code><span class="hljs-keyword">const</span> allkeys = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">'.key'</span>);

allkeys.forEach(<span class="hljs-function"><span class="hljs-params">key</span> =&gt;</span> {
  <span class="hljs-comment">//adding event listener for click event  </span>
  key.addEventListener(<span class="hljs-string">'click'</span>, <span class="hljs-function">() =&gt;</span> playNoteSound(key)); 
});

<span class="hljs-comment">//function to play the sound of key</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">playNoteSound</span>(<span class="hljs-params">key</span>) </span>{
  <span class="hljs-keyword">const</span> noteAudio = <span class="hljs-built_in">document</span>.getElementById(key.dataset.note)
  noteAudio.currentTime = <span class="hljs-number">0</span>;
  noteAudio.play();
  key.classList.add(<span class="hljs-string">'active'</span>);
  noteAudio.addEventListener(<span class="hljs-string">'ended'</span>, <span class="hljs-function">() =&gt;</span> {
    key.classList.remove(<span class="hljs-string">'active'</span>);
  })
}
</code></pre><p>This would get you going with clicking the keys. However, it is ideal to have the keys from keyboard mapped to the piano keys. Hence, we can add another event listener for 'keydown' and play the respective sounds. We need to define the keys for the white keys and black keys of the piano, as shown in the below snippet.</p>
<pre><code><span class="hljs-keyword">const</span> WHITE_KEYS = [<span class="hljs-string">'z'</span>, <span class="hljs-string">'x'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'v'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'n'</span>, <span class="hljs-string">'m'</span>];
<span class="hljs-keyword">const</span> BLACK_KEYS = [<span class="hljs-string">'s'</span>, <span class="hljs-string">'d'</span>, <span class="hljs-string">'g'</span>, <span class="hljs-string">'h'</span>, <span class="hljs-string">'j'</span>];

<span class="hljs-keyword">const</span> whiteKeys = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">'.key.white'</span>);
<span class="hljs-keyword">const</span> blackKeys = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">'.key.black'</span>);

<span class="hljs-comment">//adding event listener for key down from keyboard</span>
<span class="hljs-built_in">document</span>.addEventListener(<span class="hljs-string">'keydown'</span>, <span class="hljs-function"><span class="hljs-params">e</span> =&gt;</span> {
    <span class="hljs-keyword">if</span> (e.repeat) <span class="hljs-keyword">return</span>;
    <span class="hljs-keyword">const</span> key = e.key;
    <span class="hljs-keyword">const</span> whiteKeyIndex = WHITE_KEYS.indexOf(key);
    <span class="hljs-keyword">const</span> blackKeyIndex = BLACK_KEYS.indexOf(key);

    <span class="hljs-keyword">if</span> (whiteKeyIndex &gt; <span class="hljs-number">-1</span>) playNoteSound(whiteKeys[whiteKeyIndex]);
    <span class="hljs-keyword">if</span> (blackKeyIndex &gt; <span class="hljs-number">-1</span>) playNoteSound(blackKeys[blackKeyIndex]);
  })
</code></pre><p>Try it for yourself and have fun. I hope this was helpful. Thank you! Happy learning. </p>
]]></content:encoded></item><item><title><![CDATA[10 git commands that I use on a daily base.]]></title><description><![CDATA[Are you a software developer? If so, I am sure you know about the version control tool git. For those who have heard of Git but are not sure what is it and why we need to learn it, Git is a version control tool used to keep the version history of our...]]></description><link>https://www.shravaniroy.in/10-git-commands-that-i-use-on-a-daily-base</link><guid isPermaLink="true">https://www.shravaniroy.in/10-git-commands-that-i-use-on-a-daily-base</guid><category><![CDATA[Git]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[version control]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Sat, 08 Oct 2022 18:25:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689830937976/00f24805-60f8-4eed-935e-5a1cf544e065.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Are you a software developer? If so, I am sure you know about the version control tool git. For those who have heard of Git but are not sure what is it and why we need to learn it, Git is a version control tool used to keep the version history of our applications. It just doesn't help in saving the history of various versions of the code that we have committed(deployed), but it provides a lot of features to play around with these versions. Most disastrous production glitches in applications could be resolved by restoring previous versions, all thanks to git. It is also popular for the collaborative feature, where multiple developers can contribute to the project(application) without worrying about code conflicts. Today, we would know some popular git commands that you must know as a software developer.</p>
<h3 id="heading-1-git-init">1. git init</h3>
<p>When you want to create a new project on your local machine, you could create it using boilerplates available that can be installed using any package manager like 'npm' or 'yarn'. And when you decide to have version control for the project, you will need to initialize an empty git file onto this project. This ideally starts reading the changes in the project as you start making them and keeps these changes ready to be staged. The command to be used here is :</p>
<pre><code class="lang-python">git init
</code></pre>
<p>This would give a message as, ***'Initialized empty Git repository in C:/users/shravaniroy/desktop/newProject'</p>
<hr />
<p>If you have git already initialized earlier in your project, it would give the same message pointing to the existing git repository.</p>
<h3 id="heading-2-git-clone">2. git clone</h3>
<p>This is the command used to clone an existing Git repository on your local machine. It creates a new directory with all the objects from the remote repository. The default branch it points to is the 'master' branch. Say you want to clone one of my public repositories, where I implemented a web page to display the git jobs using Git's open API. You can find the repository <a target="_blank" href="https://github.com/ShravaniRoy/recreategitjobs.git">here</a>. Here is the command to clone the above repository.</p>
<pre><code class="lang-python">git clone https://github.com/ShravaniRoy/recreategitjobs.git
</code></pre>
<p>The above command creates a new directory in the directory where you have opened the command prompt to run the above code. From here onwards, we have to navigate to the new directory to run the below commands.</p>
<h3 id="heading-3-git-status">3. git status</h3>
<p>This command is used to check the list of files that have changes in the project. These changes could be anything, could be a small change in an existing file to adding a new file in the project. As you make these changes in the project, you will observe that the existing files are marked as M (Modified) and new files added are marked as U (Untracked). However, the node modules are excluded from the tracking by default. This is set in the .gitignore file. You could add more rules to this file to control what is to be tracked and which files to be ignored. Here is an example of how it displays these changes.</p>
<pre><code class="lang-python">git status

On branch master
Your branch <span class="hljs-keyword">is</span> up-to-date <span class="hljs-keyword">with</span> <span class="hljs-string">'origin/master'</span>.
Changes to be committed:
    (Use <span class="hljs-string">'git reset HEAD &lt;file&gt;...'</span> to unstage)

             modified: index.html
             modified: css/styles.pcss
</code></pre>
<h3 id="heading-4-git-checkout">4. git checkout</h3>
<p>Usually, in any real-time project development, it is suggested to maintain different branches. You can either have different branches for different features or have a different branch for every individual contributor. You can prefer to go with the former approach when there are limited contributors. Perhaps, it usually depends on the architect/lead. To create a new branch based on an existing branch, we use the following command.</p>
<pre><code class="lang-python">git checkout -b &lt;yourNewBranch&gt; &lt;existingBranch&gt;
//example <span class="hljs-number">1</span>:
git checkout -b productsFeature master
//example <span class="hljs-number">2</span>:
git checkout -b productionDefectFixes prod/v1<span class="hljs-number">.0</span><span class="hljs-number">.2</span>
</code></pre>
<p>If you have observed, I have named the branches for the purpose of creating them. I can't emphasize enough the importance of naming conventions throughout the developer journey. One more thing about the above command is that it not only creates a new branch but also switches to that branch. So you might have guessed it right that the same command is used to switch between branches. And in order to know which branch are you currently working on amongst all the branches you have on your local machine - use 'git branch' command. Let me show you how it displays that below.</p>
<pre><code class="lang-python">git branch //our command
*master
productsFeature
git checkout productsFeature //command
Switched to productsFeature
</code></pre>
<p>I use Visual Studio Code for work and I have observed that at times there is a delay in the changes that we make reflected in VSCode. Hence, I make sure to check the branch by using 'git branch', before I make any commits. We will know more about commits in the next section of this blog.</p>
<h3 id="heading-5-git-add">5. git add</h3>
<p>Most of these Git options are available as inbuilt features in most of the IDEs. Be it VS Code or Eclipse or any other IDE, have the git commands as features/buttons. I have observed that most developers are used to using these IDE tools instead of direct git commands, which sure makes our lives easy but it is good to know the commands to understand how Git works. Anyways, so this command helps in staging all the changes or the files you choose, to commit. Let us see how.</p>
<pre><code class="lang-python">git add .
//the above command adds all the modified <span class="hljs-keyword">or</span> untracked files to staging
git add package.json
//the above command would stage only package.json amongst all modified files.
</code></pre>
<h3 id="heading-6-git-commit">6. git commit</h3>
<p>During project development, we would have different sprints in which we deliver a feature and while developing a feature pack, we usually work on a daily base and might have to check-in our code every day. So, instead of leaving it to timestamps, it is ideal to have some description of what we have developed for every commit. Hence, the message attribute of the commit command. Commits are like landmarks. Having a descriptive commit is a good practice. It has to be human-understandable. Let us look at a sample below.</p>
<pre><code class="lang-python">git commit -m <span class="hljs-string">"routing setup done"</span>
git commit -m <span class="hljs-string">"defect 321100 - radio button alignment fixed"</span>
git commit -m <span class="hljs-string">"customer session establishment - jira story 123213"</span>
</code></pre>
<p>Like the above commits are understandable that the code that is committed in respective commits refers to setting up routing, fixing defects, and a feature pack. Naming your commits will help you and your team in the long run.</p>
<h3 id="heading-7-git-push">7. git push</h3>
<p>Once you have a few commits(or one commit) that you want to merge to the master/main branch, you can use this command to push your changes to the remote branch and you are ready to raise a PR for merging it into the main branch. We will discuss PRs in a separate blog. Let us see how this 'git push' command works.</p>
<pre><code class="lang-python">git push // <span class="hljs-keyword">from</span> the branch which has been set to upstream earlier.
Enumerating objects: <span class="hljs-number">4</span>, done.
Counting objects: <span class="hljs-number">100</span>% (<span class="hljs-number">4</span>/<span class="hljs-number">4</span>), done.
Writing objects: <span class="hljs-number">100</span>% (<span class="hljs-number">4</span>/<span class="hljs-number">4</span>), <span class="hljs-number">209</span> bytes | <span class="hljs-number">104</span> KiB/s, done.
.
.
.
</code></pre>
<pre><code class="lang-python">//If you are trying to push your local branch <span class="hljs-keyword">for</span> the first time use the below command.
git push --set-upstream origin &lt;yourBranchName&gt;
//you could get a message something like below
Branch <span class="hljs-string">'productsFeature'</span> set up to track remote branch <span class="hljs-string">'productsFeature'</span> <span class="hljs-keyword">from</span> <span class="hljs-string">'origin'</span>
</code></pre>
<h3 id="heading-8-git-fetch">8. git fetch</h3>
<p>This is an awesome command that talks facts. Many times when I was informed that there were changes shipped by other developers in the team, I used to check using 'git status' command. This used to always say that "your branch is up to date with the remote branch from 'origin'.". And then I learned about the command 'git fetch' that reads the changes from the remote repository without actually downloading them. This allows you to read any new remote branch.</p>
<pre><code class="lang-python">git fetch //straight forward
</code></pre>
<h3 id="heading-9-git-pull">9. git pull</h3>
<p>This command is similar to the previous command 'git fetch', differing in reading the remote changes. While 'git fetch' reads the changes from the remote repository and displays the list of changes, 'git pull' on the other hand downloads these. changes onto your local machine. This would show the changes in VS Code. This is ideal in case when you have expected changes, whereas fetch helps in knowing other's changes before you take any further step, mostly in a distributed team that works asynchronously. This is also a straightforward command.</p>
<h3 id="heading-10-git-merge">10. git merge.</h3>
<p>From the above commands, we have learned how to take the latest code on your local machine. However, there are pretty good chances that you and your peer had worked on the same file and have committed to a common branch. In this case, merging the remote branch with your local branch would create conflicts. As VSCode helps in retaining both - your changes and incoming changes, it lets you accept any one of them from each file that has been identified with conflicts. So, resolve them to continue. Let us see some examples of it below.</p>
<pre><code class="lang-python">//Let us say I have made changes <span class="hljs-keyword">in</span> routes.js file adding a route <span class="hljs-keyword">for</span> the products page
//And my teammate had added another route <span class="hljs-keyword">for</span> the checkout page
git branch
*productsFeature
master
git merge origin/master
// this merge command would pull latest code <span class="hljs-keyword">from</span> remote master branch on to local //productsFeature branch
</code></pre>
<h3 id="heading-most-powerful">Most powerful:</h3>
<p>Yes, there is a git command that is extremely powerful and developers try not to get to use it. I used it in my early developer days when I messed up by committing some unwanted or wrong changes. 'git revert' is the command that works on the forward-moving operation that lets you undo changes in a safe mode. When you have a commit that you want to revert, use the command 'git revert' to undo this change without actually deleting the commit. This will for sure create another commit with the changes as reverted, yet it is part of the history and you cannot delete something that happened. It remains in history. To revert the uncommitted changes use 'git reset'. This is a cool command that lets you undo local changes to the state of a Git repo.</p>
<h3 id="heading-bonus">Bonus.</h3>
<ul>
<li>git stash Say you have made some changes in your branch and you have more work to do, yet you have noticed that there are some new changes in the remote branch. In order to pull the latest changes, Git wouldn't allow you to do so without committing your local changes. Perhaps, your changes might not be as major as they could be marked as a commit. Don't worry there is a space in Git that lets you park these changes without committing but stashing them. It is of type stack. So, you could either stash your changes with a name/tag or just stash them without any tag. This allows you to park the changes and lets you get them back by popping them from the stack.</li>
</ul>
<pre><code class="lang-python">git stash
git pull
//resolve conflicts <span class="hljs-keyword">if</span> any 
git stash pop
</code></pre>
<p>This is a great tool when you want to switch between branches. There could be days when you might have to juggle between features based on shuffling priorities from the business.</p>
<ul>
<li>git worktree This is the most powerful tool that Git offers to developers. Ever since I learned this command, I feel so skilled. I can now compare two branches without having to switch between them. You can add n number of branches to the existing worktree and when done with your work, you can remove those branches from the worktree. Let me show you how.</li>
</ul>
<pre><code class="lang-python">git branch
*productsFeature
cart
master
// syntax - git worktree add &lt;path <span class="hljs-keyword">and</span> branch&gt;
git worktree add ../cartBranch
//When you want to remove a branch <span class="hljs-keyword">from</span> current worktree
git worktree list //this <span class="hljs-keyword">is</span> to check the list of branches you have on the current worktree.
git remove ../cartBranch
</code></pre>
<p>You could do a lot more using different attributes of these Git commands. There are many more commands, I just listed those I use often. I recommend you learn more from the official documentation of Git.</p>
<p>I hope this was helpful. Thank you. Happy learning!</p>
]]></content:encoded></item><item><title><![CDATA[Date - An important module of javascript.]]></title><description><![CDATA[Everything in real-time deals with timestamps and there is a maximum chance that you could resolve a problem using timestamps. Starting from bank transactions, appointments,  check-in/checkout time, and whatnot. So, javascript provides an inbuilt Dat...]]></description><link>https://www.shravaniroy.in/date-an-important-module-of-javascript</link><guid isPermaLink="true">https://www.shravaniroy.in/date-an-important-module-of-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ecmascript]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[Developer]]></category><category><![CDATA[software development]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Fri, 07 Oct 2022 11:58:13 GMT</pubDate><content:encoded><![CDATA[<p>Everything in real-time deals with timestamps and there is a maximum chance that you could resolve a problem using timestamps. Starting from bank transactions, appointments,  check-in/checkout time, and whatnot. So, javascript provides an inbuilt Date prototype, which could be used to manipulate the Date objects and play around to get the required output. This blog is to focus on the various methods of a Date object, available that are used on a day-to-day basis in developing projects. Let us get started.</p>
<h3 id="heading-creating-a-date-object">Creating a Date object.</h3>
<p>We could create a date object using the new keyword as shown below.</p>
<pre><code><span class="hljs-keyword">const</span> todayDate = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Today's date is "</span>, todayDate);
</code></pre><p>So, from the above code snippet, when the Date() constructor is called, it returns a Date object.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1665141774680/8aI3HXAms.png" alt="Screenshot 2022-10-07 at 4.52.31 PM.png" /></p>
<h3 id="heading-some-of-the-popular-instance-methods">Some of the popular instance methods.</h3>
<p>It totally depends on the requirement of which method to use. Whichever method makes your life easy :)</p>
<ol>
<li>getDate() - returns the day of the month, of the date passed.</li>
<li>getFullYear() - returns the date year in YYYY format, of the date passed</li>
<li>getMonth() - returns the month of the date passed, in numeric format.</li>
<li>getHours() - returns the number of hours of the date passed, according to universal time.</li>
<li>getMinutes() - returns the minutes of the date passed, according to universal time.</li>
<li>getSeconds() - returns the seconds of the date passed, according to universal time.</li>
<li>getMilliSeconds() - returns the milliseconds of the date passed, according to universal time.</li>
</ol>
<p>There are many more instance methods that you can check <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">here</a>.</p>
<p>There are some set methods that could be used to set the date in different formats based on requirements. These set methods are based on local time and the one it was initially created. Let me list a few popular set methods below.</p>
<ol>
<li>setDate()</li>
<li>setUTCDate()</li>
<li>setUTCMilliseconds()</li>
</ol>
<p>Also, I have shared a few methods below, that I have used often in my development journey. </p>
<ol>
<li>toLocaleString() - returns a string with locality-sensitive (reads from system clock) representation of the date. This method accepts some interesting attributes too. </li>
<li>toDateString() - returns the date portion of the date in string format.</li>
<li>toTimeString() - returns the time portion of the date as a string.</li>
<li>toUTCString() - returns the date in string format based on UTC timezone.</li>
</ol>
<p>You might be wondering why we need so many methods to convert date objects into strings of different formats. Well, it makes it easy for us to retrieve human-understandable strings and for developers, it is easy to play/manipulate the strings. </p>
<h3 id="heading-real-time-usecase">Real-time usecase:</h3>
<p>Yesterday, someone reached out to me asking if I could help them solve a date issue in javascript that needs to be passed in Bhoomi. He said that the script would receive the in-time of a student in the class and the duration he has attended the class. The expected output is the out time of the student. This is pretty straight forward right? Well yes, and I gave the below script.</p>
<pre><code><span class="hljs-keyword">const</span> getOutTime = <span class="hljs-function">(<span class="hljs-params">inTime, duration</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> inTimeMS = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(inTime).getTime();
    <span class="hljs-keyword">const</span> durationMS = <span class="hljs-built_in">parseInt</span>(duration) * <span class="hljs-number">60</span> * <span class="hljs-number">60</span> * <span class="hljs-number">1000</span>;
    <span class="hljs-keyword">const</span> outTime = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(inTimeMS + durationMS); <span class="hljs-comment">//this is in MS(milli seconds)</span>
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(outTime).toLocaleString(); 
}

<span class="hljs-keyword">const</span> output = getOutTime(<span class="hljs-string">'9/26/2022 7:20'</span>, <span class="hljs-number">2.5</span>);
<span class="hljs-built_in">console</span>.log(output);
</code></pre><p>Run this on your browser console and pass different arguments to getOutTime() to check the output. I have a couple of other assignments for you for the above function.</p>
<ol>
<li>You could slice the seconds from the output date-time string, and get the format - 'DD/MM/YYYY HH:MM'</li>
<li>Try to set the time of the in-time of students in a specific time-zone with and without using the timeZone attribute of the toLocaleString method.</li>
</ol>
<p>I hope this was helpful. Thank you! Happy learning.</p>
]]></content:encoded></item><item><title><![CDATA[What is Eslint and why do you need it?]]></title><description><![CDATA[Most of you (developers), know Eslint as a VS Code extension for making your code look prettier, generating code suggestions, avoiding bugs, and so on. Yes, Eslint is a great tool to achieve all the above-mentioned functionalities. There is much more...]]></description><link>https://www.shravaniroy.in/what-is-eslint-and-why-do-you-need-it</link><guid isPermaLink="true">https://www.shravaniroy.in/what-is-eslint-and-why-do-you-need-it</guid><category><![CDATA[eslint]]></category><category><![CDATA[ecmascript]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[ES6]]></category><dc:creator><![CDATA[Shravani Thirunagari]]></dc:creator><pubDate>Tue, 04 Oct 2022 10:54:59 GMT</pubDate><content:encoded><![CDATA[<p>Most of you (developers), know Eslint as a VS Code extension for making your code look prettier, generating code suggestions, avoiding bugs, and so on. Yes, Eslint is a great tool to achieve all the above-mentioned functionalities. There is much more that you can control on how to use it for your project. </p>
<h3 id="heading-how-does-it-work">How does it work?</h3>
<p>Eslint is a linter for ECMAScript. It parses raw code into Abstract Syntax Tree. And this is used for forming the lint rules. Having said that, it is flexible and configurable. You can either install it as a node package in your project or as an extension on your IDE. </p>
<h3 id="heading-how-can-we-configure-eslint-for-our-project">How can we configure Eslint for our project?</h3>
<p>There are multiple ways in configuring the Eslint for our project. Using YAML files, JSON files, or js files. In my case, I found this configuration in a work project and then explored the same to understand it better. Install eslint using npm or yarn, any package manager, and define a configuration file. Create an eslintrc.js or eslintrc.json or eslintrc.yaml file to write your rules. A basic JSON configuration file looks something like the one below.</p>
<pre><code><span class="hljs-built_in">module</span>.exports = {
    <span class="hljs-string">"extends"</span>: <span class="hljs-string">"eslint:recommended"</span>,
    <span class="hljs-string">"rules"</span>: {
        <span class="hljs-comment">// enable additional rules</span>
        <span class="hljs-string">"indent"</span>: [<span class="hljs-string">"error"</span>, <span class="hljs-number">4</span>],
        <span class="hljs-string">"linebreak-style"</span>: [<span class="hljs-string">"error"</span>, <span class="hljs-string">"unix"</span>],
        <span class="hljs-string">"quotes"</span>: [<span class="hljs-string">"error"</span>, <span class="hljs-string">"double"</span>],

    }
}
</code></pre><h3 id="heading-example-use-case">Example Use Case :</h3>
<p>For react projects that use react above v17, eslint is added as a dependency. Hence it yells at us saying that the <strong><em>'React' must be in scope when using JSX</em></strong> . This message has led me to learn more about eslint. I wasn't writing my Browser Router in JSX in first place and it took about 15 minutes for me to understand that this was optional and that I could avoid this bug by simply switching off some rules in eslint. In order to do that, navigate to node-modules in your IDE(V S Code in my case). Find the 'eslint-config-react-app' module and open its index.js file. Here you would find some rules with respect to how it is configured for the current react project. Switch off the below rules to avoid the above-highlighted error.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1664876386514/Y9tHjTdUz.png" alt="Screenshot 2022-10-04 at 3.01.24 PM.png" /></p>
<p>I found this interesting article about creating your own custom eslint config package <a href="https://www.freecodecamp.org/news/creating-your-own-eslint-config-package/">here</a>.</p>
<p>Refer to the official <a href="https://eslint.org/docs/latest/user-guide">documentation</a> to learn more and explore options to experiment in your project.</p>
<p>I hope this was helpful. Thank you. Happy Learning!</p>
]]></content:encoded></item></channel></rss>