<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ansak Mahir on Medium]]></title>
        <description><![CDATA[Stories by Ansak Mahir on Medium]]></description>
        <link>https://medium.com/@mohamedansak?source=rss-913c82715aff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jrTrD-EZCVtMmtcG</url>
            <title>Stories by Ansak Mahir on Medium</title>
            <link>https://medium.com/@mohamedansak?source=rss-913c82715aff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:53:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohamedansak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding out endianness using a C program]]></title>
            <link>https://medium.com/@mohamedansak/finding-out-endianness-using-a-c-program-c524bcdd2e48?source=rss-913c82715aff------2</link>
            <guid isPermaLink="false">https://medium.com/p/c524bcdd2e48</guid>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[little-endian]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[computer-architecture]]></category>
            <dc:creator><![CDATA[Ansak Mahir]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 10:07:33 GMT</pubDate>
            <atom:updated>2026-02-08T10:07:33.956Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n31S2TpJcJFJoewdcgWVNg.png" /></figure><p>The way computers store multiple-byte data in memory differs into two types. Each of them follows a different approach to how data is laid out in memory.<br>1 . Little endian - little endian stores the least significant byte (LSB) first (at the lowest address)<br>2. Big endian - big-endian stores the most significant byte (MSB) first (at the lowest address)</p><p>The advantages and disadvantages of the different methods are out of scope for this article. The real issue arises when you suddenly need to know which one your system is actually using.</p><p>Endianness is usually doesn’t feel important, until one day you’re debugging raw memory, parsing binary data, or sending bytes over the network ( which we will cover in the upcoming posts), and things don’t line up the way you expect. That’s when endianness needs attention.</p><p>Endianness of a system is in accordance with the architecture of a CPU (mostly) so reading a spec sheet will expose the endianness of the system. But in a real memory debugging, no one wants to go back and read specs, that&#39;s where poking memory directly and see what’s going on is better.</p><p>The idea is simple, writing code in a manner that&#39;s predictable to understand which endian is being used by the system. <br>1. Store a number whose byte pattern is easy to predict.<br>2. Look at the <strong>first byte in memory</strong>.<br>3. Decide the endian type using it.</p><p>We’ll use the number 1. Because in binary it looks like this:</p><pre>00000000 00000000 00000000 00000001</pre><p>Only one bit is set, which makes the result very obvious. We used unsigned data types to avoid the sign bit complexity so you do not have to think about it.</p><pre>#include &lt;stdio.h&gt;<br>int main() {<br>    unsigned int x = 1; <br>    unsigned char *c = (unsigned char*)&amp;x;<br><br> if (*c == 1){<br>       printf(&quot;Little Endian\n&quot;);<br> } else {<br>       printf(&quot;Big Endian\n&quot;);<br> }<br><br> return 0;<br>}</pre><p>What the above code does is, it assigns an unsigned integer x to 1. Integer is 4 bytes (in my laptop). Then, we create a unsigned char type pointer and do a explicit casting of the memory address of integer x to char type pointer. In simple words, even though the integer is 4 bytes, the pointer *c is only pointing to 1 byte of memory within that 4 bytes of memory.</p><p>So now, if the system is little endian, as the pointer c is pointing to the first byte (at lowest address), we check the value of that byte to be 1. If its equals to 1, then its simply little endian otherwise its big endian.</p><p>If you need to explicitly check that for big endian, you should change the if condition as <strong>if (*(c+3) == 1)</strong>. If you are not sure about the int size in your laptop, a more portable way would be<strong> if (*(c + sizeof(int) — 1) == 1). </strong>Here is the output on my laptop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3EtDDQyuxB9l30jr-YkX_w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c524bcdd2e48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distance of Data-Designing systems part 1]]></title>
            <link>https://medium.com/@mohamedansak/distance-of-data-designing-systems-part-1-67f191241a58?source=rss-913c82715aff------2</link>
            <guid isPermaLink="false">https://medium.com/p/67f191241a58</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[systems-thinking]]></category>
            <category><![CDATA[fundamentals]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[data-retrieval]]></category>
            <dc:creator><![CDATA[Ansak Mahir]]></dc:creator>
            <pubDate>Thu, 29 Jan 2026 19:18:22 GMT</pubDate>
            <atom:updated>2026-01-29T19:18:22.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIkIKXJR9p-uxdagJ_7p0w.png" /></figure><p>System designing is yet another fundamental area in Engineering. Just as everything in CS, this area has its own engineering principles. when it comes to system design most people usually talk about tools (Load balancer, CDN, cache, distributed cache and what not) than fundamentals.</p><p>The bottom line is, fun of engineering is always in the details that is abstracted away, and knowing it really makes you love computer science as a field and to think better and simple way. One of such fundamental concept is Distance of Data.</p><p>Generally, these days computers are equipped with 3GHz CPU. What it actually means is that a CPU can do 3 billion calculation cycles per second. One calculation cycle means that CPU does a small part of a instruction’s overall operation. In technical terms, what it does is a part of fetch-decode-execute cycle (Yes, the stuff we learned in computer organization &amp; architecture).</p><p>If you’re not familiar with that, you can think of the CPU as performing a “compare these two values” operation in one cycle. The loading of each value happens in different CPU cycles, and loading the operator happens in another cycle, with only the comparison itself occurring in a single cycle.</p><p>Let’s do the math: to find the time of a single CPU cycle, divide 1 second by 3 billion. This gives approximately <strong>0.33 nanoseconds</strong>. That is how tiny an amount of time it takes for a CPU to execute one cycle, performing one small task.</p><p>For comparison purposes, let’s <strong>scale this 0.33 nanoseconds to 1 second</strong>. Now, 1 CPU cycle takes 1 second in our scaled model. Using this as a reference, the time it takes to access data from different sources is approximately:</p><p>CPU Register -&gt; 1 sec<br>L1 cache -&gt; 4 sec<br>Ram -&gt; ~100 sec<br>SSD -&gt; 2–6 days<br>Network RTT -&gt; ~15 years</p><p>If you are building any system, you need to understand that data has distance. You cant treat a local variable the same way you would treat a DB record or a network call. They are orders of magnitude apart in the physical world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67f191241a58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install git-email in Ubuntu 24 and newer versions]]></title>
            <link>https://medium.com/@mohamedansak/how-to-install-git-email-in-ubuntu-24-and-newer-versions-ee25a79c4ce0?source=rss-913c82715aff------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee25a79c4ce0</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[git-email]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ansak Mahir]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 18:01:50 GMT</pubDate>
            <atom:updated>2026-01-22T18:02:43.865Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3a7ZfWtgnCgdcphYzQYEQ.png" /></figure><p>Git-email is a package that let you send email through the git itself. This is widely used by developers who contribute to Linux kernel, PostgreSQL and git itself. These open source projects use email as there way to send patches, review them and discuss about them.</p><p>As I try to install the git-email (As i already have git installed), I ended up in the error “Package git-email is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source”.</p><p>After many unsuccessful attempts, was able to install git-email, below is a simple step by step process to follow</p><p><strong>Step — 1 Add Git PPA</strong><br> sudo add-apt-repository ppa:git-core/ppa<br> sudo apt update</p><p><strong>Step — 2 Install git-email</strong><br> sudo apt install git-email</p><p>That’s it, now you have successfully installed git-email. verify the installation using the command , git send-email --help</p><p>Thanks for following, do comment if you need a help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee25a79c4ce0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Your Network Sometimes Waits Before Speaking : Nagle’s Algorithm]]></title>
            <link>https://medium.com/@mohamedansak/why-your-network-sometimes-waits-before-speaking-nagles-algorithm-0f0305c041bb?source=rss-913c82715aff------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f0305c041bb</guid>
            <category><![CDATA[computer-networking]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[nagles-algorithm]]></category>
            <category><![CDATA[latency-optimization]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Ansak Mahir]]></dc:creator>
            <pubDate>Thu, 15 Jan 2026 11:56:33 GMT</pubDate>
            <atom:updated>2026-01-15T11:56:33.237Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Why Your Network Sometimes Waits Before Speaking : Nagle’s Algorithm</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guW2btNEfKLEJIEEAsYPtw.png" /></figure><p>Nagle’s algorithm is an optimization technique used by network stack in the operating systems to avoid the inefficient bandwidth usage caused by the small packet problem. Even though the algorithm is widely accepted and used (inside Network Stack of the OS), it has become a bottleneck for specific cases. Before moving deeper, we need to touch some parts of OS and networking concepts to understand the whole picture.</p><p>I assume you have some knowledge of computer networks and TCP/IP as I may have missed explaining some jargon. if you’re a beginner, some areas might require querying an AI chatbot for clarification :).</p><p><strong>TCP/IP and Layered Networking</strong></p><p>TCP/IP as a suite or as protocols, is playing a key role for years to provide the core structure for networking. The design decisions embedded in networking protocols often have valid justifications.</p><p>Let’s look a bit about OSI and TCP/IP suite first.</p><figure><img alt="OSI Model vs TCP/IP Model" src="https://cdn-images-1.medium.com/max/1024/1*_OS-IuqeGwKG0l_jHIfUtQ.png" /></figure><p>The OSI model features 7 layers, each with its own specific responsibilities (Take this with a grain of salt). OSI is primarily a conceptual tool for teaching. In practice, the TCP/IP model abstracts this down to just 4 layers. The labels next to each layer in the diagram above show what the data is called at that specific stage (e.g., ‘Segments’ vs. ‘Packets’).</p><p>Our focus here is specifically on the Transport Layer and the Network Layer (known as the Internet Layer in TCP/IP):</p><ul><li><strong>Network Layer (IP):</strong> Handles logical addressing and routing (IP addresses). Its job is to move packets from host to host (While Layer 2 also handles host-to-host communication within a network, IP handles routing across networks), but it operates on a ‘best effort’ basis making no guarantees about delivery or order.</li><li><strong>Transport Layer (TCP):</strong> The Transport layer is built on top of IP layer. It provides end-to-end communication between applications using protocols such as TCP and UDP. This is where Nagle’s <strong>Algorithm</strong> comes to the picture. (Note: Since Nagle’s Algorithm is specific to TCP’s reliability mechanisms, we won’t be discussing UDP in this article).</li></ul><p>As shown in the diagram above, all the data that is being sent by an application is going through those 4 layers (TCP/IP model). Lets have an example of sending a character “H” as a message to a person through whatsapp desktop application. This “H” message needs to go through all those 4 layers before reaching the physical medium to go to the receiver’s side.</p><p>The “H” message becomes a segment in the transport layer (Transport). A segment has its own header (20 bytes). As the packet moves onto layer three, the IP header is another 20 bytes which sums up to 40 bytes of header and 1 byte of data, which means the header is 40 times larger than the data payload.</p><p><a href="https://datatracker.ietf.org/doc/html/rfc896">RFC 896 </a>describes a problem that was coming from the early days of networking. The small packet problem, below is a screenshot of its description</p><figure><img alt="The small packet problem RFC 896" src="https://cdn-images-1.medium.com/max/843/1*cSK0Z3IJ05gAHIvw7jSVNw.png" /></figure><p>Simply put, each TCP/IP protocol based message at the minimum level has 40 bytes of header (Options can heavily influence the header size in IP, for the purpose of this article, let’s assume we’re a bunch of backend developers using frameworks with thousand’s of abstractions [actually, we are] which do not give us the ability to manipulate a packet’s header).</p><p>So the question goes as, does the system actually send a packet with such an enormous amount of wastage (1 byte data and 40 byte headers) ? The answer is “it depends”. Then the question is upon what criteria it depends? simply on the below rules.</p><ol><li>If there is no unacknowledged data (All the data sent are acknowledged), regardless of the new packet’s size, OS will send it immediately</li><li>If there is already unacknowledged data in flight, any new data from the application is buffered locally until we receive the ACK for the previous data, or the buffered data reaches the MSS size.</li></ol><p>Here, MSS means the maximum size of the TCP payload (the pure application data) in a single segment. Do not confuse it with MTU (as I have seen a lot of confusion around these two). For easy reference, mostly MSS will be 1460 bytes (The article will not cover jumbo frames). The “ip link show” command in Linux shows the MTU size of your interfaces (It’s a different topic to manipulate MTUs for high speed on premise systems, will cover if god wills on another day)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*ZOK7a4mB4nUHDpT6nVsK3g.png" /></figure><p><strong>When Nagle’s Algorithm Becomes a Bottleneck</strong></p><p>Nagle’s algorithm becomes a bottleneck in many scenarios. It affects almost all network related activities, but because it introduces delays on the order of milliseconds, its cumulative effect is often overlooked. One key scenario it impacts is microservice communication.</p><p>Think about a typical microservice (I’m not an advocate for any architecture, I just used microservice to explain Nagle’s effect) interaction</p><p>Service A needs to fetch user data, validate a token, check inventory, and process a payment. Each step might involve a small API call with a request/response pattern.</p><ol><li>Auth request (200B) → Nagle buffers it, waiting for more data or ACK</li><li>40ms later, ACK arrives → buffer sent</li><li>Inventory request (300B) → same wait…</li></ol><p>The result is that each tiny RPC call gets delayed by Nagle’s waiting period!</p><p>Another major impact is on database queries (specifically, remote/hosted instances, not local databases).</p><blockquote>— Application needs to fetch user preferences<br>SELECT * FROM preferences WHERE user_id = ?; — Tiny query</blockquote><blockquote>— Then fetch orders<br>SELECT * FROM orders WHERE user_id = ? LIMIT 10; — Another tiny query</blockquote><blockquote>— Then update analytics<br>INSERT INTO analytics (event) VALUES (‘user_view’); — Yet another tiny query</blockquote><ul><li>Query 1 is sent immediately (as there is no unacknowledged data).</li><li>Query 2 is buffered, waiting for the ACK from Query 1.</li><li>Query 3 is then buffered behind Query 2.</li></ul><h3>So what’s the fix?</h3><p>Even though Nagle’s Algorithm is part of OS level optimizations, it can be disabled:</p><ol><li><strong>At the application level</strong>, by setting TCP_NODELAY on the socket</li><li><strong>At the OS level </strong>, through system or socket-level configuration (depending on the platform)</li></ol><p>Disabling it allows applications to send small packets immediately, trading bandwidth efficiency for responsiveness.</p><p><strong>Conclusion</strong></p><p>Nagle’s Algorithm was introduced to solve a genuine problem in early networking, excessive bandwidth waste caused by tiny packets. However, different applications have different requirements. Today’s systems prioritize low latency over minimal bandwidth usage, and this is where Nagle’s behavior becomes problematic.</p><p>For day-to-day latency-sensitive activities such as online shooting games, real-time trading platforms, chat applications, and microservice-to-microservice communication, the artificial delays introduced by Nagle’s buffering can noticeably degrade performance. Even delays measured in milliseconds can translate into missed trades, delayed actions, or missing headshot :(.</p><p>Like many things in computer science, Nagle’s Algorithm is not “bad” by default. It simply needs to be applied intentionally, rather than left enabled without considering the nature of the workload.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f0305c041bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The only article you need to read about Java’s == and .equals()]]></title>
            <link>https://medium.com/@mohamedansak/the-only-article-you-need-to-read-about-javas-and-equals-5d030c6eba1d?source=rss-913c82715aff------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d030c6eba1d</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-beginners-tutorial]]></category>
            <category><![CDATA[java-interview-questions]]></category>
            <category><![CDATA[equals-method-java]]></category>
            <category><![CDATA[core-java]]></category>
            <dc:creator><![CDATA[Ansak Mahir]]></dc:creator>
            <pubDate>Wed, 01 Oct 2025 05:09:56 GMT</pubDate>
            <atom:updated>2025-10-01T05:09:56.988Z</atom:updated>
            <content:encoded><![CDATA[<h3>The only article you need to read about Java’s == and .equals()</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFrJhsD3mZA16P4l4Lf0jw.png" /></figure><p>Its been a exhausting day and wanted to take a look on reddit for everyday updates. Ahh the ever repeating question of java subreddit once again appeared. This is the last dance entertaining it .</p><p>Java has two different data types. First one is primitives (Primitives are the “basic” types: int, char, boolean, double, float, long, byte, short). Second type is objects (like String, Integer, custom classes, etc.) . The way java treats them internally is unique for each of them.</p><p>Lets say we need to declare and initialize a variable of primitive type. For example,<strong> int numberOfStudents = 50;</strong> . The variable “numberOfStudents” will hold the value 50 because it is a primitive type variable.</p><p>The above case differs for a object type variable. Lets do the same using a wrapper class. <strong>Integer numberOfDays = 7;</strong> . Now the value “numberOfDays” hold is reference to an object in the memory, not the actual number. Typically its something like “java.lang.Integer@1a2b3c”. You may argue that <strong>System.out.println(numberOfDays);</strong> is printing out 7 instead of the memory reference, it is due to the fact toString() method is overridden in Integer class.</p><p>Now lets get into the comparison operator. The “==” operator behaves differently for each data type. In the case of <strong>primitive == primitive</strong>, it checks the value between them. For <strong>object == object</strong>, it compares their <strong>memory addresses</strong> (i.e., it checks if both references point to the <em>exact same object</em> in memory). For the case of <strong>object == primitive</strong> (the side of data type does not matter), java auto-unboxing will remove the wrapper class and gets the value to check with the primitive type value.</p><p>Case 1 → <strong>Primitive == Primitive</strong></p><figure><img alt="Comapring int with int values in java" src="https://cdn-images-1.medium.com/max/720/1*V6XRhSrSlDNZm-tr5jZDyw.png" /></figure><p>In this case, whatever the value between both the primitive will be compared. So the output is true.</p><p>Case 2 → ) O<strong>bject == Object</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*tvOHqaEDpp5ILJUjdSMYIw.png" /></figure><p>In this case, whatever the object memory will be compared. So here the expected output is false due to these are 2 different objects. But java has a caching system for Integer class values. <strong>If a Integer variable is initialized in between -128 to 127 and another Integer variable is initialized in that same range, java will point both variable to the same cached object.</strong> Due to this behavior, the above code results as true. But in the below image, it is false (due to the number being not in the caching range).</p><figure><img alt="Comparing Integer with Integer values" src="https://cdn-images-1.medium.com/max/720/1*N5kI9IhZ35MDyNoQXx7bIQ.png" /></figure><p>case 3 → <strong>Primitive == Object</strong></p><p>Whenever the == operator is used with a primitive and an object, Java automatically unboxes the wrapper class (Actually, if you go into the Integer wrapper class, you will see the variable<strong> int value</strong> which holds the actual <strong>value</strong>) and gets the value to compare it with the primitive variable.</p><figure><img alt="comparing Integer and int values in java" src="https://cdn-images-1.medium.com/max/738/1*zM6tbBpDJa4GkNLkBCfVzg.png" /></figure><p>So the above code results as true.</p><p>When it comes to .equals(), it is a method of Object class (Which is the base class of java language). Object class is extended by any class you create in java. So the .equals() method is automatically integrated with all the classes.</p><p>To make things more clear, lets look at the way how this method is implemented in the Object class itself.</p><figure><img alt="equals() method implementation in java" src="https://cdn-images-1.medium.com/max/738/1*QMkwUuyYleson8H2_fCZ8Q.png" /></figure><p>Now we have a clear understanding that the method expects an object (whatever class it may be) and checks whether the argument object and the object itself are the same (basically checking if they are pointing to same reference).</p><p>If you have followed all along, you can verify by the above equals() method implementation, that it does the same as what ‘==’ does. Then why its even needed?</p><p>The power of .equals() is that it can be overridden as needed. For example, in the case of String class, it is overridden to check if both string’s are same. In the case of Integer class, it is overridden to check if the values are same. This is how ‘==’ and .equals() differs.</p><p>So if we take the example of checking two Integer values (cited as case 2 above, not in the range of -128 to 127) which resulted in false using ‘==’ operator will result as true in the .equals() method.</p><p>Thanks to java auto-boxing, you can even use the int values inside the .equals() method of an integer and it will be automatically converted to Integer by java and the values will be compared. The below code works perfectly fine resulting true as output.</p><figure><img alt="using .equals() to compare Integer and int values (java autoboxing behind the scenes)" src="https://cdn-images-1.medium.com/max/738/1*3JcLjEVLJHCkzLN7fdgWIQ.png" /></figure><p>So the takeaway is that, always use .equals() when comparison <strong>objects</strong> in Java, not ==, because == only checks whether the two references point to the same object in memory. The .equals() method (often overridden) compares the <strong>actual content or value</strong> of the objects, ensuring correct logical comparison.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d030c6eba1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>