<?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>DEV Community: Abdulmumin yaqeen</title>
    <description>The latest articles on DEV Community by Abdulmumin yaqeen (@abdulmuminyqn).</description>
    <link>https://dev.to/abdulmuminyqn</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%2F507576%2F15e87a9b-09ae-40f5-8e83-b9d0a0a7e153.jpg</url>
      <title>DEV Community: Abdulmumin yaqeen</title>
      <link>https://dev.to/abdulmuminyqn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdulmuminyqn"/>
    <language>en</language>
    <item>
      <title>Devcanvas can now build stunning websites super FAST with AI!</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sat, 19 Apr 2025 10:58:56 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/devcanvas-can-now-build-stunning-websites-super-fast-with-ai-4kd1</link>
      <guid>https://dev.to/abdulmuminyqn/devcanvas-can-now-build-stunning-websites-super-fast-with-ai-4kd1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Devcanvas, one of my first projects into indie hacking, just got a major update.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Of course it’s AI. Devcanvas now lets you generate beautiful, responsive websites in seconds with just a simple prompt. Just tell it what you need, a portfolio? a landing page? a blog? and watch it build right in front of you.&lt;/p&gt;

&lt;p&gt;It’s not a fullstack builder (yet). For now, it only generates frontend code — but hey, we might add more down the line.&lt;/p&gt;

&lt;p&gt;You might be wondering, &lt;em&gt;why this?&lt;/em&gt; Don’t all the other chatbots already have some kind of code canvas?&lt;/p&gt;

&lt;p&gt;Well… if I’m being honest, I don’t really know either. I just wanted some skin in the game.&lt;/p&gt;

&lt;p&gt;And of course, Devcanvas still does what it’s always done best — edit and preview code super fast.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔧 Under the Hood
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Powered by &lt;strong&gt;DeepSeek-V3-new&lt;/strong&gt; excels at frontend
&lt;/li&gt;
&lt;li&gt;Generates clean &lt;strong&gt;HTML&lt;/strong&gt;, &lt;strong&gt;Tailwind CSS&lt;/strong&gt;, and &lt;strong&gt;vanilla JavaScript&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open source&lt;/strong&gt; — always will be &lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Give it a spin and let me know what you think. Open to critics!&lt;/p&gt;

&lt;h3&gt;
  
  
  Links:
&lt;/h3&gt;

&lt;p&gt;Try it out: &lt;a href="https://devcanvas.dev" rel="noopener noreferrer"&gt;https://devcanvas.dev&lt;/a&gt;&lt;br&gt;
Github: &lt;a href="https://github.com/abdulmumin1/devcanvas" rel="noopener noreferrer"&gt;https://github.com/abdulmumin1/devcanvas&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>ai</category>
    </item>
    <item>
      <title>Checkout my latest adventure</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sat, 14 Dec 2024 12:26:48 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/-3cm9</link>
      <guid>https://dev.to/abdulmuminyqn/-3cm9</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/abdulmuminyqn" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2F507576%2F15e87a9b-09ae-40f5-8e83-b9d0a0a7e153.jpg" alt="abdulmuminyqn"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/abdulmuminyqn/stop-overpaying-for-website-analytics-affordable-alternative-5a89" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Stop Overpaying for Website analytics - Affordable Alternative&lt;/h2&gt;
      &lt;h3&gt;Abdulmumin yaqeen ・ Nov 16&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#community&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#sass&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#indiehackers&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Stop Overpaying for Website analytics - Affordable Alternative</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sat, 16 Nov 2024 20:02:39 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/stop-overpaying-for-website-analytics-affordable-alternative-5a89</link>
      <guid>https://dev.to/abdulmuminyqn/stop-overpaying-for-website-analytics-affordable-alternative-5a89</guid>
      <description>&lt;p&gt;Hey fellow builders! 👋 &lt;/p&gt;

&lt;p&gt;I built an analytics tool Littlestats, and this is the story of why I built yet another analytics tool (I know, I know - but stick with me here).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem I Faced
&lt;/h2&gt;

&lt;p&gt;Ever launched a side project or small business website? Then you know this feeling:&lt;/p&gt;

&lt;p&gt;You're excited about your new project. You want to know if people are actually using it. So you add analytics.&lt;/p&gt;

&lt;p&gt;"Cool, they have a free plan!" 😎&lt;/p&gt;

&lt;p&gt;Until you realize:&lt;/p&gt;

&lt;p&gt;Want to know where your traffic comes from? That's premium.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need to track button clicks? Premium feature.&lt;/li&gt;
&lt;li&gt;Want to see which countries visit your site? You guessed it... premium.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suddenly that "free" plan feels like a demo, and you're staring at a $19-$29/month upgrade just to get basic insights about your website. &lt;/p&gt;

&lt;p&gt;Sound familiar?&lt;/p&gt;

&lt;p&gt;I looked around for alternatives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Google Analytics: Free but privacy concerns and increasingly complex&lt;/li&gt;
&lt;li&gt;Self-hosted solutions: The option i would generally go for, but didn't find the time, managing such on your own also sucks.&lt;/li&gt;
&lt;li&gt;Other SaaS analytics: All seemed to start at range of $19 - $29/month (yeah they do have a higher number of sites/domains, but that way more than my needs)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Solution: Littlestats
&lt;/h3&gt;

&lt;p&gt;So I built Littlestats with a simple promise:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Everything you actually need from analytics, for the price of a coffee (or even less 😅). - $4/month&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What do MicroSaaS founders actually need?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Traffic monitoring ✅&lt;/li&gt;
&lt;li&gt;Conversion tracking ✅&lt;/li&gt;
&lt;li&gt;Geographic data ✅&lt;/li&gt;
&lt;li&gt;Source attribution ✅&lt;/li&gt;
&lt;li&gt;Custom events ✅&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What don't we need?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Machine learning predictions&lt;/li&gt;
&lt;li&gt;Complex user journey mapping&lt;/li&gt;
&lt;li&gt;47 different dashboard views&lt;/li&gt;
&lt;li&gt;Enterprise-grade features we'll never use&lt;/li&gt;
&lt;li&gt;Adding mediocre AI features to justify the price&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why $4
&lt;/h3&gt;

&lt;p&gt;While most analytics tools charge $9-29/month for just 10k-30k hits per month, we're giving you Unlimited monthly pageviews for just $4. Simple as that. &lt;/p&gt;

