<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Snehendu Roy]]></title><description><![CDATA[Snehendu Roy]]></description><link>https://tech.roydevelops.tech</link><generator>RSS for Node</generator><lastBuildDate>Sat, 16 May 2026 18:39:32 GMT</lastBuildDate><atom:link href="https://tech.roydevelops.tech/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The TCP/IP and OSI model - Day 4]]></title><description><![CDATA[Introduction to Network Models
Imagine Maria, sitting at her desk in New York, wanting to check the flight status for her friend's arrival in Tokyo. With a few clicks, she opens her browser and navigates to the airline's website. This seemingly simpl...]]></description><link>https://tech.roydevelops.tech/the-tcpip-and-osi-model-day-4</link><guid isPermaLink="true">https://tech.roydevelops.tech/the-tcpip-and-osi-model-day-4</guid><category><![CDATA[networking]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Linux]]></category><category><![CDATA[hacking]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Sat, 03 May 2025 00:14:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1746231254591/4eba067a-4a77-48ca-a104-691cc2c3d71e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction-to-network-models">Introduction to Network Models</h1>
<p>Imagine Maria, sitting at her desk in New York, wanting to check the flight status for her friend's arrival in Tokyo. With a few clicks, she opens her browser and navigates to the airline's website. This seemingly simple action triggers an intricate sequence of events across the digital landscape, navigating through layers of network protocols before returning with the information she needs.</p>
<p>Computer networks rely on standardized frameworks to facilitate this type of communication. Two primary models exist: the practical TCP/IP model and the theoretical OSI model. These frameworks are like the postal service of the digital world, ensuring Maria's request reaches the correct destination and that she receives the proper response.</p>
<h1 id="heading-layer-comparison-between-tcpip-and-osi">Layer Comparison between TCP/IP and OSI</h1>
<p>The TCP/IP model consists of five layers:</p>
<ol>
<li><p><strong>Physical Layer (1)</strong>: Handles the transmission of raw bit streams over a physical medium. This includes electrical specifications, cables, connectors, and signaling methods. For Maria, this is where her laptop's network card converts her request into electrical signals that travel through her home's Ethernet cable or Wi-Fi radio waves.</p>
</li>
<li><p><strong>Data Link Layer (2)</strong>: Provides reliable transmission of data frames between two nodes connected by a physical layer. It handles error detection, addressing (MAC addresses), and media access control. Here, Maria's request gets an address label similar to an envelope with a local delivery code.</p>
</li>
<li><p><strong>Network Layer (3)</strong>: Manages addressing, routing, and packet forwarding between networks. The Internet Protocol (IP) operates at this layer, handling logical addressing and path determination. Maria's request now acquires long-distance addressing—like adding a country and city to her envelope—allowing it to navigate across the global internet toward Japan.</p>
</li>
<li><p><strong>Transport Layer (4)</strong>: Ensures complete data transfer by providing end-to-end communication services. TCP (connection-oriented, reliable) and UDP (connectionless, unreliable) protocols operate here, managing port numbers, segmentation, and flow control. This layer ensures Maria's request arrives completely intact, similar to how a registered mail service tracks packages and confirms delivery.</p>
</li>
<li><p><strong>Application Layer (5)</strong>: Provides network services directly to end-users or applications. In TCP/IP, this combines the functions of the upper three OSI layers (Session, Presentation, and Application). This is where Maria's browser formats her request in ways the airline server will understand.</p>
</li>
</ol>
<p>Meanwhile, the OSI model features seven layers:</p>
<ol>
<li><p><strong>Physical Layer (1)</strong>: Identical to TCP/IP's Physical layer, managing hardware connections and raw data transmission.</p>
</li>
<li><p><strong>Data Link Layer (2)</strong>: Similar to TCP/IP's Data Link layer, handling frame-based transmission and MAC addressing.</p>
</li>
<li><p><strong>Network Layer (3)</strong>: Equivalent to TCP/IP's Network layer, managing logical addressing and routing.</p>
</li>
<li><p><strong>Transport Layer (4)</strong>: Corresponds to TCP/IP's Transport layer, providing end-to-end communication control.</p>
</li>
<li><p><strong>Session Layer (5)</strong>: Establishes, manages, and terminates connections between applications, not explicitly defined in TCP/IP. For Maria, this layer manages the ongoing conversation between her browser and the airline's server.</p>
</li>
<li><p><strong>Presentation Layer (6)</strong>: Handles data translation, encryption, and formatting, also not explicitly defined in TCP/IP. This ensures the flight information appears correctly on Maria's screen regardless of what type of device she's using.</p>
</li>
<li><p><strong>Application Layer (7)</strong>: Provides network services to end-user applications, similar to TCP/IP's Application layer but more narrowly defined. This is where Maria's browser displays the flight information in a user-friendly format.</p>
</li>
</ol>
<p>Network professionals commonly use the mnemonic "Please Do Not Throw Sausage Pizza Away" to remember these seven layers.</p>
<h1 id="heading-practical-implementation">Practical Implementation</h1>
<p>While TCP/IP is more commonly implemented in real-world applications, discussions about networking typically reference the OSI model's seven-layer structure. This creates a practical hybrid approach where data transfers through TCP/IP's five layers, but professionals conceptualize them within OSI's seven-layer framework.</p>
<p>In Maria's case, her flight status request actually travels through the TCP/IP model's implementation, but network engineers troubleshooting any connection issues would discuss problems in terms of which OSI layer is affected.</p>
<h1 id="heading-session-and-presentation-layers">Session and Presentation Layers</h1>
<p>In the OSI model, two additional layers exist between the Transport and Application layers:</p>
<h2 id="heading-session-layer-5">Session Layer (5)</h2>
<p>The Session layer establishes, manages, and terminates connections between applications. Its key functions include:</p>
<ul>
<li><p>Dialog control (determining which device can transmit and when)</p>
</li>
<li><p>Session establishment, maintenance, and termination</p>
</li>
<li><p>Synchronization (establishing checkpoints during data transfer)</p>
</li>
<li><p>Managing session recovery after failures</p>
</li>
<li><p>Supporting both simplex, half-duplex, and full-duplex operation modes</p>
</li>
</ul>
<p>For Maria's flight check, this layer maintains the connection between her browser and the airline server throughout her session, even as she navigates to different pages to check additional flight details, baggage policies, or terminal information.</p>
<h2 id="heading-presentation-layer-6">Presentation Layer (6)</h2>
<p>The Presentation layer prepares data for the Application layer by transforming it into a format that application-level processes can understand. Key functions include:</p>
<ul>
<li><p>Data translation and formatting</p>
</li>
<li><p>Encryption and decryption</p>
</li>
<li><p>Compression and decompression</p>
</li>
<li><p>Character set conversion (ASCII, EBCDIC, etc.)</p>
</li>
<li><p>Managing file formats (JPEG, TIFF, GIF, etc.)</p>
</li>
<li><p>Abstracting syntax differences between communicating systems</p>
</li>
</ul>
<p>This layer ensures that when Maria receives flight information that includes the airline's logo, flight status indicators, or maps, these elements are correctly formatted and displayed on her screen regardless of her device or operating system.</p>
<h1 id="heading-data-encapsulation-process">Data Encapsulation Process</h1>
<p>When data travels from one system to another, it follows a specific encapsulation process, with the data unit having different names at each layer:</p>
<ol>
<li><p><strong>Initial Connectivity</strong>: ARP packets identify the data transfer path, and DNS servers resolve the actual IP address of the destination. When Maria types "<a target="_blank" href="http://tokyoairlines.com">tokyoairlines.com</a>" in her browser, DNS servers first translate this name into the actual IP address of the airline's web server.</p>
</li>
<li><p><strong>Application Layer (7/5)</strong>: The data begins its journey at this layer as <strong>data</strong> or <strong>messages</strong>. Maria's request for flight JL123's status is prepared for transmission using HTTP or HTTPS protocols.</p>
</li>
<li><p><strong>Presentation Layer (6)</strong>: In the OSI model, the <strong>data</strong> is formatted, possibly compressed, and/or encrypted for standardized transmission. Maria's request might be encrypted if using HTTPS, protecting her session information.</p>
</li>
<li><p><strong>Session Layer (5)</strong>: The OSI model establishes a session between the communicating applications. The <strong>data</strong> maintains its form while a unique session identifier is created for Maria's interaction with the airline website.</p>
</li>
<li><p><strong>Transport Layer (4)</strong>: Data receives a header containing port information (port 80 for HTTP or 443 for HTTPS), creating a <strong>segment</strong> (TCP) or <strong>datagram</strong> (UDP). This is like specifying which department at Tokyo Airlines should receive Maria's request.</p>
<h2 id="heading-tcp-3-way-handshake">TCP 3-Way Handshake</h2>
<p> Before Maria's flight status request data can be transmitted, her computer and the airline server must establish a reliable connection. This happens through the TCP 3-way handshake:</p>
<ol>
<li><p><strong>SYN (Synchronize)</strong>: Maria's computer sends a <strong>segment</strong> with the SYN flag set and an initial sequence number (ISN). This is like Maria saying, "Hello, Tokyo Airlines! I'd like to start a conversation with reference number 1000."</p>
</li>
<li><p><strong>SYN-ACK (Synchronize-Acknowledge)</strong>: The airline server responds with a <strong>segment</strong> containing both the SYN and ACK flags, acknowledging Maria's sequence number and providing its own ISN. This is like the airline responding, "Hello Maria! I received your message #1000, and I'm responding with my reference number 2000."</p>
</li>
<li><p><strong>ACK (Acknowledge)</strong>: Maria's computer sends a <strong>segment</strong> with the ACK flag set, acknowledging the server's sequence number. This completes the connection establishment. It's like Maria saying, "Great! I confirm receipt of your message #2000. Now we can talk about my flight status request."</p>
</li>
</ol>
</li>
</ol>
<p>    Only after this handshake is complete can Maria's actual flight status request be transmitted. This process ensures reliable, ordered delivery of data and is why TCP is considered a connection-oriented protocol.</p>
<h2 id="heading-tcp-vs-udp">TCP vs UDP</h2>
<p>    While Maria's flight status check uses TCP for reliability, her friend Raj is simultaneously streaming the airline's promotional video. His application is using UDP instead:</p>
<p>    <strong>TCP (Transmission Control Protocol)</strong>:</p>
<ul>
<li><p><strong>Connection-oriented</strong>: Establishes a connection before data transfer</p>
</li>
<li><p><strong>Reliable</strong>: Guarantees delivery through acknowledgments and retransmission</p>
</li>
<li><p><strong>Ordered</strong>: Maintains sequence of packets</p>
</li>
<li><p><strong>Flow control</strong>: Prevents overwhelming receivers with too much data</p>
</li>
<li><p><strong>Error detection</strong>: Checks for corrupted packets</p>
</li>
<li><p><strong>Examples</strong>: Web browsing (HTTP/HTTPS), email (SMTP), file transfers (FTP)</p>
</li>
</ul>
<p>    <strong>UDP (User Datagram Protocol)</strong>:</p>
<ul>
<li><p><strong>Connectionless</strong>: No handshake, just sends data immediately</p>
</li>
<li><p><strong>Unreliable</strong>: No guarantee of delivery or order</p>
</li>
<li><p><strong>Lightweight</strong>: Minimal header overhead (8 bytes vs TCP's 20+ bytes)</p>
</li>
<li><p><strong>Faster</strong>: No connection establishment, acknowledgments, or retransmission</p>
</li>
<li><p><strong>No congestion control</strong>: Will not slow down when network is busy</p>
</li>
</ul>
<p>    <strong>Real-World UDP Applications</strong>:</p>
<ul>
<li><p><strong>Live Streaming</strong>: When Raj watches the airline's promotional video, occasional dropped frames are preferable to buffering delays.</p>
</li>
<li><p><strong>Online Gaming</strong>: When Maria's son plays multiplayer games, the quick response is more important than perfect data delivery.</p>
</li>
<li><p><strong>VoIP Calls</strong>: During Maria's call to confirm her friend's arrival details, brief audio glitches are acceptable but conversation delays are not.</p>
</li>
<li><p><strong>DNS Lookups</strong>: When resolving "<a target="_blank" href="http://tokyoairlines.com">tokyoairlines.com</a>" to an IP address, speed matters most.</p>
</li>
<li><p><strong>IoT Devices</strong>: Maria's smart home sensors send frequent but non-critical updates using UDP.</p>
</li>
<li><p><strong>DHCP</strong>: When Maria's laptop first connects to the airport Wi-Fi, it uses UDP to quickly obtain an IP address.</p>
</li>
</ul>
<p>    UDP is ideal for time-sensitive applications where losing some data is preferable to waiting for retransmissions. If Maria were video-chatting with her friend about the flight status, the application would likely use UDP for the video/audio and TCP for chat messages and control signals.</p>
<ol start="6">
<li><p><strong>Network Layer (3)</strong>: The segment acquires a header with source and destination IP addresses, forming a <strong>packet</strong>. Now Maria's message has both her return address and the airline server's address.</p>
</li>
<li><p><strong>Data Link Layer (2)</strong>: Adds header and trailer with MAC addresses, creating a <strong>frame</strong>. This adds the specific information needed to get Maria's request to the first stop on its journey, her local internet gateway.</p>
</li>
<li><p><strong>Physical Layer (1)</strong>: Converts information into <strong>bits</strong> represented as signals (electrical, optical, or radio) for transmission over the physical medium. Maria's request leaves her laptop as electrical signals through her router.</p>
</li>
</ol>
<h1 id="heading-data-transmission-path">Data Transmission Path</h1>
<p>Maria's flight status request now travels through the network following a specific path:</p>
<ol>
<li><p><strong>Source Device</strong>: The request originates from Maria's laptop in New York and passes down through all layers of the protocol stack, with each layer adding its header information. By the time it leaves her device, the original data has been transformed into <strong>bits</strong> within a <strong>frame</strong>.</p>
</li>
<li><p><strong>LAN Infrastructure</strong>: The <strong>frame</strong> travels from Maria's laptop to her home's Wi-Fi router, which forwards it based on MAC addresses.</p>
</li>
<li><p><strong>Router</strong>: The router strips the <strong>frame</strong> to access the <strong>packet</strong>, examines the IP addresses, determines the best route, and forwards it toward Tokyo Airlines' servers.</p>
</li>
<li><p><strong>Internet/WAN</strong>: The <strong>packet</strong> traverses multiple routers across different networks spanning continents, with each router making independent forwarding decisions to move Maria's request closer to its destination in Japan.</p>
</li>
<li><p><strong>Destination Network</strong>: Upon reaching Tokyo Airlines' network, the <strong>packet</strong> is delivered to the appropriate server based on routing information.</p>
</li>
<li><p><strong>Destination Device</strong>: The <strong>frame</strong> arrives at the airline's web server, which processes it upward through the protocol stack, removing each layer's header. The process reverses:</p>
<ul>
<li><strong>Frame</strong> → <strong>Packet</strong> → <strong>Segment</strong> → <strong>Data</strong></li>
</ul>
</li>
</ol>
<p>The original flight status request reaches the web application, which queries its database and prepares a response showing that flight JL123 is "On Time."</p>
<p>The response then follows the same process in reverse, beginning at the application layer of the airline's server and working down through encapsulation, across the internet, and up through the protocol layers of Maria's laptop, until finally, her browser displays "Flight JL123: On Time" on her screen.</p>
<p>This process occurs bidirectionally, allowing for request-response communication between systems. At each step, the networking devices operate only at their relevant layers: switches primarily at Layer 2, routers at Layer 3, and end devices across all layers.</p>
]]></content:encoded></item><item><title><![CDATA[Networking: Switches and Routers - Day 3]]></title><description><![CDATA[Story to Set The Stage
Imagine you live in a small town where everyone sends letters to each other. At first, there was only one mail carrier who would take your letter and shout its contents to everyone in town. This was noisy and everyone heard mes...]]></description><link>https://tech.roydevelops.tech/networking-switches-and-routers-day-3</link><guid isPermaLink="true">https://tech.roydevelops.tech/networking-switches-and-routers-day-3</guid><category><![CDATA[Linux]]></category><category><![CDATA[Ubuntu]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Fri, 02 May 2025 10:32:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1746181932729/c0c2e184-c619-43be-8d43-23b210a35263.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-story-to-set-the-stage">Story to Set The Stage</h1>
<p>Imagine you live in a small town where everyone sends letters to each other. At first, there was only one mail carrier who would take your letter and shout its contents to everyone in town. This was noisy and everyone heard messages that weren't meant for them!</p>
<p>This old system is like a network "hub" - not very private or efficient.</p>
<p>Then the town got smart. They hired special mail carriers called "switches" who remembered where everyone lived. Now when you send a letter, the carrier takes it directly to your friend's house - no shouting involved!</p>
<p>But what happens when you want to send a letter to someone in another town? That's when you need the main post office, or "router," to help send your message to the right town first.</p>
<p>With this simple system, you can understand how computers talk to each other:</p>
<ul>
<li><p>Switches handle mail delivery within your own town</p>
</li>
<li><p>Routers help get messages to different towns</p>
</li>
<li><p>Each town has its own street names and house numbers (like computer networks)</p>
</li>
</ul>
<p>Let's explore how this works in more detail!</p>
<h1 id="heading-switches">Switches</h1>
<p>Switches are like smart mail carriers for your local neighborhood of computers. They connect multiple computers through cables called Ethernet ports and make sure messages go exactly where they need to.</p>
<h2 id="heading-from-hubs-to-switches">From Hubs to Switches</h2>
<p>Before switches, we had hubs. When someone sent a message through a hub, it was like shouting in a room full of people - everyone heard it whether it was for them or not! This wasted time and created security problems.</p>
<p>Switches, on the other hand, deliver messages only to the intended recipient. It's like the difference between announcing a secret to an entire room versus whispering it directly to your friend.</p>
<h2 id="heading-how-switches-work">How Switches Work</h2>
<p>The clever thing about switches is they learn and remember which computer is connected to which port. They do this through:</p>
<ol>
<li><p><strong>CAM Tables</strong> (Content Addressable Memory): Think of this as the switch's address book. It records which computer lives at which "house" (port).</p>
</li>
<li><p><strong>Learning Process</strong>: When a computer sends a message, the switch makes a note: "Computer A is at Port 3" and writes it in its address book.</p>
</li>
<li><p><strong>Smart Delivery</strong>: After learning where everyone "lives," the switch can deliver messages directly instead of broadcasting to everyone.</p>
</li>
</ol>
<h2 id="heading-technical-details">Technical Details</h2>
<p>Messages traveling through a switch are called <strong>frames</strong>. People often call them "packets" in casual conversation, but technically they're frames.</p>
<h3 id="heading-the-role-of-arp">The Role of ARP</h3>
<p>When computers talk to each other, they need to know two addresses:</p>
<ul>
<li><p>IP address: Like knowing someone lives on "Main Street" (the general neighborhood)</p>
</li>
<li><p>MAC address: Like knowing their exact house number</p>
</li>
</ul>
<p>Before sending any actual message, computers first need to find each other. This is where ARP (Address Resolution Protocol) comes in. Think of it as sending a small note asking, "Where exactly do you live?" before sending the main letter.</p>
<p>Here's what happens:</p>
<ol>
<li><p>Computer A wants to send a message to Computer B, but only knows B's street address (IP address)</p>
</li>
<li><p>Computer A first sends a special ARP packet (like a small inquiry note) asking: "Who has IP address 10.1.1.5?"</p>
</li>
<li><p>Computer B sees this ARP packet and responds: "That's me! My house number (MAC address) is 00:1A:2B:3C:4D:5E"</p>
</li>
<li><p>Computer A writes this down in its "ARP cache" (address book) for future reference</p>
</li>
<li><p>The switch also makes a note of this in its CAM table</p>
</li>
<li><p>ONLY THEN can Computer A send the actual message, now that it knows exactly where to deliver it</p>
</li>
</ol>
<p>This ARP process happens automatically before any communication between computers that haven't talked before, or when saved address information has expired. The actual message data is only sent after this ARP handshake is complete.</p>
<h2 id="heading-layer-2-the-switchs-domain">Layer 2: The Switch's Domain</h2>
<p>Switches operate at what network experts call "Layer 2" or the "Data Link Layer." This is simply the level of networking that deals with delivering frames between devices on the same network. It's concerned with MAC addresses (the physical addresses of devices) rather than IP addresses.</p>
<p>Think of Layer 2 as knowing the exact house numbers on a street, but not knowing how to get to different streets or towns.</p>
<h1 id="heading-routers">Routers</h1>
<p>While switches are excellent for connecting computers in the same neighborhood, routers connect different neighborhoods together.</p>
<h2 id="heading-life-without-routers">Life Without Routers</h2>
<p>With just switches, computers in the same neighborhood can talk easily. The switch knows everyone's "house number" (MAC address) and can deliver messages correctly.</p>
<p>But what if Computer A (address 10.1.1.80) wants to talk to Computer X (address 234.23.1.45) in a completely different neighborhood? The switch doesn't know how to get there!</p>
<p>Without a router, messages would never find their way to other neighborhoods.</p>
<h2 id="heading-life-with-routers">Life With Routers</h2>
<p>With a router (usually at address 10.1.1.1 in your neighborhood), here's what happens:</p>
<ol>
<li><p>Computer A realizes Computer X is in a different neighborhood</p>
</li>
<li><p>Computer A needs to send its message to the router first, but doesn't know the router's MAC address</p>
</li>
<li><p>Computer A sends an ARP request: "Who has IP address 10.1.1.1?" (the router's address)</p>
</li>
<li><p>The router responds with its MAC address</p>
</li>
<li><p>Computer A can now send its message to the router's MAC address</p>
</li>
<li><p>The router examines the destination IP address (234.23.1.45)</p>
</li>
<li><p>The router forwards the message toward the right neighborhood</p>
</li>
<li><p>Eventually, the message reaches Computer X</p>
</li>
</ol>
<h3 id="heading-a-detailed-look-at-cross-network-communication">A Detailed Look at Cross-Network Communication</h3>
<p>Let's walk through exactly what happens when Computer A (IP: 10.1.1.80) in one network tries to communicate with Computer X (IP: 234.23.1.45) in another network:</p>
<ol>
<li><p><strong>Finding the Router</strong>: Computer A knows X isn't in its neighborhood, so it needs to contact the router (R) first</p>
<ul>
<li><p>A sends an ARP message through Switch S1 asking: "Who has IP 10.1.1.1?"</p>
</li>
<li><p>This ARP request is broadcast to all devices connected to S1</p>
</li>
<li><p>Router R recognizes its IP and responds with its MAC address</p>
</li>
<li><p>Switch S1 delivers this response to A</p>
</li>
</ul>
</li>
<li><p><strong>Sending to the Router</strong>: Computer A now prepares the actual message</p>
<ul>
<li><p>The message has two address layers:</p>
<ul>
<li><p>Layer 2 (MAC) addresses: From A's MAC to Router's MAC</p>
</li>
<li><p>Layer 3 (IP) addresses: From A's IP (10.1.1.80) to X's IP (234.23.1.45)</p>
</li>
</ul>
</li>
<li><p>This message goes through S1 to reach Router R</p>
</li>
</ul>
</li>
<li><p><strong>Router Processing</strong>: When Router R receives the message</p>
<ul>
<li><p>It removes the Layer 2 wrapper (like taking a letter out of its first envelope)</p>
</li>
<li><p>It looks at the Layer 3 address to determine where to send it</p>
</li>
<li><p>It needs to create a new Layer 2 wrapper for the next part of the journey</p>
</li>
</ul>
</li>
<li><p><strong>Finding the Destination</strong>: Router R needs to find Computer X</p>
<ul>
<li><p>R sends its own ARP request to Switch S2: "Who has IP 234.23.1.45?"</p>
</li>
<li><p>S2 broadcasts this to all computers in the second neighborhood</p>
</li>
<li><p>Computer X responds: "That's me! Here's my MAC address"</p>
</li>
<li><p>This response travels back through S2 to Router R</p>
</li>
</ul>
</li>
<li><p><strong>Final Delivery</strong>: Router R now forwards the message</p>
<ul>
<li><p>It creates a new Layer 2 wrapper: From Router's MAC to X's MAC</p>
</li>
<li><p>It keeps the original Layer 3 addresses unchanged</p>
</li>
<li><p>The message travels through S2 to finally reach Computer X</p>
</li>
</ul>
</li>
</ol>
<p>This journey shows why both switches and routers are essential: switches handle delivery within a neighborhood using MAC addresses, while routers connect different neighborhoods and handle the transition between them.</p>
<h2 id="heading-layer-3-the-routers-territory">Layer 3: The Router's Territory</h2>
<p>Routers work at "Layer 3" or the "Network Layer." This layer deals with IP addresses and finding paths between different networks.</p>
<p>If Layer 2 is about knowing house numbers on a street, Layer 3 is about knowing how to navigate between different streets and towns using maps.</p>
<p>In an upcoming article, we'll explore all seven layers of the "OSI Model" - the complete framework that organizes all aspects of computer networking from physical cables to the applications you use daily.</p>
<h2 id="heading-a-sneak-peek-at-dns">A Sneak Peek at DNS</h2>
<p>Just as you don't memorize your friends' phone numbers anymore (you just click their name in your contacts), computers use a system called DNS to avoid memorizing number addresses.</p>
<p>DNS (Domain Name System) is like a giant phone book:</p>
<ul>
<li><p>It translates friendly names like "<a target="_blank" href="http://google.com">google.com</a>" into computer addresses like "142.250.190.78"</p>
</li>
<li><p>When you type a website name, your computer first asks DNS, "What's the address for this name?"</p>
</li>
<li><p>Once it knows the address, routers can deliver your message to the right place</p>
</li>
</ul>
<p>This makes the internet much easier for humans to use - just imagine if you had to type number addresses for every website you visit!</p>
]]></content:encoded></item><item><title><![CDATA[Managing Packages and processes in Linux - Day 2]]></title><description><![CDATA[At this point, we have learnt about a lot of things including how to manage users, groups and also we saw a lot of commands that are present in Linux. But what happens when we want to download something in Linux. Let’s start our discussion with that
...]]></description><link>https://tech.roydevelops.tech/managing-packages-and-processes-in-linux-day-2</link><guid isPermaLink="true">https://tech.roydevelops.tech/managing-packages-and-processes-in-linux-day-2</guid><category><![CDATA[Linux]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Ubuntu]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Tue, 29 Apr 2025 16:18:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1745943462194/1736cf13-bb98-4063-8ab0-452d891dd1ac.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>At this point, we have learnt about a lot of things including how to manage users, groups and also we saw a lot of commands that are present in Linux. But what happens when we want to download something in Linux. Let’s start our discussion with that</p>
<h1 id="heading-package-managers">Package Managers</h1>
<p>As we all know package managers are programs that help you to manage packages. In linux, to download and use programs, there are primary 2 kind of package managers. One being <code>dpkg</code> and the other being <code>apt</code>. I’ll not waste your time and I’ll just give you a quick overview of these and also write out some important things about these 2</p>
<h2 id="heading-dpkg">dpkg</h2>
<p>This is the low level package manager that helps install packages after you download a .deb or .rpm file in your linux distro. Based on your distro you’ll download either .deb or .rpm.</p>
<p>This package manager is pretty dumb. Let’s say you download a .deb file but there are dependencies in that package, then you’ll have to manually download those dependencies at first and then you can download your application</p>
<p>So, most of the times, we tend to use the other package manager</p>
<h2 id="heading-apt">apt</h2>
<p>This is a high level package manager in your linux distro which is not dumb as <code>dpkg</code>. The main problem in <code>dpkg</code> was that you had to manually install the dependencies. But the case of <code>apt</code> is different. If your package has dependencies, it will automatically download it for you thus saving you a lot of time</p>
<p>Installing a package is very simple in this. Just type:</p>
<pre><code class="lang-bash">sudo apt install &lt;package-name&gt;
</code></pre>
<p>To see your installed packages, you can use this command:</p>
<pre><code class="lang-bash">sudo apt list --installed
</code></pre>
<p>To remove a command, you can use these commands</p>
<pre><code class="lang-bash">sudo apt remove &lt;packagename&gt; <span class="hljs-comment"># doesn't erase user data and removes application</span>

