<?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 Pulkit Goel on Medium]]></title>
        <description><![CDATA[Stories by Pulkit Goel on Medium]]></description>
        <link>https://medium.com/@pulkitgoel?source=rss-1e89855c8ff0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*uiJSd8gBJMdj-XjOYU5cxg.jpeg</url>
            <title>Stories by Pulkit Goel on Medium</title>
            <link>https://medium.com/@pulkitgoel?source=rss-1e89855c8ff0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:09:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pulkitgoel/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[Getting device type in Next JS]]></title>
            <link>https://pulkitgoel.medium.com/getting-device-type-in-next-js-e8c3534ca421?source=rss-1e89855c8ff0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8c3534ca421</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Pulkit Goel]]></dc:creator>
            <pubDate>Sat, 23 Nov 2019 19:59:23 GMT</pubDate>
            <atom:updated>2021-09-19T02:17:42.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*2heZDpfmYZQF7Aqu.png" /></figure><p>Want to know if the incoming requests to your app are from a mobile device or a desktop? Stuck with not being able to find anything useful on the web that suit your needs? Not any longer. I have been at the same side of the cliff as you are right now. So, let’s get started.</p><blockquote><strong>TL; DR</strong></blockquote><blockquote>I have explained how to use the context object in getInitialProps, to get the device type from the incoming request and hence store it in Redux for future use.</blockquote><h3>Introduction</h3><p>If you have been developing web application in React JS you know one thing for sure, SPA frameworks like React and Vue suck when it comes to good SEO or any SEO for that matter. But the ease of developing and maintaining code using a framework makes you want to ignore that issue. Recently I found myself at an intersection of using custom SSR for React from scratch or on the other hand using Next JS. A SSR based framework based on React. But after a lot of brainstorming and finally a leap of faith in the Next JS community we decided to use Next JS for our project.</p><p>Now the problem for which you are here, So I was developing a UI component which required some sort of custom algorithm and to make it responsive to different device sizes the algorithm needed the current device type as an input. So, I used the <strong>navigator</strong> object or <strong>window.innerHeight</strong> etc. But that gave errors, such as, <strong><em>“window is undefined”.</em></strong></p><blockquote>Now the issue here is quite simple, Next JS runs on the server side and obviously I can’t have access to the browser window on the server.</blockquote><h3>getInitialProps()</h3><p>After a whole lot of research, I found different questions on GitHub about the same topic. And one of them talked about this one.</p><p>So, what getInitialProps() lifecycle hook does is, it runs on both the server and the client side and also it runs before the component gets any props. Also, getInitialProps() receives as its argument, an object named <strong>context.</strong></p><p>Context provides us with all the details about the incoming request, such as, request headers, user-agent etc. Now you can learn more about that <a href="https://nextjs.org/learn/basics/fetching-data-for-pages">here</a>.</p><p>So, here’s how I used it to get the current device type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7918cb600f0e479e80157d9e80abaa50/href">https://medium.com/media/7918cb600f0e479e80157d9e80abaa50/href</a></iframe><p>I think the above code is self-explanatory, but let’s get the summary out the way anyway 😜. So here I am checking first if the context object has a request object. If it has that means we still are on the server right now, so I collect the request’s <strong><em>‘user-agent’</em></strong> type. In the else case of the ternary operator, we check for client-side re-renders, and hence use the <strong><em>navigator </em></strong>object to get user-agent. Now after that a simple Regex can check if the user-agent is a mobile type device or a desktop.</p><p>Then comes the most important part, to send this info to the component you are using the above code snippet in. To do that you will have to return the isMobileView property as above, so that the component now has access to this property as a part of the props object, as follows:</p><pre>class Time extends React.Component {<br>  constructor(props) {<br>    super(props)<br>    console.log(this.props.isMobileView)<br>  }<br>}</pre><p><strong><em>Note: I would suggest using Redux to store it, and hence not having to use getInitialProps in every other component.</em></strong></p><p>I hope this helps, please feel free to share any feedback you have. Until next time, keep learning!</p><p>Have a good one 👼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8c3534ca421" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Importing a SQL database to Hadoop HDFS using Sqoop.]]></title>
            <link>https://pulkitgoel.medium.com/importing-a-sql-database-to-hadoop-hdfs-using-sqoop-9309b748ccb1?source=rss-1e89855c8ff0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9309b748ccb1</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sqoop]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[virtualbox]]></category>
            <dc:creator><![CDATA[Pulkit Goel]]></dc:creator>
            <pubDate>Tue, 20 Nov 2018 04:28:44 GMT</pubDate>
            <atom:updated>2021-09-19T02:27:58.219Z</atom:updated>
            <content:encoded><![CDATA[<h3>Importing SQL database to Hadoop HDFS using Python Script.</h3><figure><img alt="Hadoop logo" src="https://cdn-images-1.medium.com/max/640/0*1CkytriTdnbuwpO6.png" /></figure><p>Let’s first see what I will be covering in this tutorial (and what not…).</p><h3><strong>Outline</strong></h3><ol><li>we will begin by installing <strong>Virtual Box</strong>.</li><li>Then, a <strong>Cloudera</strong> Virtual Machine.</li><li>And, then finally importing data from <strong>MySQL</strong> to <strong>Hadoop’s</strong> <strong>HDFS </strong>using <strong>Sqoop framework</strong>.</li></ol><h3>So, what we want to do…</h3><p>Basically, we will be copying the data from an already existing database in MySQL and then properly add it to the <strong>H</strong>adoop’s <strong>D</strong>istributed <strong>F</strong>ile System (<strong>HDFS</strong>), using a tool/framework known as Sqoop.</p><p>Let’s get started…</p><h3>Installing VirtualBox and Cloudera.</h3><p>First you will need to download the latest version of the version of virtual box from <a href="https://www.virtualbox.org/wiki/Downloads"><strong><em>virtualbox.org</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjeGx9FFRpn_t8OwVsK89Q.png" /><figcaption>VirtualBox download page</figcaption></figure><p>After that let’s also download the <strong>Cloudera </strong>QuickStart VM for VirtualBox from this <a href="https://www.cloudera.com/downloads/quickstart_vms/5-13.html"><strong><em>link</em></strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4whj-8v0x9GjyEwusQEJA.png" /><figcaption>Cloudera download page</figcaption></figure><p><strong>Note</strong>: The Cloudera VM comes in a 7zip format, so if don’t have a proper extracting tool I would recommend the <a href="https://www.7-zip.org/"><strong><em>7-zip</em></strong></a> for windows. And for Mac, you can use the <a href="https://theunarchiver.com/"><strong><em>unarchiver tool</em></strong></a>.</p><p>Now that we have downloaded and extracted both the files, let’s get into the installation part. Installing VirtualBox is really easy, just click on continue until you install the software.</p><p>After installing VirtualBox, next thing is to install a VM on it. More specifically, the Clourera VM.</p><ol><li>Click on <strong>New</strong>, on the top left corner. Enter the details in the input boxes similar to the ones in the image below.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Ev0ZCKavf3xKMpZcvbIzA.png" /></figure><p>2. Assign hardware to your newly created virtual machine. 4 GB is at least recommended for a VM to work properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*00nbeMNtN7CVLxVQy8C4Lw.png" /></figure><p>3. Now browse to the cloudera quickstart file that we downloaded earlier and click on create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISxMTH4BZZR8VNlvAq4LGw.png" /></figure><p>4. Similar to RAM, you have to assign CPU cores to your vm. By right clicking on the vm and clicking <strong>Settings</strong>-&gt;<strong>System-&gt;Processor.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*OdWlcOTZMD5qfD1J05stEw.png" /></figure><p>5. Start your VM, by clicking on the start button on the top of the window.</p><p>Now, after the vm starts up (which will take a while!), you will be greeted with a firefox browser window with a tab asking you to sign in to the Hue (a user interface for Hadoop). Both email and password are ‘<strong>cloudera</strong>’.</p><p>After signing in, just keep clicking your way to next until you see the home page. Now close the browser window.</p><h3>Adding data to MySQL</h3><p>From here on you just have to follow the commands marked below with a orange rectangle, in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*tZIQ8IOG2C_W5QQuj03Ahg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*OUygpeG_Cv8vjLzKoK1ffw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*idFlpym89TxILJGwwcT5_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*iP4Hndn2jBTAiIGkk5T8Kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*sWonUD-i_PFJVlBWTlMNqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*ZeJKv8tRzoPzf3Lgf2B3LQ.png" /></figure><h3>The Sqoop script</h3><p>Now that you have setup your database in the MySQL, let’s add the following code in a python file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*bCF5VU_acPYN6B7OHq0Wvg.png" /><figcaption>This is the command for importing the data from mysql to hadoop using sqoop.</figcaption></figure><h3>Importing the Data into Hadoop</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uafl2D4Q6OfhCfXPwAH0qg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*SfRBmJWqnhxzbAiVU3U_Lw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*2M3kOEOy0cknMElJuysR3g.png" /></figure><p>This final command will show the data you have just imported.</p><p>Happy Hadooping 🐘…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9309b748ccb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using custom _id(s) in MongoDB in a ExpressJS and NodeJS app.]]></title>
            <link>https://pulkitgoel.medium.com/using-custom-id-s-in-mongodb-in-a-expressjs-and-nodejs-app-4210169680b3?source=rss-1e89855c8ff0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4210169680b3</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Pulkit Goel]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 12:34:23 GMT</pubDate>
            <atom:updated>2021-09-19T02:31:07.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*gyLlvNdA_SQGBZSB.png" /></figure><p>I Recently started working with the NodeJS platform, and as everyone I also got stuck with this problem. I am going keep it really simple, below is an example of how you can do this the classy way, and after that is a small application.</p><p>P.S. I am not using Mongoose, That’s for another time… 🐶</p><h3>Code</h3><pre>var express = require(&quot;express&quot;)</pre><pre>var mongodb = require(&quot;mongodb&quot;)</pre><pre>var MongoClient = require(&quot;mongodb&quot;).MongoClient</pre><pre>var app = express()</pre><pre>var url = &quot;mongodb://localhost:27017/&quot;</pre><pre>app.get(&#39;/user/:name/:email&#39;, (req, res) =&gt; {</pre><pre>MongoClient.connect(url, function (err, db) {</pre><pre>var user = {}</pre><pre>if (err) {</pre><pre>throw err</pre><pre>} else {</pre><pre>var dbo = db.db(&quot;testdb&quot;)</pre><pre>dbo.collection(&quot;users&quot;).count().then((total_users) =&gt; {</pre><pre>user = {</pre><pre>_id: (total_users + 1),</pre><pre>name: req.params.name,</pre><pre>email: req.params.email</pre><pre>}</pre><pre>dbo.collection(&quot;users&quot;).insertOne(user, (err, res) =&gt; {</pre><pre>if (!err) {</pre><pre>console.log(&quot;Data Inserted Successfully&quot;)</pre><pre>db.close()</pre><pre>} else {</pre><pre>throw err</pre><pre>}</pre><pre>})</pre><pre>res.status(200).send(&quot;&quot; + user._id)</pre><pre>})</pre><pre>}</pre><pre>})</pre><pre>})</pre><pre>app.listen(3000, () =&gt; {</pre><pre>console.log(&quot;Server is running on port: &quot; + 3000)</pre><pre>})</pre><h3>Explanation</h3><ul><li>See how the database name is plural, and the singular for the object we are inserting into the db.</li><li>The count() function is an async one, hence the insertOne() must be called after its execution(as we require the current number of users in the database). P.S. there are numerous ways to do this, I am a beginner and found this the easiest feel, free to share more exciting ones.</li><li>Here we are getting the name and the email for a user as parameters from the url itself. And then storing it in a temporary user object. which is then passed to the database.</li><li>After the record is created, a response is sent back to the client with the id of the newly created user.</li><li>That’s all folks…</li><li>go ahead, give it a try…</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4210169680b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>