<?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 Swaraj Rajpure on Medium]]></title>
        <description><![CDATA[Stories by Swaraj Rajpure on Medium]]></description>
        <link>https://medium.com/@swarajpure?source=rss-9362f1accc65------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zPGaZGyFEQqiLBu4M95hqg.jpeg</url>
            <title>Stories by Swaraj Rajpure on Medium</title>
            <link>https://medium.com/@swarajpure?source=rss-9362f1accc65------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:10:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swarajpure/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[My journey to SDE from a non-CSE background: magic of RDS]]></title>
            <link>https://swarajpure.medium.com/my-journey-to-sde-from-a-non-cse-background-magic-of-rds-c72e3c8ac860?source=rss-9362f1accc65------2</link>
            <guid isPermaLink="false">https://medium.com/p/c72e3c8ac860</guid>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[community]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Swaraj Rajpure]]></dc:creator>
            <pubDate>Sat, 26 Mar 2022 17:26:35 GMT</pubDate>
            <atom:updated>2022-03-26T17:26:35.602Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello all! This blog is going to be about my journey into tech, full stack development in specific. Let’s get started 🔥</p><h3>Introduction</h3><p>I’m currently working as Frontend Engineer at smallcase and pursuing final year of Instrumentation Engineering from VIT Pune (yes, a full time job while being in college 😛). I’m also a member of Real Dev Squad, a developers community where people are constantly learning new things, upskilling themselves and helping each other.</p><h3>When and how did it start</h3><p>It was March 2020 and whole of the India was under a lockdown due to Covid. All students were back to their homes. It was around May when the results of Google Summer of Code (GSoC) were out and I had seen a few folks from my college getting selected that year and previous years as well. It all felt very glamorous to me, to be honest. The LinkedIn posts, the fame, the association of your name with some programme conducted by Google, the stipend and everything else. That’s when I felt I should give it a shot.</p><p>As already mentioned in the introduction, I do not come from a CSE background and I did not have any senior friends as such to guide me back then. I was confused with where to start from, web development, mobile development, ML, cyber security and the list goes on. I started researching on YouTube and found out videos by Akshay Saini and Tanay Pratap on how web development is a good option. As any other normal kid, I started watching YouTube tutorials on HTML, CSS, JavaScript.</p><h3>The messy part</h3><p>Hype for React was real. I had just started with JS (JavaScript) and I quickly wanted to move to learning React, so I can make projects, have some experience, get into GSoC/internship at some company. I did not know what are the important parts of JavaScript, I tried asking people on Linkedin “what all things in JS which I could learn, before moving to React” and I did NOT get any proper responses, “learn all the basic things” were the replies, which did not help me much. So I was on my own again. There was a playlist that I was following on YouTube for learning JavaScript. It had pretty long videos on DOM Manipulation and that was the moment, “This is too long, I’m not doing this, I’m moving to React”. My worst mistake till date 😛</p><p>I jumped to React. I was following the YouTube videos, I was getting some confidence that I know something. Soon enough, I started getting errors and they scared the hell out of me. I could not understand the errors, because I had skipped some important parts of JS. I tried reading on stackoverflow, but I couldn’t understand the solutions too since I was unaware of the keywords there. I made up my mind, “React isn’t for me”.</p><p>I then moved to watching tutorials on NodeJS/ExpressJS. I was able to follow the tutorials this time, was enjoying it. I was gaining some confidence again. This time around, I started looking for internships in NodeJS. I found one opening on some Telegram group and I applied there. Got a call from HR, they said this will be an unpaid internship and I denied. I continued making projects in backend using Node, Express and Mongo.</p><h3>Found an amazing developers community</h3><p>I was scrolling through LinkedIn and I found a post by Ankush Dharkar, where he had mentioned something about a community that he was running — Real Dev Squad, aka RDS. I wanted to give it a try. I DMed him and I was in the discord server.</p><p>I had got some beginner friendly issues to work on. They were mostly around adding/improving README or CONTRIBUTING docs. I was just learning git at that time. 7 out of my first 10 PRs (Pull Requests) were about documentation only 😛. Then I moved into backend. The first issue that was given to me was adding Swagger docs in the codebase and I literally had no idea what is Swagger and how do you integrate it. I had tried reading up, but couldn’t understand. I gave up, someone else did that task. Then I was working on APIs, that was doable for me since I had an idea about it from the YouTube tutorials. I was getting a hang of the things going on.</p><p>Then I was told to write some integration tests and I still remember having almost an hour long call with Ankur Narkhede (owner of RDS backend) where he was explaining us what are integration tests, how do they work, how are they written. It was an amazing call, learnt a lot. I then wrote some integration tests as well.</p><p>I was in backend for like 2–3 months and then one of the members — Sumit, he started asking me to pick up tasks in React. Man, how could I explain him the hate relationship that I had developed with React 😂. I was avoiding him for some time and then he finally got me assigned to a React task. Now I was forced to overcome my fear. This time around, I wasn’t going for the YouTube tutorials, I went for the official docs directly. I was able to understand things now. I was able to complete the task that was given to me. Yes, I did need some calls to discuss my blockers.</p><h3>Getting comfortable with frontend tech</h3><p>Now my fear was going away. I was able to understand how to work with React. At this time, I also had to make a project for my college as a part of the semester. I created a full stack project with React, Express and Firestore. I also had brought my own domain and hosted it there. I was super happy that I was able to create a project just by myself.</p><p>Soon enough, we had a project in RDS which was supposed to be written in Ember. I was asked if I could lead it. I literally had not heard of Ember before, but still I did not want to lose an opportunity. I said yes. Other people were working on initial tasks and I was chilling 😂, not for long though. I was also given a task in Ember and I was forced to learn Ember as well. I took quite a long time to complete this task as I was quite reluctant to learn Ember. With some follow ups and motivational talks by Ankush, I did this task as well.</p><h3>Interview phase</h3><p>It was around March, 3–4 of my good friends had got internships by then in companies like NVIDIA, Deutsche Bank and I experienced what is called as “FOMO or Fear Of Missing Out”. I started applying to companies on LinkedIn, AngelList but did not hear back from most. Then I told my RDS friends that I’m looking for internship, will it be possible for them to refer me in their current/former companies. I got referred at Testbook and FamPay from RDS folks.</p><p>Started sending mails to companies as well. Had sent mails to Groww and smallcase, and I had heard back from smallcase. So I interviewed at Testbook, FamPay and smallcase. Fortunately, got selected in all the three companies. Decided to join smallcase for 6 month internship for July-December 2021. <a href="https://gist.github.com/swarajpure/3d21658856e45f78a16583db9072f4a6">Here is my interview experience</a> in case you’re interested.</p><p>smallcase happens to be the first company I’m working with. I was able to clear the interviews because of the learning-by-doing nature of RDS tasks and the technical discussions that we used to have. It was an amazing journey (it still is). If I can do it, you can do it too!</p><p>After my internship got over in December 2021, I was offered full time job from January 2022 itself and I’ll be graduating in May/June 2022. I am doing a job while I’m in college, which is so cool! I can afford to pay for my things, my travels and everything else 🔥</p><p>Coming from a middle class family and being able to pay my things + contribute in family expenses is a great feeling for me and my parents. All credits to RDS and the fellow members that we have here. Guidance is really important for anyone who’s starting out in their career and this is where RDS members come into picture. It’s a pretty awesome community of very talented, humble and helpful developers 💯</p><p>Special thanks to: Ankush, Akanksha, Ankur, Harshith, Nikhil, Pranav, Prakash, Rucha, Shashwat, Sumit. Couldn’t have been possible without your guidance and support!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c72e3c8ac860" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code reviews: How?]]></title>
            <link>https://swarajpure.medium.com/code-reviews-how-238f661023ac?source=rss-9362f1accc65------2</link>
            <guid isPermaLink="false">https://medium.com/p/238f661023ac</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Swaraj Rajpure]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 04:36:12 GMT</pubDate>
            <atom:updated>2022-01-13T04:36:12.270Z</atom:updated>
            <content:encoded><![CDATA[<p>Now that we’ve seen what are code reviews and why should we care about them in the <a href="https://swarajpure.medium.com/code-reviews-what-and-why-def9bf672d31">earlier blog</a>, it’s time to see how should we perform code reviews. Don’t get scared if you’re a total beginner to programming. There are some things which are very obvious to keep an eye on, even as beginners.</p><p>Most of the times people are under-confident — “I don’t know enough, so I can’t review someone else’s code”. Well, at what time do you think you’ll know enough? It won’t happen that one bright day, you’ll wake up and feel “now I know enough”. That’s just not going to happen. You should never wait for the perfect moment. Just get started and learn along the way. Perfectionists keep waiting for that perfect moment and nothing happens. Found this beautiful depiction of the same made by <a href="https://twitter.com/visualizevalue">@visualizevalue</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BAwCeR1pmnkzACyF" /></figure><p>Okay, enough philosophy. Let’s get to the point. What to look for when reviewing others’ code? This are just some starting points when you have absolutely no idea what to look for, in code reviews.</p><ol><li>Print statements:</li></ol><p>Yes, many people do leave print statements which they had used for debugging purposes lying in their code itself. These statements, if missed, will go to production and will be visible to users in the browser console (in case of JavaScript).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cs1HPIbFok60AdAz" /></figure><p>2. Commented code</p><p>I’m not talking about comments, I’m talking about commented code. What’s the point of keeping commented code? Either uncomment it, make some use of it or remove it altogether. You can always go back in git history and get back the code, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WKdg5gKgZnJ8LLLK" /></figure><p>3. Comments</p><p>Comments aren’t inherently good/bad, but they should be sparingly used. Your variable names should speak for what the variable/function is doing. However, sometimes adding comments becomes a necessity. For example, if the function is doing something which is not very easy to understand or you’re using a hack to fix some bug for the time being, then adding comments makes sense.</p><p>4. Typos</p><p>Typos may be in error/success messages, they may be in variable names. They may/may not be that critical, but if we can fix them, why not?</p><p>There is just a lot when it comes to reviewing code. I recently came across <a href="https://github.com/ryanmcdermott/clean-code-javascript">this amazing GitHub repository for clean code in JavaScript</a>. They’ve mentioned bad and good way of doing a certain thing pretty well, with examples. Would highly recommend you to check it out.</p><h3>What should be our tone while correcting some code?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl0Exc2KUt5v7XM6Xe%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl0Exc2KUt5v7XM6Xe%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl0Exc2KUt5v7XM6Xe%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="329" frameborder="0" scrolling="no"><a href="https://medium.com/media/1eec7ec6d351ce4b675375b7c4a73ad4/href">https://medium.com/media/1eec7ec6d351ce4b675375b7c4a73ad4/href</a></iframe><p>Firstly, let’s understand why are we even correcting someone’s code? We want to improve and maintain the code quality of our project, right? All kinds of improvements are welcome. Yes, people will make mistake and we’ll have to point out those mistakes but at the same time we have to make sure that we’re not targeting the person, we’re targeting a chunk of code. The PR author would have spent quite some time and energy for that PR and we MUST respect that.</p><p>If you find something that can be improved, don’t dictate “do it this way!”, rather ask some open-ended questions and let them decide for themselves. That way they will have their own “gotcha” moments and you won’t appear bad (just in case).</p><p>Let’s understand this from a couple of examples.</p><p>Scenario #1: A helper/utility function (lets call it helperFunction) already exists to do something but the author wrote the code from scratch (mostly unknowingly)</p><p>Bad:</p><blockquote>Why would you do it this way? Did not you notice helperFunction used in other parts of code? (quite rude honestly)</blockquote><p>Good:</p><blockquote>Use helperFunction here. (this is umm, okay)</blockquote><p>Better:</p><blockquote>We have a function called helperFunction which does exactly this. Do you think using that would be better in this scenario? Or do you feel that helperFunction needs to be modified to make it more efficient/inclusive?</blockquote><p>In the better part, we see that we used questions instead of statements. That leaves room for us to get improved + have the other person figure out things and choose the best + nobody feels attacked. Win-win situation, right?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F18395531&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fkatherine-ryan-gif-18395531&amp;image=https%3A%2F%2Fc.tenor.com%2FOJRSPj-OyUQAAAAC%2Fkatherine-ryan.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8260134e060939010b4959a50436393/href">https://medium.com/media/b8260134e060939010b4959a50436393/href</a></iframe><p>Scenario #2: Someone is using px for font-size in CSS.</p><p>Bad:</p><blockquote>Who the hell uses px for font-size? (The other person may not realise what’s wrong)</blockquote><p>Good:</p><blockquote>Please use rem instead of px (They understand “what to do”, but not “why to do”)</blockquote><p>Better:</p><blockquote>Do you thinking using rem instead of px here would be better? Here is an article that can help you decide: <a href="https://css-tricks.com/is-it-better-to-use-ems-rems-than-px-for-font-size/">https://css-tricks.com/is-it-better-to-use-ems-rems-than-px-for-font-size/</a> (Now they understand “what to do” and “why to do”, now let them decide)</blockquote><p>On a general note, our duty is to point out things, ask questions and let them think and come to conclusion. We as reviewers, should be always open to discussions, we should accept if the other person is making sense. We’re not fighting. We’re here to raise the bar of code quality and maintain it.</p><p>Code review is a vast topic in itself. Though, I wanted to write some basic things, which would help at least somebody out there. With that being said, please start reviewing others’ code. You’ll gain more confidence by actually doing more and more code reviews . Plus make sure to have a look at how others are reviewing code. Writing code yourself, reviewing others’ code and reading others’ code reviews will be really beneficial to you! This combined experience will help you write better code for yourself! Hope you enjoyed reading!</p><p>Some useful resources:</p><ul><li><a href="https://stackoverflow.blog/2019/09/30/how-to-make-good-code-reviews-better/"><strong>How to Make Good Code Reviews Better</strong></a><strong> — stackoverflow blog post</strong></li><li><a href="https://tsh.io/blog/code-review-best-practices/"><strong>Code review best practices. How to make people like your code review?</strong></a><strong> — </strong><a href="http://tsh.io/"><strong>tsh.io</strong></a></li><li><a href="https://github.com/ryanmcdermott/clean-code-javascript"><strong>Clean code JavaScript</strong></a><strong> — GitHub</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=238f661023ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code reviews: What and Why?]]></title>
            <link>https://swarajpure.medium.com/code-reviews-what-and-why-def9bf672d31?source=rss-9362f1accc65------2</link>
            <guid isPermaLink="false">https://medium.com/p/def9bf672d31</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[pull-request]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[code-review]]></category>
            <dc:creator><![CDATA[Swaraj Rajpure]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 06:32:00 GMT</pubDate>
            <atom:updated>2021-12-12T06:32:00.740Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0DFv3IBUdTAgcomfIOrEw.png" /></figure><p>Code reviews are the best! What is a code review? When you make some changes to a piece of code of a project (to introduce a new feature or to fix a bug or anything else) and wish to get that merged in the project, you create what is called a Pull Request and then the project maintainers will review your code before directly merging your changes. Why? Firstly, the security concern, to check if your code is (intentionally or unintentionally) leaking some sensitive information (like credentials/some other private data), or if your code has imperfect logic, missing some edge cases or if it has unnecessary code changes or if it can be improved in any way and so on. Don&#39;t worry if you are not able to relate, we&#39;ll see some examples and that&#39;ll help us get some clarity 🙂</p><h3>As a contributor to the project, why should you care about the code reviews?</h3><p>Well, nobody’s perfect and neither is the first version of our code 😛. We don’t wish to send some code with imperfect logic to be merged in the project we’re targeting, right? Even if the logic is correct, the code can be improved in many ways like improving the time complexity of some functions in some cases or improving the readability of the code (you’ll see this quite frequently in code reviews of beginner contributors) or making the code modular/decoupled. Code reviews teach us A LOT. There could be some easy way of doing something which we’ve complicated in our code, a code reviewer could point that out and we could get to learn about some new library or language API or algorithm altogether. This is “learning while building”.</p><p>There is always a limit to what we can learn in definite time. Code reviews help us leverage the experience of senior/experienced/even junior developers. Everyone comes with different experiences and there is something to learn from everyone out there. We’re <strong>writing the code with our experience</strong> and we’re <strong>improving the code with help of others’ experience</strong>, how awesome is that?! And again, this new experience gets added to our own experience as well 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*wC_kUARX1pVSaJKv.jpg" /></figure><p>At the same time, we have to understand that if someone is pointing out something to be improved in our code, that doesn’t mean we’re inferior to them or anything. We ourselves and the reviewers, we have the same goal in mind, making the project better and better. Improvising the code comes as a part of that. There’s nothing to be sad/ashamed about having changes requested on our code. In fact, we should take it as an opportunity to learn something new!</p><p>That was enough talk. Let’s take some code and try to understand what I meant by learning new things from code reviews. Let’s say there’s a use case that you have a string and you have to check if that string exists in an array of strings.</p><p>An obvious way would be to loop through the array and add equality checks, like so: (the following is a JavaScript snippet)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kvG6vEVDS81skZoif1CSQ.png" /></figure><p>Simple code, nothing fancy going on here. Even if you don’t know JavaScript, you can make sense of what’s happening here. Now, there is nothing logically wrong in the approach, but it can simplified in terms of efforts taken here. This is a standard problem which we (developers) face on regular basis and JavaScript has solved it for us, by providing us with the .includes() array method. If I was reviewing this code, I&#39;d have suggested you to read about this method and would have provided you the link to read about it (most probably MDN docs). For anyone new, this method returns us a boolean value if the array contains the field we are looking for 😉</p><p>Coming back to the code, the improved code would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WCe5QQS0VWdPuvus21XrQ.png" /></figure><p>Much simpler, easier to understand, in my opinion. It also saves the developers’ time, by not having to re-invent the wheel. We might have not known about .includes() method earlier, but now we do and this is one learning which is now going to stay with us forever. &quot;Today I learnt about a JavaScript method to check if an element exists in an array, which makes my life much simpler!&quot; 😄</p><p>This is just one example, probably an over-simplification, but we don’t wish to get stuck in some highly technical stuff right now, so let’s move ahead. I hope the point is understood 🙂</p><h3>Why should you care about code reviews as a reviewer?</h3><p>Code reviews help the reviewer more than the person whose code is being reviewed. Let me explain how. There’s a limit to the features you’ll get to work on but there’s no limit to the knowledge that’s out there. Most of the times, you’ll get to learn only about those things which you require in your own feature. How will you learn/come to know about the other things which you haven’t got exposure of? <em>CODE REVIEWS!</em> Other people might be working on something different which uses some APIs/methods/libraries/techniques which you have never come across and you’ll see those being used in their code and that’s one awesome way to learn about a ton of things in very short period of time! 💥</p><p>For example, if you had never seen an array method called .includes() in JavaScript and you see that in a pull request, you immediate understand &quot;hey, this is something new, let me google what it does&quot;. That right there, you&#39;ve learnt something new! Again, an over-simplification, but I hope you get the idea!</p><p>By the way, we’re not even discussing about wrong code here 😂 (in terms of incorrect logic, security concerns etc). I’m keeping aside the <strong>responsibility</strong> part of the reviewer and focusing on the <strong>learning</strong> part 🙂</p><p>Now that we understand why code reviews are important, even as a beginner, how do we start? What things should we look out for, when doing code reviews? What should be our tone while doing code reviews? We’ll see all of this in the next blog! Stay tuned! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def9bf672d31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[postMessage: communication between browser tabs]]></title>
            <link>https://swarajpure.medium.com/postmessage-communication-between-browser-tabs-85216a4b2046?source=rss-9362f1accc65------2</link>
            <guid isPermaLink="false">https://medium.com/p/85216a4b2046</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[postmessage]]></category>
            <category><![CDATA[browsers]]></category>
            <dc:creator><![CDATA[Swaraj Rajpure]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 04:23:25 GMT</pubDate>
            <atom:updated>2021-09-07T04:23:25.367Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how could one tab opens up another tab and they communicate with each other? Maybe you go to buy something on some site, now that site might open a new tab for processing your payment and if you try going back to the first tab/main site, you would see that the page has some sort of timer running. How does that page know that you have or have not completed the payment yet? That too which is taking place in other tab? How do these two tab communicate with each other? The answer is using postMessage browser API and message event listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_bXQSTA10S-_Exu4.jpg" /></figure><p>What’s happening here is that your main site is opening the payment page in a new tab mostly using window.open() method. How will the new tab refer to the main tab which opened it? You can refer that window using window.opener. As the name suggests, it simply points to the window object which caused this new tab to open. Main site would have started some sort of timer as soon as this new page is opened, saying something like Please complete the transaction in 5:00 minutes or so.</p><p>Your new tab obviously knows if you’re done with the payment or not. Now once you complete the payment on this tab, main site should know that. Here comes the interesting part of postMessage. This new tab will post a message to the window which opened it, using postMessage API, indicating that the payment is now complete. Okay, this tab has done its job, but how does the main site get to know this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/0*1FMbQte0yq_2Sbh_.jpg" /><figcaption>Listening for message 😛</figcaption></figure><p>There’s an event called message which this main site would be listening to (just like how we listen to click events). As soon as the main site receives the message which contains valid payload/data of the payment being completed, the UI would redirect you to maybe tracking details of that particular thing.</p><p>Enough of theory, right? Let’s get coding!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5j73lUguWJLWHVcz.jpg" /></figure><p>Here’s our index.html, nothing fancy going on here. Just one button and simple text. Do focus on the span though, we’re going to play with it 😉</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d99cf2ceea252f2efda7ca393e97c964/href">https://medium.com/media/d99cf2ceea252f2efda7ca393e97c964/href</a></iframe><p>This is what we see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*Gt713Xm8BGT_Lj5vNIIceQ.png" /></figure><p>Here’s the corresponding JavaScript code. Clicking on the button should disable it and a new tab should open with payment.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b92ed8f045b67707d4b88aa7bfc114b6/href">https://medium.com/media/b92ed8f045b67707d4b88aa7bfc114b6/href</a></iframe><p>Now we need to know how the payment.html looks like, right? Just one single button to replicate the behaviour as if the user has completed the payment (over-simplification 😬)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c69a1a050f0f1e99a793048bf28eac7/href">https://medium.com/media/1c69a1a050f0f1e99a793048bf28eac7/href</a></iframe><p>Here’s what this HTML renders:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*WICRuSsM8c1s_YUhECAgAQ.png" /></figure><p>Here’s the corresponding JavaScript code. On clicking the button, we’re sending a postMessage to the window.opener with the payload which confirms that the payment has completed. Finally we close this tab.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edf2d7868d04c9777d3d689366659c31/href">https://medium.com/media/edf2d7868d04c9777d3d689366659c31/href</a></iframe><p>But hey! How does our main page get to know that the payment has succeeded? We haven’t written any logic for it yet! Let’s add that to our index.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/247dbd045763f61cacaf9ef55fa6bd93/href">https://medium.com/media/247dbd045763f61cacaf9ef55fa6bd93/href</a></iframe><p>Now we have added an event listener for message event. Once the user clicks on the button on the other tab, we’re triggering a message, right? As soon as this tab receives a message, it opens up the e or event object and looks inside it for data.isPaymentCompleted. Once that’s done, we know the user has completed their payment and we modify the UI content. Remember we had talked about the span earlier? We’re now making it’s textContent to be true 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*FDbgdJhuhjp3Hlp0V0e4Bg.png" /></figure><p>Here is the hosted demo: <a href="https://swaraj-postmessage-demo.netlify.app/">https://swaraj-postmessage-demo.netlify.ap</a>p. Here’s the GitHub repo if you want to have a look: <a href="https://github.com/swarajpure/postMessage-demo">https://github.com/swarajpure/postMessage-demo</a></p><p>This might not have been a very good example, since we shouldn’t be dependent only on frontend for functionalities which are as delicate as payments, we should have checks from backend as well. Nonetheless, I guess you get the point I was trying to make and hope that you would have learnt something new 😄</p><p>Thank you! 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85216a4b2046" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing: What, why, how and when?]]></title>
            <link>https://swarajpure.medium.com/testing-what-why-how-and-when-fb2c9b5b335e?source=rss-9362f1accc65------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb2c9b5b335e</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Swaraj Rajpure]]></dc:creator>
            <pubDate>Thu, 15 Apr 2021 19:12:23 GMT</pubDate>
            <atom:updated>2021-04-15T19:13:33.928Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is testing?</h3><ul><li>Testing is a practice where we write code to check if (ideally) every single function/component/API/page is working as expected in different scenarios (user being/not being logged in etc).</li><li>Tests help us from manually testing every single thing by ourselves once we make some change somewhere in the codebase.</li><li>Tests also let us know if our current changes are breaking any existing features of the project, so we can code and push confidently as developers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*5JWBeG4w6J7MP-4d" /></figure><h3>Why testing?</h3><ul><li>Imagine for a certain task you needed all the details of a user. So you write an API which fetches the details of a particular user, performs something on it and returns <strong>all</strong> of the details. Those details may contain private information like email address, phone number etc. Any user could see any other user’s private information. That would be a <em>HUGE</em> privacy concern, right? Even if the result is unintended, the damage is real.</li><li>What could you do to save it? One option is to manually go and check every single API after your changes are done, to check if they’re working fine. It can become boring and tiresome as soon as the number of APIs go up. Also, humans are prone to errors. One may easily miss an important field being returned which was not supposed to be returned.</li><li>That’s why tests can be your saviors. They’ll do the testing part for you. They’ll save your time, energy, effort and of course, save your job 😛</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0Lns-KmErGWpIq851l_NA.png" /></figure><p>Though I have mentioned only about APIs and stuff, tests do exist for frontend as well. Now that we understand what is testing and why is testing necessary, let’s see what kind of tests we should write. I’m pretty sure you’d have seen those articles/videos where the only tests are to check if 2 + 2 is 4 😂. We won’t be doing that here though. We’ll be looking at <strong>logic</strong> of some real-life tests. We won’t be writing tests in this blog though.</p><h3><strong>Case 1:</strong></h3><p>Let’s take the above scenario itself. You would have an API for the user details, right? That API will get you the required data from the database. You have to make sure that the API is returning all the details which are necessary: first name, last name, their projects, pull requests, commits so on and so forth. At the same time, you have to make sure that the API is NOT returning any sensitive data at any time, like phone number and email address.</p><p>Now that you know the expected behavior of the API, we should move to writing tests. So what should the API tests look like?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r7XKQmfjrjZDVxauWWbYdA.png" /><figcaption>Test ideas for an API</figcaption></figure><h3>Case 2:</h3><p>Let’s assume you’re working in LinkedIn. You see an edit profile button when you go to your profile, right? What happens when you go to someone else’s profile page? You shouldn’t see the button. Let’s see what could be the logic for some of the tests:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BO3GVPgp8HYOg9_HDACOJw.png" /><figcaption>Test ideas for LinkedIn profile page</figcaption></figure><p>I hope now you’re getting what we mean by tests, but hey! When/where do these tests run? Good question! 😆 Once you work on a feature, you commit your changes, you create a pull request, let’s say on GitHub. On GitHub, in the repository you’re making the pull request, they’d have set up <strong>Continuous Integration </strong>pipeline. This pipeline/setup will run all the tests in that project on your pull request, that is, on your changes. So you’ll get to know what things you’re breaking (if any) with your current implementation, <strong>before</strong> it is actually merged into the repository! 🎉</p><p>This is one example of the one set of the tests being passed on one of the pull requests Real Dev Squad’s <a href="https://github.com/Real-Dev-Squad/website-backend"><strong>website-backend</strong></a> project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7BGPu1O30HLoN1mZvfsaXA.png" /><figcaption>Tests being run on CI on GitHub on a pull request</figcaption></figure><p>In this way well written tests are there to save us from breaking expected functionality/design of our projects 😉</p><p>This was just a high level overview of tests, what they are, why are they required, what kind of tests do we write, where do they actually test our code. In the next blog, we’ll actually write some tests — coding time! Again, we won’t be writing tests to check if 2 + 2 equals 4 😛 We’d actually write some meaningful tests which you can incorporate in your projects/job 😊</p><p>I hope this article helped you in some way. Nonetheless, have a great day! 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb2c9b5b335e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GitHub APIs: Fetching Pull Requests/Issues by a User/Organisation/Repository]]></title>
            <link>https://swarajpure.medium.com/github-apis-fetching-pull-requests-issues-by-a-user-organisation-repository-84ae934a106b?source=rss-9362f1accc65------2</link>
            <guid isPermaLink="false">https://medium.com/p/84ae934a106b</guid>
            <dc:creator><![CDATA[Swaraj Rajpure]]></dc:creator>
            <pubDate>Wed, 20 Jan 2021 18:32:18 GMT</pubDate>
            <atom:updated>2021-01-21T02:37:42.696Z</atom:updated>
            <content:encoded><![CDATA[<h3>GitHub APIs: How To Fetch Pull Requests/Issues by an User/Organization/Repository</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*JIjtCbGln0-kcBmY.jpg" /></figure><p>Last year (not so long ago 😛), I was working on a feature for Real Dev Squad where I needed to show the contributions of each member of the organization in form of pull requests. I had gone through the Github API documentation but I didn’t find it of much use to my particular usecase. I had then thought of scraping the webpage <a href="https://github.com/pulls">https://github.com/pulls</a> for this purpose which had to be rejected immediately as it would not have been that efficient over long time. Digging deeper into the Github APIs, I finally figured out how to make use of the Github APIs for my task. Github APIs are like Lego blocks. Different queries can be combined in various ways to make it suitable for the requirement. What can be different scenarios?</p><ul><li><strong>Listing PRs of a user:</strong> all of them/for an org/for a particular repo/open/closed</li><li><strong>Listing issues of a user:</strong> all of them/for an org/for a particular repo/assigned/unassigned/open/closed</li><li><strong>Listing total PRs: </strong>by an org/a particular repo/open/closed</li><li><strong>Listing total issues</strong> by an org/a particular repo/assigned/unassigned/open/closed</li></ul><p>There can be many more combinations. You get the idea, right?</p><p>Let us dissect what this piece of URL does:</p><blockquote><a href="https://api.github.com/search/issues?q=author:swarajpure+org:Real-Dev-Squad+type:pr&amp;sort=asc"><em>https://api.github.com/search/issues?q=author:swarajpure+org:Real-Dev-Squad+type:pr&amp;sort=asc</em></a></blockquote><p>Here the https://api.github.com is the base URL. /search and /issues are called the <strong>path parameters</strong> (aka params). Yes, you guessed it right, they&#39;re used in your computer&#39;s file explorer to locate files or folders. Path parameter can be easily distinguished by the slash /. Now you might be wondering what is a ? doing in the URL? What follows the question mark is called <strong>query parameter</strong>. The question mark is used to separate the path params from the query params. While path params are used to locate resource in a pool of data, query params are used to filter inside that particular resource.</p><p>Here we can see mainly 2 query params q and sort. What follows these parameters are their values which are given after the = sign. The q parameter contains the data to be filtered and sort sorts the data, here in ascending order (asc). The &amp; sign combines the two query params. Now you must be wondering about the + signs, right? They can be thought of as if they&#39;re combining multiple nested params. Remember, using &amp; instead of + would terminate the q param.</p><p>In a broad sense, this URL tells the server that we are searching something from the search path param. Next, are looking for issues (PRs are also a part of issues path param, not my fault. It&#39;s provided by Github itself 🤣) Next, we encounter a ? which means we are going to have query params now. The query param q is telling that we need data from the author swarajpure in the org whose name is Real-Dev-Squad and whose type is pr (pull request). Finally we encounter a &amp; sign, which specifies that earlier query param has terminated and new query param is to be added which is sort whose value is asc that is ascending.</p><p>Essentially, the above API endpoint would give us all the PRs by a user called swarajpure in the organization Real-Dev-Squad in the ascending order!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl3q2Ph0I1osaagoQE%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fl3q2Ph0I1osaagoQE&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fl3q2Ph0I1osaagoQE%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="245" frameborder="0" scrolling="no"><a href="https://medium.com/media/2abdae4cd898eaabd4ff1d385fc1e5d0/href">https://medium.com/media/2abdae4cd898eaabd4ff1d385fc1e5d0/href</a></iframe><p>Don’t worry if you’re overwhelmed! This is easy! Just bear with me for a little more and we’ll see more examples and then things will be more clear 😄</p><p>Now let’s see how can we get total pull requests by a user (not particularly in any repo) — just removed the param org</p><blockquote><a href="https://api.github.com/search/issues?q=author:swarajpure+type:pr&amp;sort=asc">https://api.github.com/search/issues?q=author:swarajpure+type:pr&amp;sort=asc</a></blockquote><p>How about getting all the issues started by a user in an org?</p><blockquote><a href="https://api.github.com/search/issues?q=author:swarajpure+org:Real-Dev-Squad+type:issue&amp;sort=asc">https://api.github.com/search/issues?q=author:swarajpure+org:Real-Dev-Squad+type:issue&amp;sort=asc</a></blockquote><p>We haven’t talked about a repo yet, right? Let’s see how to get open issues by a user in a repo:</p><blockquote><a href="https://api.github.com/search/issues?q=author:swarajpure+repo:Real-Dev-Squad/website-backend+type:issue+state:open&amp;sort=asc">https://api.github.com/search/issues?q=author:swarajpure+repo:Real-Dev-Squad/website-backend+type:issue+state:open&amp;sort=asc</a></blockquote><p>Enough of stuff by a user! Let’s see how can we get total PRs in an org:</p><blockquote><a href="https://api.github.com/search/issues?q=org:Real-Dev-Squad+type:pr&amp;sort=asc">https://api.github.com/search/issues?q=org:Real-Dev-Squad+type:pr&amp;sort=asc</a></blockquote><p>Let’s see how to get all the PRs in a repo (note that this is having different path params!):</p><blockquote><a href="https://api.github.com/repos/Real-Dev-Squad/website-backend/issues">https://api.github.com/repos/Real-Dev-Squad/website-backend/issues</a></blockquote><p>I guess you must have got enough idea by now. Feel free to explore the Github API docs here: <a href="https://docs.github.com/en/rest">https://docs.github.com/en/rest</a></p><p>I hope this blog somehow helps you! Thank you! 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84ae934a106b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>