<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhimanyu Singh Shekhawat</title>
    <description>The latest articles on DEV Community by Abhimanyu Singh Shekhawat (@abhimanyu).</description>
    <link>https://dev.to/abhimanyu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F461441%2F2f108a9f-0f45-4afa-89e6-fba29c040f7f.jpeg</url>
      <title>DEV Community: Abhimanyu Singh Shekhawat</title>
      <link>https://dev.to/abhimanyu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhimanyu"/>
    <language>en</language>
    <item>
      <title>Code Stories: Introduction</title>
      <dc:creator>Abhimanyu Singh Shekhawat</dc:creator>
      <pubDate>Thu, 26 Nov 2020 16:37:55 +0000</pubDate>
      <link>https://dev.to/abhimanyu/code-stories-introduction-37pa</link>
      <guid>https://dev.to/abhimanyu/code-stories-introduction-37pa</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;If you can't explain it simply, you don't understand it well.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Computer Science is often seen as an esoteric discipline. Most of the learners approach it in a convoluted fashion. You hear complex mathematical jargon thrown around in corridors. On top of that Pop culture left no stone unturned to depict Programming as a niche skill possessed by socially anxious(awkward) individuals.&lt;/p&gt;

&lt;p&gt;However, I can't blame them entirely. The complexity of a subject depends on a variety of things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Are you exposed to similar branches of knowledge?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;What do you want to achieve by studying it?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;How much time &amp;amp; interest do you have?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;How do you plan to approach the subject?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Often learners skip the part where they honestly answer these questions. This leads to all kinds of problems. &lt;br&gt;
It ultimately results in their dry outlook towards a rather succulent and creative branch of knowledge.&lt;/p&gt;

&lt;p&gt;Being a Computer Science graduate, I can assure you, things are not as difficult as they look like. Sure, they require novel thinking and good problem-solving skills. But like I said, these are skills and can be developed.&lt;/p&gt;

&lt;p&gt;Therefore today, I am starting a series of articles that will take a programming problem and deconstruct it into intuitive puzzles.&lt;/p&gt;

&lt;p&gt;You will see, how typical problems can be solved without any complex mumbo-jumbo if we ask ourselves the &lt;em&gt;right questions&lt;/em&gt; and approach them &lt;em&gt;systematically&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In the coming series of essays, we will follow a consistent structure:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Problem&lt;/strong&gt; 🤔&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Strategy&lt;/strong&gt; 💡&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Code&lt;/strong&gt; 🎉&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will start with a detailed problem statement and gradually proceed towards the solution by building upon &lt;em&gt;existing knowledge&lt;/em&gt; and &lt;em&gt;intuition&lt;/em&gt;. Towards the end, we will code that solution away.&lt;/p&gt;

&lt;p&gt;I am a big fan of &lt;strong&gt;&lt;em&gt;community learning&lt;/em&gt;&lt;/strong&gt;. When you learn together, it leads to an understanding that is beyond the realm of an isolated study session. &lt;br&gt;
The best way to achieve this is to share your learnings with the community that helped you grow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I strongly feel that these essays will rekindle your curiosity and soon you will see how fun problem solving is.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The journey of &lt;strong&gt;thousand&lt;/strong&gt; commits begins with a single &lt;strong&gt;init&lt;/strong&gt; 🎊&lt;/p&gt;
&lt;/blockquote&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If you liked this post, you can find similar content by:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Connecting on &lt;strong&gt;Twitter&lt;/strong&gt;: &lt;a href="https://twitter.com/abshekha"&gt;@abshekha&lt;/a&gt; 🐶&lt;/p&gt;

&lt;p&gt;Connecting on &lt;strong&gt;LinkedIn&lt;/strong&gt;: &lt;a href="https://www.linkedin.com/in/abhimanyubitsgoa/"&gt;abhimanyubitsgoa&lt;/a&gt; 🐼&lt;/p&gt;

