<?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[Adarsh Konchady's Blog]]></title><description><![CDATA[Adarsh Konchady's Blog]]></description><link>https://blog.adarshkonchady.com</link><generator>RSS for Node</generator><lastBuildDate>Tue, 09 Jun 2026 12:34:09 GMT</lastBuildDate><atom:link href="https://blog.adarshkonchady.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Unlock YouTube: Effortless Video Downloads with yt-dlp]]></title><description><![CDATA[Use the following script to download videos from YouTube using yt-dlp. Incorporating cookies-from-browser can assist in downloading videos that are behind a paywall, provided you have already paid for that content. Please ensure you adhere to the con...]]></description><link>https://blog.adarshkonchady.com/unlock-youtube-effortless-video-downloads-with-yt-dlp</link><guid isPermaLink="true">https://blog.adarshkonchady.com/unlock-youtube-effortless-video-downloads-with-yt-dlp</guid><category><![CDATA[youtube]]></category><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Mon, 09 Feb 2026 06:40:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/NmGzVG5Wsg8/upload/f38b26a745a0731d1773c2bf8a028545.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Use the following script to download videos from YouTube using yt-dlp. Incorporating <code>cookies-from-browser</code> can assist in downloading videos that are behind a paywall, provided you have already paid for that content. Please ensure you adhere to the content guidelines.</p>
<pre><code class="lang-plaintext">yt-dlp --cookies-from-browser chrome --remote-components ejs:github --js-runtimes -f "YouTube_URL" --download-sections "*10:32:01-10:54:45"
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Fixing autocomplete issues with Typescript in VScode]]></title><description><![CDATA[I ran into an issue recently where my autocomplete suggestions on VSCode would only bring up Emmet suggestions and none of the type information would be suggested in autocomplete.
After digging through VSCode settings for a bit, figured out that you ...]]></description><link>https://blog.adarshkonchady.com/fixing-autocomplete-issues-with-typescript-in-vscode</link><guid isPermaLink="true">https://blog.adarshkonchady.com/fixing-autocomplete-issues-with-typescript-in-vscode</guid><category><![CDATA[vscode]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Fri, 03 Nov 2023 03:42:45 GMT</pubDate><content:encoded><![CDATA[<p>I ran into an issue recently where my autocomplete suggestions on VSCode would only bring up Emmet suggestions and none of the type information would be suggested in autocomplete.</p>
<p>After digging through VSCode settings for a bit, figured out that you can enable the following settings to fix this issue:</p>
<ul>
<li><p>Press <code>Cmd + ,</code> to enter VSCode settings</p>
</li>
<li><p>Search for <code>autocomplete</code></p>
</li>
<li><p>Enable <code>Typescript &gt; Suggest:Enabled</code></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1698982918163/c63f2dd9-6868-44f6-895f-f23ca068097f.png" alt class="image--center mx-auto" /></p>
<p>Cheers!</p>
]]></content:encoded></item><item><title><![CDATA[Fixing VSCode issues with ESLint on Nx monorepo]]></title><description><![CDATA[I recently set up an Nx monorepo with a lot of sensible defaults. My linting config was working perfect in CI. Running ESLint on terminal through Nx would work fine as well but I was not seeing any ESLint issues on my VSCode editor.
On digging deeper...]]></description><link>https://blog.adarshkonchady.com/fixing-vscode-issues-with-eslint-on-nx-monorepo</link><guid isPermaLink="true">https://blog.adarshkonchady.com/fixing-vscode-issues-with-eslint-on-nx-monorepo</guid><category><![CDATA[VSCode Tips]]></category><category><![CDATA[vscode extensions]]></category><category><![CDATA[Nx]]></category><category><![CDATA[nx-workspace]]></category><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Thu, 12 Oct 2023 05:50:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/m6tAqZvy4RM/upload/a02f10538848d1649436fc3770b9abae.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I recently set up an Nx monorepo with a lot of sensible defaults. My linting config was working perfect in CI. Running ESLint on terminal through Nx would work fine as well but I was not seeing any ESLint issues on my VSCode editor.</p>
<p>On digging deeper, turns out we need to manually specify the working directories within an Nx monorepo correctly for VSCode to pick up the changes. This is as of Oct 12, 2023.</p>
<p>If you run into a similar issue, the first thing to check would be to</p>
<ul>
<li><p>hit <code>Cmd+shift+p</code></p>
</li>
<li><p>Type <code>ESLint: show output channel</code> and click that option</p>
</li>
</ul>
<p>and make sure you don't see any errors on the terminal that pops up. In my case, the ESLint output channel was complaining about a missing node module within the ESLint flat config. Adding the dependency got rid of that issue.</p>
<p>The next step was to make VSCode aware of the Nx monorepo setup. This can be fixed by opening your VSCode settings.json file. If you're working in a team and need to ensure everyone gets the setup that you do, you can</p>
<ul>
<li><p>create <code>.vscode/settings.json</code> file in your Nx monorepo</p>
</li>
<li><p>Add the following config to list each app/package within your monorepo.</p>
</li>
</ul>
<pre><code class="lang-json">{
  <span class="hljs-attr">"eslint.workingDirectories"</span>: [
    { <span class="hljs-attr">"pattern"</span>: <span class="hljs-string">"./apps/*/"</span> }, 
    { <span class="hljs-attr">"pattern"</span>: <span class="hljs-string">"./packages/*/"</span> }
  ]
}
</code></pre>
<blockquote>
<p>Find docs here - <a target="_blank" href="https://github.com/microsoft/vscode-eslint#settings-options">https://github.com/microsoft/vscode-eslint#settings-options</a></p>
</blockquote>
<p>After making this change,</p>
<ul>
<li><p>hit <code>Cmd+shift+p</code></p>
</li>
<li><p>Type <code>ESLint: Restart ESLint server</code> and click that option.</p>
</li>
</ul>
<p>That's it! Your Nx monorepos app and package level warnings/errors should now show up within VSCode as you open files. Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Supercharge Localhost Security with Caddy Server & NextJS]]></title><description><![CDATA[Intro
Setting up a NextJS project is exciting, but securing the localhost environment for testing and development can be challenging. To enable a common usecase of accessing cookies from the production domain (e.g., example.com) while working locally...]]></description><link>https://blog.adarshkonchady.com/supercharge-localhost-security-with-caddy-server-nextjs</link><guid isPermaLink="true">https://blog.adarshkonchady.com/supercharge-localhost-security-with-caddy-server-nextjs</guid><category><![CDATA[Caddy]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Next.js]]></category><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Tue, 18 Jul 2023 04:24:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/ox72sUdwbEA/upload/8263628948ac956af397ffdb733db655.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-intro">Intro</h2>
<p>Setting up a NextJS project is exciting, but securing the <a target="_blank" href="http://localhost">localhost</a> environment for testing and development can be challenging. To enable a common usecase of accessing cookies from the production domain (e.g., <a target="_blank" href="http://example.com">example.com</a>) while working locally, a specific domain setup like <a target="_blank" href="http://localhost.example.com">localhost.example.com</a> is needed. This integration streamlines development and ensures seamless functionality within a secure <a target="_blank" href="http://localhost">localhost</a> environment.</p>
<p>To be honest, there's nothing other than 1 specific step in this article that talks about configuring things for NextJS projects. So the steps should be widely applicable to other projects as well.</p>
<p><a target="_blank" href="[https://caddyserver.com/](https://caddyserver.com/)">Caddy server</a> is a powerful, enterprise-ready open source web server with automatic HTTPS support. Let's see how we can use this to make your localhost experience better.</p>
<h2 id="heading-steps">Steps</h2>
<p>This article assumes</p>
<ul>
<li><p>you're on a Mac. So you might have to find the necessary alternatives for certain aspects in other operating systems.</p>
</li>
<li><p>you're setting up a local environment for <code>www.example.com</code>. Replace this with your domain name.</p>
</li>
<li><p>you're setting up a mapping to a NextJS web application that's running on port 3000.</p>
</li>
</ul>
<p>First off, you'll need to map <code>localhost.example.com</code> to <code>localhost</code> . Run</p>
<pre><code class="lang-powershell">sudo vim /etc/hosts
</code></pre>
<p>and add the mapping to the end of this file. A sample here but remember to replace the name with your domain:</p>
<pre><code class="lang-powershell"><span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span>    localhost.example.com
</code></pre>
<p>Assuming your app runs on port 3000, create Caddyfile in your home directory (<code>vim ~/Caddyfile</code>) with the following contents again replacing your name :</p>
<pre><code class="lang-plaintext">localhost.example.com {
    tls internal

    reverse_proxy / localhost:3000
    reverse_proxy /_next/* localhost:3000
}
</code></pre>
<ul>
<li><p>The first line specifying <code>tls internal</code> ensures Caddy server doesn't go to the public internet to get certificates. Even though you might own this domain in this case, we're doing internal TLS to generate a certificate locally. This helps especially in an enterprise environment where you may not have control over the domain but still want to do localhost development on a project.</p>
</li>
<li><p><code>reverse_proxy / localhost:3000</code> - This ensures the home page path maps to localhost:3000. Notice we don't specify <code>*</code> here as that would stop us from mapping more paths for other sites.</p>
</li>
<li><p><code>reverse_proxy /_next/* localhost:3000</code> - This line is specific to a NextJS project. NextJS serves its assets locally under <code>_next</code> folder. So by mapping all assets under this path to <code>localhost:3000</code>, we ensure things work as expected.</p>
</li>
</ul>
<pre><code class="lang-powershell">caddy <span class="hljs-built_in">start</span> -<span class="hljs-literal">-config</span> ~/Caddyfile
</code></pre>
<p>You'll see the following popup on MacOS to allow Caddy to provision a certificate in your operating system.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689561464365/0d1461e9-ec9d-4105-a91e-738a040a69ec.png" alt class="image--center mx-auto" /></p>
<p>Provide the password and hit <code>Update Settings</code>.</p>
<p>Go to your browser and hit <code>https://localhost.example.com</code> now! You should see your local site now has a HTTPS certificate and is able to get cookies from your production domain as expected!</p>
<h2 id="heading-next-steps">Next steps</h2>
<p>You can now use additional <code>reverse_proxy</code> directives in your Caddyfile to configure additional sites. For example, use the following config to add a new NextJS <code>fancy-next-app</code> project mapping.</p>
<pre><code class="lang-powershell">localhost.example.com {
    tls internal

    reverse_proxy / localhost:<span class="hljs-number">3000</span>
    reverse_proxy /_next/* localhost:<span class="hljs-number">3000</span>

    reverse_proxy /fancy<span class="hljs-literal">-new</span><span class="hljs-literal">-app</span> localhost:<span class="hljs-number">3001</span>
    reverse_proxy /fancy<span class="hljs-literal">-new</span><span class="hljs-literal">-app</span>/_next/* localhost:<span class="hljs-number">3001</span>
}
</code></pre>
<h3 id="heading-logging">Logging</h3>
<p>If you want to debug any Caddy requests that are not being served correctly, you can use the <code>log</code> block in your Caddyfile:</p>
<pre><code class="lang-powershell">
localhost.example.com {
    ...
    log {
        output stdout
        level DEBUG
    }
}
</code></pre>
<h3 id="heading-reload-caddy-config">Reload Caddy config</h3>
<p>You can decide to have these Caddyfile configs configured per Github repo. In such cases, you might want to reload Caddy configs when switching repos. You can use the following command to do that:</p>
<pre><code class="lang-powershell">caddy reload -<span class="hljs-literal">-config</span> ./Caddyfile <span class="hljs-comment"># --config is optional if the current directory has a Caddyfile</span>
</code></pre>
<h3 id="heading-stop-caddy">Stop Caddy</h3>
<p>You can stop Caddy server with the following command:</p>
<pre><code class="lang-powershell">caddy stop
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>These steps should get you set up for a smoother web development experience on your next project. So, don't overlook the importance of configuring a secure <a target="_blank" href="http://localhost">localhost</a> setup and maximizing the potential of your NextJS project. Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[GitHub best practices for enterprise developers]]></title><description><![CDATA[This will be a running list of things that I found useful while working on enterprise projects. These can be good tips for other projects too but since there are usually a lot of developers working across enterprise codebases, it is a good idea to es...]]></description><link>https://blog.adarshkonchady.com/github-best-practices-for-enterprise-developers</link><guid isPermaLink="true">https://blog.adarshkonchady.com/github-best-practices-for-enterprise-developers</guid><category><![CDATA[GitHub]]></category><category><![CDATA[enterprise app development]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Sun, 09 Jul 2023 06:59:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/KPAQpJYzH0Y/upload/831bca9d65383647c84eef139c048e65.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This will be a running list of things that I found useful while working on enterprise projects. These can be good tips for other projects too but since there are usually a lot of developers working across enterprise codebases, it is a good idea to establish and enforce some Github (GH) practices in a timely fashion (when new repositories are created).</p>
<h2 id="heading-use-trunk-based-development">Use Trunk based development</h2>
<p>Find more info <a target="_blank" href="https://trunkbaseddevelopment.com/">here</a>. This basically means using a <code>main</code> branch for all development work. Doing this helps you move your code fast to production.</p>
<p>The alternative is something like <a target="_blank" href="https://datasift.github.io/gitflow/IntroducingGitFlow.html">Gitflow</a> which is a pain to work since you usually have to keep multiple branches in sync with this.</p>
<p>To achieve true trunk-based development, developers should have the necessary tools to fully test each PR in an integration environment. This can be achieved with a preview environment per PR. You might be familiar with how Vercel does this per PR but otherwise, your company might need to set up some in-house infra to provide this support.</p>
<h2 id="heading-set-up-branch-protection-for-main">Set up branch protection for <code>main</code></h2>
<p>Enable branch protection to ensure developers follow proper processes before merging code to <code>main</code>. This also ensures devs cannot directly push commits to <code>main</code>, unless you want that for certain developers, which is generally a bad idea. Any changes should go through a PR.</p>
<p>See <a target="_blank" href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule">Github docs</a> on how to set this up.</p>
<h2 id="heading-enable-squash-and-merge-only-for-all-gh-repos">Enable <code>Squash and merge</code> only for all GH repos</h2>
<p>Github provides 3 different options to merge:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1688883278860/e1bcd9af-6242-49d6-8b79-cbb37731d923.png" alt class="image--center mx-auto" /></p>
<p>On larger projects, where you have a lot of developers working on a common repo, using any of these other options generally means you'll have a bunch of commits on <code>main</code> branch that don't make sense. I know some projects/developers tend to argue that each commit should be a semantic commit, sometimes this just adds too much pain for devs and hinders the ability to move fast.</p>
<p>Since developers should generally be advised to make smaller commits for quicker prototypes and better developer experience (DX), a PR with 50+ commits shouldn't land on the <code>main</code> branch the same way. With Squash merging, you only create 1 commit for 1 PR on <code>main</code>.</p>
<p>This is super valuable when you have a production issue and you have no idea where it came from and you have to now <a target="_blank" href="https://git-scm.com/docs/git-bisect">git bisect</a> to find the root cause. With squash merges, you can pinpoint which PR introduced a bug much quicker!</p>
<h2 id="heading-enable-semantic-pr-checks">Enable semantic PR checks</h2>
<p>Prefer to use <a target="_blank" href="https://www.conventionalcommits.org/en/v1.0.0/">conventional commits</a> on any commits to <code>main</code> branch. This extra piece of information on every commit can be super valuable if your repo is publishing packages to npm/Artifactory and you want to automate bumping major/minor/patch versions of packages. But even on a feature repo with web applications, this provides a nice overview of <code>main</code> branch commits indicating features, bug fixes, chores, etc.</p>
<p>Since you now have only squash merge enabled, you can enable every PR title to have the conventional commit prefix with a Github action PR check.</p>
<h2 id="heading-have-a-contributingmd-file-for-your-repos">Have a CONTRIBUTING.md file for your repos</h2>
<p>Create this file as a guide to provide newcomers with onboarding documentation. If you would rather have a common Onboarding document for a larger group with something like <a target="_blank" href="https://docusaurus.io/">Docusaurus</a>, link to that site from this file.</p>
<h2 id="heading-create-smaller-gh-teams-and-make-them-codeowners">Create smaller GH teams and make them CODEOWNERS</h2>
<p>When working in a polyrepo setup with multiple teams owning different repos, having a smaller GH team is nice since you can easily identify ownership. If you have a group of 100 people owning a functionality, it usually means no one owns it. A smaller group, who can be held accountable for an area, is better for quicker feedback cycles.</p>
<p>Add this GH team to the CODEOWNERS file to ensure any PR creations on the GH repo would need the code owner group approvals.</p>
<h2 id="heading-use-renovate-to-automate-dependency-upgrades">Use Renovate to automate dependency upgrades</h2>
<p>In larger projects, keeping dependencies up to date is critical in the long term. Renovate makes this easy by creating PRs for you. It comes with a lot of baked-in defaults as well to make your life easy. For example, dependencies <code>next</code> and <code>eslint-config-next</code> should be upgraded together in NextJS projects. Hence Renovate creates a single PR for both of these updates and makes the necessary lock file updates for you. It also supports <code>pnpm</code> which is my go-to package manager for all new projects. Check their docs [here](<a target="_blank" href="https://docs.renovatebot.com/">https://docs.renovatebot.com/</a>).</p>
<h2 id="heading-enforce-pr-checks">Enforce PR checks</h2>
<p>Create PR checks for <code>build</code>, <code>lint</code>, <code>test</code>, <code>format</code>, <code>typecheck</code> etc. to make sure any commits going into the <code>main</code> branch are safe. Also, GitHub lets you mark these PR checks as <code>Required</code> so that developers cannot merge their PRs until these checks pass. You can find this under the branch protection setting for <code>main</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1688885858738/9c859a8d-0efb-422c-b945-d87860285cb0.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Git rebase to modify multiple local/remote commits at once]]></title><description><![CDATA[The git rebase command with --exec flag can be pretty handy in a variety of situations. Using this, you can execute any git command on a range of commits, both for local and remote commits.
One example that this can be really handy for is modifying c...]]></description><link>https://blog.adarshkonchady.com/git-rebase-to-modify-multiple-localremote-commits-at-once</link><guid isPermaLink="true">https://blog.adarshkonchady.com/git-rebase-to-modify-multiple-localremote-commits-at-once</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Sun, 13 Feb 2022 04:15:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/wX2L8L-fGeA/upload/7396ef1db4df53bd513d5538080b5c88.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The git rebase command with <code>--exec</code> flag can be pretty handy in a variety of situations. Using this, you can execute any git command on a range of commits, both for local and remote commits.</p>
<p>One example that this can be really handy for is modifying commit details.</p>
<pre><code class="lang-plaintext">git rebase HEAD~2 --exec "git commit --amend --no-edit --author='FirstName LastName &lt;author@gmail.com&gt;'"
</code></pre>
<p>The above commit modifies the author details on the last 2 commits in the current branch. <code>--no-edit</code> flag ensures this gets executed right away without showing the edit prompt for each commit.</p>
<p>This can be followed up with a force push <code>git push -f</code> on the current branch to modify remote commits.</p>
]]></content:encoded></item><item><title><![CDATA[Debugging standalone JS files in VSCode]]></title><description><![CDATA[You have most likely used VSCode if you have been doing web development for some time. I switch between WebStorm and VSCode for my company’s projects but I have started to prefer VSCode more since it has a much faster boot time.
Recently, I ran into ...]]></description><link>https://blog.adarshkonchady.com/debugging-standalone-js-files-in-vscode-fed928cff6aa</link><guid isPermaLink="true">https://blog.adarshkonchady.com/debugging-standalone-js-files-in-vscode-fed928cff6aa</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Tue, 24 Aug 2021 04:56:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865405281/Cux6zanP-.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You have most likely used VSCode if you have been doing web development for some time. I switch between WebStorm and VSCode for my company’s projects but I have started to prefer VSCode more since it has a much faster boot time.</p>
<p>Recently, I ran into an issue when I just wanted to test a simple script file and wanted to debug it as I wrote it. I could of course use the Chrome debugger but this needed some more work 🤷‍♂</p>
<p>Anyways, I didn’t want to do this over and over again and wanted to set this up in a way that it works across projects on my system.</p>
<p>Here is how I did it:</p>
<ul>
<li><p>Press <code>Cmd + ,</code> (or <code>Ctrl + ,</code> for Windows) to get into the Settings page</p>
</li>
<li><p>Search for <code>Global debug launch configuration</code></p>
</li>
<li><p>Click on <code>Edit in settings.json</code></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865403832/NCaHSln82.png" alt /></p>
<ul>
<li>Add the following configuration under <code>launch</code></li>
</ul>
<pre><code class="lang-json"><span class="hljs-string">"launch"</span>: {
    <span class="hljs-attr">"inputs"</span>: [],
    <span class="hljs-attr">"configurations"</span>: [
      {
          <span class="hljs-attr">"type"</span>: <span class="hljs-string">"node"</span>,
          <span class="hljs-attr">"request"</span>: <span class="hljs-string">"launch"</span>,
          <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Launch Current Opened File"</span>,
          <span class="hljs-attr">"program"</span>: <span class="hljs-string">"${file}"</span>
      }
    ],
    <span class="hljs-attr">"compounds"</span>: []
  }
</code></pre>
<p>And you’re all set !</p>
<p>Go back to your JS file and hit <code>F5</code> . Any breakpoints will let you debug variables from here on.</p>
<p>Enjoy debugging 👋</p>
]]></content:encoded></item><item><title><![CDATA[React — Quick find props changing between renders]]></title><description><![CDATA[React component performance
React has made it easy for web developers to quickly develop and deploy apps into production. However, as the app gets huge and you have many developers working on the same codebase, different patterns emerge. And as a res...]]></description><link>https://blog.adarshkonchady.com/react-quick-find-props-changing-between-renders-2274586106ee</link><guid isPermaLink="true">https://blog.adarshkonchady.com/react-quick-find-props-changing-between-renders-2274586106ee</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Mon, 17 Jun 2019 06:45:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865411044/ZtumOAGG6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React component performance</p>
<p>React has made it easy for web developers to quickly develop and deploy apps into production. However, as the app gets huge and you have many developers working on the same codebase, different patterns emerge. And as a result of this, slowly you will end up having performance issues on the website. These may not be immediately visible on the high-end laptops that we as web developers have the privilege to work on. But as the product grows its outreach into newer markets, and your users start using your web app with handheld devices, any performance issue can become a significant problem to the business revenue.</p>
<p>While trying to identify performance issues on my website, I often have to switch between <em>Performance</em> panel on <em>Chrome DevTools and the React DevTools profiler. </em>Once I identify the component having a perf issue with these previous tools, I often have to find out which props actually changed and the previous v/s new value of the culprit prop.</p>
<p>Here is one handy script that you can plug into your <code>componentDidUpdate</code> to identify the props causing re-renders for a particular component.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codesandbox.io/s/pm9o9779j0?from-embed?fontsize=14&amp;hidenavigation=1&amp;theme=dark">https://codesandbox.io/s/pm9o9779j0?from-embed?fontsize=14&amp;hidenavigation=1&amp;theme=dark</a></div>
<p>In the above code sandbox, click on the button to update the component state, and inspect the changing values on console.</p>
]]></content:encoded></item><item><title><![CDATA[Lazy load images using IntersectionObserver]]></title><description><![CDATA[Motivation
Loading images on the web has always been a hot topic. If a user doesn’t see all your images, it doesn’t make sense to send down the wire all those extra bytes. All the techniques used to lazy load images in the past have used a combinatio...]]></description><link>https://blog.adarshkonchady.com/lazy-load-images-using-intersectionobserver-b6f433ea6e4c</link><guid isPermaLink="true">https://blog.adarshkonchady.com/lazy-load-images-using-intersectionobserver-b6f433ea6e4c</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Tue, 16 Jan 2018 12:39:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/Jt9syHEhrPE/upload/56679b6542e2b9849f39037663eba68c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-motivation">Motivation</h2>
<p>Loading images on the web has always been a hot topic. If a user doesn’t see all your images, it doesn’t make sense to send down the wire all those extra bytes. All the techniques used to lazy load images in the past have used a combination of the browser provided APIs like <em>getBoundingClientReact </em>together with event listeners on each image to get the position of the element with respect to the viewport.</p>
<p>The problem with these approaches is the computations involved in the API is heavy and often results in users experiencing scroll janks navigating the site. With <em>IntersectionObserver</em>, all this would hopefully go away!</p>
<h2 id="heading-solution">Solution</h2>
<p>IntersectionObserver is an API baked right into your browser to help you combat the problem above.</p>
<h2 id="heading-code">Code</h2>
<p>Check out the following Codepen for a demo on Intersection observer to lazy load images on a site:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/akonchady/pen/QWgwQpV">https://codepen.io/akonchady/pen/QWgwQpV</a></div>
<p>The <em>IntersectionObserver</em> API accepts 2 arguments, a <em>callback</em> function and an <em>options</em> object. Checkout the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API">MDN</a> link to see the values for each of these options. Below is a brief one liner for what each options does.</p>
<p><em>root</em> - The parent element with respect to which the intersection will be calculated. Defaults to null which means, the viewport.</p>
<p><em>rootMargin</em> - Values specified here will add margin to the root element (specified by <em>root)</em> on all 4 sides.</p>
<p>threshold - Specifies what percentage of the target element (<em>the element being observed</em>) crosses the intersection for the callback to be fired.</p>
<h2 id="heading-future-possibilities">Future possibilities</h2>
<p>Instead of having an event listener on each and every image, we could have implemented this by having a placeholder ‘div’ in between a set of say, 10 images to load 10 images at once. We could then observe this placeholder instead to minimize the observers on our page and load images (in sets of 10) more effectively.</p>
<p>This would be great for a shopping site where you have a infinite scroll for images.</p>
<p>For those interested to explore more, here is a great article by Surma and Robert Flack on optimizing infinite scrolling:</p>
<p><a target="_blank" href="https://developers.google.com/web/updates/2016/07/infinite-scroller">https://developers.google.com/web/updates/2016/07/infinite-scroller</a></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Intersection Observers are great and here to stay. You could feature detect the availability and go through loading all the images or lazy loading for your users. Check the following link for the available browser support.</p>
<p><a target="_blank" href="https://caniuse.com/#search=intersectionobserver">https://caniuse.com/#search=intersectionobserver</a></p>
<blockquote>
<p><strong>Helpful links:</strong>
<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API"><strong>Intersection Observer API</strong>
<em>The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element…</em>developer.mozilla.org</a></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Find if an element is completely visible in the viewport]]></title><description><![CDATA[Here is the JS code to find out if a given element on the DOM is completely visible in the browser window viewport or not:
function isInViewport(element) {
  var rect = element.getBoundingClientRect();
  var html = document.documentElement;
  if (
  ...]]></description><link>https://blog.adarshkonchady.com/find-if-an-element-is-completely-visible-in-the-viewport-3149dc578b15</link><guid isPermaLink="true">https://blog.adarshkonchady.com/find-if-an-element-is-completely-visible-in-the-viewport-3149dc578b15</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Wed, 18 May 2016 15:34:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/FFehoJzQ6y0/upload/fbaad9596e1a1a5271d5927d66cb0b7e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here is the JS code to find out if a given element on the DOM is completely visible in the browser window viewport or not:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isInViewport</span>(<span class="hljs-params">element</span>) </span>{
  <span class="hljs-keyword">var</span> rect = element.getBoundingClientRect();
  <span class="hljs-keyword">var</span> html = <span class="hljs-built_in">document</span>.documentElement;
  <span class="hljs-keyword">if</span> (
    rect.top &gt;= <span class="hljs-number">0</span> &amp;&amp;
    rect.left &gt;= <span class="hljs-number">0</span> &amp;&amp;
    rect.bottom &lt;= (<span class="hljs-built_in">window</span>.innerHeight || html.clientHeight) &amp;&amp;
    rect.right &lt;= (<span class="hljs-built_in">window</span>.innerWidth || html.clientWidth)
  ) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  }
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[‘return’ inside constructors]]></title><description><![CDATA[function Eg() {
  this.name = 10;
  return 'adarsh';
}
new Eg(); // Returns {name: 10}

However, if you return a object inside a constructor function, that object will be returned.
function Eg() {
  this.name = 10;
  return { 
    name: 'adarsh' 
  }...]]></description><link>https://blog.adarshkonchady.com/return-inside-constructors-664148320278</link><guid isPermaLink="true">https://blog.adarshkonchady.com/return-inside-constructors-664148320278</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Fri, 18 Mar 2016 15:18:27 GMT</pubDate><content:encoded><![CDATA[<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Eg</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">this</span>.name = <span class="hljs-number">10</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-string">'adarsh'</span>;
}
<span class="hljs-keyword">new</span> Eg(); <span class="hljs-comment">// Returns {name: 10}</span>
</code></pre>
<p>However, if you return a object inside a constructor function, that object will be returned.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Eg</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">this</span>.name = <span class="hljs-number">10</span>;
  <span class="hljs-keyword">return</span> { 
    <span class="hljs-attr">name</span>: <span class="hljs-string">'adarsh'</span> 
  };
}
<span class="hljs-keyword">new</span> Eg(); <span class="hljs-comment">// Returns {name: "adarsh"}</span>
</code></pre>
<p>So basically, whenever you return a primitive inside a constructor function, that is ignored. However any reference types returned inside a constructor function will override the 'new'ly created object.
A sample 'new' implementation</p>
<pre><code class="lang-js">NEW = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">constructor, args</span>)</span>{
    <span class="hljs-comment">// var obj = Object.create(constructor.prototype);</span>
    <span class="hljs-keyword">var</span> obj = {};
    obj.__proto__ = constructor.prototype;
    <span class="hljs-keyword">var</span> retValue = constructor.apply(obj, args);
    <span class="hljs-keyword">if</span>(<span class="hljs-keyword">typeof</span> retValue === <span class="hljs-string">'object'</span>) {
        <span class="hljs-keyword">return</span> retValue;
    }
    <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> obj;
    }
};
</code></pre>
<p>Usage: <code>NEW(Person, ['Adarsh']);</code>
Note: Line 1 (commented) inside the above function 
      can replace lines 2 and 3
For more details, follow the below link:
http://www.bennadel.com/blog/2522-providing-a-return-value-in-a-javascript-constructor.htm</p>
]]></content:encoded></item><item><title><![CDATA[Problem with using ‘new’ for Inheritance]]></title><description><![CDATA[Imagine you have the following block of code.
function Animal() {
     this.offspring = [];
}
function Dog() {
}
Dog.prototype = new Animal();
Dog.prototype.constructor = Dog;
var d1 = new Dog();
var d2 = new Dog();
var pup = new Dog();
d1.offspring....]]></description><link>https://blog.adarshkonchady.com/problem-with-using-new-for-inheritance-c94ed6a65996</link><guid isPermaLink="true">https://blog.adarshkonchady.com/problem-with-using-new-for-inheritance-c94ed6a65996</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Fri, 18 Mar 2016 14:43:01 GMT</pubDate><content:encoded><![CDATA[<p>Imagine you have the following block of code.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Animal</span>(<span class="hljs-params"></span>) </span>{
     <span class="hljs-built_in">this</span>.offspring = [];
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Dog</span>(<span class="hljs-params"></span>) </span>{
}
Dog.prototype = <span class="hljs-keyword">new</span> Animal();
Dog.prototype.constructor = Dog;
<span class="hljs-keyword">var</span> d1 = <span class="hljs-keyword">new</span> Dog();
<span class="hljs-keyword">var</span> d2 = <span class="hljs-keyword">new</span> Dog();
<span class="hljs-keyword">var</span> pup = <span class="hljs-keyword">new</span> Dog();
d1.offspring.push(pup);
d2.offspring; <span class="hljs-comment">// Does 'd2.offspring' have a pup in it?</span>
</code></pre>
<p>Well it turns out that d2, in the above case, does have a pup in it !!!</p>
<p>Why you ask ?</p>
<p>Because when you write ‘d1.offspring.push’, browser will do the following in its search for ‘offspring’ array.</p>
<p>Look up ‘offspring’ in d1 -&gt; No match</p>
<p>Look up ‘offspring’ in Dog.prototype -&gt; Match found</p>
<p>Hence, ‘pup’ is pushed into the offspring of ‘Dog.prototype’ and thus d2 has the same copy?</p>
<p>How do we fix this now?</p>
<p>Look up the code below where we use ‘Object.create’ with the combination of ‘Animal.call’.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Animal</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">this</span>.offspring = [];
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Dog</span>(<span class="hljs-params"></span>) </span>{
  Animal.call(<span class="hljs-built_in">this</span>); <span class="hljs-comment">// Use Animal.call(this, args) if any arguments</span>
  <span class="hljs-comment">// exist. Else, use 'apply'</span>
}
Dog.prototype = <span class="hljs-built_in">Object</span>.create(Animal.prototype);
Dog.prototype.constructor = Dog;
<span class="hljs-keyword">var</span> d1 = <span class="hljs-keyword">new</span> Dog();
<span class="hljs-keyword">var</span> d2 = <span class="hljs-keyword">new</span> Dog();
<span class="hljs-keyword">var</span> pup = <span class="hljs-keyword">new</span> Dog();
d1.offspring.push(pup); <span class="hljs-comment">// Dog {offspring: Array[1]}</span>
d2.offspring; <span class="hljs-comment">// Dog {offspring: Array[0]}</span>
</code></pre>
<p>There you go!</p>
]]></content:encoded></item><item><title><![CDATA[Accessing parent prototype functions from Child]]></title><description><![CDATA[Consider the following code:
function Parent() {}

Parent.prototype.display = function() {
  console.log('Parent');
}

function Child() {}

Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;

Child.prototype.displ...]]></description><link>https://blog.adarshkonchady.com/accessing-parent-prototype-functions-from-child-b07d35976507</link><guid isPermaLink="true">https://blog.adarshkonchady.com/accessing-parent-prototype-functions-from-child-b07d35976507</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Tue, 12 Jan 2016 12:10:24 GMT</pubDate><content:encoded><![CDATA[<p>Consider the following code:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Parent</span>(<span class="hljs-params"></span>) </span>{}

<span class="hljs-built_in">Parent</span>.prototype.display = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  console.log(<span class="hljs-string">'Parent'</span>);
}

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

Child.prototype = <span class="hljs-keyword">Object</span>.create(<span class="hljs-built_in">Parent</span>.prototype);
Child.prototype.constructor = Child;

Child.prototype.display = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  console.log(<span class="hljs-string">'Child'</span>);
}

<span class="hljs-keyword">var</span> c = <span class="hljs-keyword">new</span> Child();

c.display(); <span class="hljs-comment">// 'Child'</span>

In the above code, the <span class="hljs-keyword">final</span> line will <span class="hljs-keyword">print</span> <span class="hljs-string">'Child'</span> because c is an <span class="hljs-keyword">object</span> of <span class="hljs-string">'Child'</span>.

Now, <span class="hljs-keyword">if</span> you observed, we did create a link between Child <span class="hljs-keyword">and</span> <span class="hljs-built_in">Parent</span> using <span class="hljs-string">'Object.create'</span>. What <span class="hljs-keyword">if</span> we need the last line to invoke <span class="hljs-string">'Parent display'</span> followed by <span class="hljs-string">'Child display'</span>?

We need to modify the <span class="hljs-string">'Child'</span> display <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">to</span> <span class="hljs-title">accomplish</span> <span class="hljs-title">this</span>.

<span class="hljs-title">Child</span>.<span class="hljs-title">prototype</span>.<span class="hljs-title">display</span> = <span class="hljs-title">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> <span class="hljs-built_in">parent</span> = <span class="hljs-keyword">Object</span>.getPrototypeOf(Child.prototype);
  <span class="hljs-built_in">parent</span>.display();
  console.log(<span class="hljs-string">'Child'</span>);
}

We are now getting the <span class="hljs-string">'Parent'</span> prototype reference by using <span class="hljs-string">'Object.getPrototypeOf'</span> on <span class="hljs-string">'Child.prototype'</span>.

Hence the following code will give the desired result:

c.display(); <span class="hljs-comment">//Parent Child</span>
</code></pre>]]></content:encoded></item><item><title><![CDATA[Creating abstract class in Javascript]]></title><description><![CDATA[An abstract class is a ‘class’ that is used just for inheritance. We should not be creating objects directly from abstract classes.
Here is the code:
function Car(name) {
  if(this.constructor === Car) {
    throw 'Cannot instantiate abstract class';...]]></description><link>https://blog.adarshkonchady.com/creating-abstract-class-in-javascript-6924e72f8835</link><guid isPermaLink="true">https://blog.adarshkonchady.com/creating-abstract-class-in-javascript-6924e72f8835</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Tue, 12 Jan 2016 11:55:15 GMT</pubDate><content:encoded><![CDATA[<p>An abstract class is a ‘class’ that is used just for inheritance. We should not be creating objects directly from abstract classes.</p>
<p>Here is the code:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Car</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">if</span>(<span class="hljs-built_in">this</span>.constructor === Car) {
    <span class="hljs-keyword">throw</span> <span class="hljs-string">'Cannot instantiate abstract class'</span>;
  }
  <span class="hljs-built_in">this</span>.name = name;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">i12</span>(<span class="hljs-params"></span>) </span>{
  Car.call(<span class="hljs-built_in">this</span>, <span class="hljs-string">'i12'</span>);
}

The key here is the <span class="hljs-string">'constructor'</span> property.

Now, <span class="hljs-keyword">if</span> I execute the following:

c = <span class="hljs-keyword">new</span> i12(); 
<span class="hljs-built_in">console</span>.log(c.name); <span class="hljs-comment">// "i12"</span>

But trying to instantiate the <span class="hljs-function"><span class="hljs-keyword">function</span> '<span class="hljs-title">Car</span>' <span class="hljs-title">directly</span> <span class="hljs-title">will</span> <span class="hljs-title">result</span> <span class="hljs-title">in</span> <span class="hljs-title">an</span> <span class="hljs-title">exception</span>.

<span class="hljs-title">c</span> = <span class="hljs-title">new</span> <span class="hljs-title">Car</span>(<span class="hljs-params"></span>); // <span class="hljs-title">Uncaught</span> <span class="hljs-title">Cannot</span> <span class="hljs-title">instantiate</span> <span class="hljs-title">abstract</span> <span class="hljs-title">class</span></span>
</code></pre>]]></content:encoded></item><item><title><![CDATA[How to create a revocable function to grant/revoke access to any other function?]]></title><description><![CDATA[The following code will show you how to create a function ‘revocable’ that will be used to grant/revoke access to other functions.
The function that will be tested here is the add function to add 2 numbers. But the ‘revocable’ function is good enough...]]></description><link>https://blog.adarshkonchady.com/how-to-create-a-revocable-function-to-grant-revoke-access-to-any-other-function-b4063a79d921</link><guid isPermaLink="true">https://blog.adarshkonchady.com/how-to-create-a-revocable-function-to-grant-revoke-access-to-any-other-function-b4063a79d921</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Sun, 20 Dec 2015 19:54:21 GMT</pubDate><content:encoded><![CDATA[<p>The following code will show you how to create a function ‘revocable’ that will be used to grant/revoke access to other functions.</p>
<p>The function that will be tested here is the add function to add 2 numbers. But the ‘revocable’ function is good enough to work for other functions as well.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span> (<span class="hljs-params">x, y</span>) </span>{
    <span class="hljs-keyword">return</span> x + y;
}
</code></pre><p>Given below is the code for the ‘revocable’ function:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">revocable</span>(<span class="hljs-params">fn</span>) </span>{
    <span class="hljs-keyword">var</span> allow = <span class="hljs-literal">true</span>;
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">invoke</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
            <span class="hljs-keyword">if</span>(!allow) {
                <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Access revoked'</span>);
            }
            <span class="hljs-keyword">return</span> fn.apply(<span class="hljs-built_in">this</span>, <span class="hljs-built_in">arguments</span>);
        },
        <span class="hljs-attr">revoke</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
            allow = <span class="hljs-literal">false</span>;
        },
        <span class="hljs-attr">grant</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
            allow = <span class="hljs-literal">true</span>;
        }
    }
}

<span class="hljs-keyword">var</span> temp = revocable(add);

temp.invoke(<span class="hljs-number">3</span>, <span class="hljs-number">4</span>); <span class="hljs-comment">// 7</span>

temp.revoke();

temp.invoke(<span class="hljs-number">3</span>, <span class="hljs-number">4</span>); <span class="hljs-comment">// Uncaught Error: Access revoked(…)</span>

temp.grant();

temp.invoke(<span class="hljs-number">3</span>, <span class="hljs-number">4</span>); <span class="hljs-comment">// 7</span>
</code></pre>]]></content:encoded></item><item><title><![CDATA[Highlight all occurrences of text in a container]]></title><description><![CDATA[Here is the JQuery code to highlight all occurrences of a given text in a container:
$(".container:contains('Google')").html(function(_, html) {
  return html.replace(/(Google)/g, '<span style="background-color: yellow;">$1</span>');
});
The above bl...]]></description><link>https://blog.adarshkonchady.com/highlight-all-occurrences-of-text-in-a-container-5eeb9bb4d18</link><guid isPermaLink="true">https://blog.adarshkonchady.com/highlight-all-occurrences-of-text-in-a-container-5eeb9bb4d18</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Thu, 10 Dec 2015 11:29:54 GMT</pubDate><content:encoded><![CDATA[<p>Here is the JQuery code to highlight all occurrences of a given text in a container:</p>
<pre><code>$(<span class="hljs-string">".container:contains('Google')"</span>).html(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">_, html</span>) </span>{
  <span class="hljs-keyword">return</span> html.replace(<span class="hljs-regexp">/(Google)/g</span>, <span class="hljs-string">'&lt;span style="background-color: yellow;"&gt;$1&lt;/span&gt;'</span>);
});
</code></pre><p>The above block will change all occurences of the text ‘Methods’ within an element of class ‘container’ and make the background color of the text yellow by inserting a new span.</p>
<p>Check it out here:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/akonchady/pen/WNObGNG">https://codepen.io/akonchady/pen/WNObGNG</a></div>
]]></content:encoded></item><item><title><![CDATA[Hard binding ‘this’ in your code]]></title><description><![CDATA[There are times when you are scratching your head wondering how on earth the value of ‘this’ got changed. For example, if you are within a function called from an object, ‘this’ may point to that object. However, when the function is set as an event ...]]></description><link>https://blog.adarshkonchady.com/hard-binding-this-in-your-code-665abca8a732</link><guid isPermaLink="true">https://blog.adarshkonchady.com/hard-binding-this-in-your-code-665abca8a732</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Fri, 31 Jul 2015 10:14:32 GMT</pubDate><content:encoded><![CDATA[<p>There are times when you are scratching your head wondering how on earth the value of ‘this’ got changed. For example, if you are within a function called from an object, ‘this’ may point to that object. However, when the function is set as an event listener to a button, ‘this’ will be the button itself.</p>
<p>So how can you ensure that ‘this’ binding remains what you want it to be? Here is the code to do just that.</p>
<pre><code><span class="hljs-keyword">function</span> bind(fn, obj) {
    // fn - <span class="hljs-keyword">Function</span> <span class="hljs-keyword">to</span> be hard binded
    // obj - <span class="hljs-keyword">Object</span> <span class="hljs-keyword">to</span> which the <span class="hljs-keyword">function</span> <span class="hljs-string">'fn'</span> has <span class="hljs-keyword">to</span> be binded
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">function</span>() {
        fn.apply(obj, arguments); // <span class="hljs-keyword">Call</span> site <span class="hljs-keyword">to</span> <span class="hljs-keyword">call</span> the <span class="hljs-keyword">function</span>
    };
}

var obj = {
    bar: "bar",
    foo: <span class="hljs-keyword">function</span>(x) {
        console.log(this.bar + <span class="hljs-string">' value: '</span> + x);
    }
};

var obj2 = {
    bar: "bar2"
};

foo = bind(obj.foo, obj);

foo(<span class="hljs-number">3</span>); // bar <span class="hljs-keyword">value</span>: <span class="hljs-number">3</span>

foo = bind(obj.foo, obj2);

foo(<span class="hljs-number">3</span>); // bar2 <span class="hljs-keyword">value</span>: <span class="hljs-number">3</span>

foo.<span class="hljs-keyword">call</span>(obj2); // This too gives <span class="hljs-string">'bar'</span> since foo has been hard binded now. Hence this <span class="hljs-keyword">is</span> <span class="hljs-keyword">no</span> longer the <span class="hljs-keyword">call</span> site.

Thankfully, ES5 onwards, this <span class="hljs-string">'bind'</span> feature <span class="hljs-keyword">is</span> built <span class="hljs-keyword">in</span> <span class="hljs-keyword">to</span> Javascript. Here <span class="hljs-keyword">is</span> the MDN page <span class="hljs-keyword">for</span> that <span class="hljs-keyword">where</span> you can see the polyfill <span class="hljs-keyword">for</span> the implementation <span class="hljs-keyword">as</span> well.

URL : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/<span class="hljs-keyword">Function</span>/bind
</code></pre>]]></content:encoded></item><item><title><![CDATA[Diving into Angular 2.0 !!!]]></title><description><![CDATA[Want to get a head start on Angular 2.0 ? Watch this video.
[embed]https://youtu.be/gNmWybAyBHI[/embed]]]></description><link>https://blog.adarshkonchady.com/diving-into-angular-2-0-77c36e277543</link><guid isPermaLink="true">https://blog.adarshkonchady.com/diving-into-angular-2-0-77c36e277543</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Mon, 20 Jul 2015 18:55:40 GMT</pubDate><content:encoded><![CDATA[<p>Want to get a head start on Angular 2.0 ? Watch this video.</p>
<p>[embed]https://youtu.be/gNmWybAyBHI[/embed]</p>
]]></content:encoded></item><item><title><![CDATA[A beginner’s guide to Git and its workflow — Part 1]]></title><description><![CDATA[This post is intended to be an introduction to Git. I have tried to cover all the basic concepts of Git, with examples, which you will need in day to day work.
We will not be going into the details a lot as it will only confuse the beginners and you ...]]></description><link>https://blog.adarshkonchady.com/a-beginners-guide-to-git-and-its-workflow-part-1-fdd2c3ef9ea9</link><guid isPermaLink="true">https://blog.adarshkonchady.com/a-beginners-guide-to-git-and-its-workflow-part-1-fdd2c3ef9ea9</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Mon, 16 Feb 2015 05:56:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865472621/kApBQ8C2a.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This post is intended to be an introduction to Git. I have tried to cover all the basic concepts of Git, with examples, which you will need in day to day work.</p>
<p>We will not be going into the details a lot as it will only confuse the beginners and you will be provided with a set of links towards the end of this where you can get more information. Let’s get started.</p>
<p>Fig. below show the basic workflow of Git.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865461799/hHuKkKzrT.png" alt /></p>
<ul>
<li><p>Git, as in any other Version Control Systems (VCS), operates in 2 regions, one is the central repository and the other region is the one which is local to each user(who clones the repository).</p>
</li>
<li><p>In the local repository, again there are 3 layers.</p>
</li>
<li><p><strong>Working directory</strong> — This the your working directory where you will be editing the files.</p>
</li>
<li><p><strong>Staging area</strong> — Once you are done editing the files in the working directory, choose the files which you want to commit. These files can then be ADDed to the staging area.</p>
</li>
<li><p><strong>Committed region</strong> — The staged files can now be COMMITted into the committed region. This contains all your commits. Remember, till this point, all the changes are still in your local system.</p>
</li>
<li><p>Finally, you can ‘PUSH’ all the changes from the local repository to the central repository.</p>
</li>
</ul>
<p>Please follow the below steps to get a hang of GIT in general. This assumes that you have an active BitBucket account.</p>
<ul>
<li><p>Go to your Windows command prompt or the Linux/Mac terminal. In Windows, you can use ‘Git bash’ for easy operation.</p>
</li>
<li><p>Switch into the directory, where you want your repository to reside.</p>
</li>
<li><p>Type the commands as shown in the screenshot below :</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865463238/sq7IJH3t5.jpeg" alt /></p>
<ul>
<li><p>‘git config’ allows to define configurations for your git repositories. Here we define the user name (&lt;first_name last_name&gt;) and user email address which will be used by GIT for all commits that you do.</p>
</li>
<li><p>If you wish to use a different email address only for specific commits or for specific repositories, you can provide the ‘git config’ command inside the specific repository folder and omit the ‘ — global’ flag.</p>
</li>
<li><p>Eg: $ git config user.name “Adarsh Konchady”</p>
</li>
<li><p>Eg: $ git config user.email “akonchady@gmail.com”</p>
</li>
<li><p>Next create a GIT repo and switch into it as follows :</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865464655/-Ni9ZAHwV.png" alt /></p>
<ul>
<li><p>Here, we first create an empty Git repository using ‘git init &lt;repository_name&gt;’ and then switch into it.</p>
</li>
<li><p>‘git status’ gives you the status of the current working directory and the staging area. Please refer the first slide of this post again in case you have difficulties remembering the staging area :)</p>
</li>
<li><p>Let’s now create a file and add some lines into it. We will be using the default vim editor to do this. If you are not familiar with the ‘vim’ editor, you can go through this link for <a target="_blank" href="http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm">VIM editor commands</a>.</p>
</li>
<li><p>Type ‘vim index.html’</p>
</li>
<li><p>Press ‘i’(insert) and start typing the contents.</p>
</li>
<li><p>Once done, key in Escape -&gt; :wq</p>
</li>
<li><p>This will save the contents and return back to the prompt</p>
</li>
<li><p>To verify if file was successfully saved and view its contents, type</p>
</li>
<li><p>cat index.html</p>
</li>
<li><p>Now, check the status again by typing ‘git status’. You will see something as follows :</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865466047/NBMhvu7K0.png" alt /></p>
<ul>
<li><p>As you can see, the newly created file ‘index.html’ is shown in red color. This means your changes are still in the working directory.</p>
</li>
<li><p>Let’s add this file to the staging area now.</p>
</li>
<li><p>Type ‘<em>git add index.html</em>’</p>
</li>
<li><p>Note, to add all untracked/modified files in the current directory recursively, you can type <em>‘git add .</em>’. The period(.) indicates the current directory.</p>
</li>
<li><p>Now, type ‘git status’ again. You will see the file in ‘green’ color as follows :</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865467370/1WBokre3i.png" alt /></p>
<ul>
<li><p>Now that we are ready to commit our changes, let’s do it !</p>
</li>
<li><p>Type ‘git commit -m “My first commit”</p>
</li>
<li><p>Please note that it is mandatory to add a commit message while committing your changes. This is because when someone views your commits later on in the project cycle, he/she can actually pinpoint when a specific feature was pushed in and with which commit.</p>
</li>
<li><p>After you do this, press ‘git status’ again. You won’t see file names !! Surprising ???</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865468636/CPiKcYY4x.png" alt /></p>
<ul>
<li><p>As mentioned earlier, ‘git status’ will only give you the status of the ‘working directory’ and the ‘staging area’.</p>
</li>
<li><p>If you want to see the changes of the committed region, type</p>
</li>
<li><p>git log</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865469989/aEgnXOx8A.png" alt /></p>
<ul>
<li><p>If you only want a short commit has code and the message, you can also type</p>
</li>
<li><p>git log — oneline</p>
</li>
<li><p>At this stage, we are done with all that has to be done in the local repository. It’s time to push your changes into the central repository so that others can see your changes!!!</p>
</li>
<li><p>To do this, follow the following steps:</p>
</li>
<li><p>Create the repository, viz. ‘mySampleRepo’.</p>
</li>
<li><p>Once the repository is created, click on the ‘Clone’ link on the left panel.</p>
</li>
<li><p>Copy the URL for HTTPS dropdown.</p>
</li>
<li><p>Come back to the command prompt/terminal and type the following commands :</p>
</li>
<li><p>git remote add origin ‘&lt;url_copied_from_your_bitbucket_account&gt;’</p>
</li>
<li><p>This will create a pointer ‘origin’ in your local repository which, from this point onwards, will be pointing to the central repository.</p>
</li>
<li><p>A ‘remote’ refers to a remote version of your repository.</p>
</li>
<li><p>git push -u origin — all</p>
</li>
<li><p>This will push all your local changes to the central repository</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1629865471303/l0bDphTWB.png" alt /></p>
<p>Congrats ! You are done with all the steps ! Enjoy !</p>
<p>Stay tuned for the next tutorial on branching and rebasing in Git.</p>
<blockquote>
<p>Helpful Links</p>
</blockquote>
<ul>
<li><p>Atlassian Git tutorial — <a target="_blank" href="https://www.atlassian.com/git/tutorials">https://www.atlassian.com/git/tutorials</a></p>
</li>
<li><p>This is a quick guide to the git commands.</p>
</li>
<li><p>Gitolite — <a target="_blank" href="http://gitolite.com/gcs.html#(1">http://gitolite.com/gcs.html#(1)</a>)</p>
</li>
<li><p>This provides a clean graph representation of all the Git commands.</p>
</li>
<li><p>Git SCM book — <a target="_blank" href="http://git-scm.com/book/en/v2">http://git-scm.com/book/en/v2</a></p>
</li>
<li><p>If you really want to master Git, complete this book !!!</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[AngularJS best practices]]></title><description><![CDATA[AngularJS best practices]]></description><link>https://blog.adarshkonchady.com/angularjs-best-practices-23b9aaf05e21</link><guid isPermaLink="true">https://blog.adarshkonchady.com/angularjs-best-practices-23b9aaf05e21</guid><dc:creator><![CDATA[Adarsh Konchady]]></dc:creator><pubDate>Fri, 13 Feb 2015 18:04:30 GMT</pubDate><content:encoded><![CDATA[<p>AngularJS best practices</p>
]]></content:encoded></item></channel></rss>