sudo apt remove &lt;packagename&gt; <span class="hljs-comment"># removes the applicatio and also user data</span>
</code></pre>
<h3 id="heading-updating-and-upgrading">Updating and Upgrading</h3>
<p>The apt comes with utility commands for both updating and upgrading commands. The two commands being:</p>
<pre><code class="lang-bash">sudo apt update
sudo apt upgrade
</code></pre>
<p>The <code>sudo apt update</code> command fetches the latest information about available packages from the configured repositories. It essentially tells your system to check for any new or updated software packages that are available for installation or upgrade.</p>
<p>After running <code>sudo apt update</code>, the <code>sudo apt upgrade</code> command downloads and installs the newest versions of the software packages that are already installed on your system. It will only upgrade packages that have newer versions available.</p>
<p>You should use both commands together to ensure that your system is running the latest software and security patches. Running <code>sudo apt update</code> first is crucial because it provides the package manager with the latest information about available updates. Without it, <code>sudo apt upgrade</code> wouldn't be aware of the newest versions and might not install them</p>
<h3 id="heading-snap">snap</h3>
<p>Snap is another package manager which are used to download standalone applications which don’t normally interact with other processes. The applications installed using snap are installed in form of containers i.e they are installed in isolated environments with dependencies packaged at once</p>
<p>Normally it is used to download applications e.g <code>vscode</code></p>
<p>Snap is being managed by a <strong>daemon</strong> named snapd. If you don’t have snap installed you can easily install it using:</p>
<pre><code class="lang-bash">sudo apt install snapd
</code></pre>
<h1 id="heading-processes-in-linux">Processes in Linux</h1>
<p>To give you a simple overview processes are instances of running program. To see the processes running in your system, you can use this command</p>
<pre><code class="lang-bash">ps aux
</code></pre>
<p>Also you can use this command to see processes with realtime usage of CPU, MEMORY:</p>
<pre><code class="lang-bash">top <span class="hljs-comment"># or</span>
htop
</code></pre>
<p>You’ll be able to see all the processes that are currently running in your system</p>
<p>If you have vscode installed in your Linux system, do this experiment:</p>
<ul>
<li><p>Open vscode once and then run this:</p>
<pre><code class="lang-bash">  ps aux | grep code
</code></pre>
</li>
<li><p>Close it and again run the same command</p>
</li>
</ul>
<p>You’ll be able to understand that this returns the currently active processes. The <code>grep</code> part helps to sort out the processed based on the search term you provide</p>
<p>The processes that we open by ourself are known as interactive processes i.e we have to open then only the processes open</p>
<p>When you ran <code>ps aux</code> command, you were able to see a long list of processes. But you didn’t start them right? You will not be able to recognize most of those commands. So who started it?</p>
<h2 id="heading-daemons">Daemons</h2>
<p>Well, those are system processes that start when your pc boots up. Those are known as <strong>daemons</strong>. Basically daemons are background processes that we don’t start, it starts at boot time automatically</p>
<p>These are also referred to as systemd units</p>
<h2 id="heading-systemd">Systemd</h2>
<p>I did talk about what systemd on day 0. But here’s are some points that will give you the idea of what systemd is:</p>
<ul>
<li><p>The master daemon which looks after all the daemons</p>
</li>
<li><p>This is also known as the service manager or the process manager</p>
</li>
<li><p>The init system that I talked about in day 0</p>
</li>
<li><p>Responsible for mounting fs, starting all services</p>
</li>
</ul>
<p>Basically this is the 1st process after the boot cycle in your pc. To see a tree of processes that have ran when your system completed the boot lifecycle, you can use the command:</p>
<pre><code class="lang-bash">pstree
</code></pre>
<p>You’ll be able to see that the 1st and the topmost process of the tree is systemd</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">In previous times, SysVInit, upstart, openrc were being used but now systemd is being widely used and accepted as the 1st init program</div>
</div>

<h2 id="heading-systemctl">systemctl</h2>
<p>This is the systemd utility that helps us to control all our daemons. With the systemctl command, you can start messing up with your background processes. Here are some commands that you can refer to get started:</p>
<pre><code class="lang-bash">sudo systemctl start &lt;service&gt;
sudo systemctl stop &lt;service&gt;
sudo systemctl restart &lt;service&gt;
</code></pre>
<p>To control weather a service will start at the system start or not, you can use the <code>enable</code> or <code>disable</code> command of systemctl:</p>
<pre><code class="lang-bash">sudo systemctl <span class="hljs-built_in">enable</span> &lt;service&gt; <span class="hljs-comment"># Enables a service at system reboot. Basically tells the pc that the service should start automatically when the pc boots up</span>
sudo systemctl <span class="hljs-built_in">disable</span> &lt;service&gt; <span class="hljs-comment"># self explanatory</span>
</code></pre>
<h2 id="heading-see-list-of-active-daemons">See list of active daemons</h2>
<p>To check the list of active daemons, you can use this command:</p>
<pre><code class="lang-bash">sudo systemctl list-units
</code></pre>
<p>Here, you'll be able to see all kinds of processes including .devices, .services. To see only of type services:</p>
<pre><code class="lang-bash">sudo systemctl list-units -t service
</code></pre>
<p>Now you are well versed about how to inspect, check which processes are running. But what happens when you want to kill a running process?</p>
<h2 id="heading-kill">kill</h2>
<p>The <code>kill</code> command is used to kill a running process in linux. But to kill a process, you need to have a process id. But let me tell you one more command:</p>
<pre><code class="lang-bash">ps -u &lt;username&gt;
</code></pre>
<p>This command will list out all the processes which is running for a particular <strong>user</strong></p>
<p>Now, let’s say you want to kill a process named “abc”. For that, you can use either of these 2 commands:</p>
<pre><code class="lang-bash">ps -u &lt;userName&gt; | grep &lt;abc&gt; <span class="hljs-comment"># or</span>
pgrep &lt;abc&gt; <span class="hljs-comment"># only returns processid</span>
</code></pre>
<p>Now once you have the process id, it is simple to kill a process with one command i.e:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">kill</span> &lt;processId&gt;
</code></pre>
<h1 id="heading-conclusion">Conclusion</h1>
<p>So, that it for today, I hope I was able to add some value to your life. Also with this article, hopefully we are done with linux as of now. Make sure to explore linux more and also a like and comment would really help me keep myself motivated in continuing this series. Thanks and see ya</p>
]]></content:encoded></item><item><title><![CDATA[The Linux Filesystem, Users and Groups - Day 2]]></title><description><![CDATA[Why again?
I know, that on day 0 of this series I wrote a section in my article which was regarding the Linux File system. Then why again? Well, that was for basic understanding of the Linux filesystem. This will be kind of a deep-dive to the Linux f...]]></description><link>https://tech.roydevelops.tech/the-linux-filesystem-users-and-groups-day-2</link><guid isPermaLink="true">https://tech.roydevelops.tech/the-linux-filesystem-users-and-groups-day-2</guid><category><![CDATA[Linux]]></category><category><![CDATA[Ubuntu]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Mon, 28 Apr 2025 06:30:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1745784042430/481679ae-6df7-40dc-b518-a8fb7d61fa09.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-why-again">Why again?</h1>
<p>I know, that on <a target="_blank" href="https://snehenduroy.hashnode.dev/basic-theory-of-linux-day-0">day 0</a> of this series I wrote a <a target="_blank" href="https://snehenduroy.hashnode.dev/basic-theory-of-linux-day-0#heading-linux-filesystems">section in my article</a> which was regarding the Linux File system. Then why again? Well, that was for basic understanding of the Linux filesystem. This will be kind of a deep-dive to the Linux filesystem where you’ll get to know where which thing is present. We will dive into the folders of linux where your configurations are present and have a look at them. So, let’s start:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745760070829/931ac24e-f3dd-48d8-b659-a4d5ef636190.webp" alt class="image--center mx-auto" /></p>
<h2 id="heading-lets-start">Let’s start</h2>
<p>When you open your terminal, to see where your terminal is open type <code>pwd</code></p>
<p>Normally you’ll be in the <code>/home/&lt;yourusername&gt;</code> directory. The <code>cd</code> command will help you to change directory right? If you type <code>cd ..</code> it changes the directory to the previous directory. Let’s keep doing it till we reach the parent directory</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> .. <span class="hljs-comment"># changes to /home/</span>
<span class="hljs-built_in">cd</span> .. <span class="hljs-comment"># now you are in /</span>
<span class="hljs-built_in">cd</span> .. <span class="hljs-comment"># doesn't have any effect as you are in the topmost root directory</span>
</code></pre>
<p>Now that we are in the root directory, if you do an <code>ls</code> you’ll be able to see a bunch of files</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745761354134/c0c79860-3c20-44d2-8db1-9787a5047f01.png" alt class="image--center mx-auto" /></p>
<p>We all know that in Linux based systems, everything is treated like a file. The commands that you type, the devices, network…. everything is treated like a file. So, where does these file lie?</p>
<p>When you do <code>ls</code> inside the <code>/</code> directory, you’ll be able to see a few directories. Some of them go by the names <code>bin</code>, <code>sbin</code>, <code>tmp</code>, <code>dev</code>, <code>usr</code>. These contain the important files that are needed to run your Linux kernel.</p>
<h1 id="heading-bin-and-sbin">bin and sbin</h1>
<p>If you do <code>ls bin</code> you’ll be able to see all the list of commands that you use including the one you used rn i.e <code>ls</code>.</p>
<p>Also, there is a dir named <code>sbin</code>. It is a shorthand notation for super <code>bin</code>. It contains commands that administrators can use. One of them is <code>adduser</code>. Here’s a small assignment: Read the manual of the <code>adduser</code> command it will help you to flex your knowledge in front of your friends</p>
<p>Now, let’s jump to the <code>/usr/</code> dir</p>
<h1 id="heading-usr">usr</h1>
<p>Let’s cd to the user dir and see what’s present there by executing <code>ls</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745762918187/4d5fdc9c-29e2-43a5-9bd9-252d5d67ab6f.png" alt class="image--center mx-auto" /></p>
<p>Hmm… There is a <code>bin</code> and <code>sbin</code> there also. If you <code>cd</code> into them and do an <code>ls</code>, you’ll be able to see some new files along with some same files like <code>ls</code> in <code>bin</code> and <code>adduser</code> in <code>sbin</code>. So which one is the real one?</p>
<p>Well, tbh both are real but why are the duplicates present?</p>
<p>Basically <code>/bin</code> holds essential binaries needed for booting and system recovery, while <code>/usr/bin</code> contains regular user applications. Originally, <code>/usr</code> could be on a separate partition, so <code>/bin</code> had to remain available even if <code>/usr</code> wasn't mounted yet</p>
<h1 id="heading-quick-review-of-other-directories-in-the-dir">Quick review of other directories in the <code>/</code> dir</h1>
<ul>
<li><p><code>boot</code> contains the files essential for booting</p>
</li>
<li><p><code>var</code> contains the log files and essential web application files</p>
</li>
<li><p><code>dev</code> contains files about devices</p>
</li>
<li><p><code>lib</code> contains the essential shared utility files</p>
</li>
</ul>
<h1 id="heading-users-in-linux">Users in Linux</h1>
<p>In Linux, when you login, you login as a user right? A user that you created while installing your OS. You can add new users and also check the name of the current user.</p>
<h2 id="heading-who-are-you">Who are you?</h2>
<p>The terminal that you are using has an associated user account with it. To know about the user of the current login session, you can type <code>whoami</code>. It will show you the username of the current terminal session</p>
<h2 id="heading-adding-new-user">Adding new user</h2>
<p>To add new user, use the <code>adduser</code> command. But remember, it is not a normal command so make sure to use <code>sudo</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745763994325/e4a1a72b-1688-44f4-9bd6-872db133b4fe.png" alt class="image--center mx-auto" /></p>
<p>But everything is treated like a file right? So where are the users? To answer your question let’s jump to the home dir</p>
<h2 id="heading-the-home-dir">The home dir</h2>
<p>Navigate to the <code>/</code> dir first. Now, type <code>ls home</code>. There you’ll be able to see the name of users that you added earlier. It is the home where every user of your Linux system lives</p>
<h2 id="heading-where-is-root">Where is root?</h2>
<p>Now, the administrators will not be normal users right? So, where do they live?</p>
<p>Well, they have a different home and the place where they reside is the <code>/root</code> directory. So, when you login into your Linux system normally through your gui, you login as a user. For getting root access to the terminal type <code>sudo su root</code>. And you’ll be able to see that the <code>$</code> change to <code>#</code>. Which means now you are the root user i.e the administrator or you can call yourself the god of your Linux OS</p>
<h2 id="heading-better-way-to-check-users">Better way to check users</h2>
<p>One way to look at users you created is by navigating to the <code>home</code> dir and listing the directories. But there is a better way to look at how many users are being created and are present in your machine. That’s what this command does</p>
<pre><code class="lang-bash">cat /etc/passwd
</code></pre>
<p>This file consists the list of all the users those are present in your system. You’ll be able to recognize the last one as it is the user that you just created.</p>
<p>If you check clearly, the last user will be like this:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">test</span>:x:1001:1001:Test,,,:/home/<span class="hljs-built_in">test</span>:/bin/bash
</code></pre>
<h3 id="heading-can-i-access-passwords">Can I access passwords</h3>
<p>The passwords of the user are present in a different file which is in <code>/etc/shadow</code>. But to access that you’ll need sudo permissions so make sure that you use the sudo command</p>
<pre><code class="lang-bash">sudo cat /etc/shadow
</code></pre>
<p>On typing this you will get the passwords of all the users in your system, the last one for me is this:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">test</span>:<span class="hljs-variable">$y</span><span class="hljs-variable">$j9T</span><span class="hljs-variable">$A</span>/LaMJOSt9gwnFARUecio0$/YjAeHOxHXmkUvbK5cBRHA0OZvJ0KxPtSq0uUUt4ve3:20205:0:99999:7:::
</code></pre>
<p>This is not the password I entered, this is the hashed version of it. So yes, you can definitely access the passwords but you can only access the hashed passwords</p>
<h2 id="heading-lets-get-back-to-the-user">Let’s get back to the user</h2>
<p>I am typing out how the user looked when I ran <code>cat /etc/passwd</code> again:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">test</span>:x:1001:1001:Test,,,:/home/<span class="hljs-built_in">test</span>:/bin/bash
</code></pre>
<p>Let’s decode the components present here</p>
<ul>
<li><p>The first word <code>test</code> is its username</p>
</li>
<li><p><code>x</code> represents the password</p>
</li>
<li><p>Then comes the user id(UID) i.e <code>1001</code></p>
</li>
<li><p>Then is the group id i.e <code>1001</code></p>
</li>
<li><p>Then the name</p>
</li>
<li><p>Then the commas which were meant to be the extra set of metadata which we didn’t provide for which it doesn’t hold any value</p>
</li>
<li><p>Then is the home directory where our user lives i.e <code>/home/test</code></p>
</li>
<li><p>Then the path of the shell that our user will use i.e <code>/bin/bash</code></p>
</li>
</ul>
<p>So the format is</p>
<pre><code class="lang-bash">username:x:UID:groupId:Name,data1,data2,data3,data4:homeDir:shellDir
</code></pre>
<p>But why user Id and group Id? You’ll get there soon but as of now let’s just keep this in mind that when you add a user using the <code>adduser</code> command, a group is being created and then a user inside that group is being created. In our case, the group test is being created and then the user test is being created.</p>
<h2 id="heading-useradd">useradd</h2>
<p>There is a difference between the <code>adduser</code> and <code>useradd</code> command. The adduser command does a lot of work by asking you information about the user like the password and other metadata. It also creates a group</p>
<p>But the <code>useradd</code> is just like you and me. It’s lazy. So let’s see what it does:</p>
<pre><code class="lang-bash">sudo adduser test1
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745777768204/3bb90a59-794e-446f-85fc-8602399c34ec.png" alt class="image--center mx-auto" /></p>
<p>As you can see, the <code>useradd</code> command didn’t ask for any password or anything it just created it automatically. But wait, is it added to the users list? Let’s see the file where user info is present. So, type in <code>cat /etc/passwd</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745777943574/f629bca0-dd47-451b-a4b9-a4654d404a22.png" alt class="image--center mx-auto" /></p>
<p>Well, I definitely see test1 but there are a few things which are different:</p>
<ul>
<li><p>The name and additional data is not present</p>
</li>
<li><p>The shell is <code>/bin/sh</code> and not <code>bash</code></p>
</li>
</ul>
<p>That’s why it is called lazy. It comes in handy when you want to add multiple users so that you don’t have to spend time configuring them</p>
<p>We didn’t give it a password right? Let’s check the <code>/etc/shadow</code> file and see if it is present using the command <code>sudo cat /etc/shadow</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745778298888/e5b91d92-a311-4ebc-9d08-b15a4f65f610.png" alt class="image--center mx-auto" /></p>
<p>Well, we definitely see an entry for our user but we don’t see a password. Okay let’s fix it by giving test1 a password</p>
<h2 id="heading-passwd">passwd</h2>
<p>To set the password for our user test1, we’ll use the <code>passwd</code> command and obv we’ll have to use sudo because this is a sensitive command which requires administrator previllages</p>
<pre><code class="lang-bash">sudo passwd test1
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745778532261/4dc0f9fc-0114-4fdb-b270-b85e750d2fa6.png" alt class="image--center mx-auto" /></p>
<p>Now, let’s check the <code>/etc/shadow</code> file:</p>
<pre><code class="lang-bash">sudo cat /etc/shadow
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745778580278/35a37125-cf57-4aa9-aa6f-dff231ed787c.png" alt class="image--center mx-auto" /></p>
<p>There we go, we see something. But the shell assigned to test1 is <code>sh</code> and not the <code>bash</code> shell. Let’s fix that</p>
<h2 id="heading-usermod">usermod</h2>
<p>To modify a created user, we use the <code>usermod</code> command. To know about the <code>usermod</code> command, type out <code>usermod -h</code>. There you’ll be able to see the option <code>-s</code> to modify the shell.</p>
<p>To modify the shell, just type out</p>
<pre><code class="lang-bash">sudo usermod test1 -s /bin/bash
</code></pre>
<p>Now, if we check the <code>/etc/passwd</code> file to see the configs, you’ll be able to see that the shell has been updated</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745779037840/af1aa5db-f670-430c-9d10-0660a7ec24ab.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-su-command">su command</h2>
<p>Now to change the user in your running terminal session, you will have to use the <code>su</code> command. It basically means <strong>switch user</strong>.</p>
<pre><code class="lang-bash">sudo su test1
</code></pre>
<p>If you don’t type <code>test1</code> then you’ll be logged in as the root user which is not a good idea anyways cuz if you mess something up as the root user, it will be bad for your system</p>
<p>Well, now we are logged in as the user <strong>test1</strong>. Let’s check the passwords file once again:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745779510535/3537b670-3a8b-4618-99a0-f2ecb781ef4f.png" alt class="image--center mx-auto" /></p>
<p>Well, we get an error. It says that test1 is not in the sudoers file. What is that? Let’s explore</p>
<h2 id="heading-the-sudoers-file">The sudoers file</h2>
<p>The <code>sudoers</code> file is a very very important file in your Linux filesystem that you don’t want to mess up by any means because if you do so, your whole linux system can get messed up. So, there are multiple text editos available to view and edit the sudoers file including vim, nano. But the safest way is to use visudo. So let’s exit as test1 and get back as the normal user and check the file</p>
<pre><code class="lang-bash">sudo visudo
</code></pre>
<p>You might want to scroll down a little till you see this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745779887455/282de75d-7848-4c20-8be5-c25a8944bca2.png" alt class="image--center mx-auto" /></p>
<p>Under the user previllage specification, you can see which users have the sudo access and then you can see the syntax for which group has the sudo access. Let’e quickly get through the syntax for a single user for now and experiment with it for a bit:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># to give test1 all sudo command previllage</span>
test1 ALL=ALL