&lt;p&gt;Visiting my &lt;strong&gt;website&lt;/strong&gt;: &lt;a href="https://abhimanyutimes.com"&gt;https://abhimanyutimes.com&lt;/a&gt; 🐻&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Hitchhiker's Guide to Raspberry Pi</title>
      <dc:creator>Abhimanyu Singh Shekhawat</dc:creator>
      <pubDate>Sun, 22 Nov 2020 17:38:14 +0000</pubDate>
      <link>https://dev.to/abhimanyu/the-hitchhiker-s-guide-to-raspberry-pi-1899</link>
      <guid>https://dev.to/abhimanyu/the-hitchhiker-s-guide-to-raspberry-pi-1899</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x9If5Pj2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AVo8b9xu-3esUEIFVZglMTg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x9If5Pj2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AVo8b9xu-3esUEIFVZglMTg.gif" alt="stark"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Ever felt a bit Starky?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can deny all you want but seeing Tony Stark designing the sophisticated Iron Man suit had an &lt;em&gt;oomph&lt;/em&gt; factor to it.&lt;br&gt;&lt;br&gt;
Now, I want you folks to pause for a moment and think, how unbelievably amazing it will be if you can also design something like this.  Not an Iron Man suit ( maybe :P ) exactly but cool stuff like &lt;em&gt;home automation suite&lt;/em&gt; or a simple &lt;em&gt;portable gaming console&lt;/em&gt;?&lt;br&gt;&lt;br&gt;
The answer lies in exploring this small yet potent device called the &lt;a href="https://www.raspberrypi.org/"&gt;Raspberry Pi&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What exactly is Raspberry Pi?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rKOSyRWf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s912jmptspzy9ijs1fj0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rKOSyRWf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s912jmptspzy9ijs1fj0.jpg" alt="Raspberry Pi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Raspberry Pi 4 Model B&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;According to the official website, Raspberry Pi can be simply seen as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A small and affordable computer that you can use to learn programming.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But if we really dive deep into the potential of this device, the above statement will surely look like an oversimplification.&lt;br&gt;&lt;br&gt;
This is essentially a hardware device with &lt;a href="https://www.raspberrypi.org/products/raspberry-pi-4-model-b/"&gt;computing ability&lt;/a&gt; quite similar to your usual desktops or laptops but what makes so useful is the presence of programmable I/O pins popularly known as &lt;strong&gt;GPIO&lt;/strong&gt; pins ( General Purpose ).&lt;br&gt;
It is due to these pins that we are able to interface a variety of &lt;a href="https://tutorials-raspberrypi.com/raspberry-pi-sensors-overview-50-important-components/"&gt;sensors&lt;/a&gt; to the board to make &lt;a href="https://www.trustedreviews.com/opinion/best-raspberry-pi-projects-pi-3-pi-zero-2949390"&gt;awesome utilities&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
But it can be a bit daunting for a beginner to start working with this marvelous piece of technology as unlike a normal computer the learning curve is a bit steeper here.&lt;br&gt;&lt;br&gt;
So let’s simplify this and bake our very own Raspberry Pi.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ingredients:
&lt;/h2&gt;

&lt;p&gt;There are several ways to set it up but mostly they require the use of a screen to follow installation instructions.&lt;br&gt;
We are going to set up the Pi in a completely &lt;strong&gt;&lt;em&gt;headless&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;(without any output display screen)&lt;/em&gt; way.&lt;br&gt;&lt;br&gt;
Let’s look at the tools we need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.org/products/raspberry-pi-4-model-b/?resellerType=home"&gt;Raspberry Pi&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.org/products/type-c-power-supply/?resellerType=home"&gt;Raspberry Pi 15.3W USB-C Power Supply&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.org/documentation/installation/installing-images/"&gt;Raspberry Pi Imager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A Desktop/Laptop&lt;/li&gt;
&lt;li&gt;Micro SD card (16 GB or above)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Flashing OS on the SD card:
&lt;/h2&gt;

