<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tushar Ravindran on Medium]]></title>
        <description><![CDATA[Stories by Tushar Ravindran on Medium]]></description>
        <link>https://medium.com/@iamtusharxo?source=rss-8cf0972ac13f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eFaBVGgtSXXlEkcfUUqv6Q.png</url>
            <title>Stories by Tushar Ravindran on Medium</title>
            <link>https://medium.com/@iamtusharxo?source=rss-8cf0972ac13f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:58:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamtusharxo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Built a Go CLI That Tracks My GitHub Streak and Roasts Me When I Miss a Day]]></title>
            <link>https://iamtusharxo.medium.com/how-i-built-a-go-cli-that-tracks-my-github-streak-and-roasts-me-when-i-miss-a-day-4053498e6a25?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4053498e6a25</guid>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Fri, 03 Jul 2026 21:01:23 GMT</pubDate>
            <atom:updated>2026-07-03T21:01:23.231Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIMiO41t5hqB_tnltP-99w.png" /></figure><blockquote><strong><em>Tech Stack:</em></strong><em> Go • </em><a href="https://github.com/tusharravindran/gitstreak"><em>GitHub</em></a><em> GraphQL API • macOS LaunchAgents • Homebrew • CLI Development</em></blockquote><h3>Installation:</h3><p><a href="https://github.com/tusharravindran/gitstreak">https://github.com/tusharravindran/gitstreak</a></p><blockquote>brew tap tusharravindran/homebrew-devdoctor<br>brew install gitstreak</blockquote><h3>Every Developer Has Good Intentions…</h3><p><em>“I’ll make a commit before I sleep.”</em></p><p>Then a production issue happens Or you binge-watch a show.</p><p>Or you spend six hours debugging a code only to realize you never pushed anything. By the time you remember, it’s <strong>12:03 AM</strong>. Your GitHub contribution streak is gone.</p><p>If you’re someone who enjoys maintaining a GitHub streak — not because of vanity, but because it encourages consistent learning — you’ve probably experienced this.I certainly have.</p><p>So instead of relying on memory, I built something that remembers for me.</p><p>Meet <strong>gitstreak</strong>.</p><h3>What is gitstreak?</h3><p><a href="https://github.com/tusharravindran/gitstreak">gitstreak</a> is a lightweight CLI written in Go that watches your GitHub contribution streak and reminds you before it&#39;s too late.</p><p>But it doesn’t just remind you.</p><p>It <strong>judges you.</strong></p><p>If you’ve already broken your streak…</p><p>It roasts you. Sometimes politely. Sometimes not.</p><h3>Features</h3><ul><li>Track your GitHub contribution streak</li><li>Daily reminders before your configured time</li><li>Native macOS notifications</li><li>Voice alerts using macOS say</li><li>Automatic background scheduling with LaunchAgents</li><li>Zero external dependencies</li><li>Homebrew installation</li></ul><h3>Demo</h3><p>Checking your streak is as simple as:</p><pre>GITHUB_TOKEN=$(gh auth token) gitstreak notify-check - username</pre><p>Add your token and Username to .~/zshrc and Configure a reminder:</p><pre>gitstreak config --reminder-time 21:00</pre><p>Start watching:</p><pre>gitstreak watch --username your-github-username</pre><p>That’s it.</p><p>No GUI. No browser extensions. No app. Just a tiny Go binary that does one thing well.</p><h3>Under the Hood</h3><p>Let’s look at how it works.</p><h3>1. Fetching GitHub Contributions</h3><p>Instead of scraping GitHub pages (which can easily break), gitstreak uses the official <strong>GitHub GraphQL API</strong>.</p><p>Specifically, it queries the contributionsCollection endpoint.</p><p>This provides:</p><ul><li>Daily contributions</li><li>Contribution calendar</li><li>Current streak</li><li>Historical contribution data</li></ul><p>Using the official API makes the tool reliable, faster, and future-proof compared to HTML scraping.</p><h3>2. Native macOS Scheduling with LaunchAgents</h3><p>One of my favorite discoveries while building this project was <strong>launchd</strong>.</p><p>Most developers immediately think of cron jobs, but macOS already provides a powerful native scheduler.</p><p>Running:</p><pre>gitstreak watch</pre><p>automatically creates a LaunchAgent inside:</p><pre>~/Library/LaunchAgents/</pre><p>The CLI loads it automatically.</p><p>No background daemon.</p><p>No tray application.</p><p>No constantly running process.</p><p>At the configured time, macOS launches:</p><pre>gitstreak notify-check</pre><p>checks your streak, sends a notification if required, and exits.</p><p>Exactly how a native macOS utility should behave.</p><h3>3. Native Notifications</h3><p>Rather than introducing another dependency, gitstreak simply leverages macOS itself.</p><p>Using Go’s os/exec, it calls:</p><pre>script := fmt.Sprintf(<br>    `display notification &quot;%s&quot; with title &quot;%s&quot; sound name &quot;Funk&quot;`,<br>    message,<br>    title,<br>)</pre><pre>exec.Command(&quot;osascript&quot;, &quot;-e&quot;, script).Run()</pre><p>This produces clean native notifications that look and behave exactly like notifications from built-in macOS applications.</p><h3>4. Voice Alerts</h3><p>This ended up becoming my favorite feature.</p><p>If your streak has already been broken…</p><p>The CLI literally talks to you.</p><pre>say &quot;Your GitHub streak is dead.&quot;</pre><p>Having Samantha remind you that you’ve abandoned your GitHub streak somehow feels much more effective than another ignored notification.</p><h3>5. The Roast Engine</h3><p>A standard reminder saying:</p><blockquote><em>“Don’t forget to commit.”</em></blockquote><p>is easy to ignore. So I decided to give the tool a little personality.</p><p>The longer you’ve ignored GitHub, the harsher the messages become.</p><p>The roast system is built using Go’s text/template package with multiple severity levels.</p><ul><li>Miss one day → Friendly reminder.</li><li>Miss several days → Increasingly brutal.</li></ul><p>The goal isn’t to shame people. It’s to make notifications memorable enough that you actually act on them.</p><h3>Final Thoughts</h3><p><em>Consistency beats intensity.</em></p><p>One meaningful commit every day is better than disappearing for weeks and trying to catch up later.</p><p>GitHub streaks aren’t a measure of engineering ability, but they are a simple way to build the habit of shipping, learning, and improving consistently.</p><p>If you’ve ever lost a streak simply because you forgot to push your code before midnight, I hope <strong>gitstreak</strong> helps.</p><p>And if you haven’t lost one yet…Install it anyway.</p><p>Tomorrow might be the day you need the reminder.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4053498e6a25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to not run migration on your production Rails App]]></title>
            <link>https://iamtusharxo.medium.com/i-locked-my-database-and-took-down-production-8a4ab83921cb?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a4ab83921cb</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[production-deployment]]></category>
            <category><![CDATA[zero-downtime]]></category>
            <category><![CDATA[migration]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Thu, 15 Jan 2026 17:57:25 GMT</pubDate>
            <atom:updated>2026-03-01T17:15:12.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*SQugc9O18Uc4L1XvQlb-zQ.png" /></figure><p>This was a story of just a column. A harmless little add_column.</p><p>What could possibly go wrong?</p><p>Everything went wrong — and the worst part was that <strong>nothing failed immediately</strong>.</p><p>Instead, things just started getting… slow.</p><p>A few minutes later, <a href="https://www.datadoghq.com/">Datadog</a> lit up with a sharp spike in database usage. Query latency climbed.</p><p>Application was alive, but unusable.</p><h3>How One Migration Turned Into a Production Incident</h3><p>Everything was fine, until one day you run this in production:</p><pre>ALTER TABLE assesments ADD COLUMN status text DEFAULT &#39;pending&#39;;</pre><p>And suddenly:</p><ul><li>Requests stop responding</li><li>Background jobs freeze</li><li>Slack starts blinking with alerts</li><li>Someone types: <em>“Is prod down?”</em></li></ul><p>Congratulations.<br>You just learned about <strong>table locks</strong>.</p><h3>“But I Only Touched One Row!”</h3><p>the most common developer misconception. Right after <em>“It worked on my machine.😅”</em></p><pre>SELECT * FROM orders WHERE status = &#39;pending&#39; FOR UPDATE;</pre><p>What you <em>think</em> this does:</p><blockquote><em>“I’m locking one row. Chill.”</em></blockquote><p>What the database hears:</p><blockquote><em>“I’d like to claim ownership of half the table and hold it hostage while I call an external API.”</em></blockquote><p>Technically, yes — <strong>only the matching rows are locked</strong>.<br>Practically? If 80% of your table is pending, you’ve just soft-locked the system.</p><p>It’s not illegal. It’s just… rude bro 👊.</p><h3>The Illusion of “It’s Just a Migration”</h3><p>Let me translate migrations into plain English.</p><p>This is fine:</p><pre>add_column :orders, :processed_at, :datetime</pre><p>This is how outages are born:</p><pre>add_column :orders, :status, :string, default: &quot;pending&quot;, null: false</pre><p>Why?</p><p>Because databases don’t magically invent data.<br>They <strong>rewrite every row</strong>.</p><p>On a large table, this means:</p><ul><li>Full table rewrite</li><li>Exclusive lock</li><li>No reads, No writes</li></ul><h3>The Senior Engineer Rulebook (Unofficial)</h3><p>After enough incidents, you learn a few rules:</p><ol><li><strong>Migrations are operational changes, not code changes</strong></li><li><strong>Lock rows to decide who works, not to do the work</strong></li><li><strong>If a change touches existing rows, assume it can break prod</strong></li></ol><blockquote>Print this. Tattoo it.<br>Or at least remember it before running rails db:migrate.</blockquote><h3>Quick Summary of what I Actually Learned the Hard Way</h3><h3>1. Renaming a Column Is NOT Harmless</h3><p>This looks innocent:</p><pre>ALTER TABLE orders RENAME COLUMN foo TO bar;</pre><p>What it really is:</p><ul><li>A <strong>schema change</strong></li><li>Requires a <strong>lock</strong></li><li>Can break running code if deployed carelessly</li></ul><h4>The safe way (zero-downtime pattern):</h4><ol><li>Add the new column</li><li>Backfill it</li><li>Switch application code</li><li>Drop the old column later</li></ol><p>Never rename directly in production unless:</p><ul><li>Traffic is low</li><li>You accept brief lock risk or the users are asleep</li></ul><h3>2. Backfilling Is a Process, Not a Query</h3><p>This is how juniors backfill:</p><pre>UPDATE orders SET status = &#39;pending&#39;;</pre><p>This is how outages are born.</p><h4>The correct way:</h4><ul><li>Backfill <strong>in batches</strong></li><li>Keep transactions <strong>small</strong></li><li>Avoid long locks</li></ul><p>Example:</p><pre>UPDATE assessment<br>SET new_status = old_status<br>WHERE new_status IS NULL<br>LIMIT 1000;</pre><p>Repeat via:</p><ul><li>Background jobs</li><li>Cron</li><li>One-off scripts</li></ul><h3>3. Defaults + NOT NULL = Hidden Table Rewrite</h3><p>This Rails migration looks clean:</p><pre>add_column :orders, :status, :string, default: &quot;pending&quot;, null: false</pre><p>What it actually does:</p><ul><li>Rewrites <strong>every row</strong></li><li>Holds an exclusive lock</li><li>Blocks the table</li></ul><h4>Safe pattern:</h4><ol><li>Add column <strong>nullable</strong></li><li>Backfill</li><li>Add constraint later</li><li>Databases hate shortcuts.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a4ab83921cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Powerful Search to Your App with Elasticsearch ]]></title>
            <link>https://iamtusharxo.medium.com/add-powerful-search-to-your-app-with-elasticsearch-0056b00dcdf0?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/0056b00dcdf0</guid>
            <category><![CDATA[search-system]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Sun, 11 Jan 2026 09:23:40 GMT</pubDate>
            <atom:updated>2026-01-11T09:23:40.967Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*4eAVZoRho1asaIX9" /></figure><p>Search is one of those features users never compliment.</p><p>But the moment it’s bad?<br>They notice. Immediately. Loudly. And usually in the form of <em>“your app is broken”</em>.</p><p>Slow results. Missed matches. One typo and suddenly <em>“No results found”</em>. That’s when users mentally uninstall your product — even if they don’t physically click the button.</p><p>This is where traditional database search starts sweating… and <strong>Elasticsearch (or OpenSearch)</strong> steps in.</p><p>Let’s talk about <strong>why Elasticsearch exists</strong>, <strong>when you should use it</strong>, and <strong>when you absolutely should not</strong>.</p><h3>Why Database Search Starts Betraying You</h3><p>Relational databases are great. Truly.<br>They are excellent at:</p><ul><li>Transactions</li><li>Constraints</li><li>Keeping your data safe and consistent</li></ul><p>They are <strong>not</strong> great at being Google.</p><p>Once you need things like:</p><ul><li>Relevance ranking (“best result”, not just <em>any</em> result)</li><li>Typo tolerance (because users type like humans, not compilers)</li><li>Partial matches</li><li>Language-aware search</li><li>Fast results across large datasets</li></ul><p>Yes, you <em>can</em> hack it with ILIKE, trigram indexes, and prayers — but it gets ugly fast.</p><h3>What Elasticsearch Is Actually Good At</h3><p>Elasticsearch is built on <strong>Apache Lucene</strong>, which is designed for one thing:</p><p><strong>Finding the right text, quickly, at scale.</strong></p><h3>1. Relevance That Makes Sense</h3><p>Elasticsearch doesn’t just ask:</p><blockquote><em>“Does this match?”</em></blockquote><p>It asks:</p><blockquote><em>“How good is this match?”</em></blockquote><p>That means:</p><ul><li>Exact matches rank higher</li><li>Important fields matter more</li><li>Results feel intentional, not random</li><li>Your users stop scrolling angrily. That’s a win.</li></ul><h3>2. Typo Tolerance (We’re Just Human — Typos Are Inevitable)</h3><p>Users will type:</p><ul><li>javscript</li><li>manger</li><li>recieve</li></ul><p>Elasticsearch doesn’t judge 😭.<br>It just finds the result anyway.</p><p>Fuzzy matching and edit distance mean:</p><ul><li>Fewer “no results”</li><li>More successful searches</li><li>Happier users who think your app is “smart”</li></ul><h3>3. Speed at Scale (No Drama)</h3><p>Elasticsearch is <strong>distributed by design</strong>.</p><p>It:</p><ul><li>Splits data into shards</li><li>Searches them in parallel</li><li>Returns results in milliseconds — even with millions of documents</li></ul><p>This is why it powers:</p><ul><li>Search-heavy SaaS products</li><li>Observability platforms</li><li>Anything where speed actually matters</li></ul><h3>4. Search That’s More Than Text</h3><p>Real search isn’t just text — it’s filters, facets, and ranking logic.</p><p>Elasticsearch supports:</p><ul><li>Filters and ranges</li><li>Aggregations</li><li>Boolean queries</li><li>Phrase matching</li><li>Field-level boosting</li></ul><p>All without turning your query into a 200-line SQL monster 😅.</p><h3>When Elasticsearch Is a Great Idea</h3><p>Elasticsearch (or OpenSearch) makes sense when:</p><ul><li>Search is a <strong>core feature</strong>, not a checkbox</li><li>Users expect “Google-like” behavior</li><li>Your data is large (or about to be)</li><li>Relevance and ranking actually matter</li><li>Reads massively outnumber writes</li><li>Eventual consistency is acceptable</li></ul><p>Common real-world use cases:</p><ul><li>SaaS search</li><li>Resume or document search</li><li>Logs and monitoring</li><li>Product catalogs</li><li>Content platforms</li></ul><h3>When Elasticsearch Is a Terrible Idea</h3><p>Let’s be honest — Elasticsearch is not always the answer.</p><p>Avoid it when:</p><ul><li>You have a small dataset</li><li>A simple SQL query works fine</li><li>You need strict transactional guarantees</li><li>Your team can’t operate distributed systems</li><li>You’re secretly trying to replace your database (please don’t)</li></ul><p>Elasticsearch should <strong>support your database</strong>, not become your database.</p><h3>Elasticsearch vs OpenSearch (The Short Version)</h3><p>Technically? Very similar.</p><p><strong>Elasticsearch</strong></p><ul><li>Mature ecosystem</li><li>Commercial features</li><li>Licensing constraints</li></ul><p><strong>OpenSearch</strong></p><ul><li>Fully open source</li><li>AWS-backed</li><li>Rapidly improving</li></ul><p>Most teams choose based on <strong>licensing, hosting, and cost</strong>, not features.</p><h3>The Biggest Mistake Teams Make</h3><p>The most common mistake?</p><p>Adding Elasticsearch <strong>too early</strong> or <strong>without a plan</strong>.</p><p>Bad search systems:</p><ul><li>Dump data into Elasticsearch</li><li>Hope relevance magically works</li><li>Never tune queries</li><li>Never monitor performance</li></ul><p>Good search systems:</p><ul><li>Design indexes intentionally</li><li>Tune relevance over time</li><li>Monitor and iterate</li><li>Treat search as a product feature</li></ul><h3>Final Thoughts</h3><p>Elasticsearch and OpenSearch are powerful tools — but only when used intentionally.</p><p>They shine when:</p><ul><li>Search quality matters</li><li>Scale is unavoidable</li><li>User experience depends on relevance</li></ul><p>They hurt when:</p><ul><li>Added prematurely</li><li>Used as databases</li><li>Operated without understanding</li></ul><p>To state simply,</p><blockquote>Used correctly, they make users fall in love with your product .<br>Used poorly, they become expensive servers everyone is afraid to touch.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0056b00dcdf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency in Golang: Writing Scalable Code Without Overengineering]]></title>
            <link>https://iamtusharxo.medium.com/concurrency-in-golang-writing-scalable-code-without-overengineering-620d51743f9d?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/620d51743f9d</guid>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Thu, 08 Jan 2026 15:37:35 GMT</pubDate>
            <atom:updated>2026-01-08T15:37:35.007Z</atom:updated>
            <content:encoded><![CDATA[<p>Concurrency is one of the most important concepts in backend development — and also one of the most misunderstood. Golang approaches concurrency not as a complex abstraction, but as a practical mechanism to build scalable, readable, and maintainable systems.</p><p>This article explains how Golang enables effective concurrency while keeping code simple and predictable.</p><h3>Goroutines: Lightweight by Design</h3><p>Concurrency in Go starts with goroutines. Unlike operating system threads, goroutines are lightweight and managed by the Go runtime.</p><pre>go processRequest(req)</pre><p>Creating thousands of goroutines is common and efficient. This allows applications to:</p><ul><li>Handle multiple requests concurrently</li><li>Execute background tasks without blocking</li><li>Scale with minimal runtime overhead</li><li>Goroutines make concurrency accessible without forcing developers to manage low-level threading concerns.</li></ul><h3>Channels: Communicating, Not Sharing Memory</h3><p>Go promotes communication between goroutines using channels instead of shared memory.</p><pre>results := make(chan int)<br>go func() {<br>    results &lt;- compute()<br>}()<br>value := &lt;-results</pre><p>This approach:</p><ul><li>Reduces race conditions</li><li>Makes data flow explicit</li><li>Improves code readability and safety</li><li>By structuring concurrency around communication, Go encourages predictable and maintainable designs.</li></ul><h3>Select: Coordinating Multiple Operations</h3><p>The select statement allows a goroutine to wait on multiple channel operations.</p><pre>select {<br>case msg := &lt;-ch1:<br>    handle(msg)<br>case &lt;-time.After(time.Second):<br>    timeout()<br>}</pre><p>This is commonly used for:</p><ul><li>Handling timeouts</li><li>Coordinating multiple asynchronous operations</li><li>Implementing retries or fallbacks</li><li>select enables clean control flow in concurrent logic without complex state handling.</li></ul><h3>Common Pitfalls to Avoid</h3><p>Concurrency is powerful, but incorrect usage can introduce unnecessary complexity.</p><p>Common mistakes include:</p><ul><li>Launching goroutines without proper lifecycle management</li><li>Forgetting to close channels</li></ul><p>Well-written Go code prioritizes clarity and simplicity over clever abstractions.</p><h3>When to Use Concurrency — and When Not To</h3><p>Concurrency should address a real problem, not add overhead.</p><p>Use concurrency when:</p><ul><li>Tasks are I/O-bound</li><li>Work can be parallelized</li><li>System responsiveness is critical</li></ul><p>Concurrency should solve real problems, not create new ones.</p><p>Avoid concurrency when:</p><ul><li>The logic is simple and sequential, and adding goroutines would only make future-you regret past-you’s decisions.</li><li>The performance gain is marginal, but the debugging effort involves staring at logs at 2 a.m. wondering which goroutine went rogue.</li><li>The problem works perfectly fine with straightforward, readable code — and concurrency would only impress no one except your debugger.</li><li>Sometimes, the most mature engineering decision is choosing <strong>not</strong> to use concurrency at all 😂.</li></ul><h3>Conclusion</h3><p>Golang’s concurrency model succeeds because it balances power with simplicity. Goroutines, channels, and clear conventions allow developers to build scalable systems without unnecessary abstraction.</p><p>Effective concurrency in Go is not about doing more work in parallel — it is about structuring programs so they remain clean, reliable, and easy to reason about.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=620d51743f9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern CSS Tricks for a Responsive Web Design (Without Media Query for all View Ports and JS)]]></title>
            <link>https://iamtusharxo.medium.com/modern-css-tricks-for-a-responsive-web-design-without-media-query-for-all-view-ports-and-js-13a095a5155a?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/13a095a5155a</guid>
            <category><![CDATA[responsive-web-design]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[media-queries]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 08:06:02 GMT</pubDate>
            <atom:updated>2025-03-02T08:11:28.336Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*I2Rayw4Z09e62tY_" /></figure><p>CSS has evolved significantly, enabling developers to create highly responsive and dynamic designs without relying on JavaScript and Media Query for all View Ports. In this blog, we will explore modern CSS techniques, including the calc(), min() and clamp() functions, the aspect-ratio property, and methods for making images, padding, and font sizes fully responsive.</p><h3>CSS Solutions Without JavaScript</h3><p>Modern CSS offers powerful features that reduce the need for JavaScript in many cases. These include:</p><ul><li>CSS Grid and Flexbox for dynamic layouts</li><li>CSS Variables (--var) for theming</li><li>CSS Animations and Transitions for interactivity</li><li>CSS Functions (min(), max(), clamp()) for adaptive styles</li></ul><p>These features allow developers to create fluid, interactive designs without additional scripting.</p><h3>Responsive Web Design with CSS</h3><p>A truly responsive website adapts seamlessly to different screen sizes and devices. Below are some CSS techniques to achieve this.</p><h3>Using min(), max(), and clamp() for Flexible Sizing</h3><p>The min(), max(), and clamp() functions allow for flexible layouts that adapt to different screen sizes.</p><p><strong>The </strong><strong>min() function:</strong> Selects the smallest value.</p><pre>.box {<br>    width: min(50vw, 500px); /* The box will be at most 500px but shrink if the viewport is smaller */<br>}</pre><p><strong>The </strong><strong>max() function:</strong> Selects the largest value.</p><pre>.box {<br>    width: max(200px, 10vw); /* Ensures the box is at least 200px wide */<br>}</pre><p><strong>The </strong><strong>clamp() function:</strong> Defines a range of possible values.</p><pre>.box {<br>    font-size: clamp(16px, 2vw, 24px); /* Font size stays between 16px and 24px */<br>}</pre><p>This ensures typography and layout adapt effectively across different screens.</p><h3>Aspect-Ratio Property for Maintaining Proportions</h3><p>The aspect-ratio property helps maintain a consistent width-to-height ratio for elements, eliminating the need for additional padding calculations or JavaScript.</p><pre>.img-container {<br>    width: 100%;<br>    aspect-ratio: 16 / 9; /* Maintains a 16:9 aspect ratio */<br>}</pre><p>This property ensures that images and other elements scale proportionally across various devices.</p><h3>Making Images Responsive</h3><p>To ensure images scale correctly across different devices, use the following CSS rule:</p><pre>img {<br>    max-width: 100%;<br>    height: auto;<br>}</pre><p>This prevents images from overflowing their containers and ensures they resize properly for different screen sizes.</p><p>Using aspect ratio to make them not 16 / 9 and 1/1 and 9/16 with appropriate <em>object-fit </em>would make the image more responsive according to the screen size responsiveness</p><h3>Making Padding Responsive</h3><p>Using clamp(), vw, or em units allows padding to adjust dynamically.</p><pre>.container {<br>    padding: clamp(10px, 2vw, 30px); /* Adjusts based on viewport size */<br>}</pre><p>This approach maintains consistent spacing without requiring media queries.</p><p>here 2 vw is the preferred the padding , when you zoom in the browser you can see the padding not reflected , so use like this</p><pre>.container {<br>    padding: clamp(10px, calc(1vw + 1rem) , 30px); /* Adjusts based on viewport size */<br>}</pre><h3>Making Font Sizes Responsive</h3><p>Using clamp(), vw, or em units allows fonts to scale effectively across devices.</p><pre>h1 {<br>    font-size: clamp(1.5rem, calc(4vw + 1rem), 3rem);<br>}</pre><p>This ensures typography remains readable across different screen sizes without requiring separate styles for mobile, tablet, and desktop views.</p><h3>Conclusion</h3><p>By leveraging properties like aspect-ratio, min(), max(), and clamp(), developers can build adaptive web experiences that perform well on all screen sizes without using media Query for All View ports.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13a095a5155a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding React useState and Common Mistakes ⛳️]]></title>
            <link>https://iamtusharxo.medium.com/understanding-react-usestate-and-common-mistakes-%EF%B8%8F-06e55a533e47?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/06e55a533e47</guid>
            <category><![CDATA[usestate]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hooks-in-react]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[common-mistakes]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Tue, 21 May 2024 06:27:57 GMT</pubDate>
            <atom:updated>2024-05-21T06:27:57.015Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Da38xZukvws-cevT.png" /></figure><p>React’s useState hook is fundamental for managing state in functional components. Despite its simplicity, developers often make mistakes that can lead to bugs or inefficient code. This article will provide a deep dive into useState, illustrate common mistakes, and demonstrate best practices with example code.</p><h3>What is useState?</h3><p>useState is a hook that allows you to add state to functional components. It returns an array with two elements: the current state and a function to update that state.</p><h3>Basic Usage</h3><pre>import React, { useState } from &#39;react&#39;;<br>function Counter() {<br>  const [count, setCount] = useState(0);<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Current Count: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default Counter;</pre><p>In this example, count is the state variable, and setCount is the function to update count.</p><h3>Common Mistakes with useState</h3><h3>1. Initial State Misconceptions</h3><p>Mistake: Assuming the initial state will update dynamically based on props or other variables.</p><p><strong>Example</strong>:</p><pre>function Timer({ initialSeconds }) {<br>  const [seconds, setSeconds] = useState(initialSeconds);<br>// ...<br>  return &lt;div&gt;Seconds: {seconds}&lt;/div&gt;;<br>}</pre><p><strong>Explanation</strong>:</p><p>initialSeconds is only used when the component mounts. Changes to initialSeconds after the initial render do not affect seconds.</p><p><strong>Solution</strong>:</p><p>Use a side effect (e.g., useEffect) to update the state when initialSeconds changes.</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br>function Timer({ initialSeconds }) {<br>  const [seconds, setSeconds] = useState(initialSeconds);<br>  useEffect(() =&gt; {<br>    setSeconds(initialSeconds);<br>  }, [initialSeconds]);<br>  // ...<br>  return &lt;div&gt;Seconds: {seconds}&lt;/div&gt;;<br>}</pre><h3>2. Not Using Functional Updates</h3><p>Mistake: Updating state based on the previous state without using the functional form.</p><p><strong>Example</strong>:</p><pre>const [count, setCount] = useState(0);<br>const handleIncrement = () =&gt; {<br>  setCount(count + 1);<br>};</pre><p><strong>Explanation</strong>:</p><p>This can lead to bugs if handleIncrement is called multiple times quickly, as the state updates might be batched.</p><p><strong>Solution</strong>:</p><p>Use the functional form of setState to ensure updates are based on the latest state.</p><pre>const handleIncrement = () =&gt; {<br>  setCount((prevCount) =&gt; prevCount + 1);<br>};</pre><h3>3. Updating State with Object Spread</h3><p>Mistake: Incorrectly updating objects or arrays in state.</p><p><strong>Example</strong>:</p><pre>const [user, setUser] = useState({ name: &#39;John&#39;, age: 30 });<br>const updateAge = () =&gt; {<br>  user.age = 31;<br>  setUser(user);<br>};</pre><p><strong>Explanation</strong>:</p><p>Directly mutating the state object and then setting it with setState does not trigger a re-render.</p><p><strong>Solution</strong>:</p><p>Create a new object when updating the state.</p><pre>const updateAge = () =&gt; {<br>  setUser((prevUser) =&gt; ({ ...prevUser, age: 31 }));<br>};</pre><h3>4. Inefficient State Updates in Loops or Callbacks</h3><p>Mistake: Performing state updates inside loops or callbacks inefficiently.</p><p>Example:</p><pre>const [items, setItems] = useState([]);<br>const addItem = (newItem) =&gt; {<br>  setItems([...items, newItem]);<br>};</pre><p><strong>Explanation</strong>:</p><p>If addItem is called frequently, this approach can lead to performance issues.</p><p>Solution:</p><p>Use functional updates for better performance</p><pre>const addItem = (newItem) =&gt; {<br>  setItems((prevItems) =&gt; [...prevItems, newItem]);<br>};</pre><h3>5. Ignoring State Initialisation with Functions</h3><p>Mistake: Using a complex initial state calculation directly in useState.</p><p>Example:</p><pre>const [expensiveState] = useState(someExpensiveFunction());</pre><p>Explanation:</p><p>someExpensiveFunction() runs on every render, not just the initial render.</p><p>Solution:</p><p>Pass a function to useState to ensure the calculation runs only once.</p><pre>const [expensiveState] = useState(() =&gt; someExpensiveFunction());</pre><p>By Understanding and avoiding common mistakes , useState can greatly improve your React code. By following best practices and leveraging the full power of functional updates, you can write more efficient, bug-free components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06e55a533e47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Redux: Managing State in Modern JavaScript Applications]]></title>
            <link>https://iamtusharxo.medium.com/introduction-to-redux-managing-state-in-modern-javascript-applications-37c00e7dd0d7?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/37c00e7dd0d7</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[application]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Wed, 15 May 2024 04:31:01 GMT</pubDate>
            <atom:updated>2024-05-15T04:31:01.675Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m_U-QVWuZdU1Fke1.png" /><figcaption>Redux-React</figcaption></figure><p>In modern JavaScript applications, managing state can become a challenging task, especially as applications grow in size and complexity. Redux is a popular library that provides a predictable state container for JavaScript apps. It helps you manage state consistently across your application, making it easier to develop and debug.</p><h4>Core Concepts of Redux</h4><p>To understand Redux, it’s essential to grasp its core concepts:</p><ul><li><strong>Store</strong>: The store holds the entire state of your application. It is created using the createStore function.</li><li><strong>Actions</strong>: Actions are plain JavaScript objects that describe changes in the state. They have a type property that indicates the type of action being performed.</li><li><strong>Reducers</strong>: Reducers are pure functions that take the <strong>current state and an action, and return a new state</strong>. They determine how the state should change in response to an action.</li><li><strong>Dispatch</strong>: The dispatch function sends an action to the store. The store then passes the action to the reducer to update the state.</li><li><strong>Selectors</strong>: Selectors are functions that extract specific pieces of data from the state.</li></ul><h4>Setting Up a Basic Redux App</h4><p>We’ll create a basic app that manages a simple counter. This app will showcase all the basic concepts of Redux.</p><blockquote>Step 1: Setting Up the Project</blockquote><p>First, create a new React project using Create React App:</p><pre>npx create-react-app redux-counter-app<br>cd redux-counter-app</pre><p>Next, install Redux and React-Redux:</p><pre>npm install redux react-redux</pre><blockquote>Step 2: Creating Actions</blockquote><p>In the src folder, create a new directory called redux. Inside this directory, create a file named actions.js:</p><pre>// src/redux/actions.js<br>export const INCREMENT = &#39;INCREMENT&#39;;<br>export const DECREMENT = &#39;DECREMENT&#39;;<br>export const increment = () =&gt; ({<br>  type: INCREMENT,<br>});<br>export const decrement = () =&gt; ({<br>  type: DECREMENT,<br>});</pre><blockquote>Step 3: Creating Reducers</blockquote><p>Next, create a file named reducers.js in the redux directory:</p><pre>// src/redux/reducers.js<br>import { INCREMENT, DECREMENT } from &#39;./actions&#39;;<br>const initialState = {<br>  count: 0,<br>};<br>const counterReducer = (state = initialState, action) =&gt; {<br>  switch (action.type) {<br>    case INCREMENT:<br>      return {<br>        ...state,<br>        count: state.count + 1,<br>      };<br>    case DECREMENT:<br>      return {<br>        ...state,<br>        count: state.count - 1,<br>      };<br>    default:<br>      return state;<br>  }<br>};<br>export default counterReducer;</pre><blockquote>Step 4: Creating the Store</blockquote><p>Now, create a file named store.js in the redux directory:</p><pre>// src/redux/store.js<br>import { createStore } from &#39;redux&#39;;<br>import counterReducer from &#39;./reducers&#39;;<br>const store = createStore(counterReducer);<br>export default store;</pre><blockquote>Step 5: Connecting React with Redux</blockquote><p>In the src folder, modify index.js to connect the React app with the Redux store:</p><pre>// src/index.js<br>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;./redux/store&#39;;<br>import App from &#39;./App&#39;;<br>ReactDOM.render(<br>  &lt;Provider store={store}&gt;<br>    &lt;App /&gt;<br>  &lt;/Provider&gt;,<br>  document.getElementById(&#39;root&#39;)<br>);</pre><blockquote>Step 6: Creating the Counter Component</blockquote><p>Create a Counter.js file in the src folder:</p><pre>// src/Counter.js<br>import React from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { increment, decrement } from &#39;./redux/actions&#39;;<br>const Counter = () =&gt; {<br>  const count = useSelector(state =&gt; state.count);<br>  const dispatch = useDispatch();<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Counter: {count}&lt;/h1&gt;<br>      &lt;button onClick={() =&gt; dispatch(increment())}&gt;Increment&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch(decrement())}&gt;Decrement&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br>export default Counter;</pre><blockquote>Step 7: Integrating the Counter Component</blockquote><p>Finally, update App.js to include the Counter component:</p><pre>// src/App.js<br>import React from &#39;react&#39;;<br>import Counter from &#39;./Counter&#39;;<br>const App = () =&gt; (<br>  &lt;div&gt;<br>    &lt;Counter /&gt;<br>  &lt;/div&gt;<br>);<br>export default App;</pre><h3>D<strong>etailed Explanation</strong></h3><p>The store is the central hub of a Redux application. It holds the entire state of the app and provides a few methods to interact with that state:</p><ul><li><strong>getState</strong>(): Returns the current state of the app.</li><li><strong>dispatch</strong>(action): Sends an action to the store to change the state.</li><li><strong>subscribe</strong>(listener): Registers a function to be called whenever an action is dispatched</li></ul><p>In our example, we created the store in store.js using createStore and passed in our counterReducer</p><p>In our counterReducer, we handle two actions: INCREMENT and DECREMENT</p><p>In our actions.js file, we defined two action types and two action creators type : INCREMENT and DECREMENT</p><p>In our Counter.js component, we use the useDispatch hook to get the dispatch function and use it to send increment and decrement actions</p><p>ie: <strong><em>dispatch(increment())</em></strong></p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSm41vsmOWPh8Cref9hFxw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37c00e7dd0d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bash Text Manipulation: Essential Techniques and Tips]]></title>
            <link>https://iamtusharxo.medium.com/bash-text-manipulation-essential-techniques-and-tips-92b3166911c8?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/92b3166911c8</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[commands]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[bash-script]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Mon, 01 Apr 2024 04:24:50 GMT</pubDate>
            <atom:updated>2024-04-01T04:24:50.661Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/225/0*APPDkAmQ4oCGRAtv" /></figure><p><strong>Introduction</strong>:</p><p>In the world of command-line interface (<strong>CLI</strong>) tools, mastering text manipulation with Bash is a fundamental skill for any Linux user, sysadmin, or programmer. From simple tasks like searching and replacing text to more complex operations like pattern matching and formatting,</p><ol><li><strong>cat</strong></li></ol><p>Description: cat is a command-line utility for concatenating files and printing their contents to the standard output.</p><p><strong>Example Content File (text.txt):</strong></p><pre>Hello, world!</pre><p><strong>Command:</strong></p><pre>cat text.txt</pre><p><strong>Result:</strong></p><pre>Hello, world!</pre><p>These examples demonstrate how each text manipulation command can be used to perform specific operations on text files or streams, allowing for efficient text processing and manipulation in the terminal</p><p><strong>2. sed</strong></p><p>Description: sed is a stream editor used for filtering and transforming text. It’s commonly used for substitution, deletion, insertion, and other text manipulations.</p><p><strong>Example Content File (file.txt):</strong></p><pre>This is old an old line.</pre><p><strong>Command:</strong></p><pre>sed &#39;s/old/new/&#39; file.txt</pre><p><strong>Result:</strong></p><pre>This is new an new line.</pre><p><strong>3. grep</strong></p><p>Description: grep is a command-line utility for searching plain-text data sets for lines that match a specified pattern or regular expression.</p><p><strong>Example Content File (logfile.txt):</strong></p><pre>Error: Connection timed out<br>Warning: Disk space low</pre><p><strong>Command:</strong></p><pre>grep &#39;error&#39; logfile.txt</pre><p><strong>Result:</strong></p><pre>Error: Connection timed out</pre><p><strong>4. sort</strong></p><p>Description: sort is a command-line utility for sorting lines of text files alphabetically or numerically.</p><p><strong>Example Content File (names.txt):</strong></p><pre>Bob<br>Alice<br>Carol</pre><p><strong>Command:</strong></p><pre>sort names.txt</pre><p><strong>Result:</strong></p><pre>Alice<br>Bob<br>Carol</pre><p><strong>5. cut</strong></p><p>Description: cut is a command-line utility used for cutting sections from each line of files. It’s often used to extract specific columns from structured data.</p><p><strong>Example Content File (data.csv):</strong></p><pre>Name,Age,Gender<br>John,25,Male<br>Alice,30,Female<br>Bob,40,Male</pre><p><strong>Command:</strong></p><pre>cut -d &#39;,&#39; -f 2 data.csv</pre><p><strong>Result:</strong></p><pre>Age<br>25<br>30<br>40</pre><p><strong>6. uniq</strong></p><p>Description: uniq is a command-line utility for reporting or omitting repeated lines in a sorted file.</p><p><strong>Example Content File (file.txt):</strong></p><pre>Apple<br>Apple<br>Banana<br>Cherry<br>Cherry</pre><p><strong>Command:</strong></p><pre>sort file.txt | uniq</pre><p><strong>Result:</strong></p><pre>Apple<br>Banana<br>Cherry</pre><p><strong>7. awk</strong></p><p>Description: awk is a powerful programming language designed for text processing. It’s often used for data extraction and reporting tasks. It operates on a line-by-line basis, parsing each line into fields based on a specified delimiter.</p><p><strong>Example Content File (data.txt):</strong></p><pre>Name Age Gender<br>John 25 Male<br>Alice 30 Female<br>Bob 40 Male</pre><p><strong>Command:</strong></p><pre>cat data.txt | awk &#39;{print $2}&#39;</pre><p><strong>Result:</strong></p><pre>Age<br>25<br>30<br>40</pre><p><strong>8. uniq</strong></p><p>Description: uniq is a command-line utility for reporting or omitting repeated lines in a sorted file. It reads adjacent matching lines from the input, and by default, it only outputs unique lines.</p><p><strong>Example Content File (file.txt):</strong></p><pre>Apple<br>Apple<br>Banana<br>Cherry<br>Cherry</pre><p><strong>Command:</strong></p><pre>sort file.txt | uniq</pre><p><strong>Result:</strong></p><pre>Apple<br>Banana<br>Cherry</pre><p>Explanation: In the example above, the sort command sorts the contents of file.txt. Then, uniq removes adjacent duplicate lines, resulting in the output showing each unique line only once.</p><p><strong>9. echo</strong></p><p>Description: echo is a command-line utility for displaying a line of text. It simply outputs the arguments passed to it to the standard output.</p><p><strong>Example:</strong></p><pre>echo &quot;Hello, world!&quot;</pre><p><strong>Result:</strong></p><pre>Hello, world!</pre><p>Explanation: The echo command simply prints the specified text, &quot;Hello, world!&quot;, to the standard output.</p><p><strong>10. fmt</strong></p><p>Description: fmt is a command-line utility for simple optimal text formatting. It restructures text to fit within a specified width, making it more readable by adjusting line breaks and spacing.</p><p><strong>Example:</strong></p><pre>echo &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&quot; | fmt</pre><p><strong>Result:</strong></p><pre>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</pre><p>Explanation: The fmt command formats the text to fit within the default width (usually 75 characters) by adjusting line breaks as needed. In this case, since the input text is shorter than the default width, it remains unchanged.</p><p><strong>11. tr</strong></p><p>Description: tr is a command-line utility for translating or deleting characters. It operates on each character in the input stream, replacing or deleting characters based on the specified rules.</p><p><strong>Example:</strong></p><pre>bashCopy code</pre><pre>echo &quot;hello&quot; | tr &#39;[:lower:]&#39; &#39;[:upper:]&#39;</pre><p><strong>Result:</strong></p><pre>HELLO</pre><p>Explanation: The tr command converts all lowercase letters to uppercase in the input text &quot;hello&quot;, resulting in &quot;HELLO&quot; as the output.</p><p><strong>12. nl</strong></p><p>Description: nl is a command-line utility for numbering lines of files. It adds line numbers to the contents of a file, providing a convenient way to reference specific lines.</p><p><strong>Example Content File (file.txt)</strong></p><pre>Line 1<br>Line 2<br>Line 3</pre><p><strong>Command:</strong></p><pre>nl file.txt</pre><p><strong>Result:</strong></p><pre>1  Line 1<br>2  Line 2<br>3  Line 3</pre><p>Explanation: The nl command adds line numbers to each line of the input file, producing output where each line is preceded by its line number.</p><p><strong>13. wc</strong></p><p>Description: wl is a command to show the word count ina text file</p><p><strong>Example Content File (file.txt)</strong></p><pre>Line 1<br>Line 2<br>Line 3<br><br>Line 4</pre><p><strong>Command</strong>:</p><pre>cat file.txt | wc</pre><p><strong>Result</strong>:</p><pre>5       8      29</pre><p><strong>Explanation</strong>:</p><p>5 — It includes total count of lines (newlines)</p><p>8 — It includes total count of words</p><p>29 — It includes count of all characters and whitespace characters present in the file, including newline characters (‘\n’) and any other special characters</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92b3166911c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlining Configuration Management in Node.js: Introducing Native .env File Support]]></title>
            <link>https://iamtusharxo.medium.com/streamlining-configuration-management-in-node-js-introducing-native-env-file-support-c13bfa9aaa81?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c13bfa9aaa81</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[dotenv]]></category>
            <category><![CDATA[env]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Fri, 15 Mar 2024 19:37:16 GMT</pubDate>
            <atom:updated>2024-03-15T19:38:16.655Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Streamlining Configuration Management in Node.js: Introducing Native .env File Support</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*27s5XMcAcHiUcTPG1L_R8w.png" /></figure><p><strong>Introduction</strong>:</p><p>Node Js developers have long grappled with the challenge of managing configuration variables and environment settings in their applications. Traditionally, this was handled through external packages like dotenv. However, with the release of <strong>Node.js v20.6.0</strong>, a significant enhancement has emerged: native support for .env files. This article delves into the implications of this feature and illustrates its usage with practical examples.</p><p><strong>Understanding .env File:</strong></p><p>.env files serve as a pivotal tool for storing application configuration outside of the codebase. These files contain essential key-value pairs, housing sensitive information such as API keys and database credentials. Moreover, .env files are adaptable to different environments, enabling developers to customize configurations for development, testing, staging, and production environments.</p><p>Previously, integrating .env files with Node.js necessitated the utilization of third-party libraries like <strong>dotenv</strong>. Developers had to install and preload these libraries to access the configuration variables within their applications.</p><pre>npm install dotenv</pre><p>Transitioning to Native Support: <strong>Node.js v20.6.0 </strong>brings the advent of native support for .env files, rendering external dependencies redundant. This not only diminishes the application’s reliance on additional packages but also establishes a standardized approach to managing configuration files across the Node.js ecosystem.</p><p>Leveraging Native .env Support: Harnessing the built-in .env support entails a straightforward process:</p><ol><li>Create a .<strong>env</strong> file in the project directory called <strong>config.env</strong>.</li><li>Populate the <strong>config</strong>.<strong>env</strong> file with key-value pairs representing configuration settings.</li><li>Initialize the Node.js application with predefined configurations using the <strong>— env-file </strong>flag followed by the path to the .env file.</li></ol><pre>node --env-file=config.env </pre><p>Example: Suppose a .env file contains the following configuration:</p><pre>PASSWORD=PASSWORD123$</pre><p>To access this variable in the Node.js application:</p><pre>console.log(process.env.PASSWORD); // Outputs: PASSWORD123$</pre><p><strong>Enhancements</strong>:</p><p>In addition to conventional configuration variables, developers can now define <strong>NODE_OPTIONS</strong> directly within the <strong>config</strong>.<strong>env</strong> file. This enhancement streamlines the management of environment settings, obviating the need to specify these options within the <strong>package.json</strong> file.</p><p>Before this enhancement, adjusting <strong>NODE_OPTIONS</strong> required modifying the package.json file. For instance, enabling the inspect flag for debugging would involve changing the start script like this:</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;node --no-warnings --inspect index.js&quot;<br>}</pre><p>Now, with Node.js v20’s native .<strong>env</strong> support, you can accomplish the same by adding NODE_OPTIONS to the .env file:</p><pre>// .env<br>NODE_OPTIONS=--no-warnings --inspect</pre><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;node index.js&quot;<br>}</pre><p>When starting your Node.js application, it automatically uses the specified options without touching the package.json. This simplifies configuration and keeps your project tidy.</p><p>But, the feature is under active development. Since the Node 20.7.0 release, you can now specify multiple files. The variables from the last file will override any previous files.</p><pre>node --env-file .env --env-file .env.development</pre><p><strong>Conclusion</strong>:</p><p>The integration of native .env file support in Node.js v20.6.0 represents a milestone in configuration management for Node.js applications. By simplifying the handling of environment variables, this feature enhances developer productivity and fosters consistency across projects. Embracing this native capability empowers developers to manage configurations more efficiently and securely, thereby fortifying the resilience of Node.js applications against configuration-related challenges</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c13bfa9aaa81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Power BI with Ruby on Rails 7]]></title>
            <link>https://iamtusharxo.medium.com/integrating-power-bi-with-ruby-on-rails-7-983fdaac1130?source=rss-8cf0972ac13f------2</link>
            <guid isPermaLink="false">https://medium.com/p/983fdaac1130</guid>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[rails-7]]></category>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[stimulus]]></category>
            <dc:creator><![CDATA[Tushar Ravindran]]></dc:creator>
            <pubDate>Thu, 14 Mar 2024 11:13:54 GMT</pubDate>
            <atom:updated>2024-03-14T11:13:54.156Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmaX-ukkDpNqWFtKtAkRYA.png" /></figure><p>Integrating Power BI with Ruby on Rails allows you to embed interactive reports and dashboards seamlessly into your web application. With Power BI, you can leverage powerful analytics capabilities to visualize and analyze your data effectively. In this guide, we’ll walk through the process of integrating Power BI with Ruby on Rails using Rails 7 Stimulus and Turbo.</p><h3>Prerequisites</h3><p>Before we begin, make sure you have the following prerequisites:</p><ol><li>Ruby on Rails installed on your system</li><li>Power BI account with necessary permissions to access reports</li><li>Client ID, Client Secret, Tenant ID, Power BI username, and password for authentication and add it to your .<strong>env</strong> file.</li></ol><h3>Setting Up the Integration Module</h3><p>First, let’s create a module named Analytics in your Rails application and add a class GetEmbedConfig for generating embed configurations.</p><pre>module Analytics<br>  module OAuth<br>    class GetEmbedConfig<br>      CLIENT_ID = ENV[&#39;CLIENT_ID&#39;]<br>      CLIENT_SECRET = ENV[&#39;CLIENT_SECRET&#39;]<br>      TENANT_ID = ENV[&#39;TENANT_ID&#39;]<br>      POWERBI_USERNAME = ENV[&#39;POWERBI_USERNAME&#39;]<br>      POWERBI_PASSWORD = ENV[&#39;POWERBI_PASSWORD&#39;]<br>     <br>      def call<br>        access_token = get_access_token<br>        api_request_headers = get_api_request_headers(access_token)<br>        group_ids = get_all_groups(api_request_headers).map { |group| group[&#39;id&#39;] }<br>        report_details = get_all_reports(api_request_headers, group_ids)<br>        embed_tokens = generate_embed_tokens(api_request_headers, report_details, group_ids)<br>        report_embed_configs(report_details, embed_tokens, group_ids)<br>      end      <br>    end<br>  end<br>end</pre><h3>Implementing Authentication and Authorization</h3><p>Inside the GetEmbedConfig class, we&#39;ll implement methods for authentication using h<a href="https://rubygems.org/gems/httparty">ttparty</a> Gem for authorization requests.</p><pre>def get_access_token<br>  # Implementation details<br>end<br><br>def get_api_request_headers(access_token)<br>  # Implementation details<br>end</pre><h3>Fetching Groups and Reports</h3><p>Next, let’s implement methods to fetch groups and reports from Power BI.</p><pre>def get_all_groups(headers)<br>  # Implementation details<br>end<br><br>def get_all_reports(headers, groups)<br>  # Implementation details<br>end</pre><h3>Generating Embed Tokens</h3><p>We’ll implement methods to generate embed tokens for embedding reports in your application.</p><pre>def generate_embed_tokens(headers, report_details, groups)<br>  # Implementation details<br>end<br><br>def generate_embed_token(headers, group_id, report_id)<br>  # Implementation details<br>end</pre><p>Finally, let’s configure embed URLs and generate embed configurations for embedding reports in your Rails views.</p><pre>def report_embed_configs(report_details, embed_tokens, groups)<br>  # Implementation details<br>end</pre><h3>Setting Up the Controller Action</h3><pre>def load_embed_config<br>  @report_embed_config = Analytics::OAuth::GetEmbedConfig.new.call<br><br>  respond_to do |format|<br>    format.json {<br>      render json: @report_embed_config<br>    }<br>    format.html { redirect_to index_path }<br>  end<br>end</pre><h3>Setting Up the Routes</h3><p>Next, let’s define a route for the load_embed_config action in your config/routes.rb file.</p><pre>Rails.application.routes.draw do<br>  get &#39;/load_embed_config&#39;, to: &#39;reports#load_embed_config&#39;<br>end</pre><h3>Creating the Stimulus Controller</h3><p>Now, let’s create a Stimulus controller to handle interactions on the client-side.</p><pre>rails stimulus:controller reports</pre><p>This command generates a Stimulus controller in the app/javascript/controllers directory.</p><p>Add <strong>powerbi-client </strong>library to <strong>importmap.rb </strong>file</p><pre>pin &quot;powerbi-client&quot;, to: &quot;https://ga.jspm.io/npm:powerbi-client@2.18.5/dist/powerbi.js&quot;</pre><h3>Implementing the Stimulus Controller</h3><p>Open the reports_controller.js file and implement the controller logic to fetch embed configurations from the server and handle interactions.</p><pre>// app/javascript/controllers/reports_controller.js<br>import { Controller } from &quot;@hotwired/stimulus&quot;;<br>import * as pbi from &quot;powerbi-client&quot;;<br><br>export default class extends Controller {<br>  static targets = [&quot;buttonGroup&quot;, &quot;container&quot;, &quot;embedButton&quot;, &quot;loadingContainer&quot;];<br><br>  connect() {<br>    this.state = {<br>      isEmbedButtonClicked: false,<br>      selectedReport: null,<br>    };<br><br>   this.embedButtonTarget.addEventListener(&quot;click&quot;, () =&gt; {<br>      // Handle Button Click Logic to Show Reports<br>   });<br><br><br>  selectReport(reportConfig, button) {<br>    // handle Report Selection Logic to Select Shown Reports<br>  }<br><br>  loadReport(reportConfig) {<br>    //handle report Loading<br>    this.containerTarget.innerHTML = &quot;&quot;;<br>    const reportContainer = document.createElement(&quot;div&quot;);<br>    reportContainer.classList.add(&quot;powerbi-report-container&quot;);<br>    this.containerTarget.appendChild(reportContainer);<br><br>    const reportLoadConfig = {<br>      type: &quot;report&quot;,<br>      tokenType: pbi.models.TokenType.Embed,<br>      accessToken: reportConfig.embedToken,<br>      embedUrl: reportConfig.embedUrl,<br>    };<br>    //Embeded the Report<br>    powerbi.embed(reportContainer, reportLoadConfig);<br>  }<br>}</pre><h3>Updating the View</h3><p>Finally, update your view file (e.g., app/views/reports/index.html.erb) to include the Stimulus controller.</p><pre>&lt;main&gt;<br>  &lt;div data-controller=&quot;analytics&quot;&gt;<br>  &lt;button data-analytics-target=&quot;embedButton&quot;&gt;Embed&lt;/button&gt;<br>     &lt;div data-analytics-target=&quot;loadingContainer&quot; style=&quot;display: none;&quot;&gt;<br>        Loading...<br>     &lt;/div&gt;<br>     &lt;div data-analytics-target=&quot;buttonGroup&quot; style=&quot;display: none;&quot;&gt;<br>   &lt;/div&gt;<br>   &lt;div data-analytics-target=&quot;container&quot;&gt;<br>   &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/main&gt;</pre><h3>Conclusion</h3><p>In this guide, we’ve outlined the process of integrating Power BI with Ruby on Rails using Rails 7. By following these steps and implementing the provided code snippets, you can seamlessly embed Power BI reports and dashboards into your Rails application.</p><blockquote>Reference : <a href="https://github.com/sedin-tushar/ROR-Embed-PowerBi/">https://github.com/sedin-tushar/ROR-Embed-PowerBi/</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=983fdaac1130" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>