<span class="hljs-comment"># to give access to only one command previllage you can use the path of that command in the sbin dir</span>
test1 ALL = /sbin/adduser <span class="hljs-comment"># only gives access to the adduser command</span>
</code></pre>
<p>For now, I’ll give test1 all previllage. So once I write <code>test1 ALL=ALL</code>, I’ll press <code>Ctrl+S</code> to save and <code>Ctrl+X</code> to exit.</p>
<p>Now let’s switch the user to test1 and chek if we can execute the sudo command or not</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745780520839/f13e5854-65ca-407b-9921-09d1ce21bfca.png" alt class="image--center mx-auto" /></p>
<p>Well, yes we could add our user</p>
<h2 id="heading-userdel">userdel</h2>
<p>Now let’s delete our newly created user cuz we don’t need hello rn. To do that, let’s use the <code>userdel</code> command. You can again check the passwd file to check if the user has been added or not:</p>
<pre><code class="lang-bash">sudo userdel hello
</code></pre>
<p>Now, let’s exit out of that login session and login as the default user by typing <code>exit</code>. Now let’s explore groups.</p>
<h2 id="heading-groups">Groups</h2>
<p>As the name suggests, groups are simply sets of users who are combined into a single group. Let’s do some basic operations on groups</p>
<h2 id="heading-groupadd">groupadd</h2>
<p>To create a new group, we use the groupadd command. Let’s create a hello group</p>
<pre><code class="lang-bash">sudo groupadd hello
</code></pre>
<p>You can see all the groups in the <code>/etc/group</code> file. Just use this command and you’ll be able to see all the groups in your system</p>
<pre><code class="lang-bash">cat /etc/group
</code></pre>
<p>Here are my last 3 lines of that command:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745781075633/da4712cc-a4ff-4750-aea7-d5857de4f783.png" alt class="image--center mx-auto" /></p>
<p>Now let’s add a few users. For now, I’ll just add world1 and world2 and also give them a password. Now, let’s add them in the group</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745781732494/0a537efa-4156-49be-9730-a2212db0702e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-usermod-ag">usermod -aG</h2>
<p>To add users into a grop, we use the <code>usermod -aG &lt;groupname&gt; &lt;username&gt;</code> command. In our case, to add user world1 to our group, we’ll have to use this command</p>
<pre><code class="lang-bash">sudo usermod -aG hello world1
</code></pre>
<p>Similarly, add world2 also. Then, when you see the file <code>/etc/group</code> you’ll see this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745782020694/4b709578-38f4-4af4-beb1-39ead14bb237.png" alt class="image--center mx-auto" /></p>
<p>Thus world1 and world2 has been successfully added to this group</p>
<p>Since we didn’t update the sudoers file for world1 and world2, so it will naturally not have sudo access. You can check it</p>
<p>But instead of that, we are now going to give the group hello sudo access. So that world1 and world2 both have sudo access. Let’s openup the sudoers file using <code>sudo visudo</code> command and add this line on the groups section</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745782238095/ccec3ed3-5714-4aca-83ce-59435f83d760.png" alt class="image--center mx-auto" /></p>
<p>Basically when you type <code>%&lt;name&gt;</code> it specified the group name. Now you can easily execute sudo commands in that group. Check it yourself by switching the user.</p>
<p>Now, let’s try to remove the users from the group</p>
<h2 id="heading-gpasswd">gpasswd</h2>
<p>To remove the users from a group, we’ll have to use the <code>gpasswd</code> command. Yes, I know the name says something different, but we have no choice. Use this command to remove user <code>world1</code> from group <code>hello</code>.</p>
<pre><code class="lang-bash">sudo gpasswd -d world1 hello
</code></pre>
<p>Now, check if world1 still has sudo access or not, also try to remove world2 from the group</p>
<h2 id="heading-groupdel">groupdel</h2>
<p>For deleting a group, we can use the groupdel command. In our case to delete the group named hello, we’ll use:</p>
<pre><code class="lang-bash">sudo groupdel hello
</code></pre>
<h1 id="heading-summary">Summary</h1>
<p>Let me sum up everything so that you can only use this section to revise the commands quickly:</p>
<h2 id="heading-linux-filesystem-structure">Linux Filesystem Structure</h2>
<ul>
<li><p>The root directory <code>/</code> is the top-level directory containing essential system folders</p>
</li>
<li><p><code>/bin</code> and <code>/sbin</code> contain essential commands (binary executables)</p>
<ul>
<li><p><code>/bin</code> has regular user commands like <code>ls</code></p>
</li>
<li><p><code>/sbin</code> (super bin) contains administrator commands like <code>adduser</code></p>
</li>
</ul>
</li>
<li><p><code>/usr/bin</code> vs <code>/bin</code>: Both contain commands, but <code>/bin</code> has essentials needed for booting, while <code>/usr/bin</code> has regular applications</p>
</li>
<li><p>Other important directories:</p>
<ul>
<li><p><code>/boot</code>: Files essential for booting</p>
</li>
<li><p><code>/var</code>: Log files and web application files</p>
</li>
<li><p><code>/dev</code>: Device files</p>
</li>
<li><p><code>/lib</code>: Essential shared utility files</p>
</li>
<li><p><code>/home</code>: Where user directories are stored</p>
</li>
<li><p><code>/root</code>: Home directory for the root user (administrator)</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-user-management">User Management</h2>
<ul>
<li><p><code>whoami</code>: Shows current user of terminal session</p>
</li>
<li><p><code>adduser</code>: Creates a new user with full configuration prompts</p>
</li>
<li><p><code>useradd</code>: Creates a new user with minimal configuration (the "lazy" version)</p>
</li>
<li><p>User information is stored in:</p>
<ul>
<li><p><code>/etc/passwd</code>: Contains user details (username, UID, GID, home directory, shell)</p>
</li>
<li><p><code>/etc/shadow</code>: Contains hashed passwords (requires sudo access)</p>
</li>
</ul>
</li>
<li><p><code>passwd</code>: Command to set/change user passwords</p>
</li>
<li><p><code>usermod</code>: Modifies user settings (like changing shell with <code>-s</code> option)</p>
</li>
<li><p><code>su</code>: Switches between users in the terminal</p>
</li>
<li><p><code>userdel</code>: Deletes users</p>
</li>
</ul>
<h2 id="heading-group-management">Group Management</h2>
<ul>
<li><p>Groups allow organizing sets of users with similar permissions</p>
</li>
<li><p><code>groupadd</code>: Creates a new group</p>
</li>
<li><p>Group information is stored in <code>/etc/group</code></p>
</li>
<li><p><code>usermod -aG</code>: Adds users to a group</p>
</li>
<li><p><code>gpasswd -d</code>: Removes users from a group</p>
</li>
<li><p><code>groupdel</code>: Deletes a group</p>
</li>
</ul>
<h2 id="heading-sudo-access-management">Sudo Access Management</h2>
<ul>
<li><p>The <code>sudoers</code> file controls which users/groups have admin privileges</p>
</li>
<li><p>Best edited with <code>visudo</code> for safety</p>
</li>
<li><p>Individual users can be given sudo access with: <code>username ALL=ALL</code></p>
</li>
<li><p>Groups can be given sudo access with: <code>%groupname ALL=ALL</code></p>
</li>
<li><p>Access can be limited to specific commands</p>
</li>
</ul>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Now you know how to poke around the file system, add users when your computer gets lonely, and play permission games with sudo. Not too shabby for a day's work!</p>
<p>Just remember - when in doubt, there's always Google... or you could just try random commands until something works. That's the Linux way! (Kidding, please don't do that.)  </p>
<p>Thanks and see ya</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745765175871/9a0bd91c-9acb-4d54-b36b-e292f9eb9b00.webp" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Inspecting through Basic Commands in Linux - Day 1]]></title><description><![CDATA[Command Line Basics
Command Line Components
The commands that you type on your fancy linux terminal normally consists of 3 components:

Command: The name of the program that you want to execute

Options: As the name suggests, these are options that c...]]></description><link>https://tech.roydevelops.tech/inspecting-through-basic-commands-in-linux-day-1</link><guid isPermaLink="true">https://tech.roydevelops.tech/inspecting-through-basic-commands-in-linux-day-1</guid><category><![CDATA[Linux]]></category><category><![CDATA[terminal command]]></category><category><![CDATA[Ubuntu]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Sun, 27 Apr 2025 08:11:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1745741448466/348c2c02-a903-41ae-a05d-34ee9d089585.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-command-line-basics">Command Line Basics</h1>
<h2 id="heading-command-line-components">Command Line Components</h2>
<p>The commands that you type on your fancy linux terminal normally consists of 3 components:</p>
<ul>
<li><p>Command: The name of the program that you want to execute</p>
</li>
<li><p>Options: As the name suggests, these are options that can be passed to the command to perform variety of tasks</p>
</li>
<li><p>Arguments: These act as a critical metadata for the options that they are being passed to in the command</p>
</li>
</ul>
<p>There are plenty of commands that don’t have options, arguments or neither</p>
<h2 id="heading-sudo">sudo</h2>
<p>Sudo refers to superuser do. sudo commands give admin privileges to the user while runtime of the commands. In ubuntu sudo is setup during the installation time, in other distros you might need to put your laziness aside and configure it manually.</p>
<h2 id="heading-virtual-terminals">Virtual Terminals</h2>
<p>Now this is something cool that you can showoff. If you are like me and use an ubuntu system, you can simultaneously open another session that is different from what you are running here.</p>
<p>Virtual Terminals (VT) are basically console sessions that take up you complete screen and keyboard outside of a graphical environment. These are not the terminal that you start inside your gui after you start your ubuntu, you can have as many of them as possible</p>
<p>These are called virtual because, although there can be multiple active terminals, only one will be visible to you. Normally, one virtual terminal (either VT1 or VT7) is being reserved for the GUI of your linux based OS</p>
<p>To switch betwee VTs, you can press <code>Ctrl + Alt + Function</code> key. If you are in ubuntu like me, the place where you see this blog is in VT1. You can switch to another VT by <code>Crtl + Alt + F3</code> or F4 or F5…. To switch back, you’ll need to press <code>Ctrl + Alt + F1</code> or F2 again</p>
<p>Basically the function keys are assigned to the VTs, the number of the function key maps to the number of the VT that you’ll use</p>
<p>Now, you can showoff</p>
<h2 id="heading-turning-off-your-gui">Turning off your GUI</h2>
<p>There’s a fancy GUI developed by smart bros so that you can use your linux distros better. In new operating systems, the GUI can be easily turned off or on as it is treated as a service. In day 0, I wrote about how to turn off a service right? Yes, the <code>systemctl</code> command.</p>
<p>To turn on or off your GUI, you can use these simple set of commands</p>
<pre><code class="lang-bash"><span class="hljs-comment"># For turning off</span>
sudo systemctl stop gdm

<span class="hljs-comment"># For starting the gui</span>
sudo systemctl start gdm
</code></pre>
<h1 id="heading-basic-command-line-operations">Basic command line operations</h1>
<h3 id="heading-login">Login</h3>
<p>Use the <code>ssh</code> command to login to your system. e.g: <code>ssh hello@world</code></p>
<h3 id="heading-shutdown-and-restart">Shutdown and restart</h3>
<p>Use <code>shutdown -h now</code> to shut down your pc immidiately</p>
<p>Use <code>shutdown -r</code> to reboot</p>
<h3 id="heading-locating-applications">Locating Applications</h3>
<p>Based on your OS, programs and softwares can be present in multiple directories. In general, the binary and the executable scripts are present in <code>/bin</code>, <code>/usr/bin</code>, <code>/sbin</code>, <code>/usr/sbin</code> directories, or somewhere under <code>/opt</code>. They can also appear in <code>/usr/local/bin</code> and <code>/usr/local/sbin</code>, or in a directory in a user's account space, such as <code>/home/student/bin</code>.</p>
<p>To locate your programs, you can use the <code>whereis</code> command. If you have python3 installed in your linux distro, you can try writing <code>whereis python3</code></p>
<h3 id="heading-creating-and-accessing-directories">Creating and Accessing directories</h3>
<ul>
<li><p><code>pwd</code>: Displays your current directory</p>
</li>
<li><p><code>mkdir dirname</code>: Makes a new directory with name “dirname”</p>
</li>
<li><p><code>cd dirname</code>: Change your current directory to dirname</p>
<ul>
<li><code>cd</code> : Changes to your home directory</li>
</ul>
</li>
<li><p><code>cd ..</code>: Change to the parent directory</p>
</li>
<li><p><code>cd -</code>: Change to previous directory</p>
</li>
<li><p><code>ls</code>: Lists the contents of that directory</p>
</li>
</ul>
<h3 id="heading-hard-links">Hard links</h3>
<p>Hard links are like another name for an existing file. When you create a hard link, both the original file and the created hard link point to the same inode. If the original file is removed, the hard link still can access the data.</p>
<p>Let’s create a file name file1 and create a hard link for file 1 named file2</p>
<pre><code class="lang-bash"><span class="hljs-comment"># creates a file</span>
touch file1
<span class="hljs-comment"># creates a hard link</span>
ln file1 file2
</code></pre>
<p>Now, if you want to see the 2 files using the <code>ls -li</code> tag, you’ll be able to see the inode number of the file in the 1st column.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745699621099/96f59417-ec79-47ae-ac8b-27f761a45c44.png" alt class="image--center mx-auto" /></p>
<p>You can clearly see that the inode numeber is same for file1 and file2</p>
<h3 id="heading-soft-links">Soft links</h3>
<p>Unlike hard links, soft link is like a shortcut to an existing file. If the original file is removed, the soft link is broken as it points to nothing</p>
<p>To create a softlink, use <code>ln -s</code> command:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745700250322/713eca0c-5a02-4a73-accc-1d605952d9a5.png" alt class="image--center mx-auto" /></p>
<p>Now, after creating a soft link to file1 you can clearly see that the inode is different</p>
<h1 id="heading-working-with-files">Working with files</h1>
<h2 id="heading-viewing-files">Viewing files</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Command</strong></td><td><strong>Usage</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>cat</strong></td><td>Used for viewing files that are not very long; it does not provide any scroll-back.</td></tr>
<tr>
<td><strong>tac</strong></td><td>Used to look at a file backwards, starting with the last line.</td></tr>
<tr>
<td><strong>less</strong></td><td>Used to view larger files because it is a paging program. It pauses at each screen full of text, provides scroll-back capabilities, and lets you search and navigate within the file.</td></tr>
</tbody>
</table>
</div><p><strong><em>NOTE</em></strong>*: Use* <strong><em>/</em></strong> <em>to search for a pattern in the forward direction and</em> <strong><em>?</em></strong> <em>for a pattern in the backward direction. An older program named more is still used, but has fewer capabilities: "less is more".</em> | | <strong>tail</strong> | Used to print the last 10 lines of a file by default. You can change the number of lines by doing <strong>-n 15</strong> or just <strong>-15</strong> if you wanted to look at the last 15 lines instead of the default. | | <strong>head</strong> | The opposite of <strong>tail</strong>; by default, it prints the first 10 lines of a file. |</p>
<h2 id="heading-creating-files">Creating files</h2>
<p>Use the <code>touch &lt;filename1&gt; &lt;filename2&gt;</code> command to create multiple files in your current directory. To create directories, use the <code>mkdir</code> command</p>
<h2 id="heading-deleting-files-and-folders">Deleting files and folders</h2>
<p>To remove a particular file, use <code>rm &lt;filename&gt;</code> and to remove a folder use <code>rmdir &lt;dirname&gt;</code>. Now, if you want to remove a directory with embedded directories and files which are not empty, then you’ll have to use <code>rm -rf &lt;dirname&gt;</code> command</p>
<pre><code class="lang-bash"><span class="hljs-comment"># remove file</span>
rm file1