&lt;p&gt;Since the operating system for Raspberry Pi resides on a micro SD card, we need to flash the downloaded image to the card and boot the Pi from it. &lt;br&gt;
Below are the detailed steps that will help you create a bootable SD Card.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download the latest version of Raspberry Pi Imager based on the link above and select the OS of your choice to install. &lt;br&gt;
For this tutorial, we are selecting &lt;strong&gt;Raspberry Pi OS (32 bit)&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R-4LA1Xp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d951hzyghpmyzws2iaxf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R-4LA1Xp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d951hzyghpmyzws2iaxf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e2Pg1B3b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/okz4wvikmwx7ytupwkok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e2Pg1B3b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/okz4wvikmwx7ytupwkok.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connect your SD card to your computer (use card reader if required) and use the Pi Imager to burn a bootable version of the selected OS on the SD card.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HnBHKCu7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cqr19kc7rpy46zbjv06a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HnBHKCu7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cqr19kc7rpy46zbjv06a.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connecting the Pi to a computer:
&lt;/h2&gt;

&lt;p&gt;Before we can start working on the Pi, we need to provide a way to connect it with our computer. Raspberry Pi can be independently used as a computer, just by attaching a keyboard and a monitor to it.&lt;br&gt;&lt;br&gt;
Since over here we are focusing on the headless setup, we will be using just our computer to work on the Pi remotely. We will be using &lt;strong&gt;SSH&lt;/strong&gt; to connect over a wireless network, using the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Put an empty file and rename it to &lt;strong&gt;ssh&lt;/strong&gt; in the boot directory of the SD Card. &lt;br&gt;
This will enable the SSH daemon just after the first boot. Now you can directly connect your computer to the Pi over SSH once you are on the same network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For allowing the Pi to securely connect to your WiFi network, then you can open &lt;code&gt;wpa-supplicant&lt;/code&gt; configuration file in an editor (say nano) and add your entry. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&lt;/code&gt; and add the below code to the end of the file.&lt;/li&gt;
&lt;li&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 network={
           ssid="testing"
           psk="testingPassword"
        }
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;For other network configurations visit this detailed  &lt;a href="https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md"&gt;guide&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Make sure that the Pi and your computer are on the same network and do an SSH to it. Please note that depending upon the OS your computer is running you will have &lt;a href="https://www.digikey.in/en/maker/blogs/2018/how-to-boot-to-command-line-and-ssh-on-raspberry-pi"&gt;different methods&lt;/a&gt; for this.&lt;br&gt;
You can find out the IP address of your Pi by simply looking at devices connected to your Router's dashboard.&lt;br&gt;&lt;br&gt;
There are other ways to access this information as well due to simplicity we won't go into those details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For doing ssh, the default username is &lt;strong&gt;&lt;em&gt;pi&lt;/em&gt;&lt;/strong&gt; and password is &lt;em&gt;**raspberry&lt;/em&gt;&lt;em&gt;.&lt;br&gt;&lt;br&gt;
Use it to log in into the Pi with the shell with &lt;code&gt;ssh pi@192.168.0.80&lt;/code&gt; assuming *192.168.0.12&lt;/em&gt; is Pi's IP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now when you are logged in, you need to enable SSH for the subsequent sessions. For doing this, write &lt;code&gt;sudo raspi-config&lt;/code&gt; in the terminal and press enter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;em&gt;Expand File System&lt;/em&gt; option from the list to so that we can use the entire card space.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;em&gt;Interfacing options -&amp;gt; SSH&lt;/em&gt; and enable it. Also, enable &lt;em&gt;VNC&lt;/em&gt; while we are at this (We will see this next).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reboot the Pi.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup Visuals for the Pi:
&lt;/h2&gt;

&lt;p&gt;Now when we had successfully configured Raspberry Pi to work with the basic command line, we can think more ambitiously in terms of assigning visual access to it.&lt;br&gt;&lt;br&gt;
We will be using &lt;strong&gt;Virtual Network Computing&lt;/strong&gt; (VNC) which is a graphical desktop sharing system. It will allow us to remotely control the desktop interface of the Pi with the help of our computer.&lt;br&gt;&lt;br&gt;
It transfers the keyboard and mouse events to the server running on the Pi and returns the respective updates on the screen. Since we have already allowed VNC above we can just install it by using &lt;code&gt;sudo apt-get install tightvncserver&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;Just type &lt;code&gt;tightvncserver&lt;/code&gt; in the terminal to start the VNC server on the Raspberry Pi. &lt;br&gt;
You will have to install a VNC client on your computer to connect to the Pi. &lt;br&gt;
Once done, you will be able to communicate with Raspberry Pi, directly from your computer.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jhtVPT67--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cvqccj9ur3rxch7hfa0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jhtVPT67--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cvqccj9ur3rxch7hfa0e.png" alt="Vnc Pi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Congratulations you have just baked your Raspberry Pi 🎉&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;blockquote&gt;
&lt;p&gt;If you liked this post, you can find more by:&lt;/p&gt;

