<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Atul Kushwaha</title>
    <description>The latest articles on Forem by Atul Kushwaha (@coderatul).</description>
    <link>https://forem.com/coderatul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F480477%2F4b1eb2a7-8d55-4a36-a739-3519bfd0d368.png</url>
      <title>Forem: Atul Kushwaha</title>
      <link>https://forem.com/coderatul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/coderatul"/>
    <language>en</language>
    <item>
      <title>hey guys i have been learning linear algebra from a great teacher and friend of mine, in such a way that i was able to see a linear transformation happening in my mind should i make a series of blogs on LA ?</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Thu, 12 Feb 2026 06:58:01 +0000</pubDate>
      <link>https://forem.com/coderatul/hey-guys-i-have-been-learning-linear-algebra-from-a-great-teacher-and-friend-of-mine-in-such-a-way-523c</link>
      <guid>https://forem.com/coderatul/hey-guys-i-have-been-learning-linear-algebra-from-a-great-teacher-and-friend-of-mine-in-such-a-way-523c</guid>
      <description></description>
      <category>beginners</category>
      <category>discuss</category>
      <category>learning</category>
      <category>writing</category>
    </item>
    <item>
      <title>Context Switch 🔁 in REAL life</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Tue, 10 Feb 2026 08:15:57 +0000</pubDate>
      <link>https://forem.com/coderatul/context-switch-in-real-life-313o</link>
      <guid>https://forem.com/coderatul/context-switch-in-real-life-313o</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;ONLY THE BANNER IS AI GENERATED, BLOG ISN'T&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I love computer science because it is so practical. I recently experienced a real-life example of a &lt;strong&gt;context switch&lt;/strong&gt;. It’s a great analogy to explain what a context switch is and why the time quantum in Round Robin scheduling shouldn't be too small.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Concepts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Context Switch&lt;/strong&gt;: is defined as the procedure of Saving the state of the Old Process and Loading the state of the New Process&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PCB (Process Control Block):&lt;/strong&gt; A PCB is created for every individual process by the OS to track various parameters, such as the last executed statement (using the Program Counter), registers being used, and the data or files accessed by the process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Degree of Multiprogramming:&lt;/strong&gt; This refers to the number of processes present in the &lt;strong&gt;Ready State&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Exam Analogy
&lt;/h3&gt;

&lt;p&gt;I recently sat for the GATE 2026 exam. Imagine you are in the examination room. A common strategy we follow is this: you start solving a question but realize midway that it will take a huge chunk of your time. If you stayed on it, you would be blocked from answering other, easier questions btw, this is essentially the &lt;strong&gt;Convoy Effect&lt;/strong&gt; seen in FCFS (First-Come, First-Served) scheduling (i.e Process with large burst time blocking processes with significantly lesser burst time) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdvoovussjewdz1i5ib3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdvoovussjewdz1i5ib3.gif" alt="Thinking" width="480" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To avoid this, you leave the question half-solved and jump to another. This is essentially a &lt;strong&gt;context switch&lt;/strong&gt;. Leaving the question is equivalent to saving its context (i.e., leaving the page in your scribble pad where you were working so the half-solved answer remains there).&lt;/p&gt;

&lt;p&gt;In an OS, there are several reasons to perform a context switch:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Higher Priority Process:&lt;/strong&gt; Similar to realizing the current question is worth 1 mark, but there are 2-mark questions left.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interrupts:&lt;/strong&gt; Similar to an invigilator coming to your desk for an attendance sheet signature.
etc etc....&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Saving and Loading Context
&lt;/h3&gt;