<span class="hljs-comment"># remove directory</span>
rmdir dir1

<span class="hljs-comment"># remove non empty directory with files and embeded directories</span>
rm -rf dir1
</code></pre>
<h2 id="heading-moving-renaming">Moving, renaming</h2>
<p>The <code>mv</code> command is used to rename a file. Fundamentally if you see, moving a file to another directory is same as renaming the file. Do it practically</p>
<pre><code class="lang-bash"><span class="hljs-comment"># create two folders test1 and test2</span>
mkdir test1 test2

<span class="hljs-comment"># cd to test1</span>
<span class="hljs-built_in">cd</span> test1
<span class="hljs-comment"># create a file name hello.txt</span>
touch hello.txt

<span class="hljs-comment"># cd to the root</span>
<span class="hljs-built_in">cd</span> ../
<span class="hljs-comment"># see the contents of test1</span>
ls test1/

<span class="hljs-comment"># now rename the file hello.txt to world.txt</span>
<span class="hljs-built_in">cd</span> test1
mv hello.txt world.txt
<span class="hljs-comment"># see the contents of test1 now</span>
ls

<span class="hljs-comment"># cd to the root dir</span>
<span class="hljs-built_in">cd</span> ../

<span class="hljs-comment"># see contents of test2</span>
ls test2/

<span class="hljs-comment"># now, we'll move the world.txt file to test2</span>
mv test1/world.txt test2/world.txt

<span class="hljs-comment"># now check the contents of test1 and test2</span>
ls test1
ls test2

<span class="hljs-comment"># rename the dirname test2 to test3</span>
mv test2/ test3/

<span class="hljs-comment"># check again</span>
ls test3
</code></pre>
<p>Through this practical exercise, you’ll yourself be able to understand about the <code>mv</code> command. Help yourself by not being lazy and try this</p>
<h1 id="heading-i-forgot-commands">I forgot commands!</h1>
<p>As you can see, there are multiple commands in linux. For file handling, for file searching, for copying files, removing files. There are a lot of commands and it is not possible to inspect through every one of them</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745739927993/736c50dc-0c90-4ecd-a000-e35754afed47.webp" alt class="image--center mx-auto" /></p>
<h2 id="heading-using-the-man-command">Using the man command</h2>
<p>Smart folks at linux got you covered. If you want to inspect the info about a command, you can use the <code>man</code> command. For example, if I want to know about a command named <code>adduser</code>, I can just type out <code>man adduser</code> and it will show me detailed manual of that command</p>
<p>Here’s what happens when I type <code>man adduser</code> in my terminal. Now, you can do that too, you can inspect through the document of any command and use your arrow keys to read about it</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745740512377/c11667ee-361e-4502-a6a6-370ae2b1b07b.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-using-the-apropos-command">Using the apropos command</h2>
<p>But you might think, what happens when we don’t know a command and want to search for it. Let’s say you want to search about which command will help you compress your file. What will your do then?</p>
<p>Well well, just use the <code>apropos</code> command. In our case, to search commands about compression, we’ll just have to type out <code>apropos compress</code>. Yes, it’s that simple</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745740800774/45e6029d-56bb-4092-9725-e92672bff2b2.png" alt class="image--center mx-auto" /></p>
<p>You will get the list of all commands which have the word “compress” in their manual</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>So, today let’s leave it here itself. Try out some commands in linux and make sure you don’t forget the <code>man</code> and <code>apropos</code> command as it will act as your in your journey to explore linux. We’ll dive deeper into the linux filesystem in the next article, till then keep learning and thanks</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745741129496/4863c526-a11b-487d-b1a5-192274e85ba6.webp" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Basic Theory of Linux - Day 0]]></title><description><![CDATA[Everyone knows what linux is: An open source operating system kernel which has been widely accepted in the entire world to create, deploy computer programs. So, I’ll rather not waste your time on a fancy definition of linux. For now, the definition t...]]></description><link>https://tech.roydevelops.tech/basic-theory-of-linux-day-0</link><guid isPermaLink="true">https://tech.roydevelops.tech/basic-theory-of-linux-day-0</guid><category><![CDATA[Linux]]></category><category><![CDATA[Ubuntu]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Sat, 26 Apr 2025 10:56:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1745664905210/60acfef0-37ff-4993-8916-1f1ed18da72b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Everyone knows what linux is: An open source operating system kernel which has been widely accepted in the entire world to create, deploy computer programs. So, I’ll rather not waste your time on a fancy definition of <strong>linux</strong>. For now, the definition that <strong>Linux is an opensource operating system kernel</strong> works fine</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Kernel: Kernel is the core part of an operating system that acts as a bridge b/w the hardware and software</div>
</div>

<h1 id="heading-linux-philosophy">Linux Philosophy</h1>
<p>Linux was inspired heavily by UNIX. At that time when linux was built, UNIX was not for rookies like you and me. It was built for computers which were much more powerful than ours PCs and were very expensive (IDK about you but I am broke af so I couldn’t buy it)</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">UNIX: Yet another OS built by Bell Labs at that time for powerful works like multitasking and other kind of cool shit</div>
</div>

<p>Linux stores files in a hierarchical file system with the top node being <strong>/root</strong> or <strong>/.</strong> In linux, everything including devices, processes, network sockets are treated like a file. Files are not just .txt or .pdf, everything acts as a file (but are not actual files)</p>
<h3 id="heading-why">Why?</h3>
<p>Cuz it makes life easier</p>
<h3 id="heading-how">How?</h3>
<ul>
<li><p>Let’s say you want to read something from your keyboard. It’s easy to read it directly from a file named <strong>/dev/keyboard</strong></p>
</li>
<li><p>Let’s say you want to send something to your printer. It’s easy to write something to a file named <strong>/dev/printer</strong></p>
</li>
</ul>
<p>So, you see reading data and writing data in files is very simple. That’s why everything is treated like a file. If you have a linux distro like ubuntu, arch or anything, just open your terminal and type <code>cat /proc/cpuinfo</code>. You’ll be able to see information about your cpu in it</p>
<p>So everything is treated like a file as doing operations like read, write, rename, copy and others are easy in a file that’s why smart bros at linux adopted this philosoply</p>
<h1 id="heading-fancy-terminologies">Fancy Terminologies</h1>
<p>These are some terms you should know about Linux that will impress your non-tech friends (or techie friends with low knowledge bandwidth)</p>
<ul>
<li><p>Kernel: I gave a definition previously which is an oddly simple definition</p>
</li>
<li><p>Boot loader: As the name suggests, it is the program that boots up the operating system</p>
</li>
<li><p>Services: Programs that run as background processes</p>
</li>
<li><p>fs (filesystem): The way by which files are organized and managed. e.g: ntfs, ext3, FAT</p>
</li>
<li><p>X window system: The X window system provides the standard toolkit and protocol for building gui on nearly all linux systems</p>
</li>
<li><p>Desktop Environment: The GUI built on top of operating system</p>
</li>
<li><p>Command Line Interface (CLI): The interface used for typing commands</p>
</li>
<li><p>Shell: The CLI that interprets the command line input and instructs OS to perform necessary tasks based on the user input</p>
</li>
<li><p>Distributions: A full Linux distribution consists of the kernel plus a number of other software tools for file-related operations, user management, and software package management.</p>
</li>
</ul>
<h1 id="heading-the-boot-process">The Boot Process</h1>
<p>The boot process is the process by which your system gets initialized. It consists of different processes from powering on your computer to the user interface that you see</p>
<p>But why is it important? It might help you troubleshoot your problems while using your linux based OS</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745656015857/41414582-6fcd-4974-be21-4a004374187f.png" alt class="image--center mx-auto" /></p>
<p>This is the diagram of the internal processes which helps to see your GUI after you power on your pc. Now, I’ll try to explain each part of it</p>
<h2 id="heading-power-on-the-step-0">Power On - The Step 0</h2>
<p>You already know it</p>
<h2 id="heading-bios">BIOS</h2>
<p>When the computer is powered on, the <strong>Basic Input/Output System (BIOS)</strong> initializes all the hardware components including screen, keyboard in your pc and tests the main memory. This process is called Power on Self Test (POST)</p>
<p>The BIOS software is then stored on your ROM chip in the motherboard. Then the remaining of the boot process is handled by your OS</p>
<h2 id="heading-boot-loader-mbr-efi">Boot Loader, MBR, EFI</h2>
<p>Well, in the diagram MBR and EFI was before boot loader but its better to study all these together cuz it will ultimately get interliked</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">CMOS (Complementary Metal-Oxide-Semiconductor): A battery powered memory on motherboard that stores basic settings like date, time and different hardware configs</div>
</div>

<p>After The POST process, the system control is passed to the boot loader. The boot loader is stored on the persistent storage like your slow HDD or fast SSD in either the boot sector (for MBR partition systems) or the EFI partition sector. Then the information on date, time and other settings are being loaded from the CMOS.</p>
<h3 id="heading-stages">Stages</h3>
<p>The boot loader has 2 distinct stages:</p>
<p>In BIOS/MBR systems, the boot loader is stored in the first 512 bytes of the hard drive, called the Master Boot Record (MBR). It checks the partition table, finds a bootable partition, and loads a second-stage boot loader like GRUB into RAM.</p>
<p>In UEFI systems, the UEFI firmware reads its Boot Manager to find and launch a UEFI application like GRUB from the EFI partition. This process is a bit more complex but more flexible than MBR.</p>
<p>The second-stage boot loader (stored in <code>/boot</code>) shows a menu to pick an operating system or kernel. Once selected, it loads the kernel into RAM</p>
<h3 id="heading-2-lines-to-summarize-boot-loader">2 lines to summarize boot loader</h3>
<p>The boot loader is responsible for loading the kernal into the RAM so that the computer system can start</p>
<p>It loads the kernel into RAM because RAM is much faster than storage devices, and the CPU can only run programs directly from RAM, not from the hard drive or SSD</p>
<h2 id="heading-initial-ram-disk">Initial Ram Disk</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745660696431/ff0f7bb5-2597-43a7-a277-d81fec8d51b8.png" alt class="image--center mx-auto" /></p>
<p>The <strong>initramfs</strong> is the filesystem image that consists of programs and binary files that contains instructions about mounting proper root fs, kernel functionality, locating devices and driver and then load them. Then it checks for errors in the root filesystem</p>
<p>After the <strong>mount</strong> program instructs the OS that the filesystem is error free and ready to use, the initialization program (<code>sbin/init</code>) is run after the initramfs gets cleared from the RAM.</p>
<h2 id="heading-command-shell-using-getty">Command Shell Using getty</h2>
<p>After the init command is executed, the terminal loads up for you to login to your linux OS.</p>
<p><strong>getty</strong> is the program that opens the terminal, displays the login prompt, and then hands over control to the login process once you enter your username.</p>
<h1 id="heading-kernel-init-and-services">Kernel, init and Services</h1>
<h2 id="heading-the-linux-kernel">The Linux Kernel</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745662012970/62dcf3d1-997f-4cf5-b4d3-8560fff3ddca.png" alt class="image--center mx-auto" /></p>
<p>The boot loader initializes the kernel and the initial RAM file system (initramfs). After the kernel instructions are loaded to the RAM, it immediately initializes and configures the computer memory and all the hardware attached to the PC</p>
<h2 id="heading-sbininit-and-services">/sbin/init and Services</h2>
<p>After the kernel sets up the necessary hardware components and mounts the file system, the init process is executed. It is the initial process that gets other systems running. Besides starting the system, the <strong>init</strong> process is also responsible for starting the PC and shutting it down correctly.</p>
<h2 id="heading-startup-services">Startup Services</h2>
<p>When your system starts, there are scripts that are responsible to start your system. <strong>Old Linux boot systems (SysVinit)</strong> started things one by one, slowly and step-by-step, which didn’t use modern multi-core processors well.</p>
<p>Back in those days, boot time was not considered as a very vital thing, but then it become a major deciding factor among users. No one wanted a slow ass system which would take long time to boot. To fix this, newer systems were developed:</p>
<ul>
<li><p><strong>Upstart</strong> (by Ubuntu, around 2006) — used for a while but later dropped.</p>
</li>
<li><p><strong>systemd</strong> (adopted widely from 2011) — now used by almost all Linux systems.</p>
</li>
</ul>
<h2 id="heading-systemd">systemd</h2>
<p>Systems with <strong>systemd</strong> starts up a service much faster than the other init methods. This is mainly because it replaced linear sequential steps to parallel steps. One systemd command (systemctl) can be used to start or stop any services in your pc</p>
<h3 id="heading-small-exercise-using-systemctl-command">Small Exercise using systemctl command</h3>
<p>Let’s do a worthless experiment to check the systemctl command:</p>
<ul>
<li><p>In your pc, there is a service named Apache Web Service</p>
</li>
<li><p>I am using ubuntu so to install Apache Web Service, I’ll run these commands</p>
<ul>
<li><pre><code class="lang-bash">    sudo apt update
    sudo apt install apache2
