<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Varun Barad - Curious Developer</title>
  <subtitle>My online home where I post about new things I learn or find interesting.</subtitle>
  <link href="https://varunbarad.com/feed.xml" rel="self" type="application/atom+xml"/>
  <link href="https://varunbarad.com/" rel="alternate" type="text/html"/>
  <updated>2026-04-19T18:58:28+05:30</updated>
  <id>https://varunbarad.com/feed.xml</id>
  <author>
    <name>Varun Barad</name>
  </author>

  
    
    <entry>
      <title type="html">Building single-page HTML tools</title>
      <link href="https://varunbarad.com/blog/html-tools.html" rel="alternate" type="text/html" title="Building single-page HTML tools"/>
      <published>2026-04-19T18:58:28+05:30</published>
      <updated>2026-04-19T18:58:28+05:30</updated>
      <id>https://varunbarad.com/blog/html-tools.html</id>
      <content type="html">
      &lt;p&gt;Following &lt;a href=&quot;https://simonwillison.net/2025/Dec/10/html-tools/&quot;&gt;Simon Willison&#39;s advice&lt;/a&gt;, I also started letting the LLMs loose on some of my tool needs which I thought could be concisely handled in a single web-page. That&#39;s how &lt;a href=&quot;https://github.com/VarunBarad/tools&quot;&gt;https://github.com/VarunBarad/tools&lt;/a&gt; was born.&lt;/p&gt;
&lt;p&gt;Most of the code here is made simply by prompting in the web version of Claude, which is then later downloaded and added to this repo. I want to try the Gemini and GPT models for some future tools I decide to add.&lt;/p&gt;
&lt;h2&gt;A4 ID Layout&lt;/h2&gt;
&lt;p&gt;I started with something that I deal with occasionally but is a huge pain every time that I have to do it. I try to keep my government IDs scanned and sorted so that whenever I need to submit one for documentation/registration/verification/whatever I can turn in a single page PDF which contains both the front and back of that ID. Previously I used to do this in GIMP, and while I had nailed down the process quite a lot, it was still a tedious task. I had to crop both the scans, rearrange both the cropped images, ensure they are the same size, apply the correct title text, export them as PNG, run it through an image-compression pass, convert it to PDF.&lt;/p&gt;
&lt;p&gt;This time I tasked Claude to make a single-file HTML webpage where I can supply the two cropped images and the title text, and it will arrange everything and I can download the arranged image directly, with a built-in live preview. There was some back and forth, and I added a couple of requirements after seeing the first version. But voilà, I have what I need and its&#39; going to be much smoother the next time I have to sort some other ID.&lt;/p&gt;
&lt;figure&gt;
   &lt;img alt=&quot;A definitely genuine driver&#39;s license for one John Wick&quot; src=&quot;https://varunbarad.com/assets/images/posts/html-tools/a4-id-layout.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;A definitely genuine driver&#39;s license for one John Wick&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Gaming tracker&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Horizon_Forbidden_West&quot;&gt;Horizon Forbidden West&lt;/a&gt; is one of the games I am playing currently, and there is also &lt;a href=&quot;https://mashthosebuttons.com/show/lightkeeper-protocol/&quot;&gt;a podcast&lt;/a&gt; I listen to about the game. In each episode of the podcast, they mention in the show-notes what missions of the game they talk about, but I don&#39;t want to listen to an episode before I have played everything covered in that episode myself. But the game is so vast that it is difficult to keep track of the names of all the story missions, side missions, errands, etc. in your head.&lt;/p&gt;
&lt;p&gt;I wanted a web-page where as I go along the game, I can tick off what missions I have completed so far. That way before listening to an episode of the podcast, I can check in my tracker whether I have completed all the in-game content covered in that episode. That led to the creation of the second tool in this tool-belt, HFW Quest Tracker.&lt;/p&gt;
&lt;p&gt;Claude fetched all the mission names and made a webpage with the complete list separated neatly into categories. I had to add a bunch of the categories and its data as it did not bring them all in by itself, but it was small work. It stores the progress data in browser&#39;s local-storage as this is not something that I care about preserving in case my device dies.&lt;/p&gt;
&lt;figure&gt;
   &lt;img alt=&quot;Progress-state image exported directly from the tool&quot; src=&quot;https://varunbarad.com/assets/images/posts/html-tools/hfw-tracker.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Progress-state image exported directly from the tool&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Random Starred Repos&lt;/h2&gt;
&lt;p&gt;I have in the past starred a lot of repos on GitHub, some of which I now look back and ponder why I did so. I want to clean up my starred repos, but I am not bothered enough with it to go through the complete list of my starred repos and then unstar any of the ones that I don&#39;t care about anymore.&lt;/p&gt;
&lt;p&gt;But just checking five repos from there at a time is something I can do. So I asked Claude to make a webpage where I can enter the GitHub username and it gives me 5 random entries from all the repos starred by that account. Since this is all public data and the usage would be so low, I could simply go by with unauthenticated GitHub API calls.&lt;/p&gt;
&lt;p&gt;Then from that list of five repos, I can open whichever ones seem un-star worthy and unstar them from GitHub. The added benefit of this tool is that as my starred list keeps getting leaner, I end up coming across interesting projects that are fun to revisit (today&#39;s hidden find was &lt;a href=&quot;https://github.com/boardgameio/boardgame.io&quot;&gt;https://github.com/boardgameio/boardgame.io&lt;/a&gt;).&lt;/p&gt;
&lt;figure&gt;
   &lt;img alt=&quot;Atleast three of these five repos are going to be un-starred&quot; src=&quot;https://varunbarad.com/assets/images/posts/html-tools/random-starred-repos.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Atleast three of these five repos are going to be un-starred&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Memory Sharpener&lt;/h2&gt;
&lt;p&gt;I remembered a game from my childhood where you start with a bunch of face-down cards and progressively reveal them in pairs. And if the two cards you open are the same, then they are eliminated, else they are turned face-down again. This I think is a good game to work on the working-memory capacity of your brain.&lt;/p&gt;
&lt;p&gt;I wanted a simple version where I could see the changes evaluated against my past attempts. I wanted to track both how long it took to complete the whole board and how many times I had to flip the cards. I want to keep both those numbers as down as possible. Again, this was completely made in the Claude web chat and then later added here. It uses &lt;a href=&quot;https://www.chartjs.org/&quot;&gt;Chart.js&lt;/a&gt; to render the historical performance chart and stores all data in local-storage.&lt;/p&gt;
&lt;p&gt;You can play it yourself over at &lt;a href=&quot;https://tools.varunbarad.com/mm2-game.html&quot;&gt;https://tools.varunbarad.com/mm2-game.html&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;
   &lt;img alt=&quot;A blank board with all 48 cards face-down&quot; src=&quot;https://varunbarad.com/assets/images/posts/html-tools/mm2-game.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;A blank board with all 48 cards face-down&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;These are the ones I have made till now, I would keep adding more as my needs keep changing.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="tools"/>
      
      <category term="web"/>
      
      <summary type="html">The major LLMs are pretty good at building small single-page HTML tools, here&#39;s a few on my tool-belt</summary>
    </entry>
  
    
    <entry>
      <title type="html">My first 3D model that I am proud of</title>
      <link href="https://varunbarad.com/blog/first-3d-model-proud.html" rel="alternate" type="text/html" title="My first 3D model that I am proud of"/>
      <published>2026-04-16T07:44:58+05:30</published>
      <updated>2026-04-16T07:44:58+05:30</updated>
      <id>https://varunbarad.com/blog/first-3d-model-proud.html</id>
      <content type="html">
      &lt;p&gt;I own a 3D printer since last year and while I have printed a bunch of different things on it, most of them were not designed by me. They were mostly models that I was just downloading from internet and printing out as I needed. There were some that were designed by me but they were extremely simple like some tokens for a board game, or a fridge magnet, etc.&lt;/p&gt;
&lt;p&gt;But &lt;s&gt;this week&lt;/s&gt; a few weeks ago (I am finishing this post much later than when I started) I designed a hook/bracket for my mother to hang her macrame support stick (a pipe in her case) from a chair&#39;s back. The portion where the actual support stick goes into the bracket is a snap-fit. So the user can put the stick in an take it out as they like, but the stick would not move out by other movements while working on the macrame threads.&lt;/p&gt;
&lt;p&gt;When I first held the printed version of this in hand, it made me feel that I also can make actually useful stuff and not just more cheap plastic waste.&lt;/p&gt;
&lt;figure&gt;
   &lt;img alt=&quot;Cross section of the bracket with the snap-fit mechanism on the left side&quot; src=&quot;https://varunbarad.com/assets/images/posts/first-3d-model-proud/cross-section.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Cross section of the bracket with the snap-fit mechanism on the left side&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;During designing it felt like the walls around the stick were too thin for the snap-fit to work correctly, but I also didn&#39;t want to thicken them up so much that they would not bend at all. I kept thinking that swapping the support stick in-and-out a few times would cause the walls to permanently deform. Thus losing the shape which made the snap-fit mechanism work in the first place. Then when the printer started printing and I saw a few layers come up, that feeling grew stronger as there was no in-fill material at those points, it was just a couple of wall layers. I thought of but decided not to cancel the print.&lt;/p&gt;
&lt;p&gt;I only printed out one to begin with (I actually needed two) and when it was finally done, the snap had just the right force. It was also not causing any sort of deformation even after swapping the stick in-and-out more than a few dozen times.&lt;/p&gt;
&lt;figure&gt;
   &lt;img alt=&quot;The bracket in use on a chair with the support pipe snapped into it&quot; src=&quot;https://varunbarad.com/assets/images/posts/first-3d-model-proud/bracket-in-action.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;The bracket in use on a chair with the support pipe snapped into it&lt;/figcaption&gt;
&lt;/figure&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="personal-growth"/>
      
      <summary type="html">I designed a bracket with a snap-fit mechanism, and I am proud of it</summary>
    </entry>
  
    
    <entry>
      <title type="html">Weak villains are not acceptable anymore</title>
      <link href="https://varunbarad.com/blog/weak-villains-are-not-acceptable-anymore.html" rel="alternate" type="text/html" title="Weak villains are not acceptable anymore"/>
      <published>2026-04-12T16:39:52+05:30</published>
      <updated>2026-04-12T16:39:52+05:30</updated>
      <id>https://varunbarad.com/blog/weak-villains-are-not-acceptable-anymore.html</id>
      <content type="html">
      &lt;p&gt;Last evening, me and my wife went to watch our first theatre/musical/play together. I have seen a play once as a child, but I don&#39;t remember much about it, so this was practically my first experience watching a play. The play was titled &lt;a href=&quot;https://www.instagram.com/merekrishnplay/&quot;&gt;Mere Krishn&lt;/a&gt; (sorry for the Instagram link, but it looks like this is their primary medium of outreach) and was based on various events in Lord Krishna&#39;s life.&lt;/p&gt;
&lt;p&gt;It was directed by Shri Rajiiv Singhh Dinkaar and chief actors were &lt;a href=&quot;https://en.wikipedia.org/wiki/Sourabh_Raaj_Jain&quot;&gt;Sourabh Raaj Jain&lt;/a&gt; as Lord Krishna, &lt;a href=&quot;https://en.wikipedia.org/wiki/Pooja_Sharma_(Indian_actress)&quot;&gt;Pooja Sharma&lt;/a&gt; as Radha Devi and &lt;a href=&quot;https://en.wikipedia.org/wiki/Arpit_Ranka&quot;&gt;Arpit Ranka&lt;/a&gt; as the antagonist Duryodhan. While everyone carried and commanded their part, it was the character and performance of Arpit Ranka who had me the most captured. Both the writing of the character and Arpit Ranka&#39;s enactment of the same were top-notch. That is what has finally snapped the threshold in me that now if any story, movie or play has a not properly written/performed antagonist then it is not getting my praise unless some other part is exceptionally well done.&lt;/p&gt;
&lt;p&gt;While watching the play and even after, I was just amazed at what all was pulled off by the back-stage crew and the logistics teams. Some amazing stuff that comes to the top of mind:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Costume changes of all the performers&lt;/li&gt;
&lt;li&gt;Visuals creating the backdrop on the LED screens behind the performing stage&lt;/li&gt;
&lt;li&gt;Creation of all the set-props and ensuring they are transported safely around wherever they go to perform&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;One thing that I felt about theatre over regular movies is that everyone is generally more intentional and present in the moment. There are no retakes if you mess up a scene, I think that separates the wheat from the chaff much better than movies usually do.&lt;/p&gt;
&lt;p&gt;These and a lot other things made yesterday wonderful. Thank you to team Mere Krishn for this memorable experience. I would urge you folks to check out if the play is coming to somewhere near you and go watch it if you can, you can find their schedule on their &lt;a href=&quot;https://www.instagram.com/merekrishnplay/&quot;&gt;Instagram page&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <category term="plays"/>
      
      <summary type="html">There is no excuse for stories to have a poorly written antagonist</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 Project Hail Mary</title>
      <link href="https://varunbarad.com/blog/movie-project-hail-mary.html" rel="alternate" type="text/html" title="🎬 Project Hail Mary"/>
      <published>2026-04-05T22:17:40+05:30</published>
      <updated>2026-04-05T22:17:40+05:30</updated>
      <id>https://varunbarad.com/blog/movie-project-hail-mary.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Poster of the movie Project Hail Mary&quot; src=&quot;https://varunbarad.com/assets/images/movies/project-hail-mary-poster.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Score: 3/5 👍 (Only because I have read the book, otherwise it would be a 4/5 👌)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In the near future, astronaut Ryland Grace wakes from a coma afflicted with amnesia. He gradually remembers that he was sent to the Tau Ceti solar system, 12 light-years from Earth, to find a means of reversing a solar dimming event that could cause the extinction of humanity.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://www.thetvdb.com/movies/project-hail-mary&quot;&gt;TheTVDB.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Since I have already read the book, I couldn&#39;t stop myself from comparing the movie with the book. The movie falls short on a lot of details that were explained in the books, and it is understandable that the director could not cover the whole thing in 2.5 hours. I am glad though that they didn&#39;t modify any incident/detail to be different from the book, all the differences were of omission and not of modification (even if there were modifications I could not recognize them as I read the book quite a few years ago now).&lt;/p&gt;
&lt;p&gt;The actors also deserve credit here. Ryan Gosling has done a good job of enacting the personality of Dr Ryland Grace. And Sandra Hüller matches the flat no-nonsense attitude of Eva Stratt. The star of the show though was definitely my beloved Rocky. The voice-acting, the motion-capture, the character was given proper justice when bringing it on-screen.&lt;/p&gt;
&lt;p&gt;If you haven&#39;t read the book, then definitely go and see the movie. It is a well-made enjoyable sci-fi movie. But if you have read the book then watch it to meet some of those characters that you enjoyed reading about. It is worth watching atleast once.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="movies"/>
      
      <summary type="html">My thoughts and opinions on this movie</summary>
    </entry>
  
    
    <entry>
      <title type="html">Prevent PyCharm from creating the PyCharmMisc project</title>
      <link href="https://varunbarad.com/blog/pycharm-prevent-pycharmmisc-project.html" rel="alternate" type="text/html" title="Prevent PyCharm from creating the PyCharmMisc project"/>
      <published>2026-03-24T07:10:07+05:30</published>
      <updated>2026-03-24T07:10:07+05:30</updated>
      <id>https://varunbarad.com/blog/pycharm-prevent-pycharmmisc-project.html</id>
      <content type="html">
      &lt;p&gt;Solution source: &lt;a href=&quot;https://platform.jetbrains.com/t/how-to-prevent-pycharm-from-creating-pycharmmiscproject-by-default/3107/5&quot;&gt;Tiago Candeias on JetBrains forums&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The PyCharm IDE now creates a project named &amp;quot;PyCharmMisc&amp;quot; in your home directory. I guess it might be to make the IDE&#39;s onboarding experience simpler for novice users, but I don&#39;t want it to clutter my home directory.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Save and close all your other open projects in PyCharm&lt;/li&gt;
&lt;li&gt;Uncheck the &amp;quot;Enable non-modal Welcome screen&amp;quot; checkbox at the bottom of the &amp;quot;Welcome to PyCharm&amp;quot; tab/screen&lt;/li&gt;
&lt;li&gt;Close PyCharm&lt;/li&gt;
&lt;li&gt;Delete the &amp;quot;PyCharmMisc&amp;quot; project from your home directory&lt;/li&gt;
&lt;li&gt;Open PyCharm, it should now open with the list of your projects (how it used to)&lt;/li&gt;
&lt;/ol&gt;
&lt;figure&gt;
   &lt;img alt=&quot;Screenshot of PyCharm with an arrow pointing to the checkbox that needs to be unchecked&quot; src=&quot;https://varunbarad.com/assets/images/posts/pycharm-prevent-pycharmmisc-project/pycharm.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Screenshot of PyCharm with an arrow pointing to the checkbox that needs to be unchecked&lt;/figcaption&gt;
&lt;/figure&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="python"/>
      
      <summary type="html">How to prevent PyCharm from creating the PyCharmMisc project on startup</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 &quot;undefined&quot; is not defined at the language level</title>
      <link href="https://varunbarad.com/blog/til-javascript-undefined.html" rel="alternate" type="text/html" title="📝 &quot;undefined&quot; is not defined at the language level"/>
      <published>2026-03-23T00:50:56+05:30</published>
      <updated>2026-03-23T00:50:56+05:30</updated>
      <id>https://varunbarad.com/blog/til-javascript-undefined.html</id>
      <content type="html">
      &lt;p&gt;Staying true to its name &lt;code&gt;undefined&lt;/code&gt; is not a language-level value in JavaScript. It is instead defined as a read-only property on the global &lt;code&gt;window&lt;/code&gt; object. The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures#undefined_type&quot;&gt;Undefined type&lt;/a&gt; is defined in the language but only the &lt;code&gt;window.undefined&lt;/code&gt; property is of that type.&lt;/p&gt;
&lt;p&gt;Since the properties of &lt;code&gt;window&lt;/code&gt; object are available globally, whenever we write &lt;code&gt;undefined&lt;/code&gt; we are pointing to the &lt;code&gt;window.undefined&lt;/code&gt; property. What this means is that even though the &lt;code&gt;window.undefined&lt;/code&gt; is read-only and we cannot change what it means (duh, that&#39;s what read-only means), we can still shadow it by redefining &lt;code&gt;undefined&lt;/code&gt; inside a closure.&lt;/p&gt;
&lt;h2&gt;Case 1: Regular behavior&lt;/h2&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;regularBehavior&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;typeof undefined:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;undefined =&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;regularBehavior&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we are just pointing to the top-level &lt;code&gt;window.undefined&lt;/code&gt; property as we don&#39;t have any other property with the same name defined in our closure (the function &lt;code&gt;regularBehavior&lt;/code&gt; in this case).&lt;/p&gt;
&lt;h2&gt;Case 2: Local variable shadowing the &lt;code&gt;window&lt;/code&gt; property&lt;/h2&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;localVariable&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;typeof undefined:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;typeof window.undefined:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;undefined&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;undefined =&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Is undefined === 2:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;localVariable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we are defining a local variable with the name &lt;code&gt;undefined&lt;/code&gt;, this makes it so that when we refer to &lt;code&gt;undefined&lt;/code&gt; it refers to our local variable rather than going to the &lt;code&gt;window&lt;/code&gt; level property. This is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Variable_shadowing&quot;&gt;variable shadowing&lt;/a&gt; where a variable in a closer scope covers a similarly named variable in a further-out scope.&lt;/p&gt;
&lt;p&gt;This might or mightn&#39;t be useful for anyone, but I found this to be weird that such a widely used language constant isn&#39;t actually a constant and can be made to give out different values instead.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="javascript"/>
      
      <category term="til"/>
      
      <summary type="html">JavaScript&#39;s infamous &lt;code&gt;undefined&lt;/code&gt; is not a language-level constant and can indeed be made to behave like a different value</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 Little Brother</title>
      <link href="https://varunbarad.com/blog/book-little-brother.html" rel="alternate" type="text/html" title="📚 Little Brother"/>
      <published>2026-03-22T19:11:19+05:30</published>
      <updated>2026-03-22T19:11:19+05:30</updated>
      <id>https://varunbarad.com/blog/book-little-brother.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Cover of the book Little Brother&quot; src=&quot;https://varunbarad.com/assets/images/books/little-brother.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Seventeen year old Marcus and his friends are in the wrong place at the wrong time during a major terrorist attack on San Francisco. They are held by the Department of Homeland Security for days before being released only to discover that their city has turned into surveillance society police state. They decide to resist in the only way they know how by taking on the DHS.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://openlibrary.org/books/OL24085290M/Little_Brother&quot;&gt;Open Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I basically read this book in two parts, the first was back when I started it in 2023. I read it up to a point and then dropped it as it seemed too doom-and-gloom, the protagonists were basically locked in a battle with a behemoth. They were in a battle that they could not at all come out unscathed from, if they can come out of it at all.&lt;/p&gt;
&lt;p&gt;I picked it up again last week thinking that I had probably read a few starting chapters the last time. I had underestimated my previous effort, as I kept reading I kept realizing that these all were sections I had already read before. Turns out that I had read more than half-way through in my last session.&lt;/p&gt;
&lt;p&gt;Having finished it, I can say that it is a pretty good book. Especially if you are trying to introduce the concepts of cryptography, network security and privacy to a younger audience. The book is written with a teen protagonist which would help them connect more with the hero.&lt;/p&gt;
&lt;p&gt;There were some sections in the middle where things look extremely bad for our heroes. We do see what could happen to them if they get caught, we are given a glimpse of that earlier in the story. If someone, like me, didn&#39;t finish the story because things weren&#39;t looking good for the heroes then rest assured that things turn out good-ish for them in the end. The heroes (with some support) put up a very brave fight, they don&#39;t immediately get all that they want, but there is a silver lining to all those clouds.&lt;/p&gt;
&lt;p&gt;If you are into any of science-fiction or software/tech or political activism then you would enjoy having read this.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="book-highlights"/>
      
      <summary type="html">My thoughts and opinions on this book</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 Dhurandhar: The Revenge</title>
      <link href="https://varunbarad.com/blog/movie-dhurandhar-revenge.html" rel="alternate" type="text/html" title="🎬 Dhurandhar: The Revenge"/>
      <published>2026-03-19T07:13:19+05:30</published>
      <updated>2026-03-19T07:13:19+05:30</updated>
      <id>https://varunbarad.com/blog/movie-dhurandhar-revenge.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Poster of the movie Dhurandhar: The Revenge&quot; src=&quot;https://varunbarad.com/assets/images/movies/dhurandhar-revenge-poster.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Score: 5/5 🎖&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As rival gangs, corrupt officials and a ruthless Major Iqbal close in, Jaskirat Singh’s mission for his country spirals into a bloody personal war where the line between patriot and monster disappears in the streets of Lyari.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://www.thetvdb.com/movies/hjj-372129&quot;&gt;TheTVDB.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is the first movie I saw in a theatre this year, and I doubt I will be watching anything else that matches the hype or tempo of this. This was even longer than the &lt;a href=&quot;https://varunbarad.com/blog/movie-dhurandhar&quot;&gt;first movie&lt;/a&gt; at over three hours and forty-five minutes, and there was not a single dull moment throughout all of it.&lt;/p&gt;
&lt;p&gt;In the age of reels and youtube shorts, this sets an example by being able to hold people&#39;s attention for so long. Maybe we didn&#39;t stop watching complete movies because our attention spans decreased, but it happened because movies stopped being good.&lt;/p&gt;
&lt;p&gt;&amp;quot;Jameel Jamali&amp;quot; performed by the legendary &lt;a href=&quot;https://en.wikipedia.org/wiki/Rakesh_Bedi&quot;&gt;Rakesh Bedi&lt;/a&gt; still remains my favorite character+actor combo, but there was a lot of competition for him in this movie. It is said that to bring out the greatness of a hero, the story needs a great villain, and boy does &lt;a href=&quot;https://en.wikipedia.org/wiki/Arjun_Rampal&quot;&gt;Arjun Rampal&lt;/a&gt; deliver that villain.&lt;/p&gt;
&lt;p&gt;The movie starts off with showing the past of Jaskirat Singh Rangi and how he was commisioned in &amp;quot;Project Dhurandhar&amp;quot;. This was very painful to watch, not because the filming was bad but because it must have been a thousand times more painful for the people involved.&lt;/p&gt;
&lt;p&gt;Near the end there were two moments which I did not expect at all. Did not expect them even a single bit. To end my rambling, I will only say one line.&lt;/p&gt;
&lt;p&gt;दिल जीत लिया धर साहब।&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="movies"/>
      
      <summary type="html">My thoughts and opinions on this movie</summary>
    </entry>
  
    
    <entry>
      <title type="html">I am not going to read Malgudi Days any further</title>
      <link href="https://varunbarad.com/blog/ditching-malgudi-days.html" rel="alternate" type="text/html" title="I am not going to read Malgudi Days any further"/>
      <published>2026-03-18T23:28:25+05:30</published>
      <updated>2026-03-18T23:28:25+05:30</updated>
      <id>https://varunbarad.com/blog/ditching-malgudi-days.html</id>
      <content type="html">
      &lt;p&gt;Malgudi Days is a very popular children&#39;s book (probably a series) written by R. K. Narayan. Some stories from it are even part of the curriculum in many schools. In school days I used to think that I didn&#39;t like the stories maybe because we were later questioned on the stories with all the typical language subject questions that teachers ask: what did we learn from this, what did the author mean by this incidence, etc.&lt;/p&gt;
&lt;p&gt;So recently I had picked up a second-hand copy of the book and was reading through it. Today I read probably the third or fourth story from the book and have decided to not read any more of it.&lt;/p&gt;
&lt;p&gt;Each story I have read so far either has a sad ending or a neutral one at best. The world painted with the words does seem very enchanting. But frankly I don&#39;t have the spare energy to read more gray/sad endings. The author is very widely acclaimed, and that might be very well deserved. But the stories don&#39;t match my taste.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Now I just need to figure out how to modify my &lt;a href=&quot;https://varunbarad.com/books&quot;&gt;books&lt;/a&gt; pages to handle books that I drop midway.&lt;/em&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="books"/>
      
      <summary type="html">I read one more story from Malgudi Days today and am not going to read any more of that book</summary>
    </entry>
  
    
    <entry>
      <title type="html">Battling a Tremortusk to gain wakefulness</title>
      <link href="https://varunbarad.com/blog/battling-tremortusk-wakefulness.html" rel="alternate" type="text/html" title="Battling a Tremortusk to gain wakefulness"/>
      <published>2026-03-13T08:40:50+05:30</published>
      <updated>2026-03-13T08:40:50+05:30</updated>
      <id>https://varunbarad.com/blog/battling-tremortusk-wakefulness.html</id>
      <content type="html">
      &lt;p&gt;One day this week, I had caught some infection and had sore throat. On taking a tablet for the same, it made me extremely drowsy and knocked me out for the first half of the day. It was a work day and I had some important tasks to finish before closing the day, so couldn&#39;t afford to doze-off again after lunch.&lt;/p&gt;
&lt;p&gt;To battle that onset of post-lunch drowsiness (the meds were making it more difficult) I decided to do a quick session of Horizon Forbidden West, as it requires quite a lot of focused attention in battles. Looking around the map from where I had last saved, I found a nearby Tremortusk site and headed for it. This proved to be a perfect 10 min jolt that my body needed.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Aloy aiming at a Tremortusk in Horizon Forbidden West&quot; src=&quot;https://varunbarad.com/assets/images/posts/battling-tremortusk-wakefulness/aloy-aim-tremortusk.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Aloy aiming at a Tremortusk in Horizon Forbidden West&lt;/figcaption&gt;
&lt;/figure&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">I was feeling extremely drowsy and decided to use a video-game to break out of it</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 The Murderbot Diaries: All Systems Red</title>
      <link href="https://varunbarad.com/blog/book-the-murderbot-diaries-all-systems-red.html" rel="alternate" type="text/html" title="📚 The Murderbot Diaries: All Systems Red"/>
      <published>2026-03-12T12:10:57+05:30</published>
      <updated>2026-03-12T12:10:57+05:30</updated>
      <id>https://varunbarad.com/blog/book-the-murderbot-diaries-all-systems-red.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Cover of the book All Systems Red&quot; src=&quot;https://varunbarad.com/assets/images/books/the-murderbot-diaries-all-systems-red.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In a corporate-dominated spacefaring future, planetary missions must be approved and supplied by the Company. Exploratory teams are accompanied by Company-supplied security androids, for their own safety.&lt;/p&gt;
&lt;p&gt;But in a society where contracts are awarded to the lowest bidder, safety isn&#39;t a primary concern.&lt;/p&gt;
&lt;p&gt;On a distant planet, a team of scientists are conducting surface tests, shadowed by their Company-supplied &#39;droid — a self-aware SecUnit that has hacked its own governor module, and refers to itself (though never out loud) as &amp;quot;Murderbot&amp;quot;. Scornful of humans, all it really wants is to be left alone long enough to figure out who it is.&lt;/p&gt;
&lt;p&gt;But when a neighboring mission goes dark, it&#39;s up to the scientists and their Murderbot to get to the truth.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://openlibrary.org/books/OL17914663W/All_Systems_Red&quot;&gt;Open Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I had not read any science-fiction for a long time and this was a wonderful book to break out of that. I liked how it started and Murderbot&#39;s inner monologue was also fun. A little more world-building would probably have made it more interesting to me, like the layouts of their habitats and/or hoppers. But I guess that would detract from the tight pacing of the story which I think the author was aiming for.&lt;/p&gt;
&lt;p&gt;I started it on a recent train journey and managed to finish around one-third of the story on that single journey, subsequently it was interesting enough that over the next 3 days I prioritised spending time reading over other hobbies.&lt;/p&gt;
&lt;p&gt;Overall, a nice short sci-fi read.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Spoilers ahead:&lt;/strong&gt; I really did not like how in the end Murderbot slipped away without notifying the very person (specifically Mensah) who helped him gain his freedom. I know this is how it&#39;s personality is developed throughout the book that he doesn&#39;t like dealing with humans and/or emotions (or emotional situations) face-to-face, but I think Mensah deserved to atleast be told to her face that he doesn&#39;t want to continue with them.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="book-highlights"/>
      
      <summary type="html">My thoughts and opinions on this book</summary>
    </entry>
  
    
    <entry>
      <title type="html">How to change the font in Kodi media player installed on a Mac</title>
      <link href="https://varunbarad.com/blog/kodi-font-mac.html" rel="alternate" type="text/html" title="How to change the font in Kodi media player installed on a Mac"/>
      <published>2026-03-01T01:57:39+05:30</published>
      <updated>2026-03-01T01:57:39+05:30</updated>
      <id>https://varunbarad.com/blog/kodi-font-mac.html</id>
      <content type="html">
      &lt;p&gt;The Kodi media player doesn&#39;t fare well in displaying non-latin characters in the default font of its default skin. We have to supply a font which can display Unicode characters properly (especially देवनागरी characters in my case).&lt;/p&gt;
&lt;p&gt;First of all, huge thanks to &lt;a href=&quot;https://forum.jellyfin.org/u-linesma&quot;&gt;&amp;quot;linesma&amp;quot;&lt;/a&gt; over on Jellyfin Forum for &lt;a href=&quot;https://forum.jellyfin.org/t-changing-the-default-font-in-kodi-to-display-unicode-characters&quot;&gt;their detailed explanation&lt;/a&gt; of this.&lt;/p&gt;
&lt;p&gt;The only problem is that the above guide covers how to do it on other platforms, but I am using a Mac. Therefore file-destinations change a bit.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;From the above guide, ensure that your font file is named &lt;code&gt;arial.ttf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Copy that &lt;code&gt;arial.ttf&lt;/code&gt; to &lt;code&gt;~/Library/Application Support/Kodi/fonts/&lt;/code&gt; directory&lt;/li&gt;
&lt;li&gt;Now you can go to Kodi and change the font used to be &amp;quot;Arial based&amp;quot;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here&#39;s a small before-and-after:&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Kodi trying to show a देवनागरी movie title with its default font&quot; src=&quot;https://varunbarad.com/assets/images/posts/kodi-font-mac/before.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Kodi trying to show a देवनागरी movie title with its default font&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Kodi successfully rendering देवनागरी movie title after updating the font&quot; src=&quot;https://varunbarad.com/assets/images/posts/kodi-font-mac/after.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Kodi successfully rendering देवनागरी movie title after updating the font&lt;/figcaption&gt;
&lt;/figure&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">How to set a font for Kodi media player (on a Mac) that properly shows देवनागरी (Devanagri) characters</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Scroll a page to an element using &lt;code&gt;scrollIntoView()&lt;/code&gt;</title>
      <link href="https://varunbarad.com/blog/til-javascript-scrollIntoView.html" rel="alternate" type="text/html" title="📝 Scroll a page to an element using &lt;code&gt;scrollIntoView()&lt;/code&gt;"/>
      <published>2026-02-08T16:56:51+05:30</published>
      <updated>2026-02-08T16:56:51+05:30</updated>
      <id>https://varunbarad.com/blog/til-javascript-scrollIntoView.html</id>
      <content type="html">
      &lt;p&gt;I was recently making a vertical accordion style component and had to have this interaction pattern:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;User is presented with a list of clickable items&lt;/li&gt;
&lt;li&gt;User clicks an item&lt;/li&gt;
&lt;li&gt;Expand the children of the selected item&lt;/li&gt;
&lt;li&gt;Scroll the page/container so that the selected item comes at the top of the page&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This had to be done so that in case the children expand outside the visible area, then the user does not get confused that nothing opened at all.&lt;/p&gt;
&lt;p&gt;I only knew originally of &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo&quot;&gt;&lt;code&gt;element.scrollTo&lt;/code&gt;&lt;/a&gt; method, but &lt;a href=&quot;https://stackoverflow.com/a/78092566/4717436&quot;&gt;Prasad Nagthane on StackOverflow&lt;/a&gt; pointed me to &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView&quot;&gt;&lt;code&gt;element.scrollIntoView()&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; element &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;elementToShowAtTop&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
element&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;scrollIntoView&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This gives me the benefit that I don&#39;t have to keep track of which element is the scroll container. If we want to use the &lt;code&gt;scrollTo&lt;/code&gt; method then we need to apply it to the scroll container rather than the actual element which we want to show.&lt;/p&gt;
&lt;p&gt;Another advantage is that &lt;code&gt;scrollIntoView&lt;/code&gt; gives much more control on how and where to position the element within the scroll container. You can choose to align it with the top or the bottom or a couple of other options. Do look into its documentation.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="javascript"/>
      
      <category term="til"/>
      
      <category term="web"/>
      
      <summary type="html">If you want to scroll a page to a particular element using JavaScript, you can call &lt;code&gt;element.scrollIntoView()&lt;/code&gt;</summary>
    </entry>
  
    
    <entry>
      <title type="html">🐘 Matching a sub-string in PostgreSQL</title>
      <link href="https://varunbarad.com/blog/postgresql-substring-match.html" rel="alternate" type="text/html" title="🐘 Matching a sub-string in PostgreSQL"/>
      <published>2026-01-28T10:08:37+05:30</published>
      <updated>2026-01-28T10:08:37+05:30</updated>
      <id>https://varunbarad.com/blog/postgresql-substring-match.html</id>
      <content type="html">
      &lt;p&gt;This is embarrassing how many times I have had to look this up. Writing it down this time, so atleast I know for sure where I can find the info.&lt;/p&gt;
&lt;p&gt;Let&#39;s say you have a table named &lt;code&gt;people_info&lt;/code&gt; with one of the columns called &lt;code&gt;email&lt;/code&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:left&quot;&gt;email&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;varun@work.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;cdain3@qq.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;varunsomeone@gmail.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;poseidon@yahoo.co.in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;special_varun@yahoo.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;areswashere@aol.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;varun+unique@example.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;trash@varunbarad.com&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Now we only want rows where &lt;code&gt;email&lt;/code&gt; contains the sub-string &lt;code&gt;varun&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; email
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people_info
&lt;span class=&quot;token keyword&quot;&gt;where&lt;/span&gt; email &lt;span class=&quot;token operator&quot;&gt;like&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;%varun%&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This now gives us:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:left&quot;&gt;email&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;varun@work.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;varunsomeone@gmail.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;special_varun@yahoo.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;varun+unique@example.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:left&quot;&gt;trash@varunbarad.com&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="postgresql"/>
      
      <summary type="html">Throwing runtime exception/error from native functions in Lox</summary>
    </entry>
  
    
    <entry>
      <title type="html">Ten pointless facts about me</title>
      <link href="https://varunbarad.com/blog/pointless-facts-2026.html" rel="alternate" type="text/html" title="Ten pointless facts about me"/>
      <published>2026-01-19T08:11:12+05:30</published>
      <updated>2026-01-19T08:11:12+05:30</updated>
      <id>https://varunbarad.com/blog/pointless-facts-2026.html</id>
      <content type="html">
      &lt;p&gt;One easy method of stepping around the writer&#39;s block is to use the prompts provided by blogging challenges. They make for an easy and lightweight starting point. &lt;a href=&quot;https://abhinavsarkar.net/notes/2025-ten-pointless-facts/&quot;&gt;Here is one&lt;/a&gt; that was doing the rounds last year.&lt;/p&gt;
&lt;h2&gt;1. Do you floss your teeth?&lt;/h2&gt;
&lt;p&gt;Nope, never have. Flossing isn&#39;t as big a deal in India as it is generally in the west. I haven&#39;t found a need to floss, but I do brush my teeth thoroughly twice a day.&lt;/p&gt;
&lt;h2&gt;2. Tea, coffee, or water?&lt;/h2&gt;
&lt;p&gt;This is complicated. Water is my favorite beverage, but I like to have a cup of cold/warm milk (depending on the season) with my breakfast. Even when going out, rather than going for coffee or tea, I generally prefer a drink with milk as the primary ingredient. My wife is a huge tea lover, so since my marriage I have been getting more and more comfortable with tea also.&lt;/p&gt;
&lt;h2&gt;3. Footwear preference?&lt;/h2&gt;
&lt;p&gt;These shoes from the &lt;a href=&quot;https://www.bata.com/in/power-outdoor-shoes-for-men-500_0PW8338944503F.html&quot;&gt;&amp;quot;Bata – Power&amp;quot;&lt;/a&gt; brand are what I find the most comfortable. In summers they only get worn outdoors, but winters see a separate pair come out specifically to be worn indoors.&lt;/p&gt;
&lt;h2&gt;4. Favourite dessert?&lt;/h2&gt;
&lt;p&gt;If we are talking about cold dessert, then generally some flavour of ice-cream, I tend to enjoy a variety of different flavours.&lt;/p&gt;
&lt;p&gt;If we are talking about warm dessert, then walnut brownies are the ones who take the crown.&lt;/p&gt;
&lt;h2&gt;5. The first thing you do when you wake up?&lt;/h2&gt;
&lt;p&gt;Drink a lot of water. I generally tend to not wake up in the middle of the night, and as a result am generally parched by the time morning comes around.&lt;/p&gt;
&lt;h2&gt;6. Age you&#39;d like to stick at?&lt;/h2&gt;
&lt;p&gt;On the one hand, I am fine with my current age. But if I could keep accruing the wisdom and experience, then I would like to keep my fitness levels from back when I was 22–23 years old.&lt;/p&gt;
&lt;h2&gt;7. How many hats do you own?&lt;/h2&gt;
&lt;p&gt;None. Caps are the preferred mode of sun-protection in India. I have four caps and three beanies. I don&#39;t think I have bought any of those, my dad generally gets me cool caps and beanies that he finds. Thanks dad ❤️&lt;/p&gt;
&lt;h2&gt;8. Describe the last photo you took?&lt;/h2&gt;
&lt;p&gt;It is of a makeshift cloth-tent that me and my wife made in our balcony to protect the &lt;em&gt;papdis&lt;/em&gt; that we put out for drying.&lt;/p&gt;
&lt;h2&gt;9. Worst TV show?&lt;/h2&gt;
&lt;p&gt;No idea. If I find a show bad, then I generally don&#39;t tend to watch it any further. So I can&#39;t rank any of them as being the &amp;quot;worst&amp;quot;.&lt;/p&gt;
&lt;h2&gt;10. As a child, what was your aspiration for adulthood?&lt;/h2&gt;
&lt;p&gt;There were different phases, including being an archeologist, being a soldier, a sports-person, etc. But the one that remained the longest was being a rocket-scientist. My parents (love you both ❤️) even got me a nice poster built of famous astronauts and rocket scientists to hang by my bedside.&lt;/p&gt;
&lt;p&gt;This challenge was initiated by David over at &lt;a href=&quot;https://forkingmad.blog/ten-pointless-facts-about-me/&quot;&gt;Forking Mad&lt;/a&gt;. I found it from one of &lt;a href=&quot;https://abhinavsarkar.net/notes/2025-ten-pointless-facts/&quot;&gt;Abhinav&#39;s posts&lt;/a&gt; last year.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/thats-all-folks.webp&quot; alt=&quot;That&#39;s all folks&quot; /&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="meta"/>
      
      <summary type="html">Another set of blog questions I wasn&#39;t challenged to answer</summary>
    </entry>
  
    
    <entry>
      <title type="html">Implementing number_to_string native function</title>
      <link href="https://varunbarad.com/blog/crafting-interpreters-number-to-string.html" rel="alternate" type="text/html" title="Implementing number_to_string native function"/>
      <published>2026-01-18T16:17:06+05:30</published>
      <updated>2026-01-18T16:17:06+05:30</updated>
      <id>https://varunbarad.com/blog/crafting-interpreters-number-to-string.html</id>
      <content type="html">
      &lt;p&gt;I am working my way through Crafting Interpreters and wanted to be able to concatenate numbers with strings so that I can print something like below:&lt;/p&gt;
&lt;pre class=&quot;language-lox&quot;&gt;&lt;code class=&quot;language-lox&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Iteration number &quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;: &quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;fibonacci_term&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The way we&#39;ve implemented the language up to this point requires both operands of the &lt;code&gt;+&lt;/code&gt; operator to either be numbers or strings, it cannot process a combination of number and string. Rather than extending the &lt;code&gt;+&lt;/code&gt; operator to deal with that scenario, I decided to add function &lt;code&gt;number_to_string&lt;/code&gt; to allow me to convert any number anywhere to a string.&lt;/p&gt;
&lt;p&gt;At this point in the book we had already defined a native function called &lt;code&gt;clock&lt;/code&gt; and decided I would do the same thing for &lt;code&gt;number_to_string&lt;/code&gt;. Here&#39;s how the existing &lt;code&gt;clock&lt;/code&gt; native function looks:&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Definition of the native function `clock`&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;com&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;varunbarad&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;lox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token import&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;java&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;NativeFunctionClock&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LoxCallable&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;arity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Interpreter&lt;/span&gt; interpreter&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1000.0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;native fn clock&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;clock&lt;/code&gt; function didn&#39;t take any parameters but &lt;code&gt;number_to_string&lt;/code&gt; takes one parameter, and I needed to ensure that only numbers are passed to it. So in this case I had to throw a runtime exception from inside the native function&#39;s &lt;code&gt;call&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;The problem is, that inside the function call, we did not have access to the token which marks the start of that function call and the &lt;code&gt;RuntimeError&lt;/code&gt; class (as shown below) requires one.&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// The custom exception we throw if we encounter a runtime problem in the lox program&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;com&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;varunbarad&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;lox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;RuntimeError&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;RuntimeException&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Token&lt;/span&gt; token&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token class-name&quot;&gt;RuntimeError&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Token&lt;/span&gt; token&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; message&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;message&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;token &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; token&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I thought of a few options of how to tackle that:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Throw an &lt;code&gt;IllegalArgumentException&lt;/code&gt; from inside the &lt;code&gt;call&lt;/code&gt; method and catch it in our &lt;code&gt;Interpreter&lt;/code&gt; class, and then throw the &lt;code&gt;RuntimeError&lt;/code&gt; from there.&lt;/li&gt;
&lt;li&gt;Drop the requirement for &lt;code&gt;Token&lt;/code&gt; from &lt;code&gt;RuntimeError&lt;/code&gt;. This was a silly idea, and I immediately shot it down.&lt;/li&gt;
&lt;li&gt;Pass the token which starts that function call inside the &lt;code&gt;call&lt;/code&gt; method of &lt;code&gt;LoxCallable&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Going with Option 1 would tightly couple the interpreter to each native function&#39;s specific errors. It would mean that the interpreter would need to be updated for any more functions (and the errors that they throw) I decide to add in the future.&lt;/p&gt;
&lt;p&gt;Option 2 was dead-on-arrival as we&#39;d lose valuable debugging information that helps us locate errors in the code.&lt;/p&gt;
&lt;p&gt;Finally, going with option 3 I can keep error handling self-contained within each native function while preserving the full error context. Here&#39;s the updated &lt;code&gt;LoxCallable&lt;/code&gt; interface:&lt;/p&gt;
&lt;pre class=&quot;language-diff-java&quot;&gt;&lt;code class=&quot;language-diff-java&quot;&gt;package com.varunbarad.lox;

import java.util.List;

public interface LoxCallable {
&lt;span class=&quot;token unchanged language-java&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;arity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;token deleted-sign deleted language-java&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt;    &lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Interpreter&lt;/span&gt; interpreter&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted language-java&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Token&lt;/span&gt; paren&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Interpreter&lt;/span&gt; interpreter&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now from withing the body of &lt;code&gt;call&lt;/code&gt; I can throw an instance of &lt;code&gt;RuntimeError&lt;/code&gt; with all the appropriate details. Here is the final implementation of &lt;code&gt;number_to_string&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Definition of the native function `number_to_string`&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;com&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;varunbarad&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;lox&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token import&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;java&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;List&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;NativeFunctionNumberToString&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LoxCallable&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;arity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Token&lt;/span&gt; paren&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Interpreter&lt;/span&gt; interpreter&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;Object&lt;/span&gt; arg &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getFirst&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;arg &lt;span class=&quot;token keyword&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Double&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Double&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; arg&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;RuntimeError&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;paren&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Argument must be a number, received: &quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; arg&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;native fn number_to_string&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, register it in the Interpreter constructor:&lt;/p&gt;
&lt;pre class=&quot;language-diff-java&quot;&gt;&lt;code class=&quot;language-diff-java&quot;&gt;// Registering `number_to_string` in the Interpreter constructor
&lt;span class=&quot;token deleted-sign deleted language-java&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Interpreter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt;    globals&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;clock&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;NativeFunctionClock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted language-java&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Interpreter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    globals&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;clock&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;NativeFunctionClock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    globals&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;number_to_string&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;NativeFunctionNumberToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the original lox sample updated to use &lt;code&gt;number_to_string&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-lox&quot;&gt;&lt;code class=&quot;language-lox&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Iteration number &quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;number_to_string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;: &quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;number_to_string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;fibonacci_term&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This now produces the output I was looking for, with iteration numbers and Fibonacci values neatly presented in a single line.&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Crafting Interpreters by Robert Nystrom: &lt;a href=&quot;https://craftinginterpreters.com/&quot;&gt;https://craftinginterpreters.com&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="crafting-interpreters"/>
      
      <summary type="html">Throwing runtime exception/error from native functions in Lox</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 Dhurandhar</title>
      <link href="https://varunbarad.com/blog/movie-dhurandhar.html" rel="alternate" type="text/html" title="🎬 Dhurandhar"/>
      <published>2025-12-31T23:55:30+05:30</published>
      <updated>2025-12-31T23:55:30+05:30</updated>
      <id>https://varunbarad.com/blog/movie-dhurandhar.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Poster of the movie Dhurandhar&quot; src=&quot;https://varunbarad.com/assets/images/movies/dhurandhar-poster.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Score: 5/5 🎖&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A death-row prisoner turned covert agent infiltrates Karachi’s deadly underworld to destroy a terror network before it engulfs India.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://www.thetvdb.com/movies/uuj-363182&quot;&gt;TheTVDB.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In a year of nice films (Chhaava and Kesari 2 come to mind), this three and half-hour banger stood out like a beacon. When I originally heard its songs, none other than the &lt;a href=&quot;https://music.youtube.com/watch?v=WzoSWtDDo1M&quot;&gt;title track&lt;/a&gt; and &lt;a href=&quot;https://music.youtube.com/watch?v=_dV23pgH3Ng&quot;&gt;Ishq Jalakar - Karvaan&lt;/a&gt; seemed good. But man have they integrated it well into the movie, now I like all of them as hearing any of them transports me to the movie part of it.&lt;/p&gt;
&lt;p&gt;The star-casting, the story writing, the performance (of each individual actor), I can&#39;t decide which of them was the best. All of them are so well done that the end-product is simply spectacular. Everyone did an awesome job, but my personal favorite was &lt;a href=&quot;https://en.wikipedia.org/wiki/Rakesh_Bedi&quot;&gt;Rakesh Bedi&lt;/a&gt; as &amp;quot;Jameel Jamali&amp;quot;.&lt;/p&gt;
&lt;p&gt;I am so happy I got to see this in theatres and can&#39;t wait to rewatch it once it is available on television. Eagerly waiting for the sequel coming in March next year (current year by the time you read this).&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="movies"/>
      
      <summary type="html">My thoughts and opinions on this movie</summary>
    </entry>
  
    
    <entry>
      <title type="html">🧳 Meghalaya Trip 2025</title>
      <link href="https://varunbarad.com/blog/trip-meghalaya.html" rel="alternate" type="text/html" title="🧳 Meghalaya Trip 2025"/>
      <published>2025-12-29T19:41:25+05:30</published>
      <updated>2025-12-29T19:41:25+05:30</updated>
      <id>https://varunbarad.com/blog/trip-meghalaya.html</id>
      <content type="html">
      &lt;p&gt;Slowly continuing our journey northwards in terms of trip-destination selection, this time me and my wife decided to visit Meghalaya in the last week of November when she got a bit of a break from her job. Here&#39;s the day-wise log of our adventures.&lt;/p&gt;
&lt;h2&gt;Day — 0 (My first trip on a Vande Bharat Express)&lt;/h2&gt;
&lt;p&gt;Since neither of us had ridden on a &lt;a href=&quot;https://en.wikipedia.org/wiki/Vande_Bharat_Express&quot;&gt;Vande Bharat Express&lt;/a&gt; before, we decided to reach Ahmedabad a day earlier than our flight so that we could take the Vande Bharat from our town to Ahmedabad. The ride was a smooth and speedy experience. But what I didn&#39;t expect was how completely booked it was, despite the tickets being on the pricier side. This was the fastest I have gone from my town to Ahmedabad. And since this is a train and not a plane, there was the added benefit of not having to bother with any sort of security checks and stuff.&lt;/p&gt;
&lt;p&gt;In the evening we decided to visit a newly opened attraction &lt;a href=&quot;https://maps.app.goo.gl/t6aqXZNhZrcPFBBZA&quot;&gt;SPECTRA - MUSEUM&lt;/a&gt; (they call it a museum but I disagree). It was very costly and completely worthless. The only good thing that came out of it was that we played in a ball-pit for the first time.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;PS: Indian Railways still have Indigo beat by a wide margin on included snacks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Complimentary snacks aboard the Vande Bharat Express&quot; src=&quot;https://varunbarad.com/assets/images/posts/trip-meghalaya/snacks-on-vande-bharat.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Complimentary snacks aboard the Vande Bharat Express&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Day — 1 (Reaching Shillong, some lake and some blossoms)&lt;/h2&gt;
&lt;p&gt;After taking an early morning flight to Guwahati, we got on a cab to our hotel in Shillong. We were going to visit Umïam lake on our way there. It is a huge reservoir lake built for Umïam Dam on the Umïam River. There is a very nice walking trail going around the lake, and just above it there is also a wooden trail which goes around at a similar level as the tree canopy. Overall a wonderful experience 😍&lt;/p&gt;
&lt;p&gt;On reaching our hotel (we stayed at the wonderful, and highly recommended by me, &lt;a href=&quot;https://www.tripuracastle.com/&quot;&gt;The Heritage Club - Tripura Castle Hotel&lt;/a&gt;) we noticed that there were a lot of cherry blossom trees on the premises, and by our luck they were in bloom too. We wanted to visit Japan during the cherry-blossom season and had never managed to so far, no one told us that there are cherry blossoms in India too 🌸. Now we can plan our Japan trip without worrying about these at all.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;PS: On reaching here, remember to ask for their awesome turmeric-based welcome drink :chefs_kiss:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;figure&gt;
  &lt;img alt=&quot;A random Varun spotted posing besides a Cherry blossom tree. Photo credit: My Awesome Wife&quot; src=&quot;https://varunbarad.com/assets/images/posts/trip-meghalaya/varun-in-front-of-cherry-blossoms.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;A random Varun spotted posing besides a Cherry blossom tree. Photo credit: My Awesome Wife&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Day — 2 (The day I touched a real jet engine)&lt;/h2&gt;
&lt;p&gt;On our second day in Shillong we visited three different places, the Laitlum Canyon, Shillong Peak and the Air Force Museum at Shillong. &lt;a href=&quot;https://maps.app.goo.gl/WLS92YiePHscM21W6&quot;&gt;Laitlum Canyon&lt;/a&gt; is a view point which can easily make you realise how tiny you are on this &lt;a href=&quot;https://www.youtube.com/watch?v=wupToqz1e2g&quot;&gt;Pale Blue Dot&lt;/a&gt;. &lt;a href=&quot;https://maps.app.goo.gl/JVtJtbfvyUdFgvhC6&quot;&gt;Shillong Peak&lt;/a&gt; gives you a complete view of the Shillong city situated inside the valley. Only Indian citizens are allowed to visit Shillong Peak as you need to pass through the Indian Air Force campus to reach there.&lt;/p&gt;
&lt;p&gt;Like &lt;a href=&quot;https://varunbarad.com/blog/trip-goa.html#:~:text=Naval%20Aviation%20Museum&quot;&gt;in Goa&lt;/a&gt;, we found an armed forces museum in Shillong too, so we just had to visit there. The &lt;a href=&quot;https://maps.app.goo.gl/GBGaKdnMTrgXZk1K9&quot;&gt;Air Force Museum&lt;/a&gt; (here is the link to &lt;a href=&quot;https://airforcemuseumuppershillong.in/&quot;&gt;official website&lt;/a&gt;) is situated inside the campus of Eastern Air Command and is open all days of the week. It houses different galleries and exhibits including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Various peacetime and wartime gallantry awards/medals&lt;/li&gt;
&lt;li&gt;Pictures and stories of IAF&#39;s contribution in the different wars&lt;/li&gt;
&lt;li&gt;Models and photos of various aircrafts (both planes and helicopters) that have been part of the IAF&lt;/li&gt;
&lt;li&gt;Various summer, winter and ceremonial officers&#39; uniforms&lt;/li&gt;
&lt;li&gt;Some life-size and some scaled-down versions of different missiles and air-to-air rocket launchers&lt;/li&gt;
&lt;li&gt;A few life-size replicas of different aircrafts&lt;/li&gt;
&lt;li&gt;:drumroll: A real decommissioned jet-engine from a MiG jet&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Me poking in stuff on a jet-engine&quot; src=&quot;https://varunbarad.com/assets/images/posts/trip-meghalaya/varun-poking-jet-engine.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Me poking in stuff on a jet-engine&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Day — 3 (Discovering that spelunking is not for me)&lt;/h2&gt;
&lt;p&gt;Today we travelled from Shillong to Cherrapunji, stopping at various spots on the way. First of which was &lt;a href=&quot;https://maps.app.goo.gl/6BPtFpSnbQXqTVAF9&quot;&gt;Elephant Falls&lt;/a&gt;, which is actually three subsequent waterfalls, with the last one looking like a multi-step fall by itself.&lt;/p&gt;
&lt;p&gt;Next up was &lt;a href=&quot;https://maps.app.goo.gl/7jFvyfQA4b2Kddv18&quot;&gt;Garden of Caves&lt;/a&gt; which contains around 11–13 different viewing points consisting of different waterfalls and various cave structures. Some of these cave structures appear as if they must have been inhabited in the past. You might easily spend over multiple hours going through all of them.&lt;/p&gt;
&lt;p&gt;After that we moved on to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Nohkalikai_Falls&quot;&gt;Nohkalikai Falls&lt;/a&gt;. At a plunge height of around 340 metres, this waterfall is the tallest plunge waterfall in India. While there we also had the pleasure of listening to a live band performing various film songs 🎶.&lt;/p&gt;
&lt;p&gt;Our last stop before reaching the hotel was &lt;a href=&quot;https://maps.app.goo.gl/WorVNvDCKcWNo4927&quot;&gt;Mawsmai Cave&lt;/a&gt; formations. These are limestone caves carved over thousands of years of chemical erosion. It was around 150 metres in length and became a tight-squeeze at many spots on the way. With uneven footing, low ceiling and such tight spots I would say this is not a place for people with health conditions or those with &lt;a href=&quot;https://en.wikipedia.org/wiki/Claustrophobia&quot;&gt;claustrophobia&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;A place inside the Mawsmai Cave where it widens up&quot; src=&quot;https://varunbarad.com/assets/images/posts/trip-meghalaya/mawsmai-cave.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;A place inside the Mawsmai Cave where it widens up&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Day — 4 (The day I became a disney princess)&lt;/h2&gt;
&lt;p&gt;On our fourth day we had booked a trek to a &lt;a href=&quot;https://maps.app.goo.gl/iUceSDDGk9sQMQkP6&quot;&gt;double-decker living root bridge&lt;/a&gt;. This was a tough but equally rewarding experience. We started the trek from right near our hotel. It is said that it takes approximately 3500 steps of climbing up and down to reach from the start to the double-decker bridge. On the way we ended up crossing the river multiple times, including over rocks and via cable bridges. At one place there is even a small single-decker root bridge.&lt;/p&gt;
&lt;p&gt;Near one of the villages on the way, a butterfly ended up landing on my arm. It even stayed there for around 50 metres or so. That&#39;s it, I finally became a Disney princess without even expecting to 🦋.&lt;/p&gt;
&lt;p&gt;The double-decker bridge even has a small tank/pond like structure built underneath it, and that has a lot of fish in it. Neither of us had expected that we would be going for a fish spa, and that too in the middle of a trek. But there we were, getting our feet tickled by those critters 🐟.&lt;/p&gt;
&lt;p&gt;From the root bridge, there even are a couple more view-points further along the trek, &lt;a href=&quot;https://maps.app.goo.gl/U6xqMbYF46bNQUC78&quot;&gt;Blue Lagoon&lt;/a&gt; and &amp;quot;Rainbow Falls&amp;quot;. We weren&#39;t able to visit the Rainbow Falls but we did go till Blue Lagoon. It is a natural small(ish) pond created by a low-height waterfall. The water there is crystal clear, and my favorite part was that you can rent life-jackets (which are compulsory) from the locals there. So there was no worry in swimming even if you don&#39;t know the first thing about it. We ended up swimming around for about half-an-hour there.&lt;/p&gt;
&lt;p&gt;The trek back was one of the physically most challenging things I have ever done in my life. Since we had to climb back up all those more than 3500 steps we had climbed down to reach the Blue Lagoon. At the end of day, both of us were tired to our bones, but neither of us, if given a do-over, would choose anything different.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Me posing with the butterfly on my left arm&quot; src=&quot;https://varunbarad.com/assets/images/posts/trip-meghalaya/varun-with-butterfly.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Me posing with the butterfly on my left arm&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Day — 5 (Back to base)&lt;/h2&gt;
&lt;p&gt;On our last day we had nothing on the roster other than getting back to Guwahati airport and subsequently back to home. On our journey back from Cherrapunji to Guwahati we also ended up getting a view of the Bangladesh territory. I did not expect this, but what is a trip without a few surprises.&lt;/p&gt;
&lt;p&gt;If you ever visit Meghalaya, then make sure to hit these places while there:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Double-Decker Living Root Bridge (do make sure to go till Blue Lagoon)&lt;/li&gt;
&lt;li&gt;Garden of Caves&lt;/li&gt;
&lt;li&gt;Elephant Falls (the café after the first fall makes delicious brownies)&lt;/li&gt;
&lt;li&gt;Air Force Museum, I don&#39;t know of many (if any) other places where you can see a real jet engine up close&lt;/li&gt;
&lt;li&gt;If within budget, then choose to stay in The Heritage Club - Tripura Castle Hotel while in Shillong&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
  &lt;img alt=&quot;The most durable slide I have ever seen&quot; src=&quot;https://varunbarad.com/assets/images/posts/trip-meghalaya/rock-slide.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;The most durable slide I have ever seen&lt;/figcaption&gt;
&lt;/figure&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="travel"/>
      
      <summary type="html">Log of my recent trip to Shillong and Cherrapunji</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Trim image to content using ImageMagick</title>
      <link href="https://varunbarad.com/blog/til-trim-image-background.html" rel="alternate" type="text/html" title="📝 Trim image to content using ImageMagick"/>
      <published>2025-12-25T07:30:00+05:30</published>
      <updated>2025-12-25T07:30:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-trim-image-background.html</id>
      <content type="html">
      &lt;p&gt;I recently had some images where I had to crop to its main content and get rid of everything else. While I was doing it on icons with transparent backgrounds, it is easier to show on an image with a coloured background. The command to trim the image is:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick input.png &lt;span class=&quot;token parameter variable&quot;&gt;-trim&lt;/span&gt; trimmed.png&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Full sized image&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-trim-png-background/full-image.png&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Image by &lt;a href=&quot;https://pixabay.com/users/haninabz-24628630&quot;&gt;Hanin Abouzeid&lt;/a&gt; from &lt;a href=&quot;https://pixabay.com/&quot;&gt;Pixabay&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Image cropped/trimmed using ImageMagick&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-trim-png-background/cropped-image.png&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Image cropped/trimmed using ImageMagick&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;ImageMagick documentation: &lt;a href=&quot;https://imagemagick.org/script/command-line-options.php#trim&quot;&gt;https://imagemagick.org/script/command-line-options.php#trim&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="imagemagick"/>
      
      <category term="til"/>
      
      <summary type="html">You can use ImageMagick to crop an image to just its central content</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 The Memo emoji (📝) contains actual text</title>
      <link href="https://varunbarad.com/blog/til-mac-memo-emoji.html" rel="alternate" type="text/html" title="📝 The Memo emoji (📝) contains actual text"/>
      <published>2025-12-24T10:45:35+05:30</published>
      <updated>2025-12-24T10:45:35+05:30</updated>
      <id>https://varunbarad.com/blog/til-mac-memo-emoji.html</id>
      <content type="html">
      &lt;p&gt;Recently when writing another one of my TIL entries, I got curious whether the 📝 emoji on mac contains actual text or is it just some scribbles.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Screenshot of memo emoji taken on a Mac OS device showing the text written in it&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-mac-memo-emoji/emoji-memo.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Screenshot of memo emoji taken on a Mac OS device showing the text written in it&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Turns out, it does contain actual text, and that too from the famous poem &amp;quot;Here&#39;s to the crazy ones&amp;quot;. I first heard that poem at the end of the &lt;a href=&quot;https://www.thetvdb.com/movies/jobs&quot;&gt;Jobs movie&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now when I was researching for this article, I found out that it was originally part of Apple&#39;s &amp;quot;Think Different&amp;quot; ad campaign back in the day (source: &lt;a href=&quot;https://basicappleguy.com/basicappleblog/heres-to-the-crazy-ones&quot;&gt;Basic Apple Guy&lt;/a&gt;). And it turns out the same poem shows up in multiple emojis and at many other places throughout the whole system.&lt;/p&gt;
&lt;p&gt;While I am not generally a fan of Apple and its recent design decisions of the past few years, I don&#39;t expect this level of nice design from any other major tech company.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;:chefs_kiss:&lt;/strong&gt; (I wish unicode had this emoji)&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <category term="til"/>
      
      <summary type="html">The unicode memo emoji on mac contains text of a very famous poem</summary>
    </entry>
  
    
    <entry>
      <title type="html">🔭 How I pack my telescope</title>
      <link href="https://varunbarad.com/blog/telescope-packing-instructions.html" rel="alternate" type="text/html" title="🔭 How I pack my telescope"/>
      <published>2025-12-21T22:49:27+05:30</published>
      <updated>2025-12-21T22:49:27+05:30</updated>
      <id>https://varunbarad.com/blog/telescope-packing-instructions.html</id>
      <content type="html">
      &lt;p&gt;I got my wife a telescope (&lt;a href=&quot;https://www.celestron.com/products/starsense-explorer-lt-80az&quot;&gt;&amp;quot;Celestron StarSense Explorer LT 80AZ&amp;quot;&lt;/a&gt; is the specific model) on her birthday. It is an engineering marvel for what is a consumer product. The one downside for it is that everytime when packing it I had to think of where each part went, which things get covers where, and stuff like that. This time I wrote down a list of all the things and where they get packed.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Tripod
&lt;ol&gt;
&lt;li&gt;Tripod thermocol spacer&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Tripod eyepiece storage tray&lt;/li&gt;
&lt;li&gt;Main Tube&lt;/li&gt;
&lt;li&gt;Red Dot Sight (with a piece of railing attached)&lt;/li&gt;
&lt;li&gt;1 piece paper Star Dial&lt;/li&gt;
&lt;li&gt;Manuals for telescope&lt;/li&gt;
&lt;li&gt;StarSense phone dock&lt;/li&gt;
&lt;li&gt;Triangular piece of sheet metal that is supposed to act as a screwdriver&lt;/li&gt;
&lt;li&gt;Cover plug for eyepiece-hole in the main tube. Fitted in main-tube.&lt;/li&gt;
&lt;li&gt;Desiccant Cap/Cup&lt;/li&gt;
&lt;li&gt;Eyepiece lens - 25 mm
&lt;ol&gt;
&lt;li&gt;Covers on both ends. Tube-side white, eye-side black.&lt;/li&gt;
&lt;li&gt;Stored in a plastic zip-lock bag.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Eyepiece lens - 10 mm
&lt;ol&gt;
&lt;li&gt;No covers.&lt;/li&gt;
&lt;li&gt;Stored in a rubber-plastic bottle.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Barlow lens - 2x magnification
&lt;ol&gt;
&lt;li&gt;Black plug/cover on both ends.&lt;/li&gt;
&lt;li&gt;Stored in a plastic zip-lock bag.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Right-angle eyepiece mirror attachment
&lt;ol&gt;
&lt;li&gt;Covers on both ends. Tube-side white cover, eyepiece side black plug.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Zip-lock bag containing: [4] and [14]&lt;/li&gt;
&lt;li&gt;2 screw knobs to attach main-tube to tripod.&lt;/li&gt;
&lt;li&gt;Cleaning liquid bottle&lt;/li&gt;
&lt;li&gt;Cleaning cloth&lt;/li&gt;
&lt;li&gt;Zip-lock bag containing: [16], [17] and [18]&lt;/li&gt;
&lt;li&gt;A different cleaning cloth&lt;/li&gt;
&lt;li&gt;Grey cloth bag containing: [8], [10], [11], [12], [13], [15], [19], [20]&lt;/li&gt;
&lt;li&gt;Small cardboard box which goes besides tripod box. Contains [2] and [21]&lt;/li&gt;
&lt;li&gt;Tripod goes in small bubble-wrap bag&lt;/li&gt;
&lt;li&gt;Tripod cardboard box which contains [7] and [23]&lt;/li&gt;
&lt;li&gt;Thermocol spacer/stabilizer for main-tube mounting rod&lt;/li&gt;
&lt;li&gt;Main-tube goes in a regular plastic bag and then gets wrapped in large/thick bubble wrap sheet&lt;/li&gt;
&lt;li&gt;Main-tube cardboard box&lt;/li&gt;
&lt;li&gt;Main Celestron box containing [5], [6], [22], [24], [27]&lt;/li&gt;
&lt;li&gt;Transport outer cardboard box which only contains [28]&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let&#39;s hope this helps the next time I have to pack the scope after a session.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <category term="toys"/>
      
      <summary type="html">A basic instruction manual (for me) on where each piece/part goes when packing my telescope</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎲 Implementing a four year old feature request</title>
      <link href="https://varunbarad.com/blog/improvement-roll-custom-tasks.html" rel="alternate" type="text/html" title="🎲 Implementing a four year old feature request"/>
      <published>2025-12-20T09:45:00+05:30</published>
      <updated>2025-12-20T09:45:00+05:30</updated>
      <id>https://varunbarad.com/blog/improvement-roll-custom-tasks.html</id>
      <content type="html">
      &lt;p&gt;I released &lt;a href=&quot;https://improvement-roll.varunbarad.com/&quot;&gt;Improvement Roll&lt;/a&gt; back in 2021 and the first thing that my friend &lt;a href=&quot;https://druchan.com/&quot;&gt;Chandru&lt;/a&gt; asked was that he wanted to add his own tasks to the list. I was reluctant to add more JavaScript to the project back then and so denied it completely. Lately I have been working more and more on websites and web-apps and thus became open to adding that functionality, but I still did not want to put in the actual effort of doing that.&lt;/p&gt;
&lt;p&gt;In AI code agents I have used Claude Code a bit but haven&#39;t really given Cursor a shot. So I wanted to try this project with Cursor, and see how far I can push it without writing a single line of code manually.&lt;/p&gt;
&lt;p&gt;I started by having the customisation controls and inputs on a different page (/customise), but when I used that version it didn&#39;t feel right that I had to go to switch between pages to enter and roll a task. Finally ended up with having a button on the home-screen which shows/hides the controls and inputs for customisation.&lt;/p&gt;
&lt;p&gt;I did all of this without writing a single line of code myself. But there was one odd thing, the items in the list of custom tasks would show up much wider than the rest of the elements of the page. By the time I was able to track down why it was so, it was easier for me to just make the change myself than to ask Cursor to do the same. So in the end I didn&#39;t escape this adventure without coding myself, but got very close to it. Maybe I should have just asked Cursor that the list appears much wider and to match its width with other elements, but I am happy with how things went. You can &lt;a href=&quot;https://improvement-roll.varunbarad.com/&quot;&gt;check it out yourself&lt;/a&gt; or check out the screenshots below.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Default homepage with button to toggle customisation controls&quot; src=&quot;https://varunbarad.com/assets/images/posts/project-improvement-roll/customise-homepage.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Default homepage with button to toggle customisation controls&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Form to enter custom tasks&quot; src=&quot;https://varunbarad.com/assets/images/posts/project-improvement-roll/customise-task-entry.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Form to enter custom tasks&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
  &lt;img alt=&quot;List of custom tasks&quot; src=&quot;https://varunbarad.com/assets/images/posts/project-improvement-roll/customise-list-tasks.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;List of custom tasks&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2&gt;Articles on this project&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/improvement-roll&quot;&gt;Public release&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Adding custom tasks (this article)&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="improvement-roll"/>
      
      <summary type="html">I finally implement a feature-request made four years ago by a friend</summary>
    </entry>
  
    
    <entry>
      <title type="html">⏰️ I want a silent clock to get me to stand up</title>
      <link href="https://varunbarad.com/blog/project-clockup.html" rel="alternate" type="text/html" title="⏰️ I want a silent clock to get me to stand up"/>
      <published>2025-12-20T00:58:36+05:30</published>
      <updated>2025-12-20T00:58:36+05:30</updated>
      <id>https://varunbarad.com/blog/project-clockup.html</id>
      <content type="html">
      &lt;p&gt;I recently read about a &lt;a href=&quot;https://hannahilea.com/blog/button-box-timer/&quot;&gt;timer made by Hannah&lt;/a&gt; which reminds her to stand up regularly (thus being less sedentary) using a few LEDs. I wanted to build something similar as this would finally be a tiny project which I would regularly use, I definitely need to stand up more frequently. This project would also be my first electronics project in a long time, and it provides an opportunity to build my custom circuit board.&lt;/p&gt;
&lt;p&gt;This is just an introductory post about it. So far all I have are the requirements of how I want this to function:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It works using a couple of AA cells, but using an 18650 Li-ion battery is also an option.&lt;/li&gt;
&lt;li&gt;One toggle switch to turn the whole thing on/off&lt;/li&gt;
&lt;li&gt;As soon as the device is turned on, a 20 min timer starts&lt;/li&gt;
&lt;li&gt;At the end of the timer an LED turns on, and remains on until a push-button switch is pushed&lt;/li&gt;
&lt;li&gt;When the push button switch is pushed, the LED turns off and the 20 min timer restarts&lt;/li&gt;
&lt;li&gt;Go back to step 4&lt;/li&gt;
&lt;li&gt;Turning the toggle switch (mentioned in step 2) turns the whole thing off&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I originally wanted to use a single AA cell, but upon initial research it looks like that won&#39;t be voltage enough. I would need to use a boost converter, but I want to try and keep this as simple as possible.&lt;/p&gt;
&lt;p&gt;The two options that have appeared so far are either using a micro-controller or a combination of a 555 timer IC and a latch (to keep the light turned on). I remember a childhood memory of my dad designing a circuit (for one of my school projects) where he built something like the latch that I want here using two (or maybe three) diodes, I may do that.&lt;/p&gt;
&lt;p&gt;There are currently a few other tasks standing between me and the actual start of this project. I think I will start this sometime early next year. Hoping to take this across the finish line.&lt;/p&gt;
&lt;p&gt;PS: The working name for the project right now is &lt;strong&gt;&amp;quot;Clock-Up&amp;quot;&lt;/strong&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="clock-up"/>
      
      <category term="project"/>
      
      <summary type="html">Start of making a silent clock/alarm clock to get me to stand up every 20ish minutes while working</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Get image file info using imagemagick</title>
      <link href="https://varunbarad.com/blog/til-image-info-using-imagemagick.html" rel="alternate" type="text/html" title="📝 Get image file info using imagemagick"/>
      <published>2025-12-09T12:13:03+05:30</published>
      <updated>2025-12-09T12:13:03+05:30</updated>
      <id>https://varunbarad.com/blog/til-image-info-using-imagemagick.html</id>
      <content type="html">
      &lt;p&gt;I am trying to make an automated workflow for any documents I scan and needed to have a step in there where I figure out the existing dimensions and scaling of the image. I looked into how to fetch that info using imagemagick. The &lt;code&gt;identify&lt;/code&gt; sub-command is the one we need.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Assuming our image file is called input.jpg&lt;/span&gt;
magick identify input.jpg&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we want all information then we can use the &lt;code&gt;-verbose&lt;/code&gt; flag.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick identify &lt;span class=&quot;token parameter variable&quot;&gt;-verbose&lt;/span&gt; input.jpg&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I only needed five pieces of info, so I went with the &lt;code&gt;-format&lt;/code&gt; flag:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick identify &lt;span class=&quot;token parameter variable&quot;&gt;-format&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;%m %w %h %x %%y&quot;&lt;/span&gt; input.jpg
&lt;span class=&quot;token comment&quot;&gt;# This gives an output like below&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# JPEG 4960 7015 600 600&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;%m&lt;/code&gt;: Format of the image file (&lt;code&gt;JPEG&lt;/code&gt;, &lt;code&gt;PNG&lt;/code&gt;, &lt;code&gt;WEBP&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%w&lt;/code&gt;: Width of the image (in pixels)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%h&lt;/code&gt;: Height of the image (in pixels)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%x&lt;/code&gt;: Resolution/Density in the x direction&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%y&lt;/code&gt;: Resolution/Density in the y direction&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can find all the available attributes &lt;a href=&quot;https://imagemagick.org/script/escape.php&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="imagemagick"/>
      
      <summary type="html">TIL: How to get information about/from an image</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 His Dark Materials: Northern Lights</title>
      <link href="https://varunbarad.com/blog/book-his-dark-materials-northern-lights.html" rel="alternate" type="text/html" title="📚 His Dark Materials: Northern Lights"/>
      <published>2025-12-09T07:27:07+05:30</published>
      <updated>2025-12-09T07:27:07+05:30</updated>
      <id>https://varunbarad.com/blog/book-his-dark-materials-northern-lights.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Cover of the book Northern Lights&quot; src=&quot;https://varunbarad.com/assets/images/books/his-dark-materials-northern-lights.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Lyra Belacqua and her animal daemon live half-wild and carefree among scholars of Jordan College, Oxford. The destiny that awaits her will take her to the frozen lands of the Arctic, where witch-clans reign and ice-bears fight. Her extraordinary journey will have immeasurable consequences far beyond her own world.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://openlibrary.org/books/OL44799605M/Northern_Lights&quot;&gt;Open Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The story was extremely slow in the starting and took a long time to pick up its pace, but it did become a page-turner somewhere around the half-way mark. I did find it interesting for a few chapters, but I again started losing interest when we got to know what the gobblers are doing and why they are doing it. The thing is, in this book&#39;s world there aren&#39;t many people doing/being good, but the flip-side both has a lot of candidates and the magnitudes of their evils are beyond any sane limits.&lt;/p&gt;
&lt;p&gt;I do have the other two books in this series, but as of now I am unsure whether I will read them.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="book-highlights"/>
      
      <summary type="html">My thoughts and opinions on this book</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 Mirai</title>
      <link href="https://varunbarad.com/blog/movie-mirai.html" rel="alternate" type="text/html" title="🎬 Mirai"/>
      <published>2025-12-09T00:20:11+05:30</published>
      <updated>2025-12-09T00:20:11+05:30</updated>
      <id>https://varunbarad.com/blog/movie-mirai.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Poster of the movie Mirai&quot; src=&quot;https://varunbarad.com/assets/images/movies/mirai-poster.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Score: 2/5 🤷️&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Following the historic Kalinga battle, where King Ashoka of the Maurya dynasty emerged as the winner, he chose to walk the path of peace instead of continuing warfare. Yet, the kingdom appointed nine warriors to protect some ancient scriptures rumored to have the ability to make someone divine or godlike.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://thetvdb.com/movies/miraay&quot;&gt;TheTVDB.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This did not live up to its hype. They have an extremely solid concept to grow their story from, but nearly everything after that doesn&#39;t hold up to the potential. Good to see that we are finally starting to base movies off our cultural history.&lt;/p&gt;
&lt;p&gt;Character writing, script writing, performance of many actors, accuracy in animations and a lot many other things just failed spectacularly. But for some reason I didn&#39;t feel that I wasted my time and would have been better off not watching this movie at all.&lt;/p&gt;
&lt;p&gt;The concept and overall story were so good that I think a game like old-school Prince of Persia could be made from it.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="movies"/>
      
      <summary type="html">My thoughts and opinions on this movie</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 Lakshadweep Adventure</title>
      <link href="https://varunbarad.com/blog/book-lakshadweep-adventure.html" rel="alternate" type="text/html" title="📚 Lakshadweep Adventure"/>
      <published>2025-12-08T23:57:30+05:30</published>
      <updated>2025-12-08T23:57:30+05:30</updated>
      <id>https://varunbarad.com/blog/book-lakshadweep-adventure.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Cover of the book Lakshadweep Adventure&quot; src=&quot;https://varunbarad.com/assets/images/books/lakshadweep-adventure.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Far out in the Arabian Sea, where the waters plunge many thousands of metres to the ocean floor, lies a chain of bewitching coral atolls–the Lakshadweep Islands. Vikram and Aditya dive into lagoons with crystal-clear water and reefs that are deep and shrouded in mystery. But when they stumble upon a devious kidnapping plot, their idyllic holiday turns into a desperate struggle for survival.&lt;/p&gt;
&lt;p&gt;Forced out into the sea in the eye of a raging storm, they endure a shipwreck, only to be marooned on a remote coral island.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://openlibrary.org/works/OL31756995W/Lakshadweep_Adventure&quot;&gt;Open Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It has been a long time since I read a teenage adventure story, and this was a refreshing change of pace. I picked this up to read during flights on a recent trip, and I am happy to have finished it on the flight back.&lt;/p&gt;
&lt;p&gt;While I don&#39;t know the first thing of captaining a boat, the descriptions of that and the coral lagoon felt immersive. A good amount of tension builds up, but the author luckily doesn&#39;t drag it on without any purpose.&lt;/p&gt;
&lt;p&gt;After Aditya&#39;s encounter with the radio, I am going to go and memorise the international frequencies for transmitting SOS signals.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="book-highlights"/>
      
      <summary type="html">My thoughts and opinions on this book</summary>
    </entry>
  
    
    <entry>
      <title type="html">New Design, Who Dis?</title>
      <link href="https://varunbarad.com/blog/redesign-2025.html" rel="alternate" type="text/html" title="New Design, Who Dis?"/>
      <published>2025-12-06T12:04:27+05:30</published>
      <updated>2025-12-06T12:04:27+05:30</updated>
      <id>https://varunbarad.com/blog/redesign-2025.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/redesign-2025/homepage.webp&quot; alt=&quot;Homepage in the new design&quot; /&gt;&lt;/p&gt;
&lt;p&gt;After years of using the same design for my website (and making some pages of it look utterly bad when last trying to redesign it) I finally have a new design for the website. And this time I have the complete site moved to the new design. I had mentioned in &lt;a href=&quot;https://varunbarad.com/blog/blog-questions-challenge-2025#:~:text=Keep%20a%20Changelog-,A%20complete%20redesign,-%2C%20as%20neither%20my&quot;&gt;a previous post&lt;/a&gt; that I would be redesigning the website this year and this is the fulfillment of that promise.&lt;/p&gt;
&lt;h2&gt;How did I arrive at the design?&lt;/h2&gt;
&lt;p&gt;After browsing a lot of other personal blogs, I liked the design of &lt;a href=&quot;https://www.coryd.dev/&quot;&gt;Cory&#39;s&lt;/a&gt; header and &lt;a href=&quot;https://zoeaubert.me/&quot;&gt;Zoe&#39;s&lt;/a&gt; footer. Starting from there and keeping a bit of my previous (maroon themed) design, I landed on my current version. Header now has six prominent navigation links and the rest go into the footer. Before the footer was doing nothing and I was trying to fit everything in the header.&lt;/p&gt;
&lt;p&gt;I originally wanted to have a hamburger menu in the header so that on mobiles and other small displays only the site name remains visible by default and then other header links could be shown as the user wishes. But I didn&#39;t want to use any JavaScript on the site and neither did I like the restyle-a-checkbox route. Finally, I ended up showing all six navigation links in a single line on bigger screens, and on smaller screens they split into two lines of three links each.&lt;/p&gt;
&lt;p&gt;I ideally want multiple themes for the design — light, dark and multiple other colour variants. But in the interest of time and getting a first version out the door, I only ended up making the default dark theme.&lt;/p&gt;
&lt;h2&gt;How I built this?&lt;/h2&gt;
&lt;p&gt;I moved a lot between what to use for the new design: &lt;a href=&quot;https://tailwindcss.com/&quot;&gt;tailwindcss&lt;/a&gt;, &lt;a href=&quot;https://picocss.com/&quot;&gt;pico&lt;/a&gt;, &lt;a href=&quot;https://simplecss.org/&quot;&gt;Simple.css&lt;/a&gt; or something custom from the ground-up. In the end I went with a &lt;a href=&quot;https://www.joshwcomeau.com/css/custom-css-reset&quot;&gt;CSS Reset from Josh Comeau&lt;/a&gt; (if you haven&#39;t seen this before then I suggest taking 5 minutes out and reading through this, it is an awesome piece of explanation) and a completely custom style built on top of it.&lt;/p&gt;
&lt;p&gt;The syntax highlighting in code-blocks is handled with &lt;a href=&quot;https://prismjs.com/&quot;&gt;Prism&lt;/a&gt; as it allowed me to bake the highlights during build-time, thus eliminating any need to ship JavaScript to the client.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://claude.com/product/claude-code&quot;&gt;Claude Code&lt;/a&gt; did most of the heavy-lifting with me guiding it and changing the source code directly when the guidance failed to communicate my intent. I went through the website page-by-page, starting with the individual blog post page layout.&lt;/p&gt;
&lt;p&gt;I wanted to start with this page because that was the only one which I could not handle in my previous effort to redesign as there were a lot of legacy parts coming together to form this page. Instead of working with them and replacing each individual piece as I made its replacement, I went for completely removing all the older parts and then starting from scratch as that ensured no old styles (or anything) were conflicting with the new version.&lt;/p&gt;
&lt;h2&gt;What next?&lt;/h2&gt;
&lt;p&gt;This has been my primary software project since the past few months, thus I was not able to focus on many other things. There are a few content fixes needed and I do want to add the &lt;a href=&quot;https://nownownow.com/&quot;&gt;/now&lt;/a&gt; page before this year ends, but that will be it for modifications to the website for now.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="meta"/>
      
      <category term="programming"/>
      
      <category term="project"/>
      
      <summary type="html">I finally finished a redesign of my website. Here&#39;s the overview of how and why things went.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 The Tail Hooker</title>
      <link href="https://varunbarad.com/blog/book-tail-hooker.html" rel="alternate" type="text/html" title="📚 The Tail Hooker"/>
      <published>2025-11-19T23:11:48+05:30</published>
      <updated>2025-11-19T23:11:48+05:30</updated>
      <id>https://varunbarad.com/blog/book-tail-hooker.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Cover of the book The Tail Hooker&quot; src=&quot;https://varunbarad.com/assets/images/books/the-tail-hooker-cover.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&#39;The Tail Hooker&#39; is a mix of facts and fiction. This is the story of an ordinary boy who discovers the extra-ordinary world of Naval Aviation. It is about his dreams and ambitions, about heartbreaks and the final triumph of dedicated effort over seemingly insurmountable odds.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://openlibrary.org/works/OL44412341W/The_Tail_Hooker&quot;&gt;Open Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The book is quite a roller-coaster ride through the author&#39;s life journey in becoming a fighter pilot in the Indian Navy. It is nicely broken up into bite-sized chapters. There was not a single dull/boring chapter, and many were outright hilarious.&lt;/p&gt;
&lt;p&gt;Somewhere in the foreword or preface it was mentioned that the author has woven both real stories and some fictional incidents nicely together. On reading a few chapters I strongly felt that they mentioned some being fiction just so they can say that no such thing actually happens in the Navy.&lt;/p&gt;
&lt;p&gt;Regardless of it being fact or fiction, had a great time reading it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;PS:&lt;/strong&gt; Also, since this book was not already in the &lt;a href=&quot;https://openlibrary.org/&quot;&gt;OpenLibrary&lt;/a&gt; database, I also got a chance to add this there.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="book-highlights"/>
      
      <summary type="html">My thoughts and opinions on this book</summary>
    </entry>
  
    
    <entry>
      <title type="html">📜 Blaugust 2025: Nice knowing you</title>
      <link href="https://varunbarad.com/blog/blaugust-2025-outro.html" rel="alternate" type="text/html" title="📜 Blaugust 2025: Nice knowing you"/>
      <published>2025-08-31T13:23:41+05:30</published>
      <updated>2025-08-31T13:23:41+05:30</updated>
      <id>https://varunbarad.com/blog/blaugust-2025-outro.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/blaugust-2025/blaugust2025-banner.webp&quot; alt=&quot;Blaugust 2025 banner&quot; /&gt;&lt;/p&gt;
&lt;p&gt;And that&#39;s a wrap. At the start of this month I set my sights on the Rainbow Diamond badge, which demanded I write 31 or more posts in this month. This is the 31&lt;sup&gt;st&lt;/sup&gt; post, the final one.&lt;/p&gt;
&lt;p&gt;It was punishing as hell. My wife put it best, she said, &amp;quot;Since school times, you haven&#39;t liked doing a single day&#39;s homework. And you thought you would be happy signing up for 31 days of homework?&amp;quot;&lt;/p&gt;
&lt;p&gt;I have always been a person who doesn&#39;t like the process of writing, but I like having written. These past 31 days have been similar. I ended up putting a lot of things I love doing on the back-burner. I did not read books, I did not play video games, I did not watch any movies, I did not work on any side-project code.&lt;/p&gt;
&lt;p&gt;All of my available free time was going towards Blaugust, even when my brain would have been much happier to do something else. It made me miserable, I don&#39;t like being miserable. But this Blaugust was a test of discipline for me, and I was not prepared to lose.&lt;/p&gt;
&lt;p&gt;Neither was I prepared enough to win 😅. I believe that a hard-fought victory is not really a victory, it is at best not-a-defeat. Okay, I have got all the rant out of me, now on to the good parts.&lt;/p&gt;
&lt;p&gt;Did I enjoy it? A heck of a lot. No doubt about that. The community was really nice and I found quite a few other blogs which I enjoyed reading. This month was finally the time when I felt that someone other than me also reads my blog.&lt;/p&gt;
&lt;p&gt;Having to write &lt;s&gt;daily&lt;/s&gt; regularly also helped me expand into other domains that I wanted to for quite some time. A bunch of old drafts and ideas also got dusted off and turned into full posts. It also taught me that if I just have a topic then I can turn that into a blog post if I just sit and start typing. I don&#39;t need to wait for an inspiration or to feel the right time or anything of that sort.&lt;/p&gt;
&lt;p&gt;Would I participate again next year? Definitely. I will be participating each year that I can, but I won&#39;t be setting the same target for myself. It was a one-time experiment for me, and I am happy that I did it. Blaugust is great, and now I understand why first timers are not suggested to target the Rainbow Diamond badge.&lt;/p&gt;
&lt;p&gt;There were a lot of times when I missed the day&#39;s post, but weekends were my friend, they helped me bounce back every single time. Here&#39;s a graph of what the standard rate of posting required me to publish and how I actually ended up publishing.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/blaugust-2025/blogging-pace-graph.webp&quot; alt=&quot;Graph showing my publishing schedule versus ideal publishing schedule for Blaugust 2025&quot; /&gt;&lt;/p&gt;
&lt;p&gt;PS: I am literally finishing this at the last hour, it is past 11:30 pm on Aug 31 in India right now.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">How was my overall experience with my first Blaugust? Did I meet my goal? Will I come back again next year?</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Set git identity based on project-directory</title>
      <link href="https://varunbarad.com/blog/til-subdirectory-based-git-identity.html" rel="alternate" type="text/html" title="📝 Set git identity based on project-directory"/>
      <published>2025-08-31T02:00:29+05:30</published>
      <updated>2025-08-31T02:00:29+05:30</updated>
      <id>https://varunbarad.com/blog/til-subdirectory-based-git-identity.html</id>
      <content type="html">
      &lt;p&gt;I am done looking this up online every time I think of doing this. This time I am writing the canonical (for me) guide on how to do this. My sincerest gratitude to the original author (&lt;a href=&quot;https://www.shirishpadalkar.com/using-separate-git-identities-on-the-same-machine/&quot;&gt;Shirish Padalkar&#39;s post&lt;/a&gt;) whose guide I followed this time.&lt;/p&gt;
&lt;p&gt;The premise is that we have multiple identities for various projects that we work on. Let&#39;s say I work as a consultant with two companies Frame and Clock, and this is how I organise my projects:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;Projects
├── all-other-projects-go-here
├── clock
│   └── projects-for-Clock-stay-here
└── frame
    └── projects-for-Frame-stay-here&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And these are the identities I need to be using in these projects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Projects for Frame: varun@frame.com&lt;/li&gt;
&lt;li&gt;Projects for Clock: varun@clock.com&lt;/li&gt;
&lt;li&gt;Everything else: varun@varunbarad.com&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The way to solve this is to have three config files for git; a base/global config and then two additional files which are decided (based on the repo-root) whether to import or not.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ~/.gitconfig-frame

[user]
    name = Varun Barad
    email = varun@frame.com
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# ~/.gitconfig-clock

[user]
    name = Varun Barad
    email = varun@clock.com
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above are our files to set the appropriate identity. Now we need to tell our global gitconfig to import either of these two files when in the correct directory.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ~/.gitconfig

[user]
    name = Varun Barad
    email = varun@varunbarad.com

[includeIf &amp;quot;gitdir:~/Projects/frame&amp;quot;]
    path: .gitconfig-frame

[includeIf &amp;quot;gitdir:~/Projects/clock&amp;quot;]
    path: .gitconfig-clock
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that&#39;s how it&#39;s done. That&#39;s all folks. Now wherever you create your repo, appropriate author information is applied based on where the repo was created.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="blaugust-2025"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to set the author identity in git for all projects under a single parent directory</summary>
    </entry>
  
    
    <entry>
      <title type="html">⌨️ Customizing the new keyboard</title>
      <link href="https://varunbarad.com/blog/keyboard-kc-v6max-basic-customization.html" rel="alternate" type="text/html" title="⌨️ Customizing the new keyboard"/>
      <published>2025-08-30T20:05:13+05:30</published>
      <updated>2025-08-30T20:05:13+05:30</updated>
      <id>https://varunbarad.com/blog/keyboard-kc-v6max-basic-customization.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/keyboard-kc-v6max/keyboard-full.webp&quot; alt=&quot;Full-size view of the Keychron V6 Max keyboard&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This is my first keyboard where I can update its firmware to change the keymapping. There are mainly two ways to customize the keyboard: either using &lt;a href=&quot;https://launcher.keychron.com/&quot;&gt;Keychron launcher&lt;/a&gt; (Keychron&#39;s website based tool) or by directly reprogrammming the keyboard firmware using QMK/VIA.&lt;/p&gt;
&lt;p&gt;I haven&#39;t yet used QMK/VIA route yet, but the Keychron launcher works well enough for simpler changes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/keyboard-kc-v6max/keychron-launcher.webp&quot; alt=&quot;Screenshot of Keychron launcher opened with my current keyboard connected&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;What did I want to change?&lt;/h2&gt;
&lt;p&gt;I was a Windows/Linux user till about 5 years ago, so my brain/hands are wired to look for Cmd/Win key between Ctrl and Alt/Opt. Next on the line were my &amp;quot;Print Screen&amp;quot; + &amp;quot;Scroll Lock&amp;quot; + &amp;quot;Pause&amp;quot; keys. They used to act like F13 + F14 + F15, and I had them configured to different OS wide shortcuts. They moved further right, and I needed to move them back to above the Insert → Page Down cluster.&lt;/p&gt;
&lt;p&gt;The last ambitious goal was to try and switch the usage of numbers and special characters in the number row above the main alphabets section. The default is when you press the key the number types, and when you do Shift + &amp;lt;key&amp;gt; it types the corresponding special character. I wanted to reverse this behaviour where the special character types by default and one would need to press Shift to type the numbers. I want that because as a programmer I use those special characters a lot and already have a huge num-pad in my keyboard if I want to input numbers.&lt;/p&gt;
&lt;h2&gt;Simple changes were simple&lt;/h2&gt;
&lt;p&gt;The repositioning of existing keys was not a big deal. You just had to select the keys in layout, and then specify which key you wanted to set there. So both the changes were quickly taken care of.&lt;/p&gt;
&lt;h2&gt;Launcher could not launch the ambition&lt;/h2&gt;
&lt;p&gt;The ambitious goal could not be met as Keychron Launcher didn&#39;t have the option to select normal operation and Shift + &amp;lt;key&amp;gt; operations separately. This needs to be done via reflashing the firmware, but that is not something I was willing to try yet. Maybe some other day.&lt;/p&gt;
&lt;h2&gt;PS: Some keys are acting up&lt;/h2&gt;
&lt;p&gt;As I am typing this I am noticing the my &amp;quot;M&amp;quot; key and &amp;quot;Delete&amp;quot; keys are acting up. The M key would end up multi-typing a lot of times and the Delete key just straight up doesn&#39;t get detected some times.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="toys"/>
      
      <summary type="html">Doing some basic keymapping changes with Keychron&#39;s web based tools</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Pixel art images should be scaled and not resized</title>
      <link href="https://varunbarad.com/blog/til-scale-pixel-art.html" rel="alternate" type="text/html" title="📝 Pixel art images should be scaled and not resized"/>
      <published>2025-08-29T10:30:01+05:30</published>
      <updated>2025-08-29T10:30:01+05:30</updated>
      <id>https://varunbarad.com/blog/til-scale-pixel-art.html</id>
      <content type="html">
      &lt;p&gt;This week I wanted to turn a 512x512 pixel image down to a 128x128 sized image. A noteworthy point is that this image was a pixel-art, and thus we needed to keep the edges sharp. Below is the image in question:&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Full sized badge image&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-scale-pixel-art/badge-full.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Full sized badge image&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I brought out the trusty old imagemagick and resized it:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick convert badge-full.webp &lt;span class=&quot;token parameter variable&quot;&gt;-resize&lt;/span&gt; 128x128 badge-resize.webp&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That got me this image:&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Resized badge image&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-scale-pixel-art/badge-resize.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Resized badge image&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;If you were to open this new image and zoom in a bit, you will see that the edges of the pixels are not as sharply defined and there is a bit of color blending going on. We obviously don&#39;t want that.&lt;/p&gt;
&lt;p&gt;Scaling to the rescue. We can scale the image like this:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick convert badge-full.webp &lt;span class=&quot;token parameter variable&quot;&gt;-scale&lt;/span&gt; 128x128 badge-scale.webp&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That gives you the one you want, with clean and crisp borders:&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;Scaled badge image&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-scale-pixel-art/badge-scale.webp&quot; style=&quot;width: fit-content; height: fit-content;&quot; /&gt;
  &lt;figcaption style=&quot;text-align: center;&quot;&gt;Scaled badge image&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The relevant documentation page for &lt;a href=&quot;https://usage.imagemagick.org/resize/#resize&quot;&gt;resize&lt;/a&gt; and &lt;a href=&quot;https://usage.imagemagick.org/resize/#scale&quot;&gt;scale&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="blaugust-2025"/>
      
      <category term="imagemagick"/>
      
      <summary type="html">TIL: Why pixel art images should be scaled and how to do it with imagemagick</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 Books through the ages</title>
      <link href="https://varunbarad.com/blog/books-through-the-ages.html" rel="alternate" type="text/html" title="📚 Books through the ages"/>
      <published>2025-08-28T22:17:43+05:30</published>
      <updated>2025-08-28T22:17:43+05:30</updated>
      <id>https://varunbarad.com/blog/books-through-the-ages.html</id>
      <content type="html">
      &lt;p&gt;This is my third listicle post in the media listicles I decided to publish during Blaugust 2025. You can check out the &lt;a href=&quot;https://varunbarad.com/blog/games-through-the-ages&quot;&gt;games&lt;/a&gt; and &lt;a href=&quot;https://varunbarad.com/blog/movies-through-the-ages&quot;&gt;movies&lt;/a&gt; posts first, or you can proceed to the list of books straight away.&lt;/p&gt;
&lt;h2&gt;Grandma&#39;s Bag of Stories&lt;/h2&gt;
&lt;p&gt;This is a collection of short stories told from the perspective of a grandma to her grandchildren. The stories are set in an Indian background, and each story gives a small moral lesson while being totally lighthearted themselves.&lt;/p&gt;
&lt;p&gt;These stories are great light reading if read by yourself. But in my opinion, the best experience is had when someone reads them to you, or you read them to someone, whether it is to your kids, partner, or parents.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://openlibrary.org/books/OL34758427M/Grandma%27s_Bag_of_Stories&quot;&gt;The book on Open Library&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Way of the Warrior Kid&lt;/h2&gt;
&lt;p&gt;This one again is targeted towards kids, but I found it to be one of the most approachable self-help books. This keeps things basic and just gives you the big picture ideas of what you can do to feel and be better/healthier/however-you-wanna-say-it.&lt;/p&gt;
&lt;p&gt;While most of you are not going to be Mark&#39;s age, I am pretty sure you can relate to his journey through his holidays with his Uncle Jake.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://openlibrary.org/books/OL26943939M/Way_of_the_warrior_kid&quot;&gt;The book on Open Library&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Jurassic Park&lt;/h2&gt;
&lt;p&gt;I would keep this short. Jurassic Park is one of my all-time favorite movies, and the only reason I did not include it in the &lt;a href=&quot;https://varunbarad.com/blog/movies-through-the-ages&quot;&gt;movies&#39; post&lt;/a&gt; is because I wanted to mention the book today.&lt;/p&gt;
&lt;p&gt;It is amongst the top science fiction stories I have ever read. The movie is great, but it still falls short if compared to the book.&lt;/p&gt;
&lt;p&gt;READ IT. READ IT NOW.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://openlibrary.org/books/OL1889702M/Jurassic_Park&quot;&gt;The book on Open Library&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Game Changer of Trauma Care&lt;/h2&gt;
&lt;p&gt;This book is not commercially available, at least not that I know of. But it is the only book I have ever seen written on the role that an anaesthetist plays inside the hospital. The way I describe anaesthetists is: &amp;quot;They keep you alive when someone is cutting you apart&amp;quot;.&lt;/p&gt;
&lt;p&gt;My wife is an anaesthetist herself, and I have seen first-hand how much mental stress they are constantly under. If you have a medical professional in your friends/family circle, then go and thank them today.&lt;/p&gt;
&lt;p&gt;The closest book you can get to understand medical professionals&#39; lives is: &lt;a href=&quot;https://openlibrary.org/books/OL37813170M/This_is_going_to_hurt&quot;&gt;This is going to hurt - by Adam Kay&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;How To?&lt;/h2&gt;
&lt;p&gt;We all would agree that cages hamper the growth of the captive. Similarly, thinking in regular real-world constraints also stunts our thinking from reaching absurd boundaries of what is actually possible.&lt;/p&gt;
&lt;p&gt;Just to give an example: if you were told that you need to cross a river, would it occur to you that a possible way to do that could be to evaporate the complete river and then walk across the river-bed.&lt;/p&gt;
&lt;p&gt;You can even pair it with the author&#39;s two other books: &lt;a href=&quot;https://openlibrary.org/works/OL17095301W/What_If?mode=all&quot;&gt;What If?&lt;/a&gt; and &lt;a href=&quot;https://openlibrary.org/works/OL17095301W/What_If?edition=key%3A/books/OL37018360M&quot;&gt;What If? 2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://openlibrary.org/works/OL20128880W/How_To?edition=key%3A/books/OL27907482M&quot;&gt;The book on Open Library&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;What? Where are the cover images?&lt;/h2&gt;
&lt;p&gt;It is very late in the night here, and I cannot be bothered to add those covers right now.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="books"/>
      
      <summary type="html">5 books I have enjoyed over the years</summary>
    </entry>
  
    
    <entry>
      <title type="html">🏆 Gamifying blogging and personal site maintenance</title>
      <link href="https://varunbarad.com/blog/blogging-achievements.html" rel="alternate" type="text/html" title="🏆 Gamifying blogging and personal site maintenance"/>
      <published>2025-08-27T23:21:49+05:30</published>
      <updated>2025-08-27T23:21:49+05:30</updated>
      <id>https://varunbarad.com/blog/blogging-achievements.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/blogging-achievements/wordsmith.webp&quot; alt=&quot;Bronze, Silver, Gold and Amethyst badges for &amp;quot;Wordsmith&amp;quot; achievements&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I got an in-game achievement when playing a game recently - a small pop-up, a flashy badge, and that familiar burst of satisfaction. Last week when writing for Blaugust it struck my mind that we can make something similar for our own blogs.&lt;/p&gt;
&lt;p&gt;A personal blog doesn&#39;t have to be just some posts on a page - it can be a game in itself, with milestones and badges for them milestones. That tiny bit of gamification can turn routine writing and site maintenance into a playful (yet capturing) quest.&lt;/p&gt;
&lt;p&gt;I came up with some ideas along those lines, some are one-off while some have tiers to them. I have even designed progression badges for one of them.&lt;/p&gt;
&lt;h2&gt;Writing &amp;amp; Publishing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;First Steps: Publish first entry
&lt;ul&gt;
&lt;li&gt;Writer: First blog post&lt;/li&gt;
&lt;li&gt;Reader: First book review&lt;/li&gt;
&lt;li&gt;Watcher: First movie review&lt;/li&gt;
&lt;li&gt;Player: First game review&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Wordsmith: Wrote &amp;quot;x&amp;quot; words in total (the badges shown at the start were designed for this)
&lt;ul&gt;
&lt;li&gt;Bronze: 8,192 words&lt;/li&gt;
&lt;li&gt;Silver: 32,768 words&lt;/li&gt;
&lt;li&gt;Gold: 1,31,072 words&lt;/li&gt;
&lt;li&gt;Amethyst: 5,24,288 words (so what if the fires are low, the &lt;s&gt;ambers&lt;/s&gt; amethysts are still aglow :P)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Centenarian: Publish 100 blog posts&lt;/li&gt;
&lt;li&gt;Speed Demon: Publish 5 posts in a week&lt;/li&gt;
&lt;li&gt;Scroll Roller: Write a post longer than 5000 words&lt;/li&gt;
&lt;li&gt;Series Samurai: Complete a multi-part blog series (3+ posts)
&lt;ul&gt;
&lt;li&gt;Bronze: First series&lt;/li&gt;
&lt;li&gt;Silver: Three series&lt;/li&gt;
&lt;li&gt;Gold: Seven series&lt;/li&gt;
&lt;li&gt;Amethyst: 29 series&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Technical/Site Building&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Phoenix Rising: Finish a complete redesign&lt;/li&gt;
&lt;li&gt;Tinker Tailor: Add a new feature yourself&lt;/li&gt;
&lt;li&gt;Bug Basher: Fixed issues spotted by readers
&lt;ul&gt;
&lt;li&gt;Bronze: First issue fixed&lt;/li&gt;
&lt;li&gt;Silver: Three issues fixed&lt;/li&gt;
&lt;li&gt;Gold: Seven issues fixed&lt;/li&gt;
&lt;li&gt;Amethyst: 15 issues fixed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Mobile Master: Optimize site for a useful mobile experience&lt;/li&gt;
&lt;li&gt;The Real OG: Incorporate appropriate open-graph tags for better previews&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Creativity &amp;amp; Exploration&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Warrior: Write about a workout you like&lt;/li&gt;
&lt;li&gt;Chef: Publish the recipe of a dish you enjoy&lt;/li&gt;
&lt;li&gt;Maker Meta: Share a behind-the-scenes post of your workflow/workspace&lt;/li&gt;
&lt;li&gt;Challenge Accepted: Complete a writing challenge (NaNoWriMo, Blaugust, etc)&lt;/li&gt;
&lt;li&gt;Deep Diver: Write a detailed analysis piece&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Process &amp;amp; Discipline&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Early Bird: Publish a post before 7 am&lt;/li&gt;
&lt;li&gt;Night Owl: Publish a post after 11 pm&lt;/li&gt;
&lt;li&gt;Weekly Warrior: Publish a post every week.
&lt;ul&gt;
&lt;li&gt;Bronze: 4 weeks&lt;/li&gt;
&lt;li&gt;Silver: 8 weeks&lt;/li&gt;
&lt;li&gt;Gold: 16 weeks&lt;/li&gt;
&lt;li&gt;Amethyst: 64 weeks (so what if the fires are low, the &lt;s&gt;ambers&lt;/s&gt; amethysts are still aglow :P)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Time Traveller: Schedule posts in advance
&lt;ul&gt;
&lt;li&gt;Bronze: One post&lt;/li&gt;
&lt;li&gt;Silver: Two posts&lt;/li&gt;
&lt;li&gt;Gold: Four posts&lt;/li&gt;
&lt;li&gt;Amethyst: 16 posts&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Editor&#39;s Eye: Updated or revised an old post&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="meta"/>
      
      <summary type="html">How adding small badges/achievements can improve the blogging experience</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 F1</title>
      <link href="https://varunbarad.com/blog/movie-f1.html" rel="alternate" type="text/html" title="🎬 F1"/>
      <published>2025-08-25T23:47:16+05:30</published>
      <updated>2025-08-25T23:47:16+05:30</updated>
      <id>https://varunbarad.com/blog/movie-f1.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Poster of the movie F1&quot; src=&quot;https://varunbarad.com/assets/images/movies/f1-poster.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Score: 5/5 🎖&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Racing legend Sonny Hayes is coaxed out of retirement to lead a struggling Formula 1 team (and mentor a young hotshot driver) while chasing one more chance at glory.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://thetvdb.com/movies/347720-apex&quot;&gt;TheTVDB.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I initially watched it with some friends and liked it so much that I went again with my wife to show her the movie too. A lot of care and effort has been put into making the details look authentic, and it shows.&lt;/p&gt;
&lt;p&gt;A good-old entertaining script, combined with the cinematic direction and an electrifying score together makes for a must-watch movie.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="movies"/>
      
      <summary type="html">My thoughts and opinions on this movie</summary>
    </entry>
  
    
    <entry>
      <title type="html">📱 What&#39;s on my phone home screen</title>
      <link href="https://varunbarad.com/blog/phone-home-screen-2025.html" rel="alternate" type="text/html" title="📱 What&#39;s on my phone home screen"/>
      <published>2025-08-24T18:04:27+05:30</published>
      <updated>2025-08-24T18:04:27+05:30</updated>
      <id>https://varunbarad.com/blog/phone-home-screen-2025.html</id>
      <content type="html">
      &lt;p&gt;Recently I saw &lt;a href=&quot;https://notes.jeddacp.com/whats-on-my-iphone-home-screen/&quot;&gt;Jedda&#39;s post&lt;/a&gt; on her phone home screen and thought I should also try something like that. Here we go:&lt;/p&gt;
&lt;img alt=&quot;Photo of my phone&#39;s home screen&quot; src=&quot;https://varunbarad.com/assets/images/posts/phone-home-screen/2025.webp&quot; style=&quot;margin: auto; width: auto; max-height: 500px;&quot; /&gt;
&lt;p&gt;Starting from the top-left, we have the usual clock widget which also opens my alarms when clicked. On the right of it we have a clock-like icon which opens a &lt;a href=&quot;https://tasker.joaoapps.com/index.html&quot;&gt;Tasker&lt;/a&gt; action which allows me to input a time and then sets 3 alarms at 15 min intervals starting from the entered time.&lt;/p&gt;
&lt;p&gt;The three similar looking icons clubbed together on the top-right are display density controls made using &lt;a href=&quot;https://www.macrodroid.com/&quot;&gt;MacroDroid&lt;/a&gt;. They allow me to set at three pre-set densities so that I can quickly make the display either more easily readable or make it contain more content.&lt;/p&gt;
&lt;p&gt;Then the 10 widgets below those are my time-tracker shortcut widgets. I try to track all my time, mostly to discourage me from sinking my time where I don&#39;t want to. You can refer to this &lt;a href=&quot;https://www.relay.fm/cortex/44&quot;&gt;Cortex podcast episode&lt;/a&gt; to understand how that goes.&lt;/p&gt;
&lt;p&gt;Then on the left the largest widget is for &lt;a href=&quot;https://todoist.com/&quot;&gt;Todoist&lt;/a&gt;, my task-management application of choice (please ignore the long overdue tasks). Below Todoist is &lt;a href=&quot;https://focusmeter.app/&quot;&gt;Focusmeter&lt;/a&gt;, my pomodoro timer, widget.&lt;/p&gt;
&lt;p&gt;Below Focusmeter on the left edge is my collection of navigation apps and shortcuts. I have Google Maps and &lt;a href=&quot;https://github.com/VarunBarad/my-places-android&quot;&gt;My Places&lt;/a&gt;, and I also have three shortcuts for directly opening driving directions to my frequently visited places. Besides the navigation folder, I have my podcasts application &lt;a href=&quot;https://podcastaddict.com/&quot;&gt;Podcast Addict&lt;/a&gt;, which is the best podcast listening app in my opinion. The third one is &lt;a href=&quot;https://www.firefox.com/en-US/browsers/mobile/android/&quot;&gt;Firefox&lt;/a&gt;, my choice of mobile (and desktop) browser.&lt;/p&gt;
&lt;p&gt;Finally, in the dock I have camera in the centre. On the left we have Phone and communications apps. And on the right we have my &lt;a href=&quot;https://github.com/VarunBarad/to-read-manager-android&quot;&gt;bookmarking app&lt;/a&gt; and my habit tracking app called &lt;a href=&quot;https://play.google.com/store/apps/details?id=org.isoron.uhabits&amp;amp;hl=en-US&quot;&gt;Loop&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To launch any application not on my home-screen is generally launched by searching for it using the search bar seen just above the dock.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">The one where I go through each and everything on my phone&#39;s home screen and explain why it is there</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Serve local sites over HTTPS connections</title>
      <link href="https://varunbarad.com/blog/https-local-sites.html" rel="alternate" type="text/html" title="📝 Serve local sites over HTTPS connections"/>
      <published>2025-08-24T13:08:17+05:30</published>
      <updated>2025-08-24T13:08:17+05:30</updated>
      <id>https://varunbarad.com/blog/https-local-sites.html</id>
      <content type="html">
      &lt;p&gt;Let&#39;s say you are building a website and testing it locally, assume it is on &lt;code&gt;localhost:8080&lt;/code&gt;. Now if you were to visit that URL in a browser, it would take you to &lt;code&gt;http://localhost:8080&lt;/code&gt;. And it won&#39;t work if you tried using the HTTPS protocol as you don&#39;t have a proper SSL/TLS certificate. But we can use the &lt;a href=&quot;https://caddyserver.com/&quot;&gt;Caddy&lt;/a&gt; server to serve a site over HTTPS.&lt;/p&gt;
&lt;p&gt;We will need to use a hostname because it&#39;s easier to get SSL/TLS cert for a domain than an IP address. We will use &lt;code&gt;garden.varun&lt;/code&gt; domain because I am pretty sure &lt;code&gt;.varun&lt;/code&gt; is not going to be a TLD ever and thus no chances of clashes with actual domains.&lt;/p&gt;
&lt;h2&gt;Installing and configuring Caddy&lt;/h2&gt;
&lt;p&gt;You can install Caddy using Homebrew on macOS with &lt;code&gt;brew install caddy&lt;/code&gt; (please look up the specific steps if you are using a different OS). After that in your project directory (or working directory, your choice) create a file named &lt;code&gt;Caddyfile&lt;/code&gt; with these contents:&lt;/p&gt;
&lt;pre class=&quot;language-caddyfile&quot;&gt;&lt;code class=&quot;language-caddyfile&quot;&gt;{
    local_certs
}

garden.varun {
    reverse_proxy 127.0.0.1:8080
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Pointing garden.varun to our own computer&lt;/h2&gt;
&lt;p&gt;Next we need to modify our computer&#39;s hosts file (in Mac or Linux it is situated at &lt;code&gt;/etc/hosts&lt;/code&gt;) to tell it to point &lt;code&gt;garden.varun&lt;/code&gt; to &lt;code&gt;127.0.0.1&lt;/code&gt;. We would need to add the below record at the bottom of the existing file&#39;s contents:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;127.0.0.1   garden.varun&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You might need to use admin privileges to update the &lt;code&gt;/etc/hosts&lt;/code&gt; file.&lt;/p&gt;
&lt;h2&gt;Firing up caddy&lt;/h2&gt;
&lt;p&gt;Next, start the caddy server using the command &lt;code&gt;caddy run&lt;/code&gt; and you should be good to go. Visit &lt;code&gt;https://garden.varun&lt;/code&gt; in your browser and it should show you the website/whatever served on your local &lt;code&gt;8080&lt;/code&gt; port with an HTTPS connection.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">TIL: How to serve your local website over HTTPS</summary>
    </entry>
  
    
    <entry>
      <title type="html">🃏 Card game: Mindikot / Dehla Pakad / Catch the Ten</title>
      <link href="https://varunbarad.com/blog/tabletop-game-mindikot.html" rel="alternate" type="text/html" title="🃏 Card game: Mindikot / Dehla Pakad / Catch the Ten"/>
      <published>2025-08-24T10:12:48+05:30</published>
      <updated>2025-08-24T10:12:48+05:30</updated>
      <id>https://varunbarad.com/blog/tabletop-game-mindikot.html</id>
      <content type="html">
      &lt;p&gt;I learned this card game back in my college days. It is a team-based 4-player game played with a standard deck of cards. Players sitting opposite are in the same team and the goal is to capture as many Tens as you can.&lt;/p&gt;
&lt;h2&gt;Setup&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;4 players: Two teams of two, partners sit opposite&lt;/li&gt;
&lt;li&gt;Standard 52 card deck&lt;/li&gt;
&lt;li&gt;Dealer is chosen randomly for the first game, then rotates clockwise&lt;/li&gt;
&lt;li&gt;The person sitting to the left of dealer decides the trump suit after getting their first 5 cards and&lt;/li&gt;
&lt;li&gt;The aim is to capture as many of the four Tens as possible. Each Ten counts as one point, no other card counts for any points.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Gameplay&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The dealer distributes 5 cards to each player&lt;/li&gt;
&lt;li&gt;The person to the left of dealer selects the trump suit after seeing their 5 cards&lt;/li&gt;
&lt;li&gt;Then the dealer distributes the remaining cards (8 to each player)&lt;/li&gt;
&lt;li&gt;The person who decided the trump suit starts the first trick&lt;/li&gt;
&lt;li&gt;Players must follow the suit if possible, if not they may play any card&lt;/li&gt;
&lt;li&gt;The highest card of the led suit wins the trick, but if the trump suit has also been played then the highest card of trump suit wins&lt;/li&gt;
&lt;li&gt;The winner of the trick starts the next one&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Scoring&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Scores are calculated for teams, and not individuals.&lt;/li&gt;
&lt;li&gt;Each captured Ten counts for 1 point&lt;/li&gt;
&lt;li&gt;No other card capture counts towards points&lt;/li&gt;
&lt;li&gt;Four games together make up a session&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="tabletop-games"/>
      
      <summary type="html">Guidebook on how to play the game</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Record HTML &amp;lt;canvas&amp;gt; video using JavaScript</title>
      <link href="https://varunbarad.com/blog/record-canvas-video.html" rel="alternate" type="text/html" title="📝 Record HTML &amp;lt;canvas&amp;gt; video using JavaScript"/>
      <published>2025-08-23T16:14:07+05:30</published>
      <updated>2025-08-23T16:14:07+05:30</updated>
      <id>https://varunbarad.com/blog/record-canvas-video.html</id>
      <content type="html">
      &lt;p&gt;You can record a &lt;code&gt;canvas&lt;/code&gt; element into a video without requiring any screen-recording permissions from the user. We use the &lt;code&gt;canvas.captureStream&lt;/code&gt; and &lt;code&gt;MediaRecorder&lt;/code&gt; API to do that.&lt;/p&gt;
&lt;h2&gt;Setup&lt;/h2&gt;
&lt;p&gt;Our example has a canvas, two buttons (to start and stop the recording) and a status message. We record the video of canvas and then download it once the recording is finished.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; mediaRecorder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; recordedChunks &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; isRecording &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; canvas &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;gameCanvas&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; buttonStartRecording &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;startRecord&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; buttonStopRecording &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;stopRecord&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; status &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;status&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Start recording&lt;/h2&gt;
&lt;p&gt;We get the video stream from a canvas with &lt;code&gt;canvas.captureStream&lt;/code&gt; and specify our desired FPS there. Then we feed it to the &lt;code&gt;MediaRecorder&lt;/code&gt; instance. Lastly, when the media-recorder receives the stop command, it will start downloading the recorded video.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;startRecording&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token comment&quot;&gt;// Request a stream at 30 FPS&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; stream &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; canvas&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;captureStream&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		
		mediaRecorder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MediaRecorder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stream&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;mimeType&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;video/webm&#39;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		recordedChunks &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		
		mediaRecorder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;dataavailable&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;size &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				recordedChunks&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		
		mediaRecorder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;stop&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;token function&quot;&gt;downloadRecording&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		
		mediaRecorder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		isRecording &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		
		&lt;span class=&quot;token function&quot;&gt;updateUi&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;error&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Error starting recording:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; error&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token function&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Error starting recording:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; error&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

buttonStartRecording&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;click&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; startRecording&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Stopping the recording&lt;/h2&gt;
&lt;p&gt;We simply ask the &lt;code&gt;mediaRecorder&lt;/code&gt; to stop recording, and it fires the &lt;code&gt;stop&lt;/code&gt; event on itself which then triggers the download.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;stopRecording&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;mediaRecorder &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; isRecording&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		mediaRecorder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		isRecording &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token function&quot;&gt;updateUi&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

buttonStopRecording&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;click&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stopRecording&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Downloading the video&lt;/h2&gt;
&lt;p&gt;We add an invisible &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element and then click it.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;downloadRecording&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;recordedChunks&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token function&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;No recording data available!&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; blob &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Blob&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;recordedChunks&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;video/webm&#39;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; url &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createObjectURL&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;blob&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;display &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;none&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;href &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; url&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	
	a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;download &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;canvas-recording-&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;Date&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;.webm&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	
	document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;token function&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;removeChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token constant&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;revokeObjectURL&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;url&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
	
	recordedChunks &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Sample&lt;/h2&gt;
&lt;p&gt;Here&#39;s a sample demo to test:&lt;/p&gt;
&lt;iframe src=&quot;https://varunbarad.com/experiments/canvas-recording.html&quot; style=&quot;width: 100%; min-height: 700px;&quot;&gt;&lt;/iframe&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="blaugust-2025"/>
      
      <category term="javascript"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to record a video of the HTML canvas element using JavaScript</summary>
    </entry>
  
    
    <entry>
      <title type="html">Low Stakes Hot Take</title>
      <link href="https://varunbarad.com/blog/low-stakes-hot-takes.html" rel="alternate" type="text/html" title="Low Stakes Hot Take"/>
      <published>2025-08-23T07:27:10+05:30</published>
      <updated>2025-08-23T07:27:10+05:30</updated>
      <id>https://varunbarad.com/blog/low-stakes-hot-takes.html</id>
      <content type="html">
      &lt;p&gt;One of the community group-post topic in this year&#39;s Blaugust was &amp;quot;Low Stakes Hot Takes&amp;quot;. Basically something which is rather inconsequential but which you feel very strongly about. I will start with one here and later on keep adding more if I feel so.&lt;/p&gt;
&lt;h2&gt;Red key-switches are better than Brown key-switches&lt;/h2&gt;
&lt;p&gt;In mechanical keyboards I believe that linear red switches are objectively better than tactile brown switches. The linear motion, compared to the tactile bump, feels lighter on fingers, thus reducing the chances of RSI. It also generally helps that they are quieter compared to the others.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="miscellaneous"/>
      
      <summary type="html">Some inconsequential hills that I don&#39;t want to get down from</summary>
    </entry>
  
    
    <entry>
      <title type="html">⌨️ Say hi to a new keyboard</title>
      <link href="https://varunbarad.com/blog/keyboard-kc-v6max-intro.html" rel="alternate" type="text/html" title="⌨️ Say hi to a new keyboard"/>
      <published>2025-08-22T21:54:41+05:30</published>
      <updated>2025-08-22T21:54:41+05:30</updated>
      <id>https://varunbarad.com/blog/keyboard-kc-v6max-intro.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/keyboard-kc-v6max/keyboard-full.webp&quot; alt=&quot;Full-size view of the Keychron V6 Max keyboard&quot; /&gt;&lt;/p&gt;
&lt;p&gt;After 4 full years with my trusty &lt;a href=&quot;https://meckeys.com/shop/keyboard/100-keyboard/ducky-one-2-tuxedo/&quot;&gt;Ducky One 2 Tuxedo&lt;/a&gt;, I finally bought a new keyboard. There is nothing wrong with my old keyboard, it is functioning just as good as the day I bought it. I just wanted an upgrade.&lt;/p&gt;
&lt;h2&gt;What did I choose?&lt;/h2&gt;
&lt;p&gt;My absolute minimum requirement was a proper full-size keyboard. None of those squeezing the arrow keys into the main section or moving the &amp;quot;Insert → Page Down&amp;quot; section around. So, after looking at the limited options available in the full-size mechanical keyboard segment, I decided to go with the &lt;a href=&quot;https://keychron.in/product/keychron-v6-qmk-custom-mechanical-keyboard/&quot;&gt;Keychron V6 Max&lt;/a&gt; (I went with the red switches).&lt;/p&gt;
&lt;h2&gt;Why did I choose it?&lt;/h2&gt;
&lt;p&gt;It was literally the only mechanical keyboard available in India which ticked all the above boxes. And it also came with these upgrades over my existing keyboard:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Triple connectivity options
&lt;ul&gt;
&lt;li&gt;Bluetooth&lt;/li&gt;
&lt;li&gt;Wired&lt;/li&gt;
&lt;li&gt;2.4 GHz dongle-based&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;QMK/VIA programmable&lt;/li&gt;
&lt;li&gt;Configurable backlight&lt;/li&gt;
&lt;li&gt;A rotary encoder knob&lt;/li&gt;
&lt;li&gt;Hot swappable switches&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;How has it been?&lt;/h2&gt;
&lt;p&gt;I am sometimes hitting the wrong keys because of the slightly changed keycap profile, but otherwise the experience has been nice. After three weeks of use, I am back at around the same efficiency I had with my previous keyboard.&lt;/p&gt;
&lt;p&gt;I haven&#39;t yet made any customisations to the keymap, but I plan to change some small things around this weekend. I&#39;ll report back next weekend with how that works out over the week.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="toys"/>
      
      <summary type="html">My first impressions with my new Keychron V6 Max</summary>
    </entry>
  
    
    <entry>
      <title type="html">📜 Blaugust 2025 Check-in</title>
      <link href="https://varunbarad.com/blog/blaugust-2025-check-in.html" rel="alternate" type="text/html" title="📜 Blaugust 2025 Check-in"/>
      <published>2025-08-21T22:52:44+05:30</published>
      <updated>2025-08-21T22:52:44+05:30</updated>
      <id>https://varunbarad.com/blog/blaugust-2025-check-in.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/blaugust-2025/blaugust2025-banner.webp&quot; alt=&quot;Blaugust 2025 banner&quot; /&gt;&lt;/p&gt;
&lt;p&gt;We are around two-thirds of the way through August. So how are you doing? How is your initial target holding? How are you holding mentally?&lt;/p&gt;
&lt;h2&gt;How am I holding up on paper?&lt;/h2&gt;
&lt;p&gt;My original target was the Rainbow Diamond badge, which demands at least 31 posts. Counting today&#39;s post, I should have been at 21 posts to keep up with that target. But so far I am at 18 posts (including this one), which is three posts behind schedule.&lt;/p&gt;
&lt;p&gt;Out of the remaining 13 posts, I have topics for 8 posts. And it is these five unknown topics that scare me more than those three backlog posts.&lt;/p&gt;
&lt;h2&gt;How am I holding mentally?&lt;/h2&gt;
&lt;p&gt;It is way tougher than I thought it would be. And I had thought that it would be tough. While I did finish the two books that were on my currently reading list, I have not picked up any new ones. Nor have I been able to play any video games. That is because I am putting all my after-work available bandwidth into this.&lt;/p&gt;
&lt;p&gt;But this has also shown me a side of mine I didn&#39;t know until yet. I never thought I would be able to publish four blog posts within 24 hours, which I did this last Sunday. It helped break the barrier for a lot of different kinds of posts to come to my blog: recipes, media recommendations, and travel diaries (to name a few).&lt;/p&gt;
&lt;p&gt;That is how I am doing with Blaugust. How are you all? For me the target is still the Rainbow Diamond badge. So, onwards and upwards I go.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">How am I doing, on paper and in mind, with Blaugust</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 Movies through the ages</title>
      <link href="https://varunbarad.com/blog/movies-through-the-ages.html" rel="alternate" type="text/html" title="🎬 Movies through the ages"/>
      <published>2025-08-21T10:38:41+05:30</published>
      <updated>2025-08-21T10:38:41+05:30</updated>
      <id>https://varunbarad.com/blog/movies-through-the-ages.html</id>
      <content type="html">
      &lt;p&gt;When starting Blaugust, I had decided that I would share at least three listicles, one of each kind of media (books, movies, and video games), featuring my recommendations under each. Each &lt;a href=&quot;https://varunbarad.com/blog/movie-rating-system&quot;&gt;movie&#39;s score&lt;/a&gt; is marked alongside the title:&lt;/p&gt;
&lt;h2&gt;Terminator 2: Judgment Day (Score: 5/5 🎖)&lt;/h2&gt;
&lt;img alt=&quot;Poster for Terminator 2: Judgment Day&quot; src=&quot;https://varunbarad.com/assets/images/posts/movies-through-the-ages/terminator-2.webp&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;This must be the first science-fiction movie I remember seeing. The crunch of the first skull-crush is still embedded in my mind. The plot, the casting of both Arnold and Robert as T-800 and T-1000, and the effects are all top-notch.&lt;/p&gt;
&lt;p&gt;The plot has a couple of robots coming back from the future, one to protect and one to eliminate. Pair that with action sequences containing car chases, gun fights, a minigun, and even a freaking grenade launcher. Somehow they still manage to fit in one small hand-to-hand combat that looks decent.&lt;/p&gt;
&lt;p&gt;This is probably the only movie in the franchise I really enjoy and is a must watch for anyone who is a fan of science-fiction or action movies.&lt;/p&gt;
&lt;h2&gt;Johnny English Reborn (Score: 4/5 👌)&lt;/h2&gt;
&lt;img alt=&quot;Poster for Johnny English Reborn&quot; src=&quot;https://varunbarad.com/assets/images/posts/movies-through-the-ages/johnny-english-reborn.webp&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;This movie is not for people who take movies seriously. Rowan Atkinson assumes the role of an MI7 agent in his own quirky style. While there may be plot holes in the movie, it is a hillarious roller-coaster of a ride.&lt;/p&gt;
&lt;p&gt;It is about Mr English (Rowan Atkinson) coming out of retirement to outsmart and beat Vortex, who are trying to assassinate the Chinese Premier during talks with the UK.&lt;/p&gt;
&lt;p&gt;This is not the first movie in this series, or probably even the best one. But I got introduced to the series with this so I am mentioning this.&lt;/p&gt;
&lt;h2&gt;Kung Fu Panda (Score: 5/5 🎖)&lt;/h2&gt;
&lt;img alt=&quot;Poster for Kung Fu Panda&quot; src=&quot;https://varunbarad.com/assets/images/posts/movies-through-the-ages/kung-fu-panda.webp&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;It takes having a great villain to even have the chance of having a great hero and this movie has one of the best written villain, Tai Lung, of all time. The scene of his introduction still remains the coldest intro any &lt;s&gt;villain&lt;/s&gt; character has ever gotten.&lt;/p&gt;
&lt;p&gt;The seriousness of Tai Lung is thoroughly matched by the insanity that is Po the panda (our protagonist). The character development that Po gets over the course of the movie is something that is quite relatable for kids and adults alike. My favorite characteristic of Po is that no matter how many punches he takes, he always stands back up to go another round.&lt;/p&gt;
&lt;h2&gt;Man of Steel (Score: 5/5 🎖)&lt;/h2&gt;
&lt;img alt=&quot;Poster for Man of Steel&quot; src=&quot;https://varunbarad.com/assets/images/posts/movies-through-the-ages/man-of-steel.webp&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;General Zod is another one of those villains who just steal the show. The difference between Superman and Zod become apparent when within a single day Zod adapts to the earth environment and is able to go toe-to-toe with Superman.&lt;/p&gt;
&lt;p&gt;Henry Cavill fits the cape of Superman quite nicely. This is a classic Superman movie containing awesome visuals and a marvellous background score. I am yet to watch the newly released Superman movie, but so far this is my favorite one.&lt;/p&gt;
&lt;h2&gt;John Wick (Score: 5/5 🎖)&lt;/h2&gt;
&lt;img alt=&quot;Poster for John Wick&quot; src=&quot;https://varunbarad.com/assets/images/posts/movies-through-the-ages/john-wick.webp&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;blockquote&gt;
&lt;p&gt;It&#39;s not what you did son, that angers me so. It&#39;s who you did it to.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And that is how you start a bad-ass introduction. Remember kids, never mess with someone who has retired from a job where people end up dying before leaving.&lt;/p&gt;
&lt;p&gt;This franchise has some of the highest attention-to-detail gunfights. The protagonist is basically a killer machine making a weapon out of anything in his reach. Oh the magazine is empty, let me just throw the whole gun at the other guy&#39;s head.&lt;/p&gt;
&lt;p&gt;This and many more such sequences ensue when a mafia&#39;s son kills the retired Baba Yaga&#39;s puppy.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="movies"/>
      
      <summary type="html">5 movies I have watched countless times over the years</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Setting up MongoDB for local development with docker compose</title>
      <link href="https://varunbarad.com/blog/mongodb-local-docker-compose.html" rel="alternate" type="text/html" title="📝 Setting up MongoDB for local development with docker compose"/>
      <published>2025-08-20T01:19:06+05:30</published>
      <updated>2025-08-20T01:19:06+05:30</updated>
      <id>https://varunbarad.com/blog/mongodb-local-docker-compose.html</id>
      <content type="html">
      &lt;p&gt;Recently for a project I needed to setup a local mongodb instance using docker (via docker-compose). I set up this simple compose file:&lt;/p&gt;
&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;3.1&quot;&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;mongo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;container_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;auth&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;mongo
    &lt;span class=&quot;token key atrule&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; mongo&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;4.4.20&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;rc0&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;focal
    &lt;span class=&quot;token key atrule&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;MONGO_INITDB_DATABASE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; authdb
      &lt;span class=&quot;token key atrule&quot;&gt;MONGO_INITDB_ROOT_USERNAME&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; mongo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;admin
      &lt;span class=&quot;token key atrule&quot;&gt;MONGO_INITDB_ROOT_PASSWORD&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; admin&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;password
    &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;27017:27017&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mongo stores the login credentials in a database named &lt;code&gt;admin&lt;/code&gt; so we would need to specify that too (as &lt;code&gt;authSource&lt;/code&gt;) when connecting to it:&lt;/p&gt;
&lt;pre class=&quot;language-dotenv&quot;&gt;&lt;code class=&quot;language-dotenv&quot;&gt;MONGO_URL=mongodb://mongo-admin:admin-password@localhost:27017/authdb?retryWrites=true&amp;w=majority&amp;authSource=admin&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https://stackoverflow.com/a/75320403/4717436&quot;&gt;Hans Kilian&lt;/a&gt; over on StockOverflow.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">TIL: How to setup MongoDB for local development</summary>
    </entry>
  
    
    <entry>
      <title type="html">📚 The Phoenix Project</title>
      <link href="https://varunbarad.com/blog/book-phoenix-project.html" rel="alternate" type="text/html" title="📚 The Phoenix Project"/>
      <published>2025-08-19T10:25:17+05:30</published>
      <updated>2025-08-19T10:25:17+05:30</updated>
      <id>https://varunbarad.com/blog/book-phoenix-project.html</id>
      <content type="html">
      &lt;p&gt;&lt;img alt=&quot;Cover of the book The Phoenix Project&quot; src=&quot;https://varunbarad.com/assets/images/books/the-phoenix-project-cover.webp&quot; style=&quot;width: fit-content; height: 320px;&quot; /&gt; &lt;br /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Bill is an IT manager at Parts Unlimited. It&#39;s Tuesday morning and on his drive into the office, Bill gets a call from the CEO.&lt;/p&gt;
&lt;p&gt;The company&#39;s new IT initiative, code named Phoenix Project, is critical to the future of Parts Unlimited, but the project is massively over budget and very late. The CEO wants Bill to report directly to him and fix the mess in ninety days or else Bill&#39;s entire department will be outsourced.&lt;/p&gt;
&lt;p&gt;With the help of a prospective board member and his mysterious philosophy of The Three Ways, Bill starts to see that IT work has more in common with manufacturing plant work than he ever imagined. With the clock ticking, Bill must organize work flow streamline interdepartmental communications, and effectively serve the other business functions at Parts Unlimited.&lt;/p&gt;
&lt;p&gt;In a fast-paced and entertaining style, three luminaries of the DevOps movement deliver a story that anyone who works in IT will recognize. Readers will not only learn how to improve their own IT organizations, they&#39;ll never view IT the same way again.&lt;/p&gt;
&lt;p&gt;— &lt;a href=&quot;https://openlibrary.org/books/OL26394601M/The_Phoenix_Project&quot;&gt;Open Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;While there are a lot of cliché tropes, I still highly recommend this book to every IT professional as it is the only (along with &lt;a href=&quot;https://varunbarad.com/blog/book-phoenix-project.html&quot;&gt;The Unicorn Project&lt;/a&gt;) story/novel written about our profession.&lt;/p&gt;
&lt;p&gt;It helps a lot to learn about &amp;quot;The Three Ways&amp;quot; and to try and incorporate them into our daily lives whether we are a developer or an ops person or someone else along the chain of software production. You will also be able to spot yourself and quite a few of your colleagues in the characters in here.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="book-highlights"/>
      
      <summary type="html">My thoughts and opinions on this book</summary>
    </entry>
  
    
    <entry>
      <title type="html">💬 Why am I making myself go through Blaugust?</title>
      <link href="https://varunbarad.com/blog/replying-to-jedda.html" rel="alternate" type="text/html" title="💬 Why am I making myself go through Blaugust?"/>
      <published>2025-08-17T22:29:49+05:30</published>
      <updated>2025-08-17T22:29:49+05:30</updated>
      <id>https://varunbarad.com/blog/replying-to-jedda.html</id>
      <content type="html">
      &lt;p&gt;Recently, Jedda, a fellow Blaugustan, posted a sort-of mid-way check-in and reminder for herself and others in this challenge: &lt;a href=&quot;https://notes.jeddacp.com/blogging-breaks-and-being-kind-to-ourselves/&quot;&gt;&amp;quot;Blogging, Breaks, and Being Kind to Ourselves&amp;quot;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In it, they address the notion that it is taxing to try to do &lt;em&gt;&amp;quot;31 posts in 31 days&amp;quot;&lt;/em&gt; and that it is totally okay to not hit the perfect milestone. And that it is more often than not better to be kinder to ourselves than what we are used to.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The end goal was never meant to be about perfection. It’s the process of finding your voice, sharing your stories, and maybe connecting with someone who needed to read exactly what you had to say that day.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I don&#39;t disagree. I have already written and published a lot of posts this month that I would not have otherwise. The pressure of this challenge has lowered a lot of self-doubt about whether a post can be published or not.&lt;/p&gt;
&lt;p&gt;But, beyond all the above, there is another reason why I am doing this challenge and why I am targeting to write 31 posts this month. For context, the highest number of posts I have written in any calendar year is 25.&lt;/p&gt;
&lt;p&gt;And the reason why I am targeting the highest tier is just to test myself on whether I can even do it or not. It is like a mental and discipline test for myself. Can I take on a &lt;s&gt;complex&lt;/s&gt; non-trivial project and see it through, or have my discipline muscles atrophied enough that I would give up?&lt;/p&gt;
&lt;p&gt;I once read something similar about a calculus professor, when asked by his students, &amp;quot;Why are we learning calculus? How will it help us in life?&amp;quot; He responded that while calculus can have many implications in engineering, the biggest benefit to them of learning calculus is that it shows them that they can learn and do difficult things.&lt;/p&gt;
&lt;p&gt;So yes, I do feel that I am &amp;quot;behind&amp;quot; when I miss a day. But it only increases the urge to focus more energy on it the next day. Today is one such example. Never before in my life have I managed to write 4 blog posts in a single 24-hour window. It is only because, by the end of yesterday, I was 6 posts behind my schedule.&lt;/p&gt;
&lt;p&gt;If I don&#39;t manage to reach 31 posts, I will not be cursing myself for &lt;em&gt;failing&lt;/em&gt;. I have already hit a much higher throughput of my ideas than I would&#39;ve otherwise. But I will look back and try to identify why I could not hit my target. And then next year I will come better prepared against those obstacles.&lt;/p&gt;
&lt;p&gt;In the end, both feelings are valid: whether you want to achieve (your choice of) perfection or whether you want to have fun while putting words to pixels, what matters are your driving forces behind those feelings. Have fun, folks, and ask for discipline from yourself if you feel the need to.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="personal-growth"/>
      
      <summary type="html">And why am I targetting the Rainbow Diamond badge after all?</summary>
    </entry>
  
    
    <entry>
      <title type="html">How to get a random point inside a circle</title>
      <link href="https://varunbarad.com/blog/random-point-inside-circle.html" rel="alternate" type="text/html" title="How to get a random point inside a circle"/>
      <published>2025-08-17T16:15:48+05:30</published>
      <updated>2025-08-17T16:15:48+05:30</updated>
      <id>https://varunbarad.com/blog/random-point-inside-circle.html</id>
      <content type="html">
      &lt;p&gt;This is something from years ago, I needed to get a random point within a circular radius from a different point. The brute-force way would have to be &amp;quot;just get a random point and check if it is within the specified distance&amp;quot;.&lt;/p&gt;
&lt;p&gt;Below is a circle of radius &#39;r&#39; centered at origin, and a point situated at (x,y) somewhere within the circle.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/random-point-inside-circle/circle.svg&quot; alt=&quot;An image of a circle of radius &#39;r&#39; centered at origin showing a point at (x,y) inside the circle&quot; /&gt;&lt;/p&gt;
&lt;p&gt;It would be something like this:&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; r&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// A number between 0 (inclusive) and r (exclusive)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; r&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// A number between 0 (inclusive) and r (exclusive)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// According to mathematical equation of this circle&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token operator&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;y&lt;span class=&quot;token operator&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;r&lt;span class=&quot;token operator&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;Hurray, we can use (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;x&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;y&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;Sorry, (&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;x&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;y&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;) doesn&#39;t fall inside the circle.&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem with this approach is that each time we have to check and we aren&#39;t sure how many iterations it might take to land on workable coordinates. But we have another way that we can approach this problem.&lt;/p&gt;
&lt;h2&gt;Polar coordinates for the win&lt;/h2&gt;
&lt;p&gt;We can even show the same point in terms of its polar coordinates: (d, θ)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/random-point-inside-circle/circle-polar.svg&quot; alt=&quot;The same point represented with its polar coordinates&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now, rather than having a constraint only on the combined values of these parameters we have individual constraints on both of them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;0 ≤ θ ≤ 2π&lt;/li&gt;
&lt;li&gt;0 ≤ d &amp;lt; r&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This makes it much easier to generate both values, which can be done like this:&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; r&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// A value between 0 (inclusive) and r (exclusive)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; angle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;PI&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// A value between 0 (inclusive) and 2π (exclusive)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Using their projections on both the axes we get the values of x and y&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;angle&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;angle&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this, in a single execution we are guaranteed to get one of the points that we desire.&lt;/p&gt;
&lt;h2&gt;Side-bonus: How to get a random point in a disc around a point&lt;/h2&gt;
&lt;p&gt;What if we want to instead of getting the point inside a circle, want to get one inside a disc centered around origin with inner-radius being &lt;code&gt;r&lt;sub&gt;i&lt;/sub&gt;&lt;/code&gt; and outer-radius being &lt;code&gt;r&lt;sub&gt;o&lt;/sub&gt;&lt;/code&gt; (&lt;code&gt;= r&lt;/code&gt; from before).&lt;/p&gt;
&lt;p&gt;The only condition we need to update here is this one:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Before: 0 ≤ d &amp;lt; r&lt;/li&gt;
&lt;li&gt;Now: &lt;code&gt;r&lt;sub&gt;i&lt;/sub&gt;&lt;/code&gt; ≤ d &amp;lt; &lt;code&gt;r&lt;sub&gt;o&lt;/sub&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The code gets updated to:&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rOuter &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; rInner&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; rInner&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// A value between rInner (inclusive) and rOuter (exclusive)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; angle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;PI&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// A value between 0 (inclusive) and 2π (exclusive)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Using their projections on both the axes we get the values of x and y&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;angle&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;angle&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="programming"/>
      
      <summary type="html">Generate random points in a circle using polar coordinates instead of brute force</summary>
    </entry>
  
    
    <entry>
      <title type="html">💾 My email backup workflow</title>
      <link href="https://varunbarad.com/blog/backup-workflow-email.html" rel="alternate" type="text/html" title="💾 My email backup workflow"/>
      <published>2025-08-17T12:11:13+05:30</published>
      <updated>2025-08-17T12:11:13+05:30</updated>
      <id>https://varunbarad.com/blog/backup-workflow-email.html</id>
      <content type="html">
      &lt;p&gt;I have previously serenaded about &lt;a href=&quot;https://varunbarad.com/blog/why-you-should-own-your-email-address&quot;&gt;why I consider email a critical service&lt;/a&gt;. And for anything you consider critical, you should have a backup of/for it. I use &lt;a href=&quot;https://fastmail.com/&quot;&gt;Fastmail&lt;/a&gt; as my email host, and this is my weekly workflow for backing it up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fetch all the new emails over IMAP&lt;/li&gt;
&lt;li&gt;Compress the local mail store to &lt;code&gt;.zip&lt;/code&gt; archive&lt;/li&gt;
&lt;li&gt;Store that archive file on my NAS&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Fetch emails from Fastmail to a local store&lt;/h2&gt;
&lt;p&gt;I use the program &lt;a href=&quot;https://sourceforge.net/projects/mailsync/&quot;&gt;Mailsync&lt;/a&gt; to download from Fastmail using the IMAP protocol. Here&#39;s my config and the command I use to run that backup:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;mbsync &lt;span class=&quot;token parameter variable&quot;&gt;--all&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--config&lt;/span&gt; /Users/varunb/.config/mailsync.rc&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;IMAPAccount fastmail
Host imap.fastmail.com
User contact@example.com
PassCmd &lt;span class=&quot;token string&quot;&gt;&quot;cat /Users/varunb/.secret/FASTMAIL_PASSWORD&quot;&lt;/span&gt;
AuthMechs LOGIN
SSLType IMAPS
PipelineDepth &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;

IMAPStore fastmail-remote
Account fastmail

MaildirStore fastmail-local
Path /Users/varunb/temp/fastmail/
Inbox /Users/varunb/temp/fastmail/Inbox
SubFolders Verbatim

Channel fastmail
Far :fastmail-remote:
Near :fastmail-local:
Patterns *
Create Near
Expunge Near
SyncState *
Sync Pull&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, in line 4, you can see that instead of supplying the credentials for Fastmail directly in the config file, I use a separate file to store the password and use the &lt;code&gt;PassCmd&lt;/code&gt; option to tell it how it can find the credentials.&lt;/p&gt;
&lt;h2&gt;Compress the local store to a zip file&lt;/h2&gt;
&lt;p&gt;Once Mailsync finishes downloading the emails, I take the whole local store and compress it to a single timestamped &lt;code&gt;.zip&lt;/code&gt; file with the highest compression ratio (speed does not matter here as much as space savings matters):&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;zip&lt;/span&gt; --recurse-paths &lt;span class=&quot;token parameter variable&quot;&gt;--test&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--quiet&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-9&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/Users/varunb/temp/fastmail_2025-08-17_02-12-12.zip&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Transfer the archive to NAS&lt;/h2&gt;
&lt;p&gt;I copy the archive to NAS using a simple &lt;code&gt;cp&lt;/code&gt; command and if that is successful then we remove the local archive file. But I let the local mail store around as that reduces the amount of network transfer that has to take place the next time I run &lt;code&gt;mbsync&lt;/code&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="backups"/>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">The why and how of my email backups</summary>
    </entry>
  
    
    <entry>
      <title type="html">Tabbed navigation on a screen in a Vue app</title>
      <link href="https://varunbarad.com/blog/vue-children-tabs.html" rel="alternate" type="text/html" title="Tabbed navigation on a screen in a Vue app"/>
      <published>2025-08-17T03:24:25+05:30</published>
      <updated>2025-08-17T03:24:25+05:30</updated>
      <id>https://varunbarad.com/blog/vue-children-tabs.html</id>
      <content type="html">
      &lt;h2&gt;Problem Statement&lt;/h2&gt;
&lt;p&gt;In a &lt;a href=&quot;https://vuejs.org/&quot;&gt;Vue&lt;/a&gt; application I needed to have a screen (on path &lt;code&gt;/department/:departmentId&lt;/code&gt;) where I need to show one common header containing a selector between three tabs and then a body section which would show different content based on which tab was selected. And each tab would be associated with a different sub-path:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;quot;Overview&amp;quot;  -&amp;gt; &lt;code&gt;/department/:id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Members&amp;quot; -&amp;gt; &lt;code&gt;/department/:id/members&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Clients&amp;quot; -&amp;gt; &lt;code&gt;/department/:id/clients&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It also had to be implemented that navigating directly to any of the sub-paths should open the correct page.&lt;/p&gt;
&lt;h2&gt;Solution Approach&lt;/h2&gt;
&lt;p&gt;I needed to use &lt;code&gt;&amp;lt;router-view /&amp;gt;&lt;/code&gt; and the &lt;a href=&quot;https://router.vuejs.org/guide/essentials/nested-routes.html&quot;&gt;nested routes&lt;/a&gt; feature from &lt;a href=&quot;https://router.vuejs.org/&quot;&gt;vue-router&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Configuring the router&lt;/h2&gt;
&lt;p&gt;Here is how we configured the routes:&lt;/p&gt;
&lt;pre class=&quot;language-typescript&quot;&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; routes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    path&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;/department/:id&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;@/views/department/Index.vue&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    children&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; path&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;department-overview&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;@/views/department/TabOverview.vue&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; path&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;members&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;department-members&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;@/views/department/TabMembers.vue&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; path&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;clients&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;department-clients&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;@/views/department/TabClients.vue&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that we haven&#39;t specified any extra &lt;code&gt;path&lt;/code&gt; for the &amp;quot;Overview&amp;quot; tab. This is by design and will be explained later.&lt;/p&gt;
&lt;h2&gt;Setting up the root view&lt;/h2&gt;
&lt;p&gt;And the contents of &lt;code&gt;Index.vue&lt;/code&gt; (containing the overall page contents) looked something like this:&lt;/p&gt;
&lt;pre class=&quot;language-vue&quot;&gt;&lt;code class=&quot;language-vue&quot;&gt;&amp;lt;script setup lang=&quot;ts&quot;&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;template&amp;gt;
  &amp;lt;nav&amp;gt;
    &amp;lt;router-link :to=&quot;{ name: &#39;department-overview&#39; }&quot;&amp;gt;Overview&amp;lt;/router-link&amp;gt;
    &amp;lt;router-link :to=&quot;{ name: &#39;department-members&#39; }&quot;&amp;gt;Members&amp;lt;/router-link&amp;gt;
    &amp;lt;router-link :to=&quot;{ name: &#39;department-clients&#39; }&quot;&amp;gt;Clients&amp;lt;/router-link&amp;gt;
  &amp;lt;/nav&amp;gt;
  &amp;lt;main&amp;gt;
    &amp;lt;router-view /&amp;gt;
  &amp;lt;/main&amp;gt;
&amp;lt;/template&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Individual tab contents&lt;/h2&gt;
&lt;p&gt;Each tab&#39;s file turns out pretty simple, something like this:&lt;/p&gt;
&lt;pre class=&quot;language-vue&quot;&gt;&lt;code class=&quot;language-vue&quot;&gt;&amp;lt;script setup lang=&quot;ts&quot;&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;template&amp;gt;
  &amp;lt;p&amp;gt;Overview/Members/Clients&amp;lt;/p&amp;gt;
&amp;lt;/template&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Combining the ingredients&lt;/h2&gt;
&lt;p&gt;The reason we did not specify an extra &lt;code&gt;path&lt;/code&gt; in our router is that we need to show it directly when &lt;code&gt;/department/:id&lt;/code&gt; is opened. Now when we go to &lt;code&gt;/department/:id&lt;/code&gt; we see the header bar showing the three tab links and the contents of the &amp;quot;Overview&amp;quot; tab under it. Clicking on any other tab shows that content below the header bar, also the url gets updated.&lt;/p&gt;
&lt;p&gt;This gives us clean URLs, browser history support, the ability to persist tab-selection across page refresh, and the ability to directly navigate to any tab via URL. No manual state management is required to determine what content to show, it will automatically update based on the URL.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="programming"/>
      
      <summary type="html">How to make tabbed navigation with appropriate sub-paths using vue-router and nested routes</summary>
    </entry>
  
    
    <entry>
      <title type="html">The blog questions challenge</title>
      <link href="https://varunbarad.com/blog/blog-questions-challenge-2025.html" rel="alternate" type="text/html" title="The blog questions challenge"/>
      <published>2025-08-15T13:12:02+05:30</published>
      <updated>2025-08-15T13:12:02+05:30</updated>
      <id>https://varunbarad.com/blog/blog-questions-challenge-2025.html</id>
      <content type="html">
      &lt;p&gt;This was a challenge/chain letter that went around near the beginning of this year. I wasn&#39;t tagged, but after reading &lt;a href=&quot;https://localghost.dev/blog/the-blog-questions-challenge/&quot;&gt;Sophie&#39;s post&lt;/a&gt; yesterday, I accepted the tag from her.&lt;/p&gt;
&lt;h2&gt;Why did you start blogging in the first place?&lt;/h2&gt;
&lt;p&gt;I always wanted an online home I could point people to. By the time I reached college, I’d already seen the peak, fall, and sunset of Orkut. So I was sure it had to be a place under my control — a personal website.&lt;/p&gt;
&lt;p&gt;Around the time I left college, I bought this domain and launched the first version of this site. Back then, it was mostly an online résumé with no blog or other functionalities.&lt;/p&gt;
&lt;p&gt;As I read more blogs from professionals in my industry, I felt that I also should write similar stuff, like bugs that I encounter or some new concept that I learn. And that is how this blog was born.&lt;/p&gt;
&lt;h2&gt;What platform are you using to manage your blog and why did you choose it? Have you blogged on other platforms before?&lt;/h2&gt;
&lt;p&gt;The current version is built using &lt;a href=&quot;https://11ty.dev/&quot;&gt;Eleventy&lt;/a&gt;, a Node.js-based static site generator. I chose it because I wanted a build system that used JavaScript but didn’t want to ship unnecessary JS to readers. Hosting is on &lt;a href=&quot;https://netlify.com/&quot;&gt;Netlify&lt;/a&gt; these days.&lt;/p&gt;
&lt;p&gt;Before that, &lt;a href=&quot;https://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt; was responsible for that duty, as it was supported out-of-the-box on GitHub Pages (where this blog used to be hosted). As I started to add more features, I found Jekyll&#39;s Ruby ecosystem unfamiliar and harder to work with.&lt;/p&gt;
&lt;p&gt;And way back in the starting days, the site was just three files (one each of HTML, CSS, and JS) from a popular Bootstrap template. It was so common that within a week, I saw two other live sites using the exact same template 😅.&lt;/p&gt;
&lt;h2&gt;How do you write your posts? For example, in a local editing tool, or in a panel/dashboard that&#39;s part of your blog?&lt;/h2&gt;
&lt;p&gt;All of my posts get created inside my IDE (I use WebStorm for this project). Most get written there too, but some I would open in &lt;a href=&quot;https://typora.io/&quot;&gt;Typora&lt;/a&gt;, especially if it is prose-heavy. I once considered adding a writing/admin section to the blog, but it felt like too much overhead for too little benefit.&lt;/p&gt;
&lt;p&gt;What I might start doing more frequently is to start a draft/post in &lt;a href=&quot;https://obsidian.md/&quot;&gt;Obsidian&lt;/a&gt; and then move it to the blog when it is ready. I also want to create scripts that would create the right file given the type of post I want to write and open it directly in Typora, so I don&#39;t necessarily need to open my IDE.&lt;/p&gt;
&lt;h2&gt;When do you feel most inspired to write?&lt;/h2&gt;
&lt;p&gt;Almost never. I like having written, but the starting inertia is always huge. In rare cases, I would have an idea/topic lodged in my head which demands to be written, and those are some of the easiest posts to write.&lt;/p&gt;
&lt;h2&gt;Do you publish immediately after writing, or do you let it simmer a bit as a draft?&lt;/h2&gt;
&lt;p&gt;As soon as I complete writing (which might take multiple sessions), I move to fixing the grammar and structure, and maybe some light editing. After that it goes straight to be published without any further delays.&lt;/p&gt;
&lt;h2&gt;What&#39;s your favourite post on your blog?&lt;/h2&gt;
&lt;p&gt;It&#39;s like picking a favourite child, but I will play favourites. &lt;a href=&quot;https://varunbarad.com/blog/filename-limits&quot;&gt;&amp;quot;🗂 Filenames can&#39;t just be anything&amp;quot;&lt;/a&gt; was the most satisfying to write. Researching it was a real head-scratcher. I want people to know those details, but also hope they never need to.&lt;/p&gt;
&lt;h2&gt;Any future plans for your blog? Maybe a redesign, a move to another platform, or adding a new feature?&lt;/h2&gt;
&lt;p&gt;Recently I&#39;ve had plenty of ideas. Some I&#39;ll implement this year:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A simple changelog based on &lt;a href=&quot;https://keepachangelog.com/&quot;&gt;Keep a Changelog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A complete redesign, as neither my older theme (on post pages) nor my current theme (on other pages) are looking that good&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some that might go into the next year:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Adding a &lt;a href=&quot;https://nownownow.com/&quot;&gt;&amp;quot;now&amp;quot;&lt;/a&gt; page with archives&lt;/li&gt;
&lt;li&gt;Improving the &amp;quot;Books&amp;quot; page and adding similar ones for &amp;quot;Movies&amp;quot; and &amp;quot;Games&amp;quot;&lt;/li&gt;
&lt;li&gt;Noting down some of my favorite recipes (will also try integrating &lt;a href=&quot;https://rknight.me/blog/adding-cooklang-support-to-eleventy-two-ways/&quot;&gt;cooklang&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Who&#39;s next?&lt;/h2&gt;
&lt;p&gt;Since I am more than half-a-year late to the bandwagon, I have little hope. But I would like to see the answers from &lt;a href=&quot;https://notes.druchan.com/&quot;&gt;Chandru&lt;/a&gt;, &lt;a href=&quot;https://afsheen.me/&quot;&gt;Afsheen&lt;/a&gt; and &lt;a href=&quot;https://hamatti.org/&quot;&gt;Juhis&lt;/a&gt; if they&#39;re interested.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="meta"/>
      
      <summary type="html">The chain-letter type post that did the rounds of interweb earlier this year</summary>
    </entry>
  
    
    <entry>
      <title type="html">🧘‍♂️ Hip Stretches</title>
      <link href="https://varunbarad.com/blog/exercise-hip-stretches.html" rel="alternate" type="text/html" title="🧘‍♂️ Hip Stretches"/>
      <published>2025-08-13T23:43:55+05:30</published>
      <updated>2025-08-13T23:43:55+05:30</updated>
      <id>https://varunbarad.com/blog/exercise-hip-stretches.html</id>
      <content type="html">
      &lt;p&gt;I follow basically these two videos from &lt;a href=&quot;https://www.youtube.com/@VentunoYoga&quot;&gt;&amp;quot;Yoga &amp;amp; You&amp;quot;&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=QdZtA5v2H2U&quot;&gt;Hip Opening Sequence&lt;/a&gt; (I start with this and complete it)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=ssLxr0weI7Y&quot;&gt;Hip Opening Sequence - 2&lt;/a&gt; (I only do the first exercise from this)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are the exercise steps written out, but do check out the videos as the visual representation helps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Baddha Konasana (Butterfly Pose)
&lt;ul&gt;
&lt;li&gt;Sit with your heels close to the groin, soles of your feet should touch each other&lt;/li&gt;
&lt;li&gt;Bend forward as deep as you can go, using a block as support under your forehead if required&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Supta Baddha Konasana
&lt;ul&gt;
&lt;li&gt;Lie down on your back and bring the soles of your feet together, bringing the heels as close to the groin as possible&lt;/li&gt;
&lt;li&gt;Drop the knees down as much as you can without pain, use blocks as support if necessary&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Anand Balasana (Happy Baby Pose)
&lt;ul&gt;
&lt;li&gt;While lying down, raise your feet above you and try to bring the knees towards the chest&lt;/li&gt;
&lt;li&gt;Hold the arches of your feet from the inside and slowly let your knees drop more and more to the floor with each exhalation&lt;/li&gt;
&lt;li&gt;Ensure that your entire back is lying flat and supported&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Knee-to-Chest and then Drop-to-Side
&lt;ul&gt;
&lt;li&gt;Lying on your back, hug your right knee into the chest&lt;/li&gt;
&lt;li&gt;Use your right palm to gently drop the right knee to your right side while keeping the left hip pressed into the ground&lt;/li&gt;
&lt;li&gt;Keep it there for a few breaths, inhale while bringing it back to your chest&lt;/li&gt;
&lt;li&gt;Now use your left palm to guide the right knee over you and towards the ground on the left side of your body. Outstretch your right arm to your right side and ensure the right shoulder blade remains grounded. This should put a gentle twist in your spine.&lt;/li&gt;
&lt;li&gt;Mirror the same with the other leg&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Figure Four (4) Stretch
&lt;ul&gt;
&lt;li&gt;Lie on your back with both feet hip-width apart.&lt;/li&gt;
&lt;li&gt;Place your right ankle on the left thigh with the right knee opened out.&lt;/li&gt;
&lt;li&gt;Lift the left leg and thread your arms around the left leg to hug it closer to your chest&lt;/li&gt;
&lt;li&gt;Mirror the same with the other leg&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="exercise"/>
      
      <category term="stretch"/>
      
      <category term="yoga"/>
      
      <summary type="html">Stretches I do to maintain my hip-joint mobility</summary>
    </entry>
  
    
    <entry>
      <title type="html">🖨️ My scribe writes my documents out in the physical world</title>
      <link href="https://varunbarad.com/blog/project-scribe.html" rel="alternate" type="text/html" title="🖨️ My scribe writes my documents out in the physical world"/>
      <published>2025-08-13T11:59:13+05:30</published>
      <updated>2025-08-13T11:59:13+05:30</updated>
      <id>https://varunbarad.com/blog/project-scribe.html</id>
      <content type="html">
      &lt;p&gt;More than a decade ago was when I first learned of network connected printers and then when I learned that we can turn a local-only printer into a networked printer just by using a Raspberry Pi I jumped into the pool to try it. I had a HP LaserJet 1020 (which I still have) which works flawlessly when using over a local USB connection from a Windows machine which I wanted to be able to use over network.&lt;/p&gt;
&lt;p&gt;When I first tried that back around 2014-2015 I learned that the particular printer I had was not directly supported by &lt;a href=&quot;https://en.wikipedia.org/wiki/CUPS&quot;&gt;CUPS&lt;/a&gt;. So I had to leave it there. Sometime near the end of last year I came across &lt;a href=&quot;https://tripad.medium.com/turning-my-old-printer-into-a-wireless-printer-with-a-raspberry-pi-1fb6d73e35a4&quot;&gt;an article&lt;/a&gt; where the author had achieved exactly what I strived to all those years ago. That is when I found out that CUPS can be extended to add support for these printers.&lt;/p&gt;
&lt;p&gt;I knew things weren&#39;t going to work perfectly the first time and even if they did, I wanted to be able to reproduce it for multiple other such printers that my dad has (a Pi will be deployed at each one). So I went through the article step-by-step and turned all the required steps into a script which I can run on a newly flashed card containing Raspbian OS. You can see the script &lt;a href=&quot;https://github.com/VarunBarad/scribe&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And it works. I tested it by printing from a Mac, an Android phone, even an iPhone and it does print from all those devices. I then connected it through a &lt;a href=&quot;https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/&quot;&gt;Cloudflare Tunnel&lt;/a&gt; and was able to print over the internet from outside my local network.&lt;/p&gt;
&lt;p&gt;Now, there are a few hiccups which would need to be ironed out before I can use this as my full-time printer setup.&lt;/p&gt;
&lt;p&gt;First and the most annoying, it takes a very long time between hitting &amp;quot;Print&amp;quot; and it actually starting the print. My suspicion is that both the network transfer as well as processing the document on a Pi might be the cause.&lt;/p&gt;
&lt;p&gt;The second one I don&#39;t hit as frequently is that it can&#39;t handle double-sided printing as well as HP&#39;s proprietary driver handles on Windows. Not sure if there is a solution for this or not but will try looking around.&lt;/p&gt;
&lt;p&gt;And the easiest to fix one is that the script currently depends on two external resources (&lt;a href=&quot;https://github.com/koenkooi/foo2zjs&quot;&gt;first&lt;/a&gt; and &lt;a href=&quot;https://www.quirinux.org/printers/sihp1020.tar.gz&quot;&gt;second&lt;/a&gt;) which I will eventually bring in-house (just a local mirror should do the trick) to avoid them being rug-pulled.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="project"/>
      
      <category term="scribe"/>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">My trusty HP LaserJet 1020 now can print over network</summary>
    </entry>
  
    
    <entry>
      <title type="html">Writing incentives, Building constraints</title>
      <link href="https://varunbarad.com/blog/writing-incentives-building-constraints.html" rel="alternate" type="text/html" title="Writing incentives, Building constraints"/>
      <published>2025-08-12T23:27:30+05:30</published>
      <updated>2025-08-12T23:27:30+05:30</updated>
      <id>https://varunbarad.com/blog/writing-incentives-building-constraints.html</id>
      <content type="html">
      &lt;p&gt;When you like building things and also want to write about them, but you have a bias toward building over writing, the writing-about-it part doesn’t happen very often. A solution I’ve found is to not move from one project to the next until I’ve written about the one I just finished (getting it to a good-enough point counts as finished).&lt;/p&gt;
&lt;p&gt;When I made &lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;valet&lt;/a&gt;, I ended up writing four different posts about that project—only because I didn’t allow myself to start the next one before finishing all the writing I had related to valet.&lt;/p&gt;
&lt;p&gt;This approach can also help ensure our blogs don’t become the kind where the only posts are about setting up the blog/platform and upgrading it. The rule here: write and publish an article before you’re allowed to add any new feature to the site. Want to add a &amp;quot;now&amp;quot; page? Then first write a post about “your thoughts on comments in blogs” (or anything you want to write about) before adding that page.&lt;/p&gt;
&lt;p&gt;I read about this concept on someone’s blog, but I can’t remember whose. I’ll update with the link if I find it.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="miscellaneous"/>
      
      <summary type="html">How to ensure you balance your time between building stuff and writing about it</summary>
    </entry>
  
    
    <entry>
      <title type="html">🧳 Goa Trip 2025</title>
      <link href="https://varunbarad.com/blog/trip-goa.html" rel="alternate" type="text/html" title="🧳 Goa Trip 2025"/>
      <published>2025-08-11T08:47:04+05:30</published>
      <updated>2025-08-11T08:47:04+05:30</updated>
      <id>https://varunbarad.com/blog/trip-goa.html</id>
      <content type="html">
      &lt;p&gt;When my wife and I were deciding to go on a short trip, after many different considerations we landed on a popular Indian holiday destination: Goa. Goa is famous for two things – cheap alcohol and the sea beaches. Since neither of us drink, and the month we decided to go in sees very rough seas (see what I did there?), we had to decide on some non-obvious ways to make the trip fun. Here&#39;s what we ended up doing:&lt;/p&gt;
&lt;h2&gt;Nature trail through Chorão Island&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Chor%C3%A3o_(island)&quot;&gt;Chorão&lt;/a&gt; is the largest island in Goa and can be reached by taking a ferry from Ribandar. We covered these activities/spots on that trail:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A boat ride on the Mandovi River through the mangroves&lt;/li&gt;
&lt;li&gt;Visit to the world&#39;s first (and one of only two) &lt;a href=&quot;https://en.wikipedia.org/wiki/Devaki#:~:text=Devaki%20Krishna%20Sansthan%20temple&quot;&gt;Devaki-Krishna temple&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Visit to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Chapel_of_St._Jerome_(Chor%C3%A3o_Island)&quot;&gt;Chapel of St. Jerome&lt;/a&gt;, one of the rare circular chapels&lt;/li&gt;
&lt;li&gt;We had our breakfast in the middle of a paddy field at &lt;a href=&quot;https://maps.app.goo.gl/HopawHquy1yzkQqb8&quot;&gt;Chudamani Baug&lt;/a&gt; (one of my finest breakfast experiences)&lt;/li&gt;
&lt;li&gt;Learned how to make a quite good &lt;a href=&quot;https://en.wikipedia.org/wiki/Garcinia_indica&quot;&gt;Kokam&lt;/a&gt; sharbat&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Divar Island exploration&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Divar&quot;&gt;Divar&lt;/a&gt; is the second-largest island in Goa and can be reached similarly to Chorão, via a ferry from Ribandar.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Another boat ride through a different part of the river. This gave us a real close-up look at some of the crocodiles that populate these waters&lt;/li&gt;
&lt;li&gt;Visited a church and a couple of temples&lt;/li&gt;
&lt;li&gt;Saw the ruins of a temple&#39;s well — the actual temple hasn&#39;t been found yet&lt;/li&gt;
&lt;li&gt;Had some awesome evening snacks at a local place, which introduced me to my new favorite bread-type called the &amp;quot;Goan bun&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Heritage Goa tour&lt;/h2&gt;
&lt;p&gt;This one covered the mainland and took us through the history of Goa.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A visit to &lt;a href=&quot;https://maps.app.goo.gl/Hee3aUk9ffWJoJFt7&quot;&gt;&amp;quot;Big Foot&amp;quot;&lt;/a&gt; walked us through what lifestyle and culture used to be like in Goa before modern times&lt;/li&gt;
&lt;li&gt;And the nearby &lt;a href=&quot;https://maps.app.goo.gl/Kzhp2p8Mtxw5e5ydA&quot;&gt;&amp;quot;Casa Araujo Alvares&amp;quot;&lt;/a&gt; gave us a glimpse of how a well-off Portuguese lawyer used to live back in the colonisation days&lt;/li&gt;
&lt;li&gt;My favorite part of this trip was our visit to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Naval_Aviation_Museum_(Goa)&quot;&gt;&amp;quot;Naval Aviation Museum&amp;quot;&lt;/a&gt;, where there are a bunch of decommissioned real aircraft (both planes and helicopters) on display. It also walks us through the history of the Indian Navy (more specifically, the part of it that rules the sky)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For now, that’s the snapshot of our Goa trip. I might revisit these stories and expand on them in the future, but this feels like the perfect place to pause.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="travel"/>
      
      <summary type="html">A short trip to a beach city/state that I took with my wife</summary>
    </entry>
  
    
    <entry>
      <title type="html">👨‍🍳 Cardamom Tea 🫖</title>
      <link href="https://varunbarad.com/blog/recipe-cardamom-tea.html" rel="alternate" type="text/html" title="👨‍🍳 Cardamom Tea 🫖"/>
      <published>2025-08-08T22:38:24+05:30</published>
      <updated>2025-08-08T22:38:24+05:30</updated>
      <id>https://varunbarad.com/blog/recipe-cardamom-tea.html</id>
      <content type="html">
      &lt;h2&gt;The recipe&lt;/h2&gt;
&lt;p&gt;The below measurements make ~3 cups of tea.&lt;/p&gt;
&lt;h3&gt;Ingredients&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Water&lt;/li&gt;
&lt;li&gt;Milk (full cream)&lt;/li&gt;
&lt;li&gt;Tea&lt;/li&gt;
&lt;li&gt;Sugar&lt;/li&gt;
&lt;li&gt;3 whole cardamom pods&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Preparation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Open the cardamom pods and separate their husks&lt;/li&gt;
&lt;li&gt;Take the black seeds inside and roughly crush them together with your hands&lt;/li&gt;
&lt;li&gt;Take 1 cup water and put it on a medium-slow flame&lt;/li&gt;
&lt;li&gt;Add the crushed cardamom seeds and husks to the water and let them steep for a minute or two&lt;/li&gt;
&lt;li&gt;Add 3 tablespoons of tea dust/leaves to the hot concoction&lt;/li&gt;
&lt;li&gt;Turn the flame slow and let the tea steep for a minute&lt;/li&gt;
&lt;li&gt;Add 2.5 cups of milk and turn the flame to medium&lt;/li&gt;
&lt;li&gt;After a minute add 2.5 teaspoons of sugar&lt;/li&gt;
&lt;li&gt;Once the liquid starts to boil, turn the flame to medium-slow and bring it to 3 full rolling boils&lt;/li&gt;
&lt;li&gt;After that, turn off the gas and cover it for 5-7 minutes&lt;/li&gt;
&lt;li&gt;Then strain and serve&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The story&lt;/h2&gt;
&lt;p&gt;Although I was never a tea person to begin with, my marriage changed that, as my wife is an avid tea enjoyer. Over time, I learned to make some decent tea. Cardamom tea is one of the ones I sometimes find to my liking.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="recipe"/>
      
      <category term="cooking"/>
      
      <summary type="html">Making cardamom tea the way I like it</summary>
    </entry>
  
    
    <entry>
      <title type="html">📇 Naming my devices</title>
      <link href="https://varunbarad.com/blog/naming-devices.html" rel="alternate" type="text/html" title="📇 Naming my devices"/>
      <published>2025-08-07T23:14:59+05:30</published>
      <updated>2025-08-07T23:14:59+05:30</updated>
      <id>https://varunbarad.com/blog/naming-devices.html</id>
      <content type="html">
      &lt;p&gt;Every time since my childhood when setting up a new device, it asked me to give the device a name. The most common instance so far has been setting up my computer, and I would end up naming it something like &amp;quot;Varun Computer&amp;quot;, &amp;quot;Home Computer&amp;quot;, or something along those lines.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.lifewire.com/how-to-clean-install-windows-8-or-8-1-2626254#:~:text=Pick%20a%20Color%20Theme%20%26%20Name%20Your%20PC&quot;&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/naming-devices/windows-setup.webp&quot; alt=&quot;Windows Setup screen asking to give the computer a name&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is only in the past few years, after I read a post by someone on how they decide names for their devices, that the thought even occurred to me that those names for my devices don&#39;t have to be so dry and meaningless. That I can treat naming my devices with some thought put into it, and name them based on some theme or the purpose that they will be serving.&lt;/p&gt;
&lt;p&gt;Since then, the theme I have started with my devices is &amp;quot;celestial bodies/objects&amp;quot;. I try to name my devices based on some constellation. Here are some of the names I have assigned since then:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;orion&lt;/strong&gt;, as it was the first constellation I had learned to identify in the night sky&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;andromeda&lt;/strong&gt;, as it is the nearest major galaxy to our own &amp;quot;Milky Way&amp;quot;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;phoenix&lt;/strong&gt;, as that computer had completely crashed itself, but when fixing the hardware issue, the service center gave me a significant RAM upgrade as they didn&#39;t have the exact matching components&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;delphinus&lt;/strong&gt; was given to my NAS, as it is the constellation containing dolphins, and when naming it I remembered that dolphins have good memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;scribe&lt;/strong&gt;: this is an exception, as it is both a project and a device. This is basically the name I am giving to a Raspberry Pi which is used to convert an old printer into a network-attached printer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;aarohan&lt;/strong&gt; was named before deciding on the theme, but it still had some thought put into it because that word in Hindi means &amp;quot;to ascend&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Other people who have written on naming their devices&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://hamatti.org/posts/naming-devices-is-fun/&quot;&gt;Juha-Matti Santala&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://rknight.me/blog/naming-my-computers/&quot;&gt;Robb Knight&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="miscellaneous"/>
      
      <summary type="html">How I have started to decide on names for my devices</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎮 Games through the ages</title>
      <link href="https://varunbarad.com/blog/games-through-the-ages.html" rel="alternate" type="text/html" title="🎮 Games through the ages"/>
      <published>2025-08-03T00:24:04+05:30</published>
      <updated>2025-08-03T00:24:04+05:30</updated>
      <id>https://varunbarad.com/blog/games-through-the-ages.html</id>
      <content type="html">
      &lt;p&gt;Video games have been a big part of my interaction with computers since childhood. For quite some time, I’ve wanted to write about some games that I enjoyed the most in their genre. So when planning for Blaugust, I thought that now would be the best time to post it. Here are some games that have left their mark on me over the years (arranged in the order I remember playing them):&lt;/p&gt;
&lt;h2&gt;Prince of Persia: Warrior Within&lt;/h2&gt;
&lt;img alt=&quot;Poster for Prince of Persia: Warrior Within&quot; src=&quot;https://varunbarad.com/assets/images/posts/games-through-the-ages/game-pop-ww.jpg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;This one is a nostalgia pick, as it was the first long-form game that I played (probably during my teenage years). It was also the first game for me that had alternate endings based on the actions you take. It had some very cool things going for it, like parkour mechanics, puzzle-solving, and time-control powers. But the best part was the scenes where one of the most terrifying villains, the Dahaka, chases after you.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://store.steampowered.com/app/13500/Prince_of_Persia_Warrior_Within/&quot;&gt;Steam page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Call of Duty 4: Modern Warfare&lt;/h2&gt;
&lt;img alt=&quot;Poster for Call of Duty 4: Modern Warfare&quot; src=&quot;https://varunbarad.com/assets/images/posts/games-through-the-ages/game-cod-mw.jpg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;I cannot make a list of my recommended games and not have any FPS (First-Person Shooter) games in there. While this was by no means the first game I played in the category, it was the first I found I liked way too much. This game ticked a lot of boxes: abundant machine guns, guns with suppressors, snipers, grenades that you can throw back, stealth missions, and a banger soundtrack. While I don&#39;t remember the name of it, the mission that takes place in Pripyat still remains etched in my mind.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://store.steampowered.com/app/7940/Call_of_Duty_4_Modern_Warfare_2007/&quot;&gt;Steam page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Horizon Zero Dawn&lt;/h2&gt;
&lt;img alt=&quot;Poster for Horizon Zero Dawn&quot; src=&quot;https://varunbarad.com/assets/images/posts/games-through-the-ages/game-hzd.jpg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; You get to fight (and sometimes use) mecha-dinosaurs in some very pretty world environments.&lt;/p&gt;
&lt;p&gt;I would say that even if for nothing else, play this game for its storyline. This one has the best story of any game I&#39;ve ever played. After Skyrim, this was the first game I played where you start going from Point A to Point B, but you encounter side-quest(s) in between, and even hours later you might not have reached Point B. And the even better part is that those side-quests aren&#39;t repetitive.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Side note:&lt;/strong&gt; If you find the side-mission inside a quarry to be too difficult, there is a way to cheese it by remaining outside the quarry.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Minor spoiler:&lt;/strong&gt; Look up the guides online for &amp;quot;Shield Weaver&amp;quot; – it’s too good to miss out on.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://store.steampowered.com/app/1151640/Horizon_Zero_Dawn_Complete_Edition/&quot;&gt;Steam page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;It Takes Two&lt;/h2&gt;
&lt;img alt=&quot;Poster for It Takes Two&quot; src=&quot;https://varunbarad.com/assets/images/posts/games-through-the-ages/game-it2.jpg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;This was the first game I ever saw where you have to have two players to play it. I am currently playing this with my wife, and these are some of the most creative graphics/visualizations that I have seen in a game. This game has an okayish storyline, but it is hidden by the wonderful environmental settings and writing (yes, the overall story is okay, but the writing in each section is fantastic). This game is a solid recommendation to play with a partner/sibling/roommate/parent (basically anyone you spend a good chunk of your time with).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://store.steampowered.com/app/1426210/It_Takes_Two/&quot;&gt;Steam page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Satisfactory&lt;/h2&gt;
&lt;img alt=&quot;Poster for Satisfactory&quot; src=&quot;https://varunbarad.com/assets/images/posts/games-through-the-ages/game-satisfactory.jpg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;p&gt;This game has somehow mastered the dopamine drip loop. If you have an engineering/systems mind, you should definitely give this a go. The premise is that you land on an alien planet and have to use the resources there to craft and ship a bunch of parts to the space station in orbit. The automation comes as a natural derivation from it. I haven&#39;t completed it yet, but I am very excited to start my rail network and ride the trains all around.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://store.steampowered.com/app/526870/Satisfactory/&quot;&gt;Steam page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Bonus entry?&lt;/h2&gt;
&lt;p&gt;There was originally going to be a bonus entry of one game, but as I was writing about each game, more and more fantastic titles came to mind. So I think I’ll publish a separate piece for them sometime in the future, probably.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <category term="video-games"/>
      
      <summary type="html">5 video games that captured me through the years</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Link to a specific piece of text on a webpage</title>
      <link href="https://varunbarad.com/blog/til-link-text-on-webpage.html" rel="alternate" type="text/html" title="📝 Link to a specific piece of text on a webpage"/>
      <published>2025-08-02T16:18:43+05:30</published>
      <updated>2025-08-02T16:18:43+05:30</updated>
      <id>https://varunbarad.com/blog/til-link-text-on-webpage.html</id>
      <content type="html">
      &lt;p&gt;Let&#39;s say you needed to link to the &amp;quot;Rainbow Badge&amp;quot; section on &lt;a href=&quot;https://nerdgirlthoughts.game.blog/2025/07/10/blaugust-2025-is-coming/&quot;&gt;this page&lt;/a&gt;, it is not an element with an &lt;code&gt;id&lt;/code&gt; set so that you can directly append a &lt;code&gt;&amp;lt;page-url&amp;gt;#element_id&lt;/code&gt; and call it a day.&lt;/p&gt;
&lt;p&gt;Recently browsers have also started supporting linking directly to any text of your choice on any given page. That concept is called &amp;quot;Text Fragments&amp;quot; (&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment/Text_fragments&quot;&gt;link to MDN docs&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The basic structure of your URL needs to be like below:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;lt;your-page-url&amp;gt;#:~:text=&amp;lt;your-target-text-url-encoded&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So for my above example I would have to use a link that looks something like this:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;https://nerdgirlthoughts.game.blog/2025/07/10/blaugust-2025-is-coming/#:~:text=Rainbow%20Diamond%20Award&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">TIL: How to link to a specific piece of text on a webpage</summary>
    </entry>
  
    
    <entry>
      <title type="html">📜 Blaugust 2025</title>
      <link href="https://varunbarad.com/blog/blaugust-2025.html" rel="alternate" type="text/html" title="📜 Blaugust 2025"/>
      <published>2025-08-01T07:44:51+05:30</published>
      <updated>2025-08-01T07:44:51+05:30</updated>
      <id>https://varunbarad.com/blog/blaugust-2025.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/blaugust-2025/blaugust2025-banner.webp&quot; alt=&quot;Blaugust 2025 banner&quot; /&gt;&lt;/p&gt;
&lt;p&gt;What is Blaugust? In my words, it is the annual month-long celebration of independent blogging and writing. If you want to read the words of the organizer, then I would guide you to the &lt;a href=&quot;https://nerdgirlthoughts.game.blog/2025/07/10/blaugust-2025-is-coming/&quot;&gt;official announcement post&lt;/a&gt;, which also contains the link to the sign-up sheet.&lt;/p&gt;
&lt;p&gt;Every year, people try to write &amp;amp; publish as much as they can for one whole month. I originally read about it in one of &lt;a href=&quot;https://hamatti.org/posts/blaugust-2024-batteries-included/&quot;&gt;Juhis&#39; 2024 post&lt;/a&gt;. This year, when he &lt;a href=&quot;https://hamatti.org/posts/blaugust-2025-starts-august-1st/&quot;&gt;posted&lt;/a&gt; that Blaugust 2025 has been announced, I decided to join too.&lt;/p&gt;
&lt;p&gt;This is my first time participating, but I have set my sights quite high and am targeting the &lt;a href=&quot;https://nerdgirlthoughts.game.blog/2025/07/10/blaugust-2025-is-coming/#:~:text=Rainbow%20Diamond%20Award&quot;&gt;🌈 Rainbow Badge&lt;/a&gt;. I already have too many ideas of things I want to write about &lt;s&gt;and update&lt;/s&gt; (no Varun, focus on writing) on this site. Let&#39;s see how close we reach to our target.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="blaugust-2025"/>
      
      <summary type="html">TLDR: Blaugust is a month-long blogging bonanza</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Mount an SMB share on Mac OS using Rust</title>
      <link href="https://varunbarad.com/blog/til-macos_mount_remote_smb_share.html" rel="alternate" type="text/html" title="📝 Mount an SMB share on Mac OS using Rust"/>
      <published>2025-06-15T08:16:58+05:30</published>
      <updated>2025-06-15T08:16:58+05:30</updated>
      <id>https://varunbarad.com/blog/til-macos_mount_remote_smb_share.html</id>
      <content type="html">
      &lt;p&gt;Just as before, while working on my last project (&lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;valet&lt;/a&gt;) I learned something new. I wanted to mount a remote SMB share from my NAS onto my laptop as that shared storage is where I eventually want to store all my files once they are cleaned-up and sorted appropriately. I know how to do that using Finder but this time I needed to do it from inside a program.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Aside: I think I should stop writing this under a TIL because at the time I am writing this, it has been more than 3 weeks since I learned how to do this.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;The AppleScript way&lt;/h3&gt;
&lt;p&gt;Previously I have mounted the same share using AppleScript. The share URL follows this pattern &lt;code&gt;smb://&amp;lt;username-on-server&amp;gt;@&amp;lt;name-of-server&amp;gt;/&amp;lt;name-of-shared-folder&amp;gt;&lt;/code&gt;, and the whole command goes something like this:&lt;/p&gt;
&lt;pre class=&quot;language-applescript&quot;&gt;&lt;code class=&quot;language-applescript&quot;&gt;mount volume &lt;span class=&quot;token string&quot;&gt;&quot;smb://varun@ella/Legal Documents&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This would automatically use the stored password from my Keychain. But the problem here was that I needed to run it from inside a rust program which does not directly run apple-script but can run shell-scripts. To execute the above as a shell-script I need to pass it to the &lt;code&gt;osascript&lt;/code&gt; program like this:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;osascript &lt;span class=&quot;token parameter variable&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;mount volume &quot;smb://varun@ella/Legal Documents&quot;&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Aside: As I am writing this next section, it comes to my mind that I could have made it work with just this setup and that would have simplified my work a lot. I then would not have had to figure out how to access the Keychain or how to properly escape these paths. But alas, that is the life of a programmer 😅&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here, to ensure that the full directory name &amp;quot;Legal Documents&amp;quot; is parsed correctly, we had to put the complete share URL inside double-quotes. And then to ensure the complete apple-script is parsed correctly, we had to put that inside another pair of single-quotes.&lt;/p&gt;
&lt;h3&gt;The shell-script way&lt;/h3&gt;
&lt;p&gt;The underlying program to use in a shell-script would be &lt;code&gt;mount_smbfs&lt;/code&gt; which takes two arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Complete URL of the remote-share which is built of below four parts and formatted like this &lt;code&gt;//u:p@s/f&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;u&lt;/code&gt;: Username on server&lt;/li&gt;
&lt;li&gt;&lt;code&gt;p&lt;/code&gt;: Password of the above username on server&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt;: Name/Network-address of the server&lt;/li&gt;
&lt;li&gt;&lt;code&gt;f&lt;/code&gt;: URL-escaped name of the shared folder&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Directory (ensure it is empty) on your local machine where to mount the share&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The invocation for that goes like:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;mount_smbfs &lt;span class=&quot;token string&quot;&gt;&quot;//varun:some-password@ella/Legal%20Documents&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/Volumes/Legal Documents&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we get control over where the shared folder gets mounted locally, but now we have to supply the password ourselves (here&#39;s how to &lt;a href=&quot;https://varunbarad.com/blog/til-read-smb-share-password-from-macos-keychain&quot;&gt;get it from Keychain&lt;/a&gt;).&lt;/p&gt;
&lt;h3&gt;Using the &lt;code&gt;mount_smbfs&lt;/code&gt; command from Rust&lt;/h3&gt;
&lt;p&gt;Now we can use &lt;code&gt;Command&lt;/code&gt; from rust&#39;s standard-library to call &lt;code&gt;mount_smbfs&lt;/code&gt; and mount the share. For that we need to ensure that all the components are appropriately escaped to form a proper URL. To do that we use the &lt;a href=&quot;https://crates.io/crates/url&quot;&gt;&lt;code&gt;url&lt;/code&gt; crate&lt;/a&gt;. Here&#39;s how we do that:&lt;/p&gt;
&lt;pre class=&quot;language-rust&quot;&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;token function-definition function&quot;&gt;get_storage_mount_path_remote&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    username&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    password&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    server_name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    shared_folder_name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; encoded_password &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;form_urlencoded&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;byte_serialize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;password&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;as_bytes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;collect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; actual_url &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token macro property&quot;&gt;format!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;//{}:{}@{}/{}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; username&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; encoded_password&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; server_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; shared_folder_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; prefixed_url &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token macro property&quot;&gt;format!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https:{}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; actual_url&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; parsed_url &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prefixed_url&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;as_str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; parsed_url
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;to_string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;strip_prefix&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https:&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;to_string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First encode the password using &lt;a href=&quot;https://crates.io/crates/form_urlencoded&quot;&gt;&lt;code&gt;form_urlencoded&lt;/code&gt; crate&lt;/a&gt; (a dependency of the &lt;code&gt;url&lt;/code&gt; crate) to ensure proper escaping of it&lt;/li&gt;
&lt;li&gt;Form the whole URL and prefix it with a protocol (any protocol should work) at the beginning, we use &lt;code&gt;https&lt;/code&gt; here. This is because the &lt;code&gt;Url::parse&lt;/code&gt; method expects a complete URL and a complete URL needs to have a protocol&lt;/li&gt;
&lt;li&gt;Convert the &lt;code&gt;Url&lt;/code&gt; object to its string representation and strip the protocol prefix from it&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;And using that cleaned-up URL we can then go and invoke the &lt;code&gt;mount_smbfs&lt;/code&gt; command like this:&lt;/p&gt;
&lt;pre class=&quot;language-rust&quot;&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Ensure there is a directory created where we want to mount the SMB share&lt;/span&gt;
&lt;span class=&quot;token namespace&quot;&gt;std&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;fs&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create_dir_all&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;storage_mount_path_local&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;Command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;mount_smbfs&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;storage_mount_path_remote&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;as_str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;storage_mount_path_local&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;as_str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Articles related to project valet&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;Project valet announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-read-smb-share-password-from-macos-keychain&quot;&gt;Read SMB share password from MacOS Keychain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-rust-build-time-env-vars&quot;&gt;Rust read build-time environment variables at run-time&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mount an SMB share on Mac OS using Rust (this article)&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to mount an SMB share on Mac OS programmatically using Rust</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Rust read build-time environment variables at run-time</title>
      <link href="https://varunbarad.com/blog/til-rust-build-time-env-vars.html" rel="alternate" type="text/html" title="📝 Rust read build-time environment variables at run-time"/>
      <published>2025-06-08T19:24:15+05:30</published>
      <updated>2025-06-08T19:24:15+05:30</updated>
      <id>https://varunbarad.com/blog/til-rust-build-time-env-vars.html</id>
      <content type="html">
      &lt;p&gt;When building &lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;valet&lt;/a&gt; I required a couple pieces of configuration values but didn&#39;t want to read them from a file and didn&#39;t want them to be forever present in my environment variables so that I can read from there on runtime. Neither did I want to put them in code anywhere, so I looked for if there was a way where I read a value from somewhere (environment variable in this case) at compile-time and then use that value during run-time without needing to have that source available at run-time.&lt;/p&gt;
&lt;p&gt;That&#39;s where I first encountered how to configure your build process using &lt;code&gt;build.rs&lt;/code&gt;. So let&#39;s take this example that you need to read &lt;code&gt;VALET_CONFIG_SOMETHING&lt;/code&gt; environment variable at build-time and then have its value available at run-time you need to put this in your &lt;code&gt;build.rs&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-rust&quot;&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;token function-definition function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; compile_time_config &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;std&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;VALET_CONFIG_SOMETHING&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Please provide config&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token macro property&quot;&gt;println!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;cargo:rustc-env=CONFIG_SOMETHING={}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; compile_time_config&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Rebuild when these change&lt;/span&gt;
    &lt;span class=&quot;token macro property&quot;&gt;println!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;cargo:rerun-if-changed=build.rs&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token macro property&quot;&gt;println!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;cargo:rerun-if-env-changed=VALET_CONFIG_SOMETHING&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then to use it in your program you need to do something like this:&lt;/p&gt;
&lt;pre class=&quot;language-rust&quot;&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;token function-definition function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token macro property&quot;&gt;println!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Config found at run-time: {}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token macro property&quot;&gt;env!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;CONFIG_SOMETHING&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To ensure cargo uses your build-script, you need to add this line to your &lt;code&gt;Cargo.toml&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-toml&quot;&gt;&lt;code class=&quot;language-toml&quot;&gt;&lt;span class=&quot;token key property&quot;&gt;build&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;build.rs&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then you need to ensure that the variable is available at build-time:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;$ &lt;span class=&quot;token assign-left variable&quot;&gt;VALET_CONFIG_SOMETHING&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;A value for config&quot;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;cargo&lt;/span&gt; build
Finished &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;`&lt;/span&gt;dev&lt;span class=&quot;token variable&quot;&gt;`&lt;/span&gt;&lt;/span&gt; profile &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;unoptimized + debuginfo&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; target&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;s&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;.00s&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then check that the value is available later at run-time:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;$ ./target/debug/valet
Config found at run-time: A value &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; config&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Articles related to project valet&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;Project valet announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-read-smb-share-password-from-macos-keychain&quot;&gt;Read SMB share password from MacOS Keychain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Rust read build-time environment variables at run-time (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-macos_mount_remote_smb_share&quot;&gt;Mount an SMB share on Mac OS using Rust&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to read in a rust program at run-time the environment variables that were only defined at build-time</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Read SMB share password from MacOS Keychain</title>
      <link href="https://varunbarad.com/blog/til-read-smb-share-password-from-macos-keychain.html" rel="alternate" type="text/html" title="📝 Read SMB share password from MacOS Keychain"/>
      <published>2025-06-08T07:37:59+05:30</published>
      <updated>2025-06-08T07:37:59+05:30</updated>
      <id>https://varunbarad.com/blog/til-read-smb-share-password-from-macos-keychain.html</id>
      <content type="html">
      &lt;p&gt;When building &lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;valet&lt;/a&gt; I needed to provide the password for my account on the SMB share hosted on my NAS. I did not want to input it every-time I run valet, but neither did I want to bake it in either the source code or in any build-time variable as then I have to recompile from source every time my password changes.&lt;/p&gt;
&lt;p&gt;Since I already had it stored in my laptop&#39;s Keychain Access as it is used when I want to mount the share using Finder, I decided to try and read from there. All the online places mention how to retrieve either a record for a website account or retrieve a generic account. But none mentions an SMB share specifically.&lt;/p&gt;
&lt;p&gt;Here&#39;s a sample entry stored in Keychain Access for an SMB share:&lt;/p&gt;
&lt;img alt=&quot;A record showing stored SMB credentials in Keychain Access&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-access-macos-keychain-programmatically/entry-in-keychain-access.png&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;h2&gt;Accessing from shell/terminal&lt;/h2&gt;
&lt;p&gt;And here&#39;s the way to retrieve the password from terminal:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;security find-internet-password &lt;span class=&quot;token parameter variable&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;varun&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-s&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;ella&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-g&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-w&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/Users/varun/Library/Keychains/login.keychain-db&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&#39;s what each option means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-a&lt;/code&gt;: Corresponds to the username&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-s&lt;/code&gt;: Corresponds to the server. In case of SMB share we don&#39;t have to enter the full-path (&lt;code&gt;smb://ella&lt;/code&gt;) but only its name&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-g&lt;/code&gt;: Display the password for the item found&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-w&lt;/code&gt;: Display only the password and not the whole record&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Accessing from Rust&lt;/h2&gt;
&lt;p&gt;There is a nice crate in rust called &lt;a href=&quot;https://crates.io/crates/security-framework&quot;&gt;&lt;code&gt;security-framework&lt;/code&gt;&lt;/a&gt; which handles things for us. Here&#39;s a snippet of how to get the password in a string in rust:&lt;/p&gt;
&lt;pre class=&quot;language-rust&quot;&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;fn&lt;/span&gt; &lt;span class=&quot;token function-definition function&quot;&gt;get_network_share_password&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;std&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;io&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; keychain &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;SecKeychain&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/Users/varun/Library/Keychains/login.keychain-db&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;password&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;find_internet_password&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;Some&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;keychain&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&quot;ella&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&quot;varun&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;SecProtocolType&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;SMB&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;SecAuthenticationType&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Ok&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;from_utf8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;password&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;to_vec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unwrap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Articles related to project valet&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/project-valet&quot;&gt;Project valet announcement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Read SMB share password from MacOS Keychain (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-rust-build-time-env-vars&quot;&gt;Rust read build-time environment variables at run-time&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-macos_mount_remote_smb_share&quot;&gt;Mount an SMB share on Mac OS using Rust&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to access entries from MacOS Keychain programmatically, specifically an SMB share&#39;s record</summary>
    </entry>
  
    
    <entry>
      <title type="html">Fixing the torch 🔦</title>
      <link href="https://varunbarad.com/blog/fixing-the-torch.html" rel="alternate" type="text/html" title="Fixing the torch 🔦"/>
      <published>2025-05-25T10:28:58+05:30</published>
      <updated>2025-05-25T10:28:58+05:30</updated>
      <id>https://varunbarad.com/blog/fixing-the-torch.html</id>
      <content type="html">
      &lt;p&gt;I DID IT.&lt;/p&gt;
&lt;p&gt;I fixed a torch that was in a broken state for quite a few weeks now. The fix was not something complicated. I ended up disassembling it too much for what the original fix was (it turned out helpful though for another fix for another broken thing I found in the torch), and that made the reassembly a bit difficult. But it doesn&#39;t matter as much. What matters is that I did it. I finally disassembled it, found the problem and fixed it.&lt;/p&gt;
&lt;p&gt;I have been wanting to get into hardware based projects for some years now and have never managed to break the barrier of entry. Always finding some excuse or other to justify it to myself. But yesterday was spent focusing on this torch and the barrier is down now.&lt;/p&gt;
&lt;p&gt;Here&#39;s that torch in all its glory.&lt;/p&gt;
&lt;img alt=&quot;The fixed torch standing on a desk&quot; src=&quot;https://varunbarad.com/assets/images/posts/fixing-the-torch/the-torch.jpg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="repair"/>
      
      <category term="personal-growth"/>
      
      <summary type="html">I fixed a torch and that has made me extremely elated</summary>
    </entry>
  
    
    <entry>
      <title type="html">🗃️ My valet parks my files for me</title>
      <link href="https://varunbarad.com/blog/project-valet.html" rel="alternate" type="text/html" title="🗃️ My valet parks my files for me"/>
      <published>2025-05-04T11:59:13+05:30</published>
      <updated>2025-05-04T11:59:13+05:30</updated>
      <id>https://varunbarad.com/blog/project-valet.html</id>
      <content type="html">
      &lt;p&gt;I was increasingly getting annoyed by having to handle various filing tasks and was looking for a way to automate it. The two most regular and straight-forward ones to handle were my credit-card statements as they came monthly and had a bunch of steps (listed below) that needed to be followed for each one:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download the statement PDF from email&lt;/li&gt;
&lt;li&gt;Decrypt it using the appropriate password&lt;/li&gt;
&lt;li&gt;Save the decrypted version so that I don&#39;t have to fuss with that password in the future&lt;/li&gt;
&lt;li&gt;Rename the file to reflect statement date&lt;/li&gt;
&lt;li&gt;Connect to my NAS and locate/create the appropriate folder for that statement&lt;/li&gt;
&lt;li&gt;Copy the statement to NAS directory&lt;/li&gt;
&lt;li&gt;Delete the files from my local machine&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since this was a long process it regularly got pushed back and when once automated had a high-probability of both reducing my cognitive/time burden as well as chances of human-errors in the process.&lt;/p&gt;
&lt;p&gt;And thus emerged &lt;a href=&quot;https://github.com/VarunBarad/valet&quot;&gt;valet&lt;/a&gt;. Before writing the program I had managed to do a lot of the above tasks using individual commands rather than using any graphical interface, this way I was inching myself toward automating it.&lt;/p&gt;
&lt;p&gt;When I first started storing decrypted statements I used to use Mac&#39;s Preview utility to open the encrypted PDF file and then print from it to another PDF file thus removing the password encryption from the new PDF. I eventually moved to using the nifty little program called &lt;code&gt;qpdf&lt;/code&gt; to remove this encryption.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;qpdf &lt;span class=&quot;token parameter variable&quot;&gt;--decrypt&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--password&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;your password here&quot;&lt;/span&gt; /path/to/encrypted.pdf /path/to/store/decrypted.pdf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To mount my NAS to my local machine I needed to open it in Finder which would in-turn mount it and thus I would be able to transfer files to/from it. I learnt of an applescript command &lt;code&gt;mount volume&lt;/code&gt; which can be used to mount SMB shares which can then be used for file-transfer. Eventually in &lt;code&gt;valet&lt;/code&gt; I had to use a different (non-applescript) command &lt;code&gt;mount_smbfs&lt;/code&gt; to achieve the same thing.&lt;/p&gt;
&lt;pre class=&quot;language-applescript&quot;&gt;&lt;code class=&quot;language-applescript&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# The applescript way&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; run argv
	&lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt;
		mount volume &lt;span class=&quot;token string&quot;&gt;&quot;smb://varun@delphinus/Legal Documents&quot;&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;error&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;false&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt; run&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# The normal shell way&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# Ensure the directory `/Volumes/Legal Documents` exists and is empty&lt;/span&gt;
mount_smbfs &lt;span class=&quot;token string&quot;&gt;&quot;//varun@delphinus/Legal%20Documents&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/Volumes/Legal Documents&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I had atleast two things which I had not foreseen that I would end up learning:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Accessing password(s) from Mac&#39;s Keychain Access programmatically. I ended up learning both how to do it from terminal and from within a rust program.&lt;/li&gt;
&lt;li&gt;Using a custom build-script to access variables in my rust program at run-time whose values were passed as environment variables at compile-time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would write about both of those in coming days.&lt;/p&gt;
&lt;p&gt;Some other things which I sort of expected to learn and actually ended up learning were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to run shell commands from within a rust program&lt;/li&gt;
&lt;li&gt;Encoding both parts for a URL and the complete URL to ensure no non-permitted character messes up the mounting URL for SMB share&lt;/li&gt;
&lt;li&gt;Finding files in rust from a directory based on the filename matching a regex&lt;/li&gt;
&lt;li&gt;Date-time parsing/handling in rust&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The current version of valet only handles a couple of my credit card statements but already some other things are coming to my mind which I can slowly take on and move to automate with valet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The bills that I create for my consulting clients&lt;/li&gt;
&lt;li&gt;Some of the bills that I receive (for example from my ISP)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Articles related to project valet&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Project valet announcement (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-read-smb-share-password-from-macos-keychain&quot;&gt;Read SMB share password from MacOS Keychain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-rust-build-time-env-vars&quot;&gt;Rust read build-time environment variables at run-time&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/til-macos_mount_remote_smb_share&quot;&gt;Mount an SMB share on Mac OS using Rust&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="valet"/>
      
      <category term="rust"/>
      
      <category term="tools"/>
      
      <category term="programming"/>
      
      <category term="project"/>
      
      <summary type="html">I finally stitched-together a valet to process and park various files from my inbox to their respective destinations</summary>
    </entry>
  
    
    <entry>
      <title type="html">Installing my first monitor arm</title>
      <link href="https://varunbarad.com/blog/first-monitor-arm.html" rel="alternate" type="text/html" title="Installing my first monitor arm"/>
      <published>2025-03-30T23:12:26+05:30</published>
      <updated>2025-03-30T23:12:26+05:30</updated>
      <id>https://varunbarad.com/blog/first-monitor-arm.html</id>
      <content type="html">
      &lt;p&gt;I don&#39;t know how I have not written any post in this year so far but here comes the auspicious beginning of the year.&lt;/p&gt;
&lt;p&gt;I have always used my monitor/display on its company provided stand. Today was the first time in my life that I installed my monitor on an adjustable arm and it has done wonders in clearing space on my desk.&lt;/p&gt;
&lt;p&gt;I have a 27 inch monitor and its stand was taking up a lot of space on my desk and I was not able to push my keyboard in as much as I actually wanted to.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/first-monitor-arm/desk_before.jpg&quot; alt=&quot;Desk before&quot; /&gt;&lt;/p&gt;
&lt;p&gt;As you can see in the photo above my dad even had built a wooden stand for the monitor so as both to raise it a bit and so that I get some more space to push my keyboard in. But it was not enough.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/first-monitor-arm/desk_after.jpg&quot; alt=&quot;Desk after&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now with the arm I can reclaim much more of the depth and real-estate of my desk. This has both increased the available space on my table and also improved the usability.&lt;/p&gt;
&lt;p&gt;The desk is from &lt;a href=&quot;https://www.ergoyou.in/&quot;&gt;ErgoYou&lt;/a&gt; and I have been using it for more than 4 years now. Their product quality is top notch so I decided to go with the same vendor for the monitor arm as well. They had a few options at the time and I decided to go with the &lt;a href=&quot;https://www.ergoyou.in/products/adjustable-spring-monitor-stand-single-screen-clamp-grommet-mount-g3-series&quot;&gt;single-screen G3 series one&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I know the Playstation is no longer on the table in second photo. I would make the appropriate space for it the next time I want to play a game.&lt;/li&gt;
&lt;li&gt;The whole table also got a nice wipe-down in the whole process and that is one less thing I would need to do before starting my week tomorrow.&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">I installed my first monitor arm and it is a desk changer.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Specifying different author and committer in git</title>
      <link href="https://varunbarad.com/blog/til-git-author-committer.html" rel="alternate" type="text/html" title="📝 Specifying different author and committer in git"/>
      <published>2024-12-18T23:13:33+05:30</published>
      <updated>2024-12-18T23:13:33+05:30</updated>
      <id>https://varunbarad.com/blog/til-git-author-committer.html</id>
      <content type="html">
      &lt;p&gt;In some cases you need to commit code/work that is originally written/done by someone else. For example when you are amending/rebasing a commit to change a small thing but still want to retain the attribution to original author when committing you can specify separate committer and author information.&lt;/p&gt;
&lt;p&gt;This is not done via any flag but by specifying a couple of environment variables.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Committer Name: Sam Smith&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# Committer Email: ss@example.com&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# Author Name: Jake Johnson&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# Author Email: jj@example.com&lt;/span&gt;
&lt;span class=&quot;token assign-left variable&quot;&gt;GIT_COMMITTER_NAME&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Sam Smith&#39;&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;GIT_COMMITTER_EMAIL&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;ss@example.com&#39;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; commit &lt;span class=&quot;token parameter variable&quot;&gt;--author&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Jake Johnson &amp;lt;jj@example.com&gt;&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Credits: &lt;a href=&quot;https://stackoverflow.com/a/23108169/4717436&quot;&gt;StackOverflow&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to specify different author and committer for a commit in git</summary>
    </entry>
  
    
    <entry>
      <title type="html">Not all booleans are created equal on GitHub Actions</title>
      <link href="https://varunbarad.com/blog/github-actions-input-types.html" rel="alternate" type="text/html" title="Not all booleans are created equal on GitHub Actions"/>
      <published>2024-10-05T06:55:23+05:30</published>
      <updated>2024-10-05T06:55:23+05:30</updated>
      <id>https://varunbarad.com/blog/github-actions-input-types.html</id>
      <content type="html">
      &lt;p&gt;We use the &lt;code&gt;workflow_dispatch&lt;/code&gt; trigger to run a GitHub Action manually. This also allows us to specify any inputs that we want to provide to the action at the time of running (&lt;a href=&quot;https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#providing-inputs&quot;&gt;link to documentation&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Take the below example where an imaginary workflow greets a person based on whether they prefer &amp;quot;Hello&amp;quot; or not as told by user. This would not work if the workflow parameter &lt;code&gt;greetWithHello&lt;/code&gt; actually expects a boolean as the value of even a boolean input parameter in a &lt;code&gt;workflow_dispatch&lt;/code&gt; call is actually a string &lt;code&gt;&#39;true&#39;&lt;/code&gt;/&lt;code&gt;&#39;false&#39;&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Show inputs

&lt;span class=&quot;token key atrule&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;workflow_dispatch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;prefersHello&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Whether the person prefers to greet with a Hello&#39;&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean important&quot;&gt;true&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; boolean
        &lt;span class=&quot;token key atrule&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean important&quot;&gt;false&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;greet_person&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Greet the person
    &lt;span class=&quot;token key atrule&quot;&gt;runs-on&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ubuntu&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;latest

    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Checkout repository
        &lt;span class=&quot;token key atrule&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; imaginary/greet@v1
        &lt;span class=&quot;token key atrule&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;greetWithHello&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; github.event.inputs.prefersHello &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The way to convert this into an actual boolean is to compare the value of the input like this&lt;/p&gt;
&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;$&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; github.event.inputs.prefersHello == &#39;true&#39; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With that, the previous example turns into:&lt;/p&gt;
&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Show inputs

&lt;span class=&quot;token key atrule&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;workflow_dispatch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;prefersHello&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Whether the person prefers to greet with a Hello&#39;&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean important&quot;&gt;true&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; boolean
        &lt;span class=&quot;token key atrule&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean important&quot;&gt;false&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;greet_person&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Greet the person
    &lt;span class=&quot;token key atrule&quot;&gt;runs-on&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ubuntu&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;latest

    &lt;span class=&quot;token key atrule&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Checkout repository
        &lt;span class=&quot;token key atrule&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; imaginary/greet@v1
        &lt;span class=&quot;token key atrule&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;token key atrule&quot;&gt;greetWithHello&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; github.event.inputs.prefersHello == &#39;true&#39; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="tools"/>
      
      <summary type="html">How to get an actual boolean input value on a manually run GitHub Action</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Delay subtitles using ffmpeg</title>
      <link href="https://varunbarad.com/blog/til-ffmpeg-delay-subtitles.html" rel="alternate" type="text/html" title="📝 Delay subtitles using ffmpeg"/>
      <published>2024-06-28T11:11:33+05:30</published>
      <updated>2024-06-28T11:11:33+05:30</updated>
      <id>https://varunbarad.com/blog/til-ffmpeg-delay-subtitles.html</id>
      <content type="html">
      &lt;p&gt;Sometimes you get subtitles which are not in sync with the video. You can use &lt;code&gt;ffmpeg&lt;/code&gt; to add a fixed delay to all subtitles. Here is how you can do it:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-itsoffset&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;amount-to-delay-in-seconds&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.srt &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy output.srt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create a new file &lt;code&gt;output.srt&lt;/code&gt; with all subtitles delayed by the specified amount. You can use this command to delay subtitles by any amount of seconds. Negative and decimal values are also supported. For example:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# This would delay the subtitles by 2.5 seconds&lt;/span&gt;
ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-itsoffset&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.5&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.srt &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy output.srt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Credits: &lt;a href=&quot;https://stackoverflow.com/a/57821897/4717436&quot;&gt;StackOverflow&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to delay all subtitles in a file by a fixed amount using ffmpeg</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Remove password from PDF files using qpdf</title>
      <link href="https://varunbarad.com/blog/til-remove-pdf-password.html" rel="alternate" type="text/html" title="📝 Remove password from PDF files using qpdf"/>
      <published>2024-05-02T00:28:40+05:30</published>
      <updated>2024-05-02T00:28:40+05:30</updated>
      <id>https://varunbarad.com/blog/til-remove-pdf-password.html</id>
      <content type="html">
      &lt;p&gt;Sometimes you get PDF files which have password on them. You know the password right now but want to store those files in your archive and don&#39;t want to remember their passwords. One way to do it is using the tool called &lt;a href=&quot;https://github.com/qpdf/qpdf&quot;&gt;qpdf&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;qpdf &lt;span class=&quot;token parameter variable&quot;&gt;--decrypt&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--password&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;your-password-goes-here&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;input-file-name&gt;&quot;&lt;/span&gt; --replace-input&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note: This will replace your existing input file, so please make a copy of the file before running this command. If you want to store the output in a different file then use below command:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;qpdf &lt;span class=&quot;token parameter variable&quot;&gt;--decrypt&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--password&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;your-password-goes-here&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;input-file-name&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;output-file-name&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;References: &lt;a href=&quot;https://ourcodeworld.com/articles/read/937/how-to-remove-the-password-of-a-pdf-using-the-qpdf-cli&quot;&gt;Carlos Delgado&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: If you know the password then you can remove it from PDF files using qpdf</summary>
    </entry>
  
    
    <entry>
      <title type="html">🐍 Packaging my first Python tool</title>
      <link href="https://varunbarad.com/blog/packaging-python-tools.html" rel="alternate" type="text/html" title="🐍 Packaging my first Python tool"/>
      <published>2024-04-21T07:57:19+05:30</published>
      <updated>2024-04-21T07:57:19+05:30</updated>
      <id>https://varunbarad.com/blog/packaging-python-tools.html</id>
      <content type="html">
      &lt;p&gt;I want to make tools and scripts to simplify my work and make it easier.&lt;/p&gt;
&lt;h2&gt;The first tool in the tool-belt&lt;/h2&gt;
&lt;p&gt;Amongst the many ideas I have in mind, I decided to start with one which would help me log what all I do during my work hours. So after summoning all my creative juices, I decided to name it &lt;code&gt;worklog&lt;/code&gt;. This tool when invoked, takes a text input from the user and logs an entry to a CSV file along with the current timestamp. Below is the code for its first version (can totally be ignored for this post):&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;#!/usr/bin/env python3&lt;/span&gt;


&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; csv
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; datetime


&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    worklog_file &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;/Users/varunb/worklog.csv&#39;&lt;/span&gt;

    worklog_entries &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;worklog_file&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;r&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; newline&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; csvFile&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        reader &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; csv&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DictReader&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;csvFile&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        worklog_entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;extend&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Enter the new worklog entry&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    new_entry &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    now &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; datetime&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;datetime&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;now&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    formatted_now &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; now&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strftime&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;%Y-%m-%dT%H:%M+05:30&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    worklog_entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;append&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&#39;timestamp&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; formatted_now&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&#39;contents&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; new_entry&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;worklog_file&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; newline&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; csvFile&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        headers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;timestamp&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;contents&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        writer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; csv&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DictWriter&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;csvFile&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; fieldnames&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;headers&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writeheader&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writerows&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;worklog_entries&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;{} Worklog updated!&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;now&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strftime&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;%H:%M&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; __name__ &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;__main__&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    main&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My directory structure of the project at this moment was:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;worklog/
└── src/
    └── main.py&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Running worklog&lt;/h2&gt;
&lt;p&gt;Whenever I wanted to, I ran the script by specifying its full path in the terminal like &lt;code&gt;/Users/varunb/Projects/worklog/src/main.py&lt;/code&gt;. Since currently the script does not have any dependencies on external libraries, this approach worked fine. But I wanted to have a setup where I could run it from anywhere on my system and neither have to worry about the full path to the script, nor have to have the dependencies installed in the global Python environment. I knew it was possible to write command-line tools in Python that satisfied both of those requirements as &lt;a href=&quot;https://github.com/yt-dlp/yt-dlp&quot;&gt;yt-dlp&lt;/a&gt; is a Python based tool meeting both of those requirements. Looking around told me that I need to look for &lt;a href=&quot;https://pipx.pypa.io/&quot;&gt;&lt;code&gt;pipx&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Packaging it&lt;/h2&gt;
&lt;p&gt;I initially started with the &lt;code&gt;setup.py&lt;/code&gt; route as I found a &lt;a href=&quot;https://python-packaging.readthedocs.io/en/latest/index.html&quot;&gt;guide for it&lt;/a&gt; first, but then found that &lt;code&gt;pipx&lt;/code&gt; has a different suggested way (using &lt;code&gt;pyproject.toml&lt;/code&gt;) and they also provided a &lt;a href=&quot;https://setuptools.pypa.io/en/latest/userguide/quickstart.html&quot;&gt;guide for the same&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;My final directory structure looked like this:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;worklog/
├── pyproject.toml
└── src/
    └── worklog/
        └── __init__.py&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With &lt;code&gt;pyproject.toml&lt;/code&gt; looking like this:&lt;/p&gt;
&lt;pre class=&quot;language-toml&quot;&gt;&lt;code class=&quot;language-toml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token table class-name&quot;&gt;build-system&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;requires&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;setuptools&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;build-backend&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;setuptools.build_meta&quot;&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token table class-name&quot;&gt;project&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;worklog&quot;&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;description&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;A simple log of my work&quot;&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;version&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;0.1&quot;&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;authors&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token key property&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Varun Barad&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token key property&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;contact@varunbarad.com&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;dependencies&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token table class-name&quot;&gt;project.urls&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;Homepage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;https://github.com/VarunBarad/worklog.git&quot;&lt;/span&gt;

&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token table class-name&quot;&gt;project.scripts&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token key property&quot;&gt;worklog&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;worklog:main&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And &lt;code&gt;src/worklog/__init__.py&lt;/code&gt; remaining mostly unchanged:&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; csv
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; datetime


&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    worklog_file &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;/Users/varunb/worklog.csv&#39;&lt;/span&gt;

    worklog_entries &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;worklog_file&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;r&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; newline&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; csvFile&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        reader &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; csv&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DictReader&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;csvFile&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        worklog_entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;extend&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Enter the new worklog entry&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    new_entry &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    now &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; datetime&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;datetime&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;now&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    formatted_now &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; now&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strftime&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;%Y-%m-%dT%H:%M+05:30&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    worklog_entries&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;append&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&#39;timestamp&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; formatted_now&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&#39;contents&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; new_entry&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;worklog_file&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; newline&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; csvFile&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        headers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;timestamp&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;contents&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        writer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; csv&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DictWriter&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;csvFile&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; fieldnames&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;headers&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writeheader&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writerows&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;worklog_entries&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;{} Worklog updated!&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;now&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strftime&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;%H:%M&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Installing it&lt;/h2&gt;
&lt;p&gt;After all of this now I can do &lt;code&gt;pipx install /path/to/worklog/ worklog&lt;/code&gt; and that would install my tool and make it available to run from anywhere on my system with a simple &lt;code&gt;worklog&lt;/code&gt; command. This also takes care of creating a virtual-environment for the dependencies of this tool and installing them in there.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="tools"/>
      
      <summary type="html">My experience of packaging my first Python tool</summary>
    </entry>
  
    
    <entry>
      <title type="html">🗂 Filenames can&#39;t just be anything</title>
      <link href="https://varunbarad.com/blog/filename-limits.html" rel="alternate" type="text/html" title="🗂 Filenames can&#39;t just be anything"/>
      <published>2024-04-12T09:01:19+05:30</published>
      <updated>2024-04-12T09:01:19+05:30</updated>
      <id>https://varunbarad.com/blog/filename-limits.html</id>
      <content type="html">
      &lt;p&gt;In my forever effort to organise my family&#39;s media collection on my NAS, I came across a file which I couldn&#39;t copy over from my laptop to the NAS. The error message said that either the file-name was too long for the destination or the name contained invalid characters which were not supported by the target. For context, this was the name of that file:&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;उत्तर रामायण - EP 08 - रामराज्य में संत संगमन। गुप्तचर द्वारा राजा राम को पीड़ित स्त्री की सूचना देना।.mp4&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;It has to be the Unicode characters&lt;/h2&gt;
&lt;p&gt;Seeing as the filename contained Devanāgari (the script which language Hindi is written in) characters which exist in Unicode but not in ASCII, and it was being copied over from a Mac machine to a Synology NAS, my first thought was that it must be that Unicode is not supported on the target system.&lt;/p&gt;
&lt;p&gt;I knew that Samba was a very popular network file-sharing protocol and assumed that that was what my NAS was using so started looking up any restrictions that it has on what characters can/cannot be part of a filename. Since it is very popular for working with Windows machines I also looked up the restrictions for NTFS filesystem too. I came across &lt;a href=&quot;https://superuser.com/a/1699196&quot;&gt;this answer&lt;/a&gt; (which links to an awesome documentation page by Microsoft) on SuperUser (a cousin site of StackOverflow). That did not help as none of the characters listed as restricted there were present in my filename.&lt;/p&gt;
&lt;h2&gt;Could it be the length?&lt;/h2&gt;
&lt;p&gt;This is when my attention turned towards the possibility that it could be that the filename was too long for the target. When I started looking that up for APFS (filesystem on my Mac machine) and for NTFS it was 255 Unicode characters on APFS and 255 UTF-16 code units on NTFS. Since the filename was 106 characters long, that couldn&#39;t be the issue either. Just to be sure I made a copy of the file locally and renamed it to &lt;code&gt;aaaaaaaaaa…a.mp4&lt;/code&gt; (there are 106 &lt;code&gt;a&lt;/code&gt; in there) and tried copying it over to the NAS. It worked! So somehow the length of the filename did not appear to be the issue here.&lt;/p&gt;
&lt;h2&gt;All Unicode characters aren&#39;t measured the same&lt;/h2&gt;
&lt;p&gt;Then I thought it might be that since each Unicode character can be anywhere from 1 to 4 bytes long, the filename might be too long in bytes. I checked using Python and found that the filename was indeed 260 bytes long. That felt like I was getting closer to the actual issue. Then I made a copy of the file locally and tried renaming it to &lt;code&gt;aaaaaaaaaaaaaa…a.mp4&lt;/code&gt; (there are 255 &lt;code&gt;a&lt;/code&gt; in there) and Mac wouldn&#39;t let me do that. Turns out I forgot to account for the &lt;code&gt;.mp4&lt;/code&gt; extension, so I removed 4 &lt;code&gt;a&lt;/code&gt; from the name and now it let me rename the file. I tried copying this file over to the NAS and it worked! So the issue was indeed that the filename was too long in bytes.&lt;/p&gt;
&lt;p&gt;Now the confusion was why did MacOS not let me rename the file to a string longer than 255 bytes while it originally already has a filename which was 260 bytes long? The light-bulb went off at that time that it was because the original name even though being longer than 255 bytes was actually only 106 Unicode characters long (thus being well under the limit) but the name I was trying to rename it to was not only longer than 255 bytes but also longer than 255 Unicode characters therefore MacOS wouldn&#39;t let me do that.&lt;/p&gt;
&lt;h2&gt;The final piece of the puzzle&lt;/h2&gt;
&lt;p&gt;At this point I actually went ahead and checked what filesystem my NAS was running and lo-and-behold it wasn&#39;t NTFS, when setting it up initially I had configured it to run Btrfs where the maximum permitted filename length is 255 bytes. Now all the pieces fell into place, while the filename was well under the limit for APFS (255 Unicode characters) it was too long for Btrfs (255 bytes). Even though now I had to think of another naming convention for this whole show/series, I was relieved to have finally figured out what the issue was.&lt;/p&gt;
&lt;h2&gt;My feelings&lt;/h2&gt;
&lt;p&gt;I would say this is one place where I like Apple&#39;s choice more than the other popular Unix/Linux filesystems, none of the ext* or Btrfs or ZFS filesystems have a limit on the number of Unicode characters in a filename, they all have a limit on the number of bytes in a filename. Folks much smarter than me have written those filesystems and they must have had their reasons for choosing this way, but I feel as an end-user that it makes more sense to have a limit that applies so that two files with similarly long looking filenames are either both valid or both invalid.&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://superuser.com/a/1699196&quot;&gt;SuperUser: Which Unicode characters cannot be used for NTFS file names?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions&quot;&gt;Microsoft: Naming Files, Paths, and Namespaces&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://superuser.com/a/1561487&quot;&gt;SuperUser: What is the maximum length of a filename (APFS)?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits&quot;&gt;Wikipedia: Comparison of file systems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/UTF-8#Encoding&quot;&gt;Wikipedia: UTF-8 Encoding&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="computers"/>
      
      <summary type="html">There are limitations on how long a filename can be or even what characters it can contain. And they differ across different filesystems.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Outputting text with echo without a newline</title>
      <link href="https://varunbarad.com/blog/til-echo-without-newline.html" rel="alternate" type="text/html" title="📝 Outputting text with echo without a newline"/>
      <published>2024-04-06T15:14:19+05:30</published>
      <updated>2024-04-06T15:14:19+05:30</updated>
      <id>https://varunbarad.com/blog/til-echo-without-newline.html</id>
      <content type="html">
      &lt;p&gt;Recently I wanted to output a string containing the day&#39;s date and time. So I used the &lt;code&gt;echo&lt;/code&gt; command combined with the &lt;code&gt;date&lt;/code&gt; command. But I didn&#39;t want the newline at the end of the output. So I asked ChatGPT and here&#39;s the command I got:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Hello Varun&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to output text with echo without a newline at the end of it</summary>
    </entry>
  
    
    <entry>
      <title type="html">🐳 Starting docker on demand</title>
      <link href="https://varunbarad.com/blog/starting-docker-on-demand.html" rel="alternate" type="text/html" title="🐳 Starting docker on demand"/>
      <published>2023-09-11T13:17:31+05:30</published>
      <updated>2023-09-11T13:17:31+05:30</updated>
      <id>https://varunbarad.com/blog/starting-docker-on-demand.html</id>
      <content type="html">
      &lt;p&gt;Inspired by &lt;a href=&quot;https://alexwlchan.net/2023/docker-on-demand/&quot;&gt;this article&lt;/a&gt; from &lt;a href=&quot;https://alexwlchan.net/&quot;&gt;Alex&lt;/a&gt; I also set out to remove always running Docker daemon from the background while ensuring it is available whenever I need it on running &lt;code&gt;docker&lt;/code&gt; or &lt;code&gt;docker-compose&lt;/code&gt; commands.&lt;/p&gt;
&lt;p&gt;I created 2 scripts and put them on my path before the actual &lt;code&gt;docker&lt;/code&gt; and &lt;code&gt;docker-compose&lt;/code&gt; binaries. For an explanation of the scripts I suggest you read Alex&#39;s article linked above.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token shebang important&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class=&quot;token builtin class-name&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-o&lt;/span&gt; errexit
&lt;span class=&quot;token builtin class-name&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-o&lt;/span&gt; nounset

&lt;span class=&quot;token function-name function&quot;&gt;is_docker_running&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; /usr/local/bin/docker info &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /dev/null &lt;span class=&quot;token operator&quot;&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;2&lt;/span&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;&amp;amp;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
    &lt;span class=&quot;token builtin class-name&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;
    &lt;span class=&quot;token builtin class-name&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt; is_docker_running&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
  &lt;span class=&quot;token builtin class-name&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Starting Docker...&quot;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;open&lt;/span&gt; /Applications/Docker.app

  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token for-or-select variable&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; is_docker_running&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
      &lt;span class=&quot;token builtin class-name&quot;&gt;break&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;sleep&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;done&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;

/usr/local/bin/docker &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;$@&lt;/span&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I named the above file &lt;code&gt;docker&lt;/code&gt;, gave it executable permissions and did a similar thing for &lt;code&gt;docker-compose&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token shebang important&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class=&quot;token builtin class-name&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-o&lt;/span&gt; errexit
&lt;span class=&quot;token builtin class-name&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-o&lt;/span&gt; nounset

&lt;span class=&quot;token function-name function&quot;&gt;is_docker_running&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; /usr/local/bin/docker info &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /dev/null &lt;span class=&quot;token operator&quot;&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;2&lt;/span&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;&amp;amp;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
    &lt;span class=&quot;token builtin class-name&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;
    &lt;span class=&quot;token builtin class-name&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt; is_docker_running&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
  &lt;span class=&quot;token builtin class-name&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Starting Docker...&quot;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;open&lt;/span&gt; /Applications/Docker.app

  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token for-or-select variable&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;&lt;span class=&quot;token variable&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;seq&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; is_docker_running&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
      &lt;span class=&quot;token builtin class-name&quot;&gt;break&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;sleep&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;done&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;

/usr/local/bin/docker-compose &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;$@&lt;/span&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks again to &lt;a href=&quot;https://alexwlchan.net/&quot;&gt;Alex&lt;/a&gt; for the inspiration.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="tools"/>
      
      <summary type="html">How to avoid not having docker running when you run &lt;code&gt;docker&lt;/code&gt; or &lt;code&gt;docker-compose&lt;/code&gt; commands</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 PostgreSQL: Mark a column non-nullable after creating it</title>
      <link href="https://varunbarad.com/blog/til-postgresql-make-existing-column-non-nullable.html" rel="alternate" type="text/html" title="📝 PostgreSQL: Mark a column non-nullable after creating it"/>
      <published>2023-08-20T14:23:22+05:30</published>
      <updated>2023-08-20T14:23:22+05:30</updated>
      <id>https://varunbarad.com/blog/til-postgresql-make-existing-column-non-nullable.html</id>
      <content type="html">
      &lt;p&gt;If we have a table &lt;code&gt;people&lt;/code&gt; with a column &lt;code&gt;email&lt;/code&gt; and we want to make it non-nullable after we have already added it to table:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;table&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;column&lt;/span&gt; email &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="postgresql"/>
      
      <summary type="html">TIL: How to add a not null constraint to an existing column in a PostgreSQL table</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 PostgreSQL: Make a column unique after creating it</title>
      <link href="https://varunbarad.com/blog/til-postgresql-make-existing-column-unique.html" rel="alternate" type="text/html" title="📝 PostgreSQL: Make a column unique after creating it"/>
      <published>2023-08-19T14:23:22+05:30</published>
      <updated>2023-08-19T14:23:22+05:30</updated>
      <id>https://varunbarad.com/blog/til-postgresql-make-existing-column-unique.html</id>
      <content type="html">
      &lt;p&gt;If we have a table &lt;code&gt;people&lt;/code&gt; with a column &lt;code&gt;email&lt;/code&gt; and we want to make it unique after we have already added it to table:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;table&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;unique&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;email&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="postgresql"/>
      
      <summary type="html">TIL: How to add unique constraint to an existing column in a PostgreSQL table</summary>
    </entry>
  
    
    <entry>
      <title type="html">⚖️ Wracker Dev Log #003</title>
      <link href="https://varunbarad.com/blog/wracker-log-003.html" rel="alternate" type="text/html" title="⚖️ Wracker Dev Log #003"/>
      <published>2023-08-17T06:58:27+05:30</published>
      <updated>2023-08-17T06:58:27+05:30</updated>
      <id>https://varunbarad.com/blog/wracker-log-003.html</id>
      <content type="html">
      &lt;p&gt;This is the third log entry for my weight-tracking project and the work covered today happened over multiple days. I added a graph of the weight entries and moved away from django to flask.&lt;/p&gt;
&lt;h2&gt;Period 3 Task 1 (P3T1) - Adding a graph&lt;/h2&gt;
&lt;p&gt;Seeing the progress of my weight-change journey at-a-glance was a must for me and so a graph was required because it makes seeing the trend over time much simpler. I had already &lt;a href=&quot;https://varunbarad.com/blog/typractice-stats-chart&quot;&gt;added a chart recently to another project&lt;/a&gt; and went with the same &lt;a href=&quot;https://chartjs.org/&quot;&gt;library&lt;/a&gt; and usage pattern. A simple chart of weight-entries against the date of measurement was all I needed. Screenshots of the results follow:&lt;/p&gt;
&lt;p&gt;The website with no data added.
&lt;img src=&quot;https://varunbarad.com/assets/images/posts/wracker/003-wracker-without-data.png&quot; alt=&quot;screenshot with no data added&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The website with a few weight entries.
&lt;img src=&quot;https://varunbarad.com/assets/images/posts/wracker/003-wracker-with-data.png&quot; alt=&quot;screenshot with a few weight entries&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;P3T2 - Moving from django to flask&lt;/h2&gt;
&lt;p&gt;My initial reasoning to go with django was because I wanted to learn a Python backend framework, but with how much different types of code-bases I was seeing when looking for &amp;quot;the&amp;quot; code structure for a django project I was getting confused. So rather than burn my efficiency trying to grok just django, I decided to move to a simpler backend framework &lt;a href=&quot;https://flask.palletsprojects.com/&quot;&gt;flask&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I started by installing flask and then serving the same HTML file as a rendered template from flask. Once that was done, I removed all the django-related code from the codebase. That was followed by learning how static files are served in flask and then moving my styles and Javascript to separate static files. Final step was to move the Javascript file for the charting library in-house. I downloaded the minified version of the library with a simple &lt;code&gt;wget&lt;/code&gt; and then moved it to the static folder and pointed my HTML file to it.&lt;/p&gt;
&lt;p&gt;So far I would say that it is much easier to understand how things are happening in Flask than how they were happening in django. I am sure that django is a much more powerful framework but for my use-case, I think flask is more than enough.&lt;/p&gt;
&lt;h2&gt;Things I learned/solidified today&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Serve static files in flask&lt;/li&gt;
&lt;li&gt;Serve an HTML file as a template in flask&lt;/li&gt;
&lt;li&gt;How to remove dependencies from a Python project&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="wracker"/>
      
      <category term="programming"/>
      
      <category term="python"/>
      
      <category term="javascript"/>
      
      <summary type="html">Adding a graph and moving away from django</summary>
    </entry>
  
    
    <entry>
      <title type="html">⌨️ Paragraph performance summaries</title>
      <link href="https://varunbarad.com/blog/typractice-paragraph-summaries.html" rel="alternate" type="text/html" title="⌨️ Paragraph performance summaries"/>
      <published>2023-08-11T21:33:50+05:30</published>
      <updated>2023-08-11T21:33:50+05:30</updated>
      <id>https://varunbarad.com/blog/typractice-paragraph-summaries.html</id>
      <content type="html">
      &lt;p&gt;Apart from the graph I added last time I also wanted people to have a table where they can see their performance. Initially I was going to present the top 10 performance according to words-per-minute show up in the table. Something like a leaderboard.&lt;/p&gt;
&lt;p&gt;But as I was writing the code, GitHub Copilot autofilled for me the code of a table which shows a summary of user&#39;s performance on each paragraph. I liked the idea and went with it. Wrote a bit of CSS to make the table have rounded corners and other such touch-ups.&lt;/p&gt;
&lt;p&gt;For each different paragraph that you have typed in, you can now see the following data-points:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Paragraph number&lt;/li&gt;
&lt;li&gt;Number of attempts you have made&lt;/li&gt;
&lt;li&gt;Your best, worst and average time in minutes&lt;/li&gt;
&lt;li&gt;Your best, worst and average speed in words-per-minute&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The website looks usably nice on a laptop and desktop, it has all the functionalities that I wanted it to have. Now I declare this project as finished. I won&#39;t make any new changes to it unless to fix a bug. This declaration is primarily for me to stop myself from spending any more time thinking about this 😅.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/project-typractice/stats-table.png&quot; alt=&quot;screenshot of the summary stats table&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Articles on this project&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/project-typractice&quot;&gt;Public release&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/typractice-stats-chart&quot;&gt;Adding stats chart&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Adding summary stats table (this article)&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="typractice"/>
      
      <category term="web"/>
      
      <category term="programming"/>
      
      <summary type="html">I added a chart to show your progress over time</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Avoid .DS_Store files on removable media</title>
      <link href="https://varunbarad.com/blog/til-avoid-ds-store.html" rel="alternate" type="text/html" title="📝 Avoid .DS_Store files on removable media"/>
      <published>2023-08-09T19:24:24+05:30</published>
      <updated>2023-08-09T19:24:24+05:30</updated>
      <id>https://varunbarad.com/blog/til-avoid-ds-store.html</id>
      <content type="html">
      &lt;p&gt;Disable creation of metadata files (&lt;code&gt;.DS_Store&lt;/code&gt; and AppleDouble files) on Network Volumes&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;defaults &lt;span class=&quot;token function&quot;&gt;write&lt;/span&gt; com.apple.desktopservices DSDontWriteNetworkStores &lt;span class=&quot;token parameter variable&quot;&gt;-bool&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Disable creation of metadata files (&lt;code&gt;.DS_Store&lt;/code&gt; and AppleDouble files) on USB Volumes&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;defaults &lt;span class=&quot;token function&quot;&gt;write&lt;/span&gt; com.apple.desktopservices DSDontWriteUSBStores &lt;span class=&quot;token parameter variable&quot;&gt;-bool&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: Settings change on Mac to avoid having .DS_Store files being created on USB and Network shares</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Recursively remove .DS_Store files</title>
      <link href="https://varunbarad.com/blog/remove-ds-store-files.html" rel="alternate" type="text/html" title="📝 Recursively remove .DS_Store files"/>
      <published>2023-08-09T14:49:36+05:30</published>
      <updated>2023-08-09T14:49:36+05:30</updated>
      <id>https://varunbarad.com/blog/remove-ds-store-files.html</id>
      <content type="html">
      &lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt; &lt;span class=&quot;token builtin class-name&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-name&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.DS_Store&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-type&lt;/span&gt; f &lt;span class=&quot;token parameter variable&quot;&gt;-delete&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you just want to list out those files then skip the &lt;code&gt;-delete&lt;/code&gt; flag.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt; &lt;span class=&quot;token builtin class-name&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-name&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;.DS_Store&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-type&lt;/span&gt; f&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: Shell command to recursively remove .DS_Store files</summary>
    </entry>
  
    
    <entry>
      <title type="html">⌨️ Showing historical statistics</title>
      <link href="https://varunbarad.com/blog/typractice-stats-chart.html" rel="alternate" type="text/html" title="⌨️ Showing historical statistics"/>
      <published>2023-07-27T22:11:36+05:30</published>
      <updated>2023-07-27T22:11:36+05:30</updated>
      <id>https://varunbarad.com/blog/typractice-stats-chart.html</id>
      <content type="html">
      &lt;p&gt;While I was accruing the typing speed data each time I practiced on Typractice, the user was not able to see it. They had no way of knowing how they have progressed (or regressed) over time.&lt;/p&gt;
&lt;p&gt;I started by wanting to add a table where each entry will be shown but instead went ahead with a chart because it looks fancier, and also it makes it easier for the user to see the trend.&lt;/p&gt;
&lt;p&gt;Looked around a bit for a charting library and decided to go with the &lt;a href=&quot;https://chartjs.org/&quot;&gt;Chart.js&lt;/a&gt; library which has sane defaults with options to customize a lot of things.&lt;/p&gt;
&lt;p&gt;Each entry in the line-chart represents the speed (in words-per-minute) and the timestamp of the attempt. You can also hover over each point to see the exact value.&lt;/p&gt;
&lt;p&gt;Would love to see how your speed has changed over time. Send me screenshots of your charts.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/project-typractice/stats-chart.png&quot; alt=&quot;screenshot of the stats page&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Articles on this project&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/project-typractice&quot;&gt;Public release&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Adding stats chart (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/typractice-paragraph-summaries&quot;&gt;Adding summary stats table&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="typractice"/>
      
      <category term="web"/>
      
      <category term="programming"/>
      
      <summary type="html">I added a chart to show your progress over time</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎬 Movie rating system</title>
      <link href="https://varunbarad.com/blog/movie-rating-system.html" rel="alternate" type="text/html" title="🎬 Movie rating system"/>
      <published>2023-07-22T11:31:20+05:30</published>
      <updated>2023-07-22T11:31:20+05:30</updated>
      <id>https://varunbarad.com/blog/movie-rating-system.html</id>
      <content type="html">
      &lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Over the years I have watched a lot of movies but never found a good way to determine which of them I liked how much. That was until I came across this &lt;a href=&quot;https://kau.sh/blog/movie-rating-system/&quot;&gt;simple guide&lt;/a&gt; from &lt;a href=&quot;https://kau.sh/&quot;&gt;Kaushik Gopal&lt;/a&gt;. The rating works on a scale of 0-5 and here&#39;s how it goes:&lt;/p&gt;
&lt;h2&gt;0 (🤢)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This movie doesn&#39;t exist to me. It&#39;s so bad that I will not even mention its existence to other people.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;1 (🙅‍♂️)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;I watched this movie and I regret it.&lt;/li&gt;
&lt;li&gt;I feel like I&#39;ve been robbed off my time.&lt;/li&gt;
&lt;li&gt;I don&#39;t recommend anyone watch it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;2 (🤷️)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;I watched this movie.&lt;/li&gt;
&lt;li&gt;I don&#39;t regret it per say.&lt;/li&gt;
&lt;li&gt;But I wouldn&#39;t recommend to anyone else.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;3 (👍)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This movie was decent and I’m glad I watched it.&lt;/li&gt;
&lt;li&gt;It deserves to be watched at least once, so I would recommend this to others.&lt;/li&gt;
&lt;li&gt;But I personally wouldn’t watch this movie all over again.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;4 (👌)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This movie was really good.&lt;/li&gt;
&lt;li&gt;This would go in my list of recommended movies for the year.&lt;/li&gt;
&lt;li&gt;Heck, I’d like to watch this movie again sometime.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;5 (🎖️)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This movie was so good that I want to buy a copy of it.&lt;/li&gt;
&lt;li&gt;This movie is a work of art and/or essential watching for our age.&lt;/li&gt;
&lt;li&gt;I would sit my friends down and watch this movie again with them.&lt;/li&gt;
&lt;li&gt;Every one should watch this movie at least once in their lifetime.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Edits&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;2024-01-17:
&lt;ul&gt;
&lt;li&gt;Removed 4.5 rating&lt;/li&gt;
&lt;li&gt;Changed 0.5 rating to 0&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <category term="life-hack"/>
      
      <category term="movies"/>
      
      <summary type="html">A simple heuristic to rate movies based on their viewability and enjoyment</summary>
    </entry>
  
    
    <entry>
      <title type="html">⚖️ Wracker Dev Log #002</title>
      <link href="https://varunbarad.com/blog/wracker-log-002.html" rel="alternate" type="text/html" title="⚖️ Wracker Dev Log #002"/>
      <published>2023-06-12T19:35:00+05:30</published>
      <updated>2023-06-12T19:35:00+05:30</updated>
      <id>https://varunbarad.com/blog/wracker-log-002.html</id>
      <content type="html">
      &lt;p&gt;Welcome to the second log of my journey to build a weight-tracking website. Today I worked on the form for adding a new weight entry and also on the table for displaying all the entries.&lt;/p&gt;
&lt;h2&gt;Day 2 Challenge 1&lt;/h2&gt;
&lt;p&gt;First goal for today was to get a static HTML page served from my Django server as the homepage for the website. I couldn&#39;t figure out how to deal with &lt;code&gt;django-static&lt;/code&gt; and so ended up rendering a template (with no data passed) from an endpoint. For now I just shoved all my CSS and JS for this page in the HTML file itself. I&#39;ll figure out how to deal with static files later.&lt;/p&gt;
&lt;h2&gt;Day 2 Challenge 2&lt;/h2&gt;
&lt;p&gt;Next up on the task was to create a form which takes in the recording date (defaults to current date but user can change it) and allows user to enter their weight for that day. Then take that data and store it locally in-browser. I chose to go the &lt;code&gt;local-storage&lt;/code&gt; path for this. The most cumbersome part for me was to get the form to look how I wanted it to. Other than form-styling, actually capturing and storing the data was quite straight-forward.&lt;/p&gt;
&lt;h2&gt;Day 2 Challenge 3&lt;/h2&gt;
&lt;p&gt;The final task for me was to display the captured data in a table. Again, getting and processing the data to display was not the difficult part. The quirkiest section was when I wanted to turn the corners of my table round. Turns out, each cell individually gets their border and thus to only give the table rounded corners I had to select individual corner cells and then give them rounded corner for only the corner which was going to become a corner of the table.&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;The website with no data added.
&lt;img src=&quot;https://varunbarad.com/assets/images/posts/wracker/002-wracker-without-data.png&quot; alt=&quot;screenshot with no data added&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The website with a few weight entries.
&lt;img src=&quot;https://varunbarad.com/assets/images/posts/wracker/002-wracker-with-data.png&quot; alt=&quot;screenshot with a few weight entries&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Things I learned/solidified today&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;How to style corners of a HTML &lt;code&gt;table&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;How to serve a HTML page from under Django&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="wracker"/>
      
      <category term="programming"/>
      
      <category term="python"/>
      
      <category term="javascript"/>
      
      <summary type="html">My experience making a usable form and working with HTML &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; for the first time</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Custom 404 in Express</title>
      <link href="https://varunbarad.com/blog/til-handle-404-node-express.html" rel="alternate" type="text/html" title="📝 Custom 404 in Express"/>
      <published>2023-06-02T17:52:02+05:30</published>
      <updated>2023-06-02T17:52:02+05:30</updated>
      <id>https://varunbarad.com/blog/til-handle-404-node-express.html</id>
      <content type="html">
      &lt;p&gt;You need to define a middleware to handle it and that middleware needs to be defined after all the other routes and middlewares have been specified already.&lt;/p&gt;
&lt;p&gt;The logic is that this middleware will only be executed if the request cannot match with any other middleware/route.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;req&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; next&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Not found&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And if you don&#39;t want to provide a body then.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;req&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; next&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sendStatus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="programming"/>
      
      <category term="javascript"/>
      
      <summary type="html">TIL: How to return custom response for a 404 in Express on NodeJS</summary>
    </entry>
  
    
    <entry>
      <title type="html">⌨️ Typractice</title>
      <link href="https://varunbarad.com/blog/project-typractice.html" rel="alternate" type="text/html" title="⌨️ Typractice"/>
      <published>2023-05-25T12:21:38+05:30</published>
      <updated>2023-05-25T12:21:38+05:30</updated>
      <id>https://varunbarad.com/blog/project-typractice.html</id>
      <content type="html">
      &lt;p&gt;Recently someone I know wanted to improve their typing speed and accuracy. While there are a lot of websites available around to practice your typing, I took this as a chance to build my own which is free of any ads or tracking. Following my tradition of not-the-best puns, I present to the world: &lt;a href=&quot;https://typractice.varunbarad.com/&quot;&gt;Typractice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It&#39;s a simple website which gives you a random paragraph to type. At the end you are presented your typing speed in terms of words-per-minute. There is no mentioning of accuracy as it doesn&#39;t accept anything other than perfect text entry. The timer keeps going until you enter the whole paragraph correctly.&lt;/p&gt;
&lt;p&gt;This is also the first time I tried writing it with the help of ChatGPT. Gave it a bunch of prompts, and it gave out a bunch of code. Both the functionality and appearance of the site were not upto my expectations, but I used it and then built on top.&lt;/p&gt;
&lt;p&gt;The website also stores in-browser (all locally on your machine) how you performed on different paragraphs. I plan to add a stats page in the future which could show you how your performance changed over time, both overall and also for specific paragraphs.&lt;/p&gt;
&lt;p&gt;Check it out and let me know what you like and what you would like to change about it. You can also send me screenshots of your best scores.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/project-typractice/screenshot.png&quot; alt=&quot;my score&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Articles on this project&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Public release (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/typractice-stats-chart&quot;&gt;Adding stats chart&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/typractice-paragraph-summaries&quot;&gt;Adding summary stats table&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="typractice"/>
      
      <category term="web"/>
      
      <category term="programming"/>
      
      <category term="project"/>
      
      <summary type="html">A simple website to practice your typing</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Using emoji as a favicon</title>
      <link href="https://varunbarad.com/blog/emoji-as-favicon.html" rel="alternate" type="text/html" title="📝 Using emoji as a favicon"/>
      <published>2023-05-23T17:32:32+05:30</published>
      <updated>2023-05-23T17:32:32+05:30</updated>
      <id>https://varunbarad.com/blog/emoji-as-favicon.html</id>
      <content type="html">
      &lt;p&gt;You can use an emoji as a favicon with this simple snippet:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;icon&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;data:image/svg+xml,&amp;lt;svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22&gt;&amp;lt;text y=%22.9em%22 font-size=%2290%22&gt;🎯&amp;lt;/text&gt;&amp;lt;/svg&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Credits to &lt;a href=&quot;https://css-tricks.com/emoji-as-a-favicon/&quot;&gt;CSS-Tricks&lt;/a&gt; for this snippet.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to write a simple SVG which renders an emoji as a favicon</summary>
    </entry>
  
    
    <entry>
      <title type="html">⚖️ Wracker Dev Log #001</title>
      <link href="https://varunbarad.com/blog/wracker-log-001.html" rel="alternate" type="text/html" title="⚖️ Wracker Dev Log #001"/>
      <published>2023-05-22T23:55:00+05:30</published>
      <updated>2023-05-22T23:55:00+05:30</updated>
      <id>https://varunbarad.com/blog/wracker-log-001.html</id>
      <content type="html">
      &lt;p&gt;I have been meaning to build my skills in some areas for quite some time, Python, traditional backend frameworks and a bit of full-stack development being a few of them. I decided on building a simple weight-tracking website to learn these things. It had been tossing about in my head for a lot of time, and finally I decided to sit down and start coding it today.&lt;/p&gt;
&lt;h2&gt;Day 1 Challenge 1&lt;/h2&gt;
&lt;p&gt;The first thing to do was to create a directory to store all the code in. Here was the first roadblock I hit, what should the project be named. After contemplating and thinking a lot on it (read 3 minutes max) I decided to go with &amp;quot;Wracker&amp;quot; as it could be seen as a short for &amp;quot;Weight Tracker&amp;quot; and also it is a pun on the word &amp;quot;Wrecker&amp;quot; which I just found hilarious.&lt;/p&gt;
&lt;h2&gt;Day 1 Challenge Virtual&lt;/h2&gt;
&lt;p&gt;Up next was me wanting to install the dependencies for the project without them muddying up my system-wide python packages. I knew of &lt;code&gt;virtualenv&lt;/code&gt; and have banged my head enough in the past that it only took me 3 tries before I had it nailed down.&lt;/p&gt;
&lt;h2&gt;Day 1 Challenging Structure&lt;/h2&gt;
&lt;p&gt;Since I wanted to use Django framework for this project and I haven&#39;t ever used it before, I went to their official getting started guide and was left with a file structure looking something like this after initialising my project.&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;- Projects
  |- wracker
     |- .gitignore
     |- wracker
        |- manage.py
        |- wracker
           |- __init.py__
           |- asgi.py
           |- settings.py
           |- urls.py
           |- wsgi.py&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here I tried running the commands from getting started guide inside a pre-made directory for my project. I could not understand why it needs to create 2 separate subdirectories named the same as the project. This is something I tried understanding multiple times during the day, and we&#39;ll back come to it later.&lt;/p&gt;
&lt;h2&gt;Challenge Post the SQLite&lt;/h2&gt;
&lt;p&gt;Django by default uses an SQLite database for storing data, but I wanted to use Postgres. I had already setup a &lt;code&gt;docker-compose.yaml&lt;/code&gt; file to provision me a postgres database running inside a docker container. While initially the configuration part in Django for Postgres was a bit confusing, I was able to get it working after a bit of fitting in multiple pieces together. I also learned how to use environment variables in Python while dealing with this.&lt;/p&gt;
&lt;h2&gt;Challenge of Looking Good&lt;/h2&gt;
&lt;p&gt;I also wanted a code-formatter for Python and had heard about this one called &lt;code&gt;black&lt;/code&gt;. Went to the official website, learnt how to use it and then integrate it locally with wracker.&lt;/p&gt;
&lt;h2&gt;Challenge of the Day&lt;/h2&gt;
&lt;p&gt;After looking at all this I would give &amp;quot;Challenge of the Day&amp;quot; award only to the project structure. While none of the official documentation clearly call it out that you need to pass in &lt;code&gt;.&lt;/code&gt; as the directory to your &lt;code&gt;django-admin startproject&lt;/code&gt; I did find &lt;a href=&quot;https://automationpanda.com/2018/02/06/starting-a-django-project-in-an-existing-directory/&quot;&gt;an article online&lt;/a&gt; that clarified it.&lt;/p&gt;
&lt;h2&gt;Things I learned/solidified today&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Using &lt;code&gt;virtualenv&lt;/code&gt; to keep dependencies separate in Python&lt;/li&gt;
&lt;li&gt;How to export your dependencies as a &lt;code&gt;requirements.txt&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;Usage of environment variables in Python&lt;/li&gt;
&lt;li&gt;How to create a Django project with reasonable directory structure&lt;/li&gt;
&lt;li&gt;Formatting python code using &lt;code&gt;black&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Integrating PostgreSQL with Django instead of the default SQLite database&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="wracker"/>
      
      <category term="programming"/>
      
      <category term="project"/>
      
      <category term="python"/>
      
      <summary type="html">How I headbutted with Django setup the whole day for it to finally click around midnight</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Save dependency list of your python project to a file</title>
      <link href="https://varunbarad.com/blog/til-python-save-dependency-list.html" rel="alternate" type="text/html" title="📝 Save dependency list of your python project to a file"/>
      <published>2023-05-22T16:10:27+05:30</published>
      <updated>2023-05-22T16:10:27+05:30</updated>
      <id>https://varunbarad.com/blog/til-python-save-dependency-list.html</id>
      <content type="html">
      &lt;p&gt;Node/npm lists the dependencies you install in a project in the &lt;code&gt;dependencies&lt;/code&gt; key in your &lt;code&gt;package.json&lt;/code&gt; file. But since python doesn&#39;t have a similar file I was exploring how to do the same for a python project.&lt;/p&gt;
&lt;p&gt;I came across the convention of a &lt;code&gt;requirements.txt&lt;/code&gt; file. This file lists all the packages that are installed in your current environment.&lt;/p&gt;
&lt;p&gt;To generate the file you use:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;pip freeze &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; requirements.txt&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="python"/>
      
      <category term="programming"/>
      
      <summary type="html">TIL: How to do for python what we get with `dependencies` in npm `package.json`</summary>
    </entry>
  
    
    <entry>
      <title type="html">Group posts by year in Jekyll using Liquid</title>
      <link href="https://varunbarad.com/blog/group-posts-by-year-jekyll.html" rel="alternate" type="text/html" title="Group posts by year in Jekyll using Liquid"/>
      <published>2023-05-10T07:55:00+05:30</published>
      <updated>2023-05-10T07:55:00+05:30</updated>
      <id>https://varunbarad.com/blog/group-posts-by-year-jekyll.html</id>
      <content type="html">
      &lt;p&gt;On the &lt;a href=&quot;https://varunbarad.com/blog&quot;&gt;list-all-posts page&lt;/a&gt; on this blog I wanted to group posts by year and show the year as a section-heading.&lt;/p&gt;
&lt;p&gt;I found a &lt;a href=&quot;https://stackoverflow.com/a/61346228/4717436&quot;&gt;StackOverflow answer&lt;/a&gt; that suggested using the &lt;code&gt;group_by_exp&lt;/code&gt; filter in Liquid. I used it as follows:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;{% assign postsByYear = site.posts | group_by_exp:&quot;post&quot;, &quot;post.date | date: &#39;%Y&#39;&quot; %}
{% for year in postsByYear %}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ year.name }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;post-list&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  {% for post in year.items %}
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;{{ post.url }}&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;post-title&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ post.title }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;br&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;post-description&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ post.summary }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  {% endfor %}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
{% endfor %}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want to further do sub-sections by month then you can use something like this:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;{% assign postsByYear = site.posts | group_by_exp:&quot;post&quot;, &quot;post.date | date: &#39;%Y&#39;&quot; %}
{% for year in postsByYear %}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ year.name }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;month-list&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  {% assign postsByMonth = year.items | group_by_exp:&quot;post&quot;, &quot;post.date | date: &#39;%B&#39;&quot; %}
  {% for month in postsByMonth %}
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ month.name }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;

  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;post-list&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    {% for post in month.items %}
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;{{ post.url }}&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;post-title&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ post.title }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;br&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;post-description&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;{{ post.summary }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    {% endfor %}
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  {% endfor %}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
{% endfor %}&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">You can use the `group_by_exp` filter in Liquid to group posts by year</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Map an array of ids in postgres to matching data from another table</title>
      <link href="https://varunbarad.com/blog/til-postgres-map-array.html" rel="alternate" type="text/html" title="📝 Map an array of ids in postgres to matching data from another table"/>
      <published>2023-05-08T23:10:27+05:30</published>
      <updated>2023-05-08T23:10:27+05:30</updated>
      <id>https://varunbarad.com/blog/til-postgres-map-array.html</id>
      <content type="html">
      &lt;p&gt;If we have two tables, &lt;code&gt;people&lt;/code&gt; and &lt;code&gt;groups&lt;/code&gt;, where &lt;code&gt;people&lt;/code&gt; has a column &lt;code&gt;group_ids&lt;/code&gt; which is an array of ids from &lt;code&gt;groups&lt;/code&gt;, we can map the array of ids to the matching name from &lt;code&gt;groups&lt;/code&gt; using the following query:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt;
    p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;email &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; email&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;coalesce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;groups&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;names&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; group_names

&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; p
    &lt;span class=&quot;token keyword&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; string_agg&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;g&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; names&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; person_id

        &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; entity_groups &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; g
            &lt;span class=&quot;token keyword&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; unnest&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;group_ids&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; group_id
                &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people
            &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; person &lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;group_id &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; g&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id

        &lt;span class=&quot;token keyword&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; groups &lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; groups&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;person_id &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id

&lt;span class=&quot;token keyword&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; email&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is a three-step process, listed inside to out (i.e. the innermost query is executed first):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Convert the &lt;code&gt;group_ids&lt;/code&gt; array from &lt;code&gt;people&lt;/code&gt; into a table of &lt;code&gt;person_id&lt;/code&gt; and &lt;code&gt;group_id&lt;/code&gt; using &lt;code&gt;unnest&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Join the &lt;code&gt;group_id&lt;/code&gt; with the &lt;code&gt;id&lt;/code&gt; of &lt;code&gt;groups&lt;/code&gt; to get the &lt;code&gt;name&lt;/code&gt; of the group&lt;/li&gt;
&lt;li&gt;Aggregate the &lt;code&gt;name&lt;/code&gt; of the groups into a comma-separated string using &lt;code&gt;string_agg&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="postgresql"/>
      
      <summary type="html">TIL: How to map an array in postgres to other data</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Counting days between 2 dates in PostgreSQL</title>
      <link href="https://varunbarad.com/blog/til-postgres-days-between-dates.html" rel="alternate" type="text/html" title="📝 Counting days between 2 dates in PostgreSQL"/>
      <published>2023-04-09T07:52:44+05:30</published>
      <updated>2023-04-09T07:52:44+05:30</updated>
      <id>https://varunbarad.com/blog/til-postgres-days-between-dates.html</id>
      <content type="html">
      &lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:center&quot;&gt;payments&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;customer_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_amount&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_date&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If you want to count the number of days between each payment and today then you can use &lt;code&gt;extract&lt;/code&gt; function with &lt;code&gt;days&lt;/code&gt; as a parameter:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; payment_id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    payment_date&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    extract&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;days &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; payment_date&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; days_since_payment
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; payments&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="postgresql"/>
      
      <summary type="html">TIL: You can use the extract function to find difference in days between 2 dates</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Find the first entry in each group</title>
      <link href="https://varunbarad.com/blog/til-postgres-first-in-each-group.html" rel="alternate" type="text/html" title="📝 Find the first entry in each group"/>
      <published>2023-03-27T17:39:15+05:30</published>
      <updated>2023-03-27T17:39:15+05:30</updated>
      <id>https://varunbarad.com/blog/til-postgres-first-in-each-group.html</id>
      <content type="html">
      &lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:center&quot;&gt;payments&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;customer_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_amount&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_date&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If we want to see the payment_id of the highest amount of payment for each customer_id then we need to do:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;distinct&lt;/span&gt; customer_id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    first_value&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;payment_id&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;over&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;partition&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; customer_id &lt;span class=&quot;token keyword&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; payment_amount &lt;span class=&quot;token keyword&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; highest_payment_id
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; payments&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that you don&#39;t need to specify a &lt;code&gt;group by&lt;/code&gt; clause for the overall query in this case.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="postgresql"/>
      
      <summary type="html">TIL: How to get the first entry from each group given a sort order</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Navigate to a path in Mac Finder</title>
      <link href="https://varunbarad.com/blog/til-navigate-path-mac-finder.html" rel="alternate" type="text/html" title="📝 Navigate to a path in Mac Finder"/>
      <published>2023-03-14T18:32:10+05:30</published>
      <updated>2023-03-14T18:32:10+05:30</updated>
      <id>https://varunbarad.com/blog/til-navigate-path-mac-finder.html</id>
      <content type="html">
      &lt;p&gt;For many years I had a slight frustration with Mac&#39;s default file explorer utility Finder that it was not exposing any convenient way to go to a given path without making me click through those folders individually.&lt;/p&gt;
&lt;p&gt;Today I learnt that the way to do it is to press &lt;code&gt;Cmd + Shift + G&lt;/code&gt; when Finder is in focus. It opens a dialogue box where you can give the full path, and it will open that directly.&lt;/p&gt;
&lt;img alt=&quot;Screenshot of the opened dialog box&quot; src=&quot;https://varunbarad.com/assets/images/posts/til-navigate-path-mac-finder/screenshot.png&quot; style=&quot;width: 80%; height: auto;&quot; /&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to navigate to a given system path without clicking through folders</summary>
    </entry>
  
    
    <entry>
      <title type="html">Contacts Calendar</title>
      <link href="https://varunbarad.com/blog/contacts-calendar.html" rel="alternate" type="text/html" title="Contacts Calendar"/>
      <published>2023-03-04T17:18:03+05:30</published>
      <updated>2023-03-04T17:18:03+05:30</updated>
      <id>https://varunbarad.com/blog/contacts-calendar.html</id>
      <content type="html">
      &lt;p&gt;I store birthdays of my contacts right in my contacts application on phone. They get synced to Google Contacts.&lt;/p&gt;
&lt;p&gt;The drawback to that is I didn&#39;t get notified of any upcoming birthdays. Google does show this in your calendar, but I don&#39;t use my Google calendar as my day-to-day calendar.&lt;/p&gt;
&lt;p&gt;So I decided to build a service of my own which would let me export these into separate calendar feeds. You can go to &lt;a href=&quot;https://contacts-calendar.varunbarad.com/&quot;&gt;Contacts Calendar&lt;/a&gt; to try it out for yourself.&lt;/p&gt;
&lt;p&gt;Keeping user&#39;s privacy in mind, this project does not store authentication token for your Google account, nor does it store your contacts data. It even gives you the calendar feed file and does not directly host it on the web.  That also allowed me to side-step thinking about maintaining user accounts and data.&lt;/p&gt;
&lt;p&gt;I used this also as an opportunity to learn the basics of Spring Boot framework using Kotlin.&lt;/p&gt;
&lt;p&gt;Check it out and let me know what you like and what you would like to change about it. At the very least, have fun.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="web"/>
      
      <category term="programming"/>
      
      <category term="project"/>
      
      <summary type="html">A website which lets you export a calendar of important dates from your Google Contacts</summary>
    </entry>
  
    
    <entry>
      <title type="html">Cheatsheet - ffmpeg</title>
      <link href="https://varunbarad.com/blog/cheatsheet-ffmpeg.html" rel="alternate" type="text/html" title="Cheatsheet - ffmpeg"/>
      <published>2023-02-25T10:36:10+05:30</published>
      <updated>2023-02-25T10:36:10+05:30</updated>
      <id>https://varunbarad.com/blog/cheatsheet-ffmpeg.html</id>
      <content type="html">
      &lt;h2&gt;Extract audio from .webm to .mp3&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;FILE&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;the-file-you-want-to-process.webm&quot;&lt;/span&gt;
ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;${FILE}&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-vn&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-ab&lt;/span&gt; 128k &lt;span class=&quot;token parameter variable&quot;&gt;-ar&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;44100&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-y&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;${FILE&lt;span class=&quot;token operator&quot;&gt;%&lt;/span&gt;.webm}&lt;/span&gt;.mp3&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Credits: &lt;a href=&quot;https://bytefreaks.net/gnulinux/bash/ffmpeg-extract-audio-from-webm-to-mp3&quot;&gt;Bytefreaks.net&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Merge subtitle (srt) files with video files&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; video.mp4 &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; subtitle.srt &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy &lt;span class=&quot;token parameter variable&quot;&gt;-c:s&lt;/span&gt; mov_text -metadata:s:s:0 &lt;span class=&quot;token assign-left variable&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;eng -metadata:s:s:0 &lt;span class=&quot;token assign-left variable&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;English&quot;&lt;/span&gt; merged.mp4&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Credits: &lt;a href=&quot;https://superuser.com/a/520555&quot;&gt;StackExchange&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Convert .mkv to .mp4&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.mkv &lt;span class=&quot;token parameter variable&quot;&gt;-c:v&lt;/span&gt; copy &lt;span class=&quot;token parameter variable&quot;&gt;-c:a&lt;/span&gt; copy output.mp4&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Extract text subtitles from a video file to separate .srt files&lt;/h2&gt;
&lt;p&gt;This uses &lt;code&gt;ffprobe&lt;/code&gt; and &lt;code&gt;jq&lt;/code&gt; to extract the subtitle streams from the input file and then uses &lt;code&gt;ffmpeg&lt;/code&gt; to extract the subtitle streams to separate files.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Assuming the file is named input.mkv&lt;/span&gt;
ffprobe &lt;span class=&quot;token parameter variable&quot;&gt;-hide_banner&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-loglevel&lt;/span&gt; quiet &lt;span class=&quot;token parameter variable&quot;&gt;-select_streams&lt;/span&gt; s &lt;span class=&quot;token parameter variable&quot;&gt;-show_entries&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;codec_name,codec_type:stream_tags&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;language &lt;span class=&quot;token parameter variable&quot;&gt;-print_format&lt;/span&gt; json input.mkv &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; jq &lt;span class=&quot;token string&quot;&gt;&quot;.streams | to_entries | map({codec_name: .value.codec_name, language:(.value.tags.language // &lt;span class=&quot;token entity&quot; title=&quot;&#92;&amp;quot;&quot;&gt;&#92;&quot;&lt;/span&gt;sub&lt;span class=&quot;token entity&quot; title=&quot;&#92;&amp;quot;&quot;&gt;&#92;&quot;&lt;/span&gt;), index:.key})[] | select(.codec_name == &lt;span class=&quot;token entity&quot; title=&quot;&#92;&amp;quot;&quot;&gt;&#92;&quot;&lt;/span&gt;subrip&lt;span class=&quot;token entity&quot; title=&quot;&#92;&amp;quot;&quot;&gt;&#92;&quot;&lt;/span&gt;) | &lt;span class=&quot;token entity&quot; title=&quot;&#92;&amp;quot;&quot;&gt;&#92;&quot;&lt;/span&gt;&#92;(.language)&#92;(.index)&lt;span class=&quot;token entity&quot; title=&quot;&#92;&amp;quot;&quot;&gt;&#92;&quot;&lt;/span&gt;&quot;&lt;/span&gt; --raw-output &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;xargs&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-L1&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-I&lt;/span&gt; % &lt;span class=&quot;token parameter variable&quot;&gt;-t&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;zsh&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;ffmpeg -hide_banner -loglevel quiet -i input.mkv -map 0:s:$(echo % | sed &quot;s/[^0-9]//g&quot;) %.srt&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Embed thumbnail into an mp4 video file&lt;/h2&gt;
&lt;p&gt;Here we want to apply thumbnail from &lt;code&gt;image.png&lt;/code&gt; to &lt;code&gt;input.mp4&lt;/code&gt; and save the result to &lt;code&gt;output.mp4&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.mp4 &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; image.png &lt;span class=&quot;token parameter variable&quot;&gt;-map&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-map&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy &lt;span class=&quot;token parameter variable&quot;&gt;-disposition:0&lt;/span&gt; attached_pic output.mp4
&lt;span class=&quot;token comment&quot;&gt;# Note: attached_pic here is a keyword to the disposition option&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Credits: &lt;a href=&quot;https://stackoverflow.com/a/54719926/4717436&quot;&gt;StackOverflow&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Remove chapters from a video file&lt;/h2&gt;
&lt;p&gt;Here we want to remove embedded chapter markings from &lt;code&gt;input.mp4&lt;/code&gt; and save the result to &lt;code&gt;output.mp4&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.mp4 &lt;span class=&quot;token parameter variable&quot;&gt;-map_chapters&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-1&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy output.mp4&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Delay subtitles&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-itsoffset&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;amount-to-delay-in-seconds&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.srt &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy output.srt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create a new file &lt;code&gt;output.srt&lt;/code&gt; with all subtitles delayed by the specified amount. You can use this command to delay subtitles by any amount of seconds. Negative and decimal values are also supported. For example:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# This would delay the subtitles by 2.5 seconds&lt;/span&gt;
ffmpeg &lt;span class=&quot;token parameter variable&quot;&gt;-itsoffset&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.5&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; input.srt &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; copy output.srt&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="cheat-sheet"/>
      
      <summary type="html">A cheat-sheet for ffmpeg</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Most used commands</title>
      <link href="https://varunbarad.com/blog/til-most-used-commands.html" rel="alternate" type="text/html" title="📝 Most used commands"/>
      <published>2023-02-10T11:04:06+05:30</published>
      <updated>2023-02-10T11:04:06+05:30</updated>
      <id>https://varunbarad.com/blog/til-most-used-commands.html</id>
      <content type="html">
      &lt;p&gt;Use this command to view the top-5 most used commands on your Mac terminal&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;awk&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;BEGIN {FS=&quot;[ &#92;t]+|&#92;&#92;|&quot;} {print $5}&#39;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;uniq&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--count&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--reverse&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--sort&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;numeric &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;head&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--lines&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to view your most used terminal commands on a Mac</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 wget with custom filename</title>
      <link href="https://varunbarad.com/blog/til-wget-custom-filename.html" rel="alternate" type="text/html" title="📝 wget with custom filename"/>
      <published>2023-02-08T14:59:48+05:30</published>
      <updated>2023-02-08T14:59:48+05:30</updated>
      <id>https://varunbarad.com/blog/til-wget-custom-filename.html</id>
      <content type="html">
      &lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; --output-document &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;filename-goes-here&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--continue&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;file-url-goes-here&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to download a file with wget to a custom filename</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Taking a heap-dump from a running JVM process</title>
      <link href="https://varunbarad.com/blog/til-heap-dump-from-jvm.html" rel="alternate" type="text/html" title="📝 Taking a heap-dump from a running JVM process"/>
      <published>2023-01-19T13:00:00+05:30</published>
      <updated>2023-01-19T13:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-heap-dump-from-jvm.html</id>
      <content type="html">
      &lt;p&gt;I was trying to find the root-cause of a memory leak and amongst many different rabbit holes, I learnt how to take the heap-dump from an application running on JVM.&lt;/p&gt;
&lt;p&gt;The tool used is called &lt;code&gt;jmap&lt;/code&gt; and the exact command to dump the output to a file called &lt;code&gt;heap-dump.bin&lt;/code&gt; is:&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;jmap -dump:all,format&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;b,file&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;heap-dump.bin &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;process-id-of-the-jvm-process&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to take heap-dump from a running JVM process</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Figma styles not present in the API response</title>
      <link href="https://varunbarad.com/blog/til-figma-styles-unavailable-in-api.html" rel="alternate" type="text/html" title="📝 Figma styles not present in the API response"/>
      <published>2022-09-23T13:01:54+05:30</published>
      <updated>2022-09-23T13:01:54+05:30</updated>
      <id>https://varunbarad.com/blog/til-figma-styles-unavailable-in-api.html</id>
      <content type="html">
      &lt;p&gt;So there can be the case that your Figma file is showing that there are styles defined and present in the file, but when querying it via the API endpoint to get file-styles (&lt;code&gt;/v1/files/&amp;lt;file-id&amp;gt;/styles&lt;/code&gt;) it might return empty styles array.&lt;/p&gt;
&lt;p&gt;Simple fix is to go into the Figma file and Publish those styles (you can do it from the drop-down at the top by clicking file&#39;s name).&lt;/p&gt;
&lt;p&gt;Now if you query that endpoint, you will find the published styles available there.&lt;/p&gt;
&lt;h3&gt;Additional text just to help search-engines&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;figma api styles empty&lt;/li&gt;
&lt;li&gt;figma api not returning styles&lt;/li&gt;
&lt;li&gt;no styles present in figma api&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: Why Figma returns empty styles in API and how to fix it</summary>
    </entry>
  
    
    <entry>
      <title type="html">Office Pranks</title>
      <link href="https://varunbarad.com/blog/office-pranks.html" rel="alternate" type="text/html" title="Office Pranks"/>
      <published>2022-09-17T06:40:13+05:30</published>
      <updated>2022-09-17T06:40:13+05:30</updated>
      <id>https://varunbarad.com/blog/office-pranks.html</id>
      <content type="html">
      &lt;p&gt;These are a bunch of simple and harmless (especially HR safe) pranks you can pull on your colleagues:&lt;/p&gt;
&lt;h3&gt;Wear a different name tag every day&lt;/h3&gt;
&lt;p&gt;Come to office with a different name tag stuck to your shirt every day. There are bound to be a few people who might trip up as to what your identity actually is and how to address you.&lt;/p&gt;
&lt;h3&gt;Fake moustaches&lt;/h3&gt;
&lt;p&gt;Just show up with a fake moustache one day. Don&#39;t mention it unless someone asks about it. Some people will do a solid double-take the first time you start speaking in a meeting.&lt;/p&gt;
&lt;h3&gt;Wear multiple name tags&lt;/h3&gt;
&lt;p&gt;In this one you wear multiple different name tags at the same time. And when someone asks you who you are, you just ask them to pick who they want you to be. And each name/character comes with their own different background story and what they do now and stuff like that.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">A list of simple and safe pranks you can pull on your colleagues.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Authentication with wget</title>
      <link href="https://varunbarad.com/blog/til-authentication-with-wget.html" rel="alternate" type="text/html" title="📝 Authentication with wget"/>
      <published>2022-09-04T07:43:54+05:30</published>
      <updated>2022-09-04T07:43:54+05:30</updated>
      <id>https://varunbarad.com/blog/til-authentication-with-wget.html</id>
      <content type="html">
      &lt;p&gt;There are 2 ways to provide username and password when downloading files using wget&lt;/p&gt;
&lt;h2&gt;Directly as parameters&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--user&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;username-goes-here&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--password&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;password-goes-here&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;file-url-goes-here&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This has the disadvantage that it will show up in your shell history and in running processes lists, thus exposing your password.&lt;/p&gt;
&lt;h2&gt;Interactively entering the password&lt;/h2&gt;
&lt;p&gt;Another way is to tell wget to interactively ask you for the password&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--user&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;username-goes-here&gt;&quot;&lt;/span&gt; --ask-password &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;file-url-goes-here&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here instead of the password showing up in your command, wget asks you to enter your password.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to provide username and password for simple authentication when downloading files using wget</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 How to make non-capturing groups in RegEx</title>
      <link href="https://varunbarad.com/blog/til-regex-non-capturing-groups.html" rel="alternate" type="text/html" title="📝 How to make non-capturing groups in RegEx"/>
      <published>2022-08-30T07:44:04+05:30</published>
      <updated>2022-08-30T07:44:04+05:30</updated>
      <id>https://varunbarad.com/blog/til-regex-non-capturing-groups.html</id>
      <content type="html">
      &lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; This is how you surround a regular (capturing) group in regex &lt;code&gt;()&lt;/code&gt;. And this is how you surround a non-capturing group in regex &lt;code&gt;(?:)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I had to write a regex to extract an ID from a URL. The URL could come in either of the below form&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;https://www.randomwebsite.com/file_64fe4cd
or
https://randomwebsite.com/file_64fe4cd
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I had to extract out only the &lt;code&gt;file_64fe4cd&lt;/code&gt; part from it.&lt;/p&gt;
&lt;p&gt;I started with this regex:&lt;/p&gt;
&lt;pre class=&quot;language-regexp&quot;&gt;&lt;code class=&quot;language-regexp&quot;&gt;^https://(www&#92;.)?randomwebsite.com/(file_&#92;w+)$&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem this was giving me was it was providing two captured groups. One for the &lt;code&gt;(www&#92;.)?&lt;/code&gt; and the other one for &lt;code&gt;(file_&#92;w+)&lt;/code&gt; (the one I wanted).&lt;/p&gt;
&lt;p&gt;I wanted to treat the first group as a group (for whether it could be present) but not have it captured. That&#39;s how I got to know about non-capturing groups in regex. This is how you write a non-capturing group:&lt;/p&gt;
&lt;pre class=&quot;language-regexp&quot;&gt;&lt;code class=&quot;language-regexp&quot;&gt;(?:&lt;rest-of-your-group-match-here&gt;)&lt;/rest-of-your-group-match-here&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So our regex now becomes&lt;/p&gt;
&lt;pre class=&quot;language-regexp&quot;&gt;&lt;code class=&quot;language-regexp&quot;&gt;^https://(?:www&#92;.)?randomwebsite.com/(file_&#92;w+)$&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: What are non-capturing groups and how we can use them</summary>
    </entry>
  
    
    <entry>
      <title type="html">Useful fonts</title>
      <link href="https://varunbarad.com/blog/useful-fonts.html" rel="alternate" type="text/html" title="Useful fonts"/>
      <published>2022-08-12T00:00:00+05:30</published>
      <updated>2022-08-12T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/useful-fonts.html</id>
      <content type="html">
      &lt;p&gt;This is a list of interesting/useful fonts which can be used:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Saira?sort=popularity&amp;amp;preview.text=Workout%20Log&amp;amp;preview.text_type=custom&quot;&gt;Saira&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Chakra+Petch?sort=popularity&amp;amp;preview.text=Workout%20Log&amp;amp;preview.text_type=custom&quot;&gt;Chakra Petch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Cinzel?sort=popularity&amp;amp;preview.text=Workout%20Log&amp;amp;preview.text_type=custom&quot;&gt;Cinzel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://rostype.com/lkdown/&quot;&gt;Lkdown&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://wehtt.am/fonts/#graph&quot;&gt;Graph&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://wehtt.am/fonts/#katwijk-mono&quot;&gt;Katwijk Mono&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://simplebits.shop/products/turbeau&quot;&gt;Turbeu&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://simplebits.shop/products/parkly?variant=43482079002839&quot;&gt;Parkly&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">A list of useful fonts which can be used.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 India&#39;s national aquatic animal</title>
      <link href="https://varunbarad.com/blog/til-indias-national-aquatic-animal.html" rel="alternate" type="text/html" title="📝 India&#39;s national aquatic animal"/>
      <published>2022-07-12T00:00:00+05:30</published>
      <updated>2022-07-12T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-indias-national-aquatic-animal.html</id>
      <content type="html">
      &lt;p&gt;Today (well actually this past Sunday) I learned that nations also have something known as their &amp;quot;National Aquatic Animal&amp;quot; (NAA).&lt;/p&gt;
&lt;p&gt;I was visiting the &lt;a href=&quot;https://sciencecity.gujarat.gov.in/ticketing/ticket/aquatic-gallery-41&quot;&gt;aquatic gallery&lt;/a&gt; (a recent addition) of &lt;a href=&quot;https://sciencecity.gujarat.gov.in/home&quot;&gt;Science City&lt;/a&gt; near me and found out that besides just plain old dolphins that we hear/see about there is also something called River Dolphins and that India&#39;s National Aquatic Animal is actually a &lt;strong&gt;River Dolphin&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Later looking up on Wikipedia I found that it is specifically the &lt;a href=&quot;https://en.wikipedia.org/wiki/Ganges_river_dolphin&quot;&gt;Ganges (Platanista gangetica)&lt;/a&gt; variant that is India&#39;s NAA.&lt;/p&gt;
&lt;p&gt;PS: If you are in Gujarat, India then you should definitely take out a day and visit the Science City in Ahmedabad (&lt;a href=&quot;https://goo.gl/maps/kHXJnbhLNF2D8z557&quot;&gt;Google Maps link&lt;/a&gt;).&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: India has a species of dolphin as its national aquatic animal.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Safe alphanumeric password base</title>
      <link href="https://varunbarad.com/blog/safe-alphanumeric-password-base.html" rel="alternate" type="text/html" title="Safe alphanumeric password base"/>
      <published>2022-03-29T00:00:00+05:30</published>
      <updated>2022-03-29T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/safe-alphanumeric-password-base.html</id>
      <content type="html">
      &lt;p&gt;The below collection of characters are readable and individually distinguishable to make alphanumeric passwords out of&lt;/p&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;abcdefghjkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXY3456789&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">Collection of readable characters to make alphanumeric passwords out of</summary>
    </entry>
  
    
    <entry>
      <title type="html">🎲 Improvement Roll</title>
      <link href="https://varunbarad.com/blog/improvement-roll.html" rel="alternate" type="text/html" title="🎲 Improvement Roll"/>
      <published>2021-11-22T00:00:00+05:30</published>
      <updated>2021-11-22T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/improvement-roll.html</id>
      <content type="html">
      &lt;p&gt;So I finally finished a side-project after a long time and rolled it out public. You can find it &lt;a href=&quot;https://improvement-roll.varunbarad.com/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It is a tiny website which suggests you useful things you can do in your down-time instead of letting it be sucked in the maw of social media.&lt;/p&gt;
&lt;p&gt;The idea for this came when I saw an app by the same name on the F-Droid store. The experience I wanted was a bit different from what I had with that app and also I thought that this was so trivial that it didn&#39;t need a full-fledged native app and that just a simple website should do the trick.&lt;/p&gt;
&lt;p&gt;So I set out to building it. As with some of my other frontend related stuff, my aim was to keep this thing as less dependent on external libraries as I can (0 external dependencies sounds perfect for something of this size). Ended up not importing any external libraries/frameworks in either JS or CSS land.&lt;/p&gt;
&lt;p&gt;Later I thought that it would be awesome if I could access it offline too, if it has loaded itself in my browser once before. And so I looked into PWAs and implemented the simplest version I could find online to just setup a basic cache using the service-worker so that if the website has been loaded once in your browser it will load fine even if there is no internet connection.&lt;/p&gt;
&lt;p&gt;After doing all that it occurred to me, this website might turn out to be something completely useless to people who have JS disabled in their browsers. So I started thinking as to what value I can provide to users with JS even though the whole core of this is built using conditionals and random number generators and other stuff which can&#39;t be replicated with just HTML &amp;amp; CSS. So then I landed on the idea to provide &lt;code&gt;&amp;lt;details&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt; tags for each block of time where the whole list of that tasks for that time-block will be visible.&lt;/p&gt;
&lt;h2&gt;Articles on this project&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Public release (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://varunbarad.com/blog/improvement-roll-custom-tasks&quot;&gt;Adding custom tasks&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="javascript"/>
      
      <category term="web"/>
      
      <category term="programming"/>
      
      <category term="project"/>
      
      <category term="improvement-roll"/>
      
      <summary type="html">A tiny website to suggest you useful things to do in down-time</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 List files updated in a git commit</title>
      <link href="https://varunbarad.com/blog/til-list-files-in-a-git-commit.html" rel="alternate" type="text/html" title="📝 List files updated in a git commit"/>
      <published>2021-11-17T00:00:00+05:30</published>
      <updated>2021-11-17T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-list-files-in-a-git-commit.html</id>
      <content type="html">
      &lt;p&gt;I wanted to see the list of files committed in my last commit&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; show &lt;span class=&quot;token parameter variable&quot;&gt;--pretty&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt; --name-only &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;sha1-commit-hash&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to see a list of files updated in a git commit</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Centering elements with CSS</title>
      <link href="https://varunbarad.com/blog/til-centering-elements-with-css.html" rel="alternate" type="text/html" title="📝 Centering elements with CSS"/>
      <published>2021-10-31T00:00:00+05:30</published>
      <updated>2021-10-31T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-centering-elements-with-css.html</id>
      <content type="html">
      &lt;p&gt;We can use flexbox to do this. &lt;code&gt;#parent&lt;/code&gt; is the container element inside which to center the &lt;code&gt;#child&lt;/code&gt; element.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;#parent&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;justify-content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;align-items&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to center (horizontally and vertically) elements with CSS.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Cheatsheet - ImageMagick</title>
      <link href="https://varunbarad.com/blog/cheatsheet-imagemagick.html" rel="alternate" type="text/html" title="Cheatsheet - ImageMagick"/>
      <published>2021-10-17T00:00:00+05:30</published>
      <updated>2021-10-17T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/cheatsheet-imagemagick.html</id>
      <content type="html">
      &lt;h2&gt;Resize images to specific target size while padding remaining space with transparency&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;convert -auto-orient &lt;span class=&quot;token parameter variable&quot;&gt;-background&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#00000000&quot;&lt;/span&gt; original.jpg &lt;span class=&quot;token parameter variable&quot;&gt;-resize&lt;/span&gt; 720x576 &lt;span class=&quot;token parameter variable&quot;&gt;-gravity&lt;/span&gt; center &lt;span class=&quot;token parameter variable&quot;&gt;-extent&lt;/span&gt; 720x576 resized.png&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Resize all images of a file-type inside a folder&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token for-or-select variable&quot;&gt;PHOTO&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; *.jpg
&lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
    convert -auto-orient &lt;span class=&quot;token parameter variable&quot;&gt;-background&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#00000000&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;$PHOTO&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-resize&lt;/span&gt; 720x576 &lt;span class=&quot;token parameter variable&quot;&gt;-gravity&lt;/span&gt; center &lt;span class=&quot;token parameter variable&quot;&gt;-extent&lt;/span&gt; 720x576 &lt;span class=&quot;token string&quot;&gt;&quot;resized/&lt;span class=&quot;token variable&quot;&gt;$PHOTO&lt;/span&gt;.png&quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;done&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Replace a color in image with different color&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;convert input.png &lt;span class=&quot;token parameter variable&quot;&gt;-fuzz&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;90&lt;/span&gt;% &lt;span class=&quot;token parameter variable&quot;&gt;-fill&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#628FDB&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-opaque&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#000000&quot;&lt;/span&gt; star_blue.png&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fuzz&lt;/code&gt;: Percentage matching of the color&lt;/li&gt;
&lt;li&gt;&lt;code&gt;opaque&lt;/code&gt;: Color to replace&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fill&lt;/code&gt;: Color to replace with&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Reverse the RGB colors in an image&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;convert input.png &lt;span class=&quot;token parameter variable&quot;&gt;-channel&lt;/span&gt; RGB &lt;span class=&quot;token parameter variable&quot;&gt;-negate&lt;/span&gt; output.png&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Resize image and then crop center to fit target size&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;convert original.jpg &lt;span class=&quot;token parameter variable&quot;&gt;-resize&lt;/span&gt; 720x576^ &lt;span class=&quot;token parameter variable&quot;&gt;-gravity&lt;/span&gt; center &lt;span class=&quot;token parameter variable&quot;&gt;-crop&lt;/span&gt; 720x576+0+0 +repage resized.png&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Scale (not resize) an image&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick original.webp &lt;span class=&quot;token parameter variable&quot;&gt;-scale&lt;/span&gt; 128x128 scaled.webp&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Get info from an image file&lt;/h2&gt;
&lt;p&gt;Find more details &lt;a href=&quot;https://varunbarad.com/blog/til-image-info-using-imagemagick&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick identify &lt;span class=&quot;token parameter variable&quot;&gt;-format&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;%m %w %h %x %%y&quot;&lt;/span&gt; input.jpg
&lt;span class=&quot;token comment&quot;&gt;# This gives an output like below&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# JPEG 4960 7015 600 600&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;%m&lt;/code&gt;: Format of the image file (&lt;code&gt;JPEG&lt;/code&gt;, &lt;code&gt;PNG&lt;/code&gt;, &lt;code&gt;WEBP&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%w&lt;/code&gt;: Width of the image (in pixels)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%h&lt;/code&gt;: Height of the image (in pixels)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%x&lt;/code&gt;: Resolution/Density in the x direction&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%y&lt;/code&gt;: Resolution/Density in the y direction&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Trim image to central content&lt;/h2&gt;
&lt;p&gt;You can trim the borders/background of an image to only keep the central content. Read &lt;a href=&quot;https://varunbarad.com/blog/til-trim-image-background.html&quot;&gt;here&lt;/a&gt; for more details and example.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;magick input.png &lt;span class=&quot;token parameter variable&quot;&gt;-trim&lt;/span&gt; trimmed.png&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Automation is exciting 🤖&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="cheat-sheet"/>
      
      <category term="imagemagick"/>
      
      <summary type="html">A cheat-sheet for ImageMagick</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Resizing images from command-line</title>
      <link href="https://varunbarad.com/blog/til-resizing-images-from-command-line.html" rel="alternate" type="text/html" title="📝 Resizing images from command-line"/>
      <published>2021-10-08T00:00:00+05:30</published>
      <updated>2021-10-08T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-resizing-images-from-command-line.html</id>
      <content type="html">
      &lt;p&gt;I had to resize a bunch of images today to a specific target size while padding the remaining space with a transparent background. Out came ImageMagick&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;convert -auto-orient &lt;span class=&quot;token parameter variable&quot;&gt;-background&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#00000000&quot;&lt;/span&gt; original.jpg &lt;span class=&quot;token parameter variable&quot;&gt;-resize&lt;/span&gt; 720x576 &lt;span class=&quot;token parameter variable&quot;&gt;-gravity&lt;/span&gt; center &lt;span class=&quot;token parameter variable&quot;&gt;-extent&lt;/span&gt; 720x576 resized.png&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above command would make an output image of 720 x 576 and the remaining space will be padded by transparency (#00000000).&lt;/p&gt;
&lt;p&gt;To do it for all files inside a folder we can use this (here we are only targeting all files ending in &lt;code&gt;.jpg&lt;/code&gt;)&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token for-or-select variable&quot;&gt;PHOTO&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; *.jpg
&lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
    convert -auto-orient &lt;span class=&quot;token parameter variable&quot;&gt;-background&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;#00000000&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;$PHOTO&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-resize&lt;/span&gt; 720x576 &lt;span class=&quot;token parameter variable&quot;&gt;-gravity&lt;/span&gt; center &lt;span class=&quot;token parameter variable&quot;&gt;-extent&lt;/span&gt; 720x576 &lt;span class=&quot;token string&quot;&gt;&quot;resized/&lt;span class=&quot;token variable&quot;&gt;$PHOTO&lt;/span&gt;.png&quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;done&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <category term="imagemagick"/>
      
      <summary type="html">TIL: Resizing images from command-line while centering them and adding a transparent background.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Cheatsheet - YouTube-DL</title>
      <link href="https://varunbarad.com/blog/cheatsheet-youtube-dl.html" rel="alternate" type="text/html" title="Cheatsheet - YouTube-DL"/>
      <published>2021-10-07T00:00:00+05:30</published>
      <updated>2021-10-07T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/cheatsheet-youtube-dl.html</id>
      <content type="html">
      &lt;h2&gt;Use a separate file to record already downloaded URLs&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl --download-archive archive.txt &lt;span class=&quot;token string&quot;&gt;&quot;https://www.youtube.com/watch?v=toVfvRhWbj8&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Read URLs from a file (one URL per line)&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl &lt;span class=&quot;token parameter variable&quot;&gt;-a&lt;/span&gt; links.txt&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Write description to a file&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl --write-description &lt;span class=&quot;token string&quot;&gt;&quot;https://www.youtube.com/watch?v=xxX81WmXjPg&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Embed subtitles&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl --all-subs --embed-subs &lt;span class=&quot;token string&quot;&gt;&quot;https://www.youtube.com/watch?v=xxX81WmXjPg&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Write thumbnail&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl --write-thumbnail &lt;span class=&quot;token string&quot;&gt;&quot;https://www.youtube.com/watch?v=xxX81WmXjPg&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Extract audio from a video (and convert it to mp3)&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl &lt;span class=&quot;token parameter variable&quot;&gt;--format&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;bestaudio/best&#39;&lt;/span&gt; --audio-format &lt;span class=&quot;token string&quot;&gt;&#39;mp3&#39;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;https://www.youtube.com/watch?v=jVfDUvjvUSM&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Download a video and convert it to mp4&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;youtube-dl &lt;span class=&quot;token parameter variable&quot;&gt;--format&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;bestvideo+bestaudio/best&#39;&lt;/span&gt; --recode-video &lt;span class=&quot;token string&quot;&gt;&#39;mp4&#39;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;https://www.youtube.com/watch?v=Jv8KRwF1zQs&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Have fun and be responsible 🤺&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="cheat-sheet"/>
      
      <summary type="html">A cheat-sheet for YouTube-DL CLI</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Comparing two BigDecimal instances</title>
      <link href="https://varunbarad.com/blog/comparing-two-BigDecimal-instances.html" rel="alternate" type="text/html" title="📝 Comparing two BigDecimal instances"/>
      <published>2021-07-29T00:00:00+05:30</published>
      <updated>2021-07-29T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/comparing-two-BigDecimal-instances.html</id>
      <content type="html">
      &lt;p&gt;If you have two instances of BigDecimal as following&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toBigDecimal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7.50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toBigDecimal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems that they are equal in value and should return true when doing &lt;code&gt;a == b&lt;/code&gt; but they don&#39;t. The reason is that &lt;code&gt;b&lt;/code&gt; is more precise than &lt;code&gt;a&lt;/code&gt; and therefore not equal in value.&lt;/p&gt;
&lt;p&gt;So to compare the magnitude of two &lt;code&gt;BigDecimal&lt;/code&gt;s (while ignoring their precision) we need to use &lt;code&gt;a.compareTo(b)&lt;/code&gt;. When both the numbers are same in magnitude &lt;code&gt;compareTo&lt;/code&gt; returns &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So in Kotlin we can create an extension function like this&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; BigDecimal&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isEqualInMagnitude&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;num&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; BigDecimal&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Boolean &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;compareTo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;num&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then when we need to compare two numbers we can simply do&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toBigDecimal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7.50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toBigDecimal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isEqualInMagnitude&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Equal in magnitude&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Magnitudes of both numbers don&#39;t match&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: Turns out that 7.5.toBigDecimal() and 7.50.toBigDecimal() are not equal</summary>
    </entry>
  
    
    <entry>
      <title type="html">Windows Symlink</title>
      <link href="https://varunbarad.com/blog/windows-symlink.html" rel="alternate" type="text/html" title="Windows Symlink"/>
      <published>2021-07-24T00:00:00+05:30</published>
      <updated>2021-07-24T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/windows-symlink.html</id>
      <content type="html">
      &lt;p&gt;&lt;strong&gt;Context:&lt;/strong&gt; Any file appearing to be stored in &lt;code&gt;SourceDirectory&lt;/code&gt; are actually stored in &lt;code&gt;DestinationDirectory&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To create a link from &lt;code&gt;SourceDirectory&lt;/code&gt; to &lt;code&gt;DestinationDirectory&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-batch&quot;&gt;&lt;code class=&quot;language-batch&quot;&gt;&lt;span class=&quot;token command&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;mklink&lt;/span&gt; /&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;full-path-to-SourceDirectory&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&amp;lt;full-path-to-DestinationDirectory&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Have a great day people 👋&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="tools"/>
      
      <summary type="html">How to create a Linux-like symlink on Windows</summary>
    </entry>
  
    
    <entry>
      <title type="html">500 Million, But Not a Single One More</title>
      <link href="https://varunbarad.com/blog/500-million-but-not-a-single-one-more.html" rel="alternate" type="text/html" title="500 Million, But Not a Single One More"/>
      <published>2021-07-18T00:00:00+05:30</published>
      <updated>2021-07-18T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/500-million-but-not-a-single-one-more.html</id>
      <content type="html">
      &lt;p&gt;I found this &lt;strong&gt;awesome&lt;/strong&gt; piece of writing a few months ago on the website &lt;a href=&quot;https://blog.jaibot.com/500-million-but-not-a-single-one-more/&quot;&gt;Almost No One is Evil. Almost Everything is Broken.&lt;/a&gt; and thought of recording a read-through. This is my first go at trying voice-overs. Hope you have fun 🙂&lt;/p&gt;
&lt;p&gt;&lt;audio controls=&quot;&quot; src=&quot;https://varunbarad.com/assets/audio/posts/500-million-but-not-a-single-one-more/500-million-but-not-a-single-one-more.mp3&quot;&gt;
Your browser does not support the &lt;code&gt;audio&lt;/code&gt; element.
&lt;/audio&gt;&lt;/p&gt;
&lt;p&gt;We will never know their names.&lt;/p&gt;
&lt;p&gt;The first victim could not have been recorded, for there was no written language to record it. They were someone’s daughter, or son, and someone’s friend, and they were loved by those around them. And they were in pain, covered in rashes, confused, scared, not knowing why this was happening to them or what they could do about it – victim of a mad, inhuman god. There was nothing to be done – humanity was not strong enough, not aware enough, not knowledgeable enough, to fight back against a monster that could not be seen.&lt;/p&gt;
&lt;p&gt;It was in Ancient Egypt, where it attacked slave and pharaoh alike. In Rome, it effortlessly decimated armies. It killed in Syria. It killed in Moscow.  In India, five million dead. It killed a thousand Europeans every day in the 18th century. It killed more than &lt;em&gt;fifty million&lt;/em&gt; Native Americans. From the Peloponnesian War to the Civil War, it slew more soldiers and civilians than any weapon, any soldier, any army (Not that this stopped the most foolish and empty souls from attempting to harness the demon as a weapon against their enemies).&lt;/p&gt;
&lt;p&gt;Cultures grew and faltered, and it remained. Empires rose and fell, and it thrived. Ideologies waxed and waned, but it did not care. Kill. Maim. Spread. An ancient, mad god, hidden from view, that could not be fought, could not be confronted, could not even be comprehended. Not the only one of its kind, but the most devastating.&lt;/p&gt;
&lt;p&gt;For a long time, there was no hope – only the bitter, hollow endurance of survivors.&lt;/p&gt;
&lt;p&gt;In China, in the 10th century, humanity began to fight back.&lt;/p&gt;
&lt;p&gt;It was observed that survivors of the mad god’s curse would never be touched again: they had taken a portion of that power into themselves, and were so protected from it. Not only that, but this power could be shared by consuming a remnant of the wounds. There was a price, for you could not take the god’s power without first defeating it – but a smaller battle, on humanity’s terms. By the 16th century, the technique spread, to India, across Asia, the Ottoman Empire and, in the 18th century, Europe. In 1796, a more powerful technique was discovered by &lt;a href=&quot;http://en.wikipedia.org/wiki/Edward_Jenner&quot;&gt;Edward Jenner&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;An idea began to take hold: Perhaps the ancient god could be killed.&lt;/p&gt;
&lt;p&gt;A whisper became a voice; a voice became a call; a call became a battle cry, sweeping across villages, cities, nations. Humanity began to cooperate, spreading the protective power across the globe, dispatching masters of the craft to protect whole populations. People who had once been sworn enemies joined in common cause for this one battle. Governments mandated that all citizens protect themselves, for giving the ancient enemy a single life would put millions in danger.&lt;/p&gt;
&lt;p&gt;And, inch by inch, humanity drove its enemy back. Fewer friends wept; Fewer neighbors were crippled; Fewer parents had to bury their children.&lt;/p&gt;
&lt;p&gt;At the dawn of the 20th century, for the first time, humanity banished the enemy from entire regions of the world. Humanity faltered many times in its efforts, but there individuals who never gave up, who fought for the dream of a world where no child or loved one would ever fear the demon ever again. &lt;a href=&quot;http://en.wikipedia.org/wiki/Viktor_Zhdanov&quot;&gt;Viktor Zhdanov&lt;/a&gt;, who called for humanity to unite in a final push against the demon; The great tactician &lt;a href=&quot;http://en.wikipedia.org/wiki/Karel_Ra%C5%A1ka&quot;&gt;Karel Raška&lt;/a&gt;, who conceived of a strategy to annihilate the enemy; &lt;a href=&quot;http://en.wikipedia.org/wiki/Donald_Henderson&quot;&gt;Donald Henderson&lt;/a&gt;, who led the efforts of those final days.&lt;/p&gt;
&lt;p&gt;The enemy grew weaker. Millions became thousands, thousands became dozens. And then, when the enemy did strike, scores of humans came forth to defy it, protecting all those whom it might endanger.&lt;/p&gt;
&lt;p&gt;The enemy’s last attack in the wild was on &lt;a href=&quot;http://en.wikipedia.org/wiki/Ali_Maow_Maalin&quot;&gt;Ali Maow Maalin&lt;/a&gt;, in 1977. For months afterwards, dedicated humans swept the surrounding area, seeking out any last, desperate hiding place where the enemy might yet remain.&lt;/p&gt;
&lt;p&gt;They found none.&lt;/p&gt;
&lt;p&gt;35 years ago, on December 9th, 1979, humanity declared victory.&lt;/p&gt;
&lt;p&gt;This one evil, the horror from beyond memory, the monster that took 500 million people from this world – was destroyed.&lt;/p&gt;
&lt;p&gt;You are a member of the species that did that. Never forget what we are capable of, when we band together and declare battle on what is broken in the world.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Smallpox#Eradication&quot;&gt;Happy Smallpox Eradication Day&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">My first attempt at recording a voice-over of an awesome article</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Castle Under Threat</title>
      <link href="https://varunbarad.com/blog/til-castle-under-threat.html" rel="alternate" type="text/html" title="📝 Castle Under Threat"/>
      <published>2021-06-29T00:00:00+05:30</published>
      <updated>2021-06-29T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-castle-under-threat.html</id>
      <content type="html">
      &lt;p&gt;In one of our chess games at work I learnt that you cannot perform the castle move with King if the blocks where the king has to pass through or end at are under threat from any of opponent&#39;s piece(s).&lt;/p&gt;
&lt;h2&gt;Examples&lt;/h2&gt;
&lt;img alt=&quot;Midway block threatened by queen&quot; src=&quot;https://varunbarad.com/assets/images/posts/castle-under-threat/threat-midway.png&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
We cannot castle in this case because one of the midway blocks is threatened by black queen.
&lt;img alt=&quot;End block threatened by rook&quot; src=&quot;https://varunbarad.com/assets/images/posts/castle-under-threat/threat-end.png&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
We cannot castle in this case because the square where king would end up is threatened by black rook.

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: You cannot castle your king in chess if king&#39;s path is under threat</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Ugh fields</title>
      <link href="https://varunbarad.com/blog/til-ugh-fields.html" rel="alternate" type="text/html" title="📝 Ugh fields"/>
      <published>2021-05-28T00:00:00+05:30</published>
      <updated>2021-05-28T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-ugh-fields.html</id>
      <content type="html">
      &lt;p&gt;I came across this concept the other day called &amp;quot;Ugh Fields&amp;quot;. Basically it points out that there are some/many areas in your life/work which you always flinch away from, they don&#39;t start out that bad but eventually pavlovian conditioning almost turns them into areas that we can&#39;t go into.&lt;/p&gt;
&lt;p&gt;Original article link: &lt;a href=&quot;https://www.lesswrong.com/posts/EFQ3F6kmt4WHXRqik/ugh-fields&quot;&gt;https://www.lesswrong.com/posts/EFQ3F6kmt4WHXRqik/ugh-fields&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is one of the few pieces of writing that I consider a must-read for everyone.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: What are &quot;ugh fields&quot; and why everyone should atleast know about them.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Opening current terminal command in $EDITOR</title>
      <link href="https://varunbarad.com/blog/til-opening-current-terminal-command-in-editor.html" rel="alternate" type="text/html" title="📝 Opening current terminal command in $EDITOR"/>
      <published>2021-05-26T00:00:00+05:30</published>
      <updated>2021-05-26T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-opening-current-terminal-command-in-editor.html</id>
      <content type="html">
      &lt;p&gt;If you are working with a long command in your terminal and want to edit parts of it, &lt;code&gt;Ctrl+X&lt;/code&gt; followed by a &lt;code&gt;Ctrl+E&lt;/code&gt; (don&#39;t lift your finger from &lt;code&gt;Ctrl&lt;/code&gt; between them) will open the command you are currently editing into the program specified in your &lt;code&gt;$EDITOR&lt;/code&gt; environment variable. Tested on zsh and heard that it works on bash too.&lt;/p&gt;
&lt;p&gt;Thanks to my colleague &lt;a href=&quot;https://msfjarvis.dev/&quot;&gt;Harsh&lt;/a&gt; for this tip.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: Ctrl+X followed by Ctrl+E opens the command you are currently editing in your $EDITOR program</summary>
    </entry>
  
    
    <entry>
      <title type="html">🐘 Cheatsheet - PostgreSQL</title>
      <link href="https://varunbarad.com/blog/cheatsheet-postgresql.html" rel="alternate" type="text/html" title="🐘 Cheatsheet - PostgreSQL"/>
      <published>2021-05-17T00:00:00+05:30</published>
      <updated>2021-05-17T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/cheatsheet-postgresql.html</id>
      <content type="html">
      &lt;h2&gt;Dump database to a script (.sql) file&lt;/h2&gt;
&lt;p&gt;Extract/Dump the database contents to a script (.sql) file&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;pg_dump &lt;span class=&quot;token parameter variable&quot;&gt;-f&lt;/span&gt; ~/path/to/file.sql &lt;span class=&quot;token variable&quot;&gt;$YOUR_DATABASE_URL&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Run a script (.sql) from file on a database&lt;/h2&gt;
&lt;p&gt;Run SQL commands from a file on a database&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;psql &lt;span class=&quot;token variable&quot;&gt;$YOUR_DATABASE_URL&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-f&lt;/span&gt; ~/path/to/file.sql&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Check whether there is any row in the table matching your condition&lt;/h2&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; your_table &lt;span class=&quot;token keyword&quot;&gt;where&lt;/span&gt; your_condition&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Use single-quote inside a string&lt;/h2&gt;
&lt;p&gt;Put two single-quotes (&#39;) wherever you want to use a single-quote inside the string&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;where&lt;/span&gt; full_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Travis O&#39;&#39;Connor&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Convert timestamptz to a timestamp in a particular timezone&lt;/h2&gt;
&lt;p&gt;Assuming &lt;code&gt;created_at&lt;/code&gt; is a column in table &lt;code&gt;people&lt;/code&gt; with type &lt;code&gt;timstamptz&lt;/code&gt; and we want to see what those timestamps are in IST (Asia/Kolkata or Asia/Calcutta)&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; created_at at &lt;span class=&quot;token keyword&quot;&gt;time&lt;/span&gt; zone &lt;span class=&quot;token string&quot;&gt;&#39;Asia/Kolkata&#39;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; shifted &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Format timestamp/date&lt;/h2&gt;
&lt;p&gt;Assuming &lt;code&gt;birthdate&lt;/code&gt; is a column in table &lt;code&gt;people&lt;/code&gt; with type &lt;code&gt;date&lt;/code&gt; and we want to display those values in &lt;code&gt;10 Oct 2021&lt;/code&gt; format&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; to_char&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;birthdate&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;DD Mon YYYY&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Refer to &lt;a href=&quot;https://www.postgresql.org/docs/current/functions-formatting.html&quot;&gt;official docs&lt;/a&gt; for more and/or latest details&lt;/p&gt;
&lt;h2&gt;Auto-populate values for created_at and updated_at columns&lt;/h2&gt;
&lt;p&gt;We first need to create a function which would update the value of &lt;code&gt;updated_at&lt;/code&gt; column every time data in a row changes&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;replace&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; update_modified_timestamp&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;returns&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;trigger&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;language&lt;/span&gt; plpgsql &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt;
$$
&lt;span class=&quot;token keyword&quot;&gt;BEGIN&lt;/span&gt;
    new&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;updated_at :&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;current_timestamp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; new&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
$$&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we need to provide default values to columns when defining table schema&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;table&lt;/span&gt; people &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    id &lt;span class=&quot;token keyword&quot;&gt;integer&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;primary&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    created_at timestamptz &lt;span class=&quot;token operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    updated_at timestamptz &lt;span class=&quot;token operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    name &lt;span class=&quot;token keyword&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;null&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At last we need to add a trigger to each table where we want to auto-update the value of &lt;code&gt;updated_at&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;trigger&lt;/span&gt; update_timestamp before &lt;span class=&quot;token keyword&quot;&gt;update&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; people
&lt;span class=&quot;token keyword&quot;&gt;for each row&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;execute&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;procedure&lt;/span&gt; update_modified_timestamp&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Generate list of months between two dates&lt;/h2&gt;
&lt;p&gt;This will give us a list of dates for the first day of every month that falls between &lt;code&gt;earlier_date&lt;/code&gt; and &lt;code&gt;later_date&lt;/code&gt;. Taking the example of &lt;code&gt;earlier_date = &#39;2022-11-16&#39;&lt;/code&gt; and &lt;code&gt;later_date = &#39;2023-02-14&#39;&lt;/code&gt;, it will return November 2022, December 2022, January 2023 and February 2023.&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; generate_series&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    cast&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date_trunc&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;month&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; earlier_date&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    cast&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date_trunc&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;month&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; later_date&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;interval&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;1 month&#39;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Count rows that satisfy a condition&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:center&quot;&gt;payments&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;customer_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_amount&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_date&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If we want to count the number of payments where &lt;code&gt;payment_amount&lt;/code&gt; is greater than 100 then we use a &lt;code&gt;filter&lt;/code&gt; on the &lt;code&gt;count&lt;/code&gt; aggregate:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; customer_id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;payment_id&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; filter &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;where&lt;/span&gt; payment_amount &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; payments
&lt;span class=&quot;token keyword&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; customer_id&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Get first entry in each group&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:center&quot;&gt;payments&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;customer_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_amount&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;payment_date&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If we want to see the payment_id of the highest amount of payment for each customer_id then we need to do:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;distinct&lt;/span&gt; customer_id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    first_value&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;payment_id&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;over&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;partition&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; customer_id &lt;span class=&quot;token keyword&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; payment_amount &lt;span class=&quot;token keyword&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; highest_payment_id
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; payments&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that you don&#39;t need to specify a &lt;code&gt;group by&lt;/code&gt; clause for the overall query in this case.&lt;/p&gt;
&lt;h2&gt;Map an array of ids to matching data from another table&lt;/h2&gt;
&lt;p&gt;If we have two tables, &lt;code&gt;people&lt;/code&gt; and &lt;code&gt;groups&lt;/code&gt;, where &lt;code&gt;people&lt;/code&gt; has a column &lt;code&gt;group_ids&lt;/code&gt; which is an array of ids from &lt;code&gt;groups&lt;/code&gt;, we can map the array of ids to the matching name from &lt;code&gt;groups&lt;/code&gt; using the following query:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt;
    p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;email &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; email&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;coalesce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;groups&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;names&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; group_names

&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; p
    &lt;span class=&quot;token keyword&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; string_agg&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;g&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; names&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; person_id

        &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; entity_groups &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; g
            &lt;span class=&quot;token keyword&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; unnest&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;group_ids&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; group_id
                &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people
            &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; person &lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;group_id &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; g&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id

        &lt;span class=&quot;token keyword&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; groups &lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; groups&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;person_id &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id

&lt;span class=&quot;token keyword&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;by&lt;/span&gt; email&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is a three-step process, listed inside to out (i.e. the innermost query is executed first):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Convert the &lt;code&gt;group_ids&lt;/code&gt; array from &lt;code&gt;people&lt;/code&gt; into a table of &lt;code&gt;person_id&lt;/code&gt; and &lt;code&gt;group_id&lt;/code&gt; using &lt;code&gt;unnest&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Join the &lt;code&gt;group_id&lt;/code&gt; with the &lt;code&gt;id&lt;/code&gt; of &lt;code&gt;groups&lt;/code&gt; to get the &lt;code&gt;name&lt;/code&gt; of the group&lt;/li&gt;
&lt;li&gt;Aggregate the &lt;code&gt;name&lt;/code&gt; of the groups into a comma-separated string using &lt;code&gt;string_agg&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Make a column unique after creating it&lt;/h2&gt;
&lt;p&gt;If we have a table &lt;code&gt;people&lt;/code&gt; with a column &lt;code&gt;email&lt;/code&gt; and we want to make it unique after we have already added it to table:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;table&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;unique&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;email&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Make a colum non-nullable after creating it&lt;/h2&gt;
&lt;p&gt;If we have a table &lt;code&gt;people&lt;/code&gt; with a column &lt;code&gt;email&lt;/code&gt; and we want to make it non-nullable after we have already added it to table:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;table&lt;/span&gt; people &lt;span class=&quot;token keyword&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;column&lt;/span&gt; email &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Sub-string matching&lt;/h2&gt;
&lt;p&gt;If we have a &lt;code&gt;people_info&lt;/code&gt; table with a column email and we only want rows where email contains (but not necessarily is the exact value) &lt;code&gt;varun&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;language-sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; people_info
&lt;span class=&quot;token keyword&quot;&gt;where&lt;/span&gt; email &lt;span class=&quot;token operator&quot;&gt;like&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;%varun%&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Have a great day people 👋&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="cheat-sheet"/>
      
      <category term="postgresql"/>
      
      <summary type="html">A cheat-sheet for PostgreSQL database</summary>
    </entry>
  
    
    <entry>
      <title type="html">Tips when building a PC</title>
      <link href="https://varunbarad.com/blog/tips-when-building-a-pc.html" rel="alternate" type="text/html" title="Tips when building a PC"/>
      <published>2021-05-15T00:00:00+05:30</published>
      <updated>2021-05-15T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/tips-when-building-a-pc.html</id>
      <content type="html">
      &lt;p&gt;One of my friend emailed me today saying that he wants to build a RISC-V PC and was asking for any tips/advice on the basic dos and don&#39;ts and suggested that I &lt;em&gt;can&lt;/em&gt; make it into a blog-post. So following the &lt;a href=&quot;https://www.hanselman.com/blog/do-they-deserve-the-gift-of-your-keystrokes&quot;&gt;conserving the keystrokes rule&lt;/a&gt; from &lt;a href=&quot;https://www.hanselman.com/&quot;&gt;Scott Hanselman&lt;/a&gt; here is the blog post that generated out of it.&lt;/p&gt;
&lt;p&gt;Disclaimer: I have only built one PC so far and it was back in 2013. Haven&#39;t used that one since more than 3 years now but it is still working rock solid for my dad and hasn&#39;t needed a single upgrade ever.&lt;/p&gt;
&lt;p&gt;One of my main philosophies regarding electronics is to buy the best (no-compromises) stuff you can afford at any given time. This pushes back the compulsory-upgrade time much more in future. But always keep your budget in mind. I have no idea about RISC-V, the only PC I ever built was on the x86-64 architecture. Completely uncharted territory there. But these are the points I will take care of when building a PC myself these days.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The most important tip in here is, check that all your components are compatible with each other. Double check it, because this can bite very badly down the road if you find out later that you have a CPU compatible with LGA-1150 socket while your motherboard has a LGA-1155 socket (numbers generated randomly from mind for example&#39;s sake).&lt;/li&gt;
&lt;li&gt;Build only if it is completely essential. Due to silicone chip shortages (this was written in May 2021), prices are skyrocketing way beyond what they should be. The better performers in the market these days are generally a combination of AMD Ryzen CPU with an Nvidia Graphics Card (I suggest going atleast for 30XX series). And both of them are not available for any fair price. I&#39;ve heard that Intel iX series processors are available for reasonable prices (they don&#39;t perform as well as the AMD Ryzens though) so you may go with those if you absolutely need to.&lt;/li&gt;
&lt;li&gt;Make sure that you have a display output. If you are buying a discrete graphics card then all is fine, but if not then make sure that both your processor and your motherboard support onboard display output. Sometimes the motherboard might have a display out but the processor doesn&#39;t support it or other times the processor might support inbuilt graphics but the motherboard might not have any display output port. Currently the AMD Ryzen line-up processors don&#39;t come with inbuilt graphics so they necessarily need an external graphics card, even a pretty old graphics card should work if the only load on it is going to be regular graphics and no heavy gaming/computation or stuff like that. Intel iX series processors do come with onboard graphics, so that is another point in favor of Intel right now.&lt;/li&gt;
&lt;li&gt;4 RAM slots are better than 2 and 2 are better than 1 (but I don&#39;t think any motherboards come with a single RAM slot). Lesson here is, leave room for upgradability in future, and RAM is probably the cheapest thing you can upgrade. Another distinct reason for more slots in case of RAM is that it gives better performance when using say 2x8 GB RAM sticks than a single 16 GB stick because it gives more parallel channels for it to talk with your CPU, therefore better performance.&lt;/li&gt;
&lt;li&gt;Speaking of upgradability, buy a power-supply that is 25-50% above your needs (in terms of power output). So if you think your system would be fine with a 450W power supply, go for a 600W unit. This way when you upgrade your components in future or decide to add more components, you will be covered. Also you don&#39;t want to go for an off-brand or a shady local brand for your power supply, this is a unit which literally has the power to fry your other components if not built correctly. Some reputable brands I can name off hand are: Cooler Master, Seasonic and Corsair.&lt;/li&gt;
&lt;li&gt;Check components compatibility with each other. I mentioned this at the beginning and am still mentioning it again, it is that important.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&#39;s it. Those are all the tips/advice I have right now for someone looking to build a computer for themselves. I will keep adding things here as and when I think appropriate.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">A friend asked me what to look out for when building a PC and this is the list</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 Google gives refresh token only once</title>
      <link href="https://varunbarad.com/blog/til-google-gives-refresh-token-only-once.html" rel="alternate" type="text/html" title="📝 Google gives refresh token only once"/>
      <published>2021-05-06T00:00:00+05:30</published>
      <updated>2021-05-06T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-google-gives-refresh-token-only-once.html</id>
      <content type="html">
      &lt;p&gt;According to Google&#39;s &lt;a href=&quot;https://developers.google.com/identity/protocols/oauth2/web-server&quot;&gt;docs on OAuth&lt;/a&gt;, the server application gets &lt;code&gt;refresh_token&lt;/code&gt; from Google (on exchanging the auth code) only if the original redirection request to Google contains the param &lt;code&gt;access_type&lt;/code&gt; with value &lt;code&gt;offline&lt;/code&gt; (&lt;a href=&quot;https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient&quot;&gt;documentation link&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;But this is only for the first time a user authenticates with your app. If for some reason your flow takes the user through the authentication flow again without having changed anything (user&#39;s Google account, permissions required, etc. Haven&#39;t tested with changed permissions yet but definitely happens when permissions also remain the same) then when you exchange auth code for tokens from Google, the Google servers don&#39;t return the &lt;code&gt;refresh_token&lt;/code&gt; this second time.&lt;/p&gt;
&lt;p&gt;This is based on anecdotal observation, and I couldn&#39;t find any such mention in their documentation. An &lt;a href=&quot;https://stackoverflow.com/questions/10827920/not-receiving-google-oauth-refresh-token/10857806#10857806&quot;&gt;answer on Stack Overflow&lt;/a&gt; confirmed for me that it wasn&#39;t something misconfigured on my end 😅.&lt;/p&gt;
&lt;p&gt;A &amp;quot;solution&amp;quot; for this could be to always specify the param &lt;code&gt;prompt&lt;/code&gt; with a value of &lt;code&gt;consent&lt;/code&gt; in the original redirect request where we send user to Google&#39;s flow.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: Google doesn&#39;t return refresh token on subsequent authentication after the first one.</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 JavaScript can &quot;throw&quot; the table</title>
      <link href="https://varunbarad.com/blog/til-javascript-can-throw-the-table.html" rel="alternate" type="text/html" title="📝 JavaScript can &quot;throw&quot; the table"/>
      <published>2021-05-04T12:00:00+05:30</published>
      <updated>2021-05-04T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-javascript-can-throw-the-table.html</id>
      <content type="html">
      &lt;p&gt;Since JavaScript does not have the concept of a throwable type. Therefore you can throw anything in JavaScript.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;the table&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;stable table&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above code would produce &lt;code&gt;the table&lt;/code&gt; in console logs and not &lt;code&gt;stable table&lt;/code&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: JavaScript can throw anything</summary>
    </entry>
  
    
    <entry>
      <title type="html">📝 CSS support for browser dark-mode preference</title>
      <link href="https://varunbarad.com/blog/til-css-support-browser-dark-mode-preference.html" rel="alternate" type="text/html" title="📝 CSS support for browser dark-mode preference"/>
      <published>2021-05-04T00:00:00+05:30</published>
      <updated>2021-05-04T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/til-css-support-browser-dark-mode-preference.html</id>
      <content type="html">
      &lt;p&gt;There is a simple CSS media query with which we can specify styles only for dark mode or light mode.&lt;/p&gt;
&lt;p&gt;For specifying CSS when dark mode preference is selected.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;prefers-color-scheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dark&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For specifying CSS when light mode preference is selected or no active preference has been expressed.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;prefers-color-scheme&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; light&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Original posting: &lt;a href=&quot;https://twitter.com/varun_barad/status/1190613832575725571&quot;&gt;https://twitter.com/varun_barad/status/1190613832575725571&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="til"/>
      
      <summary type="html">TIL: How to support dark-mode preference of browser via CSS</summary>
    </entry>
  
    
    <entry>
      <title type="html">Why you should own your email address?</title>
      <link href="https://varunbarad.com/blog/why-you-should-own-your-email-address.html" rel="alternate" type="text/html" title="Why you should own your email address?"/>
      <published>2021-03-14T00:00:00+05:30</published>
      <updated>2021-03-14T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/why-you-should-own-your-email-address.html</id>
      <content type="html">
      &lt;p&gt;This week I was talking to a friend and the discussion somehow turned onto emails. Then I started explaining why I think that one should have their email address on their own domain instead of having a generic &amp;quot;some.random.thing@gmail.com&amp;quot; or another such provider&#39;s email address.&lt;/p&gt;
&lt;p&gt;This is built on the backdrop that your email address is basically your identity around the internet and much of your communication and life is now tied into it. The major (and probably the only) reason is this allows you the flexibility if one day that email provider shuts down their business, or the other case (which is way more likely) of your account somehow getting flagged as not following their terms of service (TOS) and them blocking your account.&lt;/p&gt;
&lt;p&gt;Just imagine if you are using &amp;quot;some.random.thing@gmail.com&amp;quot; and due to some weird reason &lt;strong&gt;The Algorithm&lt;/strong&gt; decides that you have violated their TOS and blocks you off. Depending on providers it is &lt;em&gt;probably&lt;/em&gt; possible for you to somehow get that misunderstanding resolved and you regaining access to your account. But if that does not happen then you need to register a new email account and then make sure to update the new email address across &lt;em&gt;all&lt;/em&gt; the account over the internet. There are even some services which don&#39;t make you set a password when you setup account with them but instead email you an OTP every time you want to login. Good luck with those ones.&lt;/p&gt;
&lt;p&gt;If instead your email address is something like &amp;quot;blah@yourdomain.xyz&amp;quot; and it is hosted with say FastMail and they decide that you have violated their TOS then you can just move from them and setup an account with PurelyMail and you will still keep receiving emails on &amp;quot;blah@yourdomain.xyz&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Open offer:&lt;/strong&gt; If I know you and you want to setup your email on your domain then reach out to me and I will guide you through the whole process 🙂.&lt;/p&gt;
&lt;p&gt;That&#39;s it for today, I will update this in future if I happen upon other crucial reasons. In the meantime if you want to discuss this or anything else you can reach out to me on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt; or &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;via email&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">My write-up on reasons why it is better for you to own your email address.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Challenge Update: Two and a Quarter Books</title>
      <link href="https://varunbarad.com/blog/challenge-update-two-and-a-quarter-books.html" rel="alternate" type="text/html" title="Challenge Update: Two and a Quarter Books"/>
      <published>2021-01-10T00:00:00+05:30</published>
      <updated>2021-01-10T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/challenge-update-two-and-a-quarter-books.html</id>
      <content type="html">
      &lt;p&gt;So finally I couldn&#39;t finish the list of books from last post before the year ended. I happened to change a book midway and then the last couple of weeks of the year brought with them a huge adventure at work which took up much more of my time and energy than what I could have anticipated beforehand. So here are some thoughts on what I could read before the year ended.&lt;/p&gt;
&lt;h2&gt;A Caribbean Mystery (Author: Agatha Christie)&lt;/h2&gt;
&lt;p&gt;I picked up this book knowing that Agatha Christie had a detective character in her books named Hercule Poirot. So I was surprised when it became clear to me that the there was no such character in this story. Instead Miss Marple, another famous character of Agatha Christie which I just did not know about, was the protagonist in this crime thriller. And it came as a nice fresh breeze. There was a very stark difference between stratagems that were employed by Miss Marple instead of the ones that I normally saw from Sherlock Holmes. Since Miss Marple has been written an old lady so she was relying mostly on her social skills. This was awesome to read as those skills are something which we can continue to learn from and don&#39;t need to come across crimes for them to be helpful in our regular life.&lt;/p&gt;
&lt;h2&gt;Smarter Faster Better (Author: Charles Duhigg)&lt;/h2&gt;
&lt;p&gt;I continued with this book after I was done with &amp;quot;A Caribbean Mystery&amp;quot; and I don&#39;t have much to report here, this is the quarter book from title.&lt;/p&gt;
&lt;h2&gt;Treasure Island (Robert Louis Stevenson)&lt;/h2&gt;
&lt;p&gt;Once I figured out I won&#39;t be able to get through &amp;quot;Smarter Faster Better&amp;quot; with the additional adventure going on at work I picked up Treasure Island from Robert Louis Stevenson. This was another one of the classic book I had heard about but never read. The best and worst part of the book for me was its language, the language was so antiquated and the vocabulary so highly relied on nautical terms that I had to understand the pages as it was nigh impossible for me to understand lines. All in all, I was able to piece together what happened in the story but it is completely possible that I might have completely misunderstood some particular part of the narration.&lt;/p&gt;
&lt;p&gt;Completing the challenge was a pretty close call as I closed Treasure Island with less than an hour remaining in the year. I somehow managed to truck through more than a third of that book on the last evening of the year.&lt;/p&gt;
&lt;p&gt;I don&#39;t see myself taking on any more such reading challenge for the time to come. Do check back here in a few days as I intend to post a round-up of all the books and/or stories that I read during the last year.&lt;/p&gt;
&lt;p&gt;Bye for now 👋&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">Update on my 2020 year-end reading challenge</summary>
    </entry>
  
    
    <entry>
      <title type="html">2020: Year in review</title>
      <link href="https://varunbarad.com/blog/2020-year-in-review.html" rel="alternate" type="text/html" title="2020: Year in review"/>
      <published>2021-01-09T00:00:00+05:30</published>
      <updated>2021-01-09T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/2020-year-in-review.html</id>
      <content type="html">
      &lt;p&gt;This will be the first year in review I have ever written. And what a year I picked to begin 😅. It was a year of a lot of change and simultaneously I didn&#39;t get the change I was most looking forward to. I&#39;m not willing to go into the dumpster fire this year was overall, but just going to write about my achievements and reflections.&lt;/p&gt;
&lt;h2&gt;Finally landed a new job after months of searching&lt;/h2&gt;
&lt;p&gt;Is the job good/satisfactory? Am I enjoying working there? Yes, and a resounding YES to both the questions. I joined &lt;a href=&quot;https://obvious.in/&quot;&gt;Obvious&lt;/a&gt; right from the beginning of April 2020 and I can say without a doubt that I am working with some of the nicest people on earth. Also each one of them individually is pretty far above the average of what their field has to offer. My job offer was negotiated before this pandemic dropped on humanity and they never went back on the job offer even once the pandemic was acknoledged neither there were any talks of renegotiation.&lt;/p&gt;
&lt;p&gt;This was uncommon (😉) to hear when so many of my friends were facing pay-cuts or some were even on the brink of losing their jobs while simultaneously learning to work from home. I was pretty set for WFH since I worked remotely in my last job too. In case you are looking for any design or engineering related work do check out &lt;a href=&quot;https://obvious.in/&quot;&gt;Obvious&lt;/a&gt;, we are great at what we do.&lt;/p&gt;
&lt;p&gt;Also made a bunch of new professional friends since I joined Obvious.&lt;/p&gt;
&lt;h2&gt;Wrote 21 posts&lt;/h2&gt;
&lt;p&gt;It has always been important to me to articulate and share my thoughts, and I mostly use this website to do that. Slowly I have been getting into the habit of doing that more and more frequently. In 2019, I wrote 12 posts on here and 2020 saw it getting almost doubled to 21 posts over the whole year.&lt;/p&gt;
&lt;p&gt;Some of them were just archived versions of the newsletters I sent. I am also very proud of some others as they were fairly technical and needed research and consolidation on my part.&lt;/p&gt;
&lt;h2&gt;Completed my first fitness challenge&lt;/h2&gt;
&lt;p&gt;In the month of November I took up a challenge of doing 1500 push-ups over the whole month. This was finally the first fitness challenge I took up which did not end up in the Graveyard of Incomplete. There were a few days where I missed that day&#39;s exercise but I was preparing for it by doing more than the minimum required every day since the start. So I was finally able to finish this in the last week of the month.&lt;/p&gt;
&lt;p&gt;There was a happy side-effect of this that I never expected. I was posting my daily update to our work slack and it turned out that my updates and seeing me keep going at my aim was the motivation that helped push a few others also to keep at their targets. Even if for nothing else than this, I would consider the energy well spent.&lt;/p&gt;
&lt;h2&gt;Reading challenge&lt;/h2&gt;
&lt;p&gt;The last time I set a reading challenge for me and was able to see it through was when I decided to read atleast 12 books in the year 2017. This year I happened to visit a Crossword bookstore near the month of October and bought a fresh stack of 8 books. This turned gears in my head that I just had the time to take on a crazy challenge and finish all of them 8 before end of the year (basically 8 books in 8 weeks).&lt;/p&gt;
&lt;p&gt;By the time I finished first one it was clear to me that I won&#39;t be able to read all 8 of them so I changed my goalposts and finally settled on completing 4 out of those 8 books before January starts. Finally managed that in the nick of time with only an hour or two to spare.&lt;/p&gt;
&lt;h2&gt;Android/Flutter/Backend/Slack take your pick&lt;/h2&gt;
&lt;p&gt;Before this year I only knew, from how I could understand different systems, that I was a good general engineer and not someone who would be completely out of their depth if dropped in something different from their core skill. This year I have switched so many platforms and hats (all professionally) that I now have proof (projects I can point to) which assures me that I &lt;em&gt;am&lt;/em&gt; a good engineer and can adapt to fields where I lack previous experience.&lt;/p&gt;
&lt;h2&gt;Participated in a hackathon&lt;/h2&gt;
&lt;p&gt;This was also the year where I ended up in a hackathon for the first time. And what a way to begin the hackathon experience, I entered as a mentor. My favorite moment during the hackathon was when I was helping a student with something and just happened to ask them since when they had been learning Flutter. They answered, &amp;quot;Oh I&#39;ve only started this since April.&amp;quot; That moment was dear to me because April was the month &lt;em&gt;I myself&lt;/em&gt; started taking Flutter seriously 😅.&lt;/p&gt;
&lt;h2&gt;Got more in touch with friends&lt;/h2&gt;
&lt;p&gt;Most of my friends live in different cities and we didn&#39;t used to talk much but when the lockdown started a couple of us took the initiative and started having weekly group video calls to keep in touch with everyone. Glad to say that it is still ongoing.&lt;/p&gt;
&lt;h2&gt;That&#39;s all folks&lt;/h2&gt;
&lt;p&gt;And that is what I remember happening in the past year in my life. Have I forgotten something, do you think this could have been written better. All suggestions are welcome via &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;email&lt;/a&gt; or Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">A review of the year 2020 for me</summary>
    </entry>
  
    
    <entry>
      <title type="html">Java convert LocalDateTime to Instant using ZoneId</title>
      <link href="https://varunbarad.com/blog/java-convert-localdatetime-to-instant-using-zoneid.html" rel="alternate" type="text/html" title="Java convert LocalDateTime to Instant using ZoneId"/>
      <published>2020-12-14T00:00:00+05:30</published>
      <updated>2020-12-14T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/java-convert-localdatetime-to-instant-using-zoneid.html</id>
      <content type="html">
      &lt;p&gt;Last week I was working on something which required me to convert &lt;code&gt;LocalDateTime&lt;/code&gt; to &lt;code&gt;Instant&lt;/code&gt;. The direct conversion APIs that are available needed an instance of &lt;code&gt;ZoneOffset&lt;/code&gt; to perform the conversion. Catch was that I had &lt;code&gt;ZoneId&lt;/code&gt; and not &lt;code&gt;ZoneOffset&lt;/code&gt; there was a tiny round-about way to do so.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Convert &lt;code&gt;LocalDateTime&lt;/code&gt; to &lt;code&gt;ZonedDateTime&lt;/code&gt; using &lt;code&gt;ZoneId&lt;/code&gt; : &lt;code&gt;localDateTime.atZone(zoneId)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Convert &lt;code&gt;ZonedDateTime&lt;/code&gt; to &lt;code&gt;Instant&lt;/code&gt; : &lt;code&gt;zonedDateTime.toInstant()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I don&#39;t know why there isn&#39;t a native API to convert from &lt;code&gt;LocalDateTime&lt;/code&gt; to &lt;code&gt;Instant&lt;/code&gt; directly using a &lt;code&gt;ZoneId&lt;/code&gt;. If you do then I would like to know either via &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;email&lt;/a&gt; or Twitter (&lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;).&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">How to convert from LocalDateTime to Instant using ZoneId without ZoneOffset in Java 8 Time APIs</summary>
    </entry>
  
    
    <entry>
      <title type="html">Cheatsheet - Git</title>
      <link href="https://varunbarad.com/blog/cheatsheet-git.html" rel="alternate" type="text/html" title="Cheatsheet - Git"/>
      <published>2020-12-07T00:00:00+05:30</published>
      <updated>2020-12-07T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/cheatsheet-git.html</id>
      <content type="html">
      &lt;p&gt;This is first in my collection of cheat-sheets. This is here as a blog post until I figure out how to have a separate section just for cheat-sheets and not make them show up in posts, and then find time to implement it. Till then here it is and here it will be updated as and when need arises 🙃&lt;/p&gt;
&lt;h2&gt;Show change-history of a file&lt;/h2&gt;
&lt;p&gt;History of commits where this file was changed. This only gives the commits where it was changed (not the file-diff for those commits)&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; log -- &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;file&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;History of commits with file-diff&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; log &lt;span class=&quot;token parameter variable&quot;&gt;-p&lt;/span&gt; -- &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;file&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;History of commits with file-diff tracked across renames&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; log &lt;span class=&quot;token parameter variable&quot;&gt;--follow&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-p&lt;/span&gt; -- &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;file&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Automatically rearrange fixup commits to their appropriate positions when rebasing&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; rebase &lt;span class=&quot;token parameter variable&quot;&gt;--interactive&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;commit-hash&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--autosquash&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Find which files have had the most commits&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; log &lt;span class=&quot;token parameter variable&quot;&gt;--all&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-M&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-C&lt;/span&gt; --name-only &lt;span class=&quot;token parameter variable&quot;&gt;--format&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;format:&#39;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;$@&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;^$&#39;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;uniq&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;awk&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;BEGIN {print &quot;count&#92;tfile&quot;} {print $1 &quot;&#92;t&quot; $2}&#39;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;tail&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Create an empty commit&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; commit --allow-empty &lt;span class=&quot;token parameter variable&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Commit message goes here&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;List files in a commit&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; show &lt;span class=&quot;token parameter variable&quot;&gt;--pretty&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&quot;&lt;/span&gt; --name-only &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;sha1-commit-hash&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Reset a branch head to a specific commit&lt;/h2&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; checkout &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;branch-name&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; reset &lt;span class=&quot;token parameter variable&quot;&gt;--hard&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;commit-hash&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Reference: &lt;a href=&quot;https://stackoverflow.com/a/7310222/4717436&quot;&gt;stackoverflow&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Make git forget a tracked file&lt;/h2&gt;
&lt;p&gt;Let&#39;s suppose we want to remove &lt;code&gt;file.log&lt;/code&gt; from git tracking but keep it in the file system.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add &lt;code&gt;file.log&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Commit &lt;code&gt;.gitignore&lt;/code&gt; changes&lt;/li&gt;
&lt;li&gt;Execute the command &lt;code&gt;git rm --cached file.log&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Commit the removal of &lt;code&gt;file.log&lt;/code&gt; from git.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Have a great day people 👋&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="cheat-sheet"/>
      
      <summary type="html">A cheat-sheet for git CLI</summary>
    </entry>
  
    
    <entry>
      <title type="html">Challenge Update: The Adventures of Sherlock Holmes</title>
      <link href="https://varunbarad.com/blog/challenge-update-the-adventures-of-sherlock-holmes.html" rel="alternate" type="text/html" title="Challenge Update: The Adventures of Sherlock Holmes"/>
      <published>2020-12-06T00:00:00+05:30</published>
      <updated>2020-12-06T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/challenge-update-the-adventures-of-sherlock-holmes.html</id>
      <content type="html">
      &lt;p&gt;Today I finished the second book for my end of year reading challenge. The Adventure of Sherlock Holmes was a book which I had read previously, but this was probably the first time I was reading it in paperback format. I could remember some stories from my previous reading and would observe the clues alongside Mr Holmes before he explained it to Dr Watson. Then there were others where I would be just as blind as my first read through of the story (in the past) and the bulb would only light up when Holmes gave an explanation as to how he reached to his deductions.&lt;/p&gt;
&lt;p&gt;I still feel as if I am lagging behind in the challenge but there is always hope, and I do hope that I will be completing the remaining two books before the year ends. Or if not by then, then definitely on the first weekend of the new year.&lt;/p&gt;
&lt;p&gt;My progress now looks like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Around the World in 80 Days (Completed)&lt;/li&gt;
&lt;li&gt;The Adventures of Sherlock Holmes (Completed)&lt;/li&gt;
&lt;li&gt;Smarter Faster Better (Somewhere between 15-20% progress in this one)&lt;/li&gt;
&lt;li&gt;A Caribbean Mystery&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Will keep you folks posted on how things progress from here. Bye for now 👋&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">Update on my 2020 year-end reading challenge</summary>
    </entry>
  
    
    <entry>
      <title type="html">Achievement Unlocked: Finished my first exercise challenge</title>
      <link href="https://varunbarad.com/blog/achievement-unlocked-first-exercise-challenge.html" rel="alternate" type="text/html" title="Achievement Unlocked: Finished my first exercise challenge"/>
      <published>2020-11-29T00:00:00+05:30</published>
      <updated>2020-11-29T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/achievement-unlocked-first-exercise-challenge.html</id>
      <content type="html">
      &lt;p&gt;People who know me know that I care about my physical health, and due to that I have taken on numerous fitness challenges in the past to gamify my exercises and to keep myself consistent. But alas most of them have been abandoned midway (if not on exactly the second day).&lt;/p&gt;
&lt;p&gt;This time it was different, the challenge started this time with someone at my work mentioning that we should try and do fitness challenges in November as it is a month of many festivals and sweets in India. We each decided to make our own challenges and so I decided to do a total of 1500 push-ups in the month of November. That turns out to be 50 push-ups per day for 30 days.&lt;/p&gt;
&lt;p&gt;The key difference this time with the challenge was that I was posting daily updates of my progress on our company&#39;s Slack workspace. This kept me accountable in a way that I couldn&#39;t easily afford to not exercise some day because then my colleagues would ask me as to why there was no update.&lt;/p&gt;
&lt;p&gt;For me, the 50 push-ups per day wasn&#39;t the challenging part, I could easily manage that. The challenge was to stick daily to it and thus complete the 1500 in November. I anticipated that despite my best efforts there will be days where I can&#39;t manage to do the day&#39;s 50 (or I just might forget sometimes). Therefore I decided that the least I have to do per day will be 60 push-ups, so as to generate some slack for future me. And I allowed myself to do 50 on a day only if that does not bring down the average till then to 50 or less.&lt;/p&gt;
&lt;p&gt;As I anticipated, there were a few hiccups where twice I could not manage to exercise for 2 days in a row. The first time it happened, it also brought down my average till then to quite below 50 and then I had to climb back from there to get on my regular track (&lt;em&gt;cue hero&#39;s journey music&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;Finally after everything I managed to complete the last of the 1500 push-ups this Friday (3 days earlier than deadline). I also ended up setting a couple of personal-records along the way.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For the first time I did 100 push-ups in a single workout.&lt;/li&gt;
&lt;li&gt;For the first time I did 40 push-ups in a single set (previous best was ~25).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I am now thinking of what to challenge myself with in December. If you folks have any ideas or challenges then shoot them my way via &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;email&lt;/a&gt; or Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="fitness"/>
      
      <category term="personal-growth"/>
      
      <summary type="html">I have taken on many exercise challenges in the past but this is the first time I finished one.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Challenge Update: Around the World in 80 Days</title>
      <link href="https://varunbarad.com/blog/challenge-update-around-the-world-in-80-days.html" rel="alternate" type="text/html" title="Challenge Update: Around the World in 80 Days"/>
      <published>2020-11-17T00:00:00+05:30</published>
      <updated>2020-11-17T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/challenge-update-around-the-world-in-80-days.html</id>
      <content type="html">
      &lt;p&gt;So I finished my first book for the challenge last night. Around the World in 80 Days was definitely a fun read as the story progressed. I couldn&#39;t enjoy it properly from the start because I was constantly comparing it both to the movie and to other suspense adventure stories (but there was no suspense in a way here as I knew that they do end up completing the journey in time).&lt;/p&gt;
&lt;p&gt;One thing I have taken from this 2 weeks&#39; experience is that I am cutting my book numbers for the challenge by half. Otherwise it would just be unnecessarily stressful to juggle this challenge along with all other responsibilities.&lt;/p&gt;
&lt;p&gt;So now I only intend to finish these 4 books before the year ends:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Around the World in 80 Days (Already completed)&lt;/li&gt;
&lt;li&gt;Smarter Faster Better (Somewhere between 15-20% progress in this one)&lt;/li&gt;
&lt;li&gt;The Adventures of Sherlock Holmes&lt;/li&gt;
&lt;li&gt;A Caribbean Mystery&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Will keep you folks posted on how things progress from here. Bye for now 👋&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">Update on my 2020 year-end reading challenge</summary>
    </entry>
  
    
    <entry>
      <title type="html">Postel&#39;s Law</title>
      <link href="https://varunbarad.com/blog/postels-law.html" rel="alternate" type="text/html" title="Postel&#39;s Law"/>
      <published>2020-11-07T00:00:00+05:30</published>
      <updated>2020-11-07T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/postels-law.html</id>
      <content type="html">
      &lt;p&gt;This week I learned about a software principle that aims to make developer&#39;s lives easier. It even seems benevolent in the way that it does not necessarily help the person who tries to follow it, it rather helps the person who has to integrate with the aforementioned person&#39;s code.&lt;/p&gt;
&lt;p&gt;The Postel&#39;s Law (more actually a guideline) was formulated by Jon Postel (an early pioneer of the Internet). It is also known as Robustness Principle.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Be liberal in what you accept, and conservative in what you send.&lt;/p&gt;
&lt;p&gt;Jon Postel&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When I thought a bit about the statement and its implications, it struck me that following this principle makes the developer&#39;s (who tries to follow this) life harder as they have to write extra code that handles all the different kinds of things that they choose to accept as input, and then have to streamline that data into tighter output. But this simplifies other peoples&#39; work who build on top of this work.&lt;/p&gt;
&lt;p&gt;Then the next connection I made from that was that as more and more people try to follow this principle they decrease the entropy of the overall system. Side-note: Entropy in physics roughly is the measure of disorder in a system.&lt;/p&gt;
&lt;h3&gt;Credits and references&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/gonsalves_r&quot;&gt;Rahul Gonsalves&lt;/a&gt; mentioned this law when trying to explain how to design user-friendly input fields.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://devopedia.org/postel-s-law&quot;&gt;Explanation of Postel&#39;s Law on Devopedia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Robustness_principle&quot;&gt;Robustness principle on Wikipedia&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This was an insightful learning for me, do you have any other connections that you might have made off of this. Please let me know (I really want to hear them) via &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;email&lt;/a&gt; or Twitter (&lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;).&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">A good yardstick to increase developer sanity</summary>
    </entry>
  
    
    <entry>
      <title type="html">2020 End of Year Reading Challenge</title>
      <link href="https://varunbarad.com/blog/2020-end-of-year-reading-challenge.html" rel="alternate" type="text/html" title="2020 End of Year Reading Challenge"/>
      <published>2020-10-31T00:00:00+05:30</published>
      <updated>2020-10-31T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/2020-end-of-year-reading-challenge.html</id>
      <content type="html">
      &lt;p&gt;This will be a really short post. I went to a nearby book store this week and bought &lt;em&gt;a few&lt;/em&gt; of books.&lt;/p&gt;
&lt;img alt=&quot;Photo of the books I bought&quot; src=&quot;https://varunbarad.com/assets/images/posts/2020-eoy-reading-challenge/books-all.jpeg&quot; style=&quot;width: 50%; height: auto;&quot; /&gt;
&lt;ul&gt;
&lt;li&gt;A Caribbean Mystery - Agatha Christie&lt;/li&gt;
&lt;li&gt;Smarter Faster Better - Charles Duhigg&lt;/li&gt;
&lt;li&gt;The Adventures of Sherlock Holmes - Arthur Conan Doyle&lt;/li&gt;
&lt;li&gt;The Return of Sherlock Holmes - Arthur Conan Doyle&lt;/li&gt;
&lt;li&gt;His Last Bow - Arthur Conan Doyle&lt;/li&gt;
&lt;li&gt;Around the World in 80 Days - Jules Verne&lt;/li&gt;
&lt;li&gt;Twenty Thousand Leagues Under the Sea - Jules Verne&lt;/li&gt;
&lt;li&gt;Journey to the Centre of the Earth - Jules Verne&lt;/li&gt;
&lt;li&gt;Treasure Island - Robert Louis Stevenson&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The Challenge&lt;/h2&gt;
&lt;p&gt;The challenge I have taken is to read all of these books before the end of this year. This is a stretch goal for me (even considering that I have read the Sherlock stories already) taking into account that I probably haven&#39;t read 8 books during this whole year till now.&lt;/p&gt;
&lt;p&gt;I am excited to see how far I can take this. Will post updates in the coming weeks here, wish me luck ✌️.&lt;/p&gt;
&lt;p&gt;Want to wish me luck for this challenge or have anything else to discuss, then please get in touch via &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;email&lt;/a&gt; or over at Twitter on &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">I went to a nearby bookstore this week and now taking on a reading challenge</summary>
    </entry>
  
    
    <entry>
      <title type="html">Check if your request body is compressed</title>
      <link href="https://varunbarad.com/blog/check-if-your-request-body-is-compressed.html" rel="alternate" type="text/html" title="Check if your request body is compressed"/>
      <published>2020-10-11T00:00:00+05:30</published>
      <updated>2020-10-11T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/check-if-your-request-body-is-compressed.html</id>
      <content type="html">
      &lt;h2&gt;Entering the maze&lt;/h2&gt;
&lt;p&gt;Recently in one of the projects I was trying to make a POST request to an external API. This was my first time using Jersey http client and so when the server responded with an error saying &lt;code&gt;could not find required parameter &amp;quot;code&amp;quot;&lt;/code&gt; I thought there must be something wrong going on with how I was making the request.&lt;/p&gt;
&lt;p&gt;I spent 2 hours on this and even roped in 2 of my senior colleagues into figuring out how to send a simple POST request with a form-encoded request body. We tried all methods listed in the docs. The same way would work with some other API but not with the one we wanted to integrate with.&lt;/p&gt;
&lt;h2&gt;Convolutions by miscommunication&lt;/h2&gt;
&lt;p&gt;The most confusing part was that the errors it threw didn&#39;t make much sense, since even the errors didn&#39;t align with what we expected them to be. We needed to pass 4 parameters and here&#39;s what some of the errors we found out were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Included all 4 parameters. Error: &lt;code&gt;could not find required parameter &amp;quot;code&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Supplied only the &lt;code&gt;code&lt;/code&gt; parameter. Error: &lt;code&gt;illegal arguments&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Started adding all the 4 parameters one-by-one. Error: &lt;code&gt;illegal arguments&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;As soon as we reached all 4 parameters. Error: &lt;code&gt;could not find required parameter &amp;quot;code&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Removed one of the parameters at random. Error: &lt;code&gt;could not find required parameters &amp;quot;code&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Included all 4 parameters but changed the &lt;strong&gt;value&lt;/strong&gt; of &lt;code&gt;code&lt;/code&gt;. Error: &lt;code&gt;illegal arguments&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The ray of hope&lt;/h2&gt;
&lt;p&gt;This was so bizarre that all 3 of us were confused with the behavior. Then one of the colleagues added a logger to the jersey client and figured out that the request body was getting compressed with gzip. It is a standard practice to compress API responses with gzip but this was the first time I encountered a &lt;strong&gt;request&lt;/strong&gt; body getting compressed.&lt;/p&gt;
&lt;p&gt;We configured jersey to disable gzip compression for requests and finally the API could understand what we were trying to speak to it. Phew.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;When an API says it can&#39;t read what you are sending it and you are confident that you are sending it the data as it requested then first thing you should check is whether your request body is getting compressed or not and whether the API supports taking in gzipped requests.&lt;/p&gt;
&lt;p&gt;Found this confusing maze interesting and have something of yours to share (or even if you just wanna talk) then you have my standing invitation to get in touch with me over &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt; on Twitter.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">Make sure to know what is the default request body compression setting in your http library is</summary>
    </entry>
  
    
    <entry>
      <title type="html">Techniques to Improve Focus</title>
      <link href="https://varunbarad.com/blog/techniques-to-improve-focus.html" rel="alternate" type="text/html" title="Techniques to Improve Focus"/>
      <published>2020-08-21T00:00:00+05:30</published>
      <updated>2020-08-21T00:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/techniques-to-improve-focus.html</id>
      <content type="html">
      &lt;p&gt;Recently I realized that my attention span and ability to focus have drastically reduced over the past 2 years. I initially waved it off as just my brain not being interested in those particular tasks but it became worrisome when I observed similarly high distractability for even stuff that I enjoy(ed). That and the loss of ability (to focus) being an impediment in me achieving my best finally got me to take this seriously. Luckily I also happened to stumble on an &lt;a href=&quot;https://www.buzzsprout.com/1121972/4005569-improving-concentration-influential-books-and-figuring-out-what-to-focus-on-deep-questions&quot;&gt;episode of Dr Cal Newport&#39;s podcast &amp;quot;Deep Questions&amp;quot;&lt;/a&gt; where he tackles a similar question from someone else.&lt;/p&gt;
&lt;p&gt;Dr Newport mentions that it is a good idea to train your concentration like an athlete would prepare for their sport. Athletes train themselves in 2 ways to keep in shape. There is the general fitness training which keeps their baseline in good form, and then they train specifically for the sport that they compete in. Similarly we also need to train our focus in 2 ways.&lt;/p&gt;
&lt;p&gt;The general fitness training maps to &amp;quot;allow ourselves to be bored&amp;quot;. You should allow yourselves time where your brain gets bored of the thing it is doing without giving it something else to focus on while doing that task. For example if you are cleaning the dishes, don&#39;t put on any music or podcast or audiobook in the background to listen to while cleaning the dishes. It is a boring task but allowing yourself to get bored in that way helps in breaking the &lt;a href=&quot;https://en.wikipedia.org/wiki/Classical_conditioning&quot;&gt;pavlovian cycle&lt;/a&gt; that your brain has adapted to: whenever I get bored, that boredom can be cured by some stimulus.&lt;/p&gt;
&lt;p&gt;Now you might ask as to why is it necessary to break that particular cycle? The answer to that is that the work you do on a day to day basis is not always stimulating which will cause you to get bored. If always that our mind gets bored we provide it with some stimulation it will expect similar stimuli while we are trying to work too. Thus distracting us and causing us to lose focus.&lt;/p&gt;
&lt;p&gt;The next part is training specifically for the sport that the athlete competes regularly in. For us it means that we should start small and set periods of time where we try to focus solely on our work. If we get distracted during that time then we don&#39;t count that session, we gotta reset the timer and start it again.&lt;/p&gt;
&lt;p&gt;The above sounds like a simple set of actions to perform but personal experience dictates that it is so not the case. I found both the parts to be non-trivial. It goes so much against my instincts to let myself be bored. I would try to cram a podcast or a book or an article or atleast some music to rid my brain of the mental silence. Then the second part is equally, if not more, difficult. My focus has so deteriorated that I started by setting a 10 min timer to focus solely on a particular task, &lt;strong&gt;and I still failed&lt;/strong&gt;. I have been working to increase that duration over the past week and finally I can regularly hit the 10 min mark without getting distracted (not a big thing for many people but trust me it feels good).&lt;/p&gt;
&lt;p&gt;Feel free to reach out to me to discuss this or anything else under the stars over &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt; on Twitter.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="personal-growth"/>
      
      <summary type="html">How to build your focus muscle when it has atrophied over the years</summary>
    </entry>
  
    
    <entry>
      <title type="html">Interesting Stuff - Week 4</title>
      <link href="https://varunbarad.com/blog/interesting-stuff-week-4.html" rel="alternate" type="text/html" title="Interesting Stuff - Week 4"/>
      <published>2020-07-19T12:00:00+05:30</published>
      <updated>2020-07-19T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/interesting-stuff-week-4.html</id>
      <content type="html">
      &lt;p&gt;Hi folks, these are the interesting things I found during this week.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=eAdanPfQdCA&quot;&gt;The Astounding Physics of N95 Masks&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before seeing this video I used to think that N95 masks worked by having the gaps between their fibers be so thin that particulate matter could not cross it. But it is so not the case. Even if you don&#39;t read/see any of the remaining things, still make time to watch this 6 min video. N95 masks are way cooler than I used to think previously.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://window-swap.com/&quot;&gt;Window Swap&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Feel cooped up in your own home and bored of seeing the same scene outside your window? Try the above website which lets users submit pictures (or ultra-short videos) of scenes from their windows from around the world. It had a calming effect on me. If you can, do submit the scene from your window too (someone might find that captivating).&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0Sz55gmNUaI&quot;&gt;The World&#39;s Largest Indoor Waterpark&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Check out the above video if you want to see how the biggest uninterrupted (no support pillars for the roof) indoor space looks like. It is just a cherry on the top that it happens to be a waterpark, of all things. Fun fact: It is so big to have indoor hot-air balloon rides.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-687-private-pilot-ground-school-january-iap-2019/&quot;&gt;Private Pilot Ground School&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If it is your dream too to someday learn to fly planes then this course offered by MIT might be a good way to cover the ground-school part of flight training. They even called some guest experts for extra sessions. My favorite was the one by Lieutenant Colonel Randy Gordon where he explains F-22 flight controls and his experiences in flying fighter jets (&lt;a href=&quot;https://www.youtube.com/watch?v=Evhrk5tY-Yo&quot;&gt;https://www.youtube.com/watch?v=Evhrk5tY-Yo&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;If you find something interesting and think I should check it out send it over to &lt;a href=&quot;mailto:interesting@varunbarad.com&quot;&gt;interesting@varunbarad.com&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="interesting"/>
      
      <summary type="html">My weekly newsletter of things I found interesting</summary>
    </entry>
  
    
    <entry>
      <title type="html">Interesting Stuff - Week 3</title>
      <link href="https://varunbarad.com/blog/interesting-stuff-week-3.html" rel="alternate" type="text/html" title="Interesting Stuff - Week 3"/>
      <published>2020-07-12T12:00:00+05:30</published>
      <updated>2020-07-12T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/interesting-stuff-week-3.html</id>
      <content type="html">
      &lt;p&gt;Hi folks, these are the interesting things I found during this week.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.bloomberg.com/news/features/2020-07-01/did-china-steal-canada-s-edge-in-5g-from-nortel&quot;&gt;The kind of long game that can be played&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I am not saying that what is written in this article is morally right, heck it can even be incorrect. But all of us can definitely learn some lessons on the scale of long-term game which can be played.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://fs.blog/2015/09/munger-worldly-wisdom/&quot;&gt;Charlie Munger and the Pursuit of Worldly Wisdom&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I was made aware this week that not everyone is familiar with Charlie Munger. So to correct that, here is a short article on why he is not only one of the best investors in the world, but also one of the best thinkers too.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Indian_Financial_System_Code&quot;&gt;Indian Financial System Code&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;During some recent work, I had to deal with users inputting IFS code for their account. I wanted to find out if there is any specified pattern for these codes, and that is how I ended up on this simple Wikipedia page for the same.&lt;/p&gt;
&lt;p&gt;PS: I learned that it is to be spoken as &amp;quot;IFS code&amp;quot; and not as &amp;quot;IFSC code&amp;quot;.&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.sckaiser.com/&quot;&gt;Quantum Computer Programming&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;During one of Twitch raids I came across Twitch office hours session of Dr. Sarah Kaiser. She is an experimental quantum physicist and also works on open-source programs for quantum computers.&lt;/p&gt;
&lt;p&gt;You can find her website at &lt;a href=&quot;https://www.sckaiser.com/&quot;&gt;https://www.sckaiser.com&lt;/a&gt; or join her live on Twitch &lt;a href=&quot;https://www.twitch.tv/crazy4pi314&quot;&gt;@crazy4pi314&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=9XIjqdk69O4&quot;&gt;How are highways designed&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This is an awesome video which shows what all factors are taken into consideration when highways (or more generally any roads) are being designed, what constraints dictate the radius of curve or the angle of a slope.&lt;/p&gt;
&lt;p&gt;If you find something interesting and think I should check it out send it over to &lt;a href=&quot;mailto:interesting@varunbarad.com&quot;&gt;interesting@varunbarad.com&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="interesting"/>
      
      <summary type="html">My weekly newsletter of things I found interesting</summary>
    </entry>
  
    
    <entry>
      <title type="html">Interesting Stuff - Week 2</title>
      <link href="https://varunbarad.com/blog/interesting-stuff-week-2.html" rel="alternate" type="text/html" title="Interesting Stuff - Week 2"/>
      <published>2020-07-05T12:00:00+05:30</published>
      <updated>2020-07-05T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/interesting-stuff-week-2.html</id>
      <content type="html">
      &lt;p&gt;Hi folks, this is the second edition of my new experiment where I list articles, podcasts, videos or basically anything I found interesting during last week.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=OpoLkMcQh24&quot;&gt;The Baboon That Controlled a Railway for 9 Years&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=9Y9ppMqXwkQ&quot;&gt;Autofocusing reading glasses of the future - Nitish Padmanaban&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://karpathy.github.io/2020/06/11/biohacking-lite/&quot;&gt;Biohacking Lite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://thomask.sdf.org/blog/2019/11/09/take-care-editing-bash-scripts.html&quot;&gt;Pitfalls in editing a bash script&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you find something interesting and think I should check it out send it over to &lt;a href=&quot;mailto:interesting@varunbarad.com&quot;&gt;interesting@varunbarad.com&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="interesting"/>
      
      <summary type="html">My weekly newsletter of things I found interesting</summary>
    </entry>
  
    
    <entry>
      <title type="html">Interesting Stuff - Week 1</title>
      <link href="https://varunbarad.com/blog/interesting-stuff-week-1.html" rel="alternate" type="text/html" title="Interesting Stuff - Week 1"/>
      <published>2020-06-28T12:00:00+05:30</published>
      <updated>2020-06-28T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/interesting-stuff-week-1.html</id>
      <content type="html">
      &lt;p&gt;Hi fellows, I am starting a new experiment, where I would be listing some articles, podcasts, videos or basically anything I found interesting that week into a post. Here goes the first edition of that.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://fs.blog/2015/09/two-types-of-knowledge&quot;&gt;Max Planck / Chauffeur Knowledge Test&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://sklum.github.io/2020/06/14/sleep-hygiene-for-software-engineers.html&quot;&gt;Sleep Hygiene for Software Engineers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.nytimes.com/interactive/2020/06/09/magazine/remote-work-covid.html&quot;&gt;Awesome Graphics&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://static01.nyt.com/images/2020/06/14/magazine/14mag-remote/14mag-remote-superJumbo.jpg&quot;&gt;Direct Image Link 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://static01.nyt.com/images/2020/06/14/magazine/14mag-remote-02/14mag-remote-02-superJumbo.jpg&quot;&gt;Direct Image Link 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you find something interesting and think I should check it out send it over to &lt;a href=&quot;mailto:interesting@varunbarad.com&quot;&gt;interesting@varunbarad.com&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="interesting"/>
      
      <summary type="html">My weekly newsletter of things I found interesting</summary>
    </entry>
  
    
    <entry>
      <title type="html">Prevent back navigation to login screen</title>
      <link href="https://varunbarad.com/blog/prevent-back-navigation-to-login-screen.html" rel="alternate" type="text/html" title="Prevent back navigation to login screen"/>
      <published>2020-06-21T12:00:00+05:30</published>
      <updated>2020-06-21T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/prevent-back-navigation-to-login-screen.html</id>
      <content type="html">
      &lt;p&gt;There is a typical use-case in apps where once the user has logged in, you won&#39;t want them to return to login screens when they press back. Instead what you want is to close the app itself.&lt;/p&gt;
&lt;p&gt;I have encountered such a situation many times but learnt this week that the path I was following was way suboptimal and had its flaws. I also got introduced to a much cleaner approach of achieving that.&lt;/p&gt;
&lt;h2&gt;Setup&lt;/h2&gt;
&lt;p&gt;Let us say that our app has 2 activities &lt;code&gt;LoginActivity&lt;/code&gt; and &lt;code&gt;DashboardActivity&lt;/code&gt;. We don&#39;t want anyone to reach &lt;code&gt;DashboardActivity&lt;/code&gt; until they haven&#39;t logged in. And we also want that when user presses back from &lt;code&gt;DashboardActivity&lt;/code&gt; they exit the app instead of going back to the &lt;code&gt;LoginActivity&lt;/code&gt; (normal behavior of pressing back on an activity is to open the previous activity which opened current activity).&lt;/p&gt;
&lt;h2&gt;What I used to do&lt;/h2&gt;
&lt;p&gt;Till now I used to setup &lt;code&gt;LoginActivity&lt;/code&gt; such that it won&#39;t be saved to the back-stack. I used to  set the &lt;code&gt;android:noHistory&lt;/code&gt; flag for &lt;code&gt;LoginActivity&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt; in &lt;code&gt;AndroidManifest.xml&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Atleast I thought that this was just preventing the activity from being placed on back-stack. But what it actually does is tells the system to not maintain any kind of history for instances of this activity class.&lt;/p&gt;
&lt;p&gt;I never realized the problem with this because it worked okay with single-screen login flows (so far I had built only those). The place where this breaks is when you have multiple screens for login implemented via fragments.&lt;/p&gt;
&lt;p&gt;What I started to notice in multi-screen login flow is that once user passes the first screen and then leaves the app (via pressing home-button, thus not actually going back) and come back to it they are brought back to the first fragment in the flow instead of taking them back to the fragment/screen where they left the app.&lt;/p&gt;
&lt;p&gt;The problem here was the android system was completely forgetting everything about the activity as soon as the user left. All it remembered was that this is the activity that user left on and thus when they come back, they have to be shown this activity again.&lt;/p&gt;
&lt;h2&gt;What is the solution for this&lt;/h2&gt;
&lt;p&gt;One of my colleague (&lt;a href=&quot;https://twitter.com/sanchita_ag&quot;&gt;Sanchita&lt;/a&gt;) showed me a much better way to do this. This method does not set any flags on any activity thus they keep their natural behavior of resuming user to the fragment that they left on.&lt;/p&gt;
&lt;p&gt;What you want to do is, once the user is logged-in, you provide a couple of flags to the intent that launches the &lt;code&gt;DashboardActivity&lt;/code&gt;. Those flags tell it to clear the current task and launch our &lt;code&gt;DashboardActivity&lt;/code&gt; on a new task. This new task won&#39;t have the &lt;code&gt;LoginActivity&lt;/code&gt; in its back-stack so when user presses back on &lt;code&gt;DashboardActivity&lt;/code&gt; the app would exit instead of taking them back to &lt;code&gt;LoginActivity&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is how the launching code for &lt;code&gt;DashboardActivity&lt;/code&gt; should look like:&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;startDashboardActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; intent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; DashboardActivity&lt;span class=&quot;token operator&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;java&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  intent&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;flags &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Intent&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;FLAG_ACTIVITY_CLEAR_TASK &lt;span class=&quot;token operator&quot;&gt;or&lt;/span&gt; Intent&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;FLAG_ACTIVITY_NEW_TASK
  context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;startActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;intent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can look at this &lt;a href=&quot;https://stackoverflow.com/a/29565717/4717436&quot;&gt;StackOverflow answer&lt;/a&gt; which explains those flags in much more detail.&lt;/p&gt;
&lt;p&gt;Anyways, this was more as a documentation of my learning than a tutorial so do ask if there was still anything unclear in my explanation.&lt;/p&gt;
&lt;p&gt;Feel free to reach out to me to discuss this or anything else. You can find me on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt; or &lt;a href=&quot;mailto:contact@varunbarad.com&quot;&gt;email me&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <category term="programming"/>
      
      <summary type="html">The guide to correct way of preventing back navigation to login screens once user is logged-in</summary>
    </entry>
  
    
    <entry>
      <title type="html">Foie Gras</title>
      <link href="https://varunbarad.com/blog/foie-gras.html" rel="alternate" type="text/html" title="Foie Gras"/>
      <published>2020-06-17T12:00:00+05:30</published>
      <updated>2020-06-17T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/foie-gras.html</id>
      <content type="html">
      &lt;p&gt;I was listening to the podcast &lt;a href=&quot;https://www.iheart.com/podcast/105-stuff-you-should-know-26940277/&quot;&gt;&amp;quot;Stuff You Should Know&amp;quot;&lt;/a&gt; and today I got across their minisode on &lt;a href=&quot;https://www.iheart.com/podcast/105-stuff-you-should-know-26940277/episode/short-stuff-foie-gras-63697112/&quot;&gt;&amp;quot;Foie Gras&amp;quot;&lt;/a&gt;. Here&#39;s my compilation of what I have remembered from them.&lt;/p&gt;
&lt;p&gt;Foie Gras literally translates to &amp;quot;fatty liver&amp;quot;. It is made by force-feeding birds (primarily geese) which makes their liver fatty. This is an adaptation those birds developed which helps them store extra energy for their seasonal migrations.&lt;/p&gt;
&lt;p&gt;At some point in history, humans figured out that livers with extra fat taste quite different (and tasty to some people). So they started force-feeding geese and presented the dish made from their liver to the local kings. This process of preparation was (and still today is) significantly costlier than regular meat and thus made it popular among people of higher social position as something of a status symbol. Civilisation through civilization it somehow reached France where it got the name we know it today with, Foie Gras.&lt;/p&gt;
&lt;p&gt;Now many people are taking a stance against it saying that it is harmful to the birds because their conditions when they are being force-fed are deplorable. Due to such oppositions serving foie gras is on the roadmap to become illegal somewhere around the year 2022 in parts of US. It is already banned in many other countries of the world.&lt;/p&gt;
&lt;p&gt;There have even been people bringing their own point that it is not as harmful to birds as it looks. They say that since birds don&#39;t share the same tube between oesophagus and trachea, it (apparently) isn&#39;t as uncomfortable for them to have a pipe shoved down their throat as it is for humans. They even say that birds already have the mechanism in them to handle extra food and being overfed doesn&#39;t bother them that much, that they are just accelerating the process that the birds would have naturally done.&lt;/p&gt;
&lt;p&gt;I personally believe that humans can do completely fine without resorting to eat extra fatty liver from birds that have been fed beyond their regular capacity. Feel free to reach out to me to discuss this or anything else under the stars over &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt; on Twitter.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="miscellaneous"/>
      
      <summary type="html">Summary of what I know about Foie Gras, whose literal translation from French is Fatty Liver</summary>
    </entry>
  
    
    <entry>
      <title type="html">Immigration Dead Man&#39;s Switch</title>
      <link href="https://varunbarad.com/blog/immigration-dead-mans-switch.html" rel="alternate" type="text/html" title="Immigration Dead Man&#39;s Switch"/>
      <published>2020-05-16T12:00:00+05:30</published>
      <updated>2020-05-16T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/immigration-dead-mans-switch.html</id>
      <content type="html">
      &lt;p&gt;&lt;strong&gt;Necessary disclaimer:&lt;/strong&gt; I am not a lawyer so please don&#39;t take my statements here on face value, do your own due diligence before pulling off any stunts.&lt;/p&gt;
&lt;p&gt;When passing through customs check, the customs agents have the right to ask for your fingerprint or any other biometrics but they don&#39;t have the right to ask you to enter your password/pin-code.&lt;/p&gt;
&lt;p&gt;So there is an option in both iPhone and Android, check for iPhone but in Android it is called &lt;code&gt;Lockdown Mode&lt;/code&gt;. This makes it so that your phone can only be opened with the designated pin-code or password.&lt;/p&gt;
&lt;p&gt;What I suggest with devices having finger-print or facial unlock, use the biometric lock for daily use and keep a looong passcode.&lt;/p&gt;
&lt;p&gt;One way to memorize a long number is to not use a custom number but to pick one of the constants from Physics/Chemistry/Mathematics. That way even if you forget the exact digits, you can just look up its value online. The security lies in no-one knowing what constant you have used. They don&#39;t even know that you are using a constant. Go for atleast 10-digit pin.&lt;/p&gt;
&lt;p&gt;Then comes the risk of immigration agents detaining you and when you are travelling alone you don&#39;t even have the option to contact your lawyer because the agents might cut your access to your devices too.&lt;/p&gt;
&lt;p&gt;So for this you set something that&#39;s called a &amp;quot;dead man&#39;s switch&amp;quot;. The concept comes from war, here someone rigs up a switch not in the way that when they press it the bomb blasts. But in the way that if they release it, the bomb blasts. So even if someone kills them there is a much higher chance of the bomb going off.&lt;/p&gt;
&lt;p&gt;What you have to do is, right before you enter the immigration check. Message someone you trust that you are about to pass through customs. Give them all the details as to the airport where you are, the flight by which you came, etc. Ask them to contact your lawyer if they don&#39;t hear back from you within a specified time (a couple of hours probably). Then when you are cleared of immigration just let them know that you are out of the hairy-zone.&lt;/p&gt;
&lt;p&gt;I got the idea of this from one of &lt;a href=&quot;https://youtu.be/f-mHLBD64HM?t=195&quot;&gt;CGP Grey&#39;s video&lt;/a&gt; over on YouTube.&lt;/p&gt;
&lt;p&gt;Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="life-hack"/>
      
      <category term="privacy"/>
      
      <summary type="html">How to protect your data and yourself while passing through customs/immigration check</summary>
    </entry>
  
    
    <entry>
      <title type="html">Keep Android screen on When USB is connected</title>
      <link href="https://varunbarad.com/blog/keep-android-screen-on-when-usb-connected.html" rel="alternate" type="text/html" title="Keep Android screen on When USB is connected"/>
      <published>2020-05-11T12:00:00+05:30</published>
      <updated>2020-05-11T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/keep-android-screen-on-when-usb-connected.html</id>
      <content type="html">
      &lt;p&gt;To keep your Android phone screen from turning off when it is connected to your PC and you are using it to debug apps, enter the following command once in your terminal with the device connected.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;adb shell svc power stayon usb&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sets flag inside the device using adb that whenever this device is connected via USB to not turn its screen off automatically.&lt;/p&gt;
&lt;p&gt;Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <category term="programming"/>
      
      <summary type="html">Use the command `adb shell svc power stayon usb`</summary>
    </entry>
  
    
    <entry>
      <title type="html">Write Custom Android Lint Rule - Manifest File</title>
      <link href="https://varunbarad.com/blog/write-custom-android-lint-rule-manifest-file.html" rel="alternate" type="text/html" title="Write Custom Android Lint Rule - Manifest File"/>
      <published>2020-02-28T12:00:00+05:30</published>
      <updated>2020-02-28T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/write-custom-android-lint-rule-manifest-file.html</id>
      <content type="html">
      &lt;p&gt;Welcome folks, last time we wrote a lint check for making sure that all of our &lt;code&gt;EditText&lt;/code&gt; have the &lt;code&gt;android:inputType&lt;/code&gt; attribute.&lt;/p&gt;
&lt;p&gt;This time we will be writing a check which works on our &lt;code&gt;AndroidManifest.xml&lt;/code&gt; file. This check will ensure that our &lt;code&gt;application&lt;/code&gt; tag has a child &lt;code&gt;meta-data&lt;/code&gt; tag with attribute &lt;code&gt;android:name=&amp;quot;android.webkit.WebView.MetricsOptOut&amp;quot;&lt;/code&gt;. Read the background for that &lt;a href=&quot;https://developer.android.com/guide/webapps/managing-webview#metrics&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you haven&#39;t yet then first go through &lt;a href=&quot;https://varunbarad.com/blog/write-custom-android-lint-rule-layout-files&quot;&gt;the last post&lt;/a&gt; otherwise you might not understand many things as we will be building upon what we have created in that post.&lt;/p&gt;
&lt;h2&gt;Changes to add to last project&lt;/h2&gt;
&lt;p&gt;We will be building upon the &lt;code&gt;lint-checks&lt;/code&gt; module we created last time. We would need to make following changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add a new issue and detector pertaining to this manifest check&lt;/li&gt;
&lt;li&gt;Register the new issue in &lt;code&gt;LintRegistry&lt;/code&gt; class&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Create the detector&lt;/h2&gt;
&lt;p&gt;Create a class named &lt;code&gt;WebViewMetricsMetaTagDetector&lt;/code&gt; which extends from &lt;code&gt;ManifestDetector&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; WebViewMetricsMetaTagDetector &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ManifestDetector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now to define the Issue.&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;companion&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation builtin&quot;&gt;@JvmStatic&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; ISSUE_MISSING_WEBVIEW_METRICS_META_TAG &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Issue&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        id &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;MissingWebViewMetricsMetaTag&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        briefDescription &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Specify whether you want to opt-out of metrics tracking via WebView.&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        explanation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;WebView can upload diagnostic data to Google. You can opt-out by specifying a `meta-data` tag under your `application` tag in manifest.&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        category &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Category&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;SECURITY&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        priority &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        severity &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Severity&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ERROR&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        implementation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Implementation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            WebViewMetricsMetaTagDetector&lt;span class=&quot;token operator&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;java&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            Scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;MANIFEST_SCOPE
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addMoreInfo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https://developer.android.com/guide/webapps/managing-webview#metrics&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The things that have changed here are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;id&lt;/code&gt;, &lt;code&gt;briefDescription&lt;/code&gt; and &lt;code&gt;explanation&lt;/code&gt; for the issue.&lt;/li&gt;
&lt;li&gt;Scope inside the Implementation object passed against &lt;code&gt;implementation&lt;/code&gt; parameter. We changed from &lt;code&gt;Scope.ALL_RESOURCES_SCOPE&lt;/code&gt; to &lt;code&gt;Scope.MANIFEST_SCOPE&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We now override the 2 required methods:&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getApplicableElements&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Collection&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;listOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        SdkConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TAG_APPLICATION
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;visitElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; XmlContext&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; element&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; containsWebViewMetricsOptOutTag &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; element&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;childNodes
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; it&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;nodeName &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;meta-data&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; node &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
            node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;attributes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toPairedNameValueList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; attribute &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
                attribute&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;first &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;android:name&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; attribute&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;second &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;android.webkit.WebView.MetricsOptOut&quot;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isNotEmpty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;containsWebViewMetricsOptOutTag&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            issue &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ISSUE_MISSING_WEBVIEW_METRICS_META_TAG&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            location &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getLocation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ISSUE_MISSING_WEBVIEW_METRICS_META_TAG&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getExplanation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;TextFormat&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TEXT&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the &lt;code&gt;visitElement&lt;/code&gt; method, we are traversing through all children of &lt;code&gt;&amp;lt;application&amp;gt;&lt;/code&gt; and checking that a &lt;code&gt;meta-data&lt;/code&gt; tag with attribute &lt;code&gt;android:name=&amp;quot;android.webkit.WebView.MetricsOptOut&amp;quot;&lt;/code&gt; exists. If it does not exist then we raise our issue &lt;code&gt;ISSUE_MISSING_WEBVIEW_METRICS_META_TAG&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Register the new issue&lt;/h2&gt;
&lt;p&gt;The last thing we need to do now is to add the above created issue in our &lt;code&gt;LintRegistry&lt;/code&gt; class.&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; LintRegistry &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;IssueRegistry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; api&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Int
        &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; CURRENT_API

    &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; issues&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; List&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Issue&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;listOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            InputTypeDetector&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ISSUE_MISSING_INPUT_TYPE&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            WebViewMetricsMetaTagDetector&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ISSUE_MISSING_WEBVIEW_METRICS_META_TAG &lt;span class=&quot;token comment&quot;&gt;// We added this line&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Run the lint checks&lt;/h2&gt;
&lt;p&gt;There we are done, now to run the lint checks using gradle&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;./gradlew lint&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <category term="programming"/>
      
      <summary type="html">Writing our own custom android lint rules for verifying AndroidManifest file.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Write Custom Android Lint Rule - Layout Files</title>
      <link href="https://varunbarad.com/blog/write-custom-android-lint-rule-layout-files.html" rel="alternate" type="text/html" title="Write Custom Android Lint Rule - Layout Files"/>
      <published>2020-02-27T12:00:00+05:30</published>
      <updated>2020-02-27T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/write-custom-android-lint-rule-layout-files.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/headers/write-custom-android-lint-rule-layout-files.jpg&quot; alt=&quot;Article Header - Write Custom Android Lint Rules&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Welcome devs, I recently faced an issue where if I didn&#39;t specify any &lt;code&gt;android:inputType&lt;/code&gt; for &lt;code&gt;EditText&lt;/code&gt; then keyboard capitalisation did not correctly show. The deeper problem was that I always forgot to include that attribute. So I decided to use a lint check which would fail my build if any of my &lt;code&gt;EditText&lt;/code&gt; does not have the &lt;code&gt;android:inputType&lt;/code&gt; attribute.&lt;/p&gt;
&lt;p&gt;Since there was no such thing included in pre-provided checks I decided to write a custom lint rule. What follows is a guide on how to write a lint-check which goes checks all of our layout files and flags any &lt;code&gt;EditText&lt;/code&gt; without &lt;code&gt;android:inputType&lt;/code&gt; attribute.&lt;/p&gt;
&lt;h2&gt;What is Android lint?&lt;/h2&gt;
&lt;p&gt;Android lint is a tool which provides us static code-analysis (it does not need to run the application to identify potential problems). The Android SDK already provides us with some pre-made lint checks, but the best part is that it allows us to write our own custom lint checks.&lt;/p&gt;
&lt;h2&gt;Writing a custom lint check&lt;/h2&gt;
&lt;p&gt;We will be writing a lint check which checks whether each &lt;code&gt;EditText&lt;/code&gt;, &lt;code&gt;androidx.appcompat.widget.AppCompatEditText&lt;/code&gt; and &lt;code&gt;android.support.v7.widget.AppCompatEditText&lt;/code&gt; has the &lt;code&gt;android:inputType&lt;/code&gt; attribute defined or not.
This lint check is set to fail the build when it finds any of the above element not containing the &lt;code&gt;android:inputType&lt;/code&gt; attribute.&lt;/p&gt;
&lt;h3&gt;Create a new Library Module&lt;/h3&gt;
&lt;p&gt;In the project for which you want to write the lint check, add a new &amp;quot;Java or Kotlin Library&amp;quot; module.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For Library name you can put anything but I have used &lt;code&gt;lint-checks&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;For Class name put &lt;code&gt;LintRegistry&lt;/code&gt; (we will get to the reasoning later)&lt;/li&gt;
&lt;li&gt;I have selected Kotlin as the language&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/write-custom-android-lint-rule-layout-files/create-new-module.png&quot; alt=&quot;Screenshot - Add new Java or Kotlin Library Module&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;Add dependencies in Gradle&lt;/h3&gt;
&lt;p&gt;You only need 3 dependencies in your &lt;code&gt;lint-checks&lt;/code&gt; module&#39;s &lt;code&gt;build.gradle&lt;/code&gt; and all of them need to be only &lt;code&gt;compileOnly&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-groovy&quot;&gt;&lt;code class=&quot;language-groovy&quot;&gt;dependencies &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    compileOnly &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61&quot;&lt;/span&gt;&lt;/span&gt;
    compileOnly &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;com.android.tools.lint:lint-api:26.6.0&quot;&lt;/span&gt;&lt;/span&gt;
    compileOnly &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;com.android.tools.lint:lint-checks:26.6.0&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Create the detector&lt;/h3&gt;
&lt;p&gt;Now let&#39;s write the class which will actually detect the issues. We create a new class named &lt;code&gt;InputTypeDetector&lt;/code&gt; which extends from &lt;code&gt;LayoutDetector&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; InputTypeDetector &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;LayoutDetector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we specify the Issue that we want our detector to raise when we find and edit-text without input-type. We declare it as a property under companion object of this class (and mark it with &lt;code&gt;@JvmStatic&lt;/code&gt; so that it appears as static field when accessed from Java code).&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;companion&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation builtin&quot;&gt;@JvmStatic&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; ISSUE_MISSING_INPUT_TYPE &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Issue&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        id &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;MissingInputType&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        briefDescription &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Specify inputType attribute to get proper keyboard shown by system.&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        explanation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;You should specify an inputType for each EditText so that you can get the proper keyboard to be shown by system.&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        category &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Category&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;USABILITY&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        priority &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        severity &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Severity&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ERROR&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        implementation &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Implementation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            InputTypeDetector&lt;span class=&quot;token operator&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;java&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            Scope&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ALL_RESOURCES_SCOPE
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addMoreInfo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https://developer.android.com/training/keyboard-input/style&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The important things here are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;id&lt;/code&gt; - The name which is shown in the lint report&lt;/li&gt;
&lt;li&gt;&lt;code&gt;severity&lt;/code&gt; - There are many types of severity, here we have specified &lt;code&gt;ERROR&lt;/code&gt; as we want the build to fail when we find this issue&lt;/li&gt;
&lt;li&gt;&lt;code&gt;implementation&lt;/code&gt; - The implementation defines which XML files to scan for this issue and which detector to use to detect this issue.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After that we override the function &lt;code&gt;getApplicableElements&lt;/code&gt;, where we specify for which elements we want this detector to be run (so that our detector doesn&#39;t get unnecessarily called for every element).&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getApplicableElements&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Collection&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;listOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        SdkConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;EDIT_TEXT&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;androidx.appcompat.widget.AppCompatEditText&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;android.support.v7.widget.AppCompatEditText&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since we only want our detector to be called for &lt;code&gt;EditText&lt;/code&gt;, &lt;code&gt;androidx.appcompat.widget.AppCompatEditText&lt;/code&gt; and &lt;code&gt;android.support.v7.widget.AppCompatEditText&lt;/code&gt; we return a list of all of them.&lt;/p&gt;
&lt;p&gt;The last thing remaining to be done in detector is to actually determine if any given element has the problem or not. For that we override the &lt;code&gt;visitElement&lt;/code&gt; method.&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;visitElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; XmlContext&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; element&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;hasAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;SdkConstants&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ATTR_INPUT_TYPE&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Check if the element has the `android:inputType` attribute&lt;/span&gt;
        context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;report&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            issue &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ISSUE_MISSING_INPUT_TYPE&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// The issue that we defined above&lt;/span&gt;
            location &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getLocation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;element&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ISSUE_MISSING_INPUT_TYPE&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getExplanation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;TextFormat&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TEXT&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we are doing 2 things&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Checking if given element has the &lt;code&gt;android:inputType&lt;/code&gt; attribute or not&lt;/li&gt;
&lt;li&gt;Raise the issue if the &lt;code&gt;android:inputType&lt;/code&gt; attribute is not present&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; One thing you might have noticed is the &lt;code&gt;location&lt;/code&gt; parameter, that is used by the &lt;code&gt;lint&lt;/code&gt; tool to show exactly where any issue is reported.&lt;/p&gt;
&lt;h3&gt;Registering the Issue&lt;/h3&gt;
&lt;p&gt;Now we have declared the issue and corresponding detector, but we need to register them at a central location so that the lint tool knows that it has to execute these checks too. For that we go back to our &lt;code&gt;LintRegistry&lt;/code&gt; class that we declared earlier when creating the &lt;code&gt;lint-checks&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;We extend that class from &lt;code&gt;IssueRegistry&lt;/code&gt; class and override a couple of properties.&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; LintRegistry &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;IssueRegistry&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; api&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Int
        &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; CURRENT_API

    &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; issues&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; List&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Issue&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;listOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            InputTypeDetector&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ISSUE_MISSING_INPUT_TYPE
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any future issues that we declare/write are to be added to this &lt;code&gt;issues&lt;/code&gt; property list.&lt;/p&gt;
&lt;h3&gt;Registering our Issue Registry&lt;/h3&gt;
&lt;p&gt;We now need to declare this class within the manifest of our JAR. We do this in our build script. Add the following block under your &lt;code&gt;lint-checks&lt;/code&gt; module&#39;s &lt;code&gt;build.gradle&lt;/code&gt; file&lt;/p&gt;
&lt;pre class=&quot;language-groovy&quot;&gt;&lt;code class=&quot;language-groovy&quot;&gt;jar &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    manifest &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Format is&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// attributes(&quot;Lint-Registry-v2&quot;: &quot;&amp;lt;fully-qualified-class-name-of-your-issue-registry&gt;&quot;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;attributes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Lint-Registry-v2&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;com.varunbarad.androidlintchecks.LintRegistry&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Integrating our custom lint check module into our project&lt;/h2&gt;
&lt;p&gt;In your &lt;code&gt;app&lt;/code&gt; module go and add a &lt;code&gt;lintChecks&lt;/code&gt; dependency on your &lt;code&gt;lint-checks&lt;/code&gt; module like this&lt;/p&gt;
&lt;pre class=&quot;language-groovy&quot;&gt;&lt;code class=&quot;language-groovy&quot;&gt;dependencies &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    lintChecks &lt;span class=&quot;token function&quot;&gt;project&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;:lint-checks&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Run the lint checks&lt;/h2&gt;
&lt;p&gt;That was all that was needed to write your custom lint check. Now whenever you run a lint check using gradle, it will also check whether your code passes our custom lint checks or not.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Command to run lint check&lt;/span&gt;
./gradlew lint&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Edits&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;2020-03-02:&lt;/strong&gt; Add the step of &amp;quot;Registering our Issue Registry&amp;quot;&lt;/li&gt;
&lt;/ol&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <category term="programming"/>
      
      <summary type="html">Writing our own custom android lint rules for verifying layout files.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Dart Extension Methods</title>
      <link href="https://varunbarad.com/blog/dart-extensions-methods.html" rel="alternate" type="text/html" title="Dart Extension Methods"/>
      <published>2020-02-04T12:00:00+05:30</published>
      <updated>2020-02-04T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/dart-extensions-methods.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/headers/dart-extension-methods.png&quot; alt=&quot;Article Header - Dart Extension Methods&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Welcome devs, have you tried your hands at extensions methods? Dart recently announced support for extension methods (from Dart 2.7) and extension properties.&lt;/p&gt;
&lt;p&gt;Extension methods are a way to add functionality to existing libraries. When you are using someone else&#39;s library it&#39;s often impractical/impossible to change the API. But you can &lt;em&gt;extend&lt;/em&gt; it using extension methods.&lt;/p&gt;
&lt;h2&gt;What are extension methods?&lt;/h2&gt;
&lt;p&gt;Consider the following code that parses a string into an integer:&lt;/p&gt;
&lt;pre class=&quot;language-dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;int&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;42&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Won&#39;t it look cleaner/better if this functionality was available on &lt;code&gt;String&lt;/code&gt; class like below?&lt;/p&gt;
&lt;pre class=&quot;language-dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;&lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;42&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since the language (where class &lt;code&gt;String&lt;/code&gt; comes from) doesn&#39;t provide such a method we can&#39;t parse a string to an int like that. Extension methods allow us to specify such custom functionalities not provided by the library (Dart language in this case). Let&#39;s see how to do that in next section.&lt;/p&gt;
&lt;h2&gt;Writing a basic extension method&lt;/h2&gt;
&lt;p&gt;So we want to have a method &lt;code&gt;parseInt&lt;/code&gt; &lt;strong&gt;on&lt;/strong&gt; &lt;code&gt;String&lt;/code&gt; class which would parse the given string to integer.&lt;/p&gt;
&lt;pre class=&quot;language-dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;&lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;42&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For that we will define an extension method on &lt;code&gt;String&lt;/code&gt; like this&lt;/p&gt;
&lt;pre class=&quot;language-dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// File: extension_methods.dart&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;StringExtras&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    int &lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; int&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// We can also define getters as extensions&lt;/span&gt;
    int &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt; doubleLength &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; length &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have named this set of extension methods as &lt;code&gt;StringExtras&lt;/code&gt;, you can name them anything you like.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; As you might have noticed above, we can define multiple extension methods/getters under a single extension block.&lt;/p&gt;
&lt;h2&gt;Using the extension method&lt;/h2&gt;
&lt;p&gt;Extension methods (once imported) can be used just like any member method on that class&#39;s object. Our example would go like this&lt;/p&gt;
&lt;pre class=&quot;language-dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;extension_methods.dart&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;42&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Would print 50&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Similarly we can use the getters too&lt;/p&gt;
&lt;pre class=&quot;language-dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;extension_methods.dart&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&#39;42&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;doubleLength&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Would print 4&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Important Notes&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Extension methods &lt;em&gt;don&#39;t&lt;/em&gt; work with the type &lt;code&gt;dynamic&lt;/code&gt;. However they &lt;em&gt;do&lt;/em&gt; work with Dart&#39;s type inference.&lt;/li&gt;
&lt;li&gt;Since extension methods are resolved statically, they&#39;re as fast as calling a static function.&lt;/li&gt;
&lt;li&gt;Extension methods can&#39;t access private members of the class.&lt;/li&gt;
&lt;li&gt;If an extension member has a name conflict then you should refer &lt;a href=&quot;https://dart.dev/guides/language/extension-methods#api-conflicts&quot;&gt;here&lt;/a&gt; for your options.&lt;/li&gt;
&lt;li&gt;You can define extension methods on classes which take generic type parameters (for example &lt;code&gt;List&amp;lt;T&amp;gt;&lt;/code&gt;). Refer &lt;a href=&quot;https://dart.dev/guides/language/extension-methods#implementing-generic-extensions&quot;&gt;this section&lt;/a&gt; for further details.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Reference&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://dart.dev/guides/language/extension-methods&quot;&gt;Official release documentation - https://dart.dev/guides/language/extension-methods&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="flutter"/>
      
      <category term="dart"/>
      
      <category term="programming"/>
      
      <summary type="html">An overview of extension methods in Dart and how they can be useful</summary>
    </entry>
  
    
    <entry>
      <title type="html">P vs NP Algorithm Problem Types</title>
      <link href="https://varunbarad.com/blog/p-vs-np-algorithm-problem-types.html" rel="alternate" type="text/html" title="P vs NP Algorithm Problem Types"/>
      <published>2020-02-02T12:00:00+05:30</published>
      <updated>2020-02-02T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/p-vs-np-algorithm-problem-types.html</id>
      <content type="html">
      &lt;p&gt;&lt;img src=&quot;https://varunbarad.com/assets/images/posts/p-np-venn-diagram.png&quot; alt=&quot;Venn Diagram - Problem Types&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The above image represents something completely un-understandable to me during my college years. I couldn&#39;t understand what the professor tried to explain during my algorithms class when the topic of P vs NP vs NP-Complete problems came.&lt;/p&gt;
&lt;p&gt;Finally I understood it from &lt;a href=&quot;https://www.youtube.com/watch?v=EHp4FPyajKQ&quot;&gt;a video by &amp;quot;Up and Atom&amp;quot;&lt;/a&gt;. The problems are grouped according to these 2 criteria:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Can a solution to the problem be found in polynomial time?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Can a given solution for the problem be verified in polynomial time?&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;NP Problems&lt;/h2&gt;
&lt;p&gt;These are the problems for which condition 2 holds true. If given a solution to such problem, the correctness of that solution can be verified in polynomial time. Condition 1 being true or false for such problems doesn&#39;t affect whether they can fall under NP category or not.&lt;/p&gt;
&lt;h2&gt;NP-Complete Problems&lt;/h2&gt;
&lt;p&gt;These are the problems for which condition 2 holds true but condition 1 is false. A valid solution to the problem can&#39;t be verified in polynomial time, but if given a solution to the problem the correctness of that solution can be verified in polynomial time.&lt;/p&gt;
&lt;h2&gt;P Problems&lt;/h2&gt;
&lt;p&gt;For these problems, both conditions 1 &amp;amp; 2 hold true. There exist methods by which a valid solution to any of these problem can be found under polynomial time. And also, any given solution for such problem can be verified in polynomial time.&lt;/p&gt;
&lt;p&gt;Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">I finally wrapped my head around the differences between P vs NP vs NP-Complete problems</summary>
    </entry>
  
    
    <entry>
      <title type="html">Record Linux terminal session</title>
      <link href="https://varunbarad.com/blog/record-linux-terminal-session.html" rel="alternate" type="text/html" title="Record Linux terminal session"/>
      <published>2019-10-26T12:00:00+05:30</published>
      <updated>2019-10-26T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/record-linux-terminal-session.html</id>
      <content type="html">
      &lt;p&gt;I was recently setting up my computer with Ubuntu on it and this time I was decided that I would document every step of the process so that I can get it done faster the next time. That thought and process worked easily for the programs whose installations were just a simple &lt;code&gt;sudo apt install ...&lt;/code&gt; but when I was installing something new (like VS Code) there were many steps involved and it wasn&#39;t an easy task to document them as I went on installing those things.&lt;/p&gt;
&lt;p&gt;What I decided to then do was to just record my terminal sessions for each such long program and review those recordings later to write a script for everything that I needed to do.&lt;/p&gt;
&lt;p&gt;Linux has a handy utility called &lt;code&gt;script&lt;/code&gt; which does just that. If it isn&#39;t pre-installed then you can easily install it with &lt;code&gt;sudo apt install script&lt;/code&gt; as it is generally available in the default PPA.&lt;/p&gt;
&lt;p&gt;Using it is straight-forward too.&lt;/p&gt;
&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;script &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;file_name_to_write_record_to&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I also find these options to be of significance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-a, --append&lt;/code&gt;: This appends the recording if the file is already existing.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-c, --command &amp;lt;command_which_is_to_be_recorded&amp;gt;&lt;/code&gt;: If you want to record the interaction of a program with terminal then you can use this.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I found this command to be quite helpful in my recent endeavour of documenting the setup process and think it might others too. Want to discuss this or any other interesting thing, hit me up on Twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">How to record your linux terminal session to work on later.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Sync git fork with upstream</title>
      <link href="https://varunbarad.com/blog/sync-git-fork-with-upstream.html" rel="alternate" type="text/html" title="Sync git fork with upstream"/>
      <published>2019-10-25T12:00:00+05:30</published>
      <updated>2019-10-25T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/sync-git-fork-with-upstream.html</id>
      <content type="html">
      &lt;p&gt;It is a common situation when we fork a project on Github and after some time we want to update our fork with the changes that have been integrated into the source project from where we forked. This is a simple guide on how to do that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conditions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We have the &lt;code&gt;remote&lt;/code&gt; of source project added to our local git repo.&lt;/li&gt;
&lt;li&gt;The name of the source project remote is &lt;code&gt;upstream&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We are syncing changes from &lt;code&gt;upstream/master&lt;/code&gt; to our local &lt;code&gt;master&lt;/code&gt; branch.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Below are the steps I found on Github&#39;s guide.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Commit/Stash all your local changes.&lt;/li&gt;
&lt;li&gt;Checkout your local &lt;code&gt;master&lt;/code&gt; branch if not already there. &lt;code&gt;git checkout master&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Fetch (not pull) changes from &lt;code&gt;upstream&lt;/code&gt;. &lt;code&gt;git fetch upstream&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Merge changes from &lt;code&gt;upstream/master&lt;/code&gt; to local &lt;code&gt;master&lt;/code&gt;. &lt;code&gt;git merge upstream/master&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Resolve merge-conflicts, if any.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;And you are done. Your local &lt;code&gt;master&lt;/code&gt; branch is now updated with changes from &lt;code&gt;upstream/master&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Source: &lt;a href=&quot;https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork&quot;&gt;Github guide&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Syncing like this will only update your local &lt;code&gt;master&lt;/code&gt;. You will still need to push those synced changes to your Github repo if you want to update that too.&lt;/p&gt;
&lt;p&gt;This was just a quick tip that I needed quite a lot recently and every time I had to go and search for that guide. So I wrote this to solidify the concepts in my mind. If you have any more such tips I would love to hear about them at this &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">This is a simple guide on how to sync your fork of a git/github project with upstream changes.</summary>
    </entry>
  
    
    <entry>
      <title type="html">How to add &quot;latest&quot; post redirect to Jekyll site</title>
      <link href="https://varunbarad.com/blog/how-to-add-latest-post-redirect-to-jekyll-site.html" rel="alternate" type="text/html" title="How to add &quot;latest&quot; post redirect to Jekyll site"/>
      <published>2019-10-08T12:00:00+05:30</published>
      <updated>2019-10-08T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/how-to-add-latest-post-redirect-to-jekyll-site.html</id>
      <content type="html">
      &lt;p&gt;I wanted to have a URL which I can give to someone and it would always take them to the latest post published on my blog. I ended up using &lt;a href=&quot;https://varunbarad.com/blog/latest&quot;&gt;https://varunbarad.com/blog/latest&lt;/a&gt; as the URL.&lt;/p&gt;
&lt;p&gt;Since my website is statically generated and hosted, it wasn&#39;t an option for me to specify a server-side &lt;code&gt;30x&lt;/code&gt; redirect for that particular URL to my latest post.&lt;/p&gt;
&lt;p&gt;So what I ended up doing is generate a page on each build which would redirect user to the latest post using JS. To get the information about latest post, I made use of Jekyll&#39;s Liquid templating &lt;em&gt;syntax&lt;/em&gt; (not sure what else to call it).&lt;/p&gt;
&lt;p&gt;So the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag of that page ended up looking like this:&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
{%- assign latest_post = site.posts[0] -%}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;Redirecting you to {{ latest_post.title }}&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;span class=&quot;token language-javascript&quot;&gt;
    window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;location&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;href &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;{{ latest_post.url }}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here I get the details of latest post by taking the first post in the list &lt;code&gt;site.posts&lt;/code&gt;. AFAIK &lt;code&gt;site.posts&lt;/code&gt; is sorted in descending order by publishing date, so this approach fetches me the last published post.&lt;/p&gt;
&lt;p&gt;Then it is a simple matter of setting the &lt;code&gt;window.location.href&lt;/code&gt; to the final url of the latest post.&lt;/p&gt;
&lt;p&gt;The final task remaining was to make sure that this page was compiled and generated exactly at &lt;code&gt;https://varunbarad.com/blog/latest&lt;/code&gt;. For that I specified a &lt;code&gt;permalink: &amp;quot;/blog/latest/&amp;quot;&lt;/code&gt; in the front-matter for that page. That way Jekyll knows where to put the final generated HTML file for that page.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;That was all, a simple way to add a URL to your Jekyll site which will always take the visitor to your latest blog post. You can take a look at the full source code of my website over at &lt;a href=&quot;https://github.com/VarunBarad/varunbarad.github.io/tree/development&quot;&gt;GitHub&lt;/a&gt; or you can also find the full code of this &amp;quot;latest post redirect&amp;quot; page at &lt;a href=&quot;https://github.com/VarunBarad/varunbarad.github.io/blob/development/latest-post-redirect.html&quot;&gt;this link&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want to talk with me about anything related to this feel free to reach out to me on twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="web"/>
      
      <summary type="html">I wanted to add a URL to my site which will always redirect the visitor to the latest blog post I have published at that time.</summary>
    </entry>
  
    
    <entry>
      <title type="html">JavaScript 30 - Array Cardio 1</title>
      <link href="https://varunbarad.com/blog/javascript-30-array-cardio-1.html" rel="alternate" type="text/html" title="JavaScript 30 - Array Cardio 1"/>
      <published>2019-10-03T12:00:00+05:30</published>
      <updated>2019-10-03T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/javascript-30-array-cardio-1.html</id>
      <content type="html">
      &lt;p&gt;Day 4 of &lt;a href=&quot;https://javascript30.com/&quot;&gt;JS30 challenge&lt;/a&gt;, today I worked with various methods on array (I knew most of them beforehand) but I learned two cool things today.&lt;/p&gt;
&lt;p&gt;The key concepts I learned from today&#39;s challenge were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Converting iterables to array in JS.&lt;/li&gt;
&lt;li&gt;Displaying array of objects nicely formatted in console.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Converting iterables to array in JS&lt;/h2&gt;
&lt;p&gt;As you might have observed that &lt;code&gt;document.querySelectorAll&lt;/code&gt; doesn&#39;t return us an actual &lt;code&gt;Array&lt;/code&gt; but instead it returns us what is called as a &lt;code&gt;NodeList&lt;/code&gt;. Consequently &lt;code&gt;NodeList&lt;/code&gt; doesn&#39;t have all the methods that an &lt;code&gt;Array&lt;/code&gt; does (like &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;reduce&lt;/code&gt; etc).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;NodeList&lt;/code&gt; is an example of what we call as &amp;quot;iterable&amp;quot; in JS. So whenever working with iterables we tend to prefer to convert them to an actual &lt;code&gt;Array&lt;/code&gt; so that we have more options to work with.&lt;/p&gt;
&lt;p&gt;I already knew of one way to convert them:&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; anyIterable &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; convertedArray &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;anyIterable&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we used the &lt;code&gt;Array.from&lt;/code&gt; method to convert the iterable to an &lt;code&gt;Array&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The other way I learned today was:&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; anyIterable &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; convertedArray &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;anyIterable&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we made use of a combination of 2 things:&lt;/p&gt;
&lt;h4&gt;1. ES6 spread operator &lt;code&gt;...&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;When we prepend an iterable with &lt;code&gt;...&lt;/code&gt; (called the ES6 spread operator) what it does is it extracts all values from that iterable and replaces the &lt;code&gt;...anyIterable&lt;/code&gt; part of the expression with those values.&lt;/p&gt;
&lt;h4&gt;2. Array literal &lt;code&gt;[]&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;Then when we enclose the &amp;quot;spreaded&amp;quot; values with &lt;code&gt;[&lt;/code&gt; and &lt;code&gt;]&lt;/code&gt; it converts the whole thing into an array containing all the values from that iterable.&lt;/p&gt;
&lt;p&gt;Both produce the same result. I don&#39;t know if one performs better than the other under large data-sets. But even though the &lt;code&gt;[...anyIterable]&lt;/code&gt; way is more concise, to me the &lt;code&gt;Array.from(anyIterable)&lt;/code&gt; usage seems more readable.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;That&#39;s all folks, that was it for today. If you have anything unclear in this article or want to discuss anything else, hit me up on twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="web"/>
      
      <category term="javascript-30"/>
      
      <summary type="html">Day 4 of JS30 challenge, today we worked with various methods on array and I learned one nifty trick of displaying them in console.</summary>
    </entry>
  
    
    <entry>
      <title type="html">JavaScript 30 - CSS Variables</title>
      <link href="https://varunbarad.com/blog/javascript-30-css-variables.html" rel="alternate" type="text/html" title="JavaScript 30 - CSS Variables"/>
      <published>2019-10-02T12:00:00+05:30</published>
      <updated>2019-10-02T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/javascript-30-css-variables.html</id>
      <content type="html">
      &lt;p&gt;On my day 3 of &lt;a href=&quot;https://javascript30.com/&quot;&gt;JS30 challenge&lt;/a&gt; I got introduced primarily to CSS variables but also to many other things.&lt;/p&gt;
&lt;p&gt;The key concepts I learned from today&#39;s challenge were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CSS variables&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dataset&lt;/code&gt; property on DOM elements&lt;/li&gt;
&lt;li&gt;Image blur&lt;/li&gt;
&lt;li&gt;Color input&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;CSS variables&lt;/h2&gt;
&lt;p&gt;CSS variables work very similar to how we use variables in JS or any other programming language. They let us define their value at one place and then just use that same value anywhere we refer to that variable.&lt;/p&gt;
&lt;p&gt;For example, we can define at one place that we want text on our website to be &lt;code&gt;white&lt;/code&gt; then we can define it like this&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;:root&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;--text-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we define this &lt;code&gt;text-color&lt;/code&gt; variable at the root element. Now any place that we need to use this value we need to do something like&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.content&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;--text-color&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;CSS variables can be used for more than just colors. In today&#39;s project we used these variables for storing the border thickness and color of an image and also for storing the blur amount for that image.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; One fun idea I have with CSS variables is that I can define the color palette of my website at one place and then provide the user with a night-mode switch. I can change colors across the whole website by changing them at just one place.&lt;/p&gt;
&lt;p&gt;To modify their value via JS a simple method call does the trick.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;dom&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;element&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setProperty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;--text-color&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;red&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above snippet will change the value associated with &lt;code&gt;--text-color&lt;/code&gt; at any point in the &lt;code&gt;dom-element&lt;/code&gt; and any of &lt;code&gt;dom-element&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;&lt;code&gt;dataset&lt;/code&gt; property on DOM elements&lt;/h2&gt;
&lt;p&gt;In HTML whenever we want to write a custom-property on an element we make use of what are called &lt;code&gt;data&lt;/code&gt; attributes. A sample can be like&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;blur&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;range&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;blur&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;25&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;5&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-sizing&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;px&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;data-purpose&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;A slider input to select blur amount&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have defined 2 data attributes, namely &lt;code&gt;data-sizing&lt;/code&gt; and &lt;code&gt;data-purpose&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now when we need to use these in JS we can simply do&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;inputElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;dataset&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;sizing&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Used to access the data-sizing attribute.&lt;/span&gt;
console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;inputElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;dataset&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;purpose&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Used to access the data-purpose attribute.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;dataset&lt;/code&gt; is a very simple property on DOM elements which lists all the &lt;code&gt;data&lt;/code&gt; attributes defined on that element.&lt;/p&gt;
&lt;h2&gt;Image blur&lt;/h2&gt;
&lt;p&gt;Today I learnt a nifty simple trick to blur an image using only CSS.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;blur&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;5px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can just specify a &lt;code&gt;blur&lt;/code&gt; CSS filter and our work is done. There are lots of other functions available which can be used as &lt;code&gt;filter&lt;/code&gt;, do make sure to take a look at that list.&lt;/p&gt;
&lt;h2&gt;Color input&lt;/h2&gt;
&lt;p&gt;Standardisation of HTML and CSS has made it easy to create a simple and functional color-picker. The only thing that needs to be done is&lt;/p&gt;
&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;base&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;base&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;#43bc46&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have just declared an input tag which then takes care of displaying a color picker and also shows the user with a tiny sample of the color they have picked.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;That&#39;s all folks, that was it for today. If you have anything unclear in this article or want to discuss anything else, hit me up on twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="web"/>
      
      <category term="javascript-30"/>
      
      <summary type="html">Day 3 of JS30 challenge where I built an analog clock with CSS and animate its changes using JS and CSS.</summary>
    </entry>
  
    
    <entry>
      <title type="html">JavaScript 30 - CSS Analog Clock</title>
      <link href="https://varunbarad.com/blog/javascript-30-css-analog-clock.html" rel="alternate" type="text/html" title="JavaScript 30 - CSS Analog Clock"/>
      <published>2019-10-01T12:00:00+05:30</published>
      <updated>2019-10-01T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/javascript-30-css-analog-clock.html</id>
      <content type="html">
      &lt;p&gt;Today I am continuing my work on &lt;a href=&quot;https://javascript30.com/&quot;&gt;JS30 challenge&lt;/a&gt; and building a simple analog clock using CSS shapes and then animate it with CSS transforms timed using JS.&lt;/p&gt;
&lt;p&gt;The key concepts I learned from today&#39;s challenge were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Changing rotation center of an object in CSS&lt;/li&gt;
&lt;li&gt;CSS Transition timing function&lt;/li&gt;
&lt;li&gt;A weird reverse-jump in animation whenever any clock hand crosses 12 o&#39;clock mark.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Changing rotation center of an object in CSS&lt;/h2&gt;
&lt;p&gt;By default an object in CSS rotates around its center. But in our clock we need to rotate them around one of their corners. Therefore we need to change their CSS origins&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.hand&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transform-origin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above snippet moves the origin point for all CSS transforms to the right end of that element.&lt;/p&gt;
&lt;h2&gt;CSS Transition timing function&lt;/h2&gt;
&lt;p&gt;You can provide a timing function for your CSS transitions so that they follow it for their rate of change during the duration of your transitions.&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.hand&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transition-timing-function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ease-in-out&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are many built-in transition timing functions but I generally liked the &lt;code&gt;ease-in-out&lt;/code&gt; for how its acceleration and deceleration feel much like natural movements. You can check out the rest of them if you like.&lt;/p&gt;
&lt;p&gt;My favorite ability in this was that we can provide our custom timing functions using what is known as a bezier curve specification. For example:&lt;/p&gt;
&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.hand&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;transition-timing-function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;cubic-bezier&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;0.42&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.0&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 0.58&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1.0&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above code-sample I have written the &lt;code&gt;cubic-bezier&lt;/code&gt; format of the &lt;code&gt;ease-in-out&lt;/code&gt; timing function but you can customize the bezier curve to your heart&#39;s content using those 2 anchor points.&lt;/p&gt;
&lt;h1&gt;A weird reverse-jump in animation whenever any clock hand crosses 12 o&#39;clock mark&lt;/h1&gt;
&lt;p&gt;The hands of my clock were moving nicely from 12 to 12 but when they were just going to reach 12 they would do a weird jump and instead of moving 1 tick forward from right before 12 to 12, they would perform a full reverse circle and reach 12 from that side.&lt;/p&gt;
&lt;p&gt;This problem was occurring because of how we calculated the angles of rotation. We used the below equation for counting number of seconds.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; secondsDegrees &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;seconds &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;360&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;90&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// Here 90 degrees is the initial offset to make clock-hands start at 12&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this what would happen is as below:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:center&quot;&gt;Seconds&lt;/th&gt;
&lt;th style=&quot;text-align:center&quot;&gt;Degrees&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;0&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;90&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;15&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;180&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;30&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;270&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;45&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;360&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;60 (or 0)&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;90&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;So the main issue is that when reaching the 60 second mark it rotates counter-clockwise because the final value of clock-hand handle (90) is less than its current value (360). So instead of the transition being a smooth forward transition, it jumps counter-clockwise and that&#39;s where we see that queer problem.&lt;/p&gt;
&lt;p&gt;A very quick way to deal with this is to keep the degrees calculation so that they are always increasing. The result with that would be something like this:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align:center&quot;&gt;Seconds&lt;/th&gt;
&lt;th style=&quot;text-align:center&quot;&gt;Degrees&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;0&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;90&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;15&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;180&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;30&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;270&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;45&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;360&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align:center&quot;&gt;60 (or 0)&lt;/td&gt;
&lt;td style=&quot;text-align:center&quot;&gt;450&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;If you want to discuss anything that was unclear in today&#39;s article then hit me up on twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="web"/>
      
      <category term="javascript-30"/>
      
      <summary type="html">Day 2 of JS30 challenge where I built an analog clock with CSS and animate its changes using JS and CSS.</summary>
    </entry>
  
    
    <entry>
      <title type="html">JavaScript 30 - Building a Drum Kit</title>
      <link href="https://varunbarad.com/blog/javascript-30-building-a-drum-kit.html" rel="alternate" type="text/html" title="JavaScript 30 - Building a Drum Kit"/>
      <published>2019-09-30T12:00:00+05:30</published>
      <updated>2019-09-30T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/javascript-30-building-a-drum-kit.html</id>
      <content type="html">
      &lt;p&gt;&lt;a href=&quot;https://wesbos.com/&quot;&gt;Wes Bos&lt;/a&gt; has created a &lt;a href=&quot;https://javascript30.com/&quot;&gt;course&lt;/a&gt; to get you confident in your JS skills in 30 days. In it you work on a new project daily for 30 days and in each project you make something using vanilla JS without any frameworks or libraries.&lt;/p&gt;
&lt;p&gt;Today I started the challenge and first project was to make a drum-kit where different sounds are played based on the keyboard button you press. And the corresponding button gets highlighted on screen.&lt;/p&gt;
&lt;p&gt;The key concepts I learned from today&#39;s challenge were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Setting event-listeners with JS&lt;/li&gt;
&lt;li&gt;Working with keyboard events and identifying key-codes&lt;/li&gt;
&lt;li&gt;Playing audio and restarting the audio when it is already playing&lt;/li&gt;
&lt;li&gt;How to sync JS code with CSS transitions&lt;/li&gt;
&lt;li&gt;What value &lt;code&gt;this&lt;/code&gt; takes inside the event listener function&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Setting event-listeners with JS&lt;/h2&gt;
&lt;p&gt;The syntax for this is very simple&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;target&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;element&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&amp;lt;event-name&gt;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;to&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;call&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;when&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;event&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;is&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;fired&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can find a list of supported events &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/Events&quot;&gt;here&lt;/a&gt; but beware, the complete list of events is too large and you might never need to use most of them.&lt;/p&gt;
&lt;h2&gt;Working with keyboard events and identifying key-codes&lt;/h2&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;handleKeyDownEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;keyCode&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;keydown&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; handleKeyDownEvent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we attach an event-listener for the &lt;code&gt;keydown&lt;/code&gt; event to the &lt;code&gt;window&lt;/code&gt; object since we want to capture the events across our whole web-page.
Then we find out which key was pressed based on the &lt;code&gt;keyCode&lt;/code&gt; value passed via the fired event.&lt;/p&gt;
&lt;p&gt;Wes has created a &lt;a href=&quot;https://keycode.info/&quot;&gt;nifty little website (https://keycode.info)&lt;/a&gt; which we can use to find the corresponding &lt;code&gt;keyCode&lt;/code&gt; for any key.&lt;/p&gt;
&lt;h2&gt;Playing audio and restarting the audio when it is already playing&lt;/h2&gt;
&lt;p&gt;In this project we have a set of buttons on the screen corresponding to different keys on the keyboard. And each button has a corresponding &lt;code&gt;&amp;lt;audio&amp;gt;&lt;/code&gt; element on the page. The goal is to play the corresponding audio when a valid key is pressed on the keyboard.&lt;/p&gt;
&lt;p&gt;So after detecting which key is pressed using the &lt;code&gt;keyCode&lt;/code&gt; attribute, we select the corresponding &lt;code&gt;&amp;lt;audio&amp;gt;&lt;/code&gt; element using a pre-specified &lt;code&gt;data-key&lt;/code&gt; attribute in HTML and call the &lt;code&gt;audioElement.play();&lt;/code&gt; method on it.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; audioElement &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;audio[data-key=&quot;&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;keyCode&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;]&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
audioElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;currentTime &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
audioElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;play&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above code-block you might have observed that I set the &lt;code&gt;current-time&lt;/code&gt; of that element to &lt;code&gt;0&lt;/code&gt; before calling &lt;code&gt;play&lt;/code&gt; on it. This is done because when an &lt;code&gt;audio&lt;/code&gt; is still playing (that is it has not finished) and we call &lt;code&gt;.play()&lt;/code&gt; on it, this new call gets ignored. Therefore we reset the play-time for that particular audio element so that it correctly registers and plays 2 consecutive commands of the same key.&lt;/p&gt;
&lt;h2&gt;How to sync JS code with CSS transitions&lt;/h2&gt;
&lt;p&gt;When a key is pressed, we highlight the corresponding button for a short duration on the screen while playing sound for it. To highlight the button, we just add a class &lt;code&gt;playing&lt;/code&gt; to it which scales it up and changes the border a bit. The second part of that is to remove the &lt;code&gt;playing&lt;/code&gt; class as soon as the transition is finished so as to return the button to normal state.&lt;/p&gt;
&lt;p&gt;For this I initially thought of using &lt;code&gt;setTimeout&lt;/code&gt; with the same time-out as that mentioned in CSS as transition duration. Wes pointed out the flaw in it is that when we decide to update the transition duration we would need to make sure to update it in both the places (in CSS and in JS).&lt;/p&gt;
&lt;p&gt;So a better way to synchronize CSS transitions with JS is again to use &lt;strong&gt;events&lt;/strong&gt;. Here we specifically use &lt;code&gt;transitionend&lt;/code&gt; event on the buttons like below.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;removeButtonHighlight&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;propertyName &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;transform&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;classList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;playing&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;.keys&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    button&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;transitionend&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; removeButtonHighlight&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In above code, we select each button and then add the &lt;code&gt;transitionend&lt;/code&gt; event-listener for it so now it will call &lt;code&gt;removeButtonHighlight&lt;/code&gt; only and exactly when any transition on any of those buttons ends.&lt;/p&gt;
&lt;p&gt;After that we simply remove the &lt;code&gt;playing&lt;/code&gt; class from that button so that it returns back to its original/normal state. You might have noticed that I have put a check of &lt;code&gt;event.propertyName === &#39;transform&#39;&lt;/code&gt;. I would suggest you try and remove that check and &lt;code&gt;console.log&lt;/code&gt; the event to find out why I might have put that check in.&lt;/p&gt;
&lt;h2&gt;What value &lt;code&gt;this&lt;/code&gt; takes inside the event-listener function&lt;/h2&gt;
&lt;p&gt;One of the toughest concept to learn and correctly understand in JS is &lt;code&gt;this&lt;/code&gt; or more specifically, what &lt;code&gt;this&lt;/code&gt; means at different points of execution in our code.&lt;/p&gt;
&lt;p&gt;In the last code-block you have noticed that I simply did &lt;code&gt;this.classList.remove(&#39;playing&#39;)&lt;/code&gt; instead of trying to select that particular element using any other method.&lt;/p&gt;
&lt;p&gt;It is so because in that particular case the value of &lt;code&gt;this&lt;/code&gt; is whatever object the function &lt;code&gt;removeButtonHighlight&lt;/code&gt; has been called.&lt;/p&gt;
&lt;p&gt;So when we attach an event-listener on each of our button and on triggering of those events, they call &lt;code&gt;removeButtonHighlight&lt;/code&gt; with the context of that particular button. So there &lt;code&gt;this&lt;/code&gt; is referring directly to the button on which the event listener has been triggered.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hope I have been able to explain what I learned in today&#39;s challenge. Hit me up on twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt; in case you haven&#39;t understood something from this article or you have something new for me to learn.&lt;/p&gt;
&lt;p&gt;In any case, don&#39;t forget to check out the &lt;a href=&quot;https://javascript30.com/&quot;&gt;JavaScript30 challenge&lt;/a&gt; from Wes Bos. It is an awesome way to get some JS confidence.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="web"/>
      
      <category term="javascript-30"/>
      
      <summary type="html">I started the JavaScript30 challenge from Wes Bos today and learnt how to build a simple drum-kit.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Switching RxJava schedulers between app code and corresponding tests</title>
      <link href="https://varunbarad.com/blog/switching-rxjava-schedulers-between-app-code-and-corresponding-tests.html" rel="alternate" type="text/html" title="Switching RxJava schedulers between app code and corresponding tests"/>
      <published>2019-08-16T12:00:00+05:30</published>
      <updated>2019-08-16T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/switching-rxjava-schedulers-between-app-code-and-corresponding-tests.html</id>
      <content type="html">
      &lt;p&gt;When using RxJava we need to specify the schedulers which we want to use to 1) perform the given task and 2) return result of the operation chain.&lt;/p&gt;
&lt;p&gt;One of the interesting ways I found while working on a take-home challenge for a company was as below:&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; VarunSchedulers &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; schedulers&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; RxSchedulers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; RxSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Default

    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;enableTesting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;schedulers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; RxSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Test
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;disableTesting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;schedulers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; RxSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Default
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;sealed&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; RxSchedulers &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler
        &lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler
        &lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler

        &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; Test &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;RxSchedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;trampoline&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;trampoline&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;trampoline&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; Default &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;RxSchedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Schedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Scheduler &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; AndroidSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;mainThread&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let&#39;s take the example of fetching a network query, we can simply do this&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;pandaService&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getCutestPanda&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;VarunSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;VarunSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And when we write our unit-tests we can easily turn testing-mode on and off using the &lt;code&gt;@Before&lt;/code&gt; and &lt;code&gt;@After&lt;/code&gt; methods.&lt;/p&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; SomeTestClass &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation builtin&quot;&gt;@Before&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setupTests&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        VarunSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;enableTesting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token annotation builtin&quot;&gt;@After&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;tearDown&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        VarunSchedulers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;disableTesting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token comment&quot;&gt;// Write your tests&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now whenever we are inside tests, then automatically the &lt;code&gt;trampoline&lt;/code&gt; schedulers are assigned and respectively appropriate schedulers by default in case we are not in tests.&lt;/p&gt;
&lt;p&gt;If you have more such tricks up your sleeve or something in here isn&#39;t clear to you or you just want to chat then hit me up on twitter &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="rx-java"/>
      
      <summary type="html">A simple way to switch between using appropriate schedulers in app code and using trampoline schedulers for tests.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Make git forget a tracked file</title>
      <link href="https://varunbarad.com/blog/make-git-forget-a-tracked-file.html" rel="alternate" type="text/html" title="Make git forget a tracked file"/>
      <published>2019-06-06T12:00:00+05:30</published>
      <updated>2019-06-06T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/make-git-forget-a-tracked-file.html</id>
      <content type="html">
      &lt;p&gt;The default &lt;code&gt;.gitignore&lt;/code&gt; file generated by Android Studio&#39;s &amp;quot;New Project&amp;quot; wizard keeps some local IDE configuration files in VCS tracking. Nowadays I tweak the &lt;code&gt;.gitignore&lt;/code&gt; file immediately after creating a new project, so as to avoid getting those files tracked.&lt;/p&gt;
&lt;p&gt;But last week I opened one of my old projects and I hadn&#39;t made those modifications to the &lt;code&gt;.gitignore&lt;/code&gt; back then, so it was tracking those files. I wanted git to stop tracking those files but still wanted to keep them in my file-system.&lt;/p&gt;
&lt;p&gt;So I went searching how to do it and found the below method.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Commit/Stash all your other changes&lt;/li&gt;
&lt;li&gt;Add that file to your &lt;code&gt;.gitignore&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Commit the &lt;code&gt;.gitignore&lt;/code&gt; changes&lt;/li&gt;
&lt;li&gt;Execute the command &lt;code&gt;git rm --cached &amp;lt;file&amp;gt;&lt;/code&gt; (For each file that you want to remove from tracking)&lt;/li&gt;
&lt;li&gt;Commit the removal of those files from VCS.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Word of caution:&lt;/strong&gt; This will keep the files in your directory but the next time these changes are pulled on some other machine, the removed files will be deleted from that machine. So it is advised to make a copy of those files first before pulling and then pasting your copied files back.&lt;/p&gt;
&lt;p&gt;Source: &lt;a href=&quot;https://stackoverflow.com/a/1274447&quot;&gt;Stackoverflow&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This was just a quick tip that I needed recently and thought of sharing. If you have any more such tips I would love to hear about them at this &lt;a href=&quot;https://twitter.com/varun_barad/status/1136608795973603332&quot;&gt;twitter thread&lt;/a&gt;. Feel free to contact me for anything else that you would like to talk about &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <summary type="html">What to do when you are tracking a file with git but then want to remove it from VCS while keeping it in your file system.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Testing Deep-Link URLs using ADB</title>
      <link href="https://varunbarad.com/blog/testing-deep-link-urls-using-adb.html" rel="alternate" type="text/html" title="Testing Deep-Link URLs using ADB"/>
      <published>2019-05-02T12:00:00+05:30</published>
      <updated>2019-05-02T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/testing-deep-link-urls-using-adb.html</id>
      <content type="html">
      &lt;p&gt;ADB is a treasure trove and I regularly keep finding some gem from it. Recently I was working on creating some new deep-link integrations for the company I work at. The below command fires an event similar to one that gets fired when we click on a link in the device itself.&lt;/p&gt;
&lt;p&gt;The pattern for command to trigger the deep-link is as below:&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;adb shell am start &lt;span class=&quot;token parameter variable&quot;&gt;-a&lt;/span&gt; android.intent.action.VIEW &lt;span class=&quot;token parameter variable&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;your-link-goes-inside-these-quotes&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Example&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;adb shell am start &lt;span class=&quot;token parameter variable&quot;&gt;-a&lt;/span&gt; android.intent.action.VIEW &lt;span class=&quot;token parameter variable&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;https://varunbarad.com/blog&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This was just a quick ADB tip that I have learnt and wanted to share with you. If you have any more such tips or tricks, I would love to hear about them on &lt;a href=&quot;https://twitter.com/varun_barad/status/1123999186574303234&quot;&gt;twitter thread for this article&lt;/a&gt;. Feel free to contact me for anything else that you would like to talk about &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <summary type="html">Simple adb command to help you fire deep-link url in mobile from your console.</summary>
    </entry>
  
    
    <entry>
      <title type="html">HTTP Network Requests on Android Pie</title>
      <link href="https://varunbarad.com/blog/http-network-requests-on-android-pie.html" rel="alternate" type="text/html" title="HTTP Network Requests on Android Pie"/>
      <published>2019-04-07T12:00:00+05:30</published>
      <updated>2019-04-07T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/http-network-requests-on-android-pie.html</id>
      <content type="html">
      &lt;p&gt;Recently when I started work on a new app for my company I noticed that all of my requests were being rejected before even reaching the server. This was a problem I was facing only on the emulator and not on the Nexus 5 I had for physical testing. I searched on the Internet a bit and found out that Android Pie has disabled cleartext network traffic by default.&lt;/p&gt;
&lt;p&gt;I found 2 solutions for this. You can either enable cleartext traffic from your app for specific domains or you can set it for all the domains.&lt;/p&gt;
&lt;h2&gt;Enabling cleartext traffic for all domains (discouraged due to being less secure)&lt;/h2&gt;
&lt;p&gt;Add this attribute to the &lt;code&gt;&amp;lt;application&amp;gt;&lt;/code&gt; tag in your &lt;code&gt;AndroidManifest.xml&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;android:usesCleartextTraffic=&quot;true&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will enable app-wide cleartext traffic for any and all domains to which your app makes a request.&lt;/p&gt;
&lt;p&gt;This is discouraged as you don&#39;t specifically allow only the domains that require cleartext.&lt;/p&gt;
&lt;h2&gt;Enabling HTTP requests for specific domains (go for this one if you can)&lt;/h2&gt;
&lt;p&gt;You first need to create a file named &lt;code&gt;network_security_config.xml&lt;/code&gt; file inside your &lt;code&gt;res/xml&lt;/code&gt; directory. The file contents should be as below&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token prolog&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;network-security-config&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;domain-config&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;cleartextTrafficPermitted&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;true&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;domain&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;includeSubdomains&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;true&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;example-domain.com&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;domain&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;domain-config&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;network-security-config&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You need to replace &lt;code&gt;example-domain.com&lt;/code&gt; with the domain for which you want to enable http traffic. If you want to enable http for more than one domains then add relevant &lt;code&gt;&amp;lt;domain&amp;gt;&lt;/code&gt; tags for each.&lt;/p&gt;
&lt;p&gt;Then you need to specify this file in your &lt;code&gt;AndroidManifest.xml&lt;/code&gt; as below:&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;...
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;application&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;networkSecurityConfig&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;@xml/network_security_config&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
...&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;That&#39;s all folks&lt;/h2&gt;
&lt;p&gt;I faced this issue at work and now I am writing about it so others (and also me) can benefit from it in future. If you have more such ideas/examples or any other suggestions  under the sky, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <summary type="html">Android Pie only allows HTTPS traffic by default &amp; blocks all HTTP requests. You can enable HTTP communication for your API endpoints once you have configured this little thing.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Don&#39;t worry about specializing yet!</title>
      <link href="https://varunbarad.com/blog/dont-worry-about-specializing-yet.html" rel="alternate" type="text/html" title="Don&#39;t worry about specializing yet!"/>
      <published>2019-03-19T12:00:00+05:30</published>
      <updated>2019-03-19T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/dont-worry-about-specializing-yet.html</id>
      <content type="html">
      &lt;p&gt;In the past 4 years of my life, many people who are just starting out in programming world have asked me some version of this question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Which programming language should I focus on learning?&lt;/p&gt;
&lt;p&gt;What technologies should I be learning, so that they prove helpful in my career?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To many of them I have said:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Don&#39;t bother to fix yourself into a grove/niche just yet. You are just starting out, try any and everything that catches your attention and feels interesting.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When you are just starting out, it is not very useful to just focus on one language/technology. It might even happen that that one thing which you start focusing on doesn&#39;t interest you at all and you just get behind it because you think that it has better career-prospects. In that case your life would become terrible and since you are not interested in your learning, you won&#39;t be producing your best output. Which in turn would cause you to be mediocre at-best.&lt;/p&gt;
&lt;p&gt;Let me give my own example, my first foray into programming was during my 10th grade, it was a 10-day after-school crash-course in C programming. It was an utterly horrible experience for me. After those 10-days I swore to never learn programming. The next year in school it was a choice for me to select either Computer Science or Biology, I chose CS because Bio was worse for me. Near the end of high-school I had decidedly switched my career goal from becoming an aerospace engineer to becoming a programmer.&lt;/p&gt;
&lt;p&gt;Then college came and this was the time that I actually got to know what a vast sea of options stood in front of me. I was also enthusiastic about picking one language and then mastering it to get a good job and build cool things. There was just one hurdle for me (it actually turned out to be a boon), I didn&#39;t have anyone to ask which language to choose and similarly there wasn&#39;t anyone advising me to choose one, as I did not have confidence in either my teachers&#39; or my seniors&#39; knowledge in those regards. So I started looking at different things.&lt;/p&gt;
&lt;p&gt;I started with learning Java as I wanted to make GUIs. Let&#39;s just say that it took around a whole semester to be able to get a chat program working on local-network. Then tried learning about Android development, but poor developer experience turned me away. Then after seeing a friend using Visual Studio&#39;s Layout Editor, I decided to learn C# because it was easier to create GUIs in. For some weird reason, I picked-up Visual Basic. Got bored with it in less than a week. My journey with C# didn&#39;t last long. as there came Python, with all its conciseness and no explicit data-types. I had no idea what I should build with them, I just wanted to learn &amp;quot;cool stuff&amp;quot;.&lt;/p&gt;
&lt;p&gt;Except these, there were other periods too, like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2 months of competitive algorithmic problem solving, because I wanted to win Google Code-Jam :sweat_smile:&lt;/li&gt;
&lt;li&gt;A month of learning SQL as I wanted to become &amp;quot;The DB Programmer&amp;quot;&lt;/li&gt;
&lt;li&gt;Quite a few months of tinkering with Arduino and IOT&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But none of those were able to hold my interest for long. Then I got offered an internship as Android Developer from my neighbor in his new startup. I had nothing to lose and too much to gain so I joined it. That was the turning point of my life that finally fixed my interest in Android Development.&lt;/p&gt;
&lt;p&gt;Today 4 years after the start of that internship, I am near completing my first year as a professional Android dev. If I hadn&#39;t tried all those many things I never would have known how little do I like them.&lt;/p&gt;
&lt;p&gt;So finally, before parting, this would be my only comment. Don&#39;t worry too much about which technology or language or new hip-concept to focus on and build a career in. Keep an eye out and make sure to try everything that you find interesting. You pretty sure won&#39;t be able to so easily try everything after you start working professionally, an you would have to learn to feel okay with that. My friend &lt;a href=&quot;https://goobar.io/&quot;&gt;Nate Ebel&lt;/a&gt; has recently written a nice &lt;a href=&quot;https://goobar.io/2019/03/17/you-dont-have-to-know-it-all/&quot;&gt;article&lt;/a&gt; on it.&lt;/p&gt;
&lt;h2&gt;That&#39;s all folks&lt;/h2&gt;
&lt;p&gt;Those are my thoughts on picking a speciality very early on in your development career. You can contact me via &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="programming"/>
      
      <category term="personal-growth"/>
      
      <summary type="html">What technologies should I be learning, so that they prove helpful in my career?</summary>
    </entry>
  
    
    <entry>
      <title type="html">Show/Hide Layout Bounds in Android</title>
      <link href="https://varunbarad.com/blog/show-hide-android-layout-bounds.html" rel="alternate" type="text/html" title="Show/Hide Layout Bounds in Android"/>
      <published>2019-03-08T12:00:00+05:30</published>
      <updated>2019-03-08T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/show-hide-android-layout-bounds.html</id>
      <content type="html">
      &lt;p&gt;Sometimes while working in Android we need to display the layout-bounds on device. Recent Android versions do provide an action-tile to do so. But on previous versions, we had to go too deep into the Settings application. I wanted to be able to perform the switch from my computer.&lt;/p&gt;
&lt;p&gt;ADB does provide methods to do so, but the commands are not easy to remember and also get tiresome after some time.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# We need to execute both lines to&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# make the layout-bounds show&lt;/span&gt;
adb shell setprop debug.layout &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
adb shell &lt;span class=&quot;token function&quot;&gt;service&lt;/span&gt; call activity &lt;span class=&quot;token number&quot;&gt;1599295570&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So I made 2 files named &lt;code&gt;show-lb.sh&lt;/code&gt; and &lt;code&gt;hide-lb.sh&lt;/code&gt;, which respectively show and hide the layout-bounds on our testing device.&lt;/p&gt;
&lt;p&gt;The files are as below:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;show-lb.sh&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;adb shell setprop debug.layout &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /dev/null &lt;span class=&quot;token operator&quot;&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;2&lt;/span&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;&amp;amp;1&lt;/span&gt;
adb shell &lt;span class=&quot;token function&quot;&gt;service&lt;/span&gt; call activity &lt;span class=&quot;token number&quot;&gt;1599295570&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /dev/null &lt;span class=&quot;token operator&quot;&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;2&lt;/span&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;&amp;amp;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;hide-lb.sh&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;adb shell setprop debug.layout &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /dev/null &lt;span class=&quot;token operator&quot;&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;2&lt;/span&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;&amp;amp;1&lt;/span&gt;
adb shell &lt;span class=&quot;token function&quot;&gt;service&lt;/span&gt; call activity &lt;span class=&quot;token number&quot;&gt;1599295570&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /dev/null &lt;span class=&quot;token operator&quot;&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;2&lt;/span&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token file-descriptor important&quot;&gt;&amp;amp;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That &lt;code&gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;/code&gt; part at the end of each line is just so that the output of that particular command does not get displayed in our terminal as we don&#39;t need it.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Note for Windows users:&lt;/code&gt; You friends need to omit the &lt;code&gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;/code&gt; and save these files as &lt;code&gt;show-lb.bat&lt;/code&gt; and &lt;code&gt;hide-lb.bat&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You can save these files (make sure to give them &lt;code&gt;executable&lt;/code&gt; permission if you are on a unix-based machine) and then add their location to system&#39;s &lt;code&gt;PATH&lt;/code&gt; variable. That way you can execute these from anywhere.&lt;/p&gt;
&lt;p&gt;I do think that I would indeed make a version of this in the future where it check the current state and automatically toggle it.&lt;/p&gt;
&lt;h2&gt;That&#39;s all folks&lt;/h2&gt;
&lt;p&gt;This was my solution to improve my daily work experience by 1%. If you have more such ideas/examples or any other suggestions  under the sky, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="tools"/>
      
      <category term="android"/>
      
      <summary type="html">A couple of scripts that help to toggle display of layout-bounds on connected Android device using ADB.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Creating a single-file backup of your git repository</title>
      <link href="https://varunbarad.com/blog/git-repository-single-file-backup.html" rel="alternate" type="text/html" title="Creating a single-file backup of your git repository"/>
      <published>2019-03-03T12:00:00+05:30</published>
      <updated>2019-03-03T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/git-repository-single-file-backup.html</id>
      <content type="html">
      &lt;p&gt;Last week I needed to take a backup of my laptop&#39;s contents because I needed to give it for repair. When I started just plain copying my files to an external hard-drive I noticed that the git-files (the files used by git to store version-history for project) were taking too much time since they were very small in size but huge in numbers. So I decided to find a way using which I could create a single-file for each git enabled project and then just copy that single file over to the external hard-drive.&lt;/p&gt;
&lt;p&gt;I came across two options provided by git itself:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git archive&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git bundle&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;archive&lt;/code&gt; creates just a snapshot of how the project is at that particular instance and does not contain any of the version-history stuff, so this option went out the window for me.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;bundle&lt;/code&gt; gave me the option to generate a single-file containing all of my version-history across all the branches. This appeared to me to be &lt;strong&gt;the solution&lt;/strong&gt; that I was looking for.&lt;/p&gt;
&lt;p&gt;But alas, &lt;code&gt;bundle&lt;/code&gt; doesn&#39;t store any data of the changes you have stashed in your local-repo.&lt;/p&gt;
&lt;p&gt;After much searching I couldn&#39;t find anything that gave me both the version-history and all the stashed changes in a single file. So I decided to write my own python script which would create zip file containing the bundle file generated by &lt;code&gt;git bundle&lt;/code&gt; and patch-files for all the stashed changes in my repo.&lt;/p&gt;
&lt;p&gt;I have described how I made the program in this article, though if you only want the script, I have put a link to the gist at the bottom of this article.&lt;/p&gt;
&lt;h2&gt;Project breakdown&lt;/h2&gt;
&lt;p&gt;I decided to break the project down into parts and then conquer them one-by-one.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Getting the directory for which the git-backup needs to be generated&lt;/li&gt;
&lt;li&gt;Checking if that directory is actually the root directory for a git-enabled project&lt;/li&gt;
&lt;li&gt;Creating a &lt;code&gt;git bundle&lt;/code&gt; file from within the python script&lt;/li&gt;
&lt;li&gt;Check if the project has any changes that haven&#39;t been committed or stashed yet&lt;/li&gt;
&lt;li&gt;Stashing any changes that I find in the step above&lt;/li&gt;
&lt;li&gt;Check if the project has any stashed changes&lt;/li&gt;
&lt;li&gt;Creating individual patch-files for all the stashed changes found in previous step&lt;/li&gt;
&lt;li&gt;Creating a zip-file which contains the bundle file from git and all the patch-files that we created in previous step&lt;/li&gt;
&lt;li&gt;Deleting the bundle and patch-files since we already have them included in the zip-file&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Step 1: Getting the directory&lt;/h2&gt;
&lt;p&gt;I decided to give 2 options to the user. They can either:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to the directory via terminal and execute my script from there&lt;/li&gt;
&lt;li&gt;Provide the directory as a command-line argument to my script&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; sys
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; os

arguments &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sys&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;argv&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;arguments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    directory_to_backup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;getcwd&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    directory_to_backup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

directory_to_backup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;abspath&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In python &lt;code&gt;sys.argv&lt;/code&gt; returns a list of command-line arguments passed to our program.
Since the first item in that list is always the name of our program so we ignore it and take a look at the rest of the list.&lt;/p&gt;
&lt;p&gt;If the rest of the list is empty, we take the first use-case in consideration, ie- the user has launched our program from the directory which they want to backup. Therefore we use &lt;code&gt;os.getcwd()&lt;/code&gt; which returns the system&#39;s current working-directory, which would be the directory from where our script was launched.&lt;/p&gt;
&lt;p&gt;After that we use &lt;code&gt;os.path.abspath(directory_to_backup)&lt;/code&gt; to clean the path provided to us and also convert it to absolute path as used by the system.&lt;/p&gt;
&lt;h2&gt;Step 2: Checking if this is a root-directory for a git project&lt;/h2&gt;
&lt;p&gt;Next up on the list was to check whether the directory that we are supplied is actually the root-directory for a project which has git initiated in it. This is very important since the rest of the script would just crash if we try to execute it on a folder which isn&#39;t actually a git project.&lt;/p&gt;
&lt;p&gt;I decided to just check for the presence of a &lt;code&gt;.git&lt;/code&gt; folder inside the root folder that was supplied to us. Git stores all of its data for that project in a &lt;code&gt;.git&lt;/code&gt; folder inside that project. If you people know of a better way to make this check do let me know.&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;git_directory &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.git&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;exists&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_directory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isdir&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_directory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    create_backup_zip&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39; is not a git repository&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;os.path.exists&lt;/code&gt; checks for the existence of &lt;code&gt;git_directory&lt;/code&gt; and &lt;code&gt;os.path.isdir&lt;/code&gt; checks that it is actually a directory and not just a file named &lt;code&gt;.git&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Step 3: Creating a git bundle from within my script&lt;/h2&gt;
&lt;p&gt;Before this I had only created the git bundles from the terminal and never from within a python script. I had no idea how to do so.&lt;/p&gt;
&lt;p&gt;First I decided that I would issue terminal commands from my script and capture the output of those commands. But then I thought that it probably might not work well across platforms (I am looking at you Windows).&lt;/p&gt;
&lt;p&gt;I then went looking for a library in python to interact with git repositories. First result that Google came up with was &lt;strong&gt;GitPython&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I started reading the documentation for it and very quickly (like in under 5 minutes) started to get overwhelmed by all the git related concepts that it was throwing at me. But after around 10 minutes of searching, I found something that was helpful. I could get a handle on the &lt;code&gt;Repo&lt;/code&gt; object for that git-project and then execute my git commands using that handle.&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; directory_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
repository &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Repo&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
git_handle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; repository&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;git
git_bundle_file_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_name &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.bundle&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bundle&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;create&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;--all&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the equivalent of:&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; bundle create &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;git_bundle_name&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--all&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;--all&lt;/code&gt; flag is to include all the branches and not just the current branch.&lt;/p&gt;
&lt;h2&gt;Step 4: Check for any changes that aren&#39;t committed or stashed&lt;/h2&gt;
&lt;p&gt;Next I needed to check for any changes that haven&#39;t been committed and also haven&#39;t been stashed, so that we can stash them.&lt;/p&gt;
&lt;p&gt;Just running &lt;code&gt;git status&lt;/code&gt; gives me a list of the changed files, but it also outputs other things to make it human-friendly. There is an option &lt;code&gt;--porcelain&lt;/code&gt; which strips all that extra info.&lt;/p&gt;
&lt;p&gt;There are some files which have been left untracked, we don&#39;t want to create a new stash when all of the uncommitted files are only files that are untracked. So we filter the lines by the value in their first column and remove any lines whose first-column value is made only of &lt;code&gt;?&lt;/code&gt;. I don&#39;t know what the values of first column mean, but I only know that &lt;code&gt;?&lt;/code&gt; signifies files that are untracked. If our list of unstaged files is not empty after removing all untracked files, then we perform the next step or else we skip it.&lt;/p&gt;
&lt;h2&gt;Step 5: Stash any changes from working tree and staging area&lt;/h2&gt;
&lt;p&gt;If we find that we have any unstaged but not untracked files then we stash those changes. The command is a simple one.&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;push&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;-m&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;git-backup-stash&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Step 6: Now we check if the project has any stashed changes&lt;/h2&gt;
&lt;p&gt;Now we check if the project has any stashed changes. We do this so that we can determine whether or not we need to make any patch files. Git has a simple command to list all the stashes.&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;stashes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;list&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strip&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
stash_list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; stashes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;linesep&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stashes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stash_list&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# Create patch-files here&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Step 7: Create patch files for any stashes we have&lt;/h2&gt;
&lt;p&gt;Now we create patch files for any stashes that we have in our local repo. These files can then later be used to restore the changes that were stashed. Each stash entry gets its own patch file.&lt;/p&gt;
&lt;p&gt;Format of the patch-file&#39;s name is as below:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;stash_name&amp;gt;:&amp;lt;branch_name&amp;gt;:&amp;lt;stash_message&amp;gt;.txt&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stashes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stash_list&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    patch_files_directory &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;patch-files&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;makedirs&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; exist_ok&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; stash &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; stash_list&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        stash_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; stash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        stash_branch_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; stash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        stash_message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        patch_file_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;stash_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stash_branch_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stash_message&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.txt&#39;&lt;/span&gt;
        patch_file_path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; patch_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        patch_contents &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;show&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;-p&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stash_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file_path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; f&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_contents&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        patch_files&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;append&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file_path&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Step 8: Create a zip-file of the bundle and all the patch files&lt;/h2&gt;
&lt;p&gt;Now all we need to do is integrate all of those above files into a single zip file. First we write the bundle file created by git into the zip file. Then we include the patch files, if we have any, into a sub-folder called &amp;quot;patch-files&amp;quot; in the zip file.&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;zip_file_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; directory_name &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.zip&#39;&lt;/span&gt;
zip_file_path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; zip_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; ZipFile&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;zip_file_path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; z&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    z&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; arcname&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; patch_file &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; patch_files&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        z&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; arcname&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;patch-files&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Step 9: Deleting the bundle file and the patch files&lt;/h2&gt;
&lt;p&gt;Not so fast buddy, we still need to delete that git-bundle file and those patch-files that we created. Since we already have included them in our zip file, we no longer need them and therefore should clean those.&lt;/p&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;remove&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    shutil&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rmtree&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files_directory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Full Code&lt;/h2&gt;
&lt;pre class=&quot;language-python&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;#!/usr/bin/python3&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; os
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; sys
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; re
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; shutil
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; git &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Repo
&lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; zipfile &lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; ZipFile

&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;create_backup_zip&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; directory_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    repository &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Repo&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    git_handle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; repository&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;git
    git_bundle_file_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_name &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.bundle&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;bundle&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;create&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;--all&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    
    pattern_for_untracked_files_flag &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; re&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;compile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;r&#39;^&#92;?+$&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    non_staged_files_raw_output &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;status&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;--porcelain&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;non_staged_files_raw_output&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strip&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        non_staged_files &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;lambda&lt;/span&gt; x&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pattern_for_untracked_files_flag&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token builtin&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strip&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; non_staged_files_raw_output&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;linesep&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        non_staged_files &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;non_staged_files&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;push&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;-m&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;git-backup-stash&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    
    stashes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;list&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;strip&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    stash_list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; stashes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;linesep&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    patch_files &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stashes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stash_list&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        patch_files_directory &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;patch-files&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;makedirs&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; exist_ok&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; stash &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; stash_list&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            stash_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; stash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
            stash_branch_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; stash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
            stash_message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            
            patch_file_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;:&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;stash_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stash_branch_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stash_message&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.txt&#39;&lt;/span&gt;
            patch_file_path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; patch_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            patch_contents &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; git_handle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stash&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;show&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;-p&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stash_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file_path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; f&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_contents&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            patch_files&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;append&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file_path&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    
    zip_file_name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; directory_name &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.zip&#39;&lt;/span&gt;
    zip_file_path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;parent_directory&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; zip_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; ZipFile&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;zip_file_path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; z&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        z&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; arcname&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; patch_file &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; patch_files&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
            z&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;write&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; arcname&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;patch-files&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;split&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_file&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    
    os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;remove&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_bundle_file_name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        shutil&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rmtree&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;patch_files_directory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;zip_file_name &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39; created&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; __name__ &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    arguments &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sys&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;argv&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;arguments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        directory_to_backup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;getcwd&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        directory_to_backup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; arguments&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

    directory_to_backup &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;abspath&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    git_directory &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;join&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;.git&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;exists&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_directory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isdir&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git_directory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        create_backup_zip&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;directory_to_backup &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39; is not a git repository&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://gist.github.com/VarunBarad/c291e98dd426b0da1322171290d7bbd0&quot;&gt;GitHub gist: https://gist.github.com/VarunBarad/c291e98dd426b0da1322171290d7bbd0&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;That&#39;s all folks&lt;/h2&gt;
&lt;p&gt;This is my solution to the problem I faced of taking a backup of my projects which also included unfinished work of mine. If you have any other suggestions regarding these or any other topics under the sky, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="tools"/>
      
      <summary type="html">I created a python script which creates a zip-file containing the git-bundle and all the patch-files for different stashed changes in your repository.</summary>
    </entry>
  
    
    <entry>
      <title type="html">How Breathing Works</title>
      <link href="https://varunbarad.com/blog/how-breathing-works.html" rel="alternate" type="text/html" title="How Breathing Works"/>
      <published>2018-10-27T12:00:00+05:30</published>
      <updated>2018-10-27T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/how-breathing-works.html</id>
      <content type="html">
      &lt;p&gt;A while ago I read a prank online. It was&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Now you are breathing manually.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It got me manually breathing then just as it got you now. This spurred me into thinking about the mechanics of how different parts of our respiratory system operate, how is the air actually inhaled and exhaled and what part/parts of our brain control it. Let me tell you what I learnt.&lt;/p&gt;
&lt;h2&gt;Moving with the air&lt;/h2&gt;
&lt;p&gt;Let us first take a short trip inside our bodies to understand how the air we breathe travels inside us.&lt;/p&gt;
&lt;h3&gt;1. Taking a breath&lt;/h3&gt;
&lt;p&gt;When you take a breath, the air goes through your nose and/or mouth, down your throat and into the trachea (also known as windpipe).&lt;/p&gt;
&lt;h3&gt;2. Into the lungs&lt;/h3&gt;
&lt;p&gt;The end of trachea splits into an upside down Y-shape (something like this ⅄), thus forming the two bronchi (bronchus for singular). Air passes through left or right bronchus into respective lung.&lt;/p&gt;
&lt;h3&gt;3. Climbing the branches of the bronchial tree&lt;/h3&gt;
&lt;p&gt;Inside the lungs, each bronchus branch off into a tree-like structure of bronchioles. The air flows through bronchioles, which keep getting smaller, until it reaches the end of branches.&lt;/p&gt;
&lt;h3&gt;4. Filling up countless tiny balloons&lt;/h3&gt;
&lt;p&gt;At the end of each bronchiole, there is a tiny balloon like tissue structure called alveolus (plural alveoli) which forms an air pocket where external air is collected.&lt;/p&gt;
&lt;h3&gt;5. Gas exchange&lt;/h3&gt;
&lt;p&gt;When the air reaches the alveoli, a process similar to osmosis dissolves the oxygen from the air into capillaries while extracting carbon-dioxide from blood into the air inside alveoli at the same time.&lt;/p&gt;
&lt;h3&gt;6. The journey back to surface&lt;/h3&gt;
&lt;p&gt;The exhale phase starts at this moment and the air in the alveoli travel back to outside world following the same path it came in. That is&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Alveoli&lt;/li&gt;
&lt;li&gt;Bronchiole&lt;/li&gt;
&lt;li&gt;Bronchi&lt;/li&gt;
&lt;li&gt;Trachea&lt;/li&gt;
&lt;li&gt;Throat&lt;/li&gt;
&lt;li&gt;Nose/Mouth&lt;/li&gt;
&lt;li&gt;Sweet freedom of outside world&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Mechanics of all these&lt;/h2&gt;
&lt;p&gt;There are 2 main mechanical processes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;How is air inhaled?&lt;/li&gt;
&lt;li&gt;Consequently, how is it exhaled afterwards?&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;1. Inhaling the external air&lt;/h3&gt;
&lt;p&gt;When we want to inhale, the diaphragm (a large dome-shaped muscle located below the lungs) and the muscles between our lungs and rib-cage contract, thus creating a vacuum (more precisely they create a negative air-pressure). This forces the external air to enter our lungs through the path mentioned earlier.&lt;/p&gt;
&lt;h3&gt;2. Exhaling the inside air&lt;/h3&gt;
&lt;p&gt;Subsequently, when we want to exhale the air that we inhaled into the lungs, the same muscles (diaphragm and the muscles between lungs and rib-cage) relax. This creates a positive air-pressure inside lungs which forces the air inside them to go out.&lt;/p&gt;
&lt;h2&gt;Controlling our breathing&lt;/h2&gt;
&lt;p&gt;Finally returning to my original question of, &amp;quot;How is the actual breathing controlled? Who determines whether we breath manually or autonomously?&amp;quot;&lt;/p&gt;
&lt;p&gt;There is a part of our brain aptly named &amp;quot;Respiratory center&amp;quot;. Respiratory center (RC) is responsible for generating and maintaining the rhythm of respiration. They receive control/sensor signals of neural, chemical and hormonal nature. After processing these signals, this center sends down the appropriate signal(s) to the muscles involved in breathing. These signals ensure that your breathing muscles contract and relax regularly, thus allowing the breathing to be automatic without us even being aware of it.&lt;/p&gt;
&lt;p&gt;Although to a limited degree we can also affect our breathing rate. The cerebral-cortex sends one of the control signal to RC. This allows us to do things like holding our breath, breathing faster/slower than usual consciously.&lt;/p&gt;
&lt;p&gt;Our emotions can also affect our breathing pattern. Like being scared or angry can increase our respiratory rate. It also depends upon how physically active we are at the moment or what are the conditions of air around us.&lt;/p&gt;
&lt;p&gt;Two of the main sensor systems for respiratory regulations are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sensors in the brain and the 2 major blood vessels (the carotid artery and the aorta) detect levels of CO&lt;sub&gt;2&lt;/sub&gt; and O&lt;sub&gt;2&lt;/sub&gt; mixed in the blood and change our breathing as needed.&lt;/li&gt;
&lt;li&gt;Sensors in the airways (mouth, nose, trachea etc.) detect lung irritants. These sensors are generally responsible for triggering sneezes or coughs. After all sneezing and coughing are a form of sharp exhale of air from lungs.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;That&#39;s all folks&lt;/h2&gt;
&lt;p&gt;These are my finding when I went down the Internet lanes to find the answer of &amp;quot;How is our breathing rate controlled?&amp;quot;. If you have any other suggestions regarding these or any other topics under the sky, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;I am not a doctor and I don&#39;t pose as one on the internet. This post is just a compilation of what I found while learning about this topic.&lt;/p&gt;
&lt;h3&gt;Sources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.verywellhealth.com/physiology-of-breathing-998219&quot;&gt;Verywell Health (https://www.verywellhealth.com/physiology-of-breathing-998219)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.nhlbi.nih.gov/health-topics/how-lungs-work&quot;&gt;National Heart, Lung and Blood Institute, US (https://www.nhlbi.nih.gov/health-topics/how-lungs-work)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Respiratory_center&quot;&gt;Wikipedia - Respiratory center (https://en.wikipedia.org/wiki/Respiratory_center)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="medicine"/>
      
      <summary type="html">Ever wondered how our breathing is regulated? Let me take you on a ride down the wind-pipe.</summary>
    </entry>
  
    
    <entry>
      <title type="html">APGAR score</title>
      <link href="https://varunbarad.com/blog/apgar-score.html" rel="alternate" type="text/html" title="APGAR score"/>
      <published>2018-10-19T12:00:00+05:30</published>
      <updated>2018-10-19T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/apgar-score.html</id>
      <content type="html">
      &lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;The Apgar score is a method to quickly summarize the health of newborn children against infant mortality. Virginia Apgar, an anesthesiologist at NewYork–Presbyterian Hospital, developed the score in 1952 to quantify the effects of obstetric anesthesia on babies.&lt;/p&gt;
&lt;p&gt;The Apgar score is determined by evaluating the newborn baby on 5 simple criteria, each on a scale of zero to two. Then summing up the five values thus obtained gives a final Apgar score on the scale of zero to ten.&lt;/p&gt;
&lt;p&gt;The five criteria are summarized using words with APGAR as acronym:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Appearance&lt;/li&gt;
&lt;li&gt;Pulse&lt;/li&gt;
&lt;li&gt;Grimace&lt;/li&gt;
&lt;li&gt;Activity&lt;/li&gt;
&lt;li&gt;Respiratory effort&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Criteria&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Score of 0&lt;/th&gt;
&lt;th&gt;Score of 1&lt;/th&gt;
&lt;th&gt;Score of 2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Appearance (Skin Color)&lt;/td&gt;
&lt;td&gt;Blue or pale all over&lt;/td&gt;
&lt;td&gt;Blue at extremities; Body pink&lt;/td&gt;
&lt;td&gt;Completely pink&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pulse (Heart-beat)&lt;/td&gt;
&lt;td&gt;Absent&lt;/td&gt;
&lt;td&gt;Less than 100 beats per minute&lt;/td&gt;
&lt;td&gt;More than 100 beats per minute&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grimace (Reflex irritability)&lt;/td&gt;
&lt;td&gt;No response to stimulation&lt;/td&gt;
&lt;td&gt;Grimace on suction or aggressive stimulation&lt;/td&gt;
&lt;td&gt;Cry on stimulation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Activity&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Flexed arms and legs&lt;/td&gt;
&lt;td&gt;Active movement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Respiratory effort&lt;/td&gt;
&lt;td&gt;Absent&lt;/td&gt;
&lt;td&gt;Weak, irregular gasping&lt;/td&gt;
&lt;td&gt;Strong robust cry&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Interpretation of scores&lt;/h2&gt;
&lt;p&gt;The test is generally done at 1 and 5 minutes after birth and may be repeated later if the score is and remains low.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;7 and above are generally normal&lt;/li&gt;
&lt;li&gt;4 to 6 are considered fairly low&lt;/li&gt;
&lt;li&gt;3 or below are regarded as critically low and imply need of immediate resuscitative efforts&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Apgar test&#39;s purpose is to quickly determine whether or not a newborn needs immediate medical care.&lt;/p&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;I am not a doctor and I don&#39;t pose as one on the internet. This post is just a compilation of what I found while learning about this topic.&lt;/p&gt;
&lt;h3&gt;Sources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Apgar_score&quot;&gt;Wikipedia - Apgar score (https://en.wikipedia.org/wiki/Apgar_score)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="medicine"/>
      
      <summary type="html">A quick method used to check whether a newborn needs immediate medical care.</summary>
    </entry>
  
    
    <entry>
      <title type="html">How anesthetics work</title>
      <link href="https://varunbarad.com/blog/how-anesthetics-work.html" rel="alternate" type="text/html" title="How anesthetics work"/>
      <published>2018-08-13T12:00:00+05:30</published>
      <updated>2018-08-13T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/how-anesthetics-work.html</id>
      <content type="html">
      &lt;p&gt;Anesthetics are used to relieve people of the feeling of pain.&lt;/p&gt;
&lt;p&gt;There are three types of anesthetics based on their site of action:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Local anesthetic&lt;/li&gt;
&lt;li&gt;Regional anesthetic&lt;/li&gt;
&lt;li&gt;General anesthetic&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Local anesthetic&lt;/h2&gt;
&lt;p&gt;Local anesthetics are applied when very specific parts of the patient are to be made numb.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dentists giving anesthetic injection before performing a root canal operation&lt;/li&gt;
&lt;li&gt;Numbing out a toe before removing infected nail&lt;/li&gt;
&lt;li&gt;Applied in low doses around hip during delivery to numb off labor pain (the injections for this are generally given in the spinal discs located between vertebrae)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These can be of 2 kinds:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Topical (applied externally as a cream, gel or spray)&lt;/li&gt;
&lt;li&gt;Injected (the anesthetic is injected with the use of a syringe for deeper effect)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Sometimes a topical anesthetic is applied before giving the injection (to avoid the pain of injection or of the drug itself) for deeper anesthetic so as to numb out the pain of injection also.&lt;/p&gt;
&lt;p&gt;Local anesthetics bind with the neurotransmitters of that area thus blocking their receptors making them essentially unavailable for transporting pain signals.&lt;/p&gt;
&lt;p&gt;These are very simple with ultra rare cases of any long-lasting effects and can thus be safely administered by a standard medical practitioner.&lt;/p&gt;
&lt;p&gt;Example: Procaine, Lidocaine&lt;/p&gt;
&lt;p&gt;One of the problem with these drugs is that they are vaso-dilators (they expanding blood vessels) and can sometimes cause excessive blood loss. This is easily counter-acted by epinephrine.&lt;/p&gt;
&lt;h2&gt;Regional anesthetic&lt;/h2&gt;
&lt;p&gt;Regional anesthetics are applied when a larger part of the body is to be numbed out.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Numbing a whole foot (applied at the hip of that particular foot so that the whole set of nerves transporting signals to and from that foot get blocked)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sub-categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Peripheral regional anesthesia &lt;br /&gt;
Administered to numb-out usually a limb&lt;/li&gt;
&lt;li&gt;Central anesthesia (not same as general anesthesia) &lt;br /&gt;
It involves an injection into the cerebro-spinal fluid or the epidural space just outside spinal canal&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regional anesthetics are generally local anesthetics applied in larger quantity at strategic sites so that the whole bunch of nerves going to the targeted region get blocked.&lt;/p&gt;
&lt;p&gt;These generally need more precautions than local anesthetics since it has higher chance of something going wrong.&lt;/p&gt;
&lt;p&gt;Women who have given birth are probably very familiar with the central anesthetic technique known as an epidural. In this procedure, an anesthesiologist inserts a catheter into the epidural space, typically in the lower back area. This continuously feeds drugs such as lidocaine as well as fentanyl or clonidine to provide pain relief, resulting in a loss of sensation from the waist down.&lt;/p&gt;
&lt;p&gt;Spinal blocks, which are injected into the cerebrospinal fluid, are often used for other procedures below the waist, such as Cesarean sections or hernia surgery. They tend to paralyze further than epidurals.&lt;/p&gt;
&lt;h2&gt;General anesthetic&lt;/h2&gt;
&lt;p&gt;General anesthetics are used when the patient needs to be &amp;quot;put under&amp;quot; or made completely unconscious.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Knee replacement&lt;/li&gt;
&lt;li&gt;Heart bypass&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Much less is known about the exact functioning of general anesthetics, but so far it has been understood that these function in the fat-based medium of the cells.&lt;/p&gt;
&lt;p&gt;The current accepted theory is that they affect the spinal cord (which is why you end up immobile), the brain stem reticular activating system (which explains the unconsciousness) and the cerebral cortex (which results in changes in electrical activity on an electroencephalogram).&lt;/p&gt;
&lt;p&gt;A whole team of anesthetic specialists is needed when the patient is to be put under general anesthetic so that their condition can be constantly monitored and corrective procedures taken in case the patient&#39;s condition gets worse.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Nitrous-Oxide is a popular choice for use as general anesthetic, it is administered in the form of inhaled gas.&lt;/li&gt;
&lt;li&gt;Other types of general anesthetics(like Valium) can also be administered through an IV line.&lt;/li&gt;
&lt;li&gt;It is quick to start its effects and similarly quick to wear off.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Notes:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;You&#39;ll most likely be instructed not to eat for several hours before surgery. It&#39;s possible for someone under general anesthesia to aspirate, or breathe in, the contents of the stomach.&lt;/li&gt;
&lt;li&gt;When you&#39;re under general anesthesia, you&#39;ll be wearing a breathing mask or breathing tube, because the muscles become too relaxed to keep your airways open.&lt;/li&gt;
&lt;li&gt;Several different things are continuously monitored while you&#39;re under -- pulse oximetry (oxygen level in the blood), heart rate, blood pressure, respiratory rate, carbon dioxide exhalation levels, temperature, the concentration of the anesthetic and brain activity. There&#39;s also an alarm that goes off if your oxygen level drops below a certain point.&lt;/li&gt;
&lt;li&gt;There are 4 stages of general anesthesia
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Induction:&lt;/strong&gt; The patient is given the medication and may start to feel its effects but hasn&#39;t yet fallen unconscious.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Excitement:&lt;/strong&gt; Twitching and irregular breathing patterns or heart rates. Patients don&#39;t remember any of this as they are unconscious. Very short stage which progresses rapidly to next one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Relaxed/Anesthetized:&lt;/strong&gt; The muscles relax and breathing becomes regular. This is the target stage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Overdose:&lt;/strong&gt; This isn&#39;t part of the regular process. This overdose can result in halting heart or breath which may lead to brain damage or death if swift action isn&#39;t taken.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Procedural Sedation (Bonus category)&lt;/h2&gt;
&lt;p&gt;Procedural sedation is much like general sedation in terms of its area of effect (it also works on the whole body) but in way milder doses.&lt;/p&gt;
&lt;p&gt;The patient is usually awake and can respond to questions, but is not necessarily aware of what&#39;s happening to/around him. The patient is usually in a sleepy and relaxed state.&lt;/p&gt;
&lt;p&gt;Due to low dosages, the side-effects observed with general anesthesia are usually not observed in case of procedural sedation.&lt;/p&gt;
&lt;p&gt;Alternate names:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Conscious sedation&lt;/li&gt;
&lt;li&gt;Twilight anesthesia&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Care needs to be taken that the patient doesn&#39;t slip into deeper sedation state.&lt;/p&gt;
&lt;h3&gt;Notes&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Normally anesthetics are administered with analgesics that also help in dulling-down the pain.&lt;/li&gt;
&lt;li&gt;While administering anesthetics, many-a-times some kind of vaso-constrictor is used to counter-act the vaso-dilator action of the anesthetic&lt;/li&gt;
&lt;li&gt;Local anesthetics are usually mixed with different diluents including (but not limited to)
&lt;ul&gt;
&lt;li&gt;Sterile saline solution&lt;/li&gt;
&lt;li&gt;Sterile distilled water&lt;/li&gt;
&lt;li&gt;Spinal Fluid&lt;/li&gt;
&lt;li&gt;Sterile dextrose solution (for hyperbaric technique)
&lt;ul&gt;
&lt;li&gt;Hyperbaric solutions in spinal anesthesia are solutions that have a density greater than that of spinal fluid.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;After surgery, the patient goes to a PACU (post-anesthesia care unit).
&lt;ul&gt;
&lt;li&gt;Often the patient will be given warm IV fluids to counteract both the dehydration resulting from anesthesia as well as shivering from changes in body temperature.&lt;/li&gt;
&lt;li&gt;As analgesic effect wears off, the patient also receives some sort of pain-relief medication.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Questions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Why do general anesthetic medicines only affect those part of brain related to conscious/non-autonomic functions?&lt;/li&gt;
&lt;li&gt;Can the patient who is put under general anesthetic still see dreams?&lt;/li&gt;
&lt;li&gt;Why are heart-beats and breathing not as affected as the sensory receptors?&lt;/li&gt;
&lt;li&gt;As we move from sea-level air pressure to lower air pressure areas at higher altitude, we adjust our breathing without us giving it even a single conscious thought, if a patient under general anesthetic were to face such change in pressure will their body handle that change itself or will it cause any complication?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;I am not a doctor and I don&#39;t pose as one on the internet. This post is just a compilation of what I found while learning about this topic.&lt;/p&gt;
&lt;h3&gt;Sources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://science.howstuffworks.com/anesthesia.htm&quot;&gt;How Stuff Works - Anesthetics (https://science.howstuffworks.com/anesthesia.htm)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.drugs.com/pro/novocain.html&quot;&gt;Novocaine/Procaine (https://www.drugs.com/pro/novocain.html)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="medicine"/>
      
      <summary type="html">A post on the different categories of anesthetics and their working mechanisms and differences.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Critical mistakes to avoid in Android development</title>
      <link href="https://varunbarad.com/blog/critical-mistakes-to-avoid-in-android-development.html" rel="alternate" type="text/html" title="Critical mistakes to avoid in Android development"/>
      <published>2018-03-14T12:00:00+05:30</published>
      <updated>2018-03-14T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/critical-mistakes-to-avoid-in-android-development.html</id>
      <content type="html">
      &lt;p&gt;As many pioneers and leaders in different fields have paraphrased:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In any endeavor, it is important to know what are the top few things that need to be done right. But, it is equally important, if not more, to know the top few things which people should avoid at all costs.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;My posts up until now have been about how to perform a particular task on Android. Heeding the above saying, today I will be writing about the first five mistakes which I think should be avoided by Android developers.&lt;/p&gt;
&lt;h2&gt;Not putting all the strings to be displayed in strings.xml&lt;/h2&gt;
&lt;p&gt;This provides for a poor internationalization experience, as you will have to design your own ways of displaying the correct version of a message based on the user’s locale.&lt;/p&gt;
&lt;p&gt;If the messages are in strings.xml, then they can easily be translated and integrated into the app. The Android OS then seamlessly handles which string resource to use based on the locale that the user has set on their device.&lt;/p&gt;
&lt;p&gt;Here are a few of the reasons given by users to not use string-resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Need context to access:&lt;/strong&gt; If you wish to display that string to UI, you will inevitably need/have some kind of context there too. Just use that same context to fetch the string&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;But I only need it in this one place:&lt;/strong&gt; There is no telling when tomorrow you might need to have that same string in some other file. It is better to invest an extra minute to provide insurance against future problems&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Complex string with run-time data:&lt;/strong&gt; Friends, Android has you covered. There are parameterized strings supported by the platform with a syntax similar to the one used in Java’s &lt;code&gt;String.format()&lt;/code&gt;. More than that, plural-strings (using different strings based on the quantity of something) are also supported. Check out &lt;a href=&quot;https://stackoverflow.com/questions/2397613/are-parameters-in-strings-xml-possible&quot; title=&quot;Parameterized Strings&quot;&gt;this StackOverflow post&lt;/a&gt; for parameterized strings and the &lt;a href=&quot;https://developer.android.com/guide/topics/resources/string-resource.html&quot; title=&quot;Plural Strings&quot;&gt;official documentation&lt;/a&gt; for plural-strings.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Not using data-binding&lt;/h2&gt;
&lt;p&gt;Who likes to write cumbersome &lt;code&gt;findViewById&lt;/code&gt; calls and then maintain the reference to those views in their current namespace? Also, in that case we need to keep our view-id’s so that we are sure of which view-id we are using in &lt;code&gt;findViewById&lt;/code&gt; . This is because autocomplete in Android Studio will suggest every id (from all layouts), but only those present in the current layout tree will be available to &lt;code&gt;findViewById&lt;/code&gt; . Non-existent ones will return &lt;code&gt;null&lt;/code&gt; (probably causing a &lt;code&gt;NullPointerException&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Google has made it extremely easy to integrate data-binding into any app (new/existing) and eliminate all those pesky boilerplate view-reference stuff.&lt;/p&gt;
&lt;p&gt;A few of the benefits of using data-binding (over not using it) are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;References to only present views available (trying to refer to an absent component will show an error while editing the file in AS. It will also throw a compile-time error instead of biting you at runtime.).&lt;/li&gt;
&lt;li&gt;A bit faster due to it needing to traverse the whole layout-tree only once as opposed to every-time when &lt;code&gt;findViewById&lt;/code&gt; is called.&lt;/li&gt;
&lt;li&gt;Your working namespace (class/function) remains clean, and you don’t have to keep a reference to all the views.&lt;/li&gt;
&lt;li&gt;You can use as few of the features in data-binding as just using it to eliminate &lt;code&gt;findViewById&lt;/code&gt; calls to much more advanced features (like in this post, George Mount of Google tries to write a single adapter for all the recycler-views in an app).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Not hiding API keys&lt;/h2&gt;
&lt;p&gt;This is a common problem which is domain-agnostic and made mostly by junior developers in almost all the areas. Once you commit some piece of code to version control it remains there forever. Even if you remove that API key in future commits, anyone who has access to that repository can view the key from its history and all sorts of problems can follow.&lt;/p&gt;
&lt;p&gt;You can take a look at &lt;a href=&quot;https://varunbarad.com/android/2018/02/01/hiding-api-keys-from-your-android-repository.html&quot;&gt;this post&lt;/a&gt; to figure out how to hide your API keys from your repository while still including them in the build process and making them available in your code.&lt;/p&gt;
&lt;h2&gt;Not taking activity life-cycle into account&lt;/h2&gt;
&lt;p&gt;Any type of configuration change will cause the current activity to be destroyed and created again. To make sure that the transition is seamless for the user, we need to store the state our app was in just before the configuration change. Then we can recreate it just how the user expects it to be using the state after our activity is created anew following the configuration change.&lt;/p&gt;
&lt;p&gt;While on the subject, we should also store the app’s state when our current activity moves to stopped state. After that, our app may be killed as per the system’s need of resources.&lt;/p&gt;
&lt;h2&gt;Not learning the keyboard shortcuts in Android Studio&lt;/h2&gt;
&lt;p&gt;This might not be something which reflects in the code you write, but it highly affects your total workflow. Android Studio is built on top of IntelliJ Idea (an IDE famous for its keyboard friendliness). This means that there is a lot to be gained in developer productivity by simply investing a bit of time in learning different keyboard shortcuts. Here are some of my favorite resources to help you with that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;KeyPromoter -&lt;/strong&gt;  This is an IntelliJ plugin (available in AS) which would display a giant ugly dialogue, showing the shortcut command for the action you just performed, whenever you use your mouse to do something. Trust me, this one will annoy the hell out of you and kind of force you to learn those shortcuts. You can find and download it from the plugins section of Android Studio settings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cheat-sheet -&lt;/strong&gt; &lt;a href=&quot;https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf&quot;&gt;This is an official printable cheat-sheet&lt;/a&gt; for the keyboard shortcuts by Jetbrains (the company behind IntelliJ). Versions for both Windows and Mac are available.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Official Guide-&lt;/strong&gt;  &lt;a href=&quot;https://www.jetbrains.com/help/idea/mastering-intellij-idea-keyboard-shortcuts.html&quot;&gt;This is the official guide&lt;/a&gt; provided by Jetbrains to mastering keyboard shortcuts on IntelliJ platform.&lt;/li&gt;
&lt;li&gt;Also check out these two videos
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=hdrAlhRI5vM&quot;&gt;Android Studio Shortcuts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=eOV2owswDkE&quot;&gt;Android Studio: (About) 10 Things You (Probably) Didn’t Know You Could Do&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;That&#39;s all folks&lt;/h3&gt;
&lt;p&gt;These are the five things which I think anyone working in Android development should focus on first. If you have any other suggestions regarding these or any other topics under the sky, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <summary type="html">Charlie Munger has said that avoiding to be stupid is more beneficial when compared to trying to be intelligent. So, let&#39;s take a look at some mistakes that we can avoid while walking the path of Android development.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Simplifying User-Experience for rating your Android app</title>
      <link href="https://varunbarad.com/blog/simplifying-user-experience-for-rating-your-android-app.html" rel="alternate" type="text/html" title="Simplifying User-Experience for rating your Android app"/>
      <published>2018-02-15T12:00:00+05:30</published>
      <updated>2018-02-15T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/simplifying-user-experience-for-rating-your-android-app.html</id>
      <content type="html">
      &lt;p&gt;Who doesn’t want their users to leave ratings for their application on the Play Store? But it is not the top thing on users’ minds (unless they are really annoyed by your app). Even if they want to rate your app, it is a rather cumbersome process for them to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open the Play Store (temporarily abandoning whatever they are doing)&lt;/li&gt;
&lt;li&gt;Search for your app&lt;/li&gt;
&lt;li&gt;Find the one that is actually yours among a buttload (&lt;a href=&quot;https://en.wiktionary.org/wiki/buttload&quot;&gt;it is an actual unit of measurement&lt;/a&gt;) of other clones&lt;/li&gt;
&lt;li&gt;Rate your app&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Simplifying the user flow&lt;/h2&gt;
&lt;p&gt;You might have seen in many apps that they provide a button or something similar which redirects them directly to the Play Store listing of their particular app. This short-circuits the first three steps in the above flow, providing user with a much shorter flow for rating your app.&lt;/p&gt;
&lt;p&gt;Providing such an option requires mainly 2 steps from the developer:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Displaying an option to user to rate the app (showing a button, dialog or something else)&lt;/li&gt;
&lt;li&gt;Launching the Play Store listing of that app on clicking the above presented option&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;1. Displaying &amp;quot;Rate-Me&amp;quot; option to user&lt;/h2&gt;
&lt;p&gt;There are many options to display an option to user for rating your app. I will be using a simple button for this purpose.&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;Button&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;@+id/button_rateMe&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;text&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;Rate Me!&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;onClick&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;rateApp&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You have many other options like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dialog&lt;/li&gt;
&lt;li&gt;Menu item&lt;/li&gt;
&lt;li&gt;Floating Action Button (FAB) in About screen of app&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;2. Launching the Play Store listing&lt;/h2&gt;
&lt;p&gt;Now comes the part where we launch the Store listing for our app when user clicks on whatever we displayed above. Continuing the above example, I have the below code in my Activity in which the above button is displayed.&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Java&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rateApp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt; rateMeButton&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; packageName &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getPackageName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; playStoreAppUri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;market://details?id=&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; packageName&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; playStoreSiteUri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;https://play.google.com/store/apps/details?id=&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; packageName&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt; playStoreAppIntent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;ACTION_VIEW&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Uri&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreAppUri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;startActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreAppIntent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;ActivityNotFoundException&lt;/span&gt; e&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt; playStoreBrowserIntent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;ACTION_VIEW&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Uri&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreSiteUri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;startActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreBrowserIntent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Kotlin&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rateApp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rateMeButton&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; View&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Unit &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; packageName &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;packageName
    &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; playStoreAppUri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;market://details?id=&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token expression&quot;&gt;packageName&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; playStoreSiteUri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https://play.google.com/store/apps/details?id=&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token expression&quot;&gt;packageName&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; playStoreAppIntent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Intent&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ACTION_VIEW&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Uri&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreAppUri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;startActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreAppIntent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; ActivityNotFoundException&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; playStoreBrowserIntent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Intent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Intent&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ACTION_VIEW&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Uri&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreSiteUri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;startActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;playStoreBrowserIntent&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let me explain what the above code does.&lt;/p&gt;
&lt;p&gt;If you have ever paid attention to the URL of the store-listing of any app on the Play Store then you would have noticed that the app’s package name is used as it’s unique identifier on the store. The structure is like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;https://play.google.com/store/apps/details?id=&amp;lt;package-name-of-your-app&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;And a similar structure is followed by the URI for Play Store app:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;market://details?id=&amp;lt;package-name-of-your-app&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;So, we first try launching the Play Store app on the device, using the URI for the app (the &lt;code&gt;market://...&lt;/code&gt; one). If the Play Store app is present on the device then it is launched and the page containing listing of our app is opened.&lt;/p&gt;
&lt;p&gt;If due to some conditions the Play Store app is not present (this can be the case with some custom ROMs), then &lt;code&gt;startActivity&lt;/code&gt; will throw the &lt;code&gt;ActivityNotFoundException&lt;/code&gt; exception and we then fall-back to opening our app’s listing on the web version of the Play Store using the browser.&lt;/p&gt;
&lt;h3&gt;That&#39;s all folks&lt;/h3&gt;
&lt;p&gt;If you know of a better way for this, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;. You can even send me ideas for any other topics that you would like to know about.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <summary type="html">Make it easy for your users to rate your Android app.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Check network connectivity on Android in 10 lines</title>
      <link href="https://varunbarad.com/blog/check-network-connectivity-on-android-in-10-lines.html" rel="alternate" type="text/html" title="Check network connectivity on Android in 10 lines"/>
      <published>2018-02-08T12:00:00+05:30</published>
      <updated>2018-02-08T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/check-network-connectivity-on-android-in-10-lines.html</id>
      <content type="html">
      &lt;p&gt;Have you ever wanted to show different things to your user based on whether they are connected to the network or not? Well, Android provides a simple way to check for an active network connection.&lt;/p&gt;
&lt;p&gt;Note: This is checking whether or not the device is connected to a network (and not whether it is connected to Internet or not).&lt;/p&gt;
&lt;p&gt;The way Android provides to check for network connectivity is just 10 lines of code. But me being the lazy coder that I am, I just write that code inside a helper method once and then use that one-line method call everywhere that I need to check for connectivity.&lt;/p&gt;
&lt;p&gt;As you can see in the code-block below, it is quite easy to wrap the connectivity check logic in a function.&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Java code sample&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ConnectivityHelper&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;isConnectedToNetwork&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Context&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;ConnectivityManager&lt;/span&gt; connectivityManager &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;ConnectivityManager&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;CONNECTIVITY_SERVICE&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;boolean&lt;/span&gt; isConnected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;connectivityManager &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token class-name&quot;&gt;NetworkInfo&lt;/span&gt; activeNetwork &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; connectivityManager&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getActiveNetworkInfo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      isConnected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;activeNetwork &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;activeNetwork&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isConnectedOrConnecting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; isConnected&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Kotlin code sample&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// The next line should be the first statement in the file&lt;/span&gt;
&lt;span class=&quot;token annotation builtin&quot;&gt;@file:JvmName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string-literal singleline&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;ConnectivityHelper&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// This line is only needed if you don&#39;t want caller statement in Java to change&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; Context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isConnectedToNetwork&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Boolean &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; connectivityManager &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getSystemService&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;CONNECTIVITY_SERVICE&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; ConnectivityManager&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; connectivityManager&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;activeNetworkInfo&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isConnectedOrConnecting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;?:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You also need to have the &lt;code&gt;ACCESS_NETWORK_STATE&lt;/code&gt; permission added in your manifest like below.&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;manifest&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
  
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;uses-permission&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;android.permission.ACCESS_NETWORK_STATE&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;application&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    ...
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;application&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;manifest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Done&lt;/h3&gt;
&lt;p&gt;Now anywhere that you need to check the connection, you only need to&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Java code sample&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;ConnectivityHelper&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isConnectedToNetwork&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Show the connected screen&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Show disconnected screen&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Kotlin code sample&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isConnectedToInternet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Show the connected screen&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Show disconnected screen&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Further reading&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html&quot;&gt;Official Documentations&lt;/a&gt; are a good place to find more about this.&lt;/p&gt;
&lt;p&gt;If you know of a better way for this, &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;. You can even send me ideas for any other topics that you would like to know about.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <summary type="html">Let&#39;s see how simple it is to show correct feedback to user on whether they are connected to the network or not in Android.</summary>
    </entry>
  
    
    <entry>
      <title type="html">Hiding API keys from your Android repository</title>
      <link href="https://varunbarad.com/blog/hiding-api-keys-from-your-android-repository.html" rel="alternate" type="text/html" title="Hiding API keys from your Android repository"/>
      <published>2018-02-01T12:00:00+05:30</published>
      <updated>2018-02-01T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/hiding-api-keys-from-your-android-repository.html</id>
      <content type="html">
      &lt;p&gt;Let’s say that you are building a nice app, one that connects to a third-party service. Almost any API worth implementing uses an API key as part of basic authentication and security. Checking this into source control can expose your key to the public if you ever open-source your project (or parts of it).&lt;/p&gt;
&lt;p&gt;The Gradle build system allows us a clean way to avoid this.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add the key to your &lt;code&gt;gradle.properties&lt;/code&gt; file in your home directory under &lt;code&gt;.gradle&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;Import the key as a &lt;code&gt;buildConfigField&lt;/code&gt; / &lt;code&gt;resValue&lt;/code&gt; in your module-level &lt;code&gt;build.gradle&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Use the key in your Java or XML files as needed.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;1. Defining key in build.gradle&lt;/h2&gt;
&lt;p&gt;Find the &lt;code&gt;.gradle&lt;/code&gt; folder in your home directory. Usually it can be found at:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Windows:&lt;/strong&gt; &lt;code&gt;C:&#92;Users&#92;&amp;lt;Your Username&amp;gt;&#92;.gradle&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mac:&lt;/strong&gt; &lt;code&gt;/Users/&amp;lt;Your Username&amp;gt;/.gradle&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Linux:&lt;/strong&gt; &lt;code&gt;/home/&amp;lt;Your Username&amp;gt;/.gradle&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Inside it there would be a file named &lt;code&gt;gradle.properties&lt;/code&gt; (just create it if there isn’t any).&lt;/p&gt;
&lt;p&gt;After that, add your key to the file as a property. If your key was &lt;code&gt;my-awesome-api-key&lt;/code&gt;, the file after adding the key might look something like:&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;MyAwesomeApp_ApiKey&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;my-awesome-api-key&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I prefer to use this format &lt;code&gt;&amp;lt;Project Name&amp;gt;_&amp;lt;Key Property Name&amp;gt;&lt;/code&gt; so that I don’t mix up keys for different projects by mistake.&lt;/p&gt;
&lt;h2&gt;2. Importing the key in your project&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your module-level &lt;code&gt;build.gradle&lt;/code&gt; file (usually the one where you define dependencies for your app).&lt;/li&gt;
&lt;li&gt;Add your property in each of your build types.&lt;/li&gt;
&lt;li&gt;If you want to access the key from Java, then add it as a &lt;code&gt;buildConfigField&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you want to access the key in your XML files (layouts and other resources), then add it as a &lt;code&gt;resValue&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After doing so, your &lt;code&gt;build.gradle&lt;/code&gt; might look like this:&lt;/p&gt;
&lt;pre class=&quot;language-gradle&quot;&gt;&lt;code class=&quot;language-gradle&quot;&gt;buildTypes &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  debug &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    buildConfigField &lt;span class=&quot;token string&quot;&gt;&#39;String&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;ApiKey&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; MyAwesomeApp_ApiKey
    resValue &lt;span class=&quot;token string&quot;&gt;&#39;string&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;api_key&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; MyAwesomeApp_ApiKey
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  release &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    minifyEnabled &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    proguardFiles &lt;span class=&quot;token function&quot;&gt;getDefaultProguardFile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;proguard-android.txt&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;proguard-rules.pro&#39;&lt;/span&gt;
    buildConfigField &lt;span class=&quot;token string&quot;&gt;&#39;String&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;ApiKey&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; MyAwesomeApp_ApiKey
    resValue &lt;span class=&quot;token string&quot;&gt;&#39;string&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;&quot;api_key&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; MyAwesomeApp_ApiKey
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;3. Using the key in your app&#39;s code&lt;/h2&gt;
&lt;p&gt;Now you can access the key from your code as described below.&lt;/p&gt;
&lt;h3&gt;Accessing in Java&lt;/h3&gt;
&lt;p&gt;It is available as a standard String in your Java/Kotlin (if you use Kotlin, you good sir just became a friend of mine) code. To access it:&lt;/p&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Java&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; apiKey &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;BuildConfig&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ApiKey&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Kotlin&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; apiKey&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; String &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; BuildConfig&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ApiKey&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Accessing in XML&lt;/h3&gt;
&lt;p&gt;If you want to use it in XML files (like AdMob keys are needed sometimes in XML), you can access them just like any other string resource (used in the last line):&lt;/p&gt;
&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;com.google.android.gms.ads.AdView&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;xmlns:&lt;/span&gt;ads&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://schemas.android.com/apk/res-auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;@+id/adView_banner&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;ads:&lt;/span&gt;adSize&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;BANNER&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;ads:&lt;/span&gt;adUnitId&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;@string/api_key&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Done&lt;/h2&gt;
&lt;p&gt;Now you can safely have a public repository that can reference API keys. You can also have different keys for debug and release (just specify different property names in respective build-types).&lt;/p&gt;
&lt;h3&gt;Being a good samaritan&lt;/h3&gt;
&lt;p&gt;Securing your API keys is an essential step and you should always do it, but you also should document how someone is supposed to provide those keys to build the project from a clean checkout from your repository.&lt;/p&gt;
&lt;p&gt;If you know of a better way for this &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;contact me&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;. You can even send me ideas for any other topics that you would like to know about.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="android"/>
      
      <summary type="html">Learn how to secure your API keys while keeping the source code for that Android app open-source.</summary>
    </entry>
  
    
    <entry>
      <title type="html">How to Stop Worrying and Start Living</title>
      <link href="https://varunbarad.com/blog/how-to-stop-worrying-and-start-living.html" rel="alternate" type="text/html" title="How to Stop Worrying and Start Living"/>
      <published>2017-01-01T12:00:00+05:30</published>
      <updated>2017-01-01T12:00:00+05:30</updated>
      <id>https://varunbarad.com/blog/how-to-stop-worrying-and-start-living.html</id>
      <content type="html">
      &lt;ul&gt;
&lt;li&gt;Live in day tight compartments.
&lt;ul&gt;
&lt;li&gt;Shut off the future as tightly as the past.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;One grain of sand at a time, one task at a time.&lt;/li&gt;
&lt;li&gt;Three steps to face a grave situation
&lt;ul&gt;
&lt;li&gt;Think, &amp;quot;What&#39;s the worst that can happen?&amp;quot;&lt;/li&gt;
&lt;li&gt;Prepare to accept it if it comes to that.&lt;/li&gt;
&lt;li&gt;Calmly proceed to improve on the worst.
&lt;ul&gt;
&lt;li&gt;Gather all the facts.
&lt;ul&gt;
&lt;li&gt;Try to reason against your preferred side.&lt;/li&gt;
&lt;li&gt;List all the facts (both sides of the argument).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Analyze the facts.&lt;/li&gt;
&lt;li&gt;Reach a decision and &lt;strong&gt;ACT&lt;/strong&gt; on it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;4 Questions to &lt;strong&gt;write&lt;/strong&gt;(not just think) answers of when something is worrying you.
&lt;ul&gt;
&lt;li&gt;What am I worrying about?&lt;/li&gt;
&lt;li&gt;What can I do about it?&lt;/li&gt;
&lt;li&gt;Here&#39;s what I will do.&lt;/li&gt;
&lt;li&gt;When will I start working on this? (preferably immediately)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When once a decision is reached &amp;amp; execution started, dismiss the care for outcome.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;For every ailment under the sun,
There is a remedy or there is none.
If there be one, try to find it.
If there be none, never mind it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;When we stop fighting the inevitable, we release energy which enables us to create a richer life.&lt;/li&gt;
&lt;li&gt;The cost of a thing is the amount of life which is required to be exchanged for it, immediately or in the long run.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you know of any other books that I should read then contact me &lt;a href=&quot;https://varunbarad.com/contact&quot;&gt;here&lt;/a&gt; or tweet to me &lt;a href=&quot;https://twitter.com/varun_barad&quot;&gt;@varun_barad&lt;/a&gt;. You can even send me ideas for any other topics that you would like to know about.&lt;/p&gt;

      </content>
      <author>
        <name>Varun Barad</name>
      </author>
      
      <category term="book-highlights"/>
      
      <summary type="html">Here are some things I found noteworthy in the book &quot;How to Stop Worrying and Start Living&quot; by Dale Carnegie.</summary>
    </entry>
  
</feed>