&lt;p&gt;Following me on &lt;strong&gt;Twitter&lt;/strong&gt;: &lt;a href="https://twitter.com/abshekha"&gt;@abshekha&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connecting on &lt;strong&gt;LinkedIn&lt;/strong&gt;: &lt;a href="https://www.linkedin.com/in/abhimanyubitsgoa/"&gt;abhimanyubitsgoa&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visiting my &lt;strong&gt;website&lt;/strong&gt;: &lt;a href="https://abhimanyutimes.com"&gt;https://abhimanyutimes.com&lt;/a&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is SGID in Linux?</title>
      <dc:creator>Abhimanyu Singh Shekhawat</dc:creator>
      <pubDate>Thu, 12 Nov 2020 18:16:49 +0000</pubDate>
      <link>https://dev.to/abhimanyu/what-is-sgid-in-linux-1g51</link>
      <guid>https://dev.to/abhimanyu/what-is-sgid-in-linux-1g51</guid>
      <description>&lt;p&gt;A few weeks ago, I stumbled upon an interesting problem.&lt;br&gt;&lt;br&gt;
In Linux, if you check the file permissions you will notice the name of the file owner along with the group which owns the file. Note that, It is &lt;strong&gt;not&lt;/strong&gt; necessary for the owner to be a part of the group but usually that is the case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Imagine this scenario:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are 3 processes operating in a system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;P1&lt;/strong&gt;: Runs  as &lt;em&gt;root&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;P2&lt;/strong&gt;: Creates the directories during the install.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;P3&lt;/strong&gt;: It access files created by P1.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Further, P2 &amp;amp; P3 are the part of the same group, say &lt;em&gt;user_grp&lt;/em&gt; and both run as owner &lt;em&gt;user&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
Now consider a directory &lt;strong&gt;&lt;em&gt;docs&lt;/em&gt;&lt;/strong&gt; which is created by our installer process P2 and its permission looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drwxr-x---  5 user user_grp  4096 Jul 31 19:56 docs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;P1 gets into the directory and wants to create a  file called &lt;strong&gt;&lt;em&gt;readme.txt&lt;/em&gt;&lt;/strong&gt; for process P3 to read.&lt;br&gt;&lt;br&gt;
Please note that there is an additional constraint here, the read, write &amp;amp; execute access for OTHERS is prohibited.&lt;br&gt;&lt;br&gt;
Nevertheless, P1 goes ahead and creates the file whose permission looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  -rwxr-----  1 root root  4096 Jul 31 19:56 readme.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Can you spot the problem here?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
After carefully examining the situation, it is not difficult to judge that Process P3 will fail in reading the file &lt;em&gt;readme.txt&lt;/em&gt; because it is neither the owner of file &lt;em&gt;readme.txt&lt;/em&gt; nor part of the same group.&lt;br&gt;&lt;br&gt;
There are a lot of ways one can go about solving this access limitation. For example, you can just issue &lt;em&gt;chgrp&lt;/em&gt; for the file to change its group to &lt;em&gt;user_grp&lt;/em&gt; so that process P3 can access, as it will then belong to the same group. But if there are a lot of files like this in the docs directory and you want P3 to read all of them, rather than firing &lt;em&gt;chgrp&lt;/em&gt; for each file, you can opt for a more elegant approach.&lt;/p&gt;

