<?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 Nitin Patel on Medium]]></title>
        <description><![CDATA[Stories by Nitin Patel on Medium]]></description>
        <link>https://medium.com/@nitinpatel_20236?source=rss-fae9d84f67cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6rWWd5Gi1W7eebzE0t6PJA.png</url>
            <title>Stories by Nitin Patel on Medium</title>
            <link>https://medium.com/@nitinpatel_20236?source=rss-fae9d84f67cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 16:55:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nitinpatel_20236/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[Advanced Search Tips Every Programmer Should Know]]></title>
            <link>https://medium.com/@nitinpatel_20236/advanced-search-tips-every-programmer-should-know-20fa11831836?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/20fa11831836</guid>
            <category><![CDATA[search-operators]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[search-engines]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 09:51:56 GMT</pubDate>
            <atom:updated>2019-07-20T09:58:22.388Z</atom:updated>
            <content:encoded><![CDATA[<p>As software engineers, we spend a lot of time searching for things on the internet. Therefore, it makes sense to spend time learning some little known search engine tricks that will boost your search productivity.</p><p>I will mainly tell you what works on Google Search because that is what I know best. But, most of these will probably work for other search engines too!</p><p>The usefulness of these is not limited to search engines though. I use a lot of these operators in searching through logs, in services like <a href="https://logdna.com/">logdna</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*AkQj7T52Cnh_Kbff.jpg" /><figcaption>google: a programmer&#39;s best friend!</figcaption></figure><p>Let’s start.</p><h3>Basic Search Operators</h3><h4>AND, OR, NOT (represented by a minus sign)</h4><p>These are pretty simple, you can use these to include or exclude certain words from search results. Example:</p><p><a href="https://www.google.com/search?q=dell+AND+apple"><strong>dell AND apple</strong></a><strong> </strong>(results that include both words)</p><p><a href="https://www.google.com/search?q=dell+OR+apple"><strong>dell OR apple</strong></a><strong> </strong>(results that include either of words)</p><p><a href="https://www.google.com/search?q=dell+-apple"><strong>dell -apple</strong></a><strong> </strong>(results that include dell but not apple)</p><p>Note: In regular searches, google defaults to <strong>AND </strong>anyway, so it doesn’t matter make much difference. But it can be quite useful when combined with other operators.</p><h4>WildCards and Exact Match</h4><p>Wildcards and exact match search serve very different purposes. Exact match search is when you tell the search engine to show results that contain the exact phrase.</p><p>This is done by including the phrase in <strong>double-quotes</strong>.</p><p>Wildcards simply mean, match any word or phrase. Quite useful if you forgot part of the word or phrase you wanted to search. There are represented by an <strong>asterisk.</strong></p><p>Aside: I also find these pretty useful for searching memes 😛 As you’ll see in the examples.</p><p>Example:</p><p><a href="https://www.google.com/search?q=&quot;we%27re+hitting&quot;+&quot;levels+never+thought+possible&quot;"><strong>“we’re hitting” “levels never thought possible”</strong></a></p><p><a href="https://www.google.com/search?q=we%27re+hitting+*+levels+never+thought+possible"><strong>we’re hitting * levels never thought possible</strong></a></p><p>Knowing these little tricks and having the ability to combine them is quite powerful. But there is more! Keep reading to know some of the advanced google search tips I use quite often at work.</p><h3>Advanced Search Operators</h3><p>These are pretty simple yet powerful search operators. Using them will make you feel like a search engine God. Let’s see some examples.</p><h4>site:</h4><p>Limit the search results to a particular site. Example:</p><p><a href="https://www.google.com/search?q=site%3Astackoverflow.com+regex+javascript"><strong>site:stackoverflow.com regex javascript</strong></a></p><h4>inurl:</h4><p>Include results whose URL contain the word or phrase. I find this extremely helpful when I want to look for something in an online documentation site that’s hard to navigate. Example:</p><p><a href="https://www.google.com/search?q=inurl%3Adeveloper.linkedin.com+&quot;pagination&quot;"><strong>inurl:developer.linkedin.com “pagination”</strong></a></p><p>You can also sneak wildcards in there:</p><p><a href="https://www.google.com/search?q=site%3A*.facebook.com+&quot;access+tokens&quot;+&quot;api&quot;"><strong>site:*.facebook.com “access tokens” “api”</strong></a></p><p><a href="https://www.google.com/search?q=inurl%3Aadmin-sdk+site%3A*.google.com+%22reseller+api%22"><strong>inurl:admin-sdk site:*.google.com “reseller api”</strong></a></p><h4>filetype:</h4><p>This operator lets you search on filetypes. Example:</p><p><a href="https://www.google.com/search?q=filetype%3Apdf+&quot;machine+learning&quot;"><strong>filetype:pdf “machine learning”</strong></a></p><p><a href="https://www.google.com/search?q=filetype%3Adocx+&quot;metaprogramming&quot;"><strong>filetype:docx “metaprogramming”</strong></a></p><h3>Closing Thoughts</h3><p>There are a lot more search operators, but these are the ones I most frequently use. If you know any other search operators that you frequently use, please comment below because I’d love to know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20fa11831836" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What does the phrase Monadic Bind mean?]]></title>
            <link>https://medium.com/@nitinpatel_20236/what-does-the-phrase-monadic-bind-mean-a2184f34b2e3?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2184f34b2e3</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[monads]]></category>
            <category><![CDATA[monadic-programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Fri, 07 Jun 2019 09:02:51 GMT</pubDate>
            <atom:updated>2019-06-07T09:23:16.537Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been learning Haskell for a few months now and I think I have a good understanding of what monads are. I’m not an expert so I should warn you this answer <em>might </em>be completely wrong.</p><p><a href="https://www.quora.com/In-Haskell-what-does-the-phrase-monadic-bind-mean/answer/Nitin-Patel-46">I originally posted this as a Quora answer. Reposting it here:</a></p><p><strong>Monadic bind</strong> is the name given to the (&gt;&gt;=) function or bind function, also known as chain, flatMap, or joinMap.</p><p>I personally like to call it the “then” function borrowing the word from JavaScript Promises. It is much more intuitive that way if you read it as “then” instead of “bind”.</p><p>Consider the following Haskell program which takes a number from stdin and prints its square root in stdout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5892d4aca63bdae4ea8777737e574e1/href">https://medium.com/media/c5892d4aca63bdae4ea8777737e574e1/href</a></iframe><p>If you read the (&gt;&gt;=) as <em>then</em>. The program basically read as:</p><p><strong>main = getLine <em>then</em> stringToNumber <em>then</em> squareRoot <em>then </em>print.</strong></p><p>If you have programmed in JavaScript and you’re familiar with Promises, you will find this approach quite intuitive.</p><p>In Practice, most people use the “Do Notation” which is just syntactic sugar over the monadic bind syntax. Once, you understand this, do notation should be quite easy.</p><p>For reference, here’s the same program converted to “Do notation”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99395392af86f1ec7e880cfdf80bc589/href">https://medium.com/media/99395392af86f1ec7e880cfdf80bc589/href</a></iframe><h3><strong>But what does (&gt;&gt;=) function actually do?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*WXYsA_WrYTAaQMRH" /><figcaption>It’s just a monoid in the category of endofunctors. What’s the problem?</figcaption></figure><p>To know what this function actually does, we first need to know what a monad is. The definition of monad can be found on <a href="https://en.wikipedia.org/wiki/Monad_(functional_programming)">Wikipedia Page on Monads</a>:</p><blockquote><em>a </em><strong><em>monad</em></strong><em> is a </em><a href="https://en.wikipedia.org/wiki/Design_pattern"><em>design pattern</em></a><em> that allows structuring programs </em><a href="https://en.wikipedia.org/wiki/Generic_programming"><em>generically</em></a><em> while automating away </em><a href="https://en.wikipedia.org/wiki/Boilerplate_code"><em>boilerplate code</em></a><em> needed by the program logic.</em></blockquote><p>Right now, this sentence doesn’t make sense, hopefully, it will make some sense after I give a few examples.</p><p><strong>Example 1: Handling Null values (Maybe type).</strong></p><p>I’ll use JavaScript syntax for convenience.</p><p>Let’s say we have a value which may or may not exist (nullable), we want to perform some computations on the value. These computations could also fail and return null values. Our code will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80a17d3fbe2449732a96e56e2cdef138/href">https://medium.com/media/80a17d3fbe2449732a96e56e2cdef138/href</a></iframe><p>This code violates the <a href="https://en.wikipedia.org/wiki/Don&#39;t_repeat_yourself">DRY Principle</a> and is quite ugly because of all the nesting. Let’s try to abstract out the repetitive code.</p><p>We can design a maybe data type which holds either some value or Null. And we can define a function that does null checking for you.</p><p>Now, instead of our functions returning null, it will return this Maybe data type. Here’s an example implementation with some functions returning Maybe type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42547dbaeb7df6dc574098a07f9f6a8e/href">https://medium.com/media/42547dbaeb7df6dc574098a07f9f6a8e/href</a></iframe><p>Then we can write our program into a flat pipeline instead of the nested hell we had earlier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3b9c16eb4db3b12b475ae00a8d15bbb/href">https://medium.com/media/e3b9c16eb4db3b12b475ae00a8d15bbb/href</a></iframe><p>If at any point the function returns Null, all other computations will be skipped. (Like if we divide by zero or square root a negative number).</p><p>Now, look again at the definition of the monad I gave above, and see if it makes a little bit more sense now:</p><blockquote><em>a </em><strong><em>monad </em></strong><em>is a </em><a href="https://en.wikipedia.org/wiki/Design_pattern"><em>design pattern</em></a><em> that allows structuring programs </em><a href="https://en.wikipedia.org/wiki/Generic_programming"><em>generically</em></a><em> while automating away </em><a href="https://en.wikipedia.org/wiki/Boilerplate_code"><em>boilerplate code</em></a><em> needed by the program logic.</em></blockquote><p><strong>Example 2:</strong> <strong>Handling Async Values (Promises)</strong></p><p>Let’s say that instead of returning Null values, our functions returned <em>Async </em>values, meaning that values that don’t exist yet but will be available in future. (For example, it’s an API request or Database call).</p><p>Here, instead of checking for null values, we need to <em>wait </em>for the value of the previous result to be available because we execute any function.</p><p>JavaScript had a solution to this called <strong>The</strong> <strong>Callback Pattern. </strong>Callback pattern solved this problem but it resulted in the same kind of nested callback hell we saw earlier. <a href="http://callbackhell.com/">more about callbacks</a>.</p><p>This is why the popular approach to handling async values in JavaScript is to use Promises.</p><p>We have seen that the <em>then</em> function in Maybe type performs an “if check” for us between every function execution. The <em>then </em>function in Promises waits for the previous result and executes the given function when it is available.*</p><p>This allows us to convert a nested callback code into a flat pipeline of functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5738871224c861e9435b07608a218416/href">https://medium.com/media/5738871224c861e9435b07608a218416/href</a></iframe><p>Hopefully, you can see a pattern here and somewhat grasp the abstract concept of monads.</p><p><strong>But what about the IO Monad in Haskell?</strong></p><p>The IO Monad works on the same principle. As we have seen before, monadic bind performs some intermediate computation in between functions, removing the need for us to write boilerplate code.</p><p>In this case, the boilerplate code would be pulling out the value obtained by performing side effect and passing it to the next function in our chain of functions.</p><p>They’re also quite similar to promises meaning that they guarantee the order of execution by creating a dependency on previous value for the function to execute. Example,</p><pre>main = function1 &gt;&gt;= function2 &gt;&gt;= function3</pre><p>Here, function1 <em>depends </em>on the value returned by function2. It cannot run until function1 is finished. Similarly, function3<strong> </strong>cannot run until function2 has finished.</p><p>If you want to actually see what bind function in IO monad does, watch this video. It is the best explanation I’ve found for IO monad.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfCoQb-zqYDI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfCoQb-zqYDI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfCoQb-zqYDI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5144fa4af7cbb32b9eb09b50310d5799/href">https://medium.com/media/5144fa4af7cbb32b9eb09b50310d5799/href</a></iframe><blockquote><em>* sidenote: </em><a href="https://buzzdecafe.github.io/2018/04/10/no-promises-are-not-monads"><em>Promise is not actually monad</em></a><em>, </em><strong><em>but</em></strong><em> it’s pretty close and solves the same problem that monads solve. My purpose here is to build intuition and not be 100% accurate.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2184f34b2e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Contribute to Open Source (If you’ve never done it before)]]></title>
            <link>https://medium.com/@nitinpatel_20236/how-to-contribute-to-open-source-if-youve-never-done-it-before-b15fe3b8823d?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b15fe3b8823d</guid>
            <category><![CDATA[open-source-contribution]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Wed, 08 May 2019 03:50:34 GMT</pubDate>
            <atom:updated>2019-05-08T03:50:34.136Z</atom:updated>
            <content:encoded><![CDATA[<p>Contributing to big open source projects can be intimidating if you have never contributed before, even for experienced developers.</p><p>I know this because I’ve been there. The good news is, it gets easier with time.</p><p>I’ve contributed to the open source project <a href="http://ipfs.io/">IPFS</a> which is a distributed file system created by Protocol Labs, the company behind filecoin.</p><p>Based on my experience, here’s some advice on contributing to open source projects as a beginner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YsLjevPWOJ3_I76o.jpg" /></figure><p><strong>Choosing a project</strong></p><p>Contributing to open source project requires a reasonable understanding of the thing you’re working on it. So, I’d recommend you to just pick one project that you want to work.</p><p>Here are some criteria when picking an open source project:</p><ul><li>Pick something you’re <strong>passionate</strong> <strong>about</strong>.</li><li>Look for projects <strong>where</strong> <strong>your</strong> <strong>skill sets apply</strong>. Obviously, no project will perfectly match your skills, and that is okay because you can always learn new skills. But you should look for as much overlap as possible.</li><li>Look at the <strong>issues list</strong> on GitHub and see how well organized it is. Are the maintainers active there? Are they friendly and willing to help out new contributors?</li></ul><p><strong>Understand the Project</strong></p><p>Spend the first few days into just understanding the project. Read about the history and motivation behind the project, then read its documentation cover to cover and then try to understand the code base and how it is structured.</p><p>When you have a big picture understanding of the project, you are better equipped to contribute to it.</p><p>At the same time, it is important to remember that <strong>you don’t need to know everything. </strong>Too many people get intimidated by the size of the code base. You don’t need an in-depth understanding of each and every component.</p><p>Just try to know the big picture initially and how different components connect with each other.</p><p><strong>Start Small</strong></p><p><strong>No contribution is too small</strong>. See a typo somewhere or a broken link? Make a Pull Request!</p><p>In fact, documentation PRs are the best way to add value initially. Finding bugs and raising issues is another good way. This way, you get to know about the projects and get a feel for working on it.</p><p>Once you start to feel comfortable, you can take on tasks of increasing difficulty.</p><p>To know what to work on, see the issues reported by other people. Issues labelled as “good first issue” can be a great starting point!</p><p><strong>Communicate with the maintainers and other team members</strong></p><p>See if there is a chatroom you can get into where you can just chat with other contributors. Also, talk to maintainers and have a good relation with them. They can give you a direction and suggest problems to work on.</p><p><strong>Have Fun!</strong></p><p>Once you get past the initial hurdles, open source contributions can be a tremendous learning experience and fun to work on. Keep taking on problems and adding value.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b15fe3b8823d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Shuffle Correctly Shuffle An Array in JavaScript]]></title>
            <link>https://medium.com/@nitinpatel_20236/how-to-shuffle-correctly-shuffle-an-array-in-javascript-15ea3f84bfb?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/15ea3f84bfb</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 23:14:27 GMT</pubDate>
            <atom:updated>2019-09-06T05:27:09.424Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Correctly Shuffle An Array in JavaScript</h3><p>About 9 years ago, TechCrunch published <a href="https://techcrunch.com/2010/02/22/microsoft-ballot-screen">this story</a>. Microsoft had this browser ballot screen on browserchoice.eu where Microsoft was supposed to show all the different browser choices to users in random order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*3S-eMoM2szvQN-muHpTFNg.png" /><figcaption>“randomly” sorted</figcaption></figure><p>Except, it was far from random. Internet Explorer showed up in the last position about 50% of the time and Chrome was most likely to show up in the top 3. What gives? Well, here’s the code they used for doing the random shuffle:</p><pre>array.sort(function (a, b) { return 0.5 — Math.random() })</pre><p>At first glance, this seems like a reasonable solution. In fact, if you google search “random shuffle javascript” this code is the top result that pops up. <br>The code uses javascript’s sort function with a custom comparator. This comparator a number between 0.5 and -0.5.</p><p>One of the problems with this sorting algorithm, however, is that <strong>it does not work</strong>. If you want a random shuffle in which every permutation is equally likely. This algorithm fails badly at it. <a href="http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html">Here’s an interesting statistical analysis on the results of this algorithm</a>.</p><p>Other than being wrong, it is also very inefficient. The time complexity of a regular sort function is O(n.logn). But in this case, the sort function is given a very inconsistent ordering. So, this could go into an infinite loop or stop after a few exchanges depending on the algorithm used for sorting.</p><h3>The Correct Way — Fisher-Yates Algorithm</h3><p>Shuffling an array of values is one of the oldest problems in computer science. And the most popular solution to it has been known since 1938. It is the Fisher-Yates shuffle.</p><p>Unlike the Microsoft shuffle, this algorithm actually shuffles the array randomly and has O(n) time complexity assuming you have a random number generator with O(1) complexity.</p><p>The original fisher yates algorithm, described is 1938 goes something likes this:</p><blockquote>1. Write down the numbers from 1 through N.<br>2. Pick a random number k between one and the number of unstruck numbers remaining (inclusive).<br>3. Counting from the low end, strike out the kth number not yet struck out, and write it down at the end of a separate list.<br>4. Repeat from step 2 until all the numbers have been struck out.<br>5. The sequence of numbers written down in step 3 is now a random permutation of the original numbers.<br>Source: <a href="https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Fisher_and_Yates&#39;_original_method">https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Fisher_and_Yates&#39;_original_method</a></blockquote><p>The modern version of this algorithm (from the book <a href="https://en.wikipedia.org/wiki/The_Art_of_Computer_Programming">The Art of Computer Programming</a> by Donald E. Knuth) goes like this:</p><pre> — To shuffle an array a of n elements (indices 0..n-1):<br>for i from n−1 downto 1 do<br> j ← random integer such that 0 ≤ j ≤ i<br> exchange a[j] and a[i]</pre><p>In javascript, it’d be implemented as:</p><pre>for(let i = array.length — 1; i &gt; 0; i--){<br>  const j = Math.floor(Math.random() * i)<br>  const temp = array[i]<br>  array[i] = array[j]<br>  array[j] = temp<br>}</pre><h3>Final Thoughts</h3><p>When trying to solve a problem, look for tried-and-tested approaches.</p><p>We as programmers stand on the shoulders of giants. These algorithms have been polished and refined in the last 7+ decades. There is very little chance that your own implementation is going to be better than that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15ea3f84bfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Evil Regexes?]]></title>
            <link>https://medium.com/@nitinpatel_20236/what-are-evil-regexes-7b21058c747e?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b21058c747e</guid>
            <category><![CDATA[security-vulnerabilities]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[regex]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 06:36:29 GMT</pubDate>
            <atom:updated>2019-03-08T06:36:29.254Z</atom:updated>
            <content:encoded><![CDATA[<p>Regular expressions are cute, but there are special kinds of regexes that can crash your computer or create a Denial of Service attack on a server.😈</p><p>If you don’t know about <a href="https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS">Regular expression Denial of Service</a> or ReDos, then keep reading because this is going to be super interesting!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*Ki9eELr9U01HQPhLFrYHOQ.jpeg" /><figcaption>I can almost hear the evil chortle! Can you?</figcaption></figure><h3>What is ReDOS?</h3><p>Fundamentally, this is a security vulnerability that takes advantage of the fact that some regular expressions have <strong>exponential time complexity</strong>. Why?</p><p>In simple words, If you have a certain string and you want the computer to tell you if it matches a certain pattern, the computer just tries every single combination until it finds a match or exhausts all the combinations to try from. This is called <a href="https://www.regular-expressions.info/catastrophic.html">catastrophic backtracking</a>.</p><p>Read <a href="https://www.regular-expressions.info/catastrophic.html">this</a> if you want a more technical explanation.</p><p>So, if a program takes an input and uses a regular expression to match against a certain pattern. And if it happens to be an evil regex, the program is vulnerable to a DoS attack.</p><p>Some of the examples(from wikipedia) are:</p><ul><li>(a+)+</li><li>([a-zA-Z]+)*</li><li>(a|aa)+</li><li>(a|a?)+</li><li>(.*a){x} for x &gt; 10</li></ul><h3>Quick Example</h3><p>There are many <a href="https://en.wikipedia.org/wiki/ReDoS#Examples">examples</a> of it on the internet. Here’s a practical example that might look familiar.</p><p>Say, you’re accepting an email input from the user and you want to make sure user is sending the correct email address. Let’s write the code for email validation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/764f08bfab64ed288ba1025049ba4a1b/href">https://medium.com/media/764f08bfab64ed288ba1025049ba4a1b/href</a></iframe><p>This code looks fine, and it would work too! For any input less than 20 characters, it gives you the result in less than half a millisecond.</p><p>But for 20 characters. It takes 1 millisecond, for 21 characters, it takes 2 milliseconds, and you can see where this is going.</p><p>Fair warning, I actually managed to crash my computer when trying this out by giving a super long string as input.</p><h3>How To Prevent This Vulnerability</h3><p>Spotting evil regexes require a deep knowledge/experience in it. There are also tools for detecting these kinds of regexes. <a href="https://github.com/davisjam/vuln-regex-detector">vuln-regex-detector</a> by <a href="https://github.com/davisjam">davisjam</a> is a good example.</p><p>I’d suggest you to just be careful when using regular expressions in your code. If you do use a regular expression, have a limit on how many characters to accept from the user and have a limit on how much time the regex matching code is allowed to run before it terminates.</p><p>If you can, avoid using regex and use reputed third-party libraries for your input validation. This way you won&#39;t end up like this guy 😂</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*XuxjT8nHiLoW5EeakUaBqQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b21058c747e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit Testing Custom React Hooks]]></title>
            <link>https://medium.com/@nitinpatel_20236/unit-testing-custom-react-hooks-caa86f58510?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/caa86f58510</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 16:21:28 GMT</pubDate>
            <atom:updated>2019-02-25T17:43:18.029Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are a developer who uses React on a day to day basis, by now I’m pretty sure you’re familiar with the latest addition to React that is all rage these days. React Hooks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*phcJ87aXoHeCSjHS.png" /><figcaption>umm.. this isn’t the correct hook they were talking about I guess.</figcaption></figure><h3>What are Hooks?</h3><p>React hooks let you use state and other react features without writing a class. One of the big benefits of using hooks is that they let you reuse the logic of your components in a much cleaner way.</p><p>Let’s take an example of a controlled form. In the traditional class component, you’d write something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/673e8628a2a683e8994ae21927e0b9f2/href">https://medium.com/media/673e8628a2a683e8994ae21927e0b9f2/href</a></iframe><p>You’d get something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*VVpYLZTU9BSadPq98jPP6Q.gif" /></figure><p>But this code structure is hard to reuse in other components. With React custom hooks, you can do something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/882da68b720c4c4af624420629fed305/href">https://medium.com/media/882da68b720c4c4af624420629fed305/href</a></iframe><p>The above code will give you the exact same result but with much cleaner code. Notice that the `useTextField` is a separate function outside of the component. It means it can be imported from another file and its logic can be reused in other components with ease! Pretty cool, right?</p><p>`useTextField` is what is called a ‘custom hook’ because we created it and it’s not something provided by React.</p><p>Now let’s move on to the main topic I want to discuss. Testing our custom react hook.</p><h3><strong>Unit Testing Custom Hooks</strong></h3><p>React Hooks are just functions so testing them should be easy right? Just call them, and make assertions on the result!</p><p>Not quite. According to the React docs, <strong>Hooks cannot be called from anywhere like regular javascript functions. </strong>They can only be called from a functional component or from other hooks.</p><p>So, how do you test it?</p><p>Well, you need to create a component from which we can call out hooks. Using a callback, we can pass the result of our custom hook in the outside scope where we want to test it. Here’s a demo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9913961bd3738e7fc0dfc507ba56df21/href">https://medium.com/media/9913961bd3738e7fc0dfc507ba56df21/href</a></iframe><p>This pattern is used by the <a href="https://github.com/kentcdodds/react-testing-library/pull/274">react-testing-library</a>. I just borrowed from there. I did not invent it.</p><p>So, once we have this setup, we can use it to test all our custom hooks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b19256198a67eab85ec003b92804693/href">https://medium.com/media/4b19256198a67eab85ec003b92804693/href</a></iframe><p>Notice I’ve also imported something called act` from react-dom/test-utils` I’ll come back to it later. This is the result I get when I run it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*sk2qJN_KADdSGmUAoRk8zw.png" /><figcaption>Green checks are so damn cool!</figcaption></figure><p>So, it works! Are we done yet? There are two more things to discuss. <strong>Testing side effects </strong>and <strong>Testing State change. </strong>Let’s get to it one by one.</p><h3><strong>Testing State change</strong></h3><p>To test if state updation works, you’d write something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ec6c569ef5cdef6297903a60bcab572/href">https://medium.com/media/4ec6c569ef5cdef6297903a60bcab572/href</a></iframe><p>Let’s see what we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*JzN7ZFP6CZKewtquzSakZw.png" /><figcaption>is this why they say red is the colour of the devil?</figcaption></figure><p>It kind of worked, I mean the tests passed, but what&#39;s with the big scary error message. The warning doesn’t tell why but we know we need to wrap our state change in act` function. It is included in `react-dom` version 16.8.1+</p><p>We need to change our tests to something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52ed322ffd8d00c3562dd05d208be7c5/href">https://medium.com/media/52ed322ffd8d00c3562dd05d208be7c5/href</a></iframe><p>Now it passes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*FL4JzuIkNB87lgskbxKoPA.png" /></figure><p>The warning is gone! And the tests work correctly. Cool! Let’s get to the final part now.</p><h3><strong>Testing UseEffect</strong></h3><p>This one is actually pretty simple. To mock side effects we that come from custom hooks, we need to do three things.</p><ol><li>Mock the side effect we expect</li><li>Pass our custom hook inside our testHook function</li><li>Assert mock function to be called.</li></ol><p>Here’s a demo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a25d3d572c0447724ec3badc84d8bcd7/href">https://medium.com/media/a25d3d572c0447724ec3badc84d8bcd7/href</a></iframe><p>The result will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*RCTWZfpVeTnAPtDzLYdeQA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caa86f58510" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating Some Repetitive Git Tasks with Bash]]></title>
            <link>https://medium.com/@nitinpatel_20236/automating-some-repetitive-git-tasks-with-bash-4f50d34ae3d?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f50d34ae3d</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Fri, 18 Jan 2019 01:37:47 GMT</pubDate>
            <atom:updated>2019-01-18T01:43:58.729Z</atom:updated>
            <content:encoded><![CDATA[<p>Here are a few things I do to automate some repetitive tasks.</p><h3>Automatic Git Add, Commit and Push</h3><p>I do this just for “work in progress” commits where you don’t have to think much before committing because they’re all going to be squashed into single commit at the end. I recommend you do the same.</p><p>Copy the following into your <em>.bashrc</em> file, or (or <em>.bash_profile</em> if Mac):</p><pre>function wipcommit() {<br> git add -A<br> git commit -a -m “${*-WIPcommit}”<br> git push<br>}</pre><p>You can then call it from anywhere using bash terminal with commit message as the argument, example usage:</p><pre>wipcommit “optional commit message”</pre><p>If a commit message isn’t specified, it will default to “WIPcommit”, you can change the script if you want to replace it with your own message. You can also change the name of the function to something you find more suitable.</p><h3>Send Github Pull Requests From Terminal</h3><p>Turns out you can send pull requests without actually touching the browser. For, this you will need to install a program called <strong>hub </strong>which describes itself as:</p><blockquote><a href="https://hub.github.com/"><strong>hub</strong></a> is an extension to command-line git that helps you do everyday GitHub tasks without ever leaving the terminal.</blockquote><p>The installation process might differ depending on your OS, so I recommend you look at the <a href="https://hub.github.com/">official website</a> for the installation process.</p><p>Once you have it installed, you can send pull requests from command line by typing:</p><pre>hub pull-request -b “[OWNER]:BRANCH”</pre><p>example,</p><pre>hub pull-request -b pesto-students:day-9-segment-1</pre><p><em>(here, that </em><strong><em>pesto-students</em></strong><em> is the owner name and </em><strong><em>day-9-segment-1</em></strong><em> is branch name)</em></p><p>Better yet, make this into a function just like we did previously.</p><pre>function pull-request(){<br> hub pull-request -b $1<br>}</pre><p>Now, you can simply do:</p><pre>pull-request pesto-students:day-9-segment-1</pre><h3>Bonus: Yarn test — watch [DIRECTORY]</h3><p>Let’s say you’re working on a programming problem and the tests have already been written for you, you want the yarn test runner to keep running but only for that particular directory.</p><p>Here too, I use the same approach of making it into a function and saving into the <em>.bashrc </em>file. It’s something like:</p><pre>function yarntest(){<br> yarn test --watch $1<br>}</pre><p>Now you can simply use it as:</p><pre>yarntest directory-to-test</pre><p>This will automatically start the test runner for the specific directory in watch mode.</p><h3>Final Thoughts</h3><p>I’m aware that these might not be the best approach, so if you have any suggestions or criticisms, please leave a comment below so it would be useful to me and other readers. If you have a better approach to doing this, share it below.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f50d34ae3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Early History of LISP (1956–1959)]]></title>
            <link>https://medium.com/@nitinpatel_20236/the-early-history-of-lisp-1956-1959-485cd27e3b25?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/485cd27e3b25</guid>
            <category><![CDATA[john-mccarthy]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[lisp]]></category>
            <category><![CDATA[history]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Mon, 14 Jan 2019 01:32:23 GMT</pubDate>
            <atom:updated>2019-01-14T01:32:23.677Z</atom:updated>
            <content:encoded><![CDATA[<p>The origins of LISP is quite fascinating because many of the programming concepts we take for granted came from the development of this language.</p><p>The rest of the blog post is the summary of research found in this paper <a href="https://github.com/papers-we-love/papers-we-love/blob/master/comp_sci_fundamentals_and_history/early-lisp-history-1956-1959-herbert-stoyan-html-rendering.pdf"><strong><em>Early LISP History (1956–1959) by Herbert Stoyan University of Erlangen-N”urnberg, Germany</em></strong></a><em>.</em></p><p>In the 1950s, almost no one thought of programming as mathematical functions. Programming was associated more with stepwise execution of algorithms.</p><p>But it was <strong>John McCarthy</strong> who was first to truly develop the idea of using “functions” or subroutines as a partial step to a program. This approach slowly evolved into a full-fledged programming paradigm which we today call functional programming.</p><h3>Origins of LISP</h3><p>John McCarthy had this idea of creating a programming language during his research on Artificial Intelligence for the Dartmouth Summer Research Project around the year 1955.</p><p>He presented a proposal for research to study the relation of language to intelligence. The conclusion was that there should be attempts to create an artificial language which can be used by computers on problems and self-reference.</p><p>The Dartmouth Summer Research project was also visited by A. Newell, H. Simon and a bunch of other computer scientists who had already created a programming language and demonstrated a running program. The language was called IPL.</p><p>McCarthy was not impressed by this new language because it was too low level. But he was inspired by the idea of list processing which IPL introduced to him and would become one of the foundations of LISP.</p><h3>Functional Programming With FORTRAN</h3><p>From the years 1955 to 1957, McCarthy worked on developing and refining the idea of functional programming. During this time, he was also involved in creating a program to prove theorems of geometry along with H. Gelernter.</p><p>IBM was developing <strong>Formula Translator</strong> or <strong>FORTRAN </strong>which looked promising to McCarthy, who was fascinated by the idea of writing programs as algebraic or mathematical expressions.</p><p>McCarthy submitted suggestions of including functions for list processing in FORTRAN which were accepted. These functions could be nested to create elaborate programs of subroutines with a single statement. His ideas were used to implement a program to prove theorems of geometry.</p><p>Many of the functions he submitted later became an important part of LISP.</p><h3>Proposals to The Committee for Programming Languages</h3><p>In 1957, he joined the ACM ad-hoc-committee for programming languages. McCarthy, along with fellow members of the committee, laid out several of his important ideas in the proposal titled — “Proposal for a Programming Language”.</p><p>Much of his proposals were rejected at the time.</p><p>In 1958, McCarthy gave a lecture in M. Minsky’s course at the department of mathematics in which he talked about “An algebraic coding system”. One graduate student described McCarthy’s thoughts in the lecture as:</p><blockquote>“FORTRAN plus variable functions, composite functions (Church lambda), multiple functions, several valued functions of several variables, direct sum of functions, label portion of program with facility to make symbolic substitutions therein…”</blockquote><p>This was one of the first references to Lambda Calculus made in the context of programming languages.</p><h3>The Second Proposal</h3><p>In an attempt to clarify some of his points, McCarthy wrote another paper titled “Proposals for the Volume 2 (V2) language”</p><p>In this paper, he stressed the benefits of composite expression and his proposed prefix notation, along with a bunch of other suggestions including:</p><blockquote>“1. Addition, substraction, multiplication and division for numerical valued functions. In general we shall want any operations which were appropriate on the range of a set of functions.</blockquote><blockquote>2. Composition … is appropriate whenever the domain of a (function) f and the range of (another function) g coincide.</blockquote><blockquote>3. Abstraction from forms. … I have chosen to propose that we use the Church Lambda notation … This implies that we must also admit forms into our system and an appropriate collection of operations on them ….</blockquote><blockquote>4. Operations on functions such as differentiation, other differential operators, and integration … 5. … direct sum operation (of multiplet valued functions) …”</blockquote><p>Along with these, he considered there be a way to describe logical relations between variables (the idea later developed into logic-oriented programming). This idea, however, could not be realized in 1958 due to the lacking state of the art in computing.</p><p>In the more detailed version of the paper, “The construction of the advice taker”, he describes representing programs as list structures.</p><h3>Leaving FORTRAN Behind</h3><p>All those interesting things, however, could not be added into FORTRAN at the time. It was this time when McCarthy set out to develop his own programming language.</p><p>To help the process, McCarthy also found a financial basis for his project. The MIT Artificial Intelligence Project which was founded on September 1958 decided to back McCarthy in developing a programming language for AI.</p><h3>The “New” Programming Language</h3><p>For the next few months, he worked with MIT to create a new programming language which he described in a memo titled: “An Algebraic Language for the Manipulation of Symbolic Expression”</p><p>The language worked with integers, word, boolean, and quantities to functions and locations. The concept of “quantities” taken from ALGOL.</p><p>The language routine worked by reading lists into the machine. A list could contain numbers (floating points as well as integers), text, symbols and lists themselves (nested lists).</p><p>It had GO statements, compound statements, statements for iteration, declaration of variables and functions, and a bunch of other functions.</p><p>This language also was the first to use what we today call map function or maplist function. It took three arguments, first is the list to be mapped, second is the variable which has various list elements and third is the function body.</p><p>It was later changed to accept just two arguments, the first being the list and second being the function. McCarthy introduced the lambda notation in the second version after which it became something like this:</p><pre>maplist(L,f)=(L=0-&gt;0,1-&gt; consls(f(L),maplist(cdr(L),f)))</pre><p>Once the language was specified, they began working on an implementation of the language. While McCarthy and team were excited to start using their new language to build AI programs, nobody in the group was expert in writing a compiler.</p><p>To gain some experience, they started by translating some of the functions into SAP assembly language.</p><p>This is when they fixed the convention for calling functions, managing the storage and working with pushdown lists in the memory.</p><p>The final definitions were fixed in the fourth Memo. The language used linear sequences of machine registers for implementing lists. It used a central stack or “public push-down list”.</p><p>This memo was also the first written document where the name “LISP” was used. Much of the memo contains the SAP code for various functions of this programming language such as cons, copy, maplist, diff and some others.</p><h3>Turing Completeness and Development of Interpreter</h3><p>By the end of 1958, McCarthy wanted to prove that his new language was “Turing complete”, meaning, not only it can describe computable functions, but it can describe the same kinds of functions as a Turing Machine.</p><p>To do that, McCarthy chose the problem of developing a universal LISP function, (akin to a universal Turing-Machine), and demonstrate that it is much more understandable that the universal Turing-Machine.</p><p>The first known interpreter for LISP was released on 15th of May, 1959. This version did not feature a garbage collector as it was developed a few months later.</p><p>The idea of garbage collection was also first described by John McCarthy. He envisioned a system in which user to the program does not have to return the registers to free storage list. Rather, it takes place automatically.</p><p>The idea was bought to life on June/July of 1959 by Dan Edwards. He was one of the first users of LISP-system.</p><h3>Conclusion</h3><p>With this, I conclude the fascinating story of the initial years of the development of LISP. If you want to learn more, check out the <a href="http://campus.hesge.ch/daehne/2004-2005/Langages/Lisp.htm">original paper</a> and more <a href="http://www.softwarepreservation.org/projects/LISP/">resources on the history of LISP</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=485cd27e3b25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing the problems Installing Ubuntu on Asus ROG Laptop (Asus GL503GE)]]></title>
            <link>https://medium.com/@nitinpatel_20236/fixing-the-problems-installing-ubuntu-on-asus-rog-laptop-asus-gl503ge-5b6f497201b8?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b6f497201b8</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[freez]]></category>
            <category><![CDATA[touchpad]]></category>
            <category><![CDATA[gtx1050]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Sun, 30 Dec 2018 14:36:21 GMT</pubDate>
            <atom:updated>2018-12-30T18:35:37.515Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fixing the problems Installing Ubuntu 18.04 on Asus ROG Laptop (Asus GL503GE)</h3><p>Installing Linux on a laptop is still always a pain. Why?</p><p>Unlike operating systems that are shipped with the device come with all the necessary drivers and settings needed for the device to work smoothly, you have to manually play with settings, install drivers, and do lots of troubleshooting to make sure it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*nV7EFegSbAhJJ8loUygZcQ.png" /><figcaption>Why don’t you “just work” ubuntu???</figcaption></figure><p><strong>In my case</strong>, there were two problems installing <strong>Ubuntu 18.04</strong> on my laptop. Below are the two problems and their solutions I found.</p><p><strong>The first problem</strong> - <strong>system freezes on startup </strong>or <strong>freezes on trying to shut down </strong>or just gives <strong>black screen of death.</strong></p><p>From a little bit of googling, I found out that this problem only occurs on laptops with an <strong>NVidia Graphics Card</strong>. (Mine has <strong>GTX 1050Ti</strong>).</p><p>The solution to this is to boot your os with ‘ <strong><em>nouveau’ </em></strong>graphics which is an open source graphics drivers for Ubuntu, to make it work and then install the <strong>NVidia Drivers for Ubuntu</strong>.</p><p><strong>The second problem</strong> - <strong>Touchpad/Trackpad didn’t work. </strong>Solution: Install the latest kernel and use the bash script <a href="https://askubuntu.com/questions/1038602/18-04-ite-8910-touchpad-on-asus-strix-gl703ge-not-working">found here</a> to activate touchpad/trackpad.</p><p>I am going to assume you already know the basics of creating a partition and installing Ubuntu on that partition. My focus here is just on fixing these problems and making it work.</p><h3>Getting Ubuntu Installation To Work</h3><p>Let&#39;s go step by step to solve the first problem. Note that <strong>since the touchpad doesn’t work just yet,</strong> <strong>you’ll have to use the keyboard or an external mouse </strong>to follow all these steps. Let’s go!</p><h4>Step 0:</h4><p>First, create a partition for your Ubuntu OS and a bootable USB drive if you haven’t already.</p><h4>Step 1:</h4><p>Second, connect the USB and reboot your computer. Upon startup, keep pressing <strong>F2</strong> key before booting into Windows so that you enter the BIOS menu.</p><h4>Step 2:</h4><p>In the BIOS menu, make sure that you <strong><em>disable fast boot option (optional) and secure boot option (important).</em></strong></p><h4>Step 3:</h4><p>Now, you are ready to start the installation. Select to boot from USB.</p><h4>Step 4:</h4><p>Now you will get a grub menu with following options,</p><pre>&gt;Try Ubuntu without Installing<br>&gt;Install Ubuntu<br>&gt;blah blah...</pre><p>The important step here, <strong>Do NOT hit Enter. </strong>The default Ubuntu version is not compatible with your NVidia GTX drivers. So, do not install anything yet. Instead, follow the next step which is…</p><p>Navigate to the second option and <strong>Press ‘e’ key </strong>which will take you to the grub menu.</p><h4>Step 5:</h4><p>Once you’re in, go to the line starting with ‘Linux …’ and insert ‘<strong><em>nouveau.modeset=0’ </em></strong>without quotes at the end of that line, (after quiet splash).</p><p>Now you can click <strong>F10</strong> to boot into Ubuntu, you will get the installation n without for Ubuntu. Follow the instructions and install Ubuntu into the partition you created.</p><p>After installation, it will prompt you to restart your computer. <strong>Do NOT Restart </strong>it just yet. Before you do that you need to update your Nvidia graphics drivers.</p><p>(*In case you accidentally hit restart, you need to do step 4 and 5 again. Just that you don’t need to reinstall the OS, just start it with the ‘<em>nouveau.modeset=0’</em><strong><em> </em></strong>grub configuration.)</p><h4>Step 6:</h4><p>Now, Go to the software update application and search for driver updates. You must see two options. Select the option to update the <strong><em>Nvidia drivers (one without the X.org)</em></strong> and click apply. Once the installation is complete is done, you can restart your system.</p><h3>Getting the Touchpad/Trackpad to Work</h3><p>The trackpad that Asus ROG laptops (<strong>ITE 8910 touchpad or ELAN1200</strong>) users do not function correctly in Ubuntu. Thankfully, this is a known problem and it has been partly fixed in the kernel version 4.17.2.</p><p>So, you need to <strong>install the latest kernel </strong>or any kernel above 4.17.2 to fix this problem.</p><p>There is a GUI program called <strong>Ukuu </strong>which you can use to do this. Just open the terminal via Ctrl+Alt+T keyboard shortcut, and type the following commands:</p><pre>sudo add-apt-repository ppa:teejee2008/ppa <br>sudo apt-get update <br>sudo apt-get install ukuu </pre><p>Then <strong>open Ukuu and Install the latest kernel </strong>and restart again to make the update work.</p><p>Viola, your touchpad should be finally working now. There is one final issue that needs to be fixed. This trackpad keeps disconnecting every few minutes on Linux.</p><p>For that, you will need an extra script if the trackpad disconnects:</p><pre>#!/bin/bash<br>if [ -z $1 ]<br>    then<br>        echo &#39;rsmod unloads and reloads kernel modules with modprobe&#39;<br>        echo &#39;usage: rsmod &lt;kernelmodulename&gt;&#39;<br>        echo &#39;Requires root privileges&#39;<br>        exit 1<br>fi<br>pkexec bash -c &quot;modprobe -r $1; modprobe $1&quot;</pre><p>Save that as <em>/usr/local/bin/rsmod</em> and call it with <em>hid-multitouch</em> when the touchpad disconnects.</p><p>That’s it, these are the things I did to get Ubuntu working. I hope it helps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b6f497201b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting XML to JSON using Recursion]]></title>
            <link>https://medium.com/@nitinpatel_20236/converting-xml-to-json-using-recursion-7b1df91b42d8?source=rss-fae9d84f67cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b1df91b42d8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[xml]]></category>
            <dc:creator><![CDATA[Nitin Patel]]></dc:creator>
            <pubDate>Fri, 28 Sep 2018 12:13:22 GMT</pubDate>
            <atom:updated>2018-09-28T12:28:11.330Z</atom:updated>
            <content:encoded><![CDATA[<p>The other day, I was working on an app which needed to fetch data from a third party rest api, and what happened next is the thing of the one of the worst nightmares of a JavaScript developer.</p><p>The server sent back response in.. gasp.. XML instead of JSON like any sane rest api would do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*XuRqFNT2fMExddcrERq-6g.jpeg" /></figure><p>So, I came up with a way to easily convert XML into JavaScript Object. <a href="https://gist.github.com/niinpatel/2c9923c30ecf356fa07b50b2d6c47f60">Here’s an example of the data I was trying to read.</a></p><p>Keep in mind that this code makes use of WebAPIs so it is not available in server side javascript like NodeJS. This works great for front end applications like React or Angular.</p><p>The format of XML is generally something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08be7971294a4e97e0ced19f22c5fa5c/href">https://medium.com/media/08be7971294a4e97e0ced19f22c5fa5c/href</a></iframe><p>I want the ouput to look a little something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a115cb11a1d0d0d3473a540a74c8ccf3/href">https://medium.com/media/a115cb11a1d0d0d3473a540a74c8ccf3/href</a></iframe><p>Since, XML has a lot of nested tags, this problem is a perfect example of a practical application of recursion.</p><p>Before we begin to code, we need to understand something called the <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMParser">DOMParser</a> Web API.</p><p>According to the MDN documentation,</p><blockquote>The <strong>DOMParser</strong> interface provides the ability to parse <a href="https://developer.mozilla.org/en-US/docs/Glossary/XML">XML</a> or <a href="https://developer.mozilla.org/en-US/docs/Glossary/HTML">HTML</a> source code from a string into a DOM TREE.</blockquote><p>In simple words, it converts and XML string into a DOM Tree. Here’s how it works.</p><p>Lets say we have an some XML stored in a string, strxml. We can parse the data in it as a DOM tree like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e864edcbee49ab83b5c30ca707a3721/href">https://medium.com/media/4e864edcbee49ab83b5c30ca707a3721/href</a></iframe><p>Now that we have got the basics right. Let’s start writing the psuedo code.</p><pre>Initialize variable jsonResult is empty object. <br>If scrDOM has no children nodes:<br>    return innerHTML of the DOM.  // This is our base case.</pre><pre>For each childNode in children nodes:<br>    Check if childNode has siblings of same name. <br>    If it has no siblings of same name: <br>        set childnode name as key whose value is json of the child      node. (we&#39;re calling the function recursively.)<br>    If it has no siblings of same name<br>        set childnode name as key whose value is an empty array, every child whose name is same as this pushed into this array. <br>return jsonResult</pre><p>Here’s the JavaScript code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43d788201fe995f906d521a2971541c4/href">https://medium.com/media/43d788201fe995f906d521a2971541c4/href</a></iframe><p>This is the basic algorithm / code for converting an XML string into a JSON object. Since, it uses recursion, it can go very deep into the DOM tree and parse every single element.</p><p>This works for most of the cases. You can modify this algorithm according to your own needs or requirements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b1df91b42d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>