&lt;p&gt;We're keeping it simple and affordable for bootstrappers and indie hackers - no complicated tiers, no enterprise bloat, just clean analytics that help you make better decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Technical Bits You'll Care About
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&amp;lt;2kb script size (your users won't even notice it)&lt;/li&gt;
&lt;li&gt;No cookies (GDPR-friendly)&lt;/li&gt;
&lt;li&gt;First-party data collection (no third-party trackers)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Who's This For?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🎯 Bootstrapped founders running 1-5 microsaas&lt;/li&gt;
&lt;li&gt;🎯 Side-project builders validating ideas&lt;/li&gt;
&lt;li&gt;🎯 Indie hackers watching their burn rate&lt;/li&gt;
&lt;li&gt;🎯 Small agency owners managing multiple client sites&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Who's This Not For?
&lt;/h3&gt;

&lt;p&gt;Let's be real:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you need enterprise features, this isn't for you&lt;/li&gt;
&lt;li&gt;If you're doing &amp;gt;1M hits/month, you've outgrown us&lt;/li&gt;
&lt;li&gt;If you need ML-powered predictions, look elsewhere&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Price Breakdown You Actually Care About
&lt;/h3&gt;

&lt;p&gt;$4/month gets you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;5 websites (will increase in the future)&lt;/li&gt;
&lt;li&gt;Unlimited hits/month&lt;/li&gt;
&lt;li&gt;All features included&lt;/li&gt;
&lt;li&gt;No upsells or hidden fees&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ready to Stop Overpaying?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Start your 30-day free trial at &lt;a href="https://littlestats.click" rel="noopener noreferrer"&gt;littlestats.click&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Add one line of code&lt;/li&gt;
&lt;li&gt;Stop thinking about analytics and focus on building&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;No credit card required. If you hate it, just don't subscribe after the trial.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Personal Note
&lt;/h3&gt;

&lt;p&gt;I built this because I needed it. If you're running small SaaS products or websites, you probably need it too.&lt;/p&gt;

&lt;p&gt;Questions? Drop them in the comments or hit me up on&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://twitter.com/@abdulmuminyqn" rel="noopener noreferrer"&gt;https://twitter.com/@abdulmuminyqn&lt;/a&gt;.&lt;br&gt;
Bluesky: &lt;a href="https://bsky.app/profile/yaqeen.me" rel="noopener noreferrer"&gt;https://bsky.app/profile/yaqeen.me&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Would love the the community feedback on this 🫶🏾&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>community</category>
      <category>sass</category>
      <category>indiehackers</category>
    </item>
    <item>
      <title>DevCanvas: Ready for Hacktoberfest! 🎉</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Mon, 30 Sep 2024 07:11:08 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/devcanvas-ready-for-hacktoberfest-51do</link>
      <guid>https://dev.to/abdulmuminyqn/devcanvas-ready-for-hacktoberfest-51do</guid>
      <description>&lt;p&gt;The summer of open source is here! It's that magical time of year when contributions flow in like never before, and the open-source community buzzes with excitement. The month where maintainers and open source enthusiast go nuts, either from too much spam contributions, or really good contributions accelerating the software at an unprecedented speed. Either way, Devcanvas is here for it (not for the spams though 🫠).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fiewgpqtfbr2dv7xagq6q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fiewgpqtfbr2dv7xagq6q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DevCanvas?
&lt;/h2&gt;

&lt;p&gt;DevCanvas is your go-to online frontend sandbox. It's a powerful playground where you can prototype with HTML, CSS, and JavaScript at lightning speed. Whether you're a seasoned developer or just starting out, DevCanvas provides the perfect environment to bring your frontend ideas to life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Tech Stack
&lt;/h2&gt;

&lt;p&gt;DevCanvas is built with modern, and the coolest technologies:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fjqzudwln99gf6sxiadto.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fjqzudwln99gf6sxiadto.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sveltekit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SvelteKit is our framework of choice, offering a powerful and efficient way to build web applications. It provides a smooth developer experience with its component-based architecture and built-in routing system, state management, transitions and all. Contributing to DevCanvas is an excellent opportunity to experience how sweet Svelte makes building web apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supabase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For our backend needs, we leverage Supabase, an open-source Firebase alternative. It provides real-time databases, authentication, instant APIs, and easy storage management. While our backend isn't open for direct contributions, understanding how we integrate with Supabase can provide valuable full-stack development insights.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use Tailwind CSS to style the user interface. This utility-first CSS framework allows for rapid UI development without leaving your HTML. If you're interested in frontend styling and creating responsive, beautiful interfaces, you'll have plenty of opportunities to work with Tailwind in DevCanvas.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This stack ensures a smooth, efficient development experience and a performant application. By contributing to DevCanvas, you'll gain hands-on experience with these modern technologies, enhancing your skill set and making you a more versatile developer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why Contribute to DevCanvas?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learn and Grow&lt;/strong&gt;: Perfect your skills in a real-world project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make an Impact&lt;/strong&gt;: Help shape a tool used by developers worldwide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Join a Community&lt;/strong&gt;: Connect with like-minded developers passionate about frontend development.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to Contribute
&lt;/h2&gt;

&lt;p&gt;We're thrilled to welcome contributions from developers of all skill levels. Here's how you can get involved:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Contributions&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Frontend Enhancements&lt;/strong&gt;: Help us improve the user interface and experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog Posts&lt;/strong&gt;: Share your frontend wisdom through our blog.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation&lt;/strong&gt;: Make DevCanvas more accessible by improving our docs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bug Squashing&lt;/strong&gt;: Found a pesky bug? Help us squash it!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feature Suggestions&lt;/strong&gt;: Have a brilliant idea? We're all ears!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Refactoring&lt;/strong&gt;: Help us clean up and optimize our codebase (it currently not looking to good).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Contribution Process&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fork the repository.&lt;/li&gt;
&lt;li&gt;Create a new branch:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  git checkout -b my-awesome-feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make your changes and commit:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  git commit -m "Add awesome feature"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Push to your fork:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  git push origin my-awesome-feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Open a pull request with a detailed description of your changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Style and Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stick to the existing code style for consistency.&lt;/li&gt;
&lt;li&gt;Write clear, concise comments to explain your code.&lt;/li&gt;
&lt;li&gt;Ensure your code is properly formatted and lint-free.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Need Help?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check out our existing issues and pull requests.&lt;/li&gt;
&lt;li&gt;Create a new issue with the "question" label for any queries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let's Make DevCanvas Awesome Together!
&lt;/h2&gt;

&lt;p&gt;Hacktoberfest is the perfect opportunity to dive into open source. Whether you're making your first contribution or your hundredth, DevCanvas welcomes you. Let's collaborate, learn, and create something amazing!&lt;/p&gt;

&lt;p&gt;Ready to start? Check out our &lt;a href="https://github.com/abdulmumin1/devcanvas" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; and let's code!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Hacking! 🚀&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>What is a subnet? | How subnetting works</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sat, 21 Sep 2024 07:04:40 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/what-is-a-subnet-how-subnetting-works-5d6g</link>
      <guid>https://dev.to/abdulmuminyqn/what-is-a-subnet-how-subnetting-works-5d6g</guid>
      <description>&lt;h2&gt;
  
  
  What is a subnet?
&lt;/h2&gt;

&lt;p&gt;A subnet or a subnetwork just as the name suggests is - a tiny network inside of a larger network. But to be more technically accurate with the definition, we can say that “a subnet is a logical partition of an Internet Protocol (IP)”. Logical because it not a physical component, but rather a virtual.&lt;/p&gt;

&lt;p&gt;Subnets are used to group networks into smaller chunks in other to make addressing and traffic flow easier and smoother. These groups are defined either by logic or location.&lt;/p&gt;

&lt;p&gt;Think of this way, Imagine a town with 256 houses, numbered 0 to 255. Without organization, a delivery person might need to check every house to find the right one.&lt;/p&gt;

&lt;p&gt;Now, let's divide this town into four subnets of 64 houses each: 0-63, 64-127, 128-191, and 192-255. If a package needs to go to house 227, the delivery person knows immediately to go to the fourth subnet (192-255) and only needs to search within those 64 houses, instead of searching the entire town, reducing the time each delivery person spends on the road (traffic).&lt;/p&gt;

&lt;p&gt;IP addresses are like the house numbers, and subnets help routers quickly determine which part of the network to send data to, reducing traffic and improving efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Subnets Works
&lt;/h2&gt;

&lt;p&gt;The IP address as you know is a 32-bit number that uniquely identifies a network interface on a machine. An IP address is typically written in decimal digits, formatted as four 8-bit fields (octet) separated by periods. Each octet represents a byte of the IP address. This form of representing the bytes of an IP address is often referred to as the &lt;strong&gt;dotted-decimal format&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The bytes of the IP address are further classified into two parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network part&lt;/li&gt;
&lt;li&gt;Host part&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Network part&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This part specifies the unique number assigned to your network. It also identifies the class of network assigned. In the above figure, the network part takes up two bytes of the IP address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Host part&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the part of the IP address that you assign to each host. It uniquely identifies this machine on your network. &lt;strong&gt;Note&lt;/strong&gt; that for each host on your network, the network part of the address will be the same, but the host part must obviously be different.&lt;/p&gt;

&lt;p&gt;What separates the Network Prefix and the Host ID depends on whether the address is a Class A, B or C address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv21wmr7c2jphxk43qb6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv21wmr7c2jphxk43qb6s.png" alt="a table showing the network classes from A-E" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class A Network Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A class A network number uses the first eight bits of the IP address as its "network part/id." The remaining 24 bits comprise the host part of the IP address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faci9hw3c9jj6gc5uty1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faci9hw3c9jj6gc5uty1t.png" alt="Byte Assignment in a Class A AddressGraphic" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The values assigned to the first byte of class A network numbers fall within the range 0-127. Consider the IP address 75.4.10.4. The value 75 in the first byte indicates that the host is on a class A network. The remaining bytes, 4.10.4, establish the host address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class B Network Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A class B network number uses 16 bits for the network number and 16 bits for host numbers. The first byte of a class B network number is in the range 128-191. In the number 129.144.50.56, the first two bytes, 129.144, are assigned by the InterNIC, and comprise the network address. The last two bytes, 50.56, make up the host address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbklk6mvywzw2959460ge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbklk6mvywzw2959460ge.png" alt="GraByte Assignment in a Class B Addressphic" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Class B is typically assigned to organizations with many hosts on their networks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class C Network Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Class C network numbers use 24 bits for the network number and 8 bits for host numbers. Class C network numbers are appropriate for networks with few hosts--the maximum being 254. A class C network number occupies the first three bytes of an IP address. Only the fourth byte is reserved for hosts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facoz0haxncy6iks7nnkl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facoz0haxncy6iks7nnkl.png" alt="Byte Assignment in a Class C AddressGraphic" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first byte of a class C network number covers the range 192-223. The second and third each cover the range 1- 255. A typical class C address might be 192.5.2.5. The first three bytes, 192.5.2, form the network number. The final byte in this example, 5, is the host number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgylpnu1dc1glarhzktq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgylpnu1dc1glarhzktq7.png" alt="Division of IP Address Space / Network classes" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn more about network class:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.cbtnuggets.com/blog/technology/networking/introduction-to-subnetting-what-is-a-network-class" rel="noopener noreferrer"&gt;What is a Network Class?&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.oracle.com/cd/E19504-01/802-5753/6i9g71m2o/index.html#planning3-78185" rel="noopener noreferrer"&gt;Network Classes - Oracle&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Subnet Number&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apart from the network and host ID, a third player can comes in, and that is the &lt;strong&gt;subnet&lt;/strong&gt;. If you choose to divide your network into subnets, you need to assign a &lt;strong&gt;subnet number&lt;/strong&gt; for the subnet. You can maximize the efficiency of the IP address space by using some of the bits from the host number part of the IP address as another network identifier for the subnet.&lt;/p&gt;

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

&lt;p&gt;A &lt;strong&gt;subnet mask&lt;/strong&gt; is used to identify the part of the address that is available for use a the &lt;strong&gt;Subnet ID&lt;/strong&gt; (essentially used to calculate the network and host portion of an IP address)&lt;/p&gt;

&lt;h2&gt;
  
  
  Subnet Mask
&lt;/h2&gt;

&lt;p&gt;A subnet mask is a 32-bit number used in conjunction with an IP address that identifies the network and host portions of a network component. Let’s say you have an IP address of 192.68.75.0/24. The subnet mask would be 255.255.255.0, or in binary, 111111.111111.111111.000000. This notation provides an easy way for a network to determine which portions of an IP address can be allocated to a host, hence borrows from it to create a subnet ID.&lt;/p&gt;

&lt;p&gt;A class A network would have a subnet mask of 255.0.0.0, B would have 255.255.0.0 and C would have 255.255.255.0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Calculate Subnet Mask
&lt;/h3&gt;

&lt;p&gt;If a subnet mask 255.255.255.0 is applied to the IP address 129.144.41.101, the result is the IP address of 129.144.41.0.&lt;/p&gt;

&lt;p&gt;129.144.41.101 &amp;amp; 255.255.255.0 = 129.144.41.0 (our network ID)&lt;/p&gt;

&lt;p&gt;In binary form, the operation is:&lt;br&gt;
10000001.10010000.00101001.01100101 (IP address)&lt;br&gt;
ANDed with&lt;br&gt;
11111111.11111111.11111111.00000000 (subnet mask)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ci4hiojuv0lv8grc3kh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ci4hiojuv0lv8grc3kh.png" alt="Deriving network address from ip address and subnet mask" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: A subnet mask would always be a stream of 1’s then 0, it can’t be interrupted. say for example &lt;code&gt;11111111.101110111.1111111.00000&lt;/code&gt; is not a valid subnet mask.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a bonus, I found this &lt;a href="https://www.solarwinds.com/free-tools/advanced-subnet-calculator" rel="noopener noreferrer"&gt;tool&lt;/a&gt; that can help you play around with calculating subnet masks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjoln1i2pt67yw26uv50p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjoln1i2pt67yw26uv50p.png" alt="Subnet Mask Calculator  - Solar Winds" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Article resource on calculating subnet masks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.techtarget.com/searchnetworking/tip/IP-addressing-and-subnetting-Calculate-a-subnet-mask-using-the-hosts-formula" rel="noopener noreferrer"&gt;How to calculate a subnet mask from hosts and subnet - TechTarget&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To calculate the number of hosts that can be acheived on a subnet mask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convert the subnet mask to binary notation&lt;/li&gt;
&lt;li&gt;Count the number of 0’s.&lt;/li&gt;
&lt;li&gt;Raise 2 to the power of that number.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Take for Example the subnet mask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Dotted-Decimal form: 255.255.248.0&lt;/p&gt;

&lt;p&gt;Dotted-Binary form: 11111111.11111111.11111000.00000000&lt;/p&gt;

&lt;p&gt;Counting, we find we have 11 zeros.&lt;/p&gt;

&lt;p&gt;So the number of host we can have on this subnet is &lt;strong&gt;2^11 = 2048.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;but remember we have to subtract the network identifier and the broadcast address, which gives us &lt;strong&gt;2046&lt;/strong&gt; usable hosts.&lt;/p&gt;

&lt;p&gt;So the formula is &lt;code&gt;2^(number of zeros) - 2&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  CIDR Notation
&lt;/h3&gt;

&lt;p&gt;Another way to write a subnet is using the CIDR (Classless Inter-Domain Routing) notation. The CIDR notation basically just states the number of bits the network is occupying.&lt;/p&gt;

&lt;p&gt;CIDR notation is used to identify Network Prefix and Mask, where the subnet mask is a number that indicates the number of ones in the Mask (e.g., 172.16.2.0/24). This is also known as Variable-Length Subnet Masking and CIDR.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;192.14.32.0&lt;code&gt;/24&lt;/code&gt; - this tells us that the first three 8-bit groups (octet) is the network ID.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;/24&lt;/code&gt; subnet means that the first 24 bits are &lt;code&gt;1&lt;/code&gt;s, and the rest are &lt;code&gt;0&lt;/code&gt;s. The binary for a &lt;code&gt;/24&lt;/code&gt; subnet mask would be.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;11111111.11111111.11111111.00000000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Thus if we’re to calculate the number of host using this CIDR notation. it would be:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2^(32-24) - 2 = 254.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;“-2” because we have to remove our network id and broadcast, remember?&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;h3&gt;
  
  
  So what happen to packets when they pass through a subnetwork?
&lt;/h3&gt;

&lt;p&gt;When you’re sending a packet to a host in a subnet, It goes through the normal networking procedure, but with some extra layers. The process happens as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The packet is first checked to see if it is intended for a device within the &lt;strong&gt;same subnet&lt;/strong&gt; as the sender.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;subnet mask&lt;/strong&gt; of the source IP address is used to determine which part of the IP address represents the network and which part represents the host.&lt;/li&gt;
&lt;li&gt;If the destination IP address belongs to the same subnet, the packet is delivered directly to the target device within the local network.&lt;/li&gt;
&lt;li&gt;If the destination IP address belongs to a different subnet, the packet needs to be routed through a &lt;strong&gt;gateway&lt;/strong&gt; or &lt;strong&gt;router&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In essence, when a packet passes through a subnet, it undergoes &lt;strong&gt;routing&lt;/strong&gt; if it's destined for a different subnet, and &lt;strong&gt;direct delivery&lt;/strong&gt; if it's destined for the same subnet. During routing, each router examines the packet and forwards it closer to its destination based on the subnet structure and routing protocols.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Subnet major benefit is in Improved Network Performance, because, when a device broadcasts a packet, it’ll reach all the network devices, burdening the network. Without proper context, broadcast packets can also spam devices within the network. This can lead to degraded network performance. By creating subnets, it limits the scope of intra-network broadcast messages to a specific subnet. This also enables efficient communication between devices in a subnet and sends a packet for routing outside the subnet if a destination address isn’t part of the subnet, leading to minimum network congestion.&lt;/p&gt;

&lt;h4&gt;
  
  
  Resources
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/cd/E19504-01/802-5753/6i9g71m2o/index.html#planning3-fig-2" rel="noopener noreferrer"&gt;Parts of the IP Address - Oracle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/cd/E19504-01/802-5753/6i9g71m2o/index.html#planning3-78185" rel="noopener noreferrer"&gt;Network Classes - Oracle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cbtnuggets.com/blog/technology/networking/introduction-to-subnetting-what-is-a-network-class" rel="noopener noreferrer"&gt;What is a network class - cbtnuggets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cbtnuggets.com/blog/technology/networking/proper-cidr" rel="noopener noreferrer"&gt;The CIDR Notation - Cbtnuggets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cloudflare.com/learning/network-layer/what-is-a-subnet/" rel="noopener noreferrer"&gt;What is a subnet - Cloudflare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.techtarget.com/searchnetworking/definition/subnet" rel="noopener noreferrer"&gt;Subnet - Techtarget&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Stay Subtle&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>network</category>
      <category>networking</category>
      <category>cybersecurity</category>
      <category>systems</category>
    </item>
    <item>
      <title>I built an open source Codepen alternative - Devcanvas</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Fri, 13 Sep 2024 06:37:19 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/i-built-an-open-source-codepen-alternative-devcanvas-1ade</link>
      <guid>https://dev.to/abdulmuminyqn/i-built-an-open-source-codepen-alternative-devcanvas-1ade</guid>
      <description>&lt;p&gt;DevCanvas (devcanvas.art) began as a fun experiment born from my journey learning SvelteKit and Supabase. What started as a simple platform for storing code snippets quickly evolved into something much more cooler: &lt;em&gt;an online editor that makes it easy to prototype and share ideas quickly and effortlessly.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Evolution
&lt;/h3&gt;

&lt;p&gt;A platform for storing code snippets, an idea I conceived while helping someone debug their code. The platform used to be called snippetland, but after getting deep in building and also trying to establish the name and stuff, I realized that another service named Snippetland that does the same thing (even better) exists.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Devcanvas is not a competitive product, but rather a stepping stone for me into the indie hacking world. As said - "Imitate until you innovate"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Snippetland early twitter posts:&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1690427906751651841-655" src="https://platform.twitter.com/embed/Tweet.html?id=1690427906751651841"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1690427906751651841-655');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1690427906751651841&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;The current form, which is a full-fledged online editor with cool features was just an experimentation. I first demoed it on twitter a long time ago.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1701642073546334375-141" src="https://platform.twitter.com/embed/Tweet.html?id=1701642073546334375"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1701642073546334375-141');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1701642073546334375&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1703859320478212173-753" src="https://platform.twitter.com/embed/Tweet.html?id=1703859320478212173"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1703859320478212173-753');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1703859320478212173&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Seeing these again, devcanvas has definitely come a really long way.&lt;/p&gt;

&lt;p&gt;Storing snippets still exists on DevCanvas, but haven't gotten any updates for a while now.&lt;/p&gt;

&lt;h3&gt;
  
  
  Feature Summary
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Easy prototyping&lt;/li&gt;
&lt;li&gt;Effortless sharing&lt;/li&gt;
&lt;li&gt;Real-time editing (i.e fast previews)&lt;/li&gt;
&lt;li&gt;Super neat interface (from my perspective at least)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DevCanvas offers a robust set of features designed to enhance the frontend development experience. These include built-in support for popular tools like Tailwind CSS, Font Awesome, and GSAP, which can be accessed with just a click.&lt;/p&gt;

&lt;p&gt;Devcanvas also supports SCSS, catering to developers who prefer using SCSS for their styling needs. Additionally, DevCanvas provides responsive design testing, allowing developers to see how their projects look on different devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Collaboration and Sharing
&lt;/h3&gt;

&lt;p&gt;One of the standout features of DevCanvas is its ability to keep projects private (a feature most keep behind a paywall), with sharing options limited to those with the link. &lt;/p&gt;

&lt;p&gt;Projects can be embedded in websites, blogs, and documentation, making it simple to showcase work or integrate it into other content. Shareable URLs and code snippets in over 50 languages further enhance Devcanvas's utility for both teaching and sharing code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;To start using DevCanvas, simply navigate to the website and begin creating your frontend projects. The intuitive interface allows for easy prototyping and experimentation, making it a great sandbox for developers of all levels.&lt;/p&gt;

&lt;h3&gt;
  
  
  Embedding Projects
&lt;/h3&gt;

&lt;p&gt;Embedding your DevCanvas projects into other platforms is straightforward. Use the provided iframe code snippet and paste it into your desired location on websites, blogs, or documentation. This feature is ideal for showcasing your work or integrating interactive elements into your content.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unique Features.
&lt;/h3&gt;

&lt;p&gt;Compared to other online frontend editors, DevCanvas stands out with its built-in plugins for Tailwind CSS, Font Awesome, and GSAP, which are just a click away. This saves developers time and effort, allowing them to focus more on the creative aspects of their projects.&lt;/p&gt;

&lt;p&gt;DevCanvas is designed with ease of use in mind, making it accessible to both beginners and experienced developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  PWA Support
&lt;/h3&gt;

&lt;p&gt;As a Progressive Web App (PWA), DevCanvas also offers offline support, allowing users to continue working even when they are not connected to the internet. This feature is particularly beneficial for developers who need to work in environments with limited connectivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenges
&lt;/h3&gt;

&lt;p&gt;Got myself into a trial and error loop making the preview as fast as possible, most of the problem coming from network resource the might be brought in into the editor. Whoa, I just conceived a superb idea while writing this (would implement later).&lt;/p&gt;

&lt;p&gt;Initially the Editor we utilize is Monaco Editor, but it really resource intensive and have a huge impact on performance in both the speed and memory consumption.&lt;/p&gt;

&lt;p&gt;I quickly switch to Codemirror, after a feedback pointing out this issue, which is more lighter and efficient. I also kinda like the DX better than monaco editor.&lt;/p&gt;

&lt;p&gt;Another challenge was SSR that had to be turned off, because it caused alot of problems rendering the editor, as they heavily rely on client side APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tech Stack
&lt;/h3&gt;

&lt;p&gt;Devcanvas is built with Sveltekit, TailwindCSS, Supabase and no Typescript (I wish I did though).&lt;/p&gt;

&lt;p&gt;Though not the coolest or hardest product to build or make money from, The process of building it was incredibly enjoyable, and using it is just as fun – hence the tagline, "The Editor with Super Powers".&lt;/p&gt;

&lt;p&gt;Currently, DevCanvas is completely free to use. &lt;/p&gt;

&lt;h3&gt;
  
  
  Open Source
&lt;/h3&gt;

&lt;p&gt;DevCanvas is proudly open source, even though, It has always just been me building this for while. I hope to get others involved in this to make DevCanvas even better and cooler.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning: Lots of technical debt and ugly code, but i'm working to make it better for contribution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Have questions, suggestions, critique or feedback, I'd love to hear from you!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Visit &lt;a href="https://devcanvas.art" rel="noopener noreferrer"&gt;https://devcanvas.art&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Also checkout my next product CommentRig (&lt;a href="http://www.commentrig.com" rel="noopener noreferrer"&gt;www.commentrig.com&lt;/a&gt;) - A modern comment management for websites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay Subtle 💛!&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Do you feel the need for a comment section for your blogs?</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Thu, 12 Sep 2024 18:36:11 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/do-you-feel-the-need-for-a-comment-section-for-your-blogs-48nm</link>
      <guid>https://dev.to/abdulmuminyqn/do-you-feel-the-need-for-a-comment-section-for-your-blogs-48nm</guid>
      <description>&lt;p&gt;I'm currently building CommentRig (&lt;a href="//www.commentrig.com"&gt;www.commentrig.com&lt;/a&gt;), a solution for comment management. While alternatives like Discus exist, I feel their UI and features may be off-putting to some users. I'm wondering: would a more flexible and seamless solution like CommentRig attract users, or are blog owners simply not interested in adding comment sections to their sites?&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Rich Text Trimming Algorithm</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Fri, 26 Jul 2024 16:35:15 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/rich-text-trimming-algorithm-20no</link>
      <guid>https://dev.to/abdulmuminyqn/rich-text-trimming-algorithm-20no</guid>
      <description>&lt;p&gt;Triming plaintext is fairly an easy algorithm to write, and we rely on it soo much more than we think. Doing the same for rich text however is a bit of a different kettle of fish, spaces are not whitespace but instead a &lt;code&gt;&amp;lt;b/&amp;gt;&lt;/code&gt; or linebreaks to say.&lt;/p&gt;

&lt;p&gt;No gainsaying the fact that we can't always trust users to do the right thing, things which might seem obvious to you (since you're the ones building it), are not so obvious to them. Even worse is that they will be thinking it's not their fault, hence why we go out of our way to build features to guardrail this.&lt;/p&gt;