</code></pre>
</li>
</ul>
</li>
<li><p>Now, to stop this service run <code>sudo systemctl stop apache2</code></p>
</li>
<li><p>To start this service run <code>sudo sysemctl start apache2</code></p>
</li>
<li><p>To check its status run <code>sudo systemctl status apache2</code></p>
</li>
</ul>
<h1 id="heading-linux-filesystems">Linux Filesystems</h1>
<h2 id="heading-intro">Intro</h2>
<p>Different types of filesystems supported by Linux:</p>
<ul>
<li><p>Conventional disk filesystems: <strong>ext3</strong>, <strong>ext4</strong>, <strong>XFS</strong>, <strong>Btrfs</strong>, <strong>JFS</strong>, <strong>NTFS</strong>, <strong>vfat</strong>, <strong>exfat</strong>, etc.</p>
</li>
<li><p>Flash storage filesystems: <strong>ubifs</strong>, <strong>jffs2</strong>, <strong>yaffs</strong>, etc.</p>
</li>
<li><p>Database filesystems</p>
</li>
<li><p>Special purpose filesystems: <strong>procfs</strong>, <strong>sysfs</strong>, <strong>tmpfs</strong>, <strong>squashfs</strong>, <strong>debugfs</strong>, <strong>fuse</strong>, etc.</p>
</li>
</ul>
<p>Let’s learn about these now</p>
<h2 id="heading-partitions-and-filesystems">Partitions and Filesystems</h2>
<p>Partition is basically a part of your entire physical storage device that acts as a whole storage volume</p>
<p>A filesystem is a method of storing and accessing files inside a partition</p>
<h2 id="heading-filesystem-hierarchy">Filesystem Hierarchy</h2>
<p>As mentioned earlier, linux uses a filesystem hierarchy to store different files. If you want to know more about this hierarchy, you can read a 50 page pdf written by our smart bros at linux: <a target="_blank" href="https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.pdf">File System Hierarchy</a></p>
<h3 id="heading-some-important-info">Some important info:</h3>
<p>All Linux filesystem names are case-sensitive, so <strong>/boot</strong>, <strong>/Boot</strong>, and <strong>/BOOT</strong> represent three different directories (or folders). Many distributions distinguish between core utilities needed for proper system operation and other programs, and place the latter in directories under <strong>/usr</strong> (think user). To get a sense for how the other programs are organized, find the <strong>/usr</strong> directory in the diagram from the previous page and compare the subdirectories with those that exist directly under the system root directory (<strong>/</strong>).</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Let’s leave this much for today, I hope I was able to add some knowledge to your knowledge stack. One like would really help to keep me motivated. Anyways, thanks for reading</p>
]]></content:encoded></item><item><title><![CDATA[How blockchain voting can be completely bribe-resistant]]></title><description><![CDATA[Make sure you know bits and pieces of blockchain, zero knowledge proofs
In offline voting systems, if you bribe a person about voting for party A, you don’t get the choice to verify if the person voted for party A or not. But if the person is casting...]]></description><link>https://tech.roydevelops.tech/how-blockchain-voting-can-be-completely-bribe-resistant</link><guid isPermaLink="true">https://tech.roydevelops.tech/how-blockchain-voting-can-be-completely-bribe-resistant</guid><category><![CDATA[Blockchain]]></category><category><![CDATA[dao-governance]]></category><category><![CDATA[Governance]]></category><category><![CDATA[Ethereum]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Sat, 28 Dec 2024 09:47:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1735374198991/a6786860-7d3c-4723-aa77-838f04791ee0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Make sure you know bits and pieces of blockchain, zero knowledge proofs</em></p>
<p>In offline voting systems, if you bribe a person about voting for <code>party A</code>, you don’t get the choice to verify if the person voted for <code>party A</code> or not. But if the person is casting the vote on chain, anyone can publicly see the party you have voted for as it is decentralized. To eliminate this collusion, the concept of MACI (Minimal Anti Collusion Infrastructure) keys were introduced</p>
<h1 id="heading-voting-systems">Voting Systems</h1>
<p>I know many of you might think that knowing about voting systems makes no sense, but I would request you to just go through it once again</p>
<h4 id="heading-in-person-voting-systemshttpsmacipsedevdocsintroductionin-person-voting-systems">In-person voting systems<a target="_blank" href="https://maci.pse.dev/docs/introduction#in-person-voting-systems">​</a></h4>
<p>In short, it's hard to know for sure how current voting systems operate. Governments and corporations spend lots of resources on their systems and processes in an attempt to ensure their integrity, but ultimately neither the systems nor the processes are fully auditable, so we must trust that these security properties are being enforced.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td>In-person</td></tr>
</thead>
<tbody>
<tr>
<td>Correct execution</td><td>🤷‍♂️</td></tr>
<tr>
<td>Censorship resistance</td><td>🤷‍♂️</td></tr>
<tr>
<td>Privacy</td><td>🤷‍♂️</td></tr>
<tr>
<td>Collusion resistance</td><td>🤷‍♂️</td></tr>
</tbody>
</table>
</div><h4 id="heading-blockchain-voting-systemshttpsmacipsedevdocsintroductionblockchain-voting-systems">Blockchain voting systems<a target="_blank" href="https://maci.pse.dev/docs/introduction#blockchain-voting-systems">​</a></h4>
<p>Blockchains offer two main features: correct execution and censorship resistance. They process user transactions based on set rules, ensuring no changes to these rules. Anyone can send a transaction if they pay the required fee.</p>
<p>However, blockchain voting has issues. Ethereum, like most blockchains, is transparent, meaning all transaction data is public. This lack of privacy makes bribery easy, as voters can show proof of their vote. Bribery can even be automated with smart contracts, making collusion easy.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td>In-person</td><td>Ethereum</td></tr>
</thead>
<tbody>
<tr>
<td>Correct execution</td><td>🤷‍♂️</td><td>✅</td></tr>
<tr>
<td>Censorship resistance</td><td>🤷‍♂️</td><td>✅</td></tr>
<tr>
<td>Privacy</td><td>🤷‍♂️</td><td>❌</td></tr>
<tr>
<td>Collusion resistance</td><td>🤷‍♂️</td><td>❌</td></tr>
</tbody>
</table>
</div><h4 id="heading-blockchain-voting-systems-with-zkps">Blockchain voting systems (with ZKPs)</h4>
<p>Zero-knowledge proofs (ZKPs) allow private voting on blockchains like Ethereum while keeping results public and verifiable. Votes are counted off-chain, but ZKPs ensure they are accurate without showing individual votes.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td>In-person</td><td>Ethereum</td><td>Ethereum w/ ZK</td></tr>
</thead>
<tbody>
<tr>
<td>Correct execution</td><td>🤷‍♂️</td><td>✅</td><td>✅</td></tr>
<tr>
<td>Censorship resistance</td><td>🤷‍♂️</td><td>✅</td><td>✅</td></tr>
<tr>
<td>Privacy</td><td>🤷‍♂️</td><td>❌</td><td>✅</td></tr>
<tr>
<td>Collusion resistance</td><td>🤷‍♂️</td><td>❌</td><td>✅</td></tr>
</tbody>
</table>
</div><h1 id="heading-wtf-is-maci">WTF is MACI?</h1>
<p>MACI stands for Minimal Anti Collusion Infrastructure. As the full form suggests, it is an <strong>anti-collusion</strong> infrastructure made so that on chain voting can be reliable, private while also being censorship resistant. It leverages zk-SNARKs technology to achieve this</p>
<h1 id="heading-workflow-of-the-entire-voting-cycle-with-maci">Workflow of the entire voting cycle with MACI</h1>
<p>There is a detailed article about the workflow on the <a target="_blank" href="https://maci.pse.dev/docs/core-concepts/workflow">official MACI docs</a>. I’ll just summarize everything in short</p>
<p>In the voting system, there are 2 parties that are being involved:</p>
<ol>
<li><p>The User: Who casts the vote</p>
</li>
<li><p>The Coordinator: Who verifies and publishes the final results of the vote based on the users choices</p>
<p> <strong>We will always assume that the coordinator is not corrupted</strong></p>
</li>
</ol>
<p>After the poll starts this is what users will have to do to create their vote</p>
<h3 id="heading-signing-up">Signing Up</h3>
<p>Before casting the vote, users will have to generate a public, private keypair which will act as their anonymous identity as the voter. The user will make a function call to the <code>signUp()</code> function of the maci smart contract and register their generated public key as the voter</p>
<h3 id="heading-casting-the-vote">Casting the Vote</h3>
<p>Casting the vote involves a few steps</p>
<ul>
<li><p>Command Creation: The user bundles their vote information (public key, vote option, amount, etc.) into a command.</p>
</li>
<li><p>Signing: The user signs this command using their private key (from signup) to prove their identity.</p>
</li>
</ul>
<p>After signing the message, comes the part of encryption:</p>
<ul>
<li><p>A unique shared key exists between each user and the coordinator</p>
</li>
<li><p>The user encrypts both the command and signature together into a message</p>
</li>
<li><p>This encryption prevents bribers from seeing vote choices in transaction data</p>
</li>
</ul>
<p>Once the encryption is done, the encrypted message can then securely be passed to the contract where it is verified and stored.</p>
<h2 id="heading-vote-ends">VOTE ENDS</h2>
<p>A Poll is "closed", when the voting period ends. At this point, no users may submit any more votes. The Poll remains closed until the coordinator tallies the final results.</p>
<p>At this point, the coordinator must process all the messages, tally the results, and publish the proofs on-chain</p>
<h1 id="heading-hmm-how-did-it-resist-collusion">Hmm.. How did it resist collusion?</h1>
<p>Ever wondered how MACI makes vote buying impossible? At its core, MACI uses a clever system of encrypted messages and shared keys. Think of each vote as a letter sealed with special ink – only the voter and the vote counter have the unique ink formula to read it. Even if someone tries to buy votes, they're out of luck. Why? Because even if a voter shows them their voting transaction on the blockchain, all they'll see is encrypted data – like trying to read a letter written in invisible ink without the decoder.</p>
<p>But here's where it gets interesting. Voters can change their votes as many times as they want, and only their last vote counts. Imagine trying to buy someone's vote when they can simply vote again later, completely nullifying their "sold" vote. And the best part? There's absolutely no way to prove if or when someone changed their vote.</p>
<p>The vote counter (called the coordinator) can see and count the votes, but they have to provide mathematical proof that they counted everything correctly. It's like having a referee who has to show their work, making it impossible to fudge the numbers. This creates a perfect balance: complete privacy for individual votes, but total transparency for the final count.</p>
<p>The result? A voting system where even if voters wanted to sell their votes, they simply couldn't prove how they voted. It's like trying to sell a secret when you can't prove you know it – mathematically impossible.</p>
<h1 id="heading-the-end">The End</h1>
<p>This article is intended to provide you an overview of how <strong>BLOCKCHAIN VOTINGS ARE COLLUSION RESISTANT</strong> it doesn’t go into the depth of how MACI keys work. If you want to know everything in depth, then refer to the <a target="_blank" href="https://maci.pse.dev/docs/introduction">official docs of MACI</a></p>
]]></content:encoded></item><item><title><![CDATA[How pigeons and rats gave the idea of ML]]></title><description><![CDATA[Pegion Superstition
The term "pigeon superstition" actually refers to a famous psychology experiment conducted by B. F. Skinner on operant conditioning. Here's the gist:

Skinner's Experiment: Pigeons were placed in cages and given food at random int...]]></description><link>https://tech.roydevelops.tech/how-pigeons-and-rats-gave-the-idea-of-ml</link><guid isPermaLink="true">https://tech.roydevelops.tech/how-pigeons-and-rats-gave-the-idea-of-ml</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[machine learning models]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Tue, 16 Apr 2024 07:33:20 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-pegion-superstition">Pegion Superstition</h1>
<p>The term "pigeon superstition" actually refers to a famous psychology experiment conducted by B. F. Skinner on operant conditioning. Here's the gist:</p>
<ul>
<li><p><strong>Skinner's Experiment:</strong> Pigeons were placed in cages and given food at random intervals. Interestingly, the pigeons developed repetitive behaviors (e.g., circling, bobbing their heads) that seemed to coincide with the food delivery.</p>
</li>
<li><p><strong>The Catch:</strong> These behaviors didn't actually cause the pigeons to get food any faster. It was purely coincidental. However, since the food sometimes appeared right after they performed a specific action, the pigeons mistakenly believed their behavior influenced the outcome.</p>
</li>
<li><p><strong>Superstitious Behavior:</strong> This is where the term "pigeon superstition" comes from. It highlights how animals (and sometimes humans) can associate random events with their actions and develop rituals or routines based on that mistaken belief.</p>
</li>
</ul>
<p>In essence, it's not that pigeons are truly superstitious, but their behavior demonstrates a basic learning principle: operant conditioning, where actions followed by rewards are more likely to be repeated.</p>
<h1 id="heading-bait-shyness">Bait Shyness</h1>
<p>Bait shyness, also sometimes called conditioned food aversion, is an evolutionary adaptation seen in many animals, particularly rodents. It describes the avoidance of a food source that has been associated with a negative experience in the past.</p>
<p>Here's a breakdown of bait shyness:</p>
<ul>
<li><p><strong>Learning from Experience:</strong> Animals, especially intelligent ones like rats and mice, are good at learning from experience. If they eat something and then get sick, they'll likely avoid that food source in the future.</p>
</li>
<li><p><strong>Taste and Smell:</strong> Animals rely heavily on taste and smell to identify food sources. When they experience illness after consuming something, they associate the taste and smell with the negative outcome.</p>
</li>
<li><p><strong>Survival Benefit:</strong> Bait shyness helps animals avoid poisonous or harmful foods in the wild, increasing their chances of survival.</p>
</li>
</ul>
<h1 id="heading-inductive-bias">Inductive Bias</h1>
<p>Imagine you're playing with building blocks. You've never seen a tower before, but you keep seeing grown-ups putting blocks on top of each other.</p>
<ul>
<li><p><strong>Learning from Examples:</strong> You start to guess how towers work. You might think, "Towers are always made of blocks, and bigger blocks usually go on the bottom." This is like learning from examples, which is what computers do with inductive bias.</p>
</li>
<li><p><strong>Guessing Based on What You Know:</strong> Inductive bias is like having a favorite type of block you like to use first. Maybe you always start with the red block because that's what you see most often. This "favorite block" idea is the computer's guess about how things work based on what it's seen before.</p>
</li>
<li><p><strong>Not Always Right:</strong> Just like sometimes a tower needs a smaller block on the bottom to be strong, the computer's guess might not always be right. It needs to see more examples and adjust its ideas as it learns new things.</p>
</li>
</ul>
<p>So, inductive bias is like a computer's way of making a guess about how things work based on what it's already learned, even though the guess might need to change later!</p>
<h1 id="heading-pegion-rats-and-inductive-bias">Pegion, rats and inductive bias</h1>
<p>Imagine you're playing outside and see a yummy-looking cookie on the ground. You reach for it, but just before you take a bite, a big gust of wind blows your hat away! You run to get your hat and come back... the cookie is gone! Uh oh!</p>
<ul>
<li><p><strong>Pigeon Superstition:</strong> This is like a pigeon thinking, "The wind blew my hat away, then the cookie disappeared. Maybe the wind took my cookie!" Even though the wind didn't really take the cookie, the pigeon makes a guess (induction) based on what it already experienced. This guess is the pigeon's inductive bias.</p>
</li>
<li><p><strong>Bait Shyness:</strong> Now imagine you see some tasty-looking seeds on the ground. You eat a few, but then you feel yucky and sick! You avoid those seeds from then on. This is like bait shyness. You learned (induction) that those seeds make you sick, so you avoid them next time.</p>
</li>
</ul>
<p>Both these examples show inductive bias. It's like a guess an animal (or even a computer sometimes!) makes based on what it's already experienced. It's not always right, just like the pigeon and the cookie, but it helps them learn and avoid getting hurt.</p>
<h1 id="heading-how-is-inductive-bias-important-for-ml">How is Inductive Bias important for ML</h1>
<p>Machine learning (ML) algorithms are like super students who can learn from data. But unlike us, they don't have all the background knowledge or common sense we take for granted. This is where inductive bias comes in!</p>
<p><strong>Inductive Bias as a "Learning Preference":</strong></p>
<ul>
<li><p>Imagine you're teaching your friend a new card game. You might explain the basic rules, but you probably won't mention every single situation that could come up. Your friend will use their own ideas (inductive bias) to fill in the gaps based on what they've learned so far.</p>
</li>
<li><p>Similarly, an ML algorithm has an inductive bias that reflects its basic assumptions about the data it's learning from. These assumptions guide the algorithm towards certain types of solutions over others.</p>
</li>
</ul>
<p><strong>Pigeon Superstition and Inductive Bias in ML:</strong></p>
<ul>
<li><p>Remember the pigeon who thought the wind stole its cookie? That's a funny example of inductive bias. The pigeon made a connection (induction) between the wind blowing and the cookie disappearing, even though there was no real connection.</p>
</li>
<li><p>In machine learning, the algorithm might have an inductive bias that assumes data points that are close together are more likely to be similar. This can be helpful, but it can also lead to mistakes if the data doesn't actually follow that pattern.</p>
</li>
</ul>
<p><strong>Benefits of Inductive Bias:</strong></p>
<ul>
<li><p>Just like a little common sense helps your friend learn the card game, inductive bias helps ML algorithms learn faster and more efficiently. It allows them to focus on the most likely possibilities instead of considering every single option, which would be overwhelming.</p>
</li>
<li><p>For example, an algorithm with an inductive bias for recognizing handwritten digits might assume that slightly messy versions of a "7" are still likely to be "7s." This helps it make accurate predictions even with imperfect data.</p>
</li>
</ul>
<p><strong>Challenges of Inductive Bias:</strong></p>
<ul>
<li><p>The downside of inductive bias is that it can lead to blind spots if the assumptions aren't right. Imagine your friend stubbornly thinks the highest card always wins in the card game! They'll miss out on important strategies.</p>
</li>
<li><p>In ML, if the inductive bias doesn't match the actual data patterns, the algorithm might make poor predictions. For example, an algorithm trained on mostly sunny weather data might not handle rainy days well because it has a bias towards sunny weather.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Machine Learning and how to learn it]]></title><description><![CDATA[Let's start with an overview of ML. Machine Learning is a technique by which an algorithm or model learns from and makes decisions based on data without being programmed to do so.
Sometimes Artificial Intelligence and Machine Learning are considered ...]]></description><link>https://tech.roydevelops.tech/machine-learning-and-how-to-learn-it</link><guid isPermaLink="true">https://tech.roydevelops.tech/machine-learning-and-how-to-learn-it</guid><category><![CDATA[WeMakeDevs]]></category><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Fri, 10 Feb 2023 03:58:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/f57lx37DCM4/upload/0026abde8391d93de2059336bb8d2a25.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let's start with an overview of ML. Machine Learning is a technique by which an algorithm or model learns from and makes decisions based on data without being programmed to do so.</p>
<p>Sometimes <strong>Artificial Intelligence</strong> and <strong>Machine Learning</strong> are considered to be the same even if they have a difference between them</p>
<h1 id="heading-artificial-intelligence-vs-machine-learning">Artificial Intelligence vs Machine Learning</h1>
<p>Imagine, there is a toy robot that can perform different tasks like singing a song, or solving puzzles. This robot is an example of Artificial Intelligence as it can do tasks that require human intelligence.</p>
<p>Now, let's say the robot learns to do a new task like catching a ball or writing a blog article by watching someone else do it a few times. That's what we call Machine Learning (ML). The robot learned how to catch a ball, and write blogs without being explicitly programmed to do so.</p>
<p>The example above gives a brief idea about the difference between Machine Learning and AI. The example is taken from ChatGPT, the modern powerful AI.</p>
<p>So, when I asked this question to ChatGPT, it found an answer which met the needs of my question and answered the question. It did a task that required human intelligence. So, that is why we call Chat GPT an AI</p>
<pre><code class="lang-plaintext">## CHAT GPT PROMPT
differentiate ai and ml such that it can be understood by a 6 years old boy
</code></pre>
<p>Now, let's go back to the time when it was created. It was provided a sample set of data which contained a bunch of prompts and their answers. From that data, it learned to answer questions like this. An algorithm was used so that it can extract the data and find patterns between them. Thus, it learned how to answer these kinds of questions by finding similar patterns in data. This process by which the algorithm learned to answer these kinds of questions is a process of Machine Learning.</p>
<h1 id="heading-roadmap">Roadmap</h1>
<p>I have seen many roadmap videos on YouTube and some stuff is common in every Machine Learning Roadmap video. So, I'll give you a detailed roadmap of Machine Learning</p>
<h2 id="heading-a-mathematics">A. Mathematics</h2>
<p>It is the backbone of machine learning, providing the tools and concepts needed to understand and apply the algorithms and models used in the field. The topics of mathematics required for Machine Learning are:</p>
<ol>
<li><p>Linear Algebra</p>
</li>
<li><p>Statistics and Probability</p>
</li>
<li><p>Calculus</p>
</li>
</ol>
<p>Let's learn the importance of these topics</p>
<h3 id="heading-linear-algebra">Linear Algebra</h3>
<p>Linear Algebra helps in playing with numbers arranged in rows and columns (known as matrices). Imagine, you have a toy box with many toys in it. Each toy can be represented as a number. Linear Algebra helps to work with these kinds of matrices by performing operations like addition, subtraction, and multiplication and it can help to find patterns in the numbers.</p>
<p>So, imagine you have a toy robot that you want to teach to make decisions based on lots of data. You can use Linear Algebra to help the robot understand and analyze the data.</p>
<h3 id="heading-statistics-and-probability">Statistics and Probability</h3>
<p>Imagine you want to teach a robot to predict the weather. Statistics and Probability can help the robot understand how likely it is to rain based on past weather data. The robot can then predict the weather.</p>
<p>We use Statistics and probability to help our toy robot guess what might happen in the future, based on what has happened in the past.</p>
<h3 id="heading-calculus">Calculus</h3>
<p>Calculus is like a GPS system for the robot that helps it find the best way to learn. Just like a GPS helps us find the quickest route to a destination, Calculus helps our robot find the quickest and easiest way to learn new things.</p>
<p>So, the work of optimizing ML algorithms (also called models) is done by Calculus</p>
<hr />
<p>You don't need to learn everything about these. You can do a Ph.D. in these topics and spend most of your life learning about Maths and not ML also. But if you want the fast way, then learn these specific topics</p>
<hr />
<h3 id="heading-linear-algebra-topics">Linear Algebra Topics</h3>
<ol>
<li><p>Vectors and vector operations:</p>
<ul>
<li><p>Definition and representation of vectors</p>
</li>
<li><p>Vector addition and subtraction</p>
</li>
<li><p>Scalar multiplication</p>
</li>
<li><p>Dot product and cross product</p>
</li>
<li><p>Length and normalization of vectors</p>
</li>
<li><p>Angle between vectors</p>
</li>
<li><p>Orthogonal and orthonormal sets of vectors</p>
</li>
</ul>
</li>
<li><p>Matrix operations:</p>
<ul>
<li><p>Definition and representation of matrices</p>
</li>
<li><p>Matrix addition and subtraction</p>
</li>
<li><p>Scalar multiplication</p>
</li>
<li><p>Matrix multiplication</p>
</li>
<li><p>Transpose of a matrix</p>
</li>
<li><p>Trace of a matrix</p>
</li>
<li><p>Determinant of a matrix</p>
</li>
<li><p>Inverse of a matrix</p>
</li>
</ul>
</li>
<li><p>Determinants, inverses, and eigenvalues/eigenvectors:</p>
<ul>
<li><p>Determinant of a matrix and its properties</p>
</li>
<li><p>Inverse of a matrix and its properties</p>
</li>
<li><p>Eigenvalues and eigenvectors of a matrix</p>
</li>
<li><p>Diagonalization of matrices</p>
</li>
<li><p>Characteristic polynomial of a matrix</p>
</li>
<li><p>Jordan form of a matrix</p>
</li>
</ul>
</li>
<li><p>Linear systems of equations and Gaussian elimination:</p>
<ul>
<li><p>Solving linear systems of equations using Gaussian elimination</p>
</li>
<li><p>Gauss-Jordan elimination</p>
</li>
<li><p>LU decomposition</p>
</li>
<li><p>QR decomposition</p>
</li>
<li><p>Singular value decomposition (SVD)</p>
</li>
</ul>
</li>
<li><p>Orthogonality and projections:</p>
<ul>
<li><p>Orthogonal and orthonormal sets of vectors</p>
</li>
<li><p>Projections and orthogonal projections</p>
</li>
<li><p>Orthogonal basis and orthonormal basis</p>
</li>
<li><p>Orthogonal matrices and orthonormal matrices</p>
</li>
<li><p>Gram-Schmidt process</p>
</li>
</ul>
</li>
<li><p>Singular value decomposition (SVD):</p>
<ul>
<li><p>Definition and properties of SVD</p>
</li>
<li><p>Computing SVD of a matrix</p>
</li>
<li><p>Applications of SVD in data compression and denoising</p>
</li>
<li><p>Low-rank approximations of matrices</p>
</li>
</ul>
</li>
<li><p>Principal Component Analysis (PCA):</p>
<ul>
<li><p>Definition and intuition behind PCA</p>
</li>
<li><p>Computing the principal components of a dataset</p>
</li>
<li><p>Dimensionality reduction using PCA</p>
</li>
<li><p>Applications of PCA in data visualization and feature extraction</p>
</li>
</ul>
</li>
<li><p>Matrix factorization methods:</p>
<ul>
<li><p>Non-Negative Matrix Factorization (NMF)</p>
</li>
<li><p>Latent Dirichlet Allocation (LDA)</p>
</li>
<li><p>Collaborative Filtering</p>
</li>
</ul>
</li>
<li><p>Least squares optimization and gradient descent:</p>
<ul>
<li><p>Least squares optimization</p>
</li>
<li><p>Gradient descent algorithm</p>
</li>
<li><p>Stochastic gradient descent (SGD)</p>
</li>
<li><p>Convergence analysis of gradient descent</p>
</li>
<li><p>Batch gradient descent vs. stochastic gradient descent</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-statistics-and-probability-topics">Statistics and Probability Topics:</h3>
<ol>
<li><p>Probability:</p>
<ul>
<li><p>Axioms of probability</p>
</li>
<li><p>Conditional probability</p>
</li>
<li><p>Bayes' Theorem</p>
</li>
<li><p>Joint and marginal distributions</p>
</li>
<li><p>Independence and dependence</p>
</li>
<li><p>Random variables and expected value</p>
</li>
<li><p>Variance and covariance</p>
</li>
</ul>
</li>
<li><p>Probability Distributions:</p>
<ul>
<li><p>Discrete distributions (Bernoulli, Binomial, Poisson, etc.)</p>
</li>
<li><p>Continuous distributions (Uniform, Normal, Exponential, etc.)</p>
</li>
<li><p>Characteristic functions and moment generating functions</p>
</li>
<li><p>Estimation of parameters (Maximum Likelihood, Moment Estimation, etc.)</p>
</li>
<li><p>Convergence in distribution</p>
</li>
</ul>
</li>
<li><p>Hypothesis Testing:</p>
<ul>
<li><p>Null and alternative hypotheses</p>
</li>
<li><p>p-values and significance levels</p>
</li>
<li><p>Type I and Type II errors</p>
</li>
<li><p>One-sample and two-sample tests</p>
</li>
<li><p>t-tests and ANOVA</p>
</li>
<li><p>Chi-square tests</p>
</li>
</ul>
</li>
<li><p>Confidence Intervals:</p>
<ul>
<li><p>Definition and properties of confidence intervals</p>
</li>
<li><p>Central Limit Theorem and normal approximation</p>
</li>
<li><p>t-intervals and proportion intervals</p>
</li>
</ul>
</li>
<li><p>Regression Analysis:</p>
<ul>
<li><p>Simple linear regression</p>
</li>
<li><p>Multiple linear regression</p>
</li>
<li><p>Logistic regression</p>
</li>
<li><p>Polynomial regression</p>
</li>
<li><p>Regularization (Ridge, Lasso, etc.)</p>
</li>
</ul>
</li>
<li><p>Statistical Inference:</p>
<ul>
<li><p>Point estimation</p>
</li>
<li><p>Interval estimation</p>
</li>
<li><p>Maximum Likelihood Estimation</p>
</li>
<li><p>Bayesian inference</p>
</li>
<li><p>Central Limit Theorem and Law of Large Numbers</p>
</li>
</ul>
</li>
<li><p>Machine Learning specific topics:</p>
<ul>
<li><p>Overfitting and underfitting</p>
</li>
<li><p>Bias-variance tradeoff</p>
</li>
<li><p>Cross-validation</p>
</li>
<li><p>Regularization</p>
</li>
<li><p>Maximum likelihood and maximum a posteriori (MAP) estimation</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-calculus-topics">Calculus Topics</h3>
<ol>
<li><p>Differentiation:</p>
<ul>
<li><p>Limits and derivatives</p>
</li>
<li><p>Rules for differentiation (power rule, sum rule, product rule, chain rule, etc.)</p>
</li>
<li><p>Partial derivatives and gradient</p>
</li>
<li><p>Jacobian matrix</p>
</li>
<li><p>Implicit differentiation</p>
</li>
</ul>
</li>
<li><p>Integration:</p>
<ul>
<li><p>Indefinite and definite integrals</p>
</li>
<li><p>Fundamental Theorem of Calculus</p>
</li>
<li><p>Techniques for integration (substitution, integration by parts, partial fractions, etc.)</p>
</li>
</ul>
</li>
<li><p>Multivariate Calculus:</p>
<ul>
<li><p>Partial derivatives and gradient</p>
</li>
<li><p>Hessian matrix and second partial derivatives</p>
</li>
<li><p>Laplacian and Laplace's equation</p>
</li>
<li><p>Extrema of multivariate functions</p>
</li>
<li><p>Constrained optimization and Lagrange multipliers</p>
</li>
</ul>
</li>
<li><p>Differential Equations:</p>
<ul>
<li><p>Ordinary Differential Equations (ODEs)</p>
</li>
<li><p>Separation of variables, Euler's method, and Runge-Kutta method</p>
</li>
<li><p>Partial Differential Equations (PDEs)</p>
</li>
<li><p>Heat equation and wave equation</p>
</li>
</ul>
</li>
<li><p>Probability and Statistics:</p>
<ul>
<li><p>Probability distributions (discrete and continuous)</p>
</li>
<li><p>Expectation and variance</p>
</li>
<li><p>Joint and marginal distributions</p>
</li>
<li><p>Conditional probability</p>
</li>
<li><p>Correlation and covariance</p>
</li>
</ul>
</li>
<li><p>Optimization:</p>
<ul>
<li><p>Unconstrained optimization and local minima/maxima</p>
</li>
<li><p>Constrained optimization and Lagrange multipliers</p>
</li>
<li><p>Gradient descent and stochastic gradient descent</p>
</li>
<li><p>Newton's method and quasi-Newton methods</p>
</li>
<li><p>Convex optimization</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-b-programming">B. Programming</h2>
<ol>
<li><p>Programming with Python</p>
</li>
<li><p>Libraries:</p>
<ol>
<li><p>Numpy</p>
</li>
<li><p>Pandas</p>
</li>
<li><p>Matplotlib</p>
</li>
</ol>
</li>
</ol>
<hr />
<p>Now, you have a solid foundation in Mathematics and programming. So, the next step is to learn the basics of ML algorithms</p>
<hr />
<h2 id="heading-c-basics-of-ml-algorithms">C. Basics of ML Algorithms</h2>
<ol>
<li><p>Supervised Learning:</p>
<ul>
<li><p>Linear Regression</p>
</li>
<li><p>Logistic Regression</p>
</li>
<li><p>Decision Trees</p>
</li>
<li><p>Random Forest</p>
</li>
<li><p>Support Vector Machines (SVM)</p>
</li>
<li><p>K-Nearest Neighbors (KNN)</p>
</li>
<li><p>Naive Bayes</p>
</li>
</ul>
</li>
<li><p>Unsupervised Learning:</p>
<ul>
<li><p>K-Means Clustering</p>
</li>
<li><p>Hierarchical Clustering</p>
</li>
<li><p>Density-Based Clustering</p>
</li>
<li><p>Principal Component Analysis (PCA)</p>
</li>
</ul>
</li>
<li><p>Reinforcement Learning:</p>
<ul>
<li><p>Markov Decision Processes (MDP)</p>
</li>
<li><p>Q-Learning</p>
</li>
<li><p>Monte Carlo Methods</p>
</li>
</ul>
</li>
<li><p>Deep Learning:</p>
<ul>
<li><p>Neural Networks</p>
</li>
<li><p>Convolutional Neural Networks (CNN)</p>
</li>
<li><p>Recurrent Neural Networks (RNN)</p>
</li>
<li><p>Long Short-Term Memory (LSTM)</p>
</li>
<li><p>Autoencoders</p>
</li>
</ul>
</li>
<li><p>Model evaluation techniques:</p>
<ul>
<li><p>Overfitting and underfitting</p>
</li>
<li><p>Bias-Variance tradeoff</p>
</li>
<li><p>Cross-Validation</p>
</li>
<li><p>Hyperparameter tuning</p>
</li>
</ul>
</li>
</ol>
<hr />
<p>Now, you have become an intermediate in ML. Its time to upgrade your ML sword now. To sharpen your sword of ML, you must <strong>Practice.</strong> One great resource is Kaggle</p>
<hr />
<h1 id="heading-how-to-learn">How to Learn</h1>
<p>In this article, you have seen the roadmap for learning Machine Learning. But there are some techniques I would like to tell you which will accelerate your learning process.</p>
<p>I have given you individual topics. So, you can search them in sequence one by one on <strong>YouTube</strong> and <strong>Google</strong> and you can gather the explanation from there.</p>
<p>I would like to tell you about one of the newest techniques for simplifying your understanding. If you are here, you might know about <strong>ChatGPT</strong></p>
<p>You can use that as a tool to accelerate your learning process. Here's how you should learn for a simplified and better understanding:</p>
<ol>
<li><p>Let's say you want to learn a specific topic from the list</p>
</li>
<li><p>Go to Chat GPT and write this prompt</p>
<ul>
<li><pre><code class="lang-plaintext">    Write a basic article on [topic] so that a child can understand it
</code></pre>
</li>
</ul>
</li>
<li><p>Now, once you know the overview of the topic you are learning, you can search on YouTube or Google for a better understanding</p>
</li>
<li><p><strong>Exception:</strong> Let's say you didn't understand a subtopic of the topic you are learning (read the sentence again) from YouTube after following my steps. Then repeat the 2nd step and just change <code>[topic]</code> to your <code>[subtopic]</code></p>
</li>
</ol>
<h1 id="heading-conclusion">Conclusion</h1>
<p>And there you have it folks, everything you need to know about Machine Learning, and the way to learn it. Whether you're a toy robot trying to learn how to solve puzzles or a human trying to understand the complexities of AI, this article has got you covered.</p>
<p>So, dive into the world of ML. And let me tell you one little secret. I have used Chat GPT intensely to make this article also. It gave me an explanation of the robot which I used earlier. The subtopics are also generated by it. So, use ChatGPT and remember one thing that I learned from <a class="user-mention" href="https://hashnode.com/@kunalk">Kunal Kushwaha</a>'s Twitter handle:</p>
<blockquote>
<p>AI will not replace you. A person who is using AI will replace you.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Decoding the World of Machine Learning: The Fundamentals You Need to Know]]></title><description><![CDATA[In this article, we will be looking at the fundamentals of machine learning and how mathematics is used in machine learning. But, at first look at Machine Learning in general
Machine Learning is the study of computer algorithms that improves themselv...]]></description><link>https://tech.roydevelops.tech/decoding-the-world-of-machine-learning-the-fundamentals-you-need-to-know</link><guid isPermaLink="true">https://tech.roydevelops.tech/decoding-the-world-of-machine-learning-the-fundamentals-you-need-to-know</guid><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Sat, 28 Jan 2023 01:35:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1674869614393/1eaea5ba-beea-4e41-8d0c-82acfc98b740.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, we will be looking at the fundamentals of machine learning and how mathematics is used in machine learning. But, at first look at Machine Learning in general</p>
<p><strong>Machine Learning is the study of computer algorithms that improves themselves through data</strong></p>
<p>In normal programming problems, we provide the data and some set of rules on which the data is processed and we expect the answer as output. In ML problems, we provide the answers and data to the program and the program finds the rules which connect the data to the answers. These relations are generated during the training process</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1674867544151/9505777f-bb9b-4244-a92d-15ce495d8f69.jpeg" alt class="image--center mx-auto" /></p>
<h1 id="heading-fundamental-ideas">Fundamental Ideas</h1>
<ul>
<li><p>All problems are data and all solutions are relations/functions: In ML problems, we need our answers and data to give to our algorithm as input. The work of the algorithm is to find out the relation between the answers and the data we provided</p>
</li>
<li><p>We convert qualitative inputs into numbers which become the input data. We call these numbers <strong>INPUT VECTORS</strong></p>
</li>
<li><p>Similarly, the answers or the output we need after training the ML algorithm has to be also converted into numbers which are called <strong>OUTPUT VECTORS</strong></p>
</li>
<li><p>As written earlier, the goal of that algorithm is to find out the relation between the <strong>INPUT</strong> and <strong>OUTPUT VECTORS</strong></p>
</li>
</ul>
<h1 id="heading-steps-in-machine-learning">Steps in Machine Learning</h1>
<ol>
<li><p>Gathering Data: We need to gather the data that is needed to train the machine</p>
</li>
<li><p>Preparing Data: We need to prepare the data to be used in that algorithm</p>
</li>
<li><p>Choosing a Model/ Algorithm that meets the needs</p>
</li>
<li><p>Training the model on the data</p>
</li>
<li><p>Testing Model</p>
</li>
<li><p>Hyperparameter Tuning: Tuning the model using parameters whose values are used to control the learning process</p>
</li>
</ol>
<p>The above 6 steps are steps of Training/ Testing the model</p>
<ol>
<li>Prediction: After everything is done, you will deploy your model and then it can be used for the prediction of your needs</li>
</ol>
<h1 id="heading-mathematics-for-machine-learning">Mathematics for Machine Learning</h1>
<h3 id="heading-linear-algebra">Linear Algebra</h3>
<p>ML is about the mapping of INPUT VECTORS to their corresponding OUTPUT VECTORS. To map these vectors, we need to use matrix-based transformations</p>
<p>So, we need to know about <strong>Matrices and Vectors</strong> in Linear Algebra</p>
<h3 id="heading-probability">Probability</h3>
<p>There can be uncertainty in data, e.g if you want to make an algorithm, that predicts the prices of stocks, there can be uncertainty</p>
<p>So, we need to know about <strong>PROBABILITY</strong></p>
<h3 id="heading-statistics">Statistics</h3>
<p>It is the science of collecting, analyzing, presenting and interpreting data. So, we need to use it in the process of Preparing data</p>
<h3 id="heading-calculus">Calculus</h3>
<p>Optimization of data is done using concepts of calculus</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Matrices for Machine Learning]]></title><description><![CDATA[Let me get this clear first. If you're looking to learn about matrices, reading this blog is only the beginning. While you'll gain an understanding of the fundamentals, if you want to truly master matrices you'll need to dive deeper. Watching lecture...]]></description><link>https://tech.roydevelops.tech/understanding-matrices-for-machine-learning</link><guid isPermaLink="true">https://tech.roydevelops.tech/understanding-matrices-for-machine-learning</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Tue, 10 Jan 2023 18:26:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/h6XihPOkSIY/upload/f7ffbaa91d1d8ed2fa926801880c613d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let me get this clear first. If you're looking to learn about matrices, reading this blog is only the beginning. While you'll gain an understanding of the fundamentals, if you want to truly master matrices you'll need to dive deeper. Watching lectures and reading books are great ways to gain a more comprehensive knowledge of the subject. You don't need to become a master of calculations either – computers take care of that – but learning the basic operations in matrices will help you make the most of the subject.</p>
<p>Matrices are a vital part of machine learning, as they are used to represent data in a structured and organized way. In this article, we will discuss the basics of matrices and how they are used in machine learning. We will also discuss some of the different types of matrices and how they can be used in Machine Learning algorithms</p>
<h1 id="heading-what-is-a-matrix">What is a Matrix?</h1>
<p>A matrix is a two-dimensional array of numbers, symbols, or expressions. In machine learning, matrices are used to represent data sets and to make calculations on them. Each element in the matrix is called a matrix entry or an entry. Entries are arranged in rows and columns, which makes a matrix appear like a table.<br />Matrices are typically used to store and manipulate multi-dimensional data sets. For example, if you want to analyze the performance of a machine learning algorithm on a data set, you would use a matrix to store the data and then work with it to analyze the results.</p>
<h1 id="heading-types-of-matrices">Types of Matrices</h1>
<ol>
<li><p>Identity Matrix: An identity matrix is a square matrix with all diagonal entries equal to 1 and all other entries equal to 0. It is often used to represent a linear transformation</p>
</li>
<li><p>Square Matrix: A square matrix is a matrix with the same number of rows and columns</p>
</li>
<li><p>Diagonal Matrix: A diagonal matrix is a square matrix with all off-diagonal entries equal to zero. It is used to represent a linear transformation, such as an affine transformation</p>
</li>
<li><p>Symmetric Matrix: A symmetric matrix is a square matrix where all entries on both the upper and lower diagonals are equal. It is used to represent a linear transformation, such as a rotation</p>
</li>
</ol>
<h1 id="heading-using-matrices-for-machine-learning">Using Matrices for Machine Learning</h1>
<p>Matrices are used in many machine learning algorithms, such as linear regression and neural networks. In linear regression, matrices are used to represent the data points and the coefficients of the regression equation. In neural networks, matrices are used to represent the weights of the network and the data points.</p>
<p>Matrices are also used in other algorithms, such as support vector machines and decision trees. In these algorithms, matrices are used to represent the data points and the parameters of the algorithm.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Matrices are an important part of machine learning, as they are used to represent data in a structured and organized way. Several different types of matrices are used in machine learning algorithms, such as identity matrices, diagonal matrices, symmetric matrices, tridiagonal matrices, and orthogonal matrices. Matrices are used in many machine learning algorithms to represent the data points and the parameters of the algorithm. Understanding matrices and how they are used in machine learning algorithms is essential for any aspiring machine learning engineer.</p>
]]></content:encoded></item><item><title><![CDATA[Supervised and Unsupervised Learning in Machine Learning]]></title><description><![CDATA[To put up simply, Machine Learning(ML) is a way by which a computer learns to predict the output of data. To achieve this, an algorithm (called an ML algorithm) is trained on a specific dataset.
Mainly there are 2 types of Machine Learning named as:
...]]></description><link>https://tech.roydevelops.tech/supervised-and-unsupervised-learning-in-machine-learning</link><guid isPermaLink="true">https://tech.roydevelops.tech/supervised-and-unsupervised-learning-in-machine-learning</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Fri, 06 Jan 2023 19:55:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/f57lx37DCM4/upload/a2342d14463616ab15699e4de735e525.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To put up simply, <strong>Machine Learning(ML)</strong> is a way by which a computer learns to predict the output of data. To achieve this, an algorithm (called an ML algorithm) is trained on a specific dataset.</p>
<p>Mainly there are 2 types of Machine Learning named as:</p>
<ol>
<li><p>Supervised Learning</p>
</li>
<li><p>Unsupervised Learning</p>
</li>
</ol>
<h1 id="heading-supervised-learning">Supervised Learning</h1>
<p>Here, the model is trained on data of desired Input and output mappings. You give your algorithm the input and the desired output data at first and then train your model. After the model has learned from your data, you give a completely new value to the model and it tries to produce a new output.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1673031866369/e04a4b7f-c123-4cb6-bd2f-d7c07d720d82.jpeg" alt class="image--center mx-auto" /></p>
<p>Spam filtering and speech recognition are some of the most used applications of supervised learning.</p>
<p>But there are two subcategories to supervised learning too:</p>
<ol>
<li><p>Regression</p>
</li>
<li><p>Classification</p>
</li>
</ol>
<h2 id="heading-regression">Regression</h2>
<p>In regression, the algorithm gives output in numbers from many possible output numbers. Let's take an example of house price prediction.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1673031722892/db98caa6-311b-45c5-82ca-e5b1dc365dbe.jpeg" alt class="image--center mx-auto" /></p>
<p>You will need to have a sample dataset of houses with a certain number of rooms, washrooms, and floors and their price. Now, your data will be used to train your ML model</p>
<p>If you need to predict the price of a house with 10 rooms, 3 washrooms and 3 floors, then your ML model will tell you the price.</p>
<h2 id="heading-classification">Classification</h2>
<p>In classification, your algorithm will return a category (also called a class) as its output. One of the classic examples of classification is spam filtering</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1673031553303/31d25fb0-295f-41e2-a4ff-aa9f0f28de19.jpeg" alt class="image--center mx-auto" /></p>
<p>The algorithm is trained on a large dataset of sample emails with input as the sender, the subject line, and the content of the email and the output of a particular email (spam or not spam) is already present there</p>
<p>Then when a new email is sent to a user, the algorithm tries to classify it as spam or not depending on the parameters like the sender, the subject line, and the content of the email</p>
<h1 id="heading-unsupervised-learning">Unsupervised Learning</h1>
<p>In supervised learning, we used data that had input and the corresponding correct output pairs. But in unsupervised learning, that output is not present in that data. The algorithm often predicts patterns in data and the data gets categorized by the rules made by the algorithm itself.</p>
<h2 id="heading-clustering">Clustering</h2>
<p>It is commonly used for tasks such as customer segmentation or document classification. In customer classification, the algorithm tries to classify the customers based on certain parameters like "paying users", "members", "blog readers" etc. etc. When an algorithm does this kind of task of classifying, it is often known as <strong>Clustering Algorithm</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1673034485557/15f0b097-7e09-47b5-a4f3-756fbd20784e.jpeg" alt class="image--center mx-auto" /></p>
<h2 id="heading-anomaly-detection">Anomaly Detection</h2>
<p>It aims at identifying any unusual data points that don't fit in any similar pattern of data. It is used in detecting transaction fraud detection</p>
<h2 id="heading-dimensionality-reduction">Dimensionality Reduction</h2>
<p>It involves reducing parameters from data while having access to much information in the dataset. It is used in tasks like data compression</p>
]]></content:encoded></item><item><title><![CDATA[Now create desktop app with Next Js]]></title><description><![CDATA[Next.js is a popular JavaScript framework that allows developers to build server-rendered, statically generated and client-side web applications. While it is typically used for building web applications, it is also possible to use Next.js to create d...]]></description><link>https://tech.roydevelops.tech/now-create-desktop-app-with-next-js</link><guid isPermaLink="true">https://tech.roydevelops.tech/now-create-desktop-app-with-next-js</guid><category><![CDATA[Next.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Tailwind CSS]]></category><category><![CDATA[Electron]]></category><category><![CDATA[programming]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Thu, 05 Jan 2023 11:20:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/gvptKmonylk/upload/b15de66b9cb837a24008b4ee8ef681d7.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Next.js is a popular JavaScript framework that allows developers to build server-rendered, statically generated and client-side web applications. While it is typically used for building web applications, it is also possible to use Next.js to create desktop apps.</p>
<p>In this tutorial, we will be showing you how to use Next.js and TailwindCSS to build a desktop app. We will be using Electron, which is a framework for building cross-platform desktop applications with web technologies, to package our Next.js app as a desktop app. Electron allows us to take our web app and wrap it in a native container, giving it the same functionality as a traditional desktop app.</p>
<p>By the end of this tutorial, you will have a basic understanding of how to use Next.js and Electron to build a desktop app. You will also have a working desktop app that you can run on your computer.</p>
<h1 id="heading-initialize-the-project">Initialize the project</h1>
<p>To begin, copy and paste the following code into your terminal to initialize a new project using Next.js, TailwindCSS and ElectronJs</p>
<pre><code class="lang-plaintext">npx create-nextron-app my-app --example with-javascript-tailwindcss
</code></pre>
<p>This will create the folders of the app, cd into that directory and install the packages using <code>npm install</code> or <code>yarn</code> .</p>
<p>After that you will be able to see a folder structure that looks like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672847817094/c8c73d89-bfa9-40b7-b036-e8ac9ccb3c4c.png" alt class="image--center mx-auto" /></p>
<p>You can see a similar folder structure to that of a bare next js app in the <code>renderer</code> folder. And we will be working on that only</p>
<p>Write <code>npm run dev</code> or <code>yarn dev</code> in your terminal of vs code and you will be able to see your electron app pop out</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672848017456/aca70283-0fd5-4d1b-b39b-1987e18cfbca.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-initial-configuration-for-next-js">Initial Configuration for Next Js</h1>
<p>In the pages folder, you will see that there is a file named <code>home.jsx</code> , which is equivalent to <code>index.js</code> file in normal Next js applications. Go ahead and rename the <code>home.jsx</code> to <code>index.jsx</code> . You will see the default 404 page of Next js in the window.</p>
<p>To make this thing correct, we will navigate to the <code>background.js</code> file under the <code>main</code> folder and change the following lines:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672849258797/b16c43a9-4af0-481d-a87f-e56dd24a0646.png" alt class="image--center mx-auto" /></p>
<p>Now, the renderer folder looks exactly like that of a new Next Js app.</p>
<p>Let's start coding 🫡🫡</p>
<h1 id="heading-what-are-we-making">What are we making</h1>
<p>We will be making a simple javascript code editor. Here's a preview</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672916721834/283489cd-37b1-4dcd-9a7f-dd4f6688a259.gif" alt class="image--center mx-auto" /></p>
<h1 id="heading-coding-the-app">Coding the app</h1>
<p>Paste this code in the <code>app.jsx</code> file so that the layout looks pretty 💘</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">"../styles/globals.css"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MyApp</span>(<span class="hljs-params">{ Component, pageProps }</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-gray-700 max-w-screen min-h-screen text-white"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Component</span> {<span class="hljs-attr">...pageProps</span>} /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> MyApp;
</code></pre>
<p>Now go to the <code>global.css</code> file in the styles folder and remove everything except these</p>
<pre><code class="lang-css"><span class="hljs-keyword">@tailwind</span> base;
<span class="hljs-keyword">@tailwind</span> components;
<span class="hljs-keyword">@tailwind</span> utilities;
</code></pre>
<p>Now you have your beautiful app layout. Head on to the <code>index.jsx</code> file and remove everything. Then paste the code below</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">"next/head"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Home</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-screen h-screen flex items-center justify-center relative"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Code Editor<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<h2 id="heading-creating-the-code-editor">Creating the code editor</h2>
<p>In this tutorial, we will be utilizing the <code>react-ace</code> library to build a code editor component for our application. So, go ahead and install the <code>react-ace</code> package.</p>
<p>Create a folder named <code>components</code> inside the <code>renderer</code> folder and then create a new file. In my case, it is <code>CodeEditor.js</code> . Below is the given code of that file. To use any other language, you will need to import it using <code>import "ace-builds/src-noconflict/mode-&lt;language&gt;"</code> . Where <code>&lt;language&gt;</code> stands for the language you want to use. Now, for using any other theme, you have to import that using <code>import "ace-builds/src-noconflict/theme-&lt;theme&gt;"</code> .</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> AceEditor <span class="hljs-keyword">from</span> <span class="hljs-string">"react-ace"</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">"ace-builds/src-noconflict/mode-javascript"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"ace-builds/src-noconflict/theme-twilight"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"ace-builds/src-noconflict/ext-language_tools"</span>;