&lt;p&gt;let's say now the next question you are solving is new, i.e you haven't read that question yet, so there is nothing you know about the question and hence nothing to retrieve from brain (except obv the concepts you'd use to solve it) btw this can also be seen as runtime environment&lt;/p&gt;

&lt;p&gt;Runtime environment, manages essential tasks like memory allocation, dynamic linking, and resource access (e.g., files, networks, I/O devices), independent of the specific OS.&lt;/p&gt;

&lt;p&gt;coming back, so a this action is same as switching to a new process in terms of OS, you save the context of the current process in its PCB. &lt;/p&gt;

&lt;p&gt;Similarly, in an exam, when you switch to a new question, you are saving the context of your current work simply by leaving it as is. Since the next question is new, there is no need to "load" a previous context because it does not yet exist; instead, you initiate a new context by reading the question and writing down the given data.&lt;/p&gt;

&lt;p&gt;However, if you switch back to a question you left earlier, it is equivalent to saving the current context and &lt;strong&gt;loading&lt;/strong&gt; the context of the old, partially executed process in terms of OS. Just as the half-solved answer on your scribble pad is the "context" that needs to be loaded back into your brain to resume solving the earlier left question, the OS retrieves the saved state from the PCB to continue execution of earlier partially executed process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Small Qt in Round Robbin
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lwce9j5quxqgszpm2vw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lwce9j5quxqgszpm2vw.gif" alt="Panic GIF" width="320" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, imagine there are only 10 minutes left. In a panic, you start a question, realize it’s too long, switch to another, realize the same, and switch again. You are now acting like a &lt;strong&gt;Round Robin algorithm with an extremely small time quantum&lt;/strong&gt;. You end up spending more time switching between questions (the overhead) than actually solving them.&lt;/p&gt;

&lt;p&gt;also, If the invigilator takes your paper away because time is up, that is a Preemptive Context Switch. You didn't choose to leave the question; the OS (Invigilator) forced you out because your 'Time Quantum' expired.&lt;/p&gt;

&lt;p&gt;also If you’ve ever struggled to differentiate between these two:&lt;/p&gt;

&lt;h3&gt;
  
  
  Parallel vs. Concurrent Execution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parallel Execution:&lt;/strong&gt; This is only possible with multiple CPUs or multiple cores within a CPU. It would mean solving three questions simultaneously at the same time while its possible for CPU's with multiple cores not possible for us humans as we only have 1 brain (cpu)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Concurrent Execution:&lt;/strong&gt; as human being's we only have a single brain(CPU), we can only work on a single task at a time, here i was not solving questions parallelly but concurrently i.e., solving multiple question in an interleaved fashion so i could cover maximum questions and making sure that my time utilization is maximum&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;which is the sole goal of concurrent programming i.e. executing multiple process concurrently in an interleaved fashion so that the CPU utilization can be maximized &lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>beginners</category>
      <category>basic</category>
      <category>learning</category>
    </item>
    <item>
      <title>Free custom domain for your projects 😉</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Sun, 04 May 2025 11:10:33 +0000</pubDate>
      <link>https://forem.com/coderatul/free-custom-domain-for-your-projects-3j7j</link>
      <guid>https://forem.com/coderatul/free-custom-domain-for-your-projects-3j7j</guid>
      <description>&lt;p&gt;The GitHub Student Developer Pack offers students free access to premium developer tools and services, including cloud credits, CI/CD platforms, and more. Follow this step-by-step guide to join the program, unlock these benefits, and claim a free domain from Namecheap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Join the GitHub Student Developer Pack
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Verify Your Student Status
&lt;/h3&gt;

&lt;p&gt;To qualify for the GitHub Student Developer Pack, you must be a current student (at least 13 years old) enrolled in a degree or diploma-granting program. Here's how to confirm eligibility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Check Requirements&lt;/strong&gt;: Ensure you have a verifiable school-issued email address (e.g., ending in &lt;code&gt;.edu&lt;/code&gt;) or other documentation like a student ID, transcript, or enrollment letter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prepare Documentation&lt;/strong&gt;: If you don’t have a school email, gather a clear image or PDF of your student ID, transcript, or an official letter from your school stating your enrollment status.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create or Log In to Your GitHub Account
&lt;/h3&gt;

&lt;p&gt;You’ll need a GitHub account to apply for the pack.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sign Up&lt;/strong&gt;: If you don’t have an account, go to &lt;a href="https://github.com" rel="noopener noreferrer"&gt;github.com&lt;/a&gt; and click “Sign up.” Follow the prompts to create a free account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log In&lt;/strong&gt;: If you already have an account, log in with your credentials.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Navigate to the GitHub Education Page
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Visit the GitHub Education website at &lt;a href="https://education.github.com" rel="noopener noreferrer"&gt;education.github.com&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Scroll to the “GitHub Student Developer Pack” section and click &lt;strong&gt;Get the Pack&lt;/strong&gt; or &lt;strong&gt;Get started&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Start the Application Process
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;On the GitHub Student Developer Pack page, click &lt;strong&gt;Get your pack&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You’ll be redirected to a form to verify your academic status.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Complete the Application Form
&lt;/h3&gt;

&lt;p&gt;Fill out the application form with the following details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Personal Information&lt;/strong&gt;: Enter your full name and GitHub username.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;School Email&lt;/strong&gt;: Provide your school-issued email address if available. This is the fastest way to get verified.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alternative Verification&lt;/strong&gt;: If you don’t have a school email, select the option to upload documentation. Upload a clear image or PDF of your student ID, transcript, or enrollment letter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Briefly describe how you plan to use the Student Developer Pack (e.g., for coding projects, learning, or open-source contributions).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Submit Your Application
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Review your information and uploaded documents (if applicable).&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Submit&lt;/strong&gt; to send your application to GitHub for review.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Wait for Verification
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;School Email&lt;/strong&gt;: If you used a school-issued email, verification is often instant or takes a few hours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manual Review&lt;/strong&gt;: If you uploaded documents, GitHub’s team will review them, which may take 1–5 business days.&lt;/li&gt;
&lt;li&gt;You’ll receive an email notification once your application is approved or if additional information is needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Access Your Benefits
&lt;/h3&gt;

&lt;p&gt;Once approved, you’ll gain access to the GitHub Student Developer Pack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in to your GitHub account.&lt;/li&gt;
&lt;li&gt;Visit &lt;a href="https://education.github.com/pack" rel="noopener noreferrer"&gt;education.github.com/pack&lt;/a&gt; to explore available tools and services.&lt;/li&gt;
&lt;li&gt;Redeem offers by following the instructions for each partner (e.g., DigitalOcean, Heroku, or Namecheap). Some may require linking your GitHub account or signing up separately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Renew Your Benefits (If Needed)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The Student Developer Pack is valid as long as you’re a student.&lt;/li&gt;
&lt;li&gt;GitHub may periodically ask you to re-verify your student status. Follow the same process to upload updated documentation or confirm your enrollment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tips for a Smooth Application
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use a School Email&lt;/strong&gt;: If available, this speeds up verification significantly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clear Documentation&lt;/strong&gt;: Ensure uploaded documents are legible and include your name, school, and current enrollment date.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check Spam Folder&lt;/strong&gt;: GitHub’s response email may land in your spam or junk folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contact Support&lt;/strong&gt;: If you face issues or delays, reach out to GitHub Support via &lt;a href="https://support.github.com" rel="noopener noreferrer"&gt;support.github.com&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Avail a Free Domain from Namecheap
&lt;/h2&gt;

&lt;p&gt;One of the many benefits of the GitHub Student Developer Pack is access to a free domain from Namecheap. Follow these steps to claim and set up your domain for use with GitHub Pages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Claim the Free Domain&lt;/strong&gt;: Among the benefits, you can claim a free &lt;code&gt;.me&lt;/code&gt; domain from Namecheap. After claiming the domain, a repository named &lt;code&gt;your-username.github.io&lt;/code&gt; will be created in your GitHub account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repository Contents&lt;/strong&gt;: This repository will contain a &lt;code&gt;CNAME&lt;/code&gt; file with your domain name as its content and a README file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Note on SSL&lt;/strong&gt;: For GitHub Pages, you don’t need to avail a free SSL certificate, as GitHub provides HTTPS automatically. However, if you plan to deploy your project elsewhere, you may need one, which is also freely available &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;validity of domain name&lt;/strong&gt;: 1 year&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznlpuo2cfjtk4s1kb5cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznlpuo2cfjtk4s1kb5cw.png" alt="namecheap" width="634" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Set Up the Domain in GitHub
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to your GitHub account’s &lt;strong&gt;Settings&lt;/strong&gt; &amp;gt; &lt;strong&gt;Pages&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Under the “Custom domain” section, click &lt;strong&gt;Add a domain&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6tzwyj3ret77vf4txjbk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6tzwyj3ret77vf4txjbk.png" alt="git1" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter your domain name (e.g., &lt;code&gt;yourname.me&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;GitHub will prompt you to verify ownership of the domain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5u07f26kihyeyk8hnbdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5u07f26kihyeyk8hnbdf.png" alt="git2" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Verify Domain Ownership with Namecheap
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Log in to your &lt;a href="https://namecheap.com" rel="noopener noreferrer"&gt;Namecheap account&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Navigate to the &lt;strong&gt;Dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Find your domain and click &lt;strong&gt;Manage&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg7bkv4wptjb3pvh07r9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg7bkv4wptjb3pvh07r9.png" alt="git3" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the &lt;strong&gt;Advanced DNS&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Add a &lt;strong&gt;TXT record&lt;/strong&gt; to verify ownership:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Host&lt;/strong&gt;: Use the value provided by GitHub (e.g., &lt;code&gt;_github-pages-challenge-yourusername&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Value&lt;/strong&gt;: Enter the verification code provided by GitHub (e.g., &lt;code&gt;81e12bbe76d30d12897eea833d7ree&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TTL&lt;/strong&gt;: Set to 1 minute.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Save the changes.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqlkc5d5c9m8e57n5fycm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqlkc5d5c9m8e57n5fycm.png" alt="git4" width="530" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Return to the GitHub Pages settings and click &lt;strong&gt;Verify&lt;/strong&gt;. GitHub will check the TXT record to confirm ownership. This process may take up to 12 hours.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add a CNAME Record (Optional)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In Namecheap’s &lt;strong&gt;Advanced DNS&lt;/strong&gt; tab, you can also add a &lt;strong&gt;CNAME record&lt;/strong&gt; to point your domain to GitHub Pages:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Type&lt;/strong&gt;: CNAME Record&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Host&lt;/strong&gt;: &lt;code&gt;www&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Value&lt;/strong&gt;: &lt;code&gt;your-username.github.io&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TTL&lt;/strong&gt;: 1 min&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fahhn4bxvybk7ozrtpxwr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fahhn4bxvybk7ozrtpxwr.png" alt="git5" width="800" height="40"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enable HTTPS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;After 12 hours, once the domain is verified, it may show a “Connection not secure” warning.&lt;/li&gt;
&lt;li&gt;To enable a secure HTTPS connection, navigate to the &lt;code&gt;your-username.github.io&lt;/code&gt; repository’s &lt;strong&gt;Settings&lt;/strong&gt; &amp;gt; &lt;strong&gt;Pages&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Check the box for &lt;strong&gt;Enforce HTTPS&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdawo6u3psyai67g1qsnh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdawo6u3psyai67g1qsnh.png" alt="git6" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;By joining the GitHub Student Developer Pack and claiming a free domain from Namecheap, you can enhance your development projects with professional tools and a custom domain. Follow these steps to set up your GitHub Pages site with a verified, secure domain. Start your journey today at &lt;a href="https://education.github.com/pack/join" rel="noopener noreferrer"&gt;education.github.com/pack/join&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>github</category>
      <category>tutorial</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
    <item>
      <title>create and deploy projects seemleasly</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Fri, 02 May 2025 08:29:50 +0000</pubDate>
      <link>https://forem.com/coderatul/create-and-deploy-projects-seemleasly-43a</link>
      <guid>https://forem.com/coderatul/create-and-deploy-projects-seemleasly-43a</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/coderatul/host-lovabledev-project-on-github-pages-1c61" class="crayons-story__hidden-navigation-link"&gt;Host Lovable.dev Project on github pages 😺&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/coderatul" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F480477%2F4b1eb2a7-8d55-4a36-a739-3519bfd0d368.png" alt="coderatul profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/coderatul" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Atul Kushwaha
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Atul Kushwaha
                
              
              &lt;div id="story-author-preview-content-2453319" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/coderatul" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F480477%2F4b1eb2a7-8d55-4a36-a739-3519bfd0d368.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Atul Kushwaha&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/coderatul/host-lovabledev-project-on-github-pages-1c61" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 2 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/coderatul/host-lovabledev-project-on-github-pages-1c61" id="article-link-2453319"&gt;
          Host Lovable.dev Project on github pages 😺
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/github"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;github&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/tutorial"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;tutorial&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/coderatul/host-lovabledev-project-on-github-pages-1c61" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;35&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/coderatul/host-lovabledev-project-on-github-pages-1c61#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              24&lt;span class="hidden s:inline"&gt; comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>github</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Host Lovable.dev Project on github pages 😺</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Fri, 02 May 2025 08:28:42 +0000</pubDate>
      <link>https://forem.com/coderatul/host-lovabledev-project-on-github-pages-1c61</link>
      <guid>https://forem.com/coderatul/host-lovabledev-project-on-github-pages-1c61</guid>
      <description>&lt;h2&gt;
  
  
  Deploying a Lovable.dev Project to GitHub Pages
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;link to the blog to get free custom &lt;code&gt;.me&lt;/code&gt; domain name &lt;a href="https://dev.to/coderatul/free-custom-domain-for-your-projects-3j7j"&gt;Free custom domain for your projects 😉&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Here is the link to my &lt;a href="https://coderatul.me" rel="noopener noreferrer"&gt;portfolio&lt;/a&gt;, generated by &lt;a href="https://lovable.dev" rel="noopener noreferrer"&gt;lovable.dev&lt;/a&gt; and hosted on &lt;a href="https://pages.github.com/" rel="noopener noreferrer"&gt;GitHub Pages&lt;/a&gt;
&lt;/h2&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, ensure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Node.js (version 18 or higher) installed on your system.&lt;/li&gt;
&lt;li&gt;Basic knowledge of Git and GitHub.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Step 1: Connect &lt;a href="https://lovable.dev" rel="noopener noreferrer"&gt;lovable.dev&lt;/a&gt; with &lt;a href="https://github.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6okw0bvjhvracpyv6io.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6okw0bvjhvracpyv6io.png" alt="connect github" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;code&gt;View on GitHub&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Clone this private project locally on your machine.&lt;/li&gt;
&lt;li&gt;Open a terminal in your cloned repository location. First, we are going to remove all Git files. For Windows, type:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Remove-Item&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Recurse&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Force&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;git&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# Check if Git files still exist&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This will remove all Git-related files from your project.&lt;/li&gt;
&lt;li&gt;Now we can try running the project locally:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;       &lt;span class="c"&gt;# Install all dependencies&lt;/span&gt;
npm run build
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6.Make any changes to the code if needed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: Create a New Repo for GitHub Pages and Update Config
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a new repository, say &lt;code&gt;coderatul-portfolio&lt;/code&gt;, on GitHub.&lt;/li&gt;
&lt;li&gt;Clone this newly created repository to your machine.&lt;/li&gt;
&lt;li&gt;Copy and paste all files from your original project (where Git was removed) to this new repo &lt;code&gt;coderatul-portfolio&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You may now delete the initially cloned repository, as we have all source code where we need it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Update &lt;code&gt;vite.config.ts&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;base&lt;/code&gt; property in the Vite configuration file (&lt;code&gt;vite.config.ts&lt;/code&gt;) must be set to the repository name for GitHub Pages. This ensures that all asset paths are correctly resolved.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@vitejs/plugin-react-swc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;componentTagger&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lovable-tagger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;::&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nf"&gt;componentTagger&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;alias&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;base&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/coderatul-portfolio/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// Replace with your GitHub repo name&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3: Push Code to GitHub and Set Up Workflow via GitHub Actions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Push the changes to your repository say &lt;code&gt;coderatul-portfolio&lt;/code&gt; here:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"adding project"&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Grant access for workflow:
Visit &lt;code&gt;https://github.com/&amp;lt;your-username&amp;gt;/&amp;lt;your-repository-name&amp;gt;/settings/actions&lt;/code&gt;, scroll down, make the necessary changes, and save.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mrfhg9muyhivt8b20vv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mrfhg9muyhivt8b20vv.png" alt="permission" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your repository, go to &lt;strong&gt;Settings &amp;gt; Pages&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwebkliglkvvazfgmujbb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwebkliglkvvazfgmujbb.png" alt="t0" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;code&gt;GitHub Actions&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then select &lt;code&gt;GitHub Pages Jekyll&lt;/code&gt; and click &lt;code&gt;Configure&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq95ztt93h5jod1ykzf8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq95ztt93h5jod1ykzf8v.png" alt="t1" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit the workflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feh13u4jiqijp9qt6qdxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feh13u4jiqijp9qt6qdxa.png" alt="t2" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Modify &lt;code&gt;workflow.yaml&lt;/code&gt; as follows:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy to GitHub Pages&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt; 
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt; 
  &lt;span class="na"&gt;pages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;    

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout code&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Setup Node.js&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v3&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;18&lt;/span&gt; 

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Vite GitHub Pages Deployer&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;skywarth/vite-github-pages-deployer@v1.5.0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;public_base_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/coderatul-portfolio/&lt;/span&gt;  &lt;span class="c1"&gt;# Replace with your repository name&lt;/span&gt;
          &lt;span class="na"&gt;build_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./dist&lt;/span&gt;
          &lt;span class="na"&gt;install_phase_node_env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dev&lt;/span&gt;
          &lt;span class="na"&gt;build_phase_node_env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;production&lt;/span&gt;
          &lt;span class="na"&gt;package_manager&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm&lt;/span&gt;
          &lt;span class="na"&gt;artifact_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github-pages&lt;/span&gt;
          &lt;span class="na"&gt;debug_mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
          &lt;span class="na"&gt;working_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 4: Verify the Deployment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Make appropriate changes, paste the modified &lt;code&gt;workflow.yaml&lt;/code&gt;, commit it, and the workflow will start under the &lt;strong&gt;Actions&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Settings &amp;gt; Pages&lt;/strong&gt;, you’ll see a live link to the deployed project.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What is a Workflow?
&lt;/h3&gt;

&lt;p&gt;A workflow automates the process: any time you push code, GitHub Actions will automatically build and deploy your project. This is part of CI/CD.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Issues and Fixes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Blank Page After Deployment&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Make sure the &lt;code&gt;base&lt;/code&gt; property in &lt;code&gt;vite.config.ts&lt;/code&gt; is correctly set to &lt;code&gt;/repository-name/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Clear browser cache or use incognito mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;403 Permission Errors&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure the &lt;code&gt;GITHUB_TOKEN&lt;/code&gt; in your workflow has the correct permissions:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
  &lt;span class="na"&gt;pages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;strong&gt;Asset Paths Not Resolving&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Double-check the &lt;code&gt;base&lt;/code&gt; property in &lt;code&gt;vite.config.ts&lt;/code&gt; and ensure it matches your repo name.&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;Deploying a &lt;code&gt;lovable.dev&lt;/code&gt; project to GitHub Pages is simple with the right setup. By setting the &lt;code&gt;base&lt;/code&gt; path in &lt;code&gt;vite.config.ts&lt;/code&gt; and automating deployment using GitHub Actions, you can publish your project effortlessly.&lt;/p&gt;

</description>
      <category>github</category>
      <category>tutorial</category>
      <category>ai</category>
      <category>webdev</category>
    </item>
    <item>
      <title>hey guys speed up your python code, especially with dynamic programming and recursive functions</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Fri, 11 Apr 2025 08:01:59 +0000</pubDate>
      <link>https://forem.com/coderatul/hey-guys-speed-up-your-python-code-especially-with-dynamic-programming-and-recursive-functions-2hol</link>
      <guid>https://forem.com/coderatul/hey-guys-speed-up-your-python-code-especially-with-dynamic-programming-and-recursive-functions-2hol</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/coderatul/cache-in-python--18g" class="crayons-story__hidden-navigation-link"&gt;Cache in Python !&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/coderatul" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F480477%2F4b1eb2a7-8d55-4a36-a739-3519bfd0d368.png" alt="coderatul profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/coderatul" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Atul Kushwaha
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Atul Kushwaha
                
              
              &lt;div id="story-author-preview-content-2399152" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/coderatul" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F480477%2F4b1eb2a7-8d55-4a36-a739-3519bfd0d368.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Atul Kushwaha&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/coderatul/cache-in-python--18g" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 11 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/coderatul/cache-in-python--18g" id="article-link-2399152"&gt;
          Cache in Python !
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/cache"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;cache&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/learning"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;learning&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/coderatul/cache-in-python--18g" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt; reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/coderatul/cache-in-python--18g#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>python</category>
      <category>cache</category>
      <category>learning</category>
    </item>
    <item>
      <title>Cache in Python !</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Fri, 11 Apr 2025 08:00:41 +0000</pubDate>
      <link>https://forem.com/coderatul/cache-in-python--18g</link>
      <guid>https://forem.com/coderatul/cache-in-python--18g</guid>
      <description>&lt;h2&gt;
  
  
  Exploring Python's &lt;code&gt;functools&lt;/code&gt;: Cache, Cached Property, and LRU Cache
&lt;/h2&gt;

&lt;p&gt;Python's &lt;code&gt;functools&lt;/code&gt; module is a treasure trove for functional programming enthusiasts, offering tools to make your code more efficient and elegant. In this post, we'll dive into three powerful functions—&lt;code&gt;cache&lt;/code&gt;, &lt;code&gt;cached_property&lt;/code&gt;, and &lt;code&gt;lru_cache&lt;/code&gt;—that help optimize performance by storing results of expensive computations. Whether you're speeding up recursive algorithms or simplifying class-based calculations, these tools have you covered. Let’s explore each one with clear explanations and practical examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;cache&lt;/code&gt;: Simple, Unbounded Memoization
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;cache&lt;/code&gt; decorator is a lightweight way to memoize function results, storing them for reuse when the same inputs occur again. It’s like a sticky note for your function’s outputs—no recomputation needed!&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What it does&lt;/strong&gt;: Stores function results in an unbounded dictionary, using arguments as keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When to use it&lt;/strong&gt;: Ideal for pure functions (same input, same output) that are computationally expensive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key feature&lt;/strong&gt;: It’s equivalent to &lt;code&gt;lru_cache(maxsize=None)&lt;/code&gt; but faster due to its simplicity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;

&lt;span class="nd"&gt;@cache&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;  &lt;span class="c1"&gt;# Computes: 3628800
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;  &lt;span class="c1"&gt;# Returns cached result, no recomputation
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why It’s Awesome
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Speed: Avoids redundant calculations, making recursive functions like factorial lightning-fast.&lt;/li&gt;
&lt;li&gt;Simplicity: No configuration needed—just slap on the decorator.&lt;/li&gt;
&lt;li&gt;Caveat: The cache grows indefinitely, so monitor memory usage for functions with many unique inputs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;cached_property&lt;/code&gt;: One-Time Property Computation
&lt;/h2&gt;

&lt;p&gt;The cached_property decorator transforms a class method into a property that computes its value once and caches it for the instance. Think of it as a lazy-loaded attribute that sticks around.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What it does: Runs the method the first time it’s accessed, caches the result as an instance attribute, and returns the cached value on subsequent calls.&lt;/li&gt;
&lt;li&gt;When to use it: Perfect for expensive calculations in classes that don’t change after the first computation.
Key feature: Works only with instance methods (requires self).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cached_property&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;

    &lt;span class="nd"&gt;@cached_property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Computing area&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mf"&gt;3.14159&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;radius&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Prints: Computing area, then 78.53975
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Prints: 78.53975 (cached, no recomputation)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why It’s Awesome
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Efficiency: Computes only once per instance, saving CPU cycles.&lt;/li&gt;
&lt;li&gt;Clean code: Reads like a property (c.area vs. c.area()), blending seamlessly into class design.&lt;/li&gt;
&lt;li&gt;Caveat: The cached value can be overridden (e.g., c.area = 0), so use it for immutable data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;lru_cache&lt;/code&gt;: Flexible, Bounded Memoization
&lt;/h2&gt;

&lt;p&gt;The lru_cache decorator is the heavy hitter of memoization, offering a Least Recently Used (LRU) cache with configurable size. It’s thread-safe and packed with introspection features, making it a go-to for optimizing complex functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What it does: Caches up to maxsize results, evicting the least recently used entry when full. Supports a typed option to treat different types (e.g., 3 vs. 3.0) as distinct keys.&lt;/li&gt;
&lt;li&gt;When to use it: Great for recursive algorithms, dynamic programming, or any function with repetitive calls.&lt;/li&gt;
&lt;li&gt;Key feature: Provides cache_info() to inspect hits, misses, and cache size.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;lru_cache&lt;/span&gt;

&lt;span class="nd"&gt;@lru_cache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;  &lt;span class="c1"&gt;# Computes: 55
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cache_info&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;  &lt;span class="c1"&gt;# Shows: CacheInfo(hits=8, misses=11, maxsize=32, currsize=11)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why It’s Awesome
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Control: Set maxsize to balance memory and performance (use None for unbounded, like cache).&lt;/li&gt;
&lt;li&gt;Thread-safe: Safe for multithreaded applications, ensuring the cache stays consistent.&lt;/li&gt;
&lt;li&gt;Debugging: cache_info() helps you tune performance by revealing cache effectiveness.&lt;/li&gt;
&lt;li&gt;Caveat: Avoid using with functions that have side effects, as the cache assumes deterministic outputs.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>cache</category>
      <category>learning</category>
    </item>
    <item>
      <title>Memory Handling in Java</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Mon, 04 Mar 2024 13:19:15 +0000</pubDate>
      <link>https://forem.com/coderatul/memory-handling-in-java-jc6</link>
      <guid>https://forem.com/coderatul/memory-handling-in-java-jc6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Before diving into memory management of java one must know java has primitive datatypes and more complex objects (reference types)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Primitive type&lt;/li&gt;
&lt;li&gt;refference type&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Java has no concept of pointers and java only has pass by value, there is nothing like pass by reference in java&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  primitives
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Primitive types are the basic data types provided by a programming language. &lt;/li&gt;
&lt;li&gt;They are the simplest and most fundamental building blocks of data. In Java, the primitive types include:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ficc9rqmutyfqkoyneyjh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ficc9rqmutyfqkoyneyjh.gif" alt="primitives" width="500" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Integral Types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;byte: 8-bit signed integer&lt;/li&gt;
&lt;li&gt;short: 16-bit signed integer&lt;/li&gt;
&lt;li&gt;int: 32-bit signed integer
-long: 64-bit signed integer&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Floating-Point Types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;float: 32-bit floating-point&lt;/li&gt;
&lt;li&gt;double: 64-bit floating-point&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Characters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;char: 16-bit Unicode character&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Boolean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;boolean: Represents true or false.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  Reference type
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reference types are more complex and are used to store references (memory addresses) to objects. Objects are instances of classes or arrays. In Java, reference types include:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5ab2jwx20pcs0ipsv03.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5ab2jwx20pcs0ipsv03.gif" alt="modern" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Objects:

&lt;ul&gt;
&lt;li&gt;Instances of classes created using the new keyword.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Arrays:

&lt;ul&gt;
&lt;li&gt;Ordered collections of elements.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Interfaces:

&lt;ul&gt;
&lt;li&gt;Types representing a contract for classes to implement.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  How primitives are stored ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;All data for primitive type variables is stored on the stack&lt;/li&gt;
&lt;li&gt;when setting a primitive type variable equal to another primitive type variable, a copy of value is made.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int a  = 10;
int b = 20;
int c = b;
int c = 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2ld0vw94lz7d3eov2lm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2ld0vw94lz7d3eov2lm.png" alt="primitive_stack" width="246" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;int a = 10; -&amp;gt; int 10 is stored on stack memory&lt;br&gt;
  int b = 20; -&amp;gt; int 20 is stored on stack memory&lt;br&gt;
  int c = b; -&amp;gt; value of b(20) is copied to c&lt;br&gt;
  int c = 100; -&amp;gt; value of c is modified to 100&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How Reference type stores value ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For reference types, the stack holds a pointer to the object on the heap memory&lt;/li&gt;
&lt;li&gt;When setting a reference type variable equal to another reference type variabel, a copy of only the pointer is made&lt;/li&gt;
&lt;li&gt;Certain object types can't be manipulated on the heap(immutables)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdvxwxaa6ovupevc6ahm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdvxwxaa6ovupevc6ahm.png" alt="referecne type" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;int[ ] c = {1,2,3,4}; -&amp;gt; creates an array of integers in the heap memory and stack has a reference to that objetc in heap&lt;/li&gt;
&lt;li&gt;int[ ] d = c; -&amp;gt; value of reference(stored in stack) is copied from variable c(stack) to variable d(stack), no new object is cretaed in the heap memory (and not the actual object)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;d[1] = 99; -&amp;gt; value of object at index 1 is changed by variable d, which had reference of object {1,2,3,4,5} hence value is also changed for variable c, as they were having the same reference in the stack memory&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;d = new int[5]; -&amp;gt; a new array is created in th heap memory and d rerences to that new array&lt;/li&gt;
&lt;li&gt;int[ ] e = {5,6,7,8} -&amp;gt; creates a new array in heap memory&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;int [ ] f = {5,6,7,8} -&amp;gt; also creates a new array in the heap although content of array &lt;code&gt;e&lt;/code&gt; and &lt;code&gt;f&lt;/code&gt;is same still the exist in various memory space &lt;/p&gt;

&lt;p&gt;f[1] = 99 -&amp;gt; this would only change index at 1 position for array &lt;code&gt;f&lt;/code&gt; and not for array &lt;code&gt;e&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;String g = "hello"; -&amp;gt; a new string with value "hello" is created in the heap memory&lt;/li&gt;
&lt;li&gt;String h = g; -&amp;gt; value of reference stored in stack memory is copied form &lt;code&gt;g&lt;/code&gt; to &lt;code&gt;h&lt;/code&gt;(and not the actual object object)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;h = "goodbye"; -&amp;gt; you might be expecting that the value of string &lt;code&gt;g&lt;/code&gt; should also have been changed as both &lt;code&gt;g&lt;/code&gt; and &lt;code&gt;h&lt;/code&gt; are pointing at same string, but as Strings are &lt;code&gt;immutable&lt;/code&gt; meaning they can't be modified, so instead a new string "goodbye" is cretaed and it's reference is assigned to &lt;code&gt;h&lt;/code&gt; and &lt;code&gt;g&lt;/code&gt; still points to hello&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@BillBarnum" rel="noopener noreferrer"&gt;for more reference and image credit&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>learning</category>
    </item>
    <item>
      <title>Thread synchronization in python's threading module</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Fri, 01 Mar 2024 14:18:04 +0000</pubDate>
      <link>https://forem.com/coderatul/thread-synchronization-in-pythons-threading-module-3aff</link>
      <guid>https://forem.com/coderatul/thread-synchronization-in-pythons-threading-module-3aff</guid>
      <description>&lt;p&gt;As we saw 👁️👁️ in our previous blogs, threading is susceptible to race conditions. To tackle race conditions, we may use locks and semaphores to manage synchronization and data consistency while using threads&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are 3 major techniques for thread synchronization&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lock 🔒&lt;/li&gt;
&lt;li&gt;Rlock ®️🔒&lt;/li&gt;
&lt;li&gt;Semaphore, BoundedSemaphore&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Lock
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A Lock is a basic &lt;code&gt;synchronization primitive&lt;/code&gt; that provides exclusive access to a shared resource.&lt;/li&gt;
&lt;li&gt;It has two states: &lt;code&gt;locked&lt;/code&gt; and &lt;code&gt;unlocked&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Only one thread can acquire the lock at a time. If another thread tries to acquire a locked lock, it will be blocked until the lock is released.&lt;/li&gt;
&lt;li&gt;It is not reentrant, meaning that a thread holding the lock cannot acquire it again without releasing it first.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;with&lt;/code&gt; context manager, manages acquiring and releasing lock for us, other wise we can use lock.acquire() and lock.release() methods as well&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;threading&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Lock&lt;/span&gt;

&lt;span class="nx"&gt;lock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Lock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;critical&lt;/span&gt; &lt;span class="nx"&gt;section&lt;/span&gt;
        &lt;span class="nx"&gt;pass&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  RLock (Reentrant Lock):
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;An RLock is an extension of the basic Lock that allows a thread to acquire the &lt;code&gt;lock multiple times&lt;/code&gt; (reentrant).&lt;/li&gt;
&lt;li&gt;A thread that already holds the lock can acquire it again without blocking, but it must release the lock the same number of times it acquired it.&lt;/li&gt;
&lt;li&gt;Useful in situations where a function might need to acquire the same lock recursively.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;threading&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;RLock&lt;/span&gt;

&lt;span class="nx"&gt;rlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RLock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;rlock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;critical&lt;/span&gt; &lt;span class="nx"&gt;section&lt;/span&gt;
        &lt;span class="nx"&gt;pass&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Semaphore
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A Semaphore is a more &lt;code&gt;generalized synchronization primitive&lt;/code&gt; that allows a specified number of threads to access a shared resource concurrently.&lt;/li&gt;
&lt;li&gt;It maintains a counter that is decremented each time a thread acquires it and incremented when the thread releases it.&lt;/li&gt;
&lt;li&gt;Useful for controlling access to a resource with limited capacity.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;threading&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Semaphore&lt;/span&gt;

&lt;span class="nx"&gt;semaphore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Semaphore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Allow&lt;/span&gt; &lt;span class="nx"&gt;up&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="nx"&gt;threads&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;access&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="nx"&gt;concurrently&lt;/span&gt;

&lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;semaphore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;critical&lt;/span&gt; &lt;span class="nx"&gt;section&lt;/span&gt;
        &lt;span class="nx"&gt;pass&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  BoundedSemaphore
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A BoundedSemaphore is similar to Semaphore but has an &lt;code&gt;upper limit&lt;/code&gt; on its counter.&lt;/li&gt;
&lt;li&gt;It raises a ValueError if the counter exceeds the specified bound when incremented.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;threading&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;BoundedSemaphore&lt;/span&gt;

&lt;span class="nx"&gt;bounded_semaphore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BoundedSemaphore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Bound&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;semaphore&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="nx"&gt;up&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="nx"&gt;threads&lt;/span&gt;

&lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;bounded_semaphore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;critical&lt;/span&gt; &lt;span class="nx"&gt;section&lt;/span&gt;
        &lt;span class="nx"&gt;pass&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In summary, Lock and RLock provide exclusive access to a shared resource, while Semaphore and BoundedSemaphore allow a specified number of threads to access a shared resource concurrently. The choice between them depends on the synchronization requirements of your multithreaded application&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>aync</category>
    </item>
    <item>
      <title>Race condition in Python's threading🏁</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Mon, 26 Feb 2024 05:00:00 +0000</pubDate>
      <link>https://forem.com/coderatul/race-condition-in-pythons-threading-3o4g</link>
      <guid>https://forem.com/coderatul/race-condition-in-pythons-threading-3o4g</guid>
      <description>&lt;p&gt;we starting this blog let's quicky understand what's a race condition 🏎️&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbDd1Y2diejVzdGlhcm10cGoxcG1xcXZrMjllNHh2NzhwdngzNnk1bSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l2JdXVTmHNtvlydzO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbDd1Y2diejVzdGlhcm10cGoxcG1xcXZrMjllNHh2NzhwdngzNnk1bSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l2JdXVTmHNtvlydzO/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Race condition is everywhere, we can see this b/w top cloud providers like AWS, GCP, Azure to acquire the position of Top cloud provider 
&amp;gt; now, with context of threading Race condtion leads to unexpected outcomes when multiple threads try to access and manipulate a single shared resource (file, varibales etc)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  intuitive doubt
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the context of threading, race conditions arise when multiple threads attempt to access and manipulate a shared resource, such as a file or variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You might wonder about the impact of the Global Interpreter Lock (GIL), which only allows one thread of a process to run at any given time. Despite this limitation, race conditions can still occur.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;let's take an example to better understand&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;threading&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current_thread&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BookTicket&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;available_seats&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;available_seats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;available_seats&lt;/span&gt;

    &lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;Bookseat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;seatToBeBooked&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{self.available_seats} seat was available before booking.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;current_thread&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;seatToBeBooked&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;available_seats&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;available_seats&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="nx"&gt;seatToBeBooked&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{seatToBeBooked} seat has been allocated to {name}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sorry, we are out of seats.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BookTicket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;T1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Bookseat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;kwargs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;seatToBeBooked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Walter White&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;T2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Bookseat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;kwargs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;seatToBeBooked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jesse Pinkman&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;T1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;T2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;quick explanation on what's going in above code&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;so we have two threads namely walter white and jesse pinkman, and these threads are trying to book a seat, if the seat is available they are alloated with a seat else we say sorry we don't have seats available.&lt;/li&gt;
&lt;li&gt;initially we have only 1 seat available with us and first thread T1(walter white) and then thread T2(jesse pink man) threads are executed&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;now you might be expecting that we had 1 seat available, walter white would get that seat and after that we'd have 0 seats available for we'd say sorry jesse we don't have seats&lt;/li&gt;
&lt;li&gt;well this could be true but not always&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sgiamepof54ri6k6s74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sgiamepof54ri6k6s74.png" alt="expected_execution" width="602" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;above we can see the expected output but due to race condition this is'nt always true, &lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp19b0hr4ik8jco3fie2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp19b0hr4ik8jco3fie2e.png" alt="unexpected behaviour" width="582" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;above is an example of race contion or an unexpected behaviour &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  now, let's understand how race condition comes into picture even with GIL
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;so according to our expectations after &lt;code&gt;1 seat has been alloted to walter white&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;available seats should be 0, but it's 1 here and then it says sorry we are out of seats&lt;/li&gt;
&lt;li&gt;ideally after printing out this  &lt;code&gt;1 seat has been alloted to walter white&lt;/code&gt;, 1 seat should have been reduced and next printed statement should have been 0 seat was available before booking(as we only had one seat initially whihc was alloated to walter white)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;but what really happened was after printing &lt;code&gt;1 seat has been alloted to walter white&lt;/code&gt; a context switch happened and thread (T2/jesse pinkman) started executing and because the number of seats available was'nt deducted by first thread (T1/walter while, due to context switch) we got an unexpected result which said &lt;code&gt;1 seat available before booking&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;and when again thread (T1/walter white) started executing from where it left before the context switch, number of available seats was subtracted now, then again context switch happened and thread (T2) started executing from where it left and as now the number of available seats was deducted by thraed T1,

&lt;code&gt;sorry we are out of seats&lt;/code&gt;

was printed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

</description>
      <category>python</category>
      <category>async</category>
      <category>programming</category>
    </item>
    <item>
      <title>Threading vs Asyncio vs Multiprocessing</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Thu, 22 Feb 2024 15:16:20 +0000</pubDate>
      <link>https://forem.com/coderatul/threading-vs-asyncio-vs-multiprocessing-10ed</link>
      <guid>https://forem.com/coderatul/threading-vs-asyncio-vs-multiprocessing-10ed</guid>
      <description>&lt;p&gt;Before Diving into Differences: Threading, Asyncio, and Multiprocessing&lt;/p&gt;

&lt;p&gt;Let's solidify our understanding of processes, threads, and context switching before delving into the intricacies of threading, asyncio, and multiprocessing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Process:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;A process is a program in execution. It's a set of instructions actively being carried out.&lt;/li&gt;
&lt;li&gt;When a processor runs a program, that program becomes a process. It requires resources like RAM and I/O operations, provided by the operating system.&lt;/li&gt;
&lt;li&gt;Each process has its own unique memory address space. This means a malfunction in one process won't affect others.
This isolation is what makes Chrome's tabbed browsing powerful. - - Each tab runs as a separate process, ensuring issues in one tab don't disrupt others.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;🧵 Thread:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;A thread is a unit of execution within a process. Like chapters in a book, a process can have multiple threads (at least one, the main thread).&lt;/li&gt;
&lt;li&gt;Threads within a process share the same memory address space. This means a failure in any thread affects the entire process execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;🔁 Context Switch:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Imagine reading a book when someone interrupts you with a task. Before switching, you wisely place a bookmark on the page.This allows you to resume reading from the exact spot later.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Similarly, when one process/thread needs to execute while another is active, a context switch occurs. This involves saving the current state of the active process/thread and restoring the one needing execution, allowing it to pick up where it left off.&lt;br&gt;
Context switching between processes is more expensive due to their distinct memory spaces. It involves updating page tables and other overhead.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In contrast, context switching between threads is much faster thanks to their shared memory space.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Threading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExb2VpcHBmZnU4bzFka3k4Z3htZzVyMDc2YTR5a3ZtaGsxeDJ5cGdoYyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/wN4GIuq6mjMGzMuhxf/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExb2VpcHBmZnU4bzFka3k4Z3htZzVyMDc2YTR5a3ZtaGsxeDJ5cGdoYyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/wN4GIuq6mjMGzMuhxf/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Threading is a python module which allows us to create a run threads&lt;/li&gt;
&lt;li&gt;Threading gives an illusion of parallelism and not true parallelism due to Python's GIL(Global Interpreter Lock) even if we have multiple cores we can't achieve true parallelism &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;python's GIL : is a mutex(mutual-exclusion) lock which makes sure that only one thread of a process can execute at a given time &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;so under the hood a thread sheduler shedules the execution of threads (depending upon the os) by rapid context swicthing &lt;/li&gt;
&lt;li&gt;due Global interpreter lock limitation threading is not a good candidate for cpu heavy task's, so where can we use threads ? we can use threading in I/O bound tasks( I/O operations like waiting for network requests or reading files); while a thread waits for I/O completion, other threads can be executed &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Asyncio
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExMjZ6OHZoc3NtYndzamNtdzFvNm56eWF5cndqc29sZjdlbmR4ajc2MSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/S9RNKRqaB4kXRQkSe6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExMjZ6OHZoc3NtYndzamNtdzFvNm56eWF5cndqc29sZjdlbmR4ajc2MSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/S9RNKRqaB4kXRQkSe6/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Asyncio is a python module for asynchronous programming&lt;/li&gt;
&lt;li&gt;Asyncio is same in the terms of functioning it also gives an illusion of parallelism but appoarch is different from threading &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;unlike threading where most of the things are handled by os, the event loop handles most scheduling and avoids explicit threading concerns in asynchronous programming. However, understanding coroutines and event loops can have a learning curve.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Asyncio Leverages an event loop and coroutines (special functions). The event loop manages tasks and schedules them for execution when resources become available (e.g., I/O completes). This minimizes context switching and avoids blocking the main thread.
Coroutines: These are special functions that can be paused and resumed later. They are the building blocks of asynchronous code in asyncio.
Event loops: These are responsible for managing the execution of coroutines and handling events.
Asynchronous I/O: asyncio provides functions for performing I/O operations asynchronously, without blocking the main thread.
async and await keywords: These keywords are used to define and use coroutines, respectively.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Multiprocessing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdXo4bDZhcGdqYWhkbGNobTdremQyMTh3a3llM3lmZ2UyOTFkMXc3ZyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/d2YYDKTqZgAL8moE/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdXo4bDZhcGdqYWhkbGNobTdremQyMTh3a3llM3lmZ2UyOTFkMXc3ZyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/d2YYDKTqZgAL8moE/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiprocessinh overcomes all of the problems that threadig has &lt;/li&gt;
&lt;li&gt;Multiprocessing in Python allows you to create multiple processes that leverage multiple CPU cores, significantly improving performance for CPU-bound tasks&lt;/li&gt;
&lt;li&gt; Processes communicate and share data using methods like pipes, queues, and shared memory&lt;/li&gt;
&lt;li&gt; Remember to implement proper synchronization mechanisms like locks and semaphores to prevent race conditions when accessing shared resources&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;while technically we may achieve true parallelism with multiprocessing but we should consider some caveats&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global Interpreter Lock (GIL): The CPython implementation of Python has a Global Interpreter Lock (GIL) that restricts a single thread from executing Python bytecode at a time. This means even with multiple processes, only one thread within each process can truly execute Python code in parallel. While the processes themselves are separate, the Python execution within each process can still be serialized due to the GIL.&lt;/li&gt;
&lt;li&gt;Overhead: Creating and managing processes involves overhead that can negate the benefits of parallelism for smaller tasks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>architecture</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Angel Hack Community Builder's Programme 2024</title>
      <dc:creator>Atul Kushwaha</dc:creator>
      <pubDate>Sat, 10 Feb 2024 22:00:00 +0000</pubDate>
      <link>https://forem.com/coderatul/angel-hack-community-builders-programme-2024-3kcd</link>
      <guid>https://forem.com/coderatul/angel-hack-community-builders-programme-2024-3kcd</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered if you could achieve something seemingly impossible, even before taking the first step? If so, then this article is for you! Hi there, I'm Atul Kushwaha, the GDSC Python Lead at my college and currently exploring the world of native Android development with Kotlin. Today, I want to share my experience of overcoming stage fright and landing a spot in the incredible AngelHack Community Builder Program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovering the Program:
&lt;/h2&gt;

&lt;p&gt;It all started with an email landing in my inbox, introducing the AngelHack Community Builder Program. The opportunity to create my own community, organize hackathons, and learn from industry experts instantly captivated me. However, there was one significant hurdle: applying required a video explaining my motivations and qualifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Facing My Fears:
&lt;/h2&gt;

&lt;p&gt;As an introvert who had only recently begun overcoming stage fright, the video application was daunting. The thought of speaking in front of a camera triggered my anxiety, and I worried about being articulate and engaging enough. Remember, though, I was the GDSC Python Lead at my college! So, with some nervousness (but no self-doubt), I began crafting my video.&lt;/p&gt;

&lt;h2&gt;
  
  
  From Stumbles to Success:
&lt;/h2&gt;

&lt;p&gt;Filming wasn't easy. Mispronunciations, filler words, and retakes plagued my initial attempts. But, fueled by my passion for community building, I persevered. After 40 takes, I had a video that felt genuine and represented my message authentically. I submitted it, and guess what? I got selected!&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning and Growing:
&lt;/h2&gt;

&lt;p&gt;Now, as a part of the program, I'm actively acquiring knowledge about community building, communication skills, and more. My key takeaway for fellow introverts? Don't let anxieties hold you back. Your first attempt may not be perfect, but every effort fuels your progress.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/X4PE-bgywP4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The Power of Authenticity:
&lt;/h2&gt;

&lt;p&gt;You can watch my &lt;a href="https://youtu.be/X4PE-bgywP4?si=iJ-4RJkqFvIGRalN" rel="noopener noreferrer"&gt;video here&lt;/a&gt;. While I may not have been perfectly fluent or brimming with confidence, my message and intentions shone through. Remember, authenticity trumps perfection. Your message matters more than how you deliver it. So, take that first step, share your genuine self, and watch your potential unfold!&lt;/p&gt;

</description>
      <category>community</category>
      <category>communication</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