&lt;p&gt;This is a problem i ran into building commentrig (&lt;a href="https://www.commentrig.com" rel="noopener noreferrer"&gt;Join the waitlist here&lt;/a&gt;) a one minute robust comment system integration into your website. I needed a way to trim out extra and unnecessary spaces/linebreaks outside and between paragraphs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925070940_Screenshot%2B2024-07-25%2Bat%2B12-47-22%2BVite%2BReact.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925070940_Screenshot%2B2024-07-25%2Bat%2B12-47-22%2BVite%2BReact.png" alt="Text in a comment box with excess line breaks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925082228_beforeafter.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925082228_beforeafter.png" alt="Trimmed and untrimmed version of the latter text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this weeks under the hood series, I want to talk about this algorithm I came up with that helped me solve the problem, hopefully helping you in your needs as well, or helping me find fault in my solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea.
&lt;/h2&gt;

&lt;p&gt;The idea is very simple, and it goes like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Create a variable to mark the top (i.e the point where text does not have any space above it)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Also create a list to store nodes that we're removing (removables 😅).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Iterate through all the nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; If the text content of the current node (x) is empty:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; Check if the next sibling (x+1) is also empty, if true, remove the current node (x) (add it to the removables)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; Else if it is the last index, (meaning no next sibling), remove it (add it to the removables).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;7.&lt;/strong&gt; Else if the next sibling is not empty, since the current index (x) is empty we will mark that as our top, but also mark it as a removable top. &lt;strong&gt;&lt;em&gt;Top can only be set once.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;8.&lt;/strong&gt; Else if the text content of the current node (x) is not empty: we mark it as our top, but a none removable top. &lt;strong&gt;&lt;em&gt;Top can only be set once.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;9.&lt;/strong&gt; After the iteration is complete, we loop over our list of removables, and remove corresponding elements from our original node. Also if our top is an element (removable top), we remove it as well, but if the set to True (non removable top) we leave it alone.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can already tell it interesting, or you can spend some time to think it over to fully understand it. But my breakdown goes like this:&lt;/p&gt;