<span class="hljs-keyword">const</span> CodeEditor = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [code, setCode] = useState(<span class="hljs-string">""</span>);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-[90%] md:w-[70%] flex h-max items-center justify-center shadow-xl"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">AceEditor</span>
        <span class="hljs-attr">mode</span>=<span class="hljs-string">"javascript"</span>
        <span class="hljs-attr">theme</span>=<span class="hljs-string">"twilight"</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setCode(e)}
        name="coding_area"
        editorProps={{ $blockScrolling: true }}
        value={code}
      /&gt;
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> CodeEditor;
</code></pre>
<p>Let's import this file into the <code>index.jsx</code> file and see how it looks</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">"next/head"</span>;
<span class="hljs-keyword">import</span> CodeEditor <span class="hljs-keyword">from</span> <span class="hljs-string">"../components/CodeEditor"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Home</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-screen h-screen flex items-center justify-center relative"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Code Editor<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">CodeEditor</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<p>If you stop the server and restart it, you will see this error</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672915864724/11a55ee0-9fa0-4763-97be-5cd3cbebde0e.webp" alt class="image--center mx-auto" /></p>
<p>This is coming due to server-side rendering of Next Js. The <code>window</code> object is only defined in the browser, so if you are trying to start the server on the server-side (e.g., using Node.js), the <code>window</code> object will not be defined.</p>
<p>We have to dynamically import the component inside the directory</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">"next/head"</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">"next/link"</span>;
<span class="hljs-keyword">import</span> dynamic <span class="hljs-keyword">from</span> <span class="hljs-string">"next/dynamic"</span>;

