<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Namit Jain</title>
    <description>The latest articles on Forem by Namit Jain (@namit2111).</description>
    <link>https://forem.com/namit2111</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1057996%2Fcb7ed2fe-8b19-4a44-8f5b-ead5fe36220a.jpeg</url>
      <title>Forem: Namit Jain</title>
      <link>https://forem.com/namit2111</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/namit2111"/>
    <language>en</language>
    <item>
      <title>What is the N+1 Query Problem and How to Solve it?</title>
      <dc:creator>Namit Jain</dc:creator>
      <pubDate>Sun, 03 Aug 2025 12:05:12 +0000</pubDate>
      <link>https://forem.com/namit2111/what-is-the-n1-query-problem-and-how-to-solve-it-1amg</link>
      <guid>https://forem.com/namit2111/what-is-the-n1-query-problem-and-how-to-solve-it-1amg</guid>
      <description>&lt;p&gt;You’ve written the code. It works. But the page loads slowly, the database is doing way too much work, and you're staring at the query logs thinking, &lt;em&gt;“Why are there so many SELECTs here?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That moment when everything &lt;em&gt;should&lt;/em&gt; be working but feels sluggish is when you might be meeting the &lt;strong&gt;N+1 query problem&lt;/strong&gt; for the first time.&lt;/p&gt;

&lt;p&gt;It’s not a bug. It’s not an error. It’s a pattern. And it’s quietly eating your performance.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is the N+1 Query Problem?
&lt;/h2&gt;

&lt;p&gt;Let’s say you want to list all blog posts along with their comments.&lt;/p&gt;

&lt;p&gt;So you do this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetch the posts.&lt;/li&gt;
&lt;li&gt;For each post, fetch its comments.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Seems fine, right?&lt;/p&gt;

&lt;p&gt;But under the hood, this happens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Step 1&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Step 2&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;comments&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;post_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;comments&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;post_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;comments&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;post_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- and so on...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have 100 posts, that’s 1 query for the posts and 100 more for the comments: N+1 queries in total.&lt;/p&gt;

&lt;p&gt;That’s the problem.&lt;/p&gt;

&lt;p&gt;It starts small. Feels innocent. But once your data grows, this turns into a flood of unnecessary database traffic and your app crawls.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Does It Happen?
&lt;/h2&gt;

&lt;p&gt;Because it’s easy.&lt;/p&gt;

&lt;p&gt;It happens when you’re thinking about data in terms of objects or loops instead of query efficiency. It happens when you reach for a simple solution without noticing what’s happening behind the scenes.&lt;/p&gt;

&lt;p&gt;And yes, it happens with raw SQL too not just with ORMs. The problem isn’t the tools. It’s the pattern.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Tell You’re Doing It
&lt;/h2&gt;

&lt;p&gt;Here’s what to watch for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You’re running a loop in your code that includes a query.&lt;/li&gt;
&lt;li&gt;Your query log is filled with the same SELECT statement, repeated with different IDs.&lt;/li&gt;
&lt;li&gt;Your app is fast with 5 records but starts dragging with 50.&lt;/li&gt;
&lt;li&gt;A profiler or database monitor shows a growing number of similar queries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your backend touches the database inside a loop, stop and look again. You might be doing more work than you think.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Solve It
&lt;/h2&gt;

&lt;p&gt;The fix is about shifting your thinking: batch the data access, then organize it in memory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a Single Query with a JOIN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This works when the related data is lightweight and belongs in the same result set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT posts.id, posts.title, comments.body
FROM posts
LEFT JOIN comments ON comments.post_id = posts.id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you’ve done in one query what used to take 101.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use an IN Clause to Fetch Related Data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sometimes you don’t want a big JOIN. Maybe the data is complex or you need to process it differently.&lt;/p&gt;

&lt;p&gt;In that case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- First: get the posts
SELECT * FROM posts WHERE ...;