&lt;h2&gt;
  
  
  Breakdown
&lt;/h2&gt;

&lt;p&gt;The first part of the algorithm, &lt;code&gt;Create a variable to mark the top&lt;/code&gt;. The reason for this variable, is solely to remove the extra space that will be present at the top of the content, as the check will not remove anything that the next sibling is a text content. I will also explain why is that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Moving forward&lt;/strong&gt; is to create a list to store the nodes we're going to be removing. This solves a fundamental problem, because if we remove directly from our node while iterating, it reduces our iteration count. Hence the list. Otherwise we might as well get rid of the top variable we're creating, because we can always check with &lt;code&gt;node.firstChildElement&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next&lt;/strong&gt; we're checking if the text content is empty, this should be it if not that, we don't want all spaces/linebreak in between paragraphs should be gone as well. At lease we will respect the intention to leave a space between paragraphs, but not excess. Hence why we're checking the next sibling is a space as well, otherwise, it should be the only space that remains.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925122634_Some%2BText.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925122634_Some%2BText.gif" alt="Illustration showing removing spaces removing extra spaces/line breaks between text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inside of the same condition&lt;/strong&gt; &lt;code&gt;text content of the current node (x) is empty&lt;/code&gt; we're checking if it is the last index or not, because the last child does not have a nextSibling. but we already know that current node is empty, so we just add it to our list of removables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925137363_Some%2BText1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925137363_Some%2BText1.gif" alt="a gif showing a logic to remove the extra space/linebreak in the last index"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Still here&lt;/strong&gt; &lt;code&gt;text content of the current node (x) is empty&lt;/code&gt;, we want to find our top which will trigger if the nextSibling is not empty and &lt;strong&gt;&lt;em&gt;if our top is not already set yet&lt;/em&gt;&lt;/strong&gt; (very important line). But we know that the current node is empty, hence we set it as our top, but a removable one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925151010_Untitled%2Bdesign3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925151010_Untitled%2Bdesign3.gif" alt="A gif showing how the “top” of the node is determined if there is an extra space/linebreak that precedes it"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Moving our of this condition&lt;/strong&gt; &lt;code&gt;text content of the current node (x) is empty&lt;/code&gt;, which means that we've encountered an element the is not empty, then we set it as our top (&lt;strong&gt;&lt;em&gt;if our top is not already set yet&lt;/em&gt;&lt;/strong&gt;), but a non removable one, meaning we will just mark to as &lt;code&gt;True&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925166030_yaqeen.me.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925166030_yaqeen.me.gif" alt="A git showing how the top is determined if there is no extra space/linebreak preceding it"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the iteration is done, we loop over our list of removables, and remove corresponding elements from our original node. Also if our top is an element (removable top), we remove it as well, but if the set to True (non removable top) we leave it alone (we can't remove that anyways).&lt;br&gt;
Here is a rough illustration of how everything comes together:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925179672_yaqeen.me2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_7C51D412F35D5EE32D7FA12E66F1AB07F248DD0FB86E6C0AF80EC2DBF81A39DD_1721925179672_yaqeen.me2.gif" alt="A step by step walk through showing the rich text trimming algorithm in action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Forgive my editing skills 😅.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;trimCommentContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tempDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;tempDiv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;htmlString&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;removeList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;emptyTagNames&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="s1"&gt;BR&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;STRONG&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;EM&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;removeEmptyNodes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;elements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;childNodes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstChild&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tagName&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BR&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nextElementSibling&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&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="nx"&gt;emptyTagNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nextElementSibling&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;firstChild&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tagName&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;t&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="nx"&gt;removeList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="p"&gt;{&lt;/span&gt;
                        &lt;span class="nx"&gt;removeList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&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="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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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="p"&gt;}&lt;/span&gt;

        &lt;span class="nx"&gt;removeList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;element&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="nx"&gt;tempDiv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;tempDiv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;removeList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;removeEmptyNodes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tempDiv&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;tempDiv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can further study the code to understand it better. I'm hoping for a feedback on potential flaws in my implementation, or even a better one.&lt;br&gt;
Super hoped you learned something new as I did.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before you go:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’m building &lt;a href="https://www.commentrig.com" rel="noopener noreferrer"&gt;commentrig&lt;/a&gt;, a platform that allow you to integrate a robust comment system to your website. Offering a native package for all your favorite frameworks.&lt;br&gt;
Join the waitlist here: &lt;a href="https://www.commentrig.com/waitlist" rel="noopener noreferrer"&gt;commentrig.com/waitlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay Super Awesome 🫶🏾.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>dsa</category>
      <category>uth</category>
      <category>javascript</category>
    </item>
    <item>
      <title>TCP/IP - Under The Hood</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sun, 21 Jul 2024 15:28:01 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/tcpip-under-the-hood-4o02</link>
      <guid>https://dev.to/abdulmuminyqn/tcpip-under-the-hood-4o02</guid>
      <description>&lt;p&gt;In this weeks under the hood series, i want to look into something pretty basic, something utilized at every tick of the clock. - TCP/IP.&lt;/p&gt;

&lt;p&gt;Lots of us most have heard of the concept of TCP/IP, but this is under the hood series, where we will be looking at the technology a bit closer.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is TCP/IP
&lt;/h2&gt;

&lt;p&gt;Transmission Control Protocol/Internet Protocol is a suite of communication protocols used to connect and communicate between devices on network.&lt;/p&gt;

&lt;p&gt;The model describes how data is transmitted over the network, ensuring the smoothest communication between networked devices. It describes how data should be broken into packets, routed, transmitted and received at the destination.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Quick Note: TCP is the specification, IP (Internet Protocol) is the addressing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The routing and addressing part of the protocol is handled by IP (Internet Protocol). Each packets moving through the internet is bundled with an IP information, providing routers with the correct information of where the packets are to be sent or routed.&lt;/p&gt;

&lt;p&gt;The Transmission Control Protocol (TCP) is a transport protocol, meaning it defines how data is sent and received.&lt;/p&gt;

&lt;p&gt;TCP/IP model assigns tasks into 4 layers, simplifying the OSI model, each layers with it unique set of responsibility and contribution in ensuring a successful communication.&lt;/p&gt;

&lt;h1&gt;
  
  
  4 Layers of TCP
&lt;/h1&gt;

&lt;p&gt;Each layer is standardized in the TCP/IP model.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Application layer
&lt;/h2&gt;

&lt;p&gt;The topmost layer of the TCP model, it the starting point of data communication at the senders end, and the ending point at the receivers end. This is what the user typically interacts with, abstracting away the complexity of data communication.&lt;/p&gt;

&lt;p&gt;It is responsible for providing high-level functions and protocols for applications to communicate over the network. Examples of protocols and services at this layer include HTTP, FTP, SMTP, DNS, Telnet, and DHCP.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Transport Layer - How the data is Transported.
&lt;/h2&gt;

&lt;p&gt;Logically, it not practical to send the entire data in one go, the TCP protocol breaks down the data into chunks or packets, these are packets are then attached to a TCP header which contains several information for transmission and handling of data at the receiving end, these includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Source port&lt;/strong&gt;: The port number of the sender’s application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Destination port&lt;/strong&gt;: the port number of the receiver’s application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sequence Number&lt;/strong&gt;: Each packet is assigned a number which helps to reassemble the data at the receiving end.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Checksum&lt;/strong&gt;: Used for error-checking of the header and data. It detects corruption during transmission.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Offset&lt;/strong&gt;: This field specifies the size of the TCP header in 32-bit words. It indicates where data begins. It is important for parsing variable-length options and ensuring that the TCP header is properly aligned.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Other&lt;/strong&gt; information includes Flags (ACK, SYN,URG, RST, …), Window size, Options, Padding among others.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720941694974_Add%2Ba%2Bsubheading5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720941694974_Add%2Ba%2Bsubheading5.png" alt="Transport layer transmission handling illustration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TCP ensures that all packets arrive in order once transmission begins. Via TCP, the recipient will acknowledge receiving each packet that arrives. Missing packets will be sent again if receipt is not acknowledged.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720939373268_3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720939373268_3.png" alt="Disassembly and reassemble of packets transmitting over TCP"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Internet Layer
&lt;/h2&gt;

&lt;p&gt;The internet layer or network layer, the is where the IP (Internet Protocol) comes in, taking up the task of routing, addressing and to make sure the packet is send to the correct destination.&lt;/p&gt;

&lt;p&gt;Packets coming from the transport layer, where the TCP headers are attached, also get another piece of header as they pass through the Internet Layer, which helps them get to the desired destination.&lt;/p&gt;

&lt;p&gt;The headers includes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;: This indicates the version of used IP address protocol, whether IPv4 or IPv6.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IP Addresses (Source and destination)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every device or domain that connects to the Internet is assigned an IP address, and as packets are directed to the IP address attached to them, data arrives where it is needed.&lt;/p&gt;

&lt;p&gt;An IP address is a unique string of characters that identifies each computer using the Internet Protocol (IP) to communicate over a network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header Length&lt;/strong&gt;: Length of the IP header&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time to Live (TTL)&lt;/strong&gt;: Limits the lifespan of the packet in the network&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protocol&lt;/strong&gt;: Indicates the next level protocol (e.g., TCP, UDP)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Others&lt;/strong&gt; includes Flags, Offset, Options...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720940553674_Add%2Ba%2Bsubheading3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720940553674_Add%2Ba%2Bsubheading3.png" alt="IP header list, excluding ip addresses source &amp;amp; destination and options"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The IP header is added to the packet containing the TCP header and data, forming the complete IP packet that will be transmitted at the network layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Data Link
&lt;/h2&gt;

&lt;p&gt;This layer function on metal, i.e on a hardware level, it responsible for handling the physical part of sending/receiving data via hardware such as Ethernet, Network card, wireless network and so forth.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720939319218_4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720939319218_4.png" alt="Header information attached at every layer of the TCP/IP model excluding the data link layer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the data link layer, the following processes occur:&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Framing:
&lt;/h5&gt;

&lt;p&gt;The network layer packet is encapsulated into a frame. This frame includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Preamble: A sequence of bits to synchronize the receiver's clock.&lt;/li&gt;
&lt;li&gt;Start Frame Delimiter: Marks the beginning of the frame.&lt;/li&gt;
&lt;li&gt;Destination MAC Address: Physical address of the destination device.&lt;/li&gt;
&lt;li&gt;Source MAC Address: Physical address of the source device.&lt;/li&gt;
&lt;li&gt;EtherType/Length: Indicates the protocol of the encapsulated data or frame length.&lt;/li&gt;
&lt;li&gt;Payload: The actual data from the network layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  2. Frame Check Sequence (FCS):
&lt;/h5&gt;

&lt;p&gt;For error detection.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Addressing:
&lt;/h5&gt;

&lt;p&gt;The frame uses MAC (Media Access Control) addresses to identify the source and destination devices on the local network segment.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Error Detection:
&lt;/h5&gt;

&lt;p&gt;The FCS allows the receiver to check for errors that may have occurred during transmission.&lt;/p&gt;

&lt;h5&gt;
  
  
  5. Flow Control:
&lt;/h5&gt;

&lt;p&gt;Manages the rate of data transmission to prevent overwhelming the receiver.&lt;/p&gt;

&lt;h5&gt;
  
  
  6. Access Control:
&lt;/h5&gt;

&lt;p&gt;In shared media, like Ethernet, the data link layer manages how devices take turns using the medium (e.g., CSMA/CD - &lt;a href="https://simple.wikipedia.org/wiki/Carrier-sense_multiple_access_with_collision_detection" rel="noopener noreferrer"&gt;Carrier Sense Multiple Access with Collision Detection&lt;/a&gt;).&lt;/p&gt;

&lt;h4&gt;
  
  
  Transmission over hardware:
&lt;/h4&gt;

&lt;p&gt;Once the frame is prepared, it's passed to the physical layer, which handles the actual transmission over the hardware:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Encoding&lt;/strong&gt;: The binary data is encoded into signals that can be transmitted over the physical medium.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signaling&lt;/strong&gt;: The encoded data is converted into electrical, light, or radio signals depending on the medium.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Physical Medium&lt;/strong&gt;: The signals are sent over the physical connection, which could be: Ethernet cable (electrical signals), Fiber optic cable (light signals) or Wi-Fi (radio waves)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reception&lt;/strong&gt;: The receiving device's physical layer picks up these signals, decodes them back into binary data, and passes them up to its data link layer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Processing&lt;/strong&gt;: The receiving data link layer processes the frame, checks for errors, and if it's the intended recipient, passes the payload up to the network layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720947840661_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_447C8B6D4796B6FCF7D4694FFC3273E4396B1B5B368DF3D5BD1E0819476F0E8B_1720947840661_image.png" alt="process of encoding data into physical form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.avast.com/c-what-is-tcp-ip" rel="noopener noreferrer"&gt;What is TCP/IP and How Does it Work? - Avast Academy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/tcp-ip-model/" rel="noopener noreferrer"&gt;TCP/IP Model - GeekforGeeks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.techtarget.com/searchnetworking/definition/TCP-IP" rel="noopener noreferrer"&gt;TCP/IP - TechTarget&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.fortinet.com/resources/cyberglossary/tcp-ip" rel="noopener noreferrer"&gt;What is Transmission Control Protocol TCP/IP? - fortinet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cloudflare.com/learning/network-layer/internet-protocol/" rel="noopener noreferrer"&gt;What is the Internet Protocol? - Cloudflare&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before you go:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm building &lt;a href="https://www.commentrig.com" rel="noopener noreferrer"&gt;commentrig&lt;/a&gt;, a platform that allow you to integrate a robust comment system to your website. Offering a package for all your favorite frameworks.&lt;/p&gt;

&lt;p&gt;Join the waitlist here: &lt;a href="https://commentrig.com/waitlist" rel="noopener noreferrer"&gt;commentrig.com/waitlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay super awesome 🫶🏾.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>networking</category>
      <category>systems</category>
      <category>uthseries</category>
    </item>
    <item>
      <title>How Garbage Collector works - Under The Hood</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sun, 30 Jun 2024 22:00:12 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/how-garbage-collector-works-under-the-hood-h9f</link>
      <guid>https://dev.to/abdulmuminyqn/how-garbage-collector-works-under-the-hood-h9f</guid>
      <description>&lt;p&gt;in this week's &lt;em&gt;under the hood series&lt;/em&gt;, I want to look into something I've heard over and over again from systems engineers and seniors, - &lt;strong&gt;Garbage Collector&lt;/strong&gt;. You've probably also heard of it as well - some say they love garbage collected languages, other say the are fine with It and some trash on It.&lt;/p&gt;

&lt;p&gt;And of course, frequency of the buzz among superiors makes you curious just like myself, you also want to understand and relate to these conversations.&lt;/p&gt;

&lt;p&gt;In this article, I will try my best to explain In simple terms, what It Is and does, why It exists and most Importantly, how It works.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Catch the previous episode here:&lt;br&gt;
&lt;a href="https://www.yaqeen.me/blog/how-ssh-works-under-the-hood" rel="noopener noreferrer"&gt;How SSH Works - Under The Hood&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Garbage Collection
&lt;/h2&gt;

&lt;p&gt;A garbage collector is a program that automatically free up memory space allocated to objects that are no longer needed to further the execution of the program.&lt;/p&gt;

&lt;p&gt;In essence, Garbage collector helps manage allocation and release of memory, ensuring the application never exceeds it memory quota.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;If you've never written code in languages that are not garbage collected, you might have never come across the scenario of manual memory management. I would assume you've never, and i'm already sure the thought of it is already scaring you away.&lt;/p&gt;

&lt;p&gt;There is no gainsaying the fact that quite a lot of human errors will be involved in manual memory management, which increase bugs and decrease your application security in various ways.&lt;/p&gt;

&lt;p&gt;Some of which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Double free&lt;/strong&gt;:
Double free occur when you're are trying to free up memory space that has “&lt;em&gt;already been freed&lt;/em&gt;”. Double frees are particularly dangerous because they can corrupt the memory allocator's internal data structures, potentially leading to more severe issues like heap corruption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dangling pointer&lt;/strong&gt;:
A dangling pointer is a pointer that references a memory space that has been freed (deallocated) and is not set to &lt;strong&gt;NULL&lt;/strong&gt; afterwards. This makes our program buggy and might crash unpredictably.&lt;/li&gt;
&lt;li&gt;Other kinds of human errors are inevitable in such scenario. such as failing to free up memory, which becomes unreachable, &lt;strong&gt;memory leak&lt;/strong&gt; is sure the right term.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These reasons might not exactly be the why Garbage Collector was first created. Either way, it first appeared around 1959, by the same guy that coined the word "Artificial Intelligence (AI)" - &lt;a href="https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist)" rel="noopener noreferrer"&gt;John McCarthy&lt;/a&gt; to simplify the memory management in &lt;a href="https://en.wikipedia.org/wiki/Lisp_(programming_language)" rel="noopener noreferrer"&gt;Lisp&lt;/a&gt;, the language he designed. John McCarthy is often refered to has the father of "Artificial Intelligence".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkij2zfc7b4d7dy66plge.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkij2zfc7b4d7dy66plge.jpg" alt="John mcCarthy at work in his artificial intelligence laboratory at Stanford" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Other languages soon follow suit, baking garbage collectors into the language's runtime or compiler.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why not?
&lt;/h3&gt;

&lt;p&gt;Garbage collection typically runs alongside your program, eating up a portion of CPU time and potentially impacting performance. Though the modern implementation have become quite efficient, making the performance impact minimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Garbage Collection works (Tracing Algorithm)
&lt;/h2&gt;

&lt;p&gt;Each implementation of garbage collection has it own distinct tweaks, but are similar in the underlying algorithm.&lt;/p&gt;

&lt;p&gt;We will be explaining the &lt;strong&gt;tracing&lt;/strong&gt; algorithm in particular, which is the go to algorithm for most garbage collection implementation.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Picks the best time for collection.
&lt;/h3&gt;

&lt;p&gt;The program first and foremost action is to determine when to collect the garbage, it does not happen in real time, hence depends on memory allocations or intervals.&lt;br&gt;
Though when a program is about to exhaust it allocated memory and new object are to be created, a priority collection is performed to free up space for the new object.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Checks Heap
&lt;/h3&gt;

&lt;p&gt;The garbage collector then find objects that are no longer being used by examining the application's roots. An application's roots include static fields, local variables on a thread's stack, CPU registers, GC handles, and the finalize queue. Each root either refers to an object on the managed heap or is set to null.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuk358vg2kb28e514e35c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuk358vg2kb28e514e35c.png" alt="a graph showing objects relationship in the managed heap" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The garbage collector then uses this list to create a graph that contains all the objects that are reachable from the roots.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxurmfsqpqkfl66ozud6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxurmfsqpqkfl66ozud6b.png" alt="a graph showing reachable objects in a grapth" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Collects &amp;amp; Compact
&lt;/h3&gt;

&lt;p&gt;All unreachable objects at this point are considered garbage. The collector scans the heap, looking for the addresses of the memory space they occupy, and eliminates them.&lt;br&gt;
Then, it uses a momery-copying function to compact the reachable objects in memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Memory compaction is a process where the garbage collector moves all the reachable (live) objects to one contiguous area of memory, eliminating the gaps left by unreachable (dead) objects. This process has two main benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It frees up larger blocks of continuous memory, making it easier to allocate new objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It improves memory access efficiency by keeping related objects closer together.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndmwauvvzyjq0iue15mb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndmwauvvzyjq0iue15mb.png" alt="memory compacting in garbage collection" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Updates Pointers.
&lt;/h3&gt;

&lt;p&gt;The final process of the collection is to correct all pointers so it points to the new locations of the reachable objects.&lt;/p&gt;

&lt;p&gt;The heap pointer is also adjusted, positioned after the last reachable object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The heap pointer, also known as the "free space pointer" or "allocation pointer," indicates where the next object will be allocated in the managed heap. After compaction, this pointer is moved to the end of the last reachable object. This ensures that new allocations will occur in the contiguous free space, promoting efficient memory usage.&lt;/p&gt;

&lt;p&gt;In summary, the garbage collector does:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqzjmwppboa3o5h2pmrba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqzjmwppboa3o5h2pmrba.png" alt="Garbage Collector in summary" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Generations
&lt;/h2&gt;

&lt;p&gt;That not the whole story though, in other to maximize efficiency and reduce performance overhead, modern algorithms includes generations.&lt;/p&gt;

&lt;p&gt;Typically, the GC Algorithm makes several assumptions, one of which is "Newer objects have shorter lifetimes, and older objects have longer lifetimes". Hence, three (3) generations are available 1, 2, and 3.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Larger Objects occupy Generation 3, collection rounds does not come around often.&lt;/li&gt;
&lt;li&gt;Generation 2 contains objects that survives the Generation 0 collection round, hence promoted. When Collection round comes by this generation, it includes those in 3 as well.&lt;/li&gt;
&lt;li&gt;Generation 1 is where all newly created objects are considered. most object here don't survive the collection round, and are promoted to Generation 2 if they did.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;[Illustration]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5anjohw5c68bp5vmcw9h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5anjohw5c68bp5vmcw9h.png" alt="Garbage collection generation hierarchy" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A lot of thing do happen during garbage collection, It was such an Interesting topic for me personally to read about, Super hoped you learn something new as I did. Stay tuned for more awesome topics coming to the &lt;a href="https://www.yaqeen.me/blog/series/uth" rel="noopener noreferrer"&gt;UTH series&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Resources
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals" rel="noopener noreferrer"&gt;Fundamentals of garbage collection - .NET | Microsoft Learn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.techtarget.com/searchstorage/definition/garbage-collection" rel="noopener noreferrer"&gt;What is garbage collection (GC) in programming?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)" rel="noopener noreferrer"&gt;Garbage collection (computer science) - Wikipedia&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Before you go:
&lt;/h3&gt;

