<?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 Varun Malhotra on Medium]]></title>
        <description><![CDATA[Stories by Varun Malhotra on Medium]]></description>
        <link>https://medium.com/@softvar?source=rss-75469a7abc3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*keVIxcMu20UWkNkNuoVOJw.jpeg</url>
            <title>Stories by Varun Malhotra on Medium</title>
            <link>https://medium.com/@softvar?source=rss-75469a7abc3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:27:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@softvar/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[Making Chrome Extension Smart By Supporting SPA websites]]></title>
            <link>https://medium.com/@softvar/making-chrome-extension-smart-by-supporting-spa-websites-1f76593637e8?source=rss-75469a7abc3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f76593637e8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <dc:creator><![CDATA[Varun Malhotra]]></dc:creator>
            <pubDate>Fri, 03 Jan 2020 21:10:27 GMT</pubDate>
            <atom:updated>2020-08-18T21:00:03.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making Browser Extension Smart By Supporting SPA websites</h3><figure><img alt="Showing Interaction among page, content-script, and background-script." src="https://cdn-images-1.medium.com/max/776/1*7ByuxF5rzrMlaurb5I_c2A.jpeg" /><figcaption>Copyright © Varun Malhotra</figcaption></figure><p>Browser Extension is a way to extend the nature of a webpage by modifying, adding, deleting, or/and by any other means. Think of it as a sword anyone can use to tweak the web the way they want for themselves. For example, you can get rid of annoying advertisements on a page, style the page you desire it to look like, block third-party libraries from stealing your private data and history, automate mundane work or anything you wish you can do with DOM and manipulate how front-end works with limited secured ways.</p><h3>Content Scripts</h3><p>Browsers provide an interface to read the details of a web page through a file, known as content-script, and DOM API to make changes. Each content-script has it’s own isolated environment.</p><p>As per the docs:</p><blockquote>Content scripts live in an isolated world, allowing a content script to makes changes to its JavaScript environment without conflicting with the page or additional content scripts.</blockquote><p>Read more <a href="https://developer.chrome.com/extensions/content_scripts">here</a>.</p><h3>What is a Single Page Application (SPA)?</h3><p>As the name suggests, there’s one single page for a particular website, and the same page gets re-rendered on page-URL change. All the critical resources, along with the content for the requested page, are downloaded before DOM construction. On viewing other pages, only the resources required to display them are dynamically downloaded and rendered on the same page. There’s no full reload of the website unless forcefully done. There are tons of resources available on the internet related to SPA pages to read.</p><p>We use a lot of SPA examples in our daily life like <em>Gmail</em>, <em>Facebook</em>, <em>Twitter</em>, <em>Medium</em>, etc. <em>GitHub</em> is also one of them which gradually moved to SPA entirely.</p><h3>How SPA behaves differently from multiple-pages?</h3><p>I can use content-script to make changes on a particular page. But the next question arises: When? When should we start modifying the page?<br>For non-SPA pages and for the pages where content is not loaded dynamically after page load, we can simply do our stuff after the <em>DOMContentLoaded</em> event is fired.</p><p>Being said so, you can now correlate the fact that for SPA pages, the DOM load event fires just once i.e. when the page is refreshed. All other times, data is fetched from the server using asynchronous AJAX calls. The callback executes once they are successful. It causes a problem for the content-script to determine when a new page loads. That’s where the content-script starts disappointing. Many hacks come into a cunning mind, but they too get failed at one or the other place.</p><p>So, how do we know that a new page has loaded without the whole website getting refreshed? That’s the “<em>hook</em>” I will be discussing in the next sections.</p><p>Before we come to the solution, I would like you to introduce to the Chrome Extension I developed and the exact problem I faced.</p><h3>Enhanced-GitHub</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*uCzt_rLS5lmX10NL8HpG7A.png" /><figcaption>Chrome Extension</figcaption></figure><p>It is a Chrome Extension that offers many benefits on the GitHub website, which are otherwise absent. Benefits like being able to copy contents of any file with just a single click, able to see the filesize before even opening it, download a file, directly access the raw link of a file, and view the size of the entire repository.</p><p>Link: <a href="https://chrome.google.com/webstore/detail/enhanced-github/anlikcnbgdeidpacdbdljnabclhahhmd?hl=en">enhanced-github</a></p><p><strong>PS: The extension has 20k+ active users currently 😍</strong></p><p>Below are the screenshots highlighting what changes would you observe on the GitHub website after installing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tI1pB_We8M5V5Ve0JZMDBA.png" /></figure><p><strong>Display repo size, size of each file, raw link, and the option to download a file directly.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*acVNLnJTzL9ePaMCiF3jYg.png" /></figure><p><strong>Copy button to copy the contents of the entire file to the clipboard.</strong></p><p><strong>Download the file directly to your system.</strong></p><p>Everything worked perfectly fine on GitHub when it was a non-SPA website.</p><p>After the introduction of SPA on the GitHub website, users of the extension started facing issues while navigating back and forth on the website. On the initial page-load, everything seems to work as intended. But clicking on any hyperlink no longer was reloading the browser tab. Instead, data was fetched using AJAX calls and rendered by replacing the same page with the new content. That means neither DOM load event would fire nor the content-script would be aware of the page change. This is where my tech-mind started exploring ways to tackle it.</p><h3>Approaches to tackling SPA behavior</h3><p><strong>Approach #1</strong></p><p>The first thing that comes in mind is to find out when does page-URL changes and immediately tell the content-script to behave as it would on page reload. The drawback of this approach is when page-URL changes, it doesn’t guarantee whether the page has the new content available instantly. A lot of websites update the page-URL first, which in turn fires the code responsible for fetching data according to the updated page-URL. The time required to download resources will vary and will most likely be ahead in time than of content-script execution time. It makes content-script execution prone to errors as the latest DOM has still not constructed. Certain required elements would not be present, and some stale selectors would result in false-positive results.<br>Hence, <strong>discarded</strong>.</p><p><strong>Approach #2</strong></p><p>Should I add a timeout and then invoke content-script execution? Again, the drawback is the exact duration of fetching resources is not known, which would cause errors.<br>Hence, <strong>discarded</strong>.</p><p><strong>Approach #3</strong></p><p>Should I add an interval after getting a page-URL change event that checks whether the required element is visible on the page? It might seem like the perfect time to execute content-script, but it still not the right way.<br>Consider a case where your content-script adds an element to the DOM on every page. Initially, it works correctly. But as soon as the page-URL change event is triggered and we check for the visibility, we will again be fooled by the stale DOM content. New content has yet not fetched, whereas the old DOM is still on the page.<br>Hence, <strong>discarded</strong>.</p><p>The above approaches taught me that these never lead to a perfect all-in-one solution.<br>The only way is to know the hook when the page-URL has changed, and the page has successfully re-rendered. Reading the docs related to webRequest API, I knew I had found the sword now.</p><h3>Background Script and hooking with webRequest and webNavigation APIs</h3><blockquote>The background script is a program running in the background to monitor events that a browser triggers, such as navigating to a new page, closing a page, etc.<br>webRequest API — Read the <a href="https://developer.chrome.com/extensions/webRequest">docs</a></blockquote><p><em>&lt;manifest.json&gt;</em></p><pre>&quot;background&quot;: {<br>  &quot;scripts&quot;: [&quot;background.js&quot;],<br>  &quot;persistent&quot;: true<br>}</pre><p>As per docs:</p><blockquote>The only occasion to keep a background script persistently active is if the extension uses <a href="https://developer.chrome.com/webRequest">chrome.webRequest</a> API to block or modify network requests. The webRequest API is incompatible with non-persistent background pages.This API assists in observing and analyzing the traffic. One can spy on every single call that’s requested.</blockquote><p><strong>Using webNavigation API </strong>— Read the <a href="https://developer.chrome.com/extensions/webNavigation">docs</a></p><p>Firstly, I had to add it to the list of permissions since any API prefixed with chrome.* has to be granted permission by the user to use it.</p><p><em>&lt;manifest.json&gt;</em></p><pre>&quot;permissions&quot;: [&quot;*://*.github.com/*&quot;, &quot;storage&quot;, &quot;webRequest&quot;, &quot;<strong>webNavigation</strong>&quot;]</pre><p><em>&lt;background.js&gt;</em></p><pre>chrome.webNavigation.onHistoryStateUpdated.addListener(details =&gt; {<br>  tabId = details.tabId;<br>  currentUrl = details.url;<br>  // ...<br>});</pre><p>We are now sure that whenever the page-URL changes, we will always be notified by the above code and has the latest page-URL.</p><p>Using the <em>onHistoryStateUpdated</em> event, we can spy on every page-URL change event. This event also provides the tab-id and the new page-URL. Tab-id is required to communicate with the content-script. We will be discussing this in the next paragraph.</p><p><strong>Using webRequest API </strong>— Read the <a href="https://developer.chrome.com/extensions/webRequest">docs</a></p><p>The only thing I needed to know was which call(s) are responsible for rendering the data on the GitHub website.<br>I was able to identify that GitHub has implemented server-side rendering. I was more than lucky to figure out that there is a single request to spy. I mentioned webRequest API earlier, which helps in analyzing the requests. So, I used the onCompleted event provided by webRequest API to mark the call has responded successfully.</p><p>I had to add it to the list of permissions since any API prefixed with chrome.* has to be granted permission by the user to use it.</p><p><em>&lt;manifest.json&gt;</em></p><pre>&quot;permissions&quot;: [&quot;*://*.github.com/*&quot;, &quot;storage&quot;, &quot;<strong>webRequest</strong>&quot;]</pre><p><em>&lt;background.js&gt;</em></p><pre>chrome.webRequest.onCompleted.addListener(function(details) {<br>  const parsedUrl = new URL(details.url);</pre><pre>// TODO: filter and check if the desired URL has completed</pre><pre>}, { urls: [&#39;*://*.github.com/*&#39;] });</pre><p>The above code will spy on every single request. The aim is to know which request is responsible for fetching and re-rendering the page. Once we know, it has to be communicated to the content-script for its execution.</p><p>Moving on to the next section, I’ll tell how to determine the time to fire the content-script execution.</p><h3>Communicating between background and content-script</h3><p>Knowing when page-URL changes and the corresponding request completes, I simply had to convey the message to the content-script to behave as if the tab has refreshed with the new page-URL.</p><p><em>&lt;background.js&gt;</em></p><pre>chrome.webRequest.onCompleted.addListener(function(details) {<br>  const parsedUrl = new URL(details.url);</pre><pre>if (currentUrl &amp;&amp; currentUrl.indexOf(parsedUrl.pathname) &gt; -1 &amp;&amp; tabId) {<br>    chrome.tabs.sendMessage(tabId, { type: &#39;page-rendered&#39;});<br>  }<br>}, { urls: [&#39;*://*.github.com/*&#39;] });</pre><p>As I mentioned earlier, I was able to figure out the call which pulls data from the GitHub server and page gets re-rendered once the content has downloaded.<br>The above code filters the call which is responsible for fetching the data for the new page and convey the same to the content-script.</p><p><em>&lt;content-script.js&gt;</em></p><p>Listening to the messages being sent by background script to the content-script is easy and can be achieved by attaching an event listener.</p><pre>chrome.runtime.onMessage.addListener(function(request) {<br>  if (request &amp;&amp; request.type === &#39;page-rendered&#39;) {<br>    // call method which gets fired as if new page is opened<br>  }<br>});</pre><p>Once a message is received by the content-script, I just need to invoke the function responsible for fetching and displaying the data.</p><p>Source Code — <a href="https://github.com/softvar/enhanced-github">GitHub</a></p><h3>References</h3><ol><li>Chrome Extension — <a href="https://chrome.google.com/webstore/detail/enhanced-github/anlikcnbgdeidpacdbdljnabclhahhmd?hl=en">https://chrome.google.com/webstore/detail/enhanced-github/anlikcnbgdeidpacdbdljnabclhahhmd?hl=en</a></li><li>Firefox Add-on — <a href="https://addons.mozilla.org/en-US/firefox/addon/enhanced-github/">https://addons.mozilla.org/en-US/firefox/addon/enhanced-github/</a></li><li>Microsoft Edge Add-on — <a href="https://microsoftedge.microsoft.com/addons/detail/enhanced-github/eibibhailjcnbpjmemmcaakcookdleon">https://microsoftedge.microsoft.com/addons/detail/enhanced-github/eibibhailjcnbpjmemmcaakcookdleon</a></li><li>Source Code — <a href="https://github.com/softvar/enhanced-github">https://github.com/softvar/enhanced-github</a></li></ol><p>Other</p><ol><li>Chrome Extension content script — <a href="https://developer.chrome.com/extensions/content_scripts">https://developer.chrome.com/extensions/content_scripts</a></li><li>Chrome Extension background script — <a href="https://developer.chrome.com/extensions/background_pages">https://developer.chrome.com/extensions/background_pages</a></li><li>webRequest API — <a href="https://developer.chrome.com/extensions/webRequest">https://developer.chrome.com/extensions/webRequest</a></li><li>webNavigation API — <a href="https://developer.chrome.com/extensions/webNavigation">https://developer.chrome.com/extensions/webNavigation</a></li></ol><p>I hope you might have learned something new in this post. For any queries, drop me words at <a href="/service/mailto:varun2902@gmail.com">varun2902@gmail.com</a>.<br>Please recommend, tweet and share to boost my confidence for more write-ups. Thanks a lot!</p><p>Would love to be connected via the following platforms:</p><blockquote><a href="https://github.com/softvar">GitHub</a> | <a href="https://twitter.com/s0ftvar">Twitter</a> | <a href="https://www.linkedin.com/in/softvar">LinkedIn</a> | <a href="https://stackoverflow.com/users/2494535/softvar">StackOverflow</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f76593637e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide to Migrate From EC2 to Droplets]]></title>
            <link>https://medium.com/hackernoon/guide-to-migrate-from-ec2-to-droplets-ec29337e7616?source=rss-75469a7abc3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec29337e7616</guid>
            <category><![CDATA[software-deployment]]></category>
            <category><![CDATA[digitalocean]]></category>
            <category><![CDATA[server-configuration]]></category>
            <category><![CDATA[python-flask]]></category>
            <category><![CDATA[server-migration]]></category>
            <dc:creator><![CDATA[Varun Malhotra]]></dc:creator>
            <pubDate>Mon, 06 Feb 2017 19:18:40 GMT</pubDate>
            <atom:updated>2017-07-15T22:19:10.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*40YJskhG0AD297OQTMibKg.png" /></figure><p><em>Note: This article isn’t about comparing Amazon EC2 and DigitalOcean Droplet. It’s just why I decided to shift and how easy it was.</em></p><p>Hey, guys! I daydream myself as a Software Engineer, who loves software designing and development to build something useful for humans. Developing a software not only involves programming but also to deploy it(assuming it to be a <em>web-app</em> in this article) to be easily accessible anytime anywhere over the internet. This deployment stuff obviously requires a server to host the site and <em>configuring it properly</em> in order to serve the user-made calls. Behind the human-computer interaction, there’s a lot of fuzz going on the servers. Static sites, which are simply built for the purpose of displaying information like portfolio sites, are easy to host and generally don’t require a <em>dedicated</em> server. There are lots of good options out there in the market like Github’s free hosting which is handy to operate and very popular these days.<br>The server is essential when there’s a need to process user input, persist data and retrieve it from a database, or do some computational work. Following is the minimalistic software lifecycle chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*2-PLlAPVzLg5TyzyUbsZ4g.png" /></figure><p>This post happens to be a lengthy one as it actually explains a step-by-step procedure to shift from one server to another. Why don’t you grab up a cup of coffee to enjoy the show?</p><p>Sometime back in time, I developed two web-apps back to back, officially named as <a href="http://json2html.varunmalhotra.xyz/"><strong><em>Json2Html</em></strong></a> and <a href="http://translatr.varunmalhotra.xyz/"><strong><em>Translatr</em></strong></a>. [ <em>Click names to view live demo </em>]</p><p><a href="http://json2html.varunmalhotra.xyz/">Json2Html</a> helps in converting JSON structure into a well defined tabular structure whereas <a href="http://translatr.varunmalhotra.xyz/">Translatr</a> tries to help the (multilingual) audience to translate a text or a paragraph into more than one language at once. Please give both the apps a shot and provide some feedback. Thank You! 🙏</p><p>I choose Python as the programming language for both the apps just because I prefer it’s ease of use. Once the apps were programmed and ready for the general availability, came the time to deploy them. As it was my first time deploying some real stuff, I chose <em>H</em><a href="https://www.heroku.com/"><em>eroku</em></a> which provides a rich ecosystem of pre-integrated extensions and services to deploy great apps at scale with little configuration. But I wasn’t happy at all. I observed <em>Heroukuapp </em>to<em> </em>be slow<em> </em>plus I always like things to be managed my own way. Moreover, I consider <em>trying things</em> over getting things done with ready-made solutions to be a great self-learning experience in any field. I usually learn technologies by actually building stuff myself. Hands-on experience is the power bank of knowledge.<br>Soon after some time, I went with Amazon Ec2 for it’s most obvious reasons.</p><blockquote><strong>Amazon</strong> Elastic Compute Cloud (<strong>Amazon EC2</strong>) is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. <strong>Amazon </strong>EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction.</blockquote><p>It’s a very popular cloud hosting provider in the market, a reliable, secure, completely controlled, and easy to start with provider. Moreover, it offers one year long free-tier plan for the beginners to get hands-on experience with AWS Cloud Services. Who wouldn’t like to play with such liberty? 😎</p><p>So, I went through the relevant <a href="https://aws.amazon.com/documentation/ec2/">AWS Amazon Docs Online</a> and must admit that the quality of docs is very very impressive. They are written in a well-organized manner, covering exactly what the user actually wants. I think Amazon has used Machine Learning here too. 😜</p><p>My EC2 t2.micro instance was ready to rule after managing a lot of struggle configuring it like a new born baby. The server was quite a noob and obeyed my commands well and was up to serve the audience. It was a moment of gratification.</p><p>Ah! The time hits the door exactly after a year and reminded me of the free tier plan’s expiry. I started getting emails to pay off the bill for the extra graceful month. The cost, as it reads, was something around $22/month. I couldn’t believe that my personal portfolio cum blogging site, running just two more python apps could generate such a handsome amount of money. I was totally confused but as soon as the next email arrived in my inbox clearly indicating me to pay the another next month bill which was projected to be somewhat around $25 otherwise the instance would forcefully be shut down; I decided to look out for other options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgRUqOibK8e0yOo5LtYEdg.png" /></figure><p>For a moment, I couldn’t understand the dilemma I was in; Whether I should start making the real value from the organic traffic which could save me a couple of dollars from my pants or I should first prepare myself to switch to some lower-range option available and then think of monetization.</p><p>This hit me hard to think wisely. Finally, after researching and discussing stuff with my colleagues, I considered DigitalOcean to be best suitable for my overall personal requirements.</p><h3>DigitalOcean Setup</h3><blockquote>DigitalOcean is a simple cloud hosting provider built for developers. Every droplet which spins up is a new VPS for our personal use. It’s very easy to deploy a blazing fast SSD cloud server in just 55 seconds within an easy-to-use control panel. Plans start at $5 per month and include 512MB RAM, 20GB SSD Disk, and 1TB Transfer.</blockquote><p><strong>A damn good deal, indeed.</strong></p><p>I signed up instantly with a new account. Check out these <a href="http://www.newcoupons.info/digitalocean-coupon-codes/">promo codes</a> before entering billing info to get some <em>good </em><a href="https://m.do.co/c/b9b0f1f34c56"><em>discount</em></a>. Get flat $10 discount using <a href="https://m.do.co/c/b9b0f1f34c56">this link</a>. Once the account was created, verified and billing info was provided, I proceeded to create a new droplet.</p><blockquote><strong>STEP 1: Choose an image</strong></blockquote><p>I considered <strong><em>Ubuntu 14.04</em></strong> as I’m much more familiar with this OS. Also, most of the DigitalOcean blogs are written considering this OS only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxLs3cY9MA9ppl_3IiiKfw.png" /></figure><blockquote><strong>STEP 2: Choose the droplet size</strong></blockquote><p>I went with <strong><em>$5 plan</em></strong> for its obvious benefits in lesser cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1OjIEolcGwyd1WMbvnqNA.png" /></figure><blockquote><strong>STEP 3: Choose a datacenter</strong></blockquote><p>I choose <strong><em>New York 3</em></strong> based on my website traffic history. I went through my Google Analytics account associated with my website and realized most of the visitors are coming from the US. So, it’s better to choose the datacenter located nearest to the majority of visitors’ geographical location to enjoy the benefits of reduced latency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-SiRHGiL2u1qzhB4z7C8pg.png" /></figure><blockquote><strong>STEP 4: Other Information</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6zKVSyq4cbzR7bsHhjqHQ.png" /></figure><p>I created a new ssh key for the droplet.</p><pre>cd ~/.ssh<br>ssh-keygen -t rsa -f ubuntu_512mb_nyc3_01 -C “<a href="/service/mailto:varun2902@gmail.com">myemail@gmail.com</a>”<br>ssh-add ~/.ssh/ubuntu_512mb_nyc3_01<br>cat ubuntu_512mb_nyc3_01.pub</pre><p>I Copied and pasted the content in the box shown below. The SSH key is very private, so please don’t share it or post it publicly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*yepT_3vlvCFNZZEemv3HZg.png" /></figure><blockquote><strong>STEP 5: And it’s done!</strong></blockquote><p>I hit the <em>Create</em> button and Voila! I have my own server up and running with my preferred choice of OS installed in it.</p><h3>Add a domain</h3><p>Now, point server’s IP to the domain name. I entered my personal website URL to start managing my DNS within my newly created DigitalOcean account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zJ7vRxvp9AeHoaxFP7G_A.png" /></figure><p>To make a new hostname, I only need to fill in the A record. If you are using an IPv6 address, you should enter it into the AAAA record.</p><p><strong>A Records</strong>: I entered in my server’s IP address and the hostname itself. The hostname will be prepended to the domain name. My screen looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*igfEawOuReiPqz0RWqNR_Q.png" /></figure><p>Read more on <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean">the DigitalOcean blog</a> in detail.</p><h4>Point to DigitalOcean nameservers from common domain registrars</h4><p>I use Namecheap as my default registrar. It’ simply awesome. I bound my domain name to one of the droplets by changing the domain name servers with the domain’s registrar.<br>Read more on <a href="https://www.digitalocean.com/community/tutorials/how-to-point-to-digitalocean-nameservers-from-common-domain-registrars">the DigitalOcean blog</a> in detail.</p><h3>Install apache and get the static site up and running</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*QdGgN8x-PSih9WLY8i7vMw.png" /></figure><p>I usually prefer Apache over Nginx as I have been using it for long and I’m less accustomed to Nginx. Apache is a free open source software which runs over 50% of the world’s web servers. The Apache web server is the most popular way of serving web content on the internet.</p><p>To install apache, I ssh to my server.</p><pre>ssh root@12.34.56.789</pre><p>And installed apache via the following commands.</p><pre>sudo apt-get update<br>sudo apt-get install apache2</pre><p>That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. <a href="http://12.34.56.789)./">http://12.34.56.789).</a> The page should display the words “It works!” like <a href="https://assets.digitalocean.com/tutorial_images/333VJ.png">this</a>.</p><p><strong>How to Find your Server’s IP address</strong></p><p>The following command helps revealing server’s IP address.</p><pre>ifconfig eth0 | grep inet | awk &#39;{ print $2 }&#39;</pre><h3>Securely transfer files from server to remote and vice-versa</h3><p>I used sftp for transferring files between a remote server and a local server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*ZvklCXr7Z-4hG4e4EglA9A.png" /></figure><blockquote>SFTP, which stands for SSH File Transfer Protocol, or Secure File Transfer Protocol, is a separate protocol packaged with SSH that works in a similar way over a secure connection. The advantage is the ability to leverage a secure connection to transfer files and traverse the filesystem on both the local and remote system.</blockquote><p>Read more on <a href="https://www.digitalocean.com/community/tutorials/how-to-use-sftp-to-securely-transfer-files-with-a-remote-server">the DigitalOcean blog</a> in detail which is an ultimate guide on how to transfer files from one server(eg: A<em>mazon EC2</em>) to local server(eg: <em>personal system</em>) and then to the another server(eg: <em>DO droplet</em>).</p><p>This way of transferring is obviously very verbose in nature. One can opt for easy to use interface like thatof <a href="https://cyberduck.io/">Cyberduck</a>. I have used it and is quite useful sometimes.</p><h3>Deploying Python Applications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*cimZfmrpK3DyNngiwam1VA.png" /></figure><p>My two web apps: <a href="http://json2html.varunmalhotra.xyz/"><strong>Json2Html</strong></a><strong> </strong>and<strong> </strong><a href="http://translatr.varunmalhotra.xyz/"><strong>Translatr</strong></a>, which I mentioned earlier, both uses <strong><em>Flask</em></strong>, a micro-framework for <strong><em>Python</em></strong> based on <em>Werkzeug</em>.</p><p>My next step was to deploy them successfully on the server to be accessible over the internet to the audience.</p><blockquote><strong>STEP 1</strong>: Install mod_wsgi</blockquote><pre>sudo apt-get install libapache2-mod-wsgi python-dev</pre><blockquote><strong>STEP 2: </strong>Enable mod_wsgi</blockquote><pre>sudo a2enmod wsgi</pre><blockquote><strong>STEP 3</strong>: Creating <strong>Flask</strong> app</blockquote><p>Check out the following apps with their source code to build up a basic Flask app.<br>1. <a href="http://json2html.varunmalhotra.xyz/">Json2Html</a> — <a href="https://github.com/softvar/json2html-flask">View Source Code</a> <br>2. <a href="http://translatr.varunmalhotra.xyz/">Translatr</a> — <a href="https://github.com/softvar/translatr">View Source Code</a></p><p>Always have all your requirements in a file. Let’s name it: <br><strong><em>requirements.txt. </em></strong>Its content can be manually written or run <strong><em>pip freeze</em></strong> which will list down all the installed modules so far in the virtual environment. Eg:</p><pre>Flask==0.10.1<br>requests</pre><blockquote><strong>STEP 4</strong>: Setting up Python environment using <strong>virtualenv</strong></blockquote><p>Using pip to install virtualenv and Flask. Installed pip through apt-get.</p><pre>sudo apt-get install python-pip</pre><p>Use pip to install <strong><em>virtualenv</em></strong> using the following command:</p><pre>sudo pip install virtualenv</pre><p>I created a virtual Python environment(<strong><em>VENV</em></strong> is the name I gave to my temporary environment).</p><pre>sudo virtualenv <strong><em>VENV</em></strong></pre><p>Now, I installed Flask in that environment by activating the virtual environment with the following command:</p><pre>source <strong><em>VENV</em></strong>/bin/activate</pre><p>Now, I installed all the dependencies of my app as listed in <strong><em>requirements.txt</em></strong> above.</p><pre>pip install -r requirements.txt</pre><p>I verified if everything’s working fine by running:</p><pre>python __init__.py</pre><p>I got a message that my server is running on <a href="http://127.0.0.1:5000/"><strong><em>127.0.0.1:5000</em></strong></a><strong><em>. </em></strong>It guaranteed that everything was working fine.</p><p>I created Virtual Hosts for different apps with different domains to point at. Creating Virtual Hosts has been covered up in next section.</p><p>Read more on <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps">the DigitalOcean blog</a> in detail.</p><h3>Set Up Apache Virtual Hosts</h3><blockquote>Virtual Host is the basic unit which allows the administrator to use one server to host multiple domains or sites off of a single interface or IP by using a matching mechanism. This is relevant to anyone looking to host more than one site off of a single VPS.</blockquote><blockquote><strong>STEP 1:</strong> Change directory as follows:</blockquote><pre>cd /etc/apache2/sites-enabled</pre><blockquote><strong>STEP 2:</strong> Sample Virtual Host file, let’s call it <strong>example.conf</strong></blockquote><pre>vim <em>example.conf</em></pre><pre># Content of <em>example.conf</em></pre><pre>&lt;VirtualHost *:80&gt;<br>    ServerAdmin admin@example.com<br>    ServerName example.com<br>    ServerAlias <a href="http://www.example.com/">www.example.com</a><br>    DocumentRoot /var/www/example.com/public_html<br>    ErrorLog ${APACHE_LOG_DIR}/error.log<br>    CustomLog ${APACHE_LOG_DIR}/access.log combined<br>&lt;/VirtualHost&gt;</pre><blockquote><strong>STEP 3:</strong> Enable the Virtual Host</blockquote><pre>sudo a2ensite <em>example.conf</em></pre><p>STEP 4: Restart the apache server</p><pre>sudo service apache2 restart</pre><p>Read more on <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts">the DigitalOcean blog</a> in detail.</p><p>Hope you might have learned something new in this post.<br>For any queries, drop me words at <a href="/service/mailto:varun2902@gmail.com">varun2902@gmail.com</a>.<br>Please recommend, tweet and share to boost my confidence for more write-ups. Thanks a lot!</p><p>I’m a social person. Would love to be connected on the following:<a href="http://varunmalhotra.xyz/"><br>Website</a> | <a href="https://github.com/softvar">Github</a> | <a href="https://twitter.com/s0ftvar">Twitter</a> | <a href="https://www.linkedin.com/in/softvar">LinkedIn</a> | <a href="http://stackoverflow.com/users/2494535/softvar">StackOverflow</a></p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec29337e7616" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/guide-to-migrate-from-ec2-to-droplets-ec29337e7616">Guide to Migrate From EC2 to Droplets</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ProductHunt Users Worldwide]]></title>
            <link>https://medium.com/@softvar/producthunt-users-worldwide-c4b9a6432aa1?source=rss-75469a7abc3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4b9a6432aa1</guid>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[product-hunt]]></category>
            <category><![CDATA[webgl]]></category>
            <dc:creator><![CDATA[Varun Malhotra]]></dc:creator>
            <pubDate>Sat, 27 Feb 2016 23:03:25 GMT</pubDate>
            <atom:updated>2016-03-01T20:26:32.771Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately, I have been addicted to opening <a href="https://www.producthunt.com/">ProductHunt(PH)</a> time to time and view trending tech products. Sometimes the list is so beautifully curated that my hours just flew away reading post by post. Something new in tech, hitting the market, surely deserves at least a glance. That’s what I like the most about PH, a platform where one can hunt for good technological products.</p><p>I, myself, posted one of my side-project <a href="https://www.producthunt.com/tech/json2html">Json2Html</a> on PH which luckily got traction and gave me a good surprise on this New Year 🙌. It seriously feels awesome when people are talking about your product(especially positive :P) and there’s a direct session of questions and answers. For those few days, my daily time spent on PH increased exponentially. Umm, slightly a bad habit it was for some time… 😉😉</p><p>No doubt PH has a good user interface but a well organized list of posts on weekly / monthly basis is certainly missing. Thus, my search for the same began and I landed on some already created stuff using PH API. <a href="http://phlics.com/">Phlics</a> is what I would say is a good use of public API. But my hunt still continued…</p><h3>Hands on different API for data collection</h3><p>While I was playing a little with PH API, I got to know that it doesn’t provide much about a particular user, but yes, it surely provides the Twitter handle, which in itself is a good source of a lot of valuable data-set. Of course, my next step was to jump upon Twitter API documentation. Analyzing a sample user twitter data, the first thing that caught my attention was the location attribute, the fundamentally most common segment to analyze first. Geographical distribution of user base is a common metric which helps in future product planning and target the correct audience smartly. 😎</p><p>So the hunt nearly slows down as the coding session started dissolving me. Apart from the data-set, I was mostly concerned about the visual representation of the location based data in a more subtle way rather than just a bar-chart. Woot! I could recall <a href="https://www.chromeexperiments.com/globe">google-experiments</a> on demonstrating some geographical depiction of location based data-set.</p><h4><a href="https://www.chromeexperiments.com/globe">The Webgl Globe</a> — A Google’s open platform experiment for geographic data visualization.</h4><p>The good part of webgl globe is scaling of huge data as well as a better 3D modelling of data with which a user can interact nicely. The library assumes the data to be a continuous repetitive Array of three values i.e (latitude, longitude, magnitude). For eg. [23.45678, -123.98765, 0.006428] which means the geographic coordinates(23.45678, -123.98765) actually represent a particular location and the magnitude(0.006428) basically tells the library the normalized magnitude weightage for that location. What I mean by normalized magnitude weightage is: mostly the data-set values cover a wide range, so for it’s representation, it is necessary to club the duplicates and then the magnitude for each location has to be normalized. Normalizing of data simply refers to the mapping of domain range to the desired output range. The library expects the magnitude values to be in [0, 1] range. The simple way of normalizing the values is as follows:</p><p>// assuming magnitude Array to be [69, 20, 46, 1 , 8, 15, 96, 100, 2]<br>1. Find the largest value (in our case, it’s 100)<br>2. Divide each value(magnitude) of Array with the largest value.<br>3. So, the Normalized array as per the basic maths would look something like: [0.69, 0.20, 0.46, 0.01, 0.08, 0.15, 0.96, 1, 0.02]<br>Just for the understanding and co-relation, one can relate these values to the density of population in a particular location assuming data-set to be number of users.</p><p>Again, to get the geocodes for different users’ location from twitter data, I had to use some public API. What can be better than using the <a href="https://developers.google.com/maps/documentation/geocoding/intro">Google Maps Geocoding API</a> for this purpose.</p><blockquote>Product Hunt Geographic distribution of users is now listed on <a href="https://www.chromeexperiments.com/globe">Google Experiments Site</a> also.</blockquote><h3>Technical Challenges faced</h3><p>The most common limitation dealing with third-party public APIs is Rate Limiting and that too when different services have their own limits. Below are the different late limiting criteria for three different third-party public API’s I used for generating the final plot-able data-set.</p><ol><li><a href="https://api.producthunt.com/v1/docs/rate_limits/headers">ProductHunt API (PHAPI)</a> -<br>Rate limiting is applied per application. You can make up to 900 requests every 15 minutes.</li><li><a href="https://dev.twitter.com/rest/public/rate-limits">Twitter API(TAPI)</a> -<br>It allows maximum 180 API Requests / 15-min window for both: user-auth and app-auth.</li><li><a href="https://developers.google.com/maps/documentation/geocoding/usage-limits">Google Maps Geocoding API (GMGAPI)</a> -<br>Users of the standard API can make up to 2,500 free requests per day maintaining no more than 10 requests per second otherwise paid plans will do the needful.</li></ol><p>Now one can simply imagine the overhead to tackle each API limits separately. Below are the response times along with the list returned by each API tested on a micro Amazon EC2 Instance.</p><ol><li>PHAPI returns <strong>100 users list in approx 1 sec / request</strong></li><li>TAPI returns <strong>100 users list in less than 1 sec / request</strong><br>I was able to send and get <em>synchronous</em> <em>180 requests’ </em>data within less than a-minute. But let me correct, one has to <em>sit idle for the next 14.5 minutes</em>.</li><li>GMGAPI returns <strong>geocode in less than 1 sec / request</strong>.</li></ol><p>Let’s do some basic maths here,</p><ol><li>PHAPI returns approx. (100*60*15 = 9,00,00) users per 15-min window.</li><li>TAPI returns approx. (180*100 = 18,000) users per 15-min window.</li><li>GMGAPI returns approx. (2500) free geocodes per day.</li></ol><p>One can notice the significant difference among the data returned by three different APIs. This was really a pain in the ass. Oh, God!<br>What could be done to overcome GMGAPI limit?</p><blockquote><strong>Challenges Accepted, My Lord !!</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*QXYJOS8lwTD0PeXU8ETY7Q.gif" /></figure><h3>Workarounds / Hacks for the Challenges faced</h3><p>PHAPI is good enough and I was able to get <strong>4 lakhs users</strong> list in a reasonable time span of 1 hour 10 minutes <strong><em>(100*60*60*1.1 ≈ 4,00,000)</em></strong>. This was technically good response time for my service, indeed.</p><p>Through TAPI, I was able to gather roughly <strong>4 lakhs users</strong> list in approximately 5 hours 30 minutes <strong><em>(180*100*4*5.55 ≈ 4,00,000)</em></strong>. Somewhat a lot of time consuming task. To tackle this, I created different apps from same account which offers different security keys and tokens to access API, and Voilla! there was a significant drop in the overall time by a factor of n, where n being the number of different apps created.</p><p>But interestingly, not all Twitter users have set their locations. Out of valid 4 lakhs twitter accounts, <strong><em>only 2,53,796 users</em></strong> have set their location and have made it public to access. For the reset of them, either the location is not set/not publicly available or it’s not a valid address(For eg. I live in a cool place, X Planet, etc.). Human beings are crazy creatures, isn’t it? :D<br>Google gives a shit about these types of locations and hence, these locations fall into untracked category by the service.<br>Another surprising fact was, <strong><em>only 60,953 many locations</em></strong> came out to be unique, after clubbing data based on the location. This was required to save unnecessary API calls and writing my own caching algorithm. Wow, analyzing the data beforehand and pre-processing saved number of geocoding API requests by a factor of 8x. This is great for my eccentric mind :P and saved a lot of valuable time for planning next iterations.</p><p>Now, the next big challenge was to hit approx. <strong>61,000 GMGAPI calls</strong> with a hard-limit of requesting 2,500 requests per day. No one can wait for <strong><em>(61,000 / 2,500 ≈ 25 days)</em></strong> to get the small task get done. Also, for the initial testing period, I wasn’t in the mood of spending some amount to get the task done quickly. So, on an average I needed 24 such more Google Maps Geocoding API enabled apps to get the work done within few hours. 10 apps can be created per account, and luckily I got 3 personal google email-ids to have such 25 apps in all. Now using the 25 different access tokens being provided by each app, I was managed to get the geocodes within few hours. A real time saver trick and seriously what a drastic change. This is somewhat a very bad hack, but I call it an intelligent act for testing out initial releases. Please don’t use such Google hacks for any misuse, I being an exception :)</p><p>The challenges that were scary but accepted, were now successfully tackled and executed. <strong>Cheers</strong> ☕️ !! (<em>Sorry, I don’t drink</em> 🍺) :P</p><blockquote>La La La LaLaLa La La . . . . .</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*axz8k7mJZpHodhxVuZGZWA.jpeg" /></figure><p>Now moving on to my last task — the data representation, the most awaited and interesting part.</p><h3>Visual Representation of data</h3><p>The final task left was to plot the data points correctly on the globe. The data being gathered and processed accordingly was now ready to be served, but of course, after passing it through the Normalizing track, as I mentioned earlier, a requirement for webgl globe.</p><p>The final process of Data Visualization consists of series of sub-tasks as explained beautifully by <a href="http://benfry.com/">Ben Fry</a>. They are:</p><blockquote>Acquire -&gt; Parse -&gt; Filter -&gt; Mine -&gt; Represent -&gt; Refine -&gt; Interact</blockquote><p><em>Yay, Yay and Yay !!!</em><br>After following the necessary steps mentioned above, everything was ready to be tasted 😋. I was so excited to see the hard work of many days finally speaking out loud in the form of beautiful and colourful pixels onto my colourful Mac OS X Retina screen. 🤓</p><blockquote>It’s being <strong>Featured on ProductHunt</strong> now :)<br><a href="https://www.producthunt.com/tech/producthunt-globe">https://www.producthunt.com/tech/producthunt-globe</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CI8Fil5LcHfPLbCQwCcEdg.png" /><figcaption>ProductHunt Users Wordlwide</figcaption></figure><p>The source code for the plotting part has been Open-sourced and is accessible on <a href="https://github.com/softvar/producthunt_globe">Github</a>.</p><p>If you like the post, please hit recommend / share on Twitter and let your comments keep flooding in regards.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4b9a6432aa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>