&lt;p&gt;Let's issue this command on &lt;strong&gt;&lt;em&gt;docs&lt;/em&gt;&lt;/strong&gt; directory to set &lt;strong&gt;&lt;em&gt;GID bit&lt;/em&gt;&lt;/strong&gt;, we will come back to what it actually means in a moment.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ chmod g+s docs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Look at the file permission of the &lt;strong&gt;&lt;em&gt;docs&lt;/em&gt;&lt;/strong&gt; directory:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drwxr-s---  5 user user_grp  4096 Jul 31 19:56 docs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Notice there is an &lt;strong&gt;&lt;em&gt;'s'&lt;/em&gt;&lt;/strong&gt; in place of &lt;strong&gt;&lt;em&gt;'x'&lt;/em&gt;&lt;/strong&gt; in the directory permissions. Now let's allow process P1 to create a file &lt;strong&gt;readme2.txt&lt;/strong&gt; in the docs directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-rwxr-----  1 root user_grp  4096 Jul 31 19:56 readme2.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is the magic of SGID!&lt;br&gt;&lt;br&gt;
When you set the SGID on a directory, all the files and directories inside it will inherit the parent directory's group.&lt;br&gt;&lt;br&gt;
So even though &lt;strong&gt;&lt;em&gt;root&lt;/em&gt;&lt;/strong&gt; is creating the file &lt;strong&gt;&lt;em&gt;readme2.txt&lt;/em&gt;&lt;/strong&gt; inside &lt;strong&gt;&lt;em&gt;docs&lt;/em&gt;&lt;/strong&gt;, the process P3 can easily read it because the file now has the same group as process P3, i.e. &lt;strong&gt;user_grp&lt;/strong&gt; instead of &lt;strong&gt;root&lt;/strong&gt;. Hence, SGID bit can be very useful for dealing with situations like the one above.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Linux holds deeper truths, we just have to MAN &lt;sup&gt;[1]&lt;/sup&gt; up to get there!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Notes
&lt;/h3&gt;

&lt;p&gt;[1] I am not trying to label courage as a masculine trait. It is just that Linux manual is called MAN pages. So a &lt;em&gt;puny&lt;/em&gt; pun 😛&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;If you liked this post, you can find more by:&lt;/p&gt;

&lt;p&gt;Following me on &lt;strong&gt;Twitter&lt;/strong&gt;: &lt;a href="https://twitter.com/abshekha"&gt;@abshekha&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connecting on &lt;strong&gt;LinkedIn&lt;/strong&gt;: &lt;a href="https://www.linkedin.com/in/abhimanyubitsgoa/"&gt;abhimanyubitsgoa&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visiting my &lt;strong&gt;website&lt;/strong&gt;: &lt;a href="https://abhimanyutimes.com"&gt;https://abhimanyutimes.com&lt;/a&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>programming</category>
      <category>security</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Newton &amp; Square Roots</title>
      <dc:creator>Abhimanyu Singh Shekhawat</dc:creator>
      <pubDate>Sun, 08 Nov 2020 14:43:50 +0000</pubDate>
      <link>https://dev.to/abhimanyu/newton-square-roots-13ge</link>
      <guid>https://dev.to/abhimanyu/newton-square-roots-13ge</guid>
      <description>&lt;p&gt;The web is an interesting place, it humbles you down and shows how little you actually know. While hitchhiking through the hyperlinks, I had one such realization recently.&lt;/p&gt;

&lt;p&gt;What if I ask you to calculate the square root of a number? Depending upon your background you are likely to come up with a variety of solutions. Let me talk about that specific fraction of you who will be interested in churning out code for doing so. &lt;em&gt;[No, sqrt()]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Binary Search&lt;/em&gt; seems to be a valid and intuitive approach, after all, we can easily discard half of the search space in each iteration. But I want you to hold that thought and glance over this small snippet below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;sq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;xn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;xn&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;xn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;eps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//eps is precision&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;xn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xn&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;xn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;xn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Magical isn't it? When I first looked at this, I was really startled by the elegance of this solution. So what is it and why does it work?&lt;/p&gt;

&lt;h2&gt;
  
  
  Sweet Mathematics
&lt;/h2&gt;