-- Then: get all related comments at once
SELECT * FROM comments WHERE post_id IN (1, 2, 3, 4, 5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you’ve done it in two queries, not 100.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build the Relationship in Your Code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you’ve got both sets of data, use code to group the related records by foreign key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Pseudocode
grouped = group_by(comments, key=lambda c: c.post_id)
for post in posts:
    post.comments = grouped.get(post.id, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Should You Care?
&lt;/h2&gt;

&lt;p&gt;Yes, especially if your app is growing or handles lots of data.&lt;/p&gt;

&lt;p&gt;The N+1 problem often hides until it becomes painful. You’ll think your logic is fine, your queries are clean, and yet performance keeps slipping. That’s why this issue is worth learning early.&lt;/p&gt;

&lt;p&gt;Fixing it is often the difference between a system that “feels fine for now” and one that scales without surprise slowdowns.&lt;/p&gt;




&lt;p&gt;Best Habits to Avoid N+1&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don’t query the database inside a loop. Ever.&lt;/li&gt;
&lt;li&gt;Think in sets, not rows. How can you get everything you need at once?&lt;/li&gt;
&lt;li&gt;Use profiling tools and query logs often.&lt;/li&gt;
&lt;li&gt;If you’re using a framework or ORM, learn how it handles data fetching under the hood.&lt;/li&gt;
&lt;li&gt;Watch for slowdowns even when the code is “technically correct.”&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;The N+1 query problem isn’t a bug in your code. It’s a lesson in how computers think about data and how to outsmart that inefficiency before it slows you down.&lt;/p&gt;




</description>
    </item>
    <item>
      <title>Devlog: Why My API Was Called Twice (And It Was Totally My Fault)</title>
      <dc:creator>Namit Jain</dc:creator>
      <pubDate>Wed, 30 Jul 2025 17:17:24 +0000</pubDate>
      <link>https://forem.com/namit2111/devlog-why-my-api-was-called-twice-and-it-was-totally-my-fault-1knj</link>
      <guid>https://forem.com/namit2111/devlog-why-my-api-was-called-twice-and-it-was-totally-my-fault-1knj</guid>
      <description>&lt;p&gt;It started like any other day. I was poking around the app - nothing serious. Just clicking through a few screens, checking the UI, casually living my best DevTools life.&lt;/p&gt;

&lt;p&gt;And then I saw it.&lt;/p&gt;

&lt;p&gt;In the Network tab:  &lt;strong&gt;Two identical API calls. Back to back.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Same endpoint. Same payload. Same timestamp, almost.&lt;/p&gt;

&lt;p&gt;At first, I thought I was seeing things. Maybe some retry logic? Maybe the backend was returning something weird and the frontend panicked?&lt;/p&gt;

&lt;p&gt;Nope. The backend was just responding. Twice. Calmly. As if I’d asked it to.&lt;/p&gt;

&lt;p&gt;So obviously, I did what any reasonable developer would do.&lt;br&gt;&lt;br&gt;
I hit refresh. Again. And again. Still two calls. Identical.&lt;/p&gt;

&lt;p&gt;Something was up. And I was pretty sure I had written it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Investigation
&lt;/h2&gt;

&lt;p&gt;I started digging through the component that made the request - a pretty straightforward React component that used a custom hook to fetch data from the backend.&lt;/p&gt;

&lt;p&gt;The hook looked fine.&lt;br&gt;&lt;br&gt;
No &lt;code&gt;useEffect&lt;/code&gt; shenanigans. No dependencies causing it to run twice.&lt;/p&gt;

&lt;p&gt;But then I noticed the same hook was being used in the &lt;strong&gt;parent&lt;/strong&gt; component &lt;em&gt;and&lt;/em&gt; in the &lt;strong&gt;child&lt;/strong&gt; component.&lt;/p&gt;

&lt;p&gt;The child used it to display a widget.&lt;br&gt;&lt;br&gt;
The parent used it to handle state.&lt;/p&gt;

&lt;p&gt;Both were independently calling the same API - without realizing they were stepping on each other.&lt;/p&gt;

&lt;p&gt;Two components. Same hook.&lt;br&gt;&lt;br&gt;
Two renders. Two calls.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Went Wrong
&lt;/h2&gt;

&lt;p&gt;Technically, nothing was broken. The app wasn’t crashing. The UI looked fine.&lt;br&gt;&lt;br&gt;
But under the hood? It was inefficient, messy, and one step away from becoming a problem.&lt;/p&gt;

&lt;p&gt;This is one of those subtle bugs that doesn't break anything, but just quietly burns your backend and bloats your network usage until someone notices.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Did
&lt;/h2&gt;

&lt;p&gt;I moved the hook to the parent component - the one that logically owned the data - and passed the result down to the child as props.&lt;/p&gt;

&lt;p&gt;No duplication. One fetch. One call.&lt;/p&gt;

&lt;p&gt;Problem gone.&lt;/p&gt;




&lt;h2&gt;
  
  
  What You Can Learn From This
&lt;/h2&gt;

&lt;p&gt;If you're working with React and using custom hooks to fetch data, here's the takeaway:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Don't blindly drop hooks in every component that needs data.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Hooks are just functions. If you call them twice, they’ll run twice. That includes API calls, effects, subscriptions - all of it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here are a few tips I wish I had followed earlier:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Centralize your data fetching
&lt;/h3&gt;

&lt;p&gt;If multiple components need the same data, let one component fetch it and pass it down.&lt;br&gt;&lt;br&gt;
Props still work. It’s not uncool to use them.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Use caching if you &lt;em&gt;must&lt;/em&gt; duplicate
&lt;/h3&gt;

&lt;p&gt;If you're using libraries like &lt;strong&gt;SWR&lt;/strong&gt; or &lt;strong&gt;React Query&lt;/strong&gt;, at least you're not hitting the network twice.&lt;br&gt;&lt;br&gt;
But be intentional about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Watch your tree
&lt;/h3&gt;

&lt;p&gt;It's easy to forget that a child component might also be calling the same logic as its parent - especially if you're reusing hooks across the app.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Trust DevTools
&lt;/h3&gt;

&lt;p&gt;If something feels off, open the Network tab. It doesn't lie.&lt;br&gt;&lt;br&gt;
(It’s also the fastest way to catch dumb mistakes.)&lt;/p&gt;




&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I found an API being called twice.&lt;/li&gt;
&lt;li&gt;It was my fault: I was calling the same hook in both parent and child.&lt;/li&gt;
&lt;li&gt;I moved the fetch to the parent and passed data down.&lt;/li&gt;
&lt;li&gt;Always check for duplicated logic when you see repeated API calls.&lt;/li&gt;
&lt;li&gt;One hook, one call. Don’t let your frontend flood your own backend.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This bug wasn’t big. It didn’t crash anything.&lt;br&gt;&lt;br&gt;
But it taught me a valuable lesson:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes performance issues aren’t about bad code.&lt;br&gt;&lt;br&gt;
They’re about code that &lt;em&gt;looks&lt;/em&gt; fine - but doesn’t respect boundaries.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hooks are powerful. But with great power comes...&lt;br&gt;&lt;br&gt;
Well, extra network calls - if you're not paying attention.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devlog</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>WTF is git cherry-pick?</title>
      <dc:creator>Namit Jain</dc:creator>
      <pubDate>Wed, 30 Jul 2025 17:15:48 +0000</pubDate>
      <link>https://forem.com/namit2111/wtf-is-git-cherry-pick-24o8</link>
      <guid>https://forem.com/namit2111/wtf-is-git-cherry-pick-24o8</guid>
      <description>&lt;p&gt;Ever wished you could steal &lt;em&gt;just one commit&lt;/em&gt; without dragging the entire messy branch with it?&lt;br&gt;&lt;br&gt;
Welcome to Git’s &lt;strong&gt;commit heist tool&lt;/strong&gt;: &lt;code&gt;git cherry-pick&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;What actually happens?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
git cherry-pick &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Git grabs the &lt;strong&gt;diff&lt;/strong&gt; from &lt;code&gt;&amp;lt;commit-hash&amp;gt;&lt;/code&gt; and replays it on &lt;code&gt;main&lt;/code&gt; as a &lt;strong&gt;brand-new commit&lt;/strong&gt;.&lt;br&gt;
Same content, &lt;strong&gt;fresh identity&lt;/strong&gt; (new hash).&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Why you need this&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;✅ &lt;strong&gt;Hotfix emergencies:&lt;/strong&gt; pluck that one bugfix without the noise.&lt;br&gt;
✅ &lt;strong&gt;Selective feature moves:&lt;/strong&gt; steal just the feature you want.&lt;br&gt;
✅ &lt;strong&gt;History hacks:&lt;/strong&gt; clean up messy branches by cherry-picking verified commits.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Pro tip:&lt;/strong&gt; If you need more than 3 commits, merging might be smarter. Don’t over-cherry-pick like a code raccoon.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Anatomy of the output&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
[main 5f8d3e2] Fix typo in README&lt;br&gt;
 Author: teammate &amp;lt;teammate@example.com&amp;gt;&lt;br&gt;
 Date:   Fri Jul 4 17:22:46 2025 +0530&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;5f8d3e2&lt;/code&gt;&lt;/strong&gt; → brand new hash, no shady reuse.&lt;/li&gt;
&lt;li&gt;Message &amp;amp; author? Still carried over for &lt;strong&gt;context clarity&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conflict mode: activate&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Conflicts are inevitable. When they hit:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fix markers (&lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;====&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;) in your favorite editor.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git add &amp;lt;resolved-files&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Continue the drama:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
   git cherry-pick --continue&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;WTF moment:&lt;/strong&gt; Cherry-pick conflicts are like that one friend who says “I’ll be chill” and then flips the table.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Spooked? Reset with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
git cherry-pick --abort&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Back to pre-cherry-pick bliss.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Pro tips&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;✅ Cherry-pick &lt;strong&gt;small, self-contained commits&lt;/strong&gt;. Big ones? Big drama.&lt;br&gt;
✅ Avoid merge commits unless you enjoy pain.&lt;br&gt;
✅ Push right after you pick. Don’t ghost your teammates.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Quick scenario&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Team fixes a critical bug on &lt;code&gt;dev&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Stakeholders demand it on &lt;code&gt;main&lt;/code&gt; &lt;em&gt;right now&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Other commits? Unstable, unreviewed. Nope.&lt;/li&gt;
&lt;li&gt;You pull the heist:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
   git checkout main&lt;br&gt;
   git cherry-pick abc1234&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Customers: happy.&lt;/li&gt;
&lt;li&gt;You: &lt;strong&gt;legend&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;Interactive demo&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Visit &lt;a href="https://www.namitjain.com/blog" rel="noopener noreferrer"&gt;https://www.namitjain.com/blog&lt;/a&gt; for interactive demo&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;TL;DR&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What&lt;/strong&gt;: Steal a commit like Ocean’s Eleven.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
  git cherry-pick &amp;lt;hash&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Why&lt;/strong&gt;: Hotfixes, targeted changes, branch surgery.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🔥 Next WTF:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://dev.to/blog/git-rebase"&gt;&lt;strong&gt;“WTF is &lt;code&gt;git rebase&lt;/code&gt; (and Why It’s Both Magic and Chaos)”&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>WTF is Git Rebase (and Why It’s Both Magic and Chaos)</title>
      <dc:creator>Namit Jain</dc:creator>
      <pubDate>Wed, 30 Jul 2025 17:12:08 +0000</pubDate>
      <link>https://forem.com/namit2111/wtf-is-git-rebase-and-why-its-both-magic-and-chaos-1o04</link>
      <guid>https://forem.com/namit2111/wtf-is-git-rebase-and-why-its-both-magic-and-chaos-1o04</guid>
      <description>&lt;p&gt;So you’ve been happily doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
git merge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;And then someone in your team says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Just rebase it.”&lt;br&gt;
…and you start questioning your life choices.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;WTF Is Git Rebase, Really?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition (boring version):&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;git rebase&lt;/code&gt; is a command that lets you &lt;strong&gt;rewrite the commit history&lt;/strong&gt; by moving or combining commits onto a new base commit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition (WTF version):&lt;/strong&gt;&lt;br&gt;
Rebase is basically telling Git:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yo, take my messy branch, pretend I started working from this new place, and make it look like I always had my sh*t together.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Why Even Bother?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Without rebase:&lt;/strong&gt;&lt;br&gt;
Your history looks like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
main ---A---B---C&lt;br&gt;
...........\&lt;br&gt;
...........D---E (feature)&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you merge:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
main ---A---B---C------merge commit&lt;br&gt;
............\........../&lt;br&gt;
.............D---E-----&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Looks like spaghetti 🍝.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With rebase:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
main ---A---B---C&lt;br&gt;
................\&lt;br&gt;
..................D'---E'&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;(Notice the &lt;code&gt;'&lt;/code&gt;? Those are rebased commits. Same code, different timeline.)&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Actual WTF Command&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Say you’re on &lt;code&gt;feature&lt;/code&gt; branch and want it updated with &lt;code&gt;main&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
git checkout feature&lt;br&gt;
git fetch origin&lt;br&gt;
git rebase origin/main&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Boom. Feature branch now looks like it was based on the latest &lt;code&gt;main&lt;/code&gt; all along.&lt;br&gt;
&lt;em&gt;Congratulations, you’re now a Git historian.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Common Rebase Moves&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Interactive Rebase:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
git rebase -i HEAD~3&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lets you:&lt;br&gt;
✅ squash commits&lt;br&gt;
✅ rename commits&lt;br&gt;
✅ feel like a time-traveling wizard &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Abort if you panic:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
git rebase --abort&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;(&lt;em&gt;You WILL need this.&lt;/em&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Continue after fixing conflicts:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
git add .&lt;br&gt;
git rebase --continue&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;When to Use Rebase vs Merge&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;✅ Use &lt;strong&gt;rebase&lt;/strong&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want a clean history&lt;/li&gt;
&lt;li&gt;You’re working on your own feature branch&lt;/li&gt;
&lt;li&gt;You hate merge commits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;❌ Don’t rebase &lt;strong&gt;shared branches&lt;/strong&gt; (like &lt;code&gt;main&lt;/code&gt;), or you’ll rewrite history and &lt;strong&gt;summon demons&lt;/strong&gt; in your team Slack.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Pros and Cons of Rebasing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;✔ &lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner history&lt;/li&gt;
&lt;li&gt;No merge commits&lt;/li&gt;
&lt;li&gt;Makes you feel pro&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✖ &lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can cause conflicts&lt;/li&gt;
&lt;li&gt;Rewrite history → danger zone&lt;/li&gt;
&lt;li&gt;Makes newbies(me) cry&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Interactive demo
&lt;/h1&gt;

&lt;p&gt;Visit &lt;a href="https://www.namitjain.com/blog/git-rebase" rel="noopener noreferrer"&gt;https://www.namitjain.com/blog/git-rebase&lt;/a&gt; for interactive demo&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;TL;DR WTF&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git merge&lt;/code&gt; = keep the mess&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git rebase&lt;/code&gt; = rewrite history to look clean&lt;/li&gt;
&lt;li&gt;Do it locally, don’t mess with shared branches&lt;/li&gt;
&lt;li&gt;Always have &lt;code&gt;--abort&lt;/code&gt; and coffee ready ☕&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🔥 &lt;strong&gt;Next WTF Episode:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;WTF is &lt;code&gt;git cherry-pick&lt;/code&gt; (and why it ruins friendships)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>git</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Debugging a Segmentation Fault in Python?! Yes, It's Possible (And Here's What I Learned)</title>
      <dc:creator>Namit Jain</dc:creator>
      <pubDate>Tue, 13 May 2025 15:46:24 +0000</pubDate>
      <link>https://forem.com/namit2111/debugging-a-segmentation-fault-in-python-yes-its-possible-and-heres-what-i-learned-52c6</link>
      <guid>https://forem.com/namit2111/debugging-a-segmentation-fault-in-python-yes-its-possible-and-heres-what-i-learned-52c6</guid>
      <description>&lt;p&gt;Let me set the scene: I’m working on a Python app — pretty standard stack, nothing wild. Then out of nowhere...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Segmentation fault.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Wait. What? In Python?&lt;/p&gt;

&lt;p&gt;Yeah. That was my reaction too.&lt;br&gt;
Isn't Python safe from stuff like this?&lt;/p&gt;

&lt;p&gt;Usually, yes. One of the reasons I love Python is because it protects you from low-level memory issues. But here's the catch: if you're using C extensions, or database drivers with native bindings under the hood... the safety net can have holes.&lt;/p&gt;

&lt;p&gt;And that’s exactly what happened to me.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Went Wrong
&lt;/h2&gt;

&lt;p&gt;In my app, I was using mysql-connector-python to talk to a MySQL database. Everything looked fine on the surface.&lt;/p&gt;

&lt;p&gt;But over time, the app would randomly crash with a segfault. No Python stack trace, just a hard exit.&lt;/p&gt;

&lt;p&gt;I was stumped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter: faulthandler + gdb
&lt;/h2&gt;

&lt;p&gt;To investigate, I enabled Python’s built-in faulthandler module to try and catch something useful. I also ran the app with gdb to get a trace of what was going on at the C level.&lt;/p&gt;

&lt;p&gt;And eventually, I found it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The culprit?
&lt;/h2&gt;

&lt;p&gt;Too many open MySQL connections. 😅&lt;/p&gt;

&lt;p&gt;Turns out I was opening a new connection to the database on every single request — but I wasn’t closing them properly. No pooling, no reuse.&lt;/p&gt;

&lt;p&gt;Eventually MySQL hit its connection limit and just bailed — crashing everything along with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fix: Connection Pooling FTW
&lt;/h2&gt;

&lt;p&gt;The solution was (thankfully) pretty straightforward: I implemented a connection pool using mysql.connector.pooling.&lt;/p&gt;

&lt;p&gt;Now the connections are managed properly, reused across requests, and I don’t run out of resources.&lt;/p&gt;

&lt;p&gt;No segfaults. No database freakouts. No angry sysadmins. 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Yes, Python can segfault. Especially when you're using C extensions or native libraries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always manage your database connections carefully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use tools like faulthandler and gdb to dig into the deeper layers when the usual logs don't help.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don’t assume you're immune to low-level bugs just because you're writing high-level code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TL;DR&lt;/p&gt;

&lt;p&gt;If you're seeing weird crashes in Python, especially when working with databases or C extensions — don’t rule out things like memory errors or connection overloads.&lt;/p&gt;

&lt;p&gt;Take the time to investigate. Your future self (and your uptime dashboard) will thank you. 🙌&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building Lip Reading Model. Part-1</title>
      <dc:creator>Namit Jain</dc:creator>
      <pubDate>Mon, 03 Apr 2023 14:09:52 +0000</pubDate>
      <link>https://forem.com/namit2111/building-lip-reading-model-part-1-4i72</link>
      <guid>https://forem.com/namit2111/building-lip-reading-model-part-1-4i72</guid>
      <description>&lt;p&gt;Lip reading, also known as speech reading, is the ability to understand speech by observing a speaker's lip movements and facial expressions. It is a crucial skill for individuals who are deaf or hard of hearing, as well as for those who need to communicate in noisy environments. However, lip reading is a challenging task that requires extensive training and experience, and even then, it can be unreliable due to variations in lip movements and speech patterns.&lt;/p&gt;

&lt;p&gt;Recent advances in machine learning and computer vision have made it possible to develop automatic lip reading systems that can recognize speech from visual cues alone. These systems have numerous applications, from enhancing speech recognition in noisy environments to improving the accessibility of multimedia content for the deaf and hard of hearing.&lt;/p&gt;

&lt;p&gt;In this blog series, we will explore how to build a lip reading model using deep learning techniques. In Part 1, we will cover the basics of lip reading and the dataset we will be using for our model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Lip Reading
&lt;/h2&gt;

&lt;p&gt;Lip reading involves analyzing the movements of the mouth, tongue, and jaw to determine the sounds being produced by a speaker. There are several challenges associated with lip reading, including variations in speech patterns, differences in accent and dialect, and the fact that many sounds are produced inside the mouth and are not visible on the lips.&lt;/p&gt;

&lt;p&gt;Despite these challenges, lip reading is a useful skill that can be learned with practice. It is typically taught using a combination of visual cues, such as the shape of the lips and the movement of the jaw, and contextual cues, such as the topic of conversation and the speaker's body language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dataset
&lt;/h2&gt;

&lt;p&gt;The Grid Corpus dataset is a widely used dataset in the field of lip reading, which contains videos of people speaking a wide range of words. The dataset was created by recording videos of speakers reading out sentences while their faces were tracked using a facial landmark detection algorithm. The dataset contains over 30,000 video clips, each clip corresponding to a spoken sentence.&lt;/p&gt;

&lt;p&gt;The videos in the dataset are captured at a resolution of 640x480 and a frame rate of 25 frames per second. The dataset also includes the corresponding audio for each video clip, as well as the transcriptions of the spoken sentences.&lt;/p&gt;

&lt;p&gt;The Grid Corpus dataset has been used in numerous studies to develop and evaluate lip reading models. Some of the popular models developed using this dataset include LipNet and Watch, Listen, and Spell (WLAS).&lt;/p&gt;

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

&lt;p&gt;In Part 1 of this blog series, we have introduced the concept of lip reading and the dataset we will be using to train our lip reading model. In the next part of the series, we will explore the preprocessing steps required to prepare the Lip Reading dataset for training, including data cleaning and feature extraction. Stay tuned for Part 2!&lt;/p&gt;

</description>
      <category>blog</category>
      <category>machinelearning</category>
      <category>datascience</category>
      <category>python</category>
    </item>
  </channel>
</rss>