<span class="hljs-comment">// Dynamically importing the component</span>
<span class="hljs-keyword">const</span> Editor = dynamic(<span class="hljs-keyword">import</span>(<span class="hljs-string">"../components/CodeEditor"</span>), { <span class="hljs-attr">ssr</span>: <span class="hljs-literal">false</span> });

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Home</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-screen h-screen flex items-center justify-center relative"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Code Editor<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Editor</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Home;
</code></pre>
<p>Now, restart the server and you will see this beautiful screen</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672916133503/ab4edf48-52bb-483c-bb7c-757eecfab93a.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-styling-the-editor">Styling the Editor</h2>
<p>To customize the code editor, you may want to consider using various props provided by the react-ace library. For a complete list of available props, please see the documentation here: <a target="_blank" href="https://github.com/securingsincity/react-ace/blob/master/docs/Ace.md#available-props"><strong>https://github.com/securingsincity/react-ace/blob/master/docs/Ace.md#available-props</strong></a>. Below, we have provided the code to beautify the editor using some of these props:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// components/CodeEditor.jsx</span>
<span class="hljs-keyword">import</span> React, { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> AceEditor <span class="hljs-keyword">from</span> <span class="hljs-string">"react-ace"</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">"ace-builds/src-noconflict/mode-javascript"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"ace-builds/src-noconflict/theme-twilight"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"ace-builds/src-noconflict/ext-language_tools"</span>;

<span class="hljs-keyword">const</span> CodeEditor = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [code, setCode] = useState(<span class="hljs-string">""</span>);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-[90%] md:w-[70%] flex h-max items-center justify-center shadow-xl"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">AceEditor</span>
        <span class="hljs-attr">mode</span>=<span class="hljs-string">"javascript"</span>
        <span class="hljs-attr">theme</span>=<span class="hljs-string">"twilight"</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setCode(e)}
        name="coding_area"
        editorProps={{ $blockScrolling: true }}
        setOptions={{
          enableBasicAutocompletion: true,
          enableLiveAutocompletion: true,
          enableSnippets: true,
        }}
        showGutter={false}
        className="rounded-lg"
        style={{ width: "100%" }}
        onLoad={(editor) =&gt; {
          editor.renderer.setPadding(20);
          editor.renderer.setScrollMargin(20);
        }}
        maxLines={100000}
        minLines={30}
        wrapEnabled
        value={code}
      /&gt;
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> CodeEditor;
</code></pre>
<p>Your app should look like this if you write the following stuff</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672916522580/611cc823-0c0f-4f76-a52d-1ed9b34ecf59.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-building-the-app-for-your-pc">Building the app for your pc</h1>
<p>Go ahead and paste <code>npm run build</code> or <code>yarn build</code> in your terminal to start the build</p>
<p>A new dist directory has been built at the root of the project. Since I am using windows, it has created a setup.exe file for me. Install it and your app is ready</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>In this article, we walked through the steps of creating a desktop app using Next.js. From setting up a new project and installing the necessary dependencies to customizing the user interface and adding features like syntax highlighting, we covered all the basics of building a desktop app with Next.js. By following these steps, you should now have a solid foundation for creating your desktop apps with Next.js. Whether you are looking to build a simple app for personal use or a more complex app for professional purposes, Next.js provides all the tools you need to get started</p>
]]></content:encoded></item><item><title><![CDATA[Adversarial Search]]></title><description><![CDATA[Introduction
Adversarial search is a type of search algorithm used in artificial intelligence and computer science to find the best move in a two-player game. In an adversarial search, one player (the maximizer) tries to maximize their score while th...]]></description><link>https://tech.roydevelops.tech/adversarial-search</link><guid isPermaLink="true">https://tech.roydevelops.tech/adversarial-search</guid><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[development]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Tue, 03 Jan 2023 20:32:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/3c6256d4f31e3bc5a7a508121c08c3d2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>Adversarial search is a type of search algorithm used in artificial intelligence and computer science to find the best move in a two-player game. In an adversarial search, one player (the maximizer) tries to maximize their score while the other player (the minimizer) tries to minimize the maximizer's score. This is in contrast to non-adversarial search algorithms, which are used to find a solution to a problem without considering the actions of any other player.</p>
<h1 id="heading-where-are-they-used">Where are they used?</h1>
<p>Adversarial search algorithms are commonly used in games such as chess, checkers, and Go, where players take turns making moves and the goal is to win the game. They are also used in other fields, such as finance and military strategy, where there is a need to make decisions in the face of an opposing player.</p>
<p>One of the key components of adversarial search algorithms is the evaluation function, which is used to evaluate the current state of the game and predict the outcome if the game were to continue from that state. The evaluation function takes into account factors such as the number of pieces each player has, their positions on the board, and any potential moves that could be made.</p>
<h1 id="heading-minimax-algorithm">Minimax Algorithm</h1>
<p>One popular adversarial search algorithm is the minimax algorithm, which is a recursive algorithm that explores all possible moves and countermoves in a game tree, evaluating the scores of each possible outcome. The minimax algorithm starts at the root of the game tree and works its way down to the leaf nodes, assigning a score to each node based on the evaluation function. The minimax algorithm then "minimizes" the score of the maximizer's moves and "maximizes" the score of the minimizer's moves, leading to an optimal move for the maximizer.</p>
<h1 id="heading-alpha-beta-pruning">Alpha Beta Pruning</h1>
<p>Another popular adversarial search algorithm is the alpha-beta pruning algorithm, which is a variant of the minimax algorithm that reduces the number of nodes that need to be evaluated by "pruning" the game tree. The alpha-beta pruning algorithm uses two values, alpha and beta, to keep track of the minimum and maximum scores that the maximizer and minimizer can achieve, respectively. If the alpha value becomes greater than the beta value, the algorithm can prune the remainder of the game tree, as it is no longer possible for the maximizer to achieve a better score.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Adversarial search algorithms are a powerful tool for finding the optimal move in two-player games, but they can be computationally expensive, as they require the evaluation of a large number of possible moves and countermoves. However, with advances in computer hardware and optimization techniques, adversarial search algorithms have become increasingly efficient and are now commonly used in a variety of applications.</p>
]]></content:encoded></item><item><title><![CDATA[Terms and Basic Search Algorithms of Artificial Intelligence]]></title><description><![CDATA[If you are in this blog, you must know what Artificial Intelligence is so I am not going to waste time on those basic kinds of stuff. I would like to tell you some prerequisites before you dive deep into this article.

You must know the fundamentals ...]]></description><link>https://tech.roydevelops.tech/terms-and-basic-search-algorithms-of-artificial-intelligence</link><guid isPermaLink="true">https://tech.roydevelops.tech/terms-and-basic-search-algorithms-of-artificial-intelligence</guid><category><![CDATA[AI]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[development]]></category><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Wed, 28 Dec 2022 16:37:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1672245367645/22f44564-5802-4592-a49f-7aff8b42a357.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are in this blog, you must know what Artificial Intelligence is so I am not going to waste time on those basic kinds of stuff. I would like to tell you some prerequisites before you dive deep into this article.</p>
<ul>
<li>You must know the fundamentals of programming i.e loops, functions, classes etc.</li>
</ul>
<p>That's it. If you know that basic stuff, then its completely alright and you can follow along</p>
<h1 id="heading-starting-with-an-example">Starting with an example</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672158598302/e15ebffb-4020-4b78-82c8-351c69ad19ec.png" alt class="image--center mx-auto" /></p>
<p>5 points denoting 5 places are marked over here named A, B, C, D, E. The arrows represent the directions.</p>
<ul>
<li><p>If you are at B, you can move to C only.</p>
</li>
<li><p>You can't move back to A. If you are at D, you can only move to E, not any other place.</p>
</li>
</ul>
<p>Now, let's say you want to move from A to E. You have 2 paths to go from A to E: One via B (let's call it <code>Path 1</code>) and other via D (let's call it <code>Path 2</code>).</p>
<p>Considering that equal distances are present between any 2 points, it is clear that you would move using <code>Path 2</code> cuz' it will take less energy.</p>
<p>There are some basic elements of AI that you need to know:</p>
<h1 id="heading-elements-of-ai-or-01">Elements of AI | 01</h1>
<p><strong>Agent:</strong> It is an entity that acts upon a given environment. In this case, since you are walking from A to E, so you are the <code>agent</code>.</p>
<p><strong>State:</strong> It is the environment in which the <code>agent</code> is present. In this case, the network of the 5 places, is the <code>state</code>.</p>
<p><strong>Initial State:</strong> It is the initial environment from where the <code>agent</code> starts. Here, if you are standing at point A, it is the <code>initial state</code>.</p>
<p><strong>Actions:</strong> It is the set of choices that can be made in a given state. If you are at B, the set of actions will contain just one action i.e <code>{move from B to C}</code> . If you are at A, the set of actions will contain 2 actions i.e <code>{move from A to B, move from A to D}</code> .</p>
<pre><code class="lang-plaintext">ACTIONS(state) -&gt; returns a set of actions that can be performed in a given state
</code></pre>
<p>Now, after you perform an <code>action</code> in a given state, your <code>state</code> has changed. So, the computer must have something to determine the state change. Here's where a <strong>Transition Model</strong> comes into light.</p>
<p>The <code>Transition Model</code> is a function that returns the result after a particular action is performed in a particular state. It takes in <code>state</code> and <code>action</code> as its arguments.</p>
<pre><code class="lang-plaintext">RESULT(state, action) -&gt; returns the resulting state
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672160237067/129d7f30-d163-45f7-8cda-a3369c461299.png" alt class="image--center mx-auto" /></p>
<p>In the picture, you are at point A and you perform an action <code>move from A to B</code> . You will get this resulting state 👇</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1672160353456/d563136f-8ea9-4db0-93bf-0ed1ac750066.png" alt class="image--center mx-auto" /></p>
<p>Now, let's say you have reached your goal. There must be a sort of test to determine that right? As a human, you know that you reached your goal but for a computer, the instruction must be given if it has reached its goal or not. That's why we do a <strong>Goal Test</strong> to determine if the AI has reached its goal or not.</p>
<p>There were 2 ways to go from A to E, right? But why did you choose the 2nd path? It is because it took less energy. A computer should take the 2nd path so that it takes less computing power. The numerical cost associated with a given path is known as <strong>Path Cost</strong>.</p>
<p>Now there were 2 <code>set of actions</code> that leads you to the goal. This set of actions that lead the agent to the goal state is called <strong>the Solution</strong></p>
<p><strong>The Optimal Solution</strong> is the solution with the lowest path cost. In this case, <code>Path 2</code> is the path with the lowest path cost so it is the Optimal Solution to this problem</p>
<p>So, <strong>Search Problems</strong> are the problems in which an <code>agent</code> is present which starts from an <code>initial state</code> and the AI finds the <code>Optimal Solution</code> for that agent to reach its <code>goal</code></p>
<h1 id="heading-solving-search-problems">Solving Search Problems</h1>
<p>In a search problem, data is stored in a node. It is a data structure that holds information that is important to the AI. A node contains:</p>
<ul>
<li><p>A state</p>
</li>
<li><p>Its parent node: The node through which the current node was generated</p>
</li>
<li><p>The action: That was applied to the parent to get to the current node</p>
</li>
<li><p>The path cost from the initial state to this node</p>
</li>
</ul>
<h2 id="heading-algorithm">Algorithm</h2>
<ol>
<li><p>Start with a frontier containing the initial state and an empty set of explored items</p>
</li>
<li><p>REPEAT UNTIL THE GOAL IS REACHED</p>
<ul>
<li><p>if the frontier is empty:</p>
<ul>
<li>return None as there are no solutions.</li>
</ul>
</li>
<li><p>else:</p>
<ul>
<li><p>Remove a node from the frontier. We will store this node in a variable (let's say the variable is <code>checking_node</code>) for checking.</p>
</li>
<li><p>If the <code>checking_node</code> is the goal then return the <code>solution</code>.</p>
</li>
<li><p>else:</p>
<ul>
<li><p>If the <code>checking_node</code> is not present in the explored set then find all the <code>nodes</code> that can be reached through that node and add them to the frontier.</p>
</li>
<li><p>Then add the current node to the explored set.</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="heading-removing-the-node-from-frontier">Removing the node from frontier</h2>
<p>The Frontier is just a data structure where nodes get added and removed. But there are choices by which these nodes get removed.</p>
<p>We can either use Stack as the data structure for the Frontier or we can use Queue as a data structure for the frontier. If we are using stack, we will be using <code>breadth-first search</code> on the other hand, if we are using a queue, we will be using <code>depth-first search</code>.</p>
<h3 id="heading-depth-first-search-dfs">Depth First Search (DFS)</h3>
<p>For performing DFS, we treat the frontier as a <code>stack</code>. We add nodes at the last and we remove the last added node from the frontier.</p>
<p><strong>The paragraph written below is taken form:</strong> <a target="_blank" href="https://cs50.harvard.edu/ai/2020/notes/0/">https://cs50.harvard.edu/ai/2020/notes/0/</a></p>
<p>Take a situation where you are looking for your keys. In a <em>depth-first</em> search approach, if you choose to start with searching in your pants, you’d first go through every single pocket, emptying each pocket and going through the contents carefully. You will stop searching in your pants and start searching elsewhere only once you will have completely exhausted the search in every single pocket of your pants.</p>
<h3 id="heading-breadth-first-search-bfs">Breadth First Search (BFS)</h3>
<p>For using BFS, we treat the frontier as a <code>queue</code>. We add nodes at the last and we remove the 1st node that was previously added.</p>
<p><strong>The paragraph written below is taken form:</strong> <a target="_blank" href="https://cs50.harvard.edu/ai/2020/notes/0/">https://cs50.harvard.edu/ai/2020/notes/0/</a></p>
<p>Suppose you are in a situation where you are looking for your keys. In this case, if you start with your pants, you will look in your right pocket. After this, instead of looking at your left pocket, you will take a look in one drawer. Then on the table. And so on, in every location, you can think of. Only after you will have exhausted all the locations will you go back to your pants and search in the next pocket.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>There are more kinds of search algorithms like Greedy Breadth First Search and A* search. In the next article, we will look at <strong>Adversarial Search</strong></p>
]]></content:encoded></item><item><title><![CDATA[Facing the valley of disappointment: Dev Retro 2022]]></title><description><![CDATA[I generally look at how others write then I try to inherit some of their writing styles. But since this is my journey, I am gonna write it myself completely.
The Start of the Year
The start of the year was pretty wonderful, I was in class 10th and I ...]]></description><link>https://tech.roydevelops.tech/facing-the-valley-of-disappointment-dev-retro-2022</link><guid isPermaLink="true">https://tech.roydevelops.tech/facing-the-valley-of-disappointment-dev-retro-2022</guid><category><![CDATA[#DevRetro2022]]></category><category><![CDATA[Developer]]></category><category><![CDATA[development]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Tue, 27 Dec 2022 07:50:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/9bc6dc5ab90b6c8f0b910de7cdd42473.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I generally look at how others write then I try to inherit some of their writing styles. But since this is my journey, I am gonna write it myself completely.</p>
<h1 id="heading-the-start-of-the-year">The Start of the Year</h1>
<p>The start of the year was pretty wonderful, I was in class 10th and I had seen hype in the crypto space. So, I started learning about web3. Learned solidity, made a few projects and then participated in Thirdweb hashnode hackathon. Learned new things <strong>but never shared</strong>.</p>
<p>To be very honest, I did it because of the prize. I had never participated in any hackathon before and didn't even earn a penny from programming. So, I thought that I will just participate, make a product and win the prize.</p>
<p>Life gave me a lemon, but I couldn't make lemonade out of it. When I couldn't win the prize, I just didn't feel like participating in any other hackathon</p>
<h1 id="heading-reality-hit-hard">Reality hit hard</h1>
<p>I worked very hard for my 10th CBSE board exam. After the board exam was over, I got a freelance client who paid $ 120 for an NFT project. That project was on the Solana Blockchain and I learned a lot again <strong>but I never shared my learnings.</strong></p>
<p>I was very happy and thought that class 11th will be easy for me. But I never knew the other side of hard work. I never knew what a mental breakdown was and I never really knew what happens when no expectations get fulfilled.</p>
<p>I was getting bad grades despite working very hard. There was a huge rise in the syllabus and I couldn't handle it at first</p>
<h1 id="heading-couldnt-stay-consistent">Couldn't stay consistent</h1>
<p>I couldn't consistently post about my learnings on social media platforms. I started using Twitter but I don't even have 50 followers today. I just have 1 follower in my hashnode as of today.</p>
<p>I don't know why I didn't post and I don't want to waste my thinking of it too. I just know that in the coming year I have to be consistent so that I can break out of this valley of regret.</p>
<hr />
<h1 id="heading-my-development-journey">My Development journey</h1>
<p>The only thing which kept me alive and gave me pleasure in this valley of regret is coding. I can code for hours without thinking of anything. I did get to hear a lot of taunts from my parents for this cuz' my school academics were not great like that of 10th but I really don't care about that now.</p>
<h3 id="heading-web-3">Web 3</h3>
<p>I learned solidity, did freelancing and did get a decent amount of money.</p>
<p>Then I started learning Rust for Solana blockchain. I found that Solana was faster than Ethereum and had very less gas fees. Found out that <a target="_blank" href="https://buildspace.so/">buildspace</a> was the perfect place for learning that. But after a couple of months, I didn't feel like doing it anymore so I left it and started building apps with what I knew.</p>
<h3 id="heading-data-structures-and-algorithms">Data Structures and Algorithms</h3>
<p>I started learning DSA from LearnCodeOnline didn't complete the full course but I learned a lot</p>
<p>DSA is like a fundamental building block. Once you know DSA, it will improve your logic-building skills immensely. I don't know everything about DSA but I have found immense progress in my logic-building skills after learning a few concepts of DSA.</p>
<h3 id="heading-making-apps">Making Apps</h3>
<p>I knew how to make web apps with MERN stack and mobile apps with React Native. But I thought why stop at that I learned NextJs and Prisma. As of today, I can make full-stack apps easily</p>
<hr />
<h1 id="heading-my-current-state">My current state</h1>
<p>I still am in a valley of disappointment. But I will implement my learnings from this year so that I can make myself better. I am currently learning about Artificial Intelligence parallelly to learning DSA. This blog will stay as a reminder to me. It will remind me about what to do next</p>
<h3 id="heading-my-learnings-to-implement">My Learnings to implement</h3>
<ul>
<li><p>I will share what I learn</p>
</li>
<li><p>I will stop putting expectations in everything</p>
</li>
<li><p>I am starting today</p>
</li>
<li><p>I will make a plan for the next day before every night (started this at the start of this month)</p>
</li>
<li><p>I will go out for a walk for 30 mins thinking about "how can I make this day better" every day (started this at the start of this month)</p>
</li>
</ul>
<h1 id="heading-quote-for-me">Quote for me</h1>
<blockquote>
<p>The best time to start a new thing was in the past</p>
<p>But the second best time is now</p>
</blockquote>
<h1 id="heading-conclusion">Conclusion</h1>
<p>If you want to put up some suggestions, then please put them up. This year, I faced hard situations but I have learned from them. Now, I can successfully avoid these traps and make myself better. And yes, I don't expect to win prizes in Dev Retro 2022 😊</p>
]]></content:encoded></item><item><title><![CDATA[Space Complexity: Measure your Code Performance | DSA 002]]></title><description><![CDATA[In my previous article I wrote about time complexity. A way to measure code with respect to growing size of inputs.
Time complexity is basically the relation between input size and running time
Think About It
You obviously have apps in your phone. Yo...]]></description><link>https://tech.roydevelops.tech/space-complexity-measure-your-code-performance-dsa-002</link><guid isPermaLink="true">https://tech.roydevelops.tech/space-complexity-measure-your-code-performance-dsa-002</guid><category><![CDATA[Python]]></category><category><![CDATA[DSA]]></category><category><![CDATA[education]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Mon, 22 Aug 2022 01:48:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661132717013/dAHp9diY6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In my <a target="_blank" href="https://tech.snehenduroy.in/time-complexity-dsa-001">previous article</a> I wrote about time complexity. A way to measure code with respect to growing size of inputs.</p>
<p>Time complexity is basically the relation between input size and running time</p>
<h2 id="heading-think-about-it">Think About It</h2>
<p>You obviously have apps in your phone. You are most likely to prefer the ones which takes less time to load the data and consumes less space. The factor which is used to measure the time is related to time complexity. But what about the space? How do we measure the space used by a code?</p>
<h2 id="heading-space-complexity">Space Complexity</h2>
<p>The relation between the input size and memory consumed in your system.</p>
<p>If you want your code to be optimized, it should take less time and less space too. So, here's where space complexity comes in place cause this is the way to measure how much space your code will take</p>
<h2 id="heading-calculating-space-complexity">Calculating Space Complexity</h2>
<p>The space used by a code depends on how many variables are used. The more variables, the more space used.</p>
<p>How much memory consumed by a code is directly proportional to how many variables assigned</p>
<pre><code>sum <span class="hljs-operator">=</span> <span class="hljs-number">0</span>
i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>
<span class="hljs-keyword">while</span> (i <span class="hljs-operator">&lt;</span> <span class="hljs-number">24</span>):
    sum <span class="hljs-operator">+</span><span class="hljs-operator">=</span> i
    i <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">1</span>