&lt;p&gt;I'm building commentrig, a platform that allows you to integrate a robust comment system to your website. Offering a package for all your favorite frameworks.&lt;/p&gt;

&lt;p&gt;Join the waitlist here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.commentrig.com" rel="noopener noreferrer"&gt;https://commentrig.com/waitlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay super awesome 🫶🏾.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
    </item>
    <item>
      <title>How SSH Works - Under The Hood</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Sat, 18 May 2024 17:06:18 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/how-ssh-works-under-the-hood-1i3k</link>
      <guid>https://dev.to/abdulmuminyqn/how-ssh-works-under-the-hood-1i3k</guid>
      <description>&lt;p&gt;In this weeks under the hood episode, we will take look into something a lot of system admins and DevOps use almost daily and that is ‘SSH’ which stands for secure shell.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In case you missed the previous UTH episode where we discussed the ‘Fisher Yates’ algorithm, you can catch that &lt;a href="https://www.yaqeen.me/blog/fisher-yates-how-the-popular-shuffling-algorithm-works-uth-series" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is SSH?
&lt;/h2&gt;

&lt;p&gt;SSH as you may already know, is a network protocol used to establish a secure access to operate a remote machine, without being physically present. SSH first appearance was in the mid 1990’s, originally developed by &lt;a href="https://ylonen.org/index.html" rel="noopener noreferrer"&gt;Tatu Ylonen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z6jc-xAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://paper-attachments.dropboxusercontent.com/s_ED4A03F1900B4A123CECA802B644C7BA40B660FB6A23CAA3446E5C1CFC04CDD5_1715889341000_file.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z6jc-xAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://paper-attachments.dropboxusercontent.com/s_ED4A03F1900B4A123CECA802B644C7BA40B660FB6A23CAA3446E5C1CFC04CDD5_1715889341000_file.webp" alt="Tatu Ylonen" width="318" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Up until it appearance, other services like Telnet, rlogin or RSH, where used to achieve this purpose. Although, they got quite a problem, i.e they transmits all information including usernames and passwords in plaintext, so it is not recommended for security-sensitive applications.&lt;/p&gt;