&lt;p&gt;You just witnessed the glamour of &lt;strong&gt;&lt;em&gt;Newton Raphson&lt;/em&gt;&lt;/strong&gt; method.&lt;br&gt;&lt;br&gt;
In simple terms, it is a way to quickly find a good approximation for the roots of a real-valued function &lt;strong&gt;f(x) = 0&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is our cue, square root for a number can be minimally represented by solving for the roots of &lt;strong&gt;f(x) = x&lt;sup&gt;2&lt;/sup&gt; - N&lt;/strong&gt;, where &lt;em&gt;N&lt;/em&gt; is the number we have to find the root of.&lt;br&gt;&lt;br&gt;
That is all cool! But how does it actually work? Let's look at the simple math behind this:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Consider a general function: &lt;strong&gt;y = f(x)&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img2.png"&gt;&lt;/a&gt;&lt;br&gt;
We start by choosing an arbitrary value &lt;strong&gt;x1&lt;/strong&gt; as our starting point&lt;sup&gt;[1]&lt;/sup&gt;. For our specific case, we can choose &lt;strong&gt;N/2&lt;/strong&gt; as our starting point and can safely discard values greater than that from the candidature of &lt;strong&gt;√N&lt;/strong&gt;.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now let's draw a tangent (Differential) to the curve at that point and mark its intersection with the x-axis. Let's call this &lt;strong&gt;x2&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img3.png"&gt;&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat &lt;em&gt;step 2&lt;/em&gt; for point &lt;strong&gt;x2&lt;/strong&gt; to obtain &lt;strong&gt;x3&lt;/strong&gt;. You must have noticed that with each iteration we are nearing the roots of the quadratic equation. Slow and steady!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img4.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Depending upon the precision, you can decide upon the number of iterations required.&lt;/em&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Formal Expression
&lt;/h2&gt;

&lt;p&gt;Let's try to workout an elegant formula for &lt;strong&gt;f(x) = x&lt;sup&gt;2&lt;/sup&gt; - N&lt;/strong&gt; which will get us the compact code we saw in the beginning. Please note that we are aiming to get a relation between &lt;strong&gt;N&lt;sup&gt;th&lt;/sup&gt;&lt;/strong&gt; and &lt;strong&gt;(N+1)&lt;sup&gt;th&lt;/sup&gt;&lt;/strong&gt; iteration.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For any point &lt;strong&gt;xN&lt;/strong&gt;, by using the equation of line we can get:&lt;br&gt;
&lt;strong&gt;f'(xN) = (f(xN+1) - f(xN))/(xN+1 - xN)&lt;/strong&gt;&lt;br&gt;
[&lt;em&gt;f'(x)&lt;/em&gt; being the slope at point &lt;em&gt;x&lt;/em&gt;]  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Putting &lt;strong&gt;0&lt;/strong&gt; for y coordinate at point &lt;strong&gt;xN+1&lt;/strong&gt; where tangent crosses x-axis we get: &lt;br&gt;
&lt;strong&gt;f'(xN) = (- f(xN))/(xN+1- xN)&lt;/strong&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rearranging the terms &amp;amp; putting &lt;strong&gt;f'(x) = 2xN&lt;/strong&gt; we have our final expression: &lt;br&gt;
&lt;strong&gt;xN+1 = (xN + N/xN)/2&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fabhimanyutimes.com%2Fassets%2Fimg%2Fnewton_img5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Visualising Newton Raphson method for N = 10000&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Notes
&lt;/h2&gt;

&lt;p&gt;[1] For the sake of simplicity, I have omitted the details about choosing the initial value which plays a crucial role in more complex functions.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Special thanks to &lt;a href="https://amsi.org.au/" rel="noopener noreferrer"&gt;AMSI&lt;/a&gt; for facilitating illustrations&lt;/em&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;If you liked this post, you can find more by:&lt;/p&gt;

&lt;p&gt;Following me on &lt;strong&gt;Twitter&lt;/strong&gt;: &lt;a href="https://twitter.com/abshekha" rel="noopener noreferrer"&gt;@abshekha&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connecting on &lt;strong&gt;LinkedIn&lt;/strong&gt;: &lt;a href="https://www.linkedin.com/in/abhimanyubitsgoa/" rel="noopener noreferrer"&gt;abhimanyubitsgoa&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visiting my &lt;strong&gt;website&lt;/strong&gt;: &lt;a href="https://abhimanyutimes.com" rel="noopener noreferrer"&gt;https://abhimanyutimes.com&lt;/a&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