print(sum)
</code></pre><p>Here, there are 2 variables which we are assigning to the memory that is <code>i</code> and <code>sum</code>. Now, no matter the the value of sum increases the memory used by that one variable would be the same. So, the space complexity for this code will be O(1)</p>
<p>Now, let's take the example of arrays. It is basically a data structure which stores a list of elements. We will talk about arrays deeply later</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_array</span>(<span class="hljs-params">n</span>):</span>
    a = []
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(n):
        a.append(i)
    <span class="hljs-keyword">return</span> a
</code></pre><p>In this function, we take integer <code>n</code> as an input. Then we create an array. Using  the loop we store the numbers 0 to n-1 in the array. Then we return it. So, basically what we are doing is, we are generating a series of numbers and storing it in an array. Here, with the increasing size of input, the space used by the code also increases. So, the space complexity for this code is O(n)</p>
<p>You can check the size here:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661132360161/rGfHfR_yL.png" alt="Screenshot 2022-08-22 070900.png" /></p>
<p><strong><code>sys.getsizeof()</code> gives out the size of a particular function, class, variable etc. in python</strong></p>
<p><strong>I really hope you understood, if you didn't then feel free to criticize in the comment section. It's okay to criticize if I have wasted your valuable time. Also if you have any doubts, feel free to put it up in the comments section</strong></p>
]]></content:encoded></item><item><title><![CDATA[Time Complexity | DSA 001]]></title><description><![CDATA[Ways to calculate code performance
Approach 1: Time based approach
calculateTime()
function fancyName(){
   do something
}
calculateTimeDifference()
In this approach of judging code, before running a chunk of code, the initial time is taken and after...]]></description><link>https://tech.roydevelops.tech/time-complexity-dsa-001</link><guid isPermaLink="true">https://tech.roydevelops.tech/time-complexity-dsa-001</guid><category><![CDATA[Python]]></category><category><![CDATA[DSA]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[education]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Sat, 20 Aug 2022 03:39:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661130311081/_cDBaAeY0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-ways-to-calculate-code-performance">Ways to calculate code performance</h2>
<h3 id="heading-approach-1-time-based-approach">Approach 1: Time based approach</h3>
<pre><code>calculateTime()
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fancyName</span>(<span class="hljs-params"></span>)</span>{
   <span class="hljs-keyword">do</span> something
}
calculateTimeDifference()
</code></pre><p>In this approach of judging code, before running a chunk of code, the initial time is taken and after running that code, the final time is taken. Then when the final time is subtracted from initial time, we get the how much time was required for processing of the code. </p>
<p>This method of calculating code performance is rated as average but still this approach is used hugely to judge code</p>
<h4 id="heading-problems-in-approach-1">Problems in Approach 1:</h4>
<ul>
<li>It is based on machine: Depends from processor to processor</li>
<li>It is based on processing: Depends on the processing power of your PC</li>
</ul>
<h3 id="heading-approach-2">Approach 2:</h3>
<p>Counting the number of operations in a code. Technically, this literally means that we are going to count the number of operations in a code.</p>
<p><strong>Count Operation in the code below</strong>
<code>a = a + 1</code></p>
<p>If you said there is one operation, you are wrong my friend. There are actually 2 operator: "=" and "+"</p>
<p>Now, count the operation in this code</p>
<pre><code>sum <span class="hljs-operator">=</span> <span class="hljs-number">0</span>
winner <span class="hljs-operator">=</span> <span class="hljs-number">1</span>
<span class="hljs-keyword">for</span> (i <span class="hljs-operator">=</span> <span class="hljs-number">1</span>; i <span class="hljs-operator">&lt;</span> n; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>){
  sum <span class="hljs-operator">=</span> sum<span class="hljs-operator">+</span><span class="hljs-number">1</span>
}
</code></pre><p>Notice closely, that there are several operators. In total, there is 3 "="s, 1 "&lt;", then in <code>i++</code>, there are actually 2 operators which are responsible to increment the value of i, <code>i++</code> can be written as <code>i = i+1</code>, so in <code>i++</code> there are 2 operators. Then inside the loop there are 2 operators: "=" and "+"</p>
<p>But, in this code, apart from <code>sum = 0</code>, <code>winner = 1</code>, <code>i=1</code>, all the other operators are dependent on the variable <code>n</code>. So, there are 3 constant operators, and 5 operators which varies with the value of <code>n</code>. Thus there are 3+5n operators</p>
<h2 id="heading-big-o">Big O</h2>
<p>The whole way of measuring code with number of operators is known as Big O. </p>
<p><strong>Code 1</strong></p>
<pre><code>sum <span class="hljs-operator">=</span> <span class="hljs-number">0</span>
i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>
<span class="hljs-keyword">while</span> (i <span class="hljs-operator">&lt;</span> n):
    sum <span class="hljs-operator">+</span><span class="hljs-operator">=</span> i
    i <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">1</span>
print(sum)
</code></pre><p>In this given code, there are 5n+2 operators. </p>
<p>Now, coming to the complexity of the code: To measure the complexity of the code, the constants are to be ignored. </p>
<p>So O(n) [Said as O of n] is the complexity</p>
<p><strong>Code 2</strong></p>
<pre><code><span class="hljs-keyword">for</span> (<span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>):
  <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>
  <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>
<span class="hljs-keyword">for</span> (<span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>):
  <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>
  <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>
</code></pre><p>You might think that the complexity of the above code is 2O(n) and that's completely correct. But since the constants are to be ignored, so the complexity will be O(n).</p>
<p><strong>Code 3</strong></p>
<pre><code><span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&lt;</span> N; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
  <span class="hljs-keyword">for</span> (let j <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; j <span class="hljs-operator">&lt;</span> N; j<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
    sum<span class="hljs-operator">+</span><span class="hljs-operator">=</span>j
  }
}
</code></pre><p>In the above code, O(n) is inside another O(n). Thus, the complexity of the code becomes O(n^2). If the nested loop would run on a constant and not on N, the complexity would not be O(n^2). </p>
<h3 id="heading-complexity-notation">Complexity Notation</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Code Complexity</td><td>Notation</td><td>Note</td></tr>
</thead>
<tbody>
<tr>
<td>O(10), O(1000) O(k), 3O(k) kO(k)</td><td>O(1)</td><td>"k" is some constant</td></tr>
<tr>
<td>O(3n), O(4n+100000)</td><td>O(n)</td><td>Constants are to be ignored</td></tr>
<tr>
<td>O(3n^2), O(4n^2+100000)</td><td>O(n^2)</td><td>Constants are to be ignored</td></tr>
<tr>
<td>O(3n^2), O(4n^2 + 3n + 4)</td><td>O(n^2)</td><td>Since with increasing value of n, the value of n^2 will become much higher than theat of n, so n can be ignored, incase of cubic equations,the complexity will be O(n^3) and so on</td></tr>
</tbody>
</table>
</div><p><img src="https://miro.medium.com/max/1400/1*yiyfZodqXNwMouC0-B0Wlg.png" alt="Complexity time graph" /></p>
<p>This graph shows the time for complexity of code with increasing input.</p>
]]></content:encoded></item><item><title><![CDATA[Introduction to Data Structures and Algorithms | 000]]></title><description><![CDATA[I am going to call Data Structures and Algorithms as DSA
Code written is in Python
Why DSA?
The main moto to learn DSA is to know how to write optimized code. In this age of Cloud Functions, the optimized code requires less money as less computation ...]]></description><link>https://tech.roydevelops.tech/introduction-to-data-structures-and-algorithms-000</link><guid isPermaLink="true">https://tech.roydevelops.tech/introduction-to-data-structures-and-algorithms-000</guid><category><![CDATA[Python]]></category><category><![CDATA[data structures]]></category><category><![CDATA[Problem Solving]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Wed, 17 Aug 2022 01:06:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660698228986/uB5cE4VDq.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>I am going to call Data Structures and Algorithms as DSA</strong>
<strong>Code written is in Python</strong></p>
<h2 id="heading-why-dsa">Why DSA?</h2>
<p>The main moto to learn DSA is to know how to write optimized code. In this age of <em>Cloud Functions</em>, the optimized code requires less money as less computation and memory is used in the servers. On the other hand if you don't write optimized code, you will have to pay more money and also the results from the cloud servers would be very slow.</p>
<h2 id="heading-judging-code">Judging code</h2>
<p>Now you know that writing optimized code would save your time. But how will you judge if a code is optimized or not? 
Many people say that the less number of lines means the more optimized code. But this is a true lie. Optimized code can't be judged by the number of lines but the parameters involved in the code. Judge this case:</p>
<p><strong>Problem Statement</strong>: Generate a series of number from 1 to n and store it in a variable or function so that it can be accessed later</p>
<p>Code 1:</p>
<pre><code>def gen_series():
    a <span class="hljs-operator">=</span> []
    n <span class="hljs-operator">=</span> <span class="hljs-keyword">int</span>(input(<span class="hljs-string">"What's n? "</span>))
    <span class="hljs-keyword">for</span> i in range(<span class="hljs-number">1</span>, n<span class="hljs-operator">+</span><span class="hljs-number">1</span>):
        a.append(i)
    <span class="hljs-keyword">return</span> a

def print_series():
    a <span class="hljs-operator">=</span> gen_series()
    <span class="hljs-keyword">for</span> i in a:
        print(i)

<span class="hljs-keyword">if</span> __name__ <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    print_series()
</code></pre><p>Code 2:</p>
<pre><code>def gen_series():
    n <span class="hljs-operator">=</span> <span class="hljs-keyword">int</span>(input(<span class="hljs-string">"What's n? "</span>))
    a <span class="hljs-operator">=</span> series(n)
    print(a)
    <span class="hljs-keyword">return</span> a

def print_series():
    a <span class="hljs-operator">=</span> gen_series()
    <span class="hljs-keyword">for</span> i in a:
        print(i)

def series(n):
    d <span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">for</span> i in range(<span class="hljs-number">1</span>, n<span class="hljs-operator">+</span><span class="hljs-number">1</span>):
        yield i <span class="hljs-operator">+</span> d
        d <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">11</span>

<span class="hljs-keyword">if</span> __name__ <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    print_series()
</code></pre><p>If you count the number of lines, you would say Code 1 is more optimized but is it?</p>
<p>In both the cases the series is generated and stored inside the function named <code>gen_series()</code>. If you know about the <code>sys.getsizeof()</code> method in python, you will know that it gives out the memory used inside a variable, function. If you write this in your code editor, run the program, and enter 200 as the input of <code>What's n?</code></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">sys</span>


<span class="hljs-title">def</span> <span class="hljs-title">gen_series</span>():
    <span class="hljs-title">a</span> <span class="hljs-operator">=</span> []
    <span class="hljs-title">n</span> <span class="hljs-operator">=</span> <span class="hljs-title"><span class="hljs-keyword">int</span></span>(<span class="hljs-title">input</span>(<span class="hljs-string">"What's n? "</span>))
    <span class="hljs-title"><span class="hljs-keyword">for</span></span> <span class="hljs-title">i</span> <span class="hljs-title">in</span> <span class="hljs-title">range</span>(1, <span class="hljs-title">n</span><span class="hljs-operator">+</span>1):
        <span class="hljs-title">a</span>.<span class="hljs-title">append</span>(<span class="hljs-title">i</span>)
    <span class="hljs-title"><span class="hljs-keyword">return</span></span> <span class="hljs-title">a</span>


<span class="hljs-title">def</span> <span class="hljs-title">print_series</span>():
    <span class="hljs-title">a</span> <span class="hljs-operator">=</span> <span class="hljs-title">gen_series</span>()
    <span class="hljs-title"><span class="hljs-keyword">for</span></span> <span class="hljs-title">i</span> <span class="hljs-title">in</span> <span class="hljs-title">a</span>:
        <span class="hljs-title">print</span>(<span class="hljs-title">i</span>)


<span class="hljs-title"><span class="hljs-keyword">if</span></span> <span class="hljs-title">__name__</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    <span class="hljs-title">print</span>(<span class="hljs-title">sys</span>.<span class="hljs-title">getsizeof</span>(<span class="hljs-title">gen_series</span>()))
</code></pre><p>You will get the memory used in bytes. And surprisingly, you will notice that the 2nd code consumes less memory.</p>
<p>So, we can come to a conclusion that less code always doesn't mean optimized code. For a code to be judged, the parameters are important.</p>
<h2 id="heading-programming-language">Programming Language</h2>
<p>DSA is mostly independent of programming language the main things which matter are the concepts. I'll be using python in the next articles regarding DSA</p>
]]></content:encoded></item><item><title><![CDATA[What are Generators | Advance Python]]></title><description><![CDATA[Starting Note
Before reading this blog, I want to make a clear statement that this blog is written completely based on my understanding about how generators work in python. To move forward, you must be an intermediate in python.
Iterators
An object t...]]></description><link>https://tech.roydevelops.tech/what-are-generators-advance-python</link><guid isPermaLink="true">https://tech.roydevelops.tech/what-are-generators-advance-python</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[advanced]]></category><dc:creator><![CDATA[Snehendu Roy]]></dc:creator><pubDate>Thu, 11 Aug 2022 04:33:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660192073774/sYY49shB9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-starting-note">Starting Note</h1>
<p>Before reading this blog, I want to make a clear statement that this blog is written completely based on my understanding about how generators work in python. To move forward, you must be an intermediate in python.</p>
<h1 id="heading-iterators">Iterators</h1>
<p>An object that contains countable number of values. The next value can be accessed with the <code>next(object_name)</code> parameter</p>
<p>You can know more about iterators here: <a target="_blank" href="https://www.w3schools.com/python/python_iterators.asp">Iterators by W3 Schools</a></p>
<h1 id="heading-case">Case</h1>
<p>Let's say you are working in a company and your company gives you a task to write a program to find a series of numbers. Each number having a difference of 12 from the previous. So the series is like: [12,24,36,48.....]</p>
<p>You have to find the series till a number given by the user and store the results somewhere so that others get those values using a loop. </p>
<p>So, if the user enters 10, the program will return a series like: <strong>12,24,36,........,120</strong></p>
<p>You will be like: <em>Okay that's easy</em></p>
<pre><code>def gen_series():
    n <span class="hljs-operator">=</span> <span class="hljs-keyword">int</span>(input(<span class="hljs-string">"What's n? "</span>))
    a <span class="hljs-operator">=</span> []
    d <span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">for</span> i in range(<span class="hljs-number">1</span>, n<span class="hljs-operator">+</span><span class="hljs-number">1</span>):
        a.append(i <span class="hljs-operator">+</span> d)
        d <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">return</span> a

<span class="hljs-keyword">if</span> __name__ <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    print(gen_series())
</code></pre><p>Now, your program works nicely if the user inputs numbers like 12, 23, 89, 74.</p>
<p>If you test this code yourself and you enter a number like 1000000000000000 then what happens?
Your code starts to hang, the program doesn't work smoothly. So, this is not the best approach to get a series of numbers.</p>
<p><strong>Let's refactor this code a bit</strong></p>
<pre><code>def gen_series():
    n <span class="hljs-operator">=</span> <span class="hljs-keyword">int</span>(input(<span class="hljs-string">"What's n? "</span>))
    a <span class="hljs-operator">=</span> series(n)
    print(a)

def series(n):
    a <span class="hljs-operator">=</span> []
    d <span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">for</span> i in range(<span class="hljs-number">1</span>, n<span class="hljs-operator">+</span><span class="hljs-number">1</span>):
        a.append(i <span class="hljs-operator">+</span> d)
        d <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">return</span> a

<span class="hljs-keyword">if</span> __name__ <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    gen_series()
</code></pre><p>Now, the program runs the same but our problem is not yet solved. We want to generate a series of numbers with each number having a difference of 12 from the previous and we want our program to generate as much numbers as we want.</p>
<p>Try to run this code:</p>
<pre><code>def gen_series():
    n <span class="hljs-operator">=</span> <span class="hljs-keyword">int</span>(input(<span class="hljs-string">"What's n? "</span>))
    a <span class="hljs-operator">=</span> series(n)
    print(a)


def series(n):
    d <span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">for</span> i in range(<span class="hljs-number">1</span>, n<span class="hljs-operator">+</span><span class="hljs-number">1</span>):
        yield i <span class="hljs-operator">+</span> d
        d <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">11</span>


<span class="hljs-keyword">if</span> __name__ <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    gen_series()
</code></pre><p>If you run this code and input a number as 20, you will see the output as <code>&lt;generator object series at 0x0000020B20684350&gt;</code>. Now, if you run again, and input a big number such as 1000000000000000, you will notice that your program doesn't lag. It works perfectly fine and you get the output.</p>
<p>The <code>yield</code> keyword is responsible to make this function a generator.</p>
<p>The <code>series</code> function is now a generator function which generates an iterator. If you have read the article of <a target="_blank" href="https://www.w3schools.com/python/python_iterators.asp">W3 Schools</a>, you will certainly know that we can easily access the values from an iterator using a loop. </p>
<p>So, here's the definition of generators</p>
<h3 id="heading-generators">Generators</h3>
<p>Generators are those kind of functions that return an iterator.</p>
<h1 id="heading-back-to-program">Back to program</h1>
<p>Now to print the values of the series we can use another function</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">print_series</span>():</span>
    a = gen_series()
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> a:
        print(i)
</code></pre><p>The complete code:</p>
<pre><code>def gen_series():
    n <span class="hljs-operator">=</span> <span class="hljs-keyword">int</span>(input(<span class="hljs-string">"What's n? "</span>))
    a <span class="hljs-operator">=</span> series(n)
    print(a)
    <span class="hljs-keyword">return</span> a


def print_series():
    a <span class="hljs-operator">=</span> gen_series()
    <span class="hljs-keyword">for</span> i in a:
        print(i)


def series(n):
    d <span class="hljs-operator">=</span> <span class="hljs-number">11</span>
    <span class="hljs-keyword">for</span> i in range(<span class="hljs-number">1</span>, n<span class="hljs-operator">+</span><span class="hljs-number">1</span>):
        yield i <span class="hljs-operator">+</span> d
        d <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">11</span>


<span class="hljs-keyword">if</span> __name__ <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"__main__"</span>:
    print_series()
</code></pre><h1 id="heading-conclusion">Conclusion</h1>
<ul>
<li>Generators are functions that return an iterator</li>
<li>We can turn a normal function to generator by using the <code>yield</code> keyword</li>
</ul>
<p><strong>If you didn't understand then don't forget to criticize me in the comments. That will help me to come up with a better explanation. It is okay to criticize me if I have wasted your time. Also if you have any questions, please ask me in the comments</strong></p>
]]></content:encoded></item></channel></rss>