&lt;p&gt;Anyone sniffing the network, would easily read all information including sensitive ones crystal clear.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl189xc73sesl6isdqvb4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl189xc73sesl6isdqvb4.png" alt="DIAGRAM OF AN ATTACKER LISTENING ON A CONNECTION BETWEEN TWO COMPUTERS" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This flaw, is what SSH aim to solve, a method to connect to a remote machine, where by all data going through the network is secured and encrypted.&lt;/p&gt;

&lt;p&gt;We will look at all process involve in successfully establishing an SSH connection , and I will try my best to simplify what happens at each of these layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialization:
&lt;/h2&gt;

&lt;p&gt;When you initialize an SSH connection with a SSH server, A three way (SYN, SYN-ACK, ACK) handshake occurs between the client and server to establish a TCP connection on port &lt;strong&gt;22&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Handshake, if you’re not familiar with it, is a process by which the client and server ensures that both are ready for communication. In case of the three-way handshake - the client sends SYN (synchronization) with a packet containing a number X, then the server acknowledges (ACK) that, by responding with an increment X+1 i.e and also it own synchronization (SYN) packet containing a number Y, by which the client acknowledges that by sending over Y+1.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, a version exchange occurs between the client and server, where they verify whether or not, they are able to communicate based on there version numbers, In case of any compatibility issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Algorithm negotiation.
&lt;/h2&gt;

