<?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 Yugal Arora on Medium]]></title>
        <description><![CDATA[Stories by Yugal Arora on Medium]]></description>
        <link>https://medium.com/@yugalarora?source=rss-1b1bf8b36cbb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*soYEkSk15xjJ5hzlUElT2g.jpeg</url>
            <title>Stories by Yugal Arora on Medium</title>
            <link>https://medium.com/@yugalarora?source=rss-1b1bf8b36cbb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:36:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yugalarora/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[The magic of argv]]></title>
            <link>https://yugalarora.medium.com/the-magic-of-argv-448b67476ee1?source=rss-1b1bf8b36cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/448b67476ee1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[systems-thinking]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[kernel]]></category>
            <dc:creator><![CDATA[Yugal Arora]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 20:09:07 GMT</pubDate>
            <atom:updated>2022-11-19T20:09:07.640Z</atom:updated>
            <content:encoded><![CDATA[<p>Every C-Program must have a function called main() , program execution starts from it.</p><p>When a program is executed with command line arguments, those are made available to program’s main() function by 2 arguments:</p><ul><li>1st argument argc of type int indicates number of arguments</li><li>2nd argument *argv[] an array of pointers to the command line arguments.</li></ul><p>The 1st string in argv i.e argv[0] is the name of program itself.</p><p>Many Linux programs use it to their benefit, by creating links to these binaries with different names.</p><p>They can perform different functions from same program depending of the program that was used to invoke them.</p><p>Let’s create a small python program program1 in /usr/local/bin</p><pre>cat &lt;&lt;EOF &gt; /usr/local/bin/program1<br>#!/usr/bin/env python3<br>from sys import argv<br>print(argv[0])<br>EOF<br><br>chmod +x /usr/local/bin/program1</pre><p>We use python’s sys module to print argv[0] i.e program’s name, since we created it in /usr/local/bin it’s already in our PATH , we simply execute by typing program1 on terminal.</p><p>output is: /usr/local/bin/program1</p><p>Now let’s create a hard link on program1 with another name program2</p><pre>ln /usr/local/bin/program1 /usr/local/bin/program2</pre><p>Now, when we execute program2 output is /usr/local/bin/program2</p><p>Thus the same 3 lines of code print different output depending on calling program.</p><p>If you noticed, I used ln to create a link, this creates a hard link .</p><p>What if I create a soft link, ln -s .</p><p>Let’s see:</p><pre>ln -s /usr/loca/bin/program1 /usr/local/bin/program3</pre><p>Run program3 in terminal, output is /usr/local/bin/program3</p><p>Makes sense, since we used a different program name to invoke it.</p><p>If you know how links work in linux:</p><ul><li>soft links -&gt; are created on file names, can span across different file systems, have different inode number, link becomes dangling/unusable once original file is deleted.</li><li>hard links -&gt; are created on inode number thus cannot span across different file systems, continues to work even if original file is deleted.</li></ul><p>Now that we know what’s what, let’s try to identify such existing programs on Linux, which are same programs doing different things under different names.</p><p>Let’s check inode number for programs we created above using ls -li command, we can also use stat to find this.</p><pre>ls -i /usr/local/bin/program1<br>61573154 /usr/local/bin/program1<br><br>ls -i /usr/local/bin/program2<br>61573154 /usr/local/bin/program2</pre><p>As we see, they both have same inode number, since program2 was a hard link on program1</p><p>What about program3</p><pre>ls -i /usr/local/bin/program3<br>61575256 /usr/local/bin/program3</pre><p>It’s inode number is different, since this was a soft link</p><p>With this understanding that hard links will have same inode number, we try to find such programs in system’s /usr/bin director:</p><pre>cat &lt;&lt;EOF &gt; dup.py<br>#!/usr/bin/env python3<br>import os<br><br>if __name__ == &quot;__main__&quot;:<br>    inode_name = {}<br>    with os.scandir(path=&quot;/usr/bin&quot;) as entries:<br>        for entry in entries:<br>            if entry.is_file():<br>                inode_name[entry.inode()] = inode_name.get(entry.inode(), []) + [entry.name]<br>    print( *[ v for _,v in inode_name.items() if len(v) &gt; 1], sep=&quot;\n&quot; )<br>EOF<br>chmod +x dup.py<br>./dup.py</pre><p>The output is a lot of programs, sharing a few here I was amazed to see:</p><pre>[&#39;umask&#39;, &#39;unalias&#39;, &#39;alias&#39;, &#39;wait&#39;, &#39;hash&#39;, &#39;fc&#39;, &#39;read&#39;, &#39;type&#39;, &#39;getopts&#39;, <br>&#39;bg&#39;, &#39;fg&#39;, &#39;cd&#39;, &#39;command&#39;, &#39;jobs&#39;, &#39;ulimit&#39;]<br>[&#39;gzcat&#39;, &#39;zcat&#39;, &#39;gunzip&#39;]<br>[&#39;readlink&#39;, &#39;stat&#39;]<br>[&#39;cksum&#39;, &#39;sum&#39;]</pre><p>cd and ulimit are same program even though both do very separate functions on a Linux system.</p><p>I wasn’t worried about soft links since they aren’t that difficult to find:</p><pre>ls -l /usr/local/bin/program3<br><br>/usr/local/bin/program3 -&gt; /usr/local/bin/program1</pre><p><strong>If you made it till here, Thanks for reading!</strong></p><p>Bonus:</p><p>When we created a hard link and this can also be seen in stat object of the file with:</p><pre>python3 -c &quot;import os;print(os.stat(&#39;/usr/local/bin/program1&#39;).st_nlink)&quot;<br><br>2</pre><p>the inode object maintains an int attribute st_nlink indicating number of links on the file.</p><p><strong>References:</strong></p><ul><li>Chapter 6, section 6 : <strong>The Linux Programming Interface — Michael Kerrisk</strong></li><li><a href="https://docs.python.org/3/library/os.html#os.scandir">https://docs.python.org/3/library/os.html#os.scandir</a></li><li><a href="https://docs.python.org/3/library/os.html#os.DirEntry.stat">https://docs.python.org/3/library/os.html#os.DirEntry.stat</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=448b67476ee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[linux date cheatsheet]]></title>
            <link>https://yugalarora.medium.com/nix-date-cheatsheet-227c50244a26?source=rss-1b1bf8b36cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/227c50244a26</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[unix]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Yugal Arora]]></dc:creator>
            <pubDate>Sat, 06 Aug 2022 21:20:47 GMT</pubDate>
            <atom:updated>2022-08-31T20:30:49.856Z</atom:updated>
            <content:encoded><![CDATA[<p>Some quick handy formats that can be used with date command on linux.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/535dcafb608b4a32c719e854132233be/href">https://medium.com/media/535dcafb608b4a32c719e854132233be/href</a></iframe><p>Example:</p><pre>date +&#39;%d&#39;<br>06</pre><pre>date +&#39;%m&#39;<br>08</pre><pre>date +&#39;%Y&#39;<br>2022</pre><pre>date +&#39;%m-%d-%Y&#39;<br>08-06-2022</pre><pre>date +&#39;%m/%d/%Y %H:%M:%S&#39;<br>08/06/2022 21:12:40</pre><pre>date +&#39;%m/%d/%Y %H:%M:%S %p&#39;<br>08/06/2022 21:12:28 PM</pre><pre>date +&#39;%x %T %p&#39;<br>08/06/22 21:11:59 PM</pre><pre><strong>bonus (to print current epoch time):</strong><br>date +&#39;%s&#39;<br>1659820538</pre><p><strong>Reference</strong>: <em>Chapter10: Time, The Linux Programming Interface</em> <strong>— </strong><a href="http://man7.org/mtk/index.html"><strong>Michael Kerrisk</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=227c50244a26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Desktop — Moving away]]></title>
            <link>https://yugalarora.medium.com/docker-desktop-moving-away-ffdb6bc78b95?source=rss-1b1bf8b36cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffdb6bc78b95</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Yugal Arora]]></dc:creator>
            <pubDate>Sat, 22 Jan 2022 20:08:21 GMT</pubDate>
            <atom:updated>2022-01-29T14:49:49.875Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker Desktop — Moving away</h3><p>Docker is changing its licensing model and Docker Desktop will require a subscription starting 31st Jan 2022, more details <a href="https://www.docker.com/blog/updating-product-subscriptions/">here</a>.</p><p>Docker Engine provides a runtime for Containers, other popular container runtimes are:</p><ul><li><a href="https://containerd.io/">Containerd</a></li><li><a href="https://github.com/cri-o/cri-o">CRI-O</a></li><li><a href="https://docs.mirantis.com/mcr/20.10/overview.html">Mirantis Container Runtime</a></li><li><a href="https://github.com/opencontainers/runc">runc</a></li><li><a href="https://github.com/containers/crun">crun</a></li><li><a href="https://github.com/hyperhq/runv">runv</a></li></ul><p>etc…</p><p>All container runtimes follow certain set of standards set by <a href="https://opencontainers.org/">OCI initiative</a>.</p><p>Next, we need a CLI which can spawn and manage containers using any of OCI Compliant runtimes, here we’re exploring below 2 options:</p><ul><li><a href="https://github.com/containerd/nerdctl">nerdctl</a></li><li><a href="https://github.com/containers/podman">podman</a></li></ul><h3>Installing nerdctl on MacOs:</h3><pre>brew install <a href="https://github.com/lima-vm/lima">lima</a><br>limactl start</pre><p>Few basic commands:</p><pre># see running containers<br>lima nerdctl ps</pre><pre># run a new container<br>lima nerdctl run nginx</pre><pre># display details of local images<br>lima nerdctl images</pre><pre># building a new image<br>nerdctl build -t foo /some-dockerfile-directory</pre><p>Commands are similar to docker commands, thus you can create an alias and continue to use same old docker commands.</p><pre>alias docker=&quot;lima nerdctl&quot;</pre><p><strong>Note</strong>: limactl start will create a ubuntu (default) virtual machine</p><p>You can run commands inside this machine by prefixing commands with lima such as:</p><pre>lima uname -a</pre><p>when you’re done using containers, do limactl stop to stop the virtual machine.</p><p>and limactl remove default to remove the image.</p><h3>Installing podman on MacOs:</h3><pre>brew install podman<br>podman machine init<br>podman machine start</pre><p>Few basic commands:</p><pre># see running containers<br>podman ps</pre><pre># run a new container<br>podman run nginx</pre><pre># display details of images<br>podman images</pre><pre># building a new image<br>podman build -t foo /some-dockerfile-directory</pre><p>As commands are similar to docker you can create an alias:</p><pre>alias docker=&quot;podman&quot;</pre><p>and keep using same old commands.</p><p>Click <a href="https://www.redhat.com/sysadmin/podman-mac-machine-architecture"><em>here</em></a><em> </em>for more details on podman</p><p><strong>Note</strong>: podman machine init download a fedora-coreos virtual machine image</p><p>podman machine start will create a virtual machine using quemu virtualisation on MacOs.</p><p>To cleanup afterwards, do:</p><pre>podman machine stop<br>podman machine rm</pre><blockquote>Thanks for reading, If you liked the article please give some claps !!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffdb6bc78b95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[jq cheatsheet]]></title>
            <link>https://yugalarora.medium.com/jq-cheatsheet-77ed0829dbec?source=rss-1b1bf8b36cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/77ed0829dbec</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[jq]]></category>
            <dc:creator><![CDATA[Yugal Arora]]></dc:creator>
            <pubDate>Fri, 22 Oct 2021 11:59:38 GMT</pubDate>
            <atom:updated>2021-10-22T13:33:03.409Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>jq</strong> is <strong>a lightweight and flexible command-line JSON processor, </strong>it is also described as sed for JSON data: You can use it to slice and filter and map and transform structured data with the same ease</p><p>We’ll use below endpoint as example `<a href="https://reqres.in/api/users">https://reqres.in/api/users</a>` which provides response in json format.</p><p><strong>Beautify json</strong></p><pre>curl <a href="https://reqres.in/api/users">https://reqres.in/api/users</a> | jq .</pre><p>Sample output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*i_0lZr_htUgxzFxr0-3ylg.png" /></figure><p><strong>2. Print value of top level attribute</strong></p><pre>curl <a href="https://reqres.in/api/users">https://reqres.in/api/users</a> | jq .page</pre><p>output:</p><pre>1</pre><p><strong>3. Print all items in top level array element </strong><strong>data</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq .data</pre><p>output:</p><pre>[<br>  {<br>    &quot;id&quot;: 1,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:george.bluth@reqres.in">george.bluth@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;George&quot;,<br>    &quot;last_name&quot;: &quot;Bluth&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/1-image.jpg">https://reqres.in/img/faces/1-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:janet.weaver@reqres.in">janet.weaver@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Janet&quot;,<br>    &quot;last_name&quot;: &quot;Weaver&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/2-image.jpg">https://reqres.in/img/faces/2-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 3,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:emma.wong@reqres.in">emma.wong@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Emma&quot;,<br>    &quot;last_name&quot;: &quot;Wong&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/3-image.jpg">https://reqres.in/img/faces/3-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 4,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:eve.holt@reqres.in">eve.holt@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Eve&quot;,<br>    &quot;last_name&quot;: &quot;Holt&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/4-image.jpg">https://reqres.in/img/faces/4-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 5,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:charles.morris@reqres.in">charles.morris@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Charles&quot;,<br>    &quot;last_name&quot;: &quot;Morris&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/5-image.jpg">https://reqres.in/img/faces/5-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 6,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:tracey.ramos@reqres.in">tracey.ramos@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Tracey&quot;,<br>    &quot;last_name&quot;: &quot;Ramos&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/6-image.jpg">https://reqres.in/img/faces/6-image.jpg</a>&quot;<br>  }<br>]</pre><p><strong>4. Print key, values in array element </strong><strong>data</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data[] | {first_name,last_name}&#39;</pre><p>output:</p><pre>{<br>  &quot;first_name&quot;: &quot;George&quot;,<br>  &quot;last_name&quot;: &quot;Bluth&quot;<br>}<br>{<br>  &quot;first_name&quot;: &quot;Janet&quot;,<br>  &quot;last_name&quot;: &quot;Weaver&quot;<br>}<br>{<br>  &quot;first_name&quot;: &quot;Emma&quot;,<br>  &quot;last_name&quot;: &quot;Wong&quot;<br>}<br>{<br>  &quot;first_name&quot;: &quot;Eve&quot;,<br>  &quot;last_name&quot;: &quot;Holt&quot;<br>}<br>{<br>  &quot;first_name&quot;: &quot;Charles&quot;,<br>  &quot;last_name&quot;: &quot;Morris&quot;<br>}<br>{<br>  &quot;first_name&quot;: &quot;Tracey&quot;,<br>  &quot;last_name&quot;: &quot;Ramos&quot;<br>}</pre><p><strong>5. Print only values from array element </strong><strong>data</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data[].first_name&#39;</pre><p>output:</p><pre>&quot;George&quot;<br>&quot;Janet&quot;<br>&quot;Emma&quot;<br>&quot;Eve&quot;<br>&quot;Charles&quot;<br>&quot;Tracey&quot;</pre><p><strong>6. Print first_name and last_name as </strong><strong>text instead of </strong><strong>json</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data[] | {first_name,last_name} | join(&quot; &quot;)&#39;</pre><p>output:</p><pre>&quot;George Bluth&quot;<br>&quot;Janet Weaver&quot;<br>&quot;Emma Wong&quot;<br>&quot;Eve Holt&quot;<br>&quot;Charles Morris&quot;<br>&quot;Tracey Ramos&quot;</pre><p><strong>7. Get all records for person with </strong><strong>first_name </strong><strong>Eve</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data[] | select(.first_name == &quot;Eve&quot;)&#39;</pre><p>output:</p><pre>{<br>  &quot;id&quot;: 4,<br>  &quot;email&quot;: &quot;<a href="/service/mailto:eve.holt@reqres.in">eve.holt@reqres.in</a>&quot;,<br>  &quot;first_name&quot;: &quot;Eve&quot;,<br>  &quot;last_name&quot;: &quot;Holt&quot;,<br>  &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/4-image.jpg">https://reqres.in/img/faces/4-image.jpg</a>&quot;<br>}</pre><p><strong>8. Get </strong><strong>email of a person with </strong><strong>first_name </strong><strong>Eve</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data[] | select(.first_name == &quot;Eve&quot;) | {email}&#39;</pre><p>output:</p><pre>{<br>  &quot;email&quot;: &quot;<a href="/service/mailto:eve.holt@reqres.in">eve.holt@reqres.in</a>&quot;<br>}</pre><p><strong>9. Extract all </strong><strong>keys from json</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq keys</pre><p>output:</p><pre>[<br>  &quot;data&quot;,<br>  &quot;page&quot;,<br>  &quot;per_page&quot;,<br>  &quot;support&quot;,<br>  &quot;total&quot;,<br>  &quot;total_pages&quot;<br>]</pre><p><strong>10. Print range from array </strong><strong>data</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data[1:3]&#39;</pre><p>output:</p><pre>[<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:janet.weaver@reqres.in">janet.weaver@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Janet&quot;,<br>    &quot;last_name&quot;: &quot;Weaver&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/2-image.jpg">https://reqres.in/img/faces/2-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 3,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:emma.wong@reqres.in">emma.wong@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Emma&quot;,<br>    &quot;last_name&quot;: &quot;Wong&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/3-image.jpg">https://reqres.in/img/faces/3-image.jpg</a>&quot;<br>  }<br>]</pre><p><strong>11. Sort array </strong><strong>data by </strong><strong>first_name</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data | sort_by(.first_name)&#39;</pre><p>output:</p><pre>[<br>  {<br>    &quot;id&quot;: 5,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:charles.morris@reqres.in">charles.morris@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Charles&quot;,<br>    &quot;last_name&quot;: &quot;Morris&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/5-image.jpg">https://reqres.in/img/faces/5-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 3,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:emma.wong@reqres.in">emma.wong@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Emma&quot;,<br>    &quot;last_name&quot;: &quot;Wong&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/3-image.jpg">https://reqres.in/img/faces/3-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 4,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:eve.holt@reqres.in">eve.holt@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Eve&quot;,<br>    &quot;last_name&quot;: &quot;Holt&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/4-image.jpg">https://reqres.in/img/faces/4-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 1,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:george.bluth@reqres.in">george.bluth@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;George&quot;,<br>    &quot;last_name&quot;: &quot;Bluth&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/1-image.jpg">https://reqres.in/img/faces/1-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:janet.weaver@reqres.in">janet.weaver@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Janet&quot;,<br>    &quot;last_name&quot;: &quot;Weaver&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/2-image.jpg">https://reqres.in/img/faces/2-image.jpg</a>&quot;<br>  },<br>  {<br>    &quot;id&quot;: 6,<br>    &quot;email&quot;: &quot;<a href="/service/mailto:tracey.ramos@reqres.in">tracey.ramos@reqres.in</a>&quot;,<br>    &quot;first_name&quot;: &quot;Tracey&quot;,<br>    &quot;last_name&quot;: &quot;Ramos&quot;,<br>    &quot;avatar&quot;: &quot;<a href="https://reqres.in/img/faces/6-image.jpg">https://reqres.in/img/faces/6-image.jpg</a>&quot;<br>  }<br>]</pre><p><strong>12. Count elements in subscripted array </strong><strong>data :</strong></p><pre>curl &#39;<a href="https://reqres.in/api/users&#39;">https://reqres.in/api/users&#39;</a> | jq &#39;.data | length&#39;</pre><p>output:</p><pre>6</pre><p>Try these examples <a href="https://jqplay.org/s/oHvsbJdxw7">here</a> as well json is pre-loaded.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77ed0829dbec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Progress bars in Python with tqdm]]></title>
            <link>https://yugalarora.medium.com/progress-bars-in-python-with-tqdm-ea17a50a1136?source=rss-1b1bf8b36cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea17a50a1136</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[site-reliability]]></category>
            <category><![CDATA[tqdm]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[scripting]]></category>
            <dc:creator><![CDATA[Yugal Arora]]></dc:creator>
            <pubDate>Thu, 21 Oct 2021 17:30:02 GMT</pubDate>
            <atom:updated>2021-10-21T17:30:02.259Z</atom:updated>
            <content:encoded><![CDATA[<p>I ran a script which processed a large chunk of data, but was not sure what percentage of data has been processed and thought it would be nicer to have a progress bar, adding which was much simpler than I thought using <a href="https://github.com/tqdm/tqdm"><strong>tqdm</strong></a>.</p><p>In order to access the python library, we need to install it in the python environment, using:</p><pre>pip install tqdm</pre><p>Import package into the script:</p><pre>from tqdm import tqdm</pre><p>And just add the progress bar to your loop:</p><pre>for i in tdqm(range(100)):<br>     pass</pre><p>To modify the progress bar:</p><pre>for i in tqdm(range(100), ascii = True):<br>    pass</pre><p>Add description:</p><pre>for i in tqdm(range(100), ascii = True, desc=&quot;bar&quot;):<br>    pass</pre><p>Control width:</p><pre>for i in tqdm(range(100), ncols=99):<br>    pass</pre><p>Modify color:</p><pre>for i in tqdm(range(100), colour=green):<br>    pass</pre><p>You can also use a more optimised version of <strong>tqdm(range)</strong> i.e <strong>trange</strong>:</p><pre>for i in trange(100):<br>    pass</pre><p>tqdm can also be used as pipes:</p><pre>seq 9999999 | wc -l | tqdm</pre><p>Let’s create a test directory with arbitrary large number of files:</p><pre>mkdir -p test;touch sample{0001..9999}.txt</pre><pre>tar -zcf - test/ | tqdm --bytes --total `du -s test/ | cut -f1` &gt; test.tgz</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ItAKAz0AqPbvKqooR0RYQQ.gif" /></figure><p><strong>Resources</strong>:</p><ul><li><a href="https://github.com/tqdm/tqdm">GitHub - tqdm/tqdm: :zap: A Fast, Extensible Progress Bar for Python and CLI</a></li><li><a href="https://stackoverflow.com/questions/3160699/python-progress-bar">Python Progress Bar</a></li></ul><p>Thanks for Reading !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea17a50a1136" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>