<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gautam Panickar SS on Medium]]></title>
        <description><![CDATA[Stories by Gautam Panickar SS on Medium]]></description>
        <link>https://medium.com/@gautampanickarss?source=rss-df0a7f33727c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fZi-BYBZ9L7U5gl_Dva62A.jpeg</url>
            <title>Stories by Gautam Panickar SS on Medium</title>
            <link>https://medium.com/@gautampanickarss?source=rss-df0a7f33727c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:45:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gautampanickarss/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NodeJS web service with standalone DB, coded in TypeScript using Express & BetterSQLite]]></title>
            <link>https://gautampanickarss.medium.com/nodejs-web-service-with-standalone-db-coded-in-typescript-using-express-bettersqlite-f16558baab26?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f16558baab26</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[bettersqlite]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-services]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 07:20:06 GMT</pubDate>
            <atom:updated>2022-09-08T16:59:38.913Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*pwMwKWqu6ig-JAYRH2giyQ.png" /></figure><p>I wish I could write an intro, but there isn’t much to talk about. The writing will be more of code and less text, as Ibelieve my code is self-explanatory 😉 . I am assuming the readers to have a minimum knowledge in TypeScript &amp; ExpressJS.</p><p>It is not necessary that you follow this project structuring or style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*ID2ZUB0IFQ7Sb4dXYrGo5A.png" /><figcaption>The project directory structure</figcaption></figure><p>Because you’ll be coding in TypeScript. Given below is it’s config file. My root directory is named as app for personal convenience.</p><p>Note that my include key in tsconfig.json consists of the following. This is essential for the compiler to pick up all the .ts files in the sub directories of app directory.</p><pre>&quot;compilerOptions&quot;: {<br>    ...<br>    &quot;outDir&quot;: &quot;./dist&quot;,<br>    &quot;baseUrl&quot;: &quot;./app&quot;,<br>    ...<br>},<br>&quot;include&quot;: [ &quot;./app/**/*&quot; ]</pre><p>Note that output files are transferred to directory name dist .</p><p>Before working on the code, lets start installing all the required npm modules.</p><pre>npm i typescript express @types/express better-sqlite3 nodemon ts-node body-parser </pre><p>In the package.json file, note the following keys.</p><pre>...<br>&quot;main&quot;: &quot;dist/server.js&quot;,<br>&quot;scripts&quot;: {<br>    &quot;compile&quot;: &quot;tsc&quot;,<br>    &quot;start&quot;: &quot;nodemon ./dist/server.js&quot;,<br>    &quot;compile-and-start&quot;: &quot;npm run compile &amp;&amp; npm run start&quot;,<br>}<br>...</pre><p>Here, note that the entry point to the main file is specified as server.js in dist directory. When compile script is executed, the .ts files in sub-directories of app is compiled into .js files and the output is stored in dist directory. Therefore, server.js is the compiled form of server.ts that we will discuss later.</p><p>Also note that we use nodemon for kicking a local server.</p><p>Moving to the bottom of the stack, which is database. We have used better-sqlite3 , which is a library based on SQLite, that claims to offer some efficient querying capabilities. The syntax is pretty much similar to SQLite. You may dig into the docs to find more about it. A simple service is coded with methods to initialise the DB and then read/add data from/into it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/157221a94f237bd9b8ab2e0d5f9dd156/href">https://medium.com/media/157221a94f237bd9b8ab2e0d5f9dd156/href</a></iframe><p>The DB name is set to hurray.db . Set verbose: console.log while initialising the DB to view the complete queries run against the DB on console. This could be useful while debugging.</p><p>Let’s code the server now. The code for server.ts is similar to that of every Node-ExpressJS application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cf0fed13777afabdb87f85d84a63058/href">https://medium.com/media/0cf0fed13777afabdb87f85d84a63058/href</a></iframe><p>Note that the port number is hard-coded. You can also see that, DB initialisation happens here, which involves the creation of tables. Another important step to note is the App class. This is the main class of the web service/app that we are creating.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/801b40363a4859783ff77d85059a9017/href">https://medium.com/media/801b40363a4859783ff77d85059a9017/href</a></iframe><p>It is important to understand how the above class is exported. I am exporting a new instance of the app.</p><pre>export default new App([new UserController()]).app;</pre><p>I have implemented CORS whitelisting. So, if you want to go raw, remove the white-listing logic and use</p><pre>res.header(&#39;Access-Control-Allow-Origin&#39;, &#39;*&#39;);</pre><p>We can have multiple controllers. UserController is the one handling user API endpoints. I also have a type declared for the controllers, which is a good practice while coding in TS. Express is incomplete without middlewares, we have an error ErrorMiddleWare for handling the errors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4c096f2d8c32cd44a8d50528f1a93b4/href">https://medium.com/media/b4c096f2d8c32cd44a8d50528f1a93b4/href</a></iframe><p>Here, HttpException is a custom type that extends the default Error .</p><p>The UserController maps to routes user/info , user/save . Express router provides all the http methods to deal with the different cases. I have sued get for user/info and post for user/save .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7466eab055601f67c0fe9f8dfa2f117/href">https://medium.com/media/a7466eab055601f67c0fe9f8dfa2f117/href</a></iframe><p>The errors in the controller methods will be handled by the middleware we wrote before. You can see that the business logic is written in UserService . Let’s dive into see what is in there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9baaa6e0139a196829d0512460eaab5/href">https://medium.com/media/d9baaa6e0139a196829d0512460eaab5/href</a></iframe><p>I am only expecting a single row in the UserInfo table. Hence, the above logic is used. Also, there is a couple of custom exceptions in use, which is easily replicable.</p><p>This is all the code you need to get started. Once finished, run</p><pre>npm run compile-and-start</pre><p>This will build and start a dev server listening on port 66666. You will also find the DB file named hurray.db in the root directory. Play with Postman or cURL to test the APIs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f16558baab26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ TECH >> Applying pagination in IndexedDB data read]]></title>
            <link>https://gautampanickarss.medium.com/tech-applying-pagination-in-indexeddb-data-read-ce5bdaa73fb?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce5bdaa73fb</guid>
            <category><![CDATA[indexeddb]]></category>
            <category><![CDATA[pagination]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Fri, 01 Oct 2021 15:48:41 GMT</pubDate>
            <atom:updated>2021-10-01T15:48:41.002Z</atom:updated>
            <content:encoded><![CDATA[<p>Data can be read in a paginated form from IDB using IDB cursors. One can leverage the advance() of IDBCursor to efficiently advance to the page indices. Here’s the sample code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f80efc3f7d4c0013e8feed661fff892/href">https://medium.com/media/5f80efc3f7d4c0013e8feed661fff892/href</a></iframe><p>For a startIndex(10) and stopIndex(25) , the code will return data from the store starting from key index 10 to 25. Note that for the very beginning, i.e for startIndex = 1, no cursor advancement is made.</p><p>cursor.advance(startIndex — 1 );<br>Since, the cursor initially points to the first element, the advanced index is reduced by 1 for arithmetic equality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce5bdaa73fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ TECH >> Testing performance of bulk writes in IndexedDB]]></title>
            <link>https://gautampanickarss.medium.com/tech-testing-performance-of-bulk-writes-in-indexeddb-a463ed68ea60?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a463ed68ea60</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[bulk-operation]]></category>
            <category><![CDATA[bulk-write]]></category>
            <category><![CDATA[indexeddb]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Sat, 12 Dec 2020 12:17:09 GMT</pubDate>
            <atom:updated>2020-12-12T12:40:28.451Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*40p7G8xJat4qgsZPXNWKZQ.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@brett-sayles?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Brett Sayles</a> from <a href="https://www.pexels.com/photo/many-cables-plugged-into-patch-panel-5073493/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>I have been adding objects to the IDB store normally, until I realised one case when my app took a little longer than expected to add about 250 objects to the DB. That’s how I ended up looking for an alternate option to add objects in bulk to IDB. Like most of the sapiens, I ran the following search query on Google..</p><blockquote><strong><em>bulk add objects into IndexedDB store</em></strong></blockquote><p>Like every developer, I was offered with an answer on StackOverflow. I found that IDB doesn’t offer a bulk-add API. So, one could either choose conventional method of iterating over the data and adding it individually or use third-party IDB implementations which provide bulk-add APIs assuring good performance.</p><p>One among the third-party wrappers is <a href="https://dexie.org/"><strong>Dexie.js</strong></a><strong> </strong>. They offer a <strong>bulkAdd </strong>method which serves the purpose. So, I decided to delve into their <a href="https://github.com/dfahlander/Dexie.js">Github</a> repository for more information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*OMNeZp_SryH7oCje9wMRrA.png" /><figcaption><a href="https://github.com/dfahlander/Dexie.js/blob/master/src/classes/table/table.ts">Dexie.js bulkAdd method</a></figcaption></figure><p>The area of interest here is the <strong>mutate</strong> method. Let’s see what it looks like. By the way, Github’s code navigation is such an awesome feature to have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*yk2jSoC6TMqSzZKNT1EYdw.png" /><figcaption><a href="https://github.com/dfahlander/Dexie.js/blob/master/src/dbcore/dbcore-indexeddb.ts">Dexie.js mutate method</a></figcaption></figure><p>The method is a little too long, but can be easily read and understood. The addition happens in the loop inside <strong>isAddOrPut </strong>condition. But, that’s all we need. Nevertheless, they are also using the same <strong>add</strong> API of IDB.</p><h3>So, let the testing begin!</h3><p>I am going to use chrome snippets for interacting with IDB. If you are unaware of that, check out my previous <a href="https://medium.com/@gautam.panickarss/chrome-dev-tools-snippets-indexeddb-its-a-piece-of-cake-a111dce5290">article</a>. All tests are going to include insertion of at least 1000 objects into the store.</p><p>I am testing on an Ubuntu 64 bit OS with 4GB RAM and the browser used is Chrome 87.</p><p>The store DB initialisation and test data can be found at <a href="https://gist.github.com/GautamPanickar/dd91435378af0ca07eeb28a24725492c">https://gist.github.com/GautamPanickar/dd91435378af0ca07eeb28a24725492c</a>.</p><p>Execute the the scripts given below and check the browser console.</p><p><strong>Test 1 &gt;&gt; Bulk write objects in individual transactions</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc111f4635bb3a3373b0814e6de21ecb/href">https://medium.com/media/cc111f4635bb3a3373b0814e6de21ecb/href</a></iframe><h3>It took a little more than <strong>3 seconds</strong> to add 1000 objects to the store. This was because, each object was added in a different transaction, resulting in a total of 1000 transactions.</h3><blockquote>The benefit of having individual transactions is that, when any addition to store fails for a particular reason, only it’s corresponding transaction fails and rest of them remain unaffected by the failure. This can be tested by modifying the script, to throw any errors while inserting to store(like adding an already added contact again).</blockquote><p><strong>Test 2&gt;&gt; Bulk write objects in single transaction</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c28caf71f17db93238dc104b3cb1f529/href">https://medium.com/media/c28caf71f17db93238dc104b3cb1f529/href</a></iframe><h3>Wow! The result after execution is even more surprising. It took less than <strong>250 ms</strong> to clear and insert 1000 objects. This is mainly because the whole addition took place in a single transaction.</h3><blockquote>This also means that, if a single insertion fails, the rest of them are also affected. The whole transaction fails and nothing will be inserted or cleared. You can test it like the way I mentioned in Test 1</blockquote><blockquote>When the length of records to write is more than 1000, it’d be better to divide the writes in order of 500 or 1000 and allot it to separate transactions.</blockquote><p><strong>Test 3 &gt;&gt; Bulk write objects in 3 separate transactions for read-update-delete, without clearing the store</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5912d2b832f1fef708a9c3f2aa4c8d4a/href">https://medium.com/media/5912d2b832f1fef708a9c3f2aa4c8d4a/href</a></iframe><p>This test case is more on the logical side, to replace add with put whenever necessary and delete stale objects. It uses 3 transaction for read, update and delete respectively.</p><p>First the existing records in store is fetched via a <strong>get </strong>and common objects are identified by comparing the id. The common records are updated with an <strong>update </strong>, the non-existent objects are deleted with a <strong>delete</strong> and rest are added using <strong>add</strong> API.</p><h3>For adding 1250 objects (1000 existing and 250 new objects) on an existing store of 1000 objects, it took below <strong>350 ms</strong>. That’s really good, given the fact that we are not clearing the DB initially as in Test Case 1 &amp; 2.</h3><blockquote>I leave it up to you on choosing the best practice. If I have missed any other test cases for evaluating the performance, please leave a comment.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a463ed68ea60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chrome Dev-tools Snippets & IndexedDB — It’s a piece of cake!]]></title>
            <link>https://gautampanickarss.medium.com/chrome-dev-tools-snippets-indexeddb-its-a-piece-of-cake-a111dce5290?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a111dce5290</guid>
            <category><![CDATA[chrome-dev-tools]]></category>
            <category><![CDATA[indexeddb]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Mon, 21 Sep 2020 18:42:55 GMT</pubDate>
            <atom:updated>2020-09-25T10:41:01.195Z</atom:updated>
            <content:encoded><![CDATA[<h3>🖥 <strong>TECH</strong> <strong>&gt;&gt;</strong> Chrome Dev-tools Snippets &amp; IndexedDB - It’s a piece of cake!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkzlR7xQKPl_o-fVBYO10Q.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@karolina-grabowska?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Karolina Grabowska</a> from <a href="https://www.pexels.com/photo/tasty-cheesecake-on-plate-with-spoon-4040695/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><blockquote>I don’t know if anyone has noticed the wonderful feature of snippets available in Chrome Dev-tools. Or, is it just me? <strong>Oh!…My!…God! </strong>(Just how Janice from ‘Friends’ would say).</blockquote><p>I may be late to the party, but I am getting a little obsessed with the richness of snippets, especially while testing my web app with dummy data. So, here are a few things I want to share with you all, that’d come useful when one is trying to manipulate IndexedDB in real-time.</p><p>Snippets are little pieces of JS code that one can write and save in Chrome browser. It can do several things. I am going to give a brief explanation on how it can be availed to communicate with IndexedDB. I expect the readers to have a minimum understanding of IndexedDB.</p><p>Snippets can be found in the Sources tab in Chrome Dev-tools. It is located inside the left sidebar there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*CXcbUucDrovInxa6j8Kkxw.png" /><figcaption>Snippets</figcaption></figure><p>I have created a couple of snippets already. And for the purpose of this tutorial let’s create a new one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*zxYtVNriGSpJZ64GYtzn6g.png" /><figcaption>GautamDBInit</figcaption></figure><p>That’s our new Snippet highlighted in blue. Now, what we are gonna do is to add some code for initialising a DB and a store inside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*vg99bYcNEctoEbYvV3HyNg.png" /><figcaption>Init code</figcaption></figure><p>I have created a DB with name gautam and store routine . Snippets can be executed on the fly by right clicking on it and hitting the run option as shown in the image. After running, check the console to see the result. Then, go to the Application tab of Dev-tools to check if DB is created. If not hit refresh option by right-clicking on IndexedDB option in the side-abr.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*1mdsPJzG55gUrgl6pWePbw.png" /><figcaption>IDB</figcaption></figure><p>See, the console also prints a part of the JS code too. From the sidebar you can see the new DB and the store. And chrome will save your snippet as long as you want it to be. I have created some more snippets to populate data into the store and then retrieve it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*giPPyblKmQQnxQDoS0knpQ.png" /><figcaption>Add</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*AULeAyB5c3HssRSPibIYAg.png" /><figcaption>Result</figcaption></figure><h3><strong>See, it’s this easy. So, leverage the power of snippets if you haven’t already! It’s a piece of cake.</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a111dce5290" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Caching images with Workbox service worker for an Angular app]]></title>
            <link>https://gautampanickarss.medium.com/caching-images-with-workbox-service-worker-for-an-angular-app-809433325d8d?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/809433325d8d</guid>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[workbox]]></category>
            <category><![CDATA[service-worker]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Sun, 19 Jul 2020 07:59:22 GMT</pubDate>
            <atom:updated>2020-09-25T10:42:41.434Z</atom:updated>
            <content:encoded><![CDATA[<h3>🖥 TECH &gt;&gt; Caching images with Workbox service worker for an Angular app</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZ7eACzK9mxI8JnzmLX8dg.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@elevate?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">ELEVATE</a> from <a href="https://www.pexels.com/photo/man-riding-a-yellow-forklift-with-boxes-1267324/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>I presume that you readers have a basic understanding of service workers, PWA and Googles’ Workbox before you begin reading this article. If not, here’s a good book to learn things .</p><blockquote><a href="https://livebook.manning.com/book/progressive-web-apps/part-1/"><strong>https://livebook.manning.com/book/progressive-web-apps/part-1/</strong></a></blockquote><p>This is not going to be an in-depth tutorial, but I certainly am thinking about doing one in the near future. This article shall address 2 methods to store images locally. First one in the service worker cache and the second method stores images in IndexedDB.</p><p>I am going to write my service worker in Typescript, since my application was written in angular. In an angular app, you will first have to register the service worker. This is preferably done in<strong> <em>main.ts</em></strong>. Or if you want to have more control on the services/stores/components depending on the interaction with the service worker, then you can register in the root component <strong><em>app.component.ts</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c73b82d00d5d3323baa6284bbb81e50c/href">https://medium.com/media/c73b82d00d5d3323baa6284bbb81e50c/href</a></iframe><p>See, the important thing here is the wb.register() method . This is solely responsible for registering your service worker. And also, don’t freak out over the line given below.</p><p>const wb = new Workbox(&#39;service-worker.js&#39;)</p><p>This is the .js file after compilation of our SW written in TS. Let’s assume before that our SW will have name <strong>service-worker</strong></p><p>Now, we will have to create a service worker. Because we are going to create it in Typescript, we need proper configuration to transpile it to JS and then provide new scripts that will in-turn generate the compiled service worker with angular productions build.</p><p>I have dedicated an entire folder sw for my service worker and put all related files into it for better separation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*9clENv2SiwE_6gO2rLXQDg.png" /><figcaption>Folder structure</figcaption></figure><p>As you can see service-worker.ts file has the main SW code. The handler code is separated in the sw-handlers.ts rest of the files handle the configuration for TS, Webpack and Workbox. Here is the code for the config files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50c6524c0963375e27143c0db4b5e4e4/href">https://medium.com/media/50c6524c0963375e27143c0db4b5e4e4/href</a></iframe><p>TS config resolves two files namely, service-worker.ts, sw-handler.ts. Note that swtest is our app name. Angular generates a folder with swtest inside dist folder when built in production. I am not going to go into the angular details as it is out of context.</p><p>In short, webpack.sw.config.js tells webpack to find service-worker.ts , load it/all ts files with ts-loader , compile and build in production(handles minification) and write to dist/swtest/service-worker.js file. I hope you now understand why we referred to the .js file while registering the workbox.</p><p>worlbox.config.js is a very simple and common workbox config that you can find anywhere in web. An interesting point to note here is that we refer to the same file in swSrsc and swDest .That is because we write over SW in TS and is then compiled to JS in /dist.</p><blockquote>But where’s the Service Worker. Show me some code for real! Here it is.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c144f04b9be45c07b53260a8d4c22e2/href">https://medium.com/media/3c144f04b9be45c07b53260a8d4c22e2/href</a></iframe><p>Take note of the comments written in the onMesage event listener. I don’t want to repeat it again :)</p><p>I told you that we are going to use 2 strategies to store images locally. One by using cache and the other by leveraging IndexedDB. So, for the IDB strategy we use initIndexedDb() to open DB with name <strong>swtest </strong>and then create an object store with name <strong>images. </strong>The logic is handled by sw-handlers.ts, so we instantiate that with the opened DB connection.</p><p>bgImagesMatcher matches request URL of format /files/bg_images/</p><p><em>For example:</em><strong> </strong>https://gplearns.com/files/bg_images/img_1.png?secret=sdfdsf123&amp;key=dhdhs1234234</p><p>We can either use bgImagesDBHandler or bgImagesCacheHandler for the route. But both at the same time would be totally inappropriate. So, I have commented out the option which stores image in IDB for the time being.</p><blockquote><strong><em>bgImagesDBHandler</em></strong><em> and </em><strong><em>bgImagesCacheHandler</em></strong><em> Where are they?</em></blockquote><p>You can find the handlers in sw-handlers.ts. Diving deep into the handlers code, you might think why I wrote a cache handler for myself rather than using the caching strategies and techniques of Workbox. That’s because, the images that I try to fetch from my server has a secret appended to it as a query param to it. This secret changes for each image fetch. In short, the URLs of the images that I fetch from my server are dynamic even though the images are same.</p><p>Why can’t I provide bgImagesMatcher as mentioned above and use a workbox strategy like this?</p><pre>registerRoute(<br>  bgImagesMatcher,<br>  new strategies.CacheFirst()<br>);</pre><p>Because the secret changes every time, same image will be cached more than once and in effect I won’t be able to make the use of the actual solution that workbox caching offers. So, that’s why decide to write a cache handler for myself.</p><p>Here’s sw-handlers.ts</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4d8588692b4c4071c20493fd2e168a0/href">https://medium.com/media/e4d8588692b4c4071c20493fd2e168a0/href</a></iframe><p>Storing in cache is the easiest way.</p><p>bgImagesCacheHandler makes use of getCacheImageURL method to generate key for caching the image. This key is actually generated by stripping off the changing query parameters. caches gives you direct access to the <strong>CacheStorage</strong> <strong>API</strong>. If a match for the key was found, the image is returned.</p><p>Otherwise, the intercepted request for fetching images are resumed and then the image response is again intercepted by the handler firstly and then returned to the original request initiating angular component. A clone of the image response is then put into cache bg-images with the key generated using getCacheImageURL.</p><blockquote>Putting images into cache or IndexedDB is entirely dependent on the use-case of your application. Check for the advantages of each and compare with your use-case to decide on an approach. Normally, anyone would prefer cache over IDB for storing images.</blockquote><p>Now if you want to store images in IndexedDB then have a look at bgImagesDBHandler. Again I need a key here to refer to the images easily. I have used a different method getImageIdFromURL for that.</p><blockquote>Okay I don’t know why I used two different methods for generating keys from URL. May be it happened as I was coding. That doesn’t look good anyway. However, I am too lazy to correct that. Please excuse me :)</blockquote><p>Again, I have used a Cache-First strategy here. It’s similar to the way we put images into and retrieved from cache as mentioned above. Except that we now have 2 methods fetchImageFromDB and putImageInDB which helps you achieve the fetching and putting respectively. Also note that the images are stored as blob in IndexedDB. So, after getting the response from the server, convert it as blob.</p><p>I don’t think there is a need for me to explain what is going inside fetchImageFromDB and putImageInDB. Anyone familiar with IndexedDB will be able to relate to it quickly.</p><p>Finally, to make the building process reliable here are the scripts that you may want to add to your package.json . Make sure that you have the necessary workbox packages installed and also http-server. because you know why, :)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87cea0e9f8a98330dbfb5eb0a5737877/href">https://medium.com/media/87cea0e9f8a98330dbfb5eb0a5737877/href</a></iframe><p>So, that’s all folks! I hope you enjoyed reading and found it useful. I might have made mistakes here and there. Please let me know if it can be done more efficiently and be free to point out the mistakes.</p><p>Here are the links which I referred to in my pursuit of learning PWAs and service workers.</p><blockquote><a href="https://html.spec.whatwg.org/multipage/workers.html">https://html.spec.whatwg.org/multipage/workers.html</a><br><a href="https://www.html5rocks.com/en/tutorials/workers/basics/">https://www.html5rocks.com/en/tutorials/workers/basics/</a></blockquote><blockquote><a href="https://developers.google.com/web/fundamentals/primers/service-workers/?authuser=0">https://developers.google.com/web/fundamentals/primers/service-workers/</a></blockquote><blockquote><a href="https://developers.google.com/web/tools/workbox/guides/get-started">https://developers.google.com/web/tools/workbox/guides/get-started</a></blockquote><blockquote><a href="https://codelabs.developers.google.com/codelabs/workbox-indexeddb/?authuser=0#0">https://codelabs.developers.google.com/codelabs/workbox-indexeddb/#0</a></blockquote><blockquote><a href="https://medium.com/runic-software/simple-guide-to-workbox-in-angular-197c25396e68">https://medium.com/runic-software/simple-guide-to-workbox-in-angular-197c25396e68</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=809433325d8d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I did it again!]]></title>
            <link>https://gautampanickarss.medium.com/i-did-it-again-5d3330c81bc3?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d3330c81bc3</guid>
            <category><![CDATA[crush]]></category>
            <category><![CDATA[random-thoughts]]></category>
            <category><![CDATA[lovestory]]></category>
            <category><![CDATA[memories]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 10:19:00 GMT</pubDate>
            <atom:updated>2020-09-25T10:46:42.249Z</atom:updated>
            <content:encoded><![CDATA[<h3>📝BLOG &gt;&gt; I did it again!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*sAU9JgLxeZvv_j7th7yCEg.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@shvetsa?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Anna Shvets</a> from <a href="https://www.pexels.com/photo/person-holding-smartphone-3943951/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>I did it again!</p><p>“Can I ask you a question?” asked this girl.</p><p>“Yeah, that’ll be fun!” I replied back.</p><p>“You know that blog, which you wrote about your crush. Who was it?” The sharpness of the question shot me down. If it wasn’t for this girl, I would have said the name without hesitation.</p><p>Crushes or Infatuations are common for boys unless for some nerds. My thought of being a nerd was proven wrong when I got a higher rank in Engineering entrance. 36087 is a great number, but it was more of a statement that I was no less a common boy. I had few crushes in college. A couple of which I still ponder on. It did not happen at the very same time. That’d seem inappropriate. One in first year and the other distributed around the last 2 years.</p><p>By the end of my first year at college, I knew I had something going on with a girl. But the fact that there were too many bees buzzing around her head, made it a short-lived one. It was Christmas which incited the feeling and it took another Christ to pave way for my second adventure. An year passed by without another stop and somehow it happened again. There was a pall of uncertainty which always hung over my second experience. I didn’t know when, how or where it happened. But, it was special and so was she. Some say, “to have a crush on someone is a sign of growing up”. Rightly so, because I outgrew my wits but never my inhibitions. And even before I realised, college was over.</p><p>Because it lasted for a while, I decided to write a blog. I gave it the title “My crush was never in a relationship”. I always hoped her to be in a relationship, as I lacked the courage to express myself in person. But this question still breathed down by my neck “Who are you referring to?”. The answer was conspicuous by its absence.</p><p>But, when she came back with the same question 2 years later, I was overwhelmed to find out that she had read it. Afterall, very few people used Google Plus even during it’s prime. I soon deleted the blog, fearing she would seek an answer. Standing face to face with my fears, I took the easiest choice.</p><p>“So tell me, do not try to dodge.” She demanded.</p><p>“It was Girl-1, first year. That was my first crush”. I told her the lie but there was some truth. I refrained from saying, “there was another one and it was you”. Nevertheless, nobody wants to be second to none.</p><p>I lied to my crush about my crush. I did it again! I evaded the truth. I am getting better at lying day by day. From master procrastinator to master liar.😇</p><p><em>Originally published at </em><a href="https://sonnynefarious.blogspot.com/2020/04/i-did-it-again-can-i-ask-you-question.html"><em>https://sonnynefarious.blogspot.com</em></a><em> on April 29, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d3330c81bc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The serious malayalee and a light movie.Perfect retardation!]]></title>
            <link>https://gautampanickarss.medium.com/the-serious-malayalee-and-a-light-movie-perfect-retardation-632371d7c725?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/632371d7c725</guid>
            <category><![CDATA[random-musings]]></category>
            <category><![CDATA[movies]]></category>
            <category><![CDATA[malayalam-movie]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Mon, 04 Jun 2018 08:37:00 GMT</pubDate>
            <atom:updated>2020-09-25T10:46:42.493Z</atom:updated>
            <content:encoded><![CDATA[<h3>📝BLOG &gt;&gt; The serious malayalee and a light movie.Perfect retardation!</h3><blockquote>This was written in 2018. I had just finished watching a beautiful movie named <strong><em>Aanandam</em></strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/0*DT7oZ08o5rWSQB6d.jpeg" /></figure><p>Aanandam a movie portraying the story of a college tour, released in 2016 is not the talk of this write-up. But yes it is!<br> Being a lazy movie buff I often get into this habit of prolonged movie watching spree. And that’s how I got to see this movie a few days back on Television. During the time of it’s release, I still remember my “over-hyped” movie critic friends tagging it as an extremely “Panjara” movie. One of the DQ(aka Dulquer Salman)fan who was all praise for a movie like “Bangalore Days” seemed very disappointed by this effort. In fact, I thought his gang in college would like this movie the most. Given, the fact that they were the №1 “Panjara” team in my class and the first thing I was reminded of was their gang, after watching the film. Now that college is over this discussion is irrelevant. Sorry “Panjara” team!<br> Coming back to the movie. Honestly speaking(Oh! Forgot the fact that I was writing), I wished If my college tour had a tinge of “Aanandam”, after watching it. “A-light-romantic-tour-Breezer”,is the phrase I prefer to wrap it with. But why was it not glorified among the target audience, mainly college students. I think I know the answer.<br> We are malayalees! We find pleasure in pointing out imperfections and we are damn serious; except while flirting. We are romantic at heart but hates anything explicit. We value friendship a lot but, we corner the weaker of our friends like wolves and bully them. We are incredibly possessive and mischievously jealous. We can never be coward but can easily slip out of any situation.<br> Hence it is proved that we cannot accept “Aanandam”. In case if you didn’t know, our tour was better!<br> PS: My views are entirely based on my friend circle and this blog is weakly based on the above mentioned circle.</p><p><em>Originally published at </em><a href="https://sonnynefarious.blogspot.com/2018/06/the-serious-malayalee-and-light.html"><em>https://sonnynefarious.blogspot.com</em></a><em> on June 4, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=632371d7c725" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is my passion?]]></title>
            <link>https://gautampanickarss.medium.com/what-is-my-passion-6d52225625ff?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d52225625ff</guid>
            <category><![CDATA[passion]]></category>
            <category><![CDATA[random-thoughts]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Wed, 12 Oct 2016 15:07:00 GMT</pubDate>
            <atom:updated>2021-01-06T07:06:07.244Z</atom:updated>
            <content:encoded><![CDATA[<h3>📝BLOG &gt;&gt; What is my passion?</h3><blockquote>When I wrote this, I had just finished college, back in 2016.</blockquote><p><strong>PASSION</strong>! Google gave me two suggestions for my search “<strong>passion meaning</strong>”. Of which the most likely definition that I could infer from my 18 years of studies was this “ <strong>strong and barely controllable emotion</strong>“</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*v4qZ0uQ5DIR0lj1N.jpg" /></figure><p>I had strayed into writing this blog with an incomplete answer to my question. If I go with the definition I had agreed to in the beginning, then finding an answer may seem so painless. Cricket was and continues to be my breath of life. I never get bored following this modest answer. And this modesty is what draws a fair degree of incompleteness.</p><p>The conflict arises here, and rightly so. When I dig in deeper into my passion, be it cricket,music or caricatures;the solitary reason that leaves the rest in solitude is MONEY. So, I began questioning the “modest” answer! Why cricket/music/caricature? And I got a sequential answer like the “fibonacci series”,the consecutive ones getting added on to give a completely new item. Like for example, “it’s my passion” + “It gets me fame and respect” = “it’ll help me earn a lot of money”.</p><p>And here I am, writing a blog in search of a complete answer for the most sought after question in the world. But my intentions are as clear as my eyes would see while hitting a cricket ball or as music I make when I have a good rhythm or as the characters that I etch while caricaturing;it is to make some money out of the views that I get for this blog!</p><p><em>Originally published at </em><a href="https://sonnynefarious.blogspot.com/2016/10/what-is-my-passion.html"><em>https://sonnynefarious.blogspot.com</em></a><em> on October 12, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d52225625ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New thoughts and new way of thinking!]]></title>
            <link>https://gautampanickarss.medium.com/new-thoughts-and-new-way-of-thinking-453fd670923?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/453fd670923</guid>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[random-thoughts]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Sat, 13 Sep 2014 16:12:00 GMT</pubDate>
            <atom:updated>2020-09-25T10:48:08.300Z</atom:updated>
            <content:encoded><![CDATA[<h3>📝BLOG &gt;&gt; New thoughts and new way of thinking!</h3><blockquote>This was also written when I was in my 12th Standard. Then, later adapted for Google blogger in 2014. Facebook was just getting it’s feet upright in India. I was a beginner back then, so excuse the naivety.</blockquote><p>Ah! I am about to say this wonderful incident which took place in “mydream avenue” at “some timeduringmysleep”. Well,now you got it,right?(it’s a fantasy that I am about to deliver). Yes,it is really worth reading( Please don’t confuse that I am bragging for readers at the moment). But, this tiny little incident will give you an idea about the current generation in India, jokes apart at least in Kerala. Two kids were standing near the gate of some school somewhere in my city(don’t forget the place that I had mentioned in the first para). From their somewhat hurried lip movements, I could smell a horrible day that had just passed by for the 13 year old looking kids(oh! yeah they seemed like kids,the reason which you will find about in the next few lines). I took a few steps towards them. “Oh! you are so girlish Varun… Otherwise…Otherwise you would have dropped your habit of picking up things from here and there,and then doing all the spy works”. The boy who said this was in kinda an agitated mood.The boy who was until then at the receiving end replied,”So you pretend not to be a girl?”. The other one’s answer surprised me. He gave that boy in reply, a gritty grim faced stare which lasted for some 10 seconds or so. You know! something we actually see in an Amal Neerad thriller(See,Amal Neerad is a Malayalam film director). And he hadn’t forgotten to give away the last piece of word that was being awaited for, “You’re gonna pay for it Varun, you are so really gonna pay for it…….<br><strong>SEE YOU ON FACEBOOK</strong>!”. Oh! boy this left me awestruck!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*tmJRAaFnbF9YHdpF.png" /></figure><p>And oh yes I am facebooked!</p><p><em>Originally published at </em><a href="https://sonnynefarious.blogspot.com/2014/09/new-thoughts-and-new-way-of-thinking.html"><em>https://sonnynefarious.blogspot.com</em></a><em> on September 13, 2014.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=453fd670923" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Indian Judicial System-How can you fly without wings?]]></title>
            <link>https://gautampanickarss.medium.com/the-indian-judicial-system-how-can-you-fly-without-wings-f6a3deeda6bb?source=rss-df0a7f33727c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6a3deeda6bb</guid>
            <category><![CDATA[indian-judiciary]]></category>
            <category><![CDATA[random-thoughts]]></category>
            <category><![CDATA[indian-politics]]></category>
            <dc:creator><![CDATA[Gautam Panickar SS]]></dc:creator>
            <pubDate>Fri, 12 Sep 2014 14:37:00 GMT</pubDate>
            <atom:updated>2020-09-20T17:35:52.751Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This was written when I was in my 12th Standard. Then, later adapted for Google blogger in 2014. I was a beginner back then, so excuse the naivety</blockquote><p>Let me present to you an <strong>analogue</strong> to the Indian Judicial System. <br>Once upon a time exactly 64 years ago , during one of the celebrated hours of the day a child was born.Sonny was actually born on 26th January 1950.The same day his jubilant dad bought him a gift ,a 1950 model car. Even though the gift was brought in with a prologue that it would commemorate his son’s birthday,it was actually meant for the whole family. The car was treated to be a priceless possession and was flaunted every time, given an opportunity.</p><p>Things went fine,since Sonny’s 10th birthday. They had their occasional drives,rides and party.Until that particular day,no one had actually realised about their ailing member in the family.Yes,the car.It was showing glimpses of ageing. All of a sudden it had started producing noises as creepy and irritating ,at times even overtaking little Sonny’s screams.But his dad persisted on going on with their 10 year old friend.In another 10 years the car was no more in working condition. But dad was so adamant that,wherever they went they had to go by this car(pun intended). Now,the 20 year old Sonny who was no more a teenager had something to say.”Dad,how can you expect us to go in this immovable piece?Do you expect us to push it through with our bare hands , or pull it by hiring an elephant?”But,this is what is all about when people become older their mind become more numb.Dad,was not going to lose the battle.He insisted on his decision.Being an obedient and obsessed son,Sonny took on his word.Years have gone by but the car hasn’t changed let alone the purpose for which it was bought for.The car was meant to carry Sonny and his family but for the past 45 years it is Sonny and family who have been carrying this car ,in fact pushing it through.Adding to the misery ,the car had never undergone single repair(excuse the pun).It has traveled untrodden paths,imagine how much strain Sonny would have undergone.<br> Sonny is now 68 years old and oh yes the car is still with him,looks like a messed up combination of rusty metals all around.</p><p><strong>— — — — — — — — — — — — </strong><br><strong>The car — The Indian Judicial System</strong> <br><strong>Sonny — India</strong> <br><strong>Sonny’s Family — Indian citizens</strong></p><p><em>Originally published at </em><a href="https://sonnynefarious.blogspot.com/2014/09/the-indian-judicial-system-how-can-you.html"><em>https://sonnynefarious.blogspot.com</em></a><em> on September 12, 2014.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6a3deeda6bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>