&lt;p&gt;Following the version exchange, both the client and server exchange list of their supported cryptographic algorithms, and then they agree on the algorithms to use, typically the first mutually supported algorithm from each list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Exchange
&lt;/h2&gt;

&lt;p&gt;In this step, both client and server securely generates a session key by using mostly Diffie Hellman algorithm.&lt;/p&gt;

&lt;p&gt;The algorithm works very simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Keep in mind that “value” is some mathematical thingy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Initially both parties agree upon common value (mostly a large prime number), which is usually not needed to be secret, let say it the seed value.&lt;/li&gt;
&lt;li&gt;Then, they generate a secret value, that they don’t exchange with each other. (a private key)&lt;/li&gt;
&lt;li&gt;Both the seed value and the secret value are then combined together to generate a public key, and then exchanged over the network.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;This can be done because, it will be very difficult to break it up into the exact values that created it. hence a third party doesn't stand a chance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Then upon the client and server receiving each others resulting combinations, they both uses their private key, public key and the seed value to compute a shared secret.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think one of the most simplified explanation and visual, will be that of the color mixing analogy:&lt;/p&gt;

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

&lt;p&gt;Further learning&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#Cryptographic_explanation" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#Cryptographic_explanation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=NmM9HA2MQGI&amp;amp;" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=NmM9HA2MQGI&amp;amp;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/NmM9HA2MQGI" rel="noopener noreferrer"&gt;https://youtu.be/NmM9HA2MQGI&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication
&lt;/h2&gt;

&lt;p&gt;After both devices have successfully establish a secure communication, authenticating the client will be required in other to provide access.&lt;/p&gt;

&lt;p&gt;In SSH, authentication can be done with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passwords&lt;/li&gt;
&lt;li&gt;private/public key mechanism&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While passwords are very straightforward to understand. let skip that and look at the private/public key mechanism method.&lt;/p&gt;

&lt;p&gt;Typically what you do is:&lt;/p&gt;

&lt;p&gt;Generate an SSH key and copy that over to your ssh server.&lt;/p&gt;

&lt;p&gt;Then, whenever you request to connect, the SSH does something like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The server encrypt some kind of message with your public key and sends it over.&lt;/li&gt;
&lt;li&gt;Your SSH client uses your private key to decrypt the challenge from the server.&lt;/li&gt;
&lt;li&gt;If the decryption is successful, it proves you possess the corresponding private key.&lt;/li&gt;
&lt;li&gt;The server can then verify if it was indeed it original message and allow you to connect.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Transport
&lt;/h2&gt;

&lt;p&gt;After a successful authentication, SSH open up a new channel for back and forth transportation, which allows for different functionality like multiplexing, tunneling, port forwarding and so forth.&lt;/p&gt;

&lt;p&gt;Every packet going through is encrypted, also a little bit of padding is added in there just for a little more extra security.&lt;/p&gt;

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

&lt;p&gt;That’s it, an overview of SSH does under the wood to establish a connection between devices.&lt;/p&gt;

&lt;p&gt;Super hoped you learned something new as I did.&lt;/p&gt;

&lt;h4&gt;
  
  
  What I’m currently working on:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="http://devcanvas.art" rel="noopener noreferrer"&gt;devcanvas.art&lt;/a&gt; - an online frontend editor with super powers; fast preview, plugins and an amazing library of cool frontend creations for your inspiration and learning.&lt;/p&gt;

&lt;p&gt;Try devcanvas @ &lt;a href="http://devcanvas.art/new" rel="noopener noreferrer"&gt;devcanvas.art/new&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Further reading:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=ORcvSkgdA58" rel="noopener noreferrer"&gt;How Secure Shell Works (SSH) - Computerphile&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.hostinger.com/tutorials/ssh-tutorial-how-does-ssh-work" rel="noopener noreferrer"&gt;What Is SSH: Understanding Encryption, Ports and Connection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cloudflare.com/learning/access-management/what-is-ssh/" rel="noopener noreferrer"&gt;What is SSH? | Secure Shell (SSH) protocol&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process" rel="noopener noreferrer"&gt;Understanding the SSH Encryption and Connection Process&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=hwKhJ74ydOw" rel="noopener noreferrer"&gt;What is SSH? How it Works? [Animated Video]&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>devops</category>
      <category>network</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Fisher Yates - How the popular shuffling Algorithm Works - Under the hood series</title>
      <dc:creator>Abdulmumin yaqeen</dc:creator>
      <pubDate>Fri, 10 May 2024 07:55:57 +0000</pubDate>
      <link>https://dev.to/abdulmuminyqn/fisher-yates-how-the-popular-shuffling-algorithm-works-under-the-hood-series-1dg9</link>
      <guid>https://dev.to/abdulmuminyqn/fisher-yates-how-the-popular-shuffling-algorithm-works-under-the-hood-series-1dg9</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Following my curiosity, I decided to try demystify new concepts, algorithms or just how things work behind the scenes every week. And It would make a lot more sense, if I even share those journeys with the community, so I decided to take it on.&lt;/p&gt;

