<?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 Anurag Bhatt on Medium]]></title>
        <description><![CDATA[Stories by Anurag Bhatt on Medium]]></description>
        <link>https://medium.com/@anuragbhatt-2000?source=rss-0651a2ade0d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_33YWUYmQUbXmmJ4zNXO4g.jpeg</url>
            <title>Stories by Anurag Bhatt on Medium</title>
            <link>https://medium.com/@anuragbhatt-2000?source=rss-0651a2ade0d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:22:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anuragbhatt-2000/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[I Built a “Flashlight” for the Web Because I Couldn’t Focus]]></title>
            <link>https://javascript.plainenglish.io/i-built-a-flashlight-for-the-web-because-i-couldnt-focus-33b5bab5e9a7?source=rss-0651a2ade0d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/33b5bab5e9a7</guid>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[html-css]]></category>
            <category><![CDATA[creativity]]></category>
            <dc:creator><![CDATA[Anurag Bhatt]]></dc:creator>
            <pubDate>Mon, 09 Feb 2026 17:53:46 GMT</pubDate>
            <atom:updated>2026-02-09T17:53:46.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t0bMtO_7rkLtxomv" /><figcaption>Photo by <a href="https://unsplash.com/@redaquamedia?utm_source=medium&amp;utm_medium=referral">Denny Müller</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This project is <strong>100% Open Source</strong>. You can fork it, improve it, or just judge my code right here: 👉 <a href="https://github.com/anuragbhatt408/Focus-Flashlight-Edge-Extension">Focus Flashlight</a>.</p><p>It was 11 PM. I was trying to read a dense technical book on my laptop, and I was failing miserably.</p><p>My eyes kept drifting. Sidebar ads, open tabs, the blinding white background of the rest of the page — everything was competing for my attention. I realized I needed digital horse blinders. I wanted a way to dim the entire internet and shine a literal spotlight on just the paragraph I was currently reading.</p><p>I looked for existing tools, but nothing felt quite right. So, I opened VS Code and decided to build it myself.</p><p>Here is how I built <strong>Focus Flashlight</strong>, and a deep dive into the code that makes it work.</p><h3>The Architecture</h3><p>If you’ve never built one, a browser extension isn’t just one JavaScript file. It’s a small system of distinct components that live in separate worlds and have to communicate via a special messaging bridge.</p><p>My extension relies on three main parts:</p><ol><li><strong>The Popup (The Remote Control):</strong> The little HTML menu that appears when you click the extension icon. It has its own isolated DOM and JS environment.</li><li><strong>The Content Script (The Worker):</strong> The JavaScript file that actually gets injected <em>into</em> the webpage (like Wikipedia). This is the only part that can touch the page content.</li><li><strong>CSS Magic (The Visuals):</strong> The clever styling that creates the flashlight effect without killing performance.</li></ol><h3>The Deep Dive: How It Works Under the Hood</h3><p>How does clicking a button in a tiny popup make a giant flashlight appear on a webpage? It’s a game of telephone.</p><h4>Step 1: The User Clicks “Turn On” (Popup.js)</h4><p>When you open the extension menu, you are looking at popup.html. It has sliders for size and darkness, and a &quot;Turn On&quot; button.</p><p>When you click that button, popup.js wakes up. It cannot directly manipulate the webpage. Instead, it packages the user’s desired settings into a message object and ships it off to the active tab.</p><pre>// popup.js (simplified)<br>btnOn.addEventListener(&#39;click&#39;, () =&gt; {<br>  // 1. Find the active tab<br>  chrome.tabs.query({active: true, currentWindow: true}, (tabs) =&gt; {<br>    <br>    // 2. Send the message across the bridge<br>    chrome.tabs.sendMessage(tabs[0].id, { <br>      command: &quot;turn_on&quot;, <br>      setting: { <br>        size: sizeSlider.value,  // e.g., &quot;300&quot;<br>        darkness: darknessSlider.value // e.g., &quot;0.8&quot;<br>      }<br>    });<br>  });<br>});</pre><h4>Step 2: The Worker Receives the Signal (Content.js)</h4><p>Sitting quietly inside the Wikipedia tab is content.js. It has a listener waiting for messages.</p><p>When it receives the &quot;turn_on&quot; command, it springs into action. It doesn&#39;t use an image for the flashlight; it creates a full-screen &lt;div&gt; overlay and injects it into the body of the page.</p><p>It also starts an event listener to track your mouse movements.</p><pre>// content.js (simplified)<br>chrome.runtime.onMessage.addListener((message) =&gt; {<br>  if (message.command === &quot;turn_on&quot;) {<br>    enableFlashlight(message.setting);<br>  }<br>});</pre><h4>Step 3: The Performance Hack (CSS Variables)</h4><p>This is the most crucial part. If we tried to re-render the overlay graphic every single time the mouse moved a pixel, the browser would choke. It would lag horribly.</p><p>Instead, we use <strong>CSS Variables</strong>.</p><p>Every time the mouse moves, the content script grabs the X and Y coordinates and instantly pumps them into two CSS variables on the overlay element: --x and --y.</p><pre>// content.js - The math part<br>function moveLight(e) {<br>  // e.clientX and e.clientY are the mouse coordinates<br>  overlay.style.setProperty(&#39;--x&#39;, e.clientX + &#39;px&#39;);<br>  overlay.style.setProperty(&#39;--y&#39;, e.clientY + &#39;px&#39;);<br>}</pre><p>Over in our CSS file, the magic happens. The “flashlight” isn’t a physical hole; it’s a giant <strong>Radial Gradient</strong> background.</p><p>We set the center of that gradient to use those CSS variables. Because CSS variables update instantly without causing a full browser re-flow, the movement is silky smooth (60fps).</p><pre>/* styles.css */<br>#focus-flashlight {<br>  position: fixed;<br>  /*Covers entire screen*/<br>  width: 100vw; height: 100vh; <br>  /* Sits on top of almost everything */<br>  z-index: 2147483647; <br>  /* Lets clicks pass through to the page below */<br>  pointer-events: none; <br><br>  /* THE MAGIC GRADIENT */<br>  background: radial-gradient(<br>    circle var(--radius) at var(--x) var(--y), <br>    transparent 0%,  /* The &quot;Hole&quot; */<br>    rgba(0, 0, 0, var(--darkness)) 40% /* The Curtain */<br>  );<br>}</pre><h4>Step 4: The “Pop-Out” Effect (Z-Index Stacking)</h4><p>There was one final problem: Dark Mode sites. Putting a semi-transparent black layer over a black website just makes it… blacker.</p><p>I needed the text you are reading to physically “pop out” above the darkness.</p><p>I achieved this using a Z-Index hack. The darkness layer sits at z-index: 2147483647 (the maximum integer allowed in 32-bit systems).</p><p>When you hover over a paragraph, I force that paragraph to have position: relative and an even <em>higher</em> Z-index (conceptually), creating a new stacking context that lifts it above the overlay. I also force its background to white so it looks like a bright reading card.</p><h3>The “Chrome Tax” &amp; Why I Chose Edge</h3><p>The extension is finished and works perfectly on Chrome, Edge, and Brave.</p><p>However, when I went to publish it to the Chrome Web Store, Google asked for a <strong>$5 registration fee</strong> just to verify my account.</p><p>Look, I love Chrome, but in this economy? To host a free, open-source tool? No thanks.</p><p>Microsoft Edge, however, welcomed me with open arms (and free hosting). Because Edge is built on Chromium — the same engine as Chrome — the code works exactly the same.</p><p><strong>Chrome users can still install it!</strong> You just have to follow the instructions below.</p><h3>How to Get It</h3><p>Since I built this as a free, open-source project, I didn’t pay the Google “Chrome Tax.” Here is how you can get it on your browser:</p><h4>For Microsoft Edge Users (Easiest)</h4><p>You can install it directly from the official Microsoft Add-ons Store with one click: 🚀 <strong>[INSERT MICROSOFT EDGE STORE LINK]</strong></p><h4>For Google Chrome Users</h4><p>Since this isn’t on the Chrome Store, you get to be a “Hacker” for a minute. It takes 30 seconds:</p><ol><li>Download the code from my GitHub (Green “Code” button → “Download ZIP”).</li><li>Unzip the folder.</li><li>Open chrome://extensions in your browser.</li><li>Turn on <strong>Developer Mode</strong> (top right).</li><li>Click <strong>Load Unpacked</strong> and select the unzipped folder.</li></ol><p>💻 <strong>Get the Code on GitHub:</strong> <strong>[</strong><a href="https://github.com/anuragbhatt408/Focus-Flashlight-Edge-Extension"><strong>Github</strong></a><strong>]</strong></p><p>👨‍💼 <strong>Connect on LinkedIn:</strong> <strong>[</strong><a href="https://www.linkedin.com/in/anuragbhatt408/"><strong>LinkedIn</strong></a><strong>]</strong></p><p>👉 <strong>Extension Link: [</strong><a href="https://microsoftedge.microsoft.com/addons/detail/focus-flashlight/dbeoiecheeocpjmfbfmpdfddlmapjgeo"><strong>Focus Flashlight — Microsoft Edge Addons</strong></a><strong>]</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33b5bab5e9a7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/i-built-a-flashlight-for-the-web-because-i-couldnt-focus-33b5bab5e9a7">I Built a “Flashlight” for the Web Because I Couldn’t Focus</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Generative AI as a Software Engineer: Models, RAG, Agents & Tools Explained ]]></title>
            <link>https://blog.stackademic.com/learning-generative-ai-as-a-software-engineer-models-rag-agents-tools-explained-28fa0893c022?source=rss-0651a2ade0d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/28fa0893c022</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Anurag Bhatt]]></dc:creator>
            <pubDate>Sun, 19 Oct 2025 12:59:59 GMT</pubDate>
            <atom:updated>2025-12-05T09:46:06.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="GenAI" src="https://cdn-images-1.medium.com/max/1024/0*rLMBTIgYHH6C-Nra" /><figcaption>Photo by <a href="https://unsplash.com/@emilianovittoriosi?utm_source=medium&amp;utm_medium=referral">Emiliano Vittoriosi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>1. Introduction — Why GenAI Matters for Developers 🧠</h3><ul><li>As a software developer, I’ve spent years writing logic for machines to follow. But the day I started exploring <strong>Generative AI (GenAI)</strong>, something clicked — we’re not just <em>instructing</em> machines anymore, we’re <em>collaborating</em> with them.</li><li>In this post, I’ll share the journey I wish someone had written for me — from understanding the basics of LLMs and prompts to building intelligent <strong>RAG systems</strong>, <strong>AI agents</strong>, and experimenting with tools like <strong>LangChain</strong>, <strong>LangGraph</strong>, and <strong>Hugging Face</strong>.</li><li>Let’s break down GenAI, step by step, from the lens of a developer.</li></ul><h3>2. Why Developers Should Care About GenAI 🚀</h3><p>GenAI isn’t just another tech trend. It’s <strong>changing the definition of software development</strong> itself.</p><p>We used to code every rule manually. Now, we design <em>systems that can reason</em>.<br> From GitHub Copilot writing boilerplate code, to AI-powered customer support systems, to LLMs that summarize 1000 pages in seconds — this space is exploding.</p><p>If you’re a developer, learning GenAI now is like learning web development in 2008 or mobile development in 2012. You’re early — and that’s a massive advantage.</p><h3>3. The Foundation — Prompts and LLMs 🧩</h3><h3>. Prompts 🧰</h3><p>Before diving into complex architectures, you have to understand the heart of it all: <strong>prompts</strong> and <strong>LLMs (Large Language Models).</strong></p><p>Think of an LLM like a super-smart autocomplete system trained on the internet. It doesn’t “know” facts — it predicts text based on context.<br> But when used right, it <em>feels</em> intelligent.</p><p>A <strong>prompt</strong> is how we communicate with it — the input that triggers intelligent output.</p><pre>❌ Bad prompt:<br>Explain RAG.<br><br>✅ Better prompt:<br>Explain Retrieval-Augmented Generation (RAG) as if I’m a backend developer learning GenAI for the first time. Include a small example.</pre><p>That difference? It’s the art of <strong>prompt engineering</strong> — knowing how to guide the model with structure, tone, and context.</p><p>There are several prompting strategies:</p><ul><li><strong>Zero-shot</strong>: “Translate this sentence to French.” <em>(You ask directly without examples.)</em></li></ul><pre>Translate the following sentence to French:<br>&quot;Developers are the architects of the digital world.&quot;</pre><ul><li><strong>Few-shot</strong>: “Here are examples. Now do this one.” <em>(You give a few examples before your request — great for consistent patterns.)</em></li></ul><pre>Convert the following sentences into snake_case:<br><br>Example 1: &quot;Hello World&quot; → &quot;hello_world&quot;<br>Example 2: &quot;My Name Is Anurag&quot; → &quot;my_name_is_anurag&quot;<br>Now convert: &quot;GenAI Rocks&quot;</pre><p><em>This helps the model learn the desired output format before execution.</em></p><ul><li><strong>Chain-of-thought</strong>: “Explain step by step before giving the final answer.” <em>(You ask the model to “think aloud” step-by-step before answering — great for reasoning or math.)</em></li></ul><pre>You are a reasoning assistant. Think step by step before answering:<br>Question: If a train travels 60 km in 1.5 hours, what is its average speed?</pre><ul><li><strong>Role-Based Prompting</strong>: “You define a role or persona to guide tone and expertise.”</li></ul><pre>You are a senior React developer mentoring a junior.<br>Explain useEffect and useState with a real-world example and avoid jargon.</pre><p><em>Role-based prompting is especially powerful when building </em><strong><em>chatbots or GenAI tools</em></strong><em> for specific industries (finance, education, law, etc.)</em></p><h3>. Under the Hood — How LLMs Actually Work ⚙️</h3><p>Let’s not go full math mode, but it helps to know the basics.</p><p>An <strong>LLM</strong> is built on a <strong>Transformer architecture</strong>, which introduced the concept of <strong>attention</strong> — the ability to “focus” on relevant parts of a sentence.</p><p>Here’s a developer-friendly view:</p><ol><li><strong>Text </strong>→ split into <strong>tokens</strong> (like “developer”, “AI”, “rocks!”)</li><li><strong>Tokens</strong> → converted into <strong>embeddings</strong> (vectors of numbers representing meaning)</li><li><strong>Transformer</strong> → uses <strong>attention</strong> to weigh relationships between tokens</li><li><strong>The model</strong> → predicts the next token based on context</li></ol><p>These <strong>embeddings</strong> are the secret sauce — they turn words into math the model can understand.</p><p>You can use:</p><ul><li><strong>OpenAI Embeddings</strong> (text-embedding-3-small or text-embedding-3-large)</li><li><strong>Hugging Face Transformers</strong> (sentence-transformers/all-MiniLM-L6-v2)</li><li><strong>Open-source options</strong> like <strong>InstructorXL</strong>, <strong>GTE-base</strong>, or <strong>BAAI/bge models</strong></li></ul><p>You can store these embeddings in vector databases like <strong>Pinecone</strong>, <strong>Chroma</strong>, or <strong>FAISS</strong> to power your RAG pipeline.</p><h3>4. Beyond Memory — RAG (Retrieval-Augmented Generation) 📚</h3><p>When I first built a chatbot with OpenAI’s API, it worked great… until I asked about something not in its training data. That’s when I discovered <strong>RAG</strong>.</p><p>RAG stands for <strong>Retrieval-Augmented Generation</strong>.<br> It’s like giving your AI a memory — a way to look up data <em>before</em> answering.</p><p>Here’s how it works conceptually:</p><pre>User Query → Convert to Embedding → Search Vector DB → Retrieve Top Results → LLM Generates Answer Using Context</pre><p>Example use cases:</p><ul><li>Customer support bots with company knowledge</li><li>Internal chatbots answering policy or HR queries</li><li>AI-powered documentation assistants</li></ul><p>You can build one using:</p><ul><li><strong>OpenAI + Chroma + LangChain</strong></li><li>or <strong>Hugging Face + FAISS + LlamaIndex</strong></li></ul><p>This is where embeddings shine — they help find <em>semantically similar</em> content, not just keyword matches.</p><h3>🤖 From Chatbots to Thinkers — Agentic AI and AI Agents</h3><p>Once your AI can <em>understand</em> and <em>retrieve</em>, the next leap is <strong>Agentic AI</strong> — systems that can <em>think, plan, and act.</em></p><p>An <strong>AI Agent</strong> isn’t just answering queries. It’s:</p><ul><li>Making decisions</li><li>Running code</li><li>Calling APIs</li><li>And reasoning across multiple steps</li></ul><p>It’s like turning your chatbot into a <strong>junior developer</strong> who can actually execute tasks.</p><p>We’re entering a new era where <strong>AIs will collaborate with other AIs</strong> — a team of autonomous systems working towards a shared goal.</p><h3>🗺️ My GenAI Roadmap for Developers</h3><p>If you’re starting your GenAI journey today:</p><ol><li>🪄 <strong>Learn Prompt Engineering</strong> — Master the art of structured queries.</li><li>🧠 <strong>Understand LLMs &amp; Embeddings</strong> — Learn tokenization and transformers.</li><li>🧩 <strong>Build a GenAI App</strong> — Start with OpenAI or Hugging Face APIs.</li><li>📚 <strong>Implement RAG</strong> — Connect LLMs with your data.</li><li>🤖 <strong>Build Agents</strong> — Use LangChain or LangGraph for reasoning systems.</li><li>🧰 <strong>Explore Open Source</strong> — Try Mistral, Llama, and Hugging Face models.</li><li>🚀 <strong>Deploy &amp; Monitor</strong> — Measure latency, accuracy, and user feedback.</li></ol><h3>🌍 The Future — AI That Builds Software</h3><p>The next wave of GenAI isn’t about chatbots — it’s about <strong>Agentic systems</strong> that reason, plan, and collaborate.</p><p>Imagine:</p><ul><li>An AI that reads your Jira tickets and proposes solutions</li><li>Another AI that writes code and tests it</li><li>A third one that reviews and merges pull requests</li></ul><p>That’s not science fiction — it’s already happening in research labs and open-source projects.</p><p>As developers, our job is shifting from <em>writing logic</em> to <em>designing intelligence.</em></p><h3>💬 Final Thoughts</h3><p>If you’re curious about GenAI — <strong>just start</strong>.<br> Don’t wait for a perfect roadmap. Pick a model, write a prompt, and see what happens.</p><p>That’s exactly how I began. And every time I see my AI-generated app reason, retrieve, or self-correct — it feels like watching the next era of computing unfold.</p><blockquote><em>“The next generation of developers won’t just build software — they’ll build AI that builds software.”</em></blockquote><h3>A message from our Writer</h3><p><strong>Hey, Anurag here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://www.linkedin.com/in/anuragbhatt408/"><strong>LinkedIn</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28fa0893c022" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/learning-generative-ai-as-a-software-engineer-models-rag-agents-tools-explained-28fa0893c022">Learning Generative AI as a Software Engineer: Models, RAG, Agents &amp; Tools Explained 🪜</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Docker Basics: Containers, Compose, and Networking Explained]]></title>
            <link>https://blog.devops.dev/introduction-to-docker-a-beginner-friendly-guide-e328022c7b56?source=rss-0651a2ade0d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e328022c7b56</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Anurag Bhatt]]></dc:creator>
            <pubDate>Fri, 24 Jan 2025 19:33:31 GMT</pubDate>
            <atom:updated>2025-02-06T18:03:29.886Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yjvo-peob-EruKKKaUnwwQ.png" /><figcaption>Docker</figcaption></figure><p>In today’s world of software development, the phrase “It works on my machine!” is often met with frustration. Developers work in diverse environments with varying dependencies, which can lead to inconsistencies. This is where <strong>Docker</strong> comes to the rescue.<br>Docker is an open-source platform that allows you to package, deploy, and run applications in a standardized way. In this article, we’ll explore Docker from a beginner’s perspective, with easy-to-follow examples to get you started.</p><h3>What is Docker?</h3><p>Docker simplifies the development and deployment process by using <strong>containers</strong>. A container is a lightweight, standalone, and executable unit that includes everything an application needs to run: the code, runtime, libraries, and system tools. Containers are isolated from each other, ensuring consistency across environments.</p><p>Think of Docker containers as shipping containers for your application. Just as shipping containers ensure goods arrive in the same condition regardless of transportation methods, Docker ensures your application runs consistently in any environment.</p><h3>Installing Docker</h3><p>Before diving into examples, you’ll need to install Docker:</p><ol><li>Visit the <a href="https://www.docker.com/">Docker website</a>.</li><li>Download and install Docker Desktop for your operating system (Windows, macOS, or Linux).</li><li>After installation, verify by running:</li></ol><pre>docker --version</pre><p>This should display the installed Docker version.</p><h3>Getting Started with Docker</h3><h3>1. Hello World Example</h3><p>Let’s start with a simple example to ensure Docker is working correctly:</p><ol><li>Open a terminal and run:</li></ol><pre>docker run hello-world</pre><p>2. Docker will:</p><ul><li>Check if the hello-world image exists locally.</li><li>If not, it pulls the image from Docker Hub (a repository of Docker images).</li><li>Run the container, which prints a “Hello from Docker!” message.</li></ul><p>This demonstrates how Docker pulls and runs images.</p><h3>2. Creating Your First Dockerized Application</h3><p>We’ll create a basic web server using Python:</p><h4>Step 1: Write the Application</h4><p>Create a file named app.py (This is basic server on flask that listing on port 5000) :</p><pre>from flask import Flask<br><br>app = Flask(__name__)<br><br>@app.route(&#39;/&#39;)<br>def home():<br>    return &quot;Hello, Docker!&quot;<br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(host=&#39;0.0.0.0&#39;, port=5000)</pre><h4>Step 2: Create a Dockerfile</h4><p>A Dockerfile is a script that contains instructions to build a Docker image.</p><p>Create a file named Dockerfile:</p><pre># Use an official Python runtime as a base image<br>FROM python:3.9-slim<br><br># Set the working directory in the container<br>WORKDIR /app<br><br># Copy the current directory contents into the container<br>COPY . .<br><br># Install dependencies<br>RUN pip install flask<br><br># Specify the command to run the application<br>CMD [&quot;python&quot;, &quot;app.py&quot;]</pre><h4>Step 3: Build the Docker Image</h4><p>Run the following command in the terminal where your files are located:</p><pre>docker build -t my-flask-app .</pre><p>This command:</p><ul><li>Reads the Dockerfile.</li><li>Builds an image named my-flask-app.</li></ul><h4>Step 4: Run the Container</h4><p>Run the container using:</p><pre>docker run -p 5000:5000 my-flask-app</pre><p>This maps port 5000 on the container to port 5000 on your host machine. Visit http://localhost:5000 in your browser to see <strong>Hello, Docker!</strong></p><h3>Docker Compose: Simplifying Multi-Container Applications</h3><p>For applications with multiple services (e.g., a web server and a database), managing individual containers can become cumbersome. Enter <strong>Docker Compose</strong>.</p><h3>What is Docker Compose?</h3><p>Docker Compose is a tool that allows you to define and manage multi-container Docker applications using a single YAML configuration file (docker-compose.yml). It simplifies starting, stopping, and configuring interconnected services.</p><h3>Example: Flask + Redis</h3><h4>Step 1: Create a docker-compose.yml File</h4><pre>version: &#39;3.8&#39;<br>services:<br>  web:<br>    build: .<br>    ports:<br>      - &quot;5000:5000&quot;<br>    depends_on:<br>      - redis<br>  redis:<br>    image: &quot;redis:alpine&quot;</pre><p>In this configuration:</p><ul><li>web: Defines the Flask application container.</li><li>redis: Defines the Redis service, using an official lightweight image.</li><li>depends_on: Ensures the Redis service starts before the web service.</li></ul><h4>Step 2: Run the Application</h4><p>Start the services with:</p><pre>docker-compose up</pre><p>This command:</p><ul><li>Builds the web service using the Dockerfile.</li><li>Pulls the Redis image from Docker Hub.</li><li>Starts both services.</li></ul><p>Visit http://localhost:5000 to see your Flask application running with Redis support.</p><h4>Step 3: Manage Services</h4><ol><li>Stop the services:</li></ol><pre>docker-compose down</pre><p>2. Run services in the background:</p><pre>docker-compose up -d</pre><p>3. View running services:</p><pre>docker-compose ps</pre><h3>Docker Networking</h3><p>Docker networking allows containers to communicate with each other and the outside world. By default, Docker provides the following network types:</p><h3>1. Bridge Network (Default for Containers)</h3><ul><li>Containers on the same bridge network can communicate with each other using their names.</li><li>Example:</li></ul><pre>docker network create my_bridge<br>docker run --network=my_bridge --name=container1 busybox ping container2<br>docker run --network=my_bridge --name=container2 busybox</pre><ul><li>This setup allows container1 to ping container2 by its name.</li></ul><h3>2. Host Network</h3><ul><li>The container shares the host machine’s network stack.</li><li>Use this for performance-intensive tasks where you don’t need network isolation.</li></ul><pre>docker run --network=host nginx</pre><ul><li>In this case, Nginx directly binds to the host’s ports.</li></ul><h3>3. Overlay Network</h3><ul><li>Used in multi-host scenarios, often with orchestration tools like Docker Swarm or Kubernetes.</li><li>Enables communication between containers on different hosts.</li></ul><h3>4. None Network</h3><ul><li>Completely disables networking for the container.</li></ul><pre>docker run --network=none busybox</pre><h3>Some Personal Tips</h3><ol><li><strong>Use </strong><strong>.dockerignore</strong>: Exclude unnecessary files (e.g., .git, node_modules) from the image.</li><li><strong>Keep Images Lightweight</strong>: Use slim base images to reduce size.</li><li><strong>Version Control Your Dockerfiles</strong>: Ensure reproducibility.</li><li><strong>Automate Builds</strong>: Use CI/CD pipelines to build and push images.</li></ol><h3>Some Links To Read</h3><ul><li><a href="https://docs.docker.com/build-cloud/">Docker Build Cloud</a></li><li><a href="https://docker-curriculum.com/">A Docker Tutorial for Beginners</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e328022c7b56" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/introduction-to-docker-a-beginner-friendly-guide-e328022c7b56">Mastering Docker Basics: Containers, Compose, and Networking Explained</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying JavaScript: Pure Functions, First-Class Functions, and Higher-Order Functions]]></title>
            <link>https://medium.com/javascript-decoded-in-plain-english/demystifying-javascript-pure-functions-first-class-functions-and-higher-order-functions-ad36742d9eed?source=rss-0651a2ade0d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad36742d9eed</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Anurag Bhatt]]></dc:creator>
            <pubDate>Wed, 06 Nov 2024 18:02:45 GMT</pubDate>
            <atom:updated>2025-02-08T15:36:46.621Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rvs8U1A7aD_M7AdI" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you’re starting in JavaScript, maybe you haven’t heard of Pure Functions, First-Class Functions, and Higher-Order Functions but let’s start understanding them one by one.</p><h3><strong>1. Pure Function</strong></h3><p>A <strong>pure function</strong> is a function that, given the same inputs, will always return the same output and has no side effects (e.g., does not modify external state or variables). Pure functions are important in functional programming because they are predictable and testable.</p><pre>function square(num) {<br>    return num * num;<br>}<br><br>console.log(square(4)); // Output: 16  Changing the state of an object</pre><p>In this example:</p><ul><li>square is pure because it doesn’t depend on or modify any external state. Given the same input (4), it will always return the same output (16).</li><li>It doesn’t produce any side effects, making it easy to test and predict.</li></ul><blockquote>Impure function are just opposite of that, It has side effects or depends on external state, making its behavior unpredictable or non-deterministic<br>Side Effects like (Modifying global variables, Changing the state of an object, etc)</blockquote><h3>2. First Class Function</h3><p>In JavaScript, <strong>first-class functions</strong> mean that functions are treated like any other variable. This allows us to:</p><ul><li>Assign functions to variables,</li><li>Pass them as arguments to other functions,</li><li>Return them from other functions,</li><li>Store them in data structures (like arrays or objects).</li></ul><pre>// Assigning a function to a variable<br>const greet = function(name) {<br>    return `Hello, ${name}!`;<br>};<br><br>// Passing a function as an argument<br>function processGreeting(name, fn) {<br>    return fn(name);<br>}<br><br>console.log(processGreeting(&quot;Anurag&quot;, greet)); // Output: Hello, Anurag!</pre><p>In this example:</p><ul><li>The function greet is treated like any other variable and passed as an argument to processGreeting.</li><li>This ability to pass greet is possible because JavaScript treats functions as first-class citizens.</li></ul><h3>3. Higher-Order Functions</h3><p>A <strong>higher-order function</strong> (HOF) is a function that:</p><ol><li>Takes one or more functions as arguments, and/or</li><li>Returns a function as its result.</li></ol><p>Because JavaScript functions are first-class, we can create higher-order functions, which are foundational in functional programming.</p><pre>function createMultiplier(multiplier) {<br>    return function(num) {<br>        return num * multiplier;<br>    };<br>}<br><br>const double = createMultiplier(2);<br>console.log(double(5)); // Output: 10<br><br>const triple = createMultiplier(3);<br>console.log(triple(5)); // Output: 15</pre><p>In this example:</p><ul><li>createMultiplier is a higher-order function because it returns a new function customized with a multiplier.</li><li>double and triple are partially applied functions created by createMultiplier</li></ul><h3><strong>. map, </strong><strong>filter, and </strong><strong>reduce with</strong> <strong>Real-World Examples</strong></h3><p>JavaScript’s map, filter, and reduce are higher-order functions because they take a function as an argument. These methods are commonly used to process and transform arrays.</p><pre>const products = [<br>    { name: &quot;Laptop&quot;, price: 1200, category: &quot;Electronics&quot;, rating: 4.5 },<br>    { name: &quot;Phone&quot;, price: 800, category: &quot;Electronics&quot;, rating: 4.3 },<br>    { name: &quot;Shirt&quot;, price: 50, category: &quot;Clothing&quot;, rating: 4.1 },<br>    { name: &quot;Shoes&quot;, price: 100, category: &quot;Clothing&quot;, rating: 4.7 },<br>    { name: &quot;Book&quot;, price: 20, category: &quot;Books&quot;, rating: 4.9 }<br>];</pre><ul><li><strong>map – Transforming Data</strong></li></ul><p><strong>Goal:</strong> Extract just the names of all products to create a product list.</p><p>The map method creates a new array by transforming each element in the original array based on the function provided.</p><pre>const productNames = products.map(product =&gt; product.name);<br><br>console.log(productNames); // Output: [&quot;Laptop&quot;, &quot;Phone&quot;, &quot;Shirt&quot;, &quot;Shoes&quot;, &quot;Book&quot;]</pre><p>Explanation:</p><ul><li>map applies the function to each item in products, extracting just the name of each product.</li><li>It returns a new array productNames with the names only.</li></ul><p><strong>Real-World Use Case</strong>: map is useful for transforming data without changing the original array, making it ideal for tasks like creating lists.</p><ul><li><strong>filter – Filtering Data</strong></li></ul><p><strong>Goal:</strong> Get all products in the “Electronics” category.</p><p>The filter method creates a new array containing only the elements that pass a specific test.</p><pre>const electronics = products.filter(product =&gt; product.category === &quot;Electronics&quot;);<br><br>console.log(electronics);<br>/*<br>Output:<br>[<br>    { name: &quot;Laptop&quot;, price: 1200, category: &quot;Electronics&quot;, rating: 4.5 },<br>    { name: &quot;Phone&quot;, price: 800, category: &quot;Electronics&quot;, rating: 4.3 }<br>]<br>*/</pre><p>Explanation:</p><ul><li>filter applies the function to each item in products, returning only those with a category of &quot;Electronics&quot;.</li></ul><p><strong>Real-World Use Case</strong>: filter is perfect for narrowing down data to a subset, such as finding products in a specific category.</p><ul><li><strong>reduce – Accumulating Data</strong></li></ul><p><strong>Goal:</strong> Calculate the total value of all products in the store.</p><p>The reduce method takes an array and combines it into a single value based on the function provided.</p><pre>const totalValue = products.reduce((acc, product) =&gt; acc + product.price, 0);<br><br>console.log(totalValue); // Output: 2170</pre><p>Explanation:</p><ul><li>reduce applies the function with an initial accumulator (0) to accumulate the price of each product.</li><li>This results in totalValue, which is the sum of all product prices.</li></ul><p><strong>Real-World Use Case</strong>: reduce is great for aggregating data, such as calculating totals or summarizing an array into a single result.</p><h3>Chaining map, filter, and reduce</h3><p>These methods are often chained together for complex operations.</p><p><strong>Goal:</strong> Calculate the total value of all electronics products with a rating above 4.0</p><pre>const totalElectronicsValue = products<br>    .filter(product =&gt; product.category === &quot;Electronics&quot; &amp;&amp; product.rating &gt; 4.0)<br>    .map(product =&gt; product.price)<br>    .reduce((acc, price) =&gt; acc + price, 0);<br><br>console.log(totalElectronicsValue); // Output: 2000</pre><p>Explanation:</p><ol><li><strong>filter</strong>: Filters products to include only electronics with a rating above 4.0.</li><li><strong>map</strong>: Transforms the filtered array to get an array of prices only.</li><li><strong>reduce</strong>: Sums the prices to get the total value of qualifying electronics products.</li></ol><blockquote><strong>Honest Opinion:</strong> As a developer with over 2 years of industry experience, I rarely encounter codebases that fully <strong>utilize chaining with </strong><strong>map, </strong><strong>filter, and </strong><strong>reduce</strong> in the way it’s often showcased in tutorials, let’s see what future holds for us.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad36742d9eed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javascript-decoded-in-plain-english/demystifying-javascript-pure-functions-first-class-functions-and-higher-order-functions-ad36742d9eed">Demystifying JavaScript: Pure Functions, First-Class Functions, and Higher-Order Functions</a> was originally published in <a href="https://medium.com/javascript-decoded-in-plain-english">JS Decoded in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Theory to Practice: Making React’s useState and useEffect Work for You]]></title>
            <link>https://medium.com/javascript-decoded-in-plain-english/from-theory-to-practice-making-reacts-usestate-and-useeffect-work-for-you-98239974ed23?source=rss-0651a2ade0d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/98239974ed23</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Anurag Bhatt]]></dc:creator>
            <pubDate>Sat, 26 Oct 2024 17:38:58 GMT</pubDate>
            <atom:updated>2025-02-13T08:52:58.077Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D1ZexPskLgkZZeth" /><figcaption>Photo by <a href="https://unsplash.com/@rahuulmiishra?utm_source=medium&amp;utm_medium=referral">Rahul Mishra</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>React Hooks are functions that let you use state and other React features without writing a class. Hooks allow developers to “hook into” React’s lifecycle and manage component states, side effects, and more functional components, making code more modular and concise.</p><h3><strong>1. useState</strong></h3><p><em>useState</em>: Manages local state in a functional component, It takes an initial state and returns an array with the state and a function to update it.</p><pre>const [state, setState] = useState(initalState);</pre><p>Here we are destructing the array returned by useState function which is taking the initialState variable.</p><blockquote>initialState: The value you want the state to be initially. It can be a value of any type, but there is a special behavior for functions. This argument is ignored after the initial render. but if you pass a function in initialState then it is treated as the <em>initializer</em> function. It should be pure, should take no arguments, and should return a value of any type.</blockquote><pre> const [formData, setFormData] = useState({<br>    name: &quot;&quot;,<br>    email: &quot;&quot;,<br>    password: &quot;&quot;<br>  });<br><br>  // Update the state when form inputs change<br>  const handleChange = (e) =&gt; {<br>    const { name, value } = e.target;<br>    setFormData((prevState) =&gt; ({<br>      ...prevState,<br>      [name]: value<br>    }));<br>  };<br><br>   &lt;form&gt;<br>      &lt;div&gt;<br>        &lt;label&gt;Name:&lt;/label&gt;<br>        &lt;input<br>          type=&quot;text&quot;<br>          name=&quot;name&quot;<br>          value={formData.name}<br>          onChange={handleChange}<br>        /&gt;<br>      &lt;/div&gt;<br>   &lt;/form&gt;<br></pre><p>In the above example, we can see in initialState we are passing an object with initalValue of name, email, and password as an empty string.<br>then inside the form, we are using an input tag in which “formData.name” is passed in the value attribute and any change on the input tag calls the function handleChange which updates the formData state based on input changes. The [name]: value syntax updates the correct field in the state object based on the name attribute of the input.</p><blockquote>In this example, we have only shown the input tag for Name. We can use a similar approach for the Email and Password fields as well.</blockquote><h3>2. useEffect</h3><p><strong><em>useEffect</em></strong>: Handles side effects like data fetching, subscriptions, or manually changing the DOM. It runs after every render by default but can be controlled with a dependency array to run only on specific state or prop changes.</p><blockquote>useEffect runs after every render (by default), and can optionally clean up for itself before it runs again.</blockquote><blockquote>It does not actively &quot;watch&quot; for changes. When you invoke useEffect in your component, it essentially schedules an effect to run after the render is complete.</blockquote><blockquote>Once rendering finishes, useEffect compares the current values of the dependencies against their values from the previous render. If any dependency has changed, it will execute your effect function.</blockquote><p>useEffect takes two arguments: the first is the callback function (the effect), and the second is an optional dependency array. By default, if your effect function doesn’t provide a cleanup function, it will simply return undefined. However, if a cleanup function is included, React will run this cleanup function when the component is removed from the DOM or before re-running the effect if any dependencies have changed.</p><pre>const [users, setUsers] = useState([]);<br>const [loading, setLoading] = useState(true);<br><br>useEffect(() =&gt; {<br>    // Fetch user data from the API when the component mounts<br>    const fetchUsers = async () =&gt; {<br>      try {<br>        const response = await fetch(&quot;https://jsonplaceholder.typicode.com/users&quot;);<br>        const data = await response.json();<br>        setUsers(data); // Update state with fetched data<br>        setLoading(false); // Set loading to false after data is fetched<br>      } catch (error) {<br>        console.error(&quot;Error fetching users:&quot;, error);<br>        setLoading(false); // Also stop loading if there’s an error<br>      }<br>    };<br><br>    fetchUsers();<br>  }, []); // Empty dependency array ensures this only runs once on mount<br><br> return (<br>    &lt;div&gt;<br>      &lt;h1&gt;User List&lt;/h1&gt;<br>      {loading ? (<br>        &lt;p&gt;Loading...&lt;/p&gt;<br>      ) : (<br>        &lt;ul&gt;<br>          {users.map((user) =&gt; (<br>            &lt;li key={user.id}&gt;{user.name}&lt;/li&gt;<br>          ))}<br>        &lt;/ul&gt;<br>      )}<br>    &lt;/div&gt;<br>  );</pre><ol><li><strong><em>State variable:</em></strong></li></ol><p>users: Holds the array of user data fetched from the API.</p><ul><li>loading: Keeps track of whether data is still being loaded.</li></ul><p>2. <strong><em>useEffect Hook</em></strong><em>:</em></p><ul><li>This useEffect runs only once when the component mounts because of the empty dependency array [].</li><li>Inside the effect, an asynchronous function fetchUsers fetches data from the API.</li><li>If the data fetch is successful, setUsers(data) updates the users state with the fetched data and sets loading to false.</li><li>If an error occurs, it is caught and logged to the console, and loading is also set to false.</li></ul><p>3.<em> </em><strong><em>Rendering</em></strong><em>:</em></p><ul><li>While loading is true, a loading message is displayed.</li><li>Once loading is complete, a list of user names is displayed.</li></ul><h3>Next Steps</h3><p>Check out the documentation for React to learn more about it:</p><ul><li><a href="https://react.dev/reference/react">https://react.dev/reference/react</a> (Official Docs)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98239974ed23" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javascript-decoded-in-plain-english/from-theory-to-practice-making-reacts-usestate-and-useeffect-work-for-you-98239974ed23">From Theory to Practice: Making React’s useState and useEffect Work for You</a> was originally published in <a href="https://medium.com/javascript-decoded-in-plain-english">JS Decoded in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>