<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rajan Lagah on Medium]]></title>
        <description><![CDATA[Stories by Rajan Lagah on Medium]]></description>
        <link>https://medium.com/@rajanlagah?source=rss-947d0973db51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6lSUXoj6TapjReJwPeGpOQ.png</url>
            <title>Stories by Rajan Lagah on Medium</title>
            <link>https://medium.com/@rajanlagah?source=rss-947d0973db51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:53:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajanlagah/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Easily Integrate AI into Your Website with prompt-my-client-react]]></title>
            <link>https://rajanlagah.medium.com/easily-integrate-ai-into-your-website-with-prompt-my-client-react-464afb72f45b?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/464afb72f45b</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[npm-package]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[prompt]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Sun, 31 Aug 2025 16:25:04 GMT</pubDate>
            <atom:updated>2025-08-31T16:26:42.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ml0hxp5MOg98FF-sSdNVLQ.png" /><figcaption>Minimal UI showcasing usePrompt hook</figcaption></figure><p>Artificial Intelligence is no longer just for big tech companies — it’s now accessible to anyone building websites or apps. Imagine letting your users <strong>enhance their writing, rephrase text, or even translate content</strong> — all without leaving your application.</p><p>Thanks to the <a href="https://www.npmjs.com/package/prompt-my-client-react?utm_source=chatgpt.com">prompt-my-client-react</a> package, you can integrate AI into your React app in <strong>just a few lines of code</strong>. No need to reinvent the wheel—the package comes with pre-built UI components and hooks to handle AI prompts seamlessly.</p><p>Live demos <a href="https://promptmyclient.vercel.app/demos">https://promptmyclient.vercel.app/demos</a></p><h3>🌟 What Is prompt-my-client-react?</h3><p>✅ Transform text (make it concise, professional, or casual).<br> ✅ Translate content between languages.<br> ✅ Drop in an AI-powered <strong>text dropdown</strong> without building UI from scratch.<br> ✅ Use the <strong>usePrompt hook</strong> for programmatic control.<br> ✅ Customize everything—from prompts to styling.</p><h3>⚡ Installation</h3><p>Getting started takes less than a minute. Just install it with npm or yarn:</p><pre>npm install prompt-my-client-react</pre><p>or</p><pre>yarn add prompt-my-client-react</pre><h3>🧑‍💻 Example 1: Using the usePrompt Hook</h3><p>The usePrompt hook gives you full programmatic control. Here’s a quick example:</p><pre>import React, { useState } from &#39;react&#39;;<br>import { usePrompt } from &#39;prompt-my-client-react&#39;;<br>function App() {<br>  const [input, setInput] = useState(&#39;&#39;);<br>  const { generatePrompt, isLoading, error, result } = usePrompt({<br>    onSuccess: (response) =&gt; {<br>      setInput(response);<br>      console.log(&#39;AI Response:&#39;, response);<br>    },<br>    onError: (error) =&gt; {<br>      console.error(&#39;Error:&#39;, error);<br>    }<br>  });<br>  const handleGenerate = async () =&gt; {<br>    await generatePrompt(<br>      input,<br>      &quot;Make this text more professional and concise&quot;,<br>      &quot;professional&quot;,<br>      &quot;concise&quot;<br>    );<br>  };<br>  return (<br>    &lt;div&gt;<br>      &lt;textarea<br>        value={input}<br>        onChange={(e) =&gt; setInput(e.target.value)}<br>        placeholder=&quot;Type your text here...&quot;<br>      /&gt;<br>      &lt;button onClick={handleGenerate} disabled={isLoading}&gt;<br>        {isLoading ? &#39;Processing...&#39; : &#39;Make Professional&#39;}<br>      &lt;/button&gt;<br>      {error &amp;&amp; &lt;p&gt;Error: {error}&lt;/p&gt;}<br>      {result &amp;&amp; &lt;p&gt;Result: {result}&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>👉 Here, the user types text, clicks <strong>“Make Professional”</strong>, and instantly gets an AI-transformed version.</p><h3>🎨 Example 2: Using the AIDropDown Component</h3><p>Don’t want to build UI yourself? The package gives you a <strong>ready-to-use dropdown</strong>:</p><pre>import React, { useState, useRef, useEffect } from &#39;react&#39;;<br>import { AIDropDown } from &#39;prompt-my-client-react&#39;;<br>function App() {<br>  const [input, setInput] = useState(&#39;&#39;);<br>  const textareaRef = useRef(null);<br>  useEffect(() =&gt; {<br>    if (textareaRef.current) {<br>      textareaRef.current.style.height = &#39;auto&#39;;<br>      textareaRef.current.style.height = textareaRef.current.scrollHeight + &#39;px&#39;;<br>    }<br>  }, [input]);<br>  const handleAIResponse = (response) =&gt; {<br>    if (response) setInput(response);<br>    console.log(&quot;AI Response:&quot;, response);<br>  };<br>  return (<br>    &lt;div&gt;<br>      &lt;textarea<br>        ref={textareaRef}<br>        value={input}<br>        onChange={(e) =&gt; setInput(e.target.value)}<br>        placeholder=&quot;Type your text here...&quot;<br>      /&gt;<br>      &lt;AIDropDown<br>        text={input}<br>        aiResponseCallback={handleAIResponse}<br>      /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>✨ Now your users can highlight text, pick an AI action from the dropdown, and see instant results.</p><h3>🎯 Why Use prompt-my-client-react?</h3><ul><li><strong>⚡ Fast Setup</strong>: Drop in a component or hook and you’re live.</li><li><strong>📦 Pre-built UI</strong>: Save time with ready-made dropdowns.</li><li><strong>🎛️ Customizable</strong>: Change prompts, styles, and behavior to fit your app.</li><li><strong>🌍 Multiple Use Cases</strong>: Blogging tools, e-commerce product descriptions, chat apps, internal documentation editors, and more.</li></ul><h3>💡 Real-World Use Cases</h3><p>Here are a few ideas for how you might use it in your project:</p><ul><li>📝 <strong>Content Editing</strong> → Let users refine blog posts or comments.</li><li>🌍 <strong>Language Conversion</strong> → Add translation capabilities for global reach.</li><li>🛒 <strong>E-commerce</strong> → Generate engaging product descriptions.</li><li>👨‍💼 <strong>Internal Tools</strong> → Summarize or polish meeting notes.</li></ul><h3>🚀 Conclusion</h3><p>Integrating AI into your website doesn’t have to be complicated. With prompt-my-client-react, you can <strong>add AI-driven text enhancement in minutes</strong>, giving your users powerful tools while keeping your development workflow smooth.</p><p>If you’re building a React app and want to make it smarter, give <a href="https://promptmyclient.vercel.app/?utm_source=chatgpt.com">prompt-my-client-react</a> a try.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=464afb72f45b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang vs Nodejs ( benchmarking )]]></title>
            <link>https://rajanlagah.medium.com/golang-vs-nodejs-benchmarking-bb260d9f9cde?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb260d9f9cde</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[udemy]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Sat, 08 Mar 2025 18:52:37 GMT</pubDate>
            <atom:updated>2025-03-08T18:52:37.489Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*AAbt6IJoSRVUwXPE.jpg" /></figure><p>In this blog, we will be load-testing the NodeJS and GO servers and learning about resource usage to understand the best use case for each language.</p><h4><strong>Baseline</strong></h4><ul><li>We will be using AWS t3.micro instance</li><li>API call performs simple GET requests with <br>Select title,content,createdAt from tasks;</li><li>hey CLI tool for testing</li><li>Code deployed to AWS Beanstalk</li><li>Database RDS ( Same database connected to both )</li></ul><h4><strong>Case 1</strong></h4><p>More requests per person. <br><strong>Example:-</strong> Stock Market Tracking Apps, Logging<br>- Number of users = 500<br>- Number of requests = 2000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*605p-O98ULAgkJQ7kYPbsA.png" /></figure><p>Go is the clear winner here. It took only 1 sec for the Go server and 2.3 sec for the NodeJS server. Moreover, the slowest response time in GO is the fastest response time in NodeJS. So it&#39;s clear if you are making apps where single user is making multiple requests then GO is a Good choice.</p><h3>Test 2</h3><p>Medium traffic <br>- Number of users = 100<br>- Number of requests = 1000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1cNDOv9g19y79sbGNeNKw.png" /></figure><p><strong>Example:-</strong> Analytical Dashboards.</p><p>GO server outperforms the NodeJS app again. So Going with GO is good choice but if you already have JS techstack then you can consider NodeJS as it will be easy to maintain for you.</p><h3>Test 3</h3><p>Less traffic <br>- Number of users = 40<br>- Number of requests = 500</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xextdxy_qAe1_tw8jLCnbA.png" /></figure><p><strong>Example:-</strong> No heavy real-time updates. Blogging &amp; Forums</p><p>Surprisingly NodeJS is much better for fewer users and high-activity apps. But keep in mind if traffic grows it can reduce the performance of app.</p><p><strong>Resource utilization</strong></p><p>Let’s track the resource utilization for both the servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dO4jW9XEhcsgS7geTLoKdg.png" /><figcaption>NodeJS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZxJ5o-U7kLiTGaVfJ4nA3Q.png" /><figcaption>GO Lang</figcaption></figure><p>NodeJS took more resources slightly and this reflects that GO is lightweight and efficient as compared to NodeJS because NodeJS uses V8 engine ( or some other engine ) but GO is compiled to machine binary.</p><h3>Fun part ( breaking the server )</h3><p>Monster test on t3.Micro<br>- Number of users = 1000<br>- Number of requests = 2000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MngeoJi9_zWqEsBU1hGjjA.png" /></figure><p>15 requests failed on NodeJS where as GO server handled the load efficiently.</p><p>This blog showcases Go’s exceptional ability to handle high loads efficiently while consuming fewer resources than other languages. With Go, you can reduce server costs, scale effortlessly, and improve application performance — all while keeping your cloud bills lower.</p><h3>Conclusion</h3><p>Go isn’t just powerful — it’s also in demand! Companies are actively hiring Go developers, and Go-related jobs offer some of the highest salaries in the industry.</p><p>Want to master Go and unlock high-paying opportunities? Check out my Udemy course:<br>👉 <a href="https://www.udemy.com/course/go-web-development-create-powerful-servers-with-golang/?referralCode=EA9B71B7323D2C5D1071">Go Web Development: Create Powerful Servers with Golang</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb260d9f9cde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What exactly is an XSS attack?]]></title>
            <link>https://blog.stackademic.com/what-exactly-is-xss-attack-076fa82553a6?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/076fa82553a6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Sun, 04 Aug 2024 07:16:46 GMT</pubDate>
            <atom:updated>2024-08-06T05:43:25.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bf7aXU3O8C9egxARanHEfw.png" /></figure><p>XSS attack means <strong>Cross-site scripting 😝</strong></p><p>No but seriously!</p><p><strong>XSS attacks</strong> when someone injects malicious code into your website. Code that can listen to your key inputs and send them to hackers, code that can make a LinkedIn post on your behalf, or send your cookies to an attacker.</p><p><strong>Stored XSS</strong>:</p><ul><li><strong>Definition</strong>: Malicious script is permanently stored on the target server (e.g., in a database) and executed when users view the stored data.</li></ul><p><strong>Reflected XSS</strong>:</p><ul><li><strong>Definition</strong>: Malicious script is reflected off a web application to the user’s browser via an immediate response, often as part of a URL or form submission.</li></ul><p><strong>DOM-Based XSS</strong>:</p><ul><li><strong>Definition</strong>: Malicious script is executed as a result of modifying the DOM environment in the client-side code without involving the server.</li></ul><p><strong>Self XSS</strong>:</p><ul><li><strong>Definition</strong>: The user is tricked into executing a malicious script in their browser, often through social engineering techniques.</li></ul><p><strong>Blind XSS</strong>:</p><ul><li><strong>Definition</strong>: An attacker injects a payload that is executed in an environment where the attacker does not have direct visibility of the result, typically used against administrators.</li></ul><pre>https://example.com/img%2520src=https://invalid-url%2520onerror=%2522alert(%2527XSS%2527)%2522%2520/%253E&#39;</pre><p>Consider the above example. This URL is taking img in query param and the image tag contains code like</p><pre>&lt;img src=&quot;https://invalid-url&quot; onerror=&#39;alert(&quot;XSS&quot;)&#39;/&gt;</pre><p>now if you are using query params in your code chances are onerror code will get executed and do some serious stuff.</p><h4><strong>How can we prevent it?</strong></h4><p>Most frameworks/libraries will have an inbuilt defense against these kinds of attacks.</p><h4><strong>How does React prevent this attack?</strong></h4><p><strong>No String-based Event Handlers</strong>: Unlike traditional JavaScript where you might use string-based event handlers (e.g element.setAttribute(&#39;onclick&#39;, &#39;alert(&quot;XSS&quot;)&#39;)), React does not allow this pattern. Event handlers in React are functions, which prevent the execution of arbitrary strings as code.</p><h4>Insecure Example (Traditional JavaScript):</h4><pre>&lt;button onclick=&quot;alert(&#39;XSS&#39;)&quot;&gt;Click me&lt;/button&gt;</pre><p>Secure Example (React):</p><pre>function handleClick() {<br>  alert(&#39;Button clicked!&#39;);<br>}<br><br>function MyComponent() {<br>  return &lt;button onClick={handleClick}&gt;Click me&lt;/button&gt;;<br>}</pre><p><strong>Preventing Direct DOM Manipulation</strong>: React abstracts away direct DOM manipulation. Instead of directly interacting with the DOM, you work with a virtual DOM. This abstraction reduces the risk of introducing XSS vulnerabilities through unsafe DOM manipulations.</p><h4>Example:</h4><pre>function handleInputChange(event) {<br>  console.log(event.target.value);<br>}<br><br>function MyComponent() {<br>  return &lt;input type=&quot;text&quot; onChange={handleInputChange} /&gt;;<br>}</pre><h4><strong>Summary</strong></h4><p>If you are using a server we can set our app’s header to allow requests from our app to only specific servers. This is the ultimate defense because now information can not be passed to hacker’s servers.</p><p>React provides inbuilt defense against such attacks and auto escape data in jsx but keep in mind never trust the user input and follow the best practices.</p><p>If you learn something new hit 👏 button.</p><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=076fa82553a6" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/what-exactly-is-xss-attack-076fa82553a6">What exactly is an XSS attack?</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend testing]]></title>
            <link>https://rajanlagah.medium.com/frontend-testing-d870de554fc0?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/d870de554fc0</guid>
            <category><![CDATA[e2e-testing]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cypress]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 11:04:03 GMT</pubDate>
            <atom:updated>2024-06-03T11:04:03.141Z</atom:updated>
            <content:encoded><![CDATA[<p>( Everything is in context of ReactJS, next.js or react based technologies )</p><h3>Types of testing</h3><ol><li>Unit testing: For each component write every possible state and then write test to verify it. For example your custom input field will have these and more unit text cases.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fslAgH65aMA-oz36" /></figure><p>2. Integration Testing: You will test bunch of components that are dependent or used together in your website. Example Login form will have</p><ul><li>text input</li><li>Select tag ( for selecting gender )</li><li>Button</li></ul><p>and these will work together to create Form. Now you will write test for every possible state of the form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/0*fnxI4s9L47tXpa8F" /></figure><p>3. E2E testing: Testing journeys like login or onboarding. E2E verify that the application’s components and dependencies, such as databases, networks, and external services, work together correctly.</p><p>4. Visual testing: Detect visual changes and test if its consistent. Tools like Applitools help you detect visual difference bw multiple branches</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WOXJfGWwf4le87Hg" /></figure><p>Why is visual testing important?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ptxFNcfQuSYplnVe" /></figure><p>Now look, Our tests will pass even if the UI is broken. If we had tests for, if text is rendered or heart icon is not clicked etc, they will pass but still if we see for human its not readable or usable. So to test the visual appearance we do visual testing.</p><h3>From where should we start?</h3><p>In my opinion we first guarantee core business logic. For every change that is deployed we should run test upon our core feature and they should we working e2e. It should be the starting point and bonus is e2e testing take least amount of time as compare to other unit and integration testing.</p><h3>Getting started with E2E</h3><p>Cypress is very mature tool that we can use to test our web apps. It offers great community and features like</p><ul><li>Same syntax that is used in chai/mocha etc.</li><li>Cross browser testing</li><li>timeline feature same like Redux that help debug your test cases</li><li>Easy integration with visual testing tools.</li></ul><p>After installing cypress we generally use these 2 commands the most.</p><ol><li>To run test in browser</li></ol><pre>npx cypress open</pre><p>2. To run tests in CI/CD.</p><pre>npx cypress run</pre><h3>Basic functions</h3><ol><li>cy.visit(url): Visit cmd will tell cypress to open specific page for which we want to add test cases.</li><li>cy.get(): Get cmd will return component of your website. For example</li></ol><pre>cy.get(&#39;.input&#39;) // will return html element/s with class input<br>cy.get(&#39;#submit-btn&#39;) // will return html element with class submit btn<br>cy.get(&#39;[data-testid=&quot;login-heading&quot;]&#39;) // will return html element with attribute data-testid as login-heading</pre><p>using class name or id is bad practice for testing. Instead standard practice is to use data-testid attribute.</p><p>3. should: assertion command used to assert that a specified condition or state is met.</p><pre>cy.get(&#39;#submit-button&#39;).should(&#39;be.visible&#39;);<br>cy.get(&#39;#submit-button&#39;).should(&#39;disabled&#39;);</pre><p>4. click: CMD to click HTML</p><pre>cy.get(&#39;#submit-button&#39;).should(&#39;exist&#39;).click()</pre><p>5. type: It mimic user typing.</p><pre>cy.get(&#39;[data-testid=&quot;email-input&quot;]&#39;).should(&#39;exist&#39;).type(&#39;rajanlagah@gmail.com&#39;)</pre><p>6. intercept: This cmd will intercept API call going out from FE and return the desired response.</p><pre>describe(&#39;Intercepting GET Requests&#39;, () =&gt; {<br>  it(&#39;should intercept and mock a GET request&#39;, () =&gt; {<br>    cy.intercept(&#39;GET&#39;, &#39;/api/users&#39;, {<br>      statusCode: 200,<br>      body: { users: [{ id: 1, name: &#39;John Doe&#39; }] },<br>    }).as(&#39;getUsers&#39;);</pre><pre>    cy.visit(&#39;/users&#39;);</pre><pre>    cy.wait(&#39;@getUsers&#39;).its(&#39;response.body&#39;).should(&#39;have.property&#39;, &#39;users&#39;);<br>    cy.get(&#39;.user&#39;).should(&#39;contain&#39;, &#39;John Doe&#39;);<br>  });<br>});</pre><h3>Advance concepts</h3><ol><li>Fixtures: So you want to store response outside the test file to maintain it properly. Cypress has got your back. Fixtures are used to store json</li></ol><pre>// cypress/fixtures/newUser.json<br>{<br>  &quot;id&quot;: 3,<br>  &quot;name&quot;: &quot;Alice Johnson&quot;<br>}</pre><pre>// cypress/integration/post_request_with_fixture_spec.js<br>describe(&#39;Intercepting POST Requests with Fixtures&#39;, () =&gt; {<br>  it(&#39;should intercept and mock a POST request using fixture data&#39;, () =&gt; {<br>    cy.intercept(&#39;POST&#39;, &#39;/api/users&#39;, { fixture: &#39;newUser.json&#39; }).as(&#39;createUser&#39;);</pre><pre>    cy.visit(&#39;/create-user&#39;);<br>    cy.get(&#39;input[name=&quot;name&quot;]&#39;).type(&#39;Alice Johnson&#39;);<br>    cy.get(&#39;button[type=&quot;submit&quot;]&#39;).click();</pre><pre>    cy.wait(&#39;@createUser&#39;).its(&#39;response.body&#39;).should(&#39;include&#39;, { name: &#39;Alice Johnson&#39; });<br>    cy.get(&#39;.user&#39;).should(&#39;contain&#39;, &#39;Alice Johnson&#39;);<br>  });<br>});</pre><p>2. Custom cmds: Tired of writing same long cmds again and again? You can overwrite the cmds as per your convince. For example lets overwrite ‘get’ cmds</p><pre>Cypress.Commands.overwriteQuery(&#39;get&#39;, function newGet(originalFn, ...args) {<br>    let selector = args[0]<br>    if (typeof selector === &#39;string&#39; &amp;&amp; selector.startsWith(&#39;$&#39;)) {<br>        selector = `[data-testid=&quot;${selector.substring(1)}&quot;]`;<br>    }<br>    args[0] = selector<br>    const innerGet = originalFn.apply(this, args)<br>  <br>    return (subject) =&gt; {<br>      return innerGet(subject)<br>    }<br>  })</pre><p>now instead of doing cy.get(‘[data-testid:”submit-btn”]’) we can do shortcut cy.get(‘$submit-btn’). Our logic will replace $ with required thing and format it accordingly.</p><p>3. Accessibility testing: Want to test if your website is ADA compliances compatible? You can use tools like cypress-axe to easily test these things.</p><h3>Naming conventions</h3><pre>describe(&#39;login page&#39;)</pre><p>describe is used to setup the context so make sure to pass the correct context.</p><pre>it(&#39;should logout and render login page&#39;)<br>it(&#39;show error on invalid input&#39;)</pre><p>describe will have multiple it and you should have action -&gt; reaction specified in your it block.</p><pre>data-testid=&quot;login-page__submit-btn--primary&quot;</pre><p>We can use BEM to name all the test ids.</p><p>B -&gt; Block: Here login page is higher-level component.</p><p>E -&gt; Element: Submit btn is the element</p><p>M -&gt; Modifier: Current state of button/version of the element.</p><h3>Conclusion</h3><p>Cypress testing is fun and time consuming. No doubt that it will streamline the process of deployments and provides you with confidence for deploying your websites. But if you are running out of resources then consider adding tests to at-least your core functionality. And when your write test dont forget to fail that test first by messing up with data-testid or state of element, this will ensure that your test will actually break when its required to.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d870de554fc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get JS Interview Ready]]></title>
            <link>https://rajanlagah.medium.com/get-js-interview-ready-6ebce8365322?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ebce8365322</guid>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Tue, 09 Jan 2024 17:59:46 GMT</pubDate>
            <atom:updated>2024-01-12T16:09:36.212Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-imKWYEqci5oMKAdYFTFA.jpeg" /></figure><p>Here I am listing all the JS questions that I have faced in the actual interview. I won&#39;t mention the company name but overall its good to practice or do last-minute preparations.</p><h4>Hoisting</h4><p>I believe you know hoisting diff in var,let and const. But here is tricky question.</p><h4>Lexical Scope</h4><pre>let x = &#39;fog&#39;<br>function first() {<br> console.log(x)<br>}<br>x = &#39;pog&#39;<br>function second(){<br>   let x = &#39;rog&#39;<br>  first()<br>}<br>second()</pre><p>what will be the output? What I thought was for each function execution context is created. Andsecond function first the function is called so execution context will be created inside second and x is not defined inside first a function so it will try to look up in its lexical scope. So based on that, my output was rog</p><p>But that was wrong. Right ans is when function first is getting memory allocated during memory allocation at that time x is pointing to x in global context so it will print value as pog</p><h4>Functions</h4><pre>const obj = {<br>    name: &#39;Object&#39;,<br>    op:{<br>    methodArrow: () =&gt; console.log(this),<br>    methodRegular: function(){console.log(this)}<br>    }<br>};</pre><p>Output?</p><p>Because the arrow function inherits <strong>this</strong> from its lexical scope and for regular function <strong>this</strong> points to where it is called. So output will be</p><pre>window ( window obj)<br>{methodArrow: ƒ, methodRegular: ƒ}</pre><h4>Execution Stack</h4><pre><br>console.log(&quot;start&quot;);<br><br>setTimeout(function() {<br>  console.log(&quot;Timeout 1&quot;);<br>}, 0);<br><br>new Promise(function(resolve, reject) {<br>  console.log(&quot;Promise 1&quot;);<br>  resolve();<br>}).then(function() {<br>  console.log(&quot;Promise 2&quot;);<br>});<br><br>setTimeout(function() {<br>  console.log(&quot;Timeout 2&quot;);<br>}, 0);<br><br>console.log(&quot;End&quot;);</pre><p>what will be the output of the above? Tricky right?</p><pre>start<br>Promise 1<br>End<br>Promise 2<br>Timeout 1<br>Timeout 2</pre><p>We know promise takes high priority as compared to setTimeout so this is what we will get as output.</p><h4>‘this’</h4><p>Q1.</p><pre>let name = &quot;Global Name&quot;;<br><br>function printGlobalName() {<br>  console.log(this.name);<br>}<br><br>// First call - default this is window<br>printGlobalName(); // ?</pre><p>The output will not be “Global Name”, why? Yes, you are right that in a function call, this will refer to window/global obj but each function call has its execution context and gets its copy of window/global obj. That is why it will be undefined.</p><h4>Function implementation</h4><pre>input =&gt; {<br>  field1: 1,<br>  field2: undefined,<br>  field3: &quot;value&quot;,<br>  field4: {<br>    child: &quot;child&quot;,<br>    child4: &quot;child4&quot;,<br>    child2: {<br>      child3: &quot;child2&quot;<br>    }<br>  }<br>};<br><br>output =&gt; {<br>  field1: 1,<br>  field2: undefined,<br>  field3: &quot;value&quot;,<br>  field4.child: &quot;child&quot;,<br>  field4.child2.child3: &quot;child2&quot;,<br>  field4.child4 : &quot;child4&quot;<br>}</pre><pre>let ans = {};<br>function flat(obj, prefix) {<br>  for (let key in obj) {<br>    if (typeof obj[key] == &quot;object&quot;) {<br>      flat(obj[key], prefix ? prefix + &quot;.&quot; + key : key);<br>    } else {<br>      ans[prefix ? prefix + &quot;.&quot; + key : key] = obj[key];<br>    }<br>  }<br>}<br>const target = {<br>  field1: 1,<br>  field2: undefined,<br>  field3: &quot;value&quot;,<br>  field4: {<br>    child: &quot;child&quot;,<br>    child4: &quot;child4&quot;,<br>    child2: {<br>      child3: &quot;child2&quot;<br>    }<br>  }<br>};<br>flat(target)</pre><p>I will keep adding more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ebce8365322" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fix Load time in you React.js app.]]></title>
            <link>https://rajanlagah.medium.com/fix-load-time-in-you-react-js-app-de9887a2ff98?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/de9887a2ff98</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Fri, 05 Jan 2024 20:39:32 GMT</pubDate>
            <atom:updated>2024-01-05T20:39:32.797Z</atom:updated>
            <content:encoded><![CDATA[<p>Does your app take &gt;2 secs to load? Are you sure you have done all that you can do to deliver smooth and fast experience to your client? Keep reading you will get to know more and possibly found something new that can impact your React.js app performance.</p><h4><strong>Network Performance:</strong></h4><p><strong>a. Bundle size: </strong>The first thing your browser do is to load the bundle of your app. Bundle is deliver to browser over network. So if bundle size is high it will take more time to load. But there are some ways in which you can optimize the bundle size.</p><ul><li><strong>Lazy loading:-</strong> Not everyone will visit every page of your website each time they login. So why load full bundle? You can breakdown the main bundle to multiple chunk bundle such that main bundle contain only core files. You can load chunk bundles containing less critical components when they are required. This will optimize the bundle size hence it will be loaded faster.</li><li><strong>Compression:-</strong> Brotli is latest compression technique that is not supported in all browser but its output is &lt; compressed file by gzip. We can check if browser support Brotli if yes then use brotli else gzip.</li><li><strong>Tree shaking:- </strong>In simple words remove dead code from you code. Remove code that you will never use. Bundlers like webpack support this feature.</li></ul><p><strong>b. Http2:-</strong> In http1 multiple request are loaded sequentially if you are fetching multiple resources each will have separate connection and new connection is required that each request has request and response. In http2 it can fetch multiple resources over single connection parallelly.</p><p><strong>c. CDN:-</strong> Utilize a Content Delivery Network (CDN) to distribute static assets closer to users and reduce latency.</p><p><strong>d. Cache:-</strong> Implement caching strategies (e.g., HTTP caching, Service Workers) to store and reuse previously fetched resources.</p><p><strong>e. Optimize Images &amp; Assets:-</strong> Compress and optimize images and assets to reduce file sizes without compromising quality. Use modern image formats (e.g., WebP) and consider using responsive images or lazy loading techniques.</p><h4>Rendering</h4><ul><li><strong>React Profiler:- </strong>It’s cool plugin that give insightful data regarding which component is rendering and how long its taking to render what component. You can use that to detect unwanted re-renders to boost performance.</li><li><strong>Keys:- </strong>Don’t forget to give keys to list item’s that are dynamically render based on array/object value. Key help React.js to detect which component need re-render, add or remove.</li></ul><h4>Animations</h4><p>Animations that are done using CSS are much more performant as compare to animations via JS. Here are few reasons regarding that.</p><ol><li><strong>Main Thread block</strong>:- JS animations block main thread that means high priority tasks will have to wait.</li><li><strong>Layout update:- </strong>Animations that manipulate DOM will trigger recalculation and update of layout which can impact performance.</li><li><strong>GPU:- </strong>CSS animations are GPU accelerated.</li></ol><h4>React.Fragment</h4><p>React has inbuilt HOC called Fragment which they recommend to use when ever multiple items lists are rendered. This is optimized as</p><ol><li><strong>DOM:- </strong>React.Fragment dont create extra node in DOM. It try to avoid that. Which result in less number of DOM nodes and improve performance.</li><li><strong>Styling:- </strong>React.Fragment will avoid possible issues in styling that we can face by extra parent node.</li></ol><p>I will keep adding more whenever I learn new thing that help optimizing react app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de9887a2ff98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debouncing and throttling in JavaScript]]></title>
            <link>https://rajanlagah.medium.com/debouncing-and-throttling-in-javascript-4aba321aa1e?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aba321aa1e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[throttling]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[debouncing]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Thu, 07 Dec 2023 15:07:38 GMT</pubDate>
            <atom:updated>2023-12-07T15:08:34.292Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Debouncing</strong></p><p>When you have to run some heavy function like API call and you want to optimize that function calls. A classic example will be when you search for a product on Amazon or Flipkart it shows you the product suggestions in autofill select dropdown based on value you have entered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*32VkG9yaxfQr5YwetkXnmg.png" /></figure><p>As in the above example, I have typed the word `apple` which is 5 keystrokes. And we don&#39;t want to fire suggestion API 5 times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9JyovFQGmVZ30gKh9iIsQ.png" /></figure><p>As we can see amazon is making api call 3 + 1 ( 1 is when you click on it ).</p><p>This we can achieve by debouncing.</p><p>It will wait for some time after the last keystroke and then run the API function.</p><pre>const functionDelay = 500 // ms<br>let apiCount = 0<br>const apiExample = function () {<br> console.log(&quot;API CALLED&quot;, ++apiCount)<br>}<br>function debouncing(fn, delay) {<br>let timer<br>return function () {<br> clearTimeout(timer)<br>  timer = setTimeout(function () {<br>   fn.apply(this,args)<br>  }, delay)<br> }<br>}<br>const betterApiCall = debouncing(apiExample, functionDelay)</pre><p>The above code is how we can create a debouncing function. We will run betterApiCall the function on input change.</p><p>The logic for debouncing is to create a timeout function that will run the given function and clear the older generated timeout.</p><h4>Throttling</h4><p>Unlike debouncing, which waits for a pause in the events, throttling ensures that a function is executed at a regular interval, limiting the number of times it can be called within a specified period.</p><pre>function throttle(func, delay) {<br>  let isThrottled = false;<br>  <br>  return function() {<br>    if (!isThrottled) {<br>      func.apply(this, arguments);<br>      isThrottled = true;<br>      <br>      setTimeout(() =&gt; {<br>        isThrottled = false;<br>      }, delay);<br>    }<br>  };<br>}<br>function handleCall() {<br>  console.log(&#39;Call!&#39;);<br>  // Your action here<br>}<br>const throttledClick = throttle(handleCall, 1000);<br>throttledClick()<br>throttledClick()<br>throttledClick()</pre><p>Here you will see console will print Call! only once.</p><p>Throttling can be used in places where we want to keep running functions irrespective of the last input. Like <strong>Auto Saving </strong>let’s say you have written 100 words non-stop and then the tab is closed now if implement debouncing and wait for your last keystroke then those 100 words will be lost. But on the other hand as the medium does it will call save API after ‘x’ seconds so minimum data is lost.</p><p>So this is all about Debouncing and Throttling. I hope you have learned something new today.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aba321aa1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build For Shopify.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://rajanlagah.medium.com/build-for-shopify-32e9ee5b842a?source=rss-947d0973db51------2"><img src="https://cdn-images-1.medium.com/max/642/1*tFMRMfVdEDsr6uftYowGTg.png" width="642"></a></p><p class="medium-feed-snippet">Part 1/2 &#x201C;Theme app extension&#x201D;</p><p class="medium-feed-link"><a href="https://rajanlagah.medium.com/build-for-shopify-32e9ee5b842a?source=rss-947d0973db51------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://rajanlagah.medium.com/build-for-shopify-32e9ee5b842a?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/32e9ee5b842a</guid>
            <category><![CDATA[shopify]]></category>
            <category><![CDATA[extension]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 10:26:12 GMT</pubDate>
            <atom:updated>2023-10-28T10:43:21.914Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How a company can make a chatbot from their help articles?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/aimonks/how-a-company-can-make-a-chatbot-from-help-articles-997434f88aba?source=rss-947d0973db51------2"><img src="https://cdn-images-1.medium.com/max/2600/1*TXdIilumkCs7VMTGTDeaJA.png" width="2880"></a></p><p class="medium-feed-snippet">For #SwymHackathon2023 We trained and build our chatbot that has learned from Swym help articles.</p><p class="medium-feed-link"><a href="https://medium.com/aimonks/how-a-company-can-make-a-chatbot-from-help-articles-997434f88aba?source=rss-947d0973db51------2">Continue reading on  . »</a></p></div>]]></description>
            <link>https://medium.com/aimonks/how-a-company-can-make-a-chatbot-from-help-articles-997434f88aba?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/997434f88aba</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[swym]]></category>
            <category><![CDATA[swym-relay]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Sat, 06 May 2023 06:31:40 GMT</pubDate>
            <atom:updated>2023-05-17T11:17:03.036Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Issues with useEffect]]></title>
            <link>https://rajanlagah.medium.com/issues-with-useeffect-9b6a3dc59279?source=rss-947d0973db51------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b6a3dc59279</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Rajan Lagah]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 17:53:40 GMT</pubDate>
            <atom:updated>2022-08-04T17:53:40.442Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are react dev you surely encounter multiple use cases for useEffect. But let me show how useEffect is tricking you all these times.</p><p>You want some function to run when component mounts</p><pre><br>useEffect(() =&gt; …fn() )</pre><p>But now you want function to run when some specific state value is changed</p><pre><br> const [data, setData] = useState(“”);<br> useEffect(() =&gt; {<br>  console.log(“Running useEffect”);<br> }, [data]);</pre><p>our expectation is that this function will run when data is changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kW-5I0Am-El9v5RvAX1nxw.png" /></figure><p>Check this small example.</p><p>Here we can see that useEffect callback ran even if I don’t change data.<br>That is because useEffect will run at least once on component mount.</p><h4><strong>So what is fix here?</strong></h4><p>We all use this to make some api calls and do some critical work and due to this behaviour of useEffect we can face bugs or performance issue.</p><p>So to run it only when data is changed we can.</p><pre><br>import { useState, useEffect, useRef } from “react”;</pre><pre>export function App() {<br> const isMounted = useRef(false);<br> const [data, setData] = useState(“”);<br> <br> useEffect(() =&gt; {<br>  if (isMounted.current) {<br>   console.log(“HERE”);<br>  } else {<br>   isMounted.current = true;<br>  }<br> }, [data]);<br> <br> return (<br> &lt;div&gt;<br>  &lt;input<br>   onChange={(e) =&gt; setData(e.target.value)}<br>   placeholder=”First name”<br>  /&gt;<br>  &lt;/div&gt;<br> );<br>}<br></pre><p>Now in the console you will not see HERE on mount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REaWmbUIntOCdi5WYXZLKA.png" /></figure><p>Notice here we are using useRef specifically so that on re-render value of isMounted persist else with simple js variable it will keep reseting on every mount.</p><p>Hit like if you have learned something awesome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b6a3dc59279" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>