&lt;p&gt;In this &lt;strong&gt;under the hood series&lt;/strong&gt;, I will be sharing what I’ve learned and how some algorithms or programs, or even just any cool concept (In programming of course) we use works behind the scenes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In future titles or writing, I might sometimes refer to Under the hood series as “UTH” series.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For this week, we will be starting simple. I will be demystifying a really popular technique or algorithm most of us use to shuffle our arrays i.e the “Fisher Yates or Knuth Algorithm”.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fisher Yates?
&lt;/h2&gt;

&lt;p&gt;Fisher Yates is not actually one person, it was coined after &lt;a href="https://en.wikipedia.org/wiki/Ronald_Fisher" rel="noopener noreferrer"&gt;Ronald&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Ronald_Fisher" rel="noopener noreferrer"&gt;&lt;strong&gt;Fisher&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Frank_Yates" rel="noopener noreferrer"&gt;Frank&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Frank_Yates" rel="noopener noreferrer"&gt;&lt;strong&gt;Yates&lt;/strong&gt;&lt;/a&gt;, who developed the original idea of the algorithm, which was later modified a bit for efficiency by &lt;a href="https://en.wikipedia.org/wiki/Donald_Knuth" rel="noopener noreferrer"&gt;Donald Knuth&lt;/a&gt;, hence the alternate name &lt;strong&gt;- Knuth shuffle.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s is a high level detail of how it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1. Having all the element you want to shuffle (needs to be finite of course), create a separate list to store the shuffled elements (let call it the output list).&lt;/li&gt;
&lt;li&gt;Step 2. Select an element X randomly from the list and add it to the output list, then mark X as visited.&lt;/li&gt;
&lt;li&gt;Step 3. Repeat the previous step (i.e Step 2) until all elements are visited.&lt;/li&gt;
&lt;li&gt;Step 4. End the process&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;… and a shuffled list has been obtained. This is definitionally the solution most of us would intuitively think of and if you’ve implemented such before, well, now you know what it is called.&lt;/p&gt;

&lt;p&gt;Let try to visualize this with some diagram:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Array&lt;/th&gt;
&lt;th&gt;Output list&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;[ F, I, S, H, E, R, Y, A, T, E, S ]&lt;/td&gt;
&lt;td&gt;[]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ F, I, S, H, E, R, Y, A, T, E, S ]&lt;/td&gt;
&lt;td&gt;[S]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ F, I, S, H, E, R, Y, A, T, E, - ]&lt;/td&gt;
&lt;td&gt;[SI]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ F, -, S, H, E, R, Y, A, T, E, - ]&lt;/td&gt;
&lt;td&gt;[SIH]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ F, -, S, -, E, R, Y, A, T, E, - ]&lt;/td&gt;
&lt;td&gt;[SIHR]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ F, -, S, -, E, -, Y, A, T, E, - ]&lt;/td&gt;
&lt;td&gt;[SIHRA]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ F, -, S, -, E, -, Y, -, T, E, - ]&lt;/td&gt;
&lt;td&gt;[SIHRAF]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ -, -, S, -, E, -, Y, -, T, E, - ]&lt;/td&gt;
&lt;td&gt;[SIHRAFE]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ -, -, S, -, E, -, Y, -, T, -, - ]&lt;/td&gt;
&lt;td&gt;[SIHRAFEY]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ -, -, S, -, E, -, -, -, T, -, - ]&lt;/td&gt;
&lt;td&gt;[SIHRAFEYE]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ -, -, S, -, -, -, -, -, T, -, - ]&lt;/td&gt;
&lt;td&gt;[SIHRAFEYET]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ -, -, S, -, -, -, -, -, -, -, - ]&lt;/td&gt;
&lt;td&gt;[SIHRAFEYETS]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[ -, -, -, -, -, -, -, -, -, -, - ]&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There goes the algorithm visually. Now, with all this information in check, we can implement this algorithm quite easily.&lt;/p&gt;

&lt;p&gt;I will be doing that with JavaScript, even though it not the most elegant language for a demo.&lt;/p&gt;

&lt;p&gt;Firstly some boilerplate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in our function, we will create a new array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shuffled_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we will then randomly select from our original array to the shuffled array. But before that, as seen in the description, we will not be modifying our original array whenever we pick a random value, but rather mark that spot as visited, so we will need another array to store visited indexes/positions.&lt;/p&gt;

&lt;p&gt;Hence our solution will look more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shuffled_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;visited&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;visited&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;shuffled_array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
        &lt;span class="nx"&gt;visited&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;shuffled_array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, Let test out our little algorithm to see if it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yates&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="s1"&gt;F&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;S&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;H&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;R&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Y&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;T&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;S&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shuffled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yates&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shuffled&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Random output I got after testing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ["I","A","T","Y","F","R","E","H","S","E","S"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Not very efficient, Right?
&lt;/h2&gt;

&lt;p&gt;As you can see, from the implementation we can guess that this method might not do well with large inputs, due to the step where we initialized another loop to pick another element if that randomly selected one has previously been visited.&lt;/p&gt;

&lt;p&gt;This makes the time complexity O(n2), which is not great, adding to the fact that we introduced a bunch of new arrays. This issue is what &lt;a href="https://en.wikipedia.org/wiki/Donald_Knuth" rel="noopener noreferrer"&gt;Donald Knuth&lt;/a&gt;’s variant addresses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Donald Knuth’s Solution
&lt;/h2&gt;

&lt;p&gt;While following the same principle as the Fisher Yates, Knuth’s variant makes the algorithm more efficient, getting read of the additional arrays required in the process, also reducing the time complexity to just O(n).&lt;/p&gt;

&lt;p&gt;Knuth’s variant looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1. Select an element X randomly ( index between 0 and I (inclusive), where I is the current Index ) from the list and swap it position with the last element in the list.&lt;/li&gt;
&lt;li&gt;Step 2. Repeat the previous step (i.e Step 2) for the ‘n’ number of elements in the list.&lt;/li&gt;
&lt;li&gt;Step 3. End the process, The resulted list is our shuffled list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Shuffling in the Knuth's variant is done from lowest index to the highest index of the array.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Original Array&lt;/th&gt;
&lt;th&gt;Random Index&lt;/th&gt;
&lt;th&gt;Shuffled Array&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;[K, N, U, T, H]&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;[N, K, U, T, H]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[N, K, U, T, H]&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;[N, T, U, K, H]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[N, T, U, K, H]&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;[N, T, H, K, U]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[N, T, H, K, U]&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;[N, T, K, H, U]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[N, T, K, H, U]&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;[N, T, K, H, U]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With all that, let see what the implementation looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This version looks alot better, and also less code? yes please!&lt;/p&gt;

&lt;p&gt;In this implementation, it is important to note that we are getting from the range of &lt;code&gt;0 - i+1&lt;/code&gt;, where &lt;code&gt;i&lt;/code&gt; is the current iteration, and &lt;code&gt;+1&lt;/code&gt; means to include &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That is to say, when:&lt;/p&gt;

&lt;p&gt;i = arr.length (9 for example)&lt;br&gt;
we will be picking a random number for &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo567cwsypb3yifwdo1q3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo567cwsypb3yifwdo1q3.png" alt="randomly select from 0 - 9; fisher yates knuth’s variant." width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then when &lt;code&gt;i&lt;/code&gt; is &lt;code&gt;8&lt;/code&gt;;&lt;br&gt;
The range will be from &lt;code&gt;0&lt;/code&gt; - &lt;code&gt;8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcz96zh5bd8ey87oubaus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcz96zh5bd8ey87oubaus.png" alt="randomly select from 0 - 8; fisher yates knuth’s variant." width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then when &lt;code&gt;i&lt;/code&gt; is &lt;code&gt;7&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3mnc1wsamd2nyjterto.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3mnc1wsamd2nyjterto.png" alt="randomly select from 0 - 7; fisher yates knuth’s variant." width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Until the end.&lt;/p&gt;

&lt;p&gt;That effectively sums up the Fisher Yates algorithm and also this weeks Under the wood episode.&lt;/p&gt;

&lt;p&gt;Super hope you learn something new and interesting as I did.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I’m currently working on:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DevCanvas&lt;/strong&gt; - an online editor with super powers, fast preview, plugins and super cool library of cool Frontend creations for your inspiration.&lt;/p&gt;

&lt;p&gt;Try devcanvas @ &lt;a href="https://devcanvas.art/new" rel="noopener noreferrer"&gt;devcanvas.art/new&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay super awesome 🫶🏾.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>learning</category>
      <category>programming</category>
      <category>dsa</category>
    </item>
  </channel>
</rss>
