<?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 Sanay Dev on Medium]]></title>
        <description><![CDATA[Stories by Sanay Dev on Medium]]></description>
        <link>https://medium.com/@sanay.nitjsr?source=rss-99fc166bf5ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*JfuD26l5Eq-WA__pucAtVg.jpeg</url>
            <title>Stories by Sanay Dev on Medium</title>
            <link>https://medium.com/@sanay.nitjsr?source=rss-99fc166bf5ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 01:35:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanay.nitjsr/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[Callbacks, in general! Understanding and implementing it in Java.]]></title>
            <link>https://medium.com/@sanay.nitjsr/callbacks-in-general-understanding-and-implementing-it-in-java-24751185476c?source=rss-99fc166bf5ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/24751185476c</guid>
            <category><![CDATA[event-listener]]></category>
            <category><![CDATA[callback]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[interfacee]]></category>
            <dc:creator><![CDATA[Sanay Dev]]></dc:creator>
            <pubDate>Wed, 13 May 2020 20:01:27 GMT</pubDate>
            <atom:updated>2020-05-14T07:09:26.286Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_GZO1oEtSkFY405QQK02VA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@marvelous?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Marvin Meyer</a> on <a href="https://unsplash.com/s/photos/tech?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Callbacks had always been a daunting topic for me when I was new to Java. I was always intimidated by the nitty-gritty around implementing a callback using an interface, I am pretty sure if you are reading this you might be struggling too.</p><p>I would take a fairly simple approach to explain what is a callback, using a real-life scenario, and how can you implement it in Java(Must such scenarios exist? Hmm, preposterous).</p><p>If you have an experience in android, you must have unknowingly used callbacks so many times. Doesn’t seem to ring the bells yet? Try recalling how you implement a button click listener using the OnClickListener. And try implementing a simple button click listener on your own after reading this.</p><p>Consider this scenario, you live with your friend in your flat. For some very strange reason, you and your flatmate are sitting in different rooms, where you cannot see each other. But, you can definitely shout out to each other. You are binge-watching F.R.I.E.N.D.S and in no mood to have a chat with your buddy unless he shouts for you. When he calls, you need to respond, no matter what!</p><p>Also, to ease out the situation you guys can only talk in numeric codes.</p><ul><li>Code 0 means he is calling you for something un-important.</li><li>Code 1 means, there is something important.</li><li>Anything else is too difficult to be decoded by your brain.</li></ul><p>Let us model these real-life entities one by one.</p><h3>ShoutEventListener</h3><p>This is the listener interface, this is actually the place where you generalize what should be done when he shouts. Understand that, this is where you only specify in a very abstract manner and let the listener define what exactly needs to be done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcb944a6de77a26bdf8e285e0e49dfc4/href">https://medium.com/media/fcb944a6de77a26bdf8e285e0e49dfc4/href</a></iframe><h3>You</h3><p>You are the listener, you define how to respond to each of the code. In technical terms, you provide an implementation for the abstract method in the interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c9ba92e9c4428494476c753f8c9c007/href">https://medium.com/media/3c9ba92e9c4428494476c753f8c9c007/href</a></iframe><p>I am using a switch statement to handle each of the message categories.</p><h3>Friend</h3><p>This is the driver/handler code. This is where you define the event by the friend. The friend class users an instance of the Interface and a boolean flag to indicate if the listener has started listening or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e68790b934f93175a70b7fbd36c9b97/href">https://medium.com/media/3e68790b934f93175a70b7fbd36c9b97/href</a></iframe><p>If line 43 seems a bit overwhelming to you, just understand that, since the You class, implements the OnShoutListener interface, so you can assign an instance of OnShoutListener to You class. This is a basic use case of <a href="https://en.wikipedia.org/wiki/Polymorphism_(computer_science)">polymorphism</a>.</p><p>This is what the output looks like when you download all the code and save it with the file names as mentioned in the Github gists. Be careful as to save all the files in the same folder.</p><figure><img alt="A screenshot of the terminal with the output of the code." src="https://cdn-images-1.medium.com/max/380/1*sGen3_8SNvpJAafbkRdbXA.png" /><figcaption>A screenshot of the terminal with the output of the code</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24751185476c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containing people indoors, while letting the needy go out — the techie way.]]></title>
            <link>https://medium.com/polymorphread/containing-people-indoors-while-letting-the-needy-go-out-the-techie-way-580ceefccf0a?source=rss-99fc166bf5ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/580ceefccf0a</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sanay Dev]]></dc:creator>
            <pubDate>Fri, 03 Apr 2020 20:29:33 GMT</pubDate>
            <atom:updated>2020-04-07T05:47:26.797Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Containing people indoors, while letting the needy go out — the techie way.</h3><p>Covid19 is now a pandemic, people are dying in Italy, America, China and where not. India is in the second stage of being attacked by this killing machine, people are afraid.</p><p>Prime Minister, sir Narendra Damodardas Modi in his famous 8 O’ clock speech has announced a lockdown. People are more afraid now, rushing out to buy all that they can. Police and government officials are clueless as to how to contain people in their houses.</p><p>To provide whatever little help we can, we decide to make a solution that can help the government official issue passes to people, which they can carry on their smartphones while going out. This post is a high-level overview of how the solution works and a brief explanation of the features of the application. Please note that this is not an explanation of the code. We will come up with the coding details in coming up posts.</p><p>The pass looks like this, they are of three types.</p><ul><li>Pending</li><li>Approved</li><li>Rejected</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*NEnnCY_j4fXISKgnrxfYVA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*9Z3vJ9IV2Ky63OlyL8Bm_A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*lRCpzxZr6V_j-ZFsrWYrLw.jpeg" /><figcaption>The three categories of images, after getting issued/adding a request for issuing of one (Please don’t mind the absurd data, we were testing the app).</figcaption></figure><p>The passes once issues, can be approved or rejected by the administrative authority. And scanned for checking by the police.</p><p>The administration can see a list of all passes, by segregating them with a filter. They have the authority to accept or revoke pending passes, and change the status of accepted passes to rejected and vice-versa. They can also scan passes, and change their status.</p><p>The police, on the other hand, will be out on the check-posts, and they are only authorized to scan the QR code of a pass and see its detail. But, there was a catch, what if people would go about filling fake information? So, we allowed the police-men to cancel the acceptance status of a pass if the user was found abusing the privilege. Also, police-men cannot change the acceptance status of rejected passes, to prevent any undue advantage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*kVIOkqvj3ALYjvan7MezDw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*dzFm5iXJ2oO0vC5h7DdS0A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Jb--UVerwRrTTrCvBla-0g.jpeg" /><figcaption>These screenshots depict the application for the police and the administration (Please don’t mind the absurd data filled, we were testing the app).</figcaption></figure><p>So, looks like a lot of work right? It kind of was for developing it in just one day. But we needed to act fast and in the process, we developed the following complete solution.</p><ul><li>3 Android applications — One for the user, one for the police and one for the administration.</li><li>A back-end (REST API), secure enough and lightweight.</li><li>A database.</li></ul><p>Recently the government released an order which stated that the people in quarantine need to update their status on an hourly basis by sending an update to the government with their selfie. To avoid people from abusing this order, by sending fake photos. We implemented a quarantine status reporter, which allowed people to send photos on an hourly basis, which was geotagged with their location. Whenever a user would exit the quarantine facility, the administration would get a notification, also failing to send the status on time, or shutting down the location would notify the admin of the same. So, proper action can be taken.</p><p>Implementing this was fairly challenging, keeping in mind the internet speed and the storage occupancy in the database. I will refrain from explaining the details of how we did this, as this is a 1000ft high-level overview. But interested people can be in touch, follow this blog, we will post it up shortly.</p><p>We decided to go easy on the database and we chose MongoDB. The back-end was written in Flask using Python and the android application was developed using our very own android studio.</p><p>Developing the application and writing the REST API was a fairly simple task to do. Making it secure and making it available for everyone while significantly scaling the application was the difficult part.</p><p>Authenticating was necessary, so we provided a basic authentication to secure the login credentials. Basic Authentication is a method for the client to provide a username and password securely through HTTPS requests. The username and password are then base64 encoded(which is better than openly sharing it in the request body) and added to the request’s header in the format - Authorization: Basic&lt;credentials&gt;.</p><p>JSON Web Token (JWT) is an open internet standard that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. Whenever the client provides a valid username and password, a token is generated authorizing the client for accessing certain endpoints according to the authority of the username provided. This token has a certain life-time.<br>The token is signed by the API using a SECRET key which is only known to the API. If someone modifies the token, the server would fail to decode it, and hence avoiding malicious attacks, to some extent at least.<br>JWT tokens can also be given expiration time, this makes sure that even if a token is compromised, the hacker cannot use the route forever. The generated token is then passed back to the client, which is used by the client in further API calls. The client shares the token in request header in the format: x-access-token:&lt;token&gt;. Interception of the packets between a client and a server can still compromise the JWT and Basic Authentication, so it’s better to use them with HTTPS.</p><p>We made a custom decorator for validating the tokens and only allowing authorized calls to the routing methods. Well more on decorators later. But for the meanwhile just understand that decorators reduce code redundancy.</p><p>To make it available we containerized the API on docker, using a Dockerfile. While building our API we made sure to mention every new package installed in requirements.txt to ease the process of building docker images.</p><p>1. Docker eliminates the “it works on my machine” problem once and for all, making the step of deployment faster and easier.</p><p>2. Docker ensures consistent environments from development to production. Docker containers are configured to maintain all configurations and dependencies internally; you can use the same container from development to production making sure there are no discrepancies or manual intervention.</p><p>3. Docker images are easily portable and can be used in any host OS that supports docker.</p><p>4. Docker images can be easily scaled using Kubernetes or Docker Swarm, which works like a load balancer of sorts. By allowing the developer to customize the number of worker and manager nodes. Again, more on this later.</p><p>We then deployed the API to heroku and now the app is ready to use.</p><p>We will write articles regularly, and in due course will explain the steps in elaborate details.</p><p>Liked what we do, give both of <a href="https://github.com/saanayy">Sanay</a> and <a href="https://github.com/shazz10">Suraj</a> a follow on github. And star our <a href="https://github.com/Saanayy/token-generator">repo</a> if you like it.</p><p>Special thanks to <a href="https://github.com/naman7kr">Naman</a> and <a href="https://github.com/anirudh1107">Anirudh</a> for being the co-developers. Thanks, Suraj Suresh for the awsome UI and Vaibhaw, kudos for that fantastic management.</p><p>Edit: <br>We got featured in the newspaper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ytxg5KLNd4ZMyiEEBiawA.jpeg" /><figcaption>Well they changed some of the data on their own, pardon that!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=580ceefccf0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/polymorphread/containing-people-indoors-while-letting-the-needy-go-out-the-techie-way-580ceefccf0a">Containing people indoors, while letting the needy go out — the techie way.</a> was originally published in <a href="https://medium.com/polymorphread">polymorphRead</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>