<?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 Asmin Budha on Medium]]></title>
        <description><![CDATA[Stories by Asmin Budha on Medium]]></description>
        <link>https://medium.com/@sminmgr?source=rss-5f0aae0fba01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*XcKC5eZnG75VzLiV6_M_9g.jpeg</url>
            <title>Stories by Asmin Budha on Medium</title>
            <link>https://medium.com/@sminmgr?source=rss-5f0aae0fba01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:38:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sminmgr/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[Apply Operations: Be Lazy]]></title>
            <link>https://sminmgr.medium.com/apply-operations-be-lazy-3e24bf902bbc?source=rss-5f0aae0fba01------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e24bf902bbc</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Asmin Budha]]></dc:creator>
            <pubDate>Sun, 04 Apr 2021 08:17:27 GMT</pubDate>
            <atom:updated>2021-04-04T08:17:27.618Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4cVXWRHxZXzGYx27" /><figcaption>Photo by <a href="https://unsplash.com/@priscilladupreez?utm_source=medium&amp;utm_medium=referral">Priscilla Du Preez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Work Smart, Be Lazy.<br>In this article, I’m going to use the Lazy trick to optimize the solution for one problem that was asked in the coding assessment round to my friend.</p><p>Let’s start with a problem statement. In truth, I don’t know the exact problem statement but I’m going to explain in my words that I understood from the discussion I had with my friend.<br>Suppose, you have a stack <strong>S</strong> and given the list of operations in a string you’ve to perform based on the below scenarios:</p><ol><li>‘push n’:<br>where, <strong>n</strong> is a number<br>As you’ve guessed, we have to push <strong>n</strong> to stack and print the last element from a stack, that would be <strong>n</strong>.</li><li>‘pop’:<br>Similarly, we have to pop the stack and print the last element from the stack after it is popped or if the stack is empty print ‘<strong>Empty</strong>’.</li><li>‘inc i v’<br>where, <strong>i</strong> represent index in stack and <strong>v</strong> represents value to be added. Command <strong>inc </strong>means we have to add value <strong>v </strong>from 0th to <strong>(i-1)th</strong> index. And, print last element from stack or if empty print ‘<strong>Empty</strong>’.</li></ol><p>For example, suppose you are given operations:</p><blockquote>[‘push 4’, ‘pop’, ‘push 3’, ‘push 5’, ‘push 2’, ‘inc 3 1’, ‘pop’, ‘push 1’, ‘inc 2 2’, ‘push 4’, ‘pop’, ‘pop’];</blockquote><p>Then the output would be:</p><pre>4, ‘EMPTY’, 3, 5, 2, 3, 6, 1, 1, 4, 1, 8</pre><p>First of all, let’s start with a naive solution and we will optimize later on being lazy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f4afb3a7ead5bea73d55e0a16f0e0a9/href">https://medium.com/media/4f4afb3a7ead5bea73d55e0a16f0e0a9/href</a></iframe><p>Here, since we have to traverse every operation in input which would be <strong>O(n), </strong>and for every operation <strong>pop</strong> or <strong>push</strong> is <strong>O(1)</strong> while for <strong>inc</strong> it is <strong>O(n)</strong>. So, taking the worst-case scenario total time complexity is <strong>O(n*n)</strong>.</p><p>That’s all, problem solved. Am I being lazy? Oh, sorry, we’re supposed to be lazy on our algorithm not on this article. Ugh!</p><p>Now, before adding lazy trick in our algorithm let’s first analyze where we can optimize from our above code.</p><pre>function executeOperation(input) {<br>  let stack=[];<br>  for(let operation of input) {<br>    ...<br>  }<br>}</pre><p>Hmm, Can we optimize this for..loop on this function? No, not. As we have to read every input operation so it’s not possible. Let’s try another.</p><pre>function push(stack,n){<br>  stack.push(n);<br>  return n;<br>}</pre><pre>function pop(stack){<br>  stack.pop();<br>  return stack.length &gt; 0 ? stack[stack.length - 1] : &#39;EMPTY&#39;;<br>}</pre><p>Oh, they’re already <strong>O(1)</strong>. What would be better than <strong>O(1)</strong>? Is it <strong>O(0.5)</strong>? Just kidding there’s no such thing as <strong>O(0.5).</strong></p><p>Lastly, we only have:</p><pre>function inc(stack, i, v) {<br>  ...<br>  for(let j = 0; j &lt; i; ++j) {<br>    stack[j] += v<br>  }<br>  return stack[stack.length - 1]<br>}</pre><p>Let’s try to optimize it since it is our last hope. <br>If we look into the output that we’re printing then all are the last element from the stack. So, why increment all the values?</p><p>Here comes the lazy trick part.<br>Let’s only add the value to <strong>(i-1)th</strong> position. With that</p><pre>function inc(stack, i, v) {<br>  ...<br>  stack[i-1]+=v;<br>  return stack[i-1];                       <br>}</pre><p>Does it give the right solution? Yes, and while popping we’ll add value to the previous.<br>Now, adding lazy trick our solution becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/beb0019caf572fe510f4284dc08a6d49/href">https://medium.com/media/beb0019caf572fe510f4284dc08a6d49/href</a></iframe><p>Now, if we look into our solution we only have one loop while traversing inputs. So, total complexity will be <strong>O(n)</strong>.</p><p>Phew! Cannot be lazy to write this article but can be lazy in our algorithm. My tips to you.</p><p>Thanks for reaching out to this point.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e24bf902bbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginning of my Open Source Contribution]]></title>
            <link>https://sminmgr.medium.com/beginning-of-my-open-source-contribution-e175d64ca9f5?source=rss-5f0aae0fba01------2</link>
            <guid isPermaLink="false">https://medium.com/p/e175d64ca9f5</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[react-native-camera]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Asmin Budha]]></dc:creator>
            <pubDate>Tue, 07 Jul 2020 17:07:01 GMT</pubDate>
            <atom:updated>2020-07-07T17:08:21.379Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMZRkrbi7mtML6psV7loQQ.jpeg" /><figcaption><a href="https://ji4n127gpjg29plb11l88dg7-wpengine.netdna-ssl.com/wp-content/uploads/2019/03/iStock-956366756-1024x683.jpg">https://ji4n127gpjg29plb11l88dg7-wpengine.netdna-ssl.com/wp-content/uploads/2019/03/iStock-956366756-1024x683.jpg</a></figcaption></figure><p>It has been late for this article since this article will be revolving around my contribution to<a href="https://github.com/react-native-community/react-native-camera/pull/2769"> react-native-camera</a> which was long before. But, today while writing this article I was motivated by participants in my <a href="https://www.facebook.com/events/710006749799722/">Git &amp; GitHub for beginners session</a>. Also, recalling a comment from<a href="https://www.facebook.com/hianit"> Anit Shrestha dai</a> where he mentioned maybe writing an article about it will help others, has motivated me to write this article.</p><p>In this article, I’ll be talking about my story about how I did my contribution and I’ll talk about the case before and now which I learned from it. I hope this article will give an idea and motivation to beginners who are new to the world of Open Source. For how to part, there are lots of blogs and tutorials so this article will only be focusing on the motivation part, not on how to do part.</p><h3>My Story</h3><p>It starts when I was on a react-native project on my current working company <a href="https://www.lftechnology.com/">Leapfrog Technology</a>. My tasks were mostly revolving around the camera part of the app. There are two libraries which we were using in our app i.e<a href="https://github.com/react-native-community/react-native-image-picker"> react-native-image-picker</a> and<a href="https://github.com/react-native-community/react-native-camera/"> react-native-camera</a>.</p><p>We had a task where we had to open the front camera initially for better UX and back cameras on some parts. And you know with client projects if there’s some task then you have to do it anyway. But the library hadn’t provided that props for Android, it was only available on IOS. So, we looked into the internal codes of Android if we can add that feature. We did find the solution but unfortunately, that solution doesn’t work for the Android version above 6. Although we have created a<a href="https://github.com/react-native-community/react-native-image-picker/pull/1071"> PR</a> for this if someone might benefit from it.</p><p>Later on, with react-native-image-picker, we had some random crash issues too so we decided to use react-native-camera since it allows props to show front and back cameras too. With this, we integrated react-native-camera but one feature which it provided was not in react-native-camera i.e providing paths to save the captured image. Now, again we did search into and added code. We thought this might be helpful for others too so we opened a<a href="https://github.com/react-native-community/react-native-camera/pull/2769"> PR</a> that got merged later on.</p><p><strong>Steps I took</strong></p><ol><li>Did change the code in node_modules directly for the use case of our application.</li><li>Once, changes in node_modules resolve our issue. We forked the original package to our repo then pushed our changed code.</li><li>With our forked repo, we can use it until those features are merged into the original library.</li><li>Now, to create PR into the original library, we tried to generalize this feature and made it accessible through props.</li><li>Tested out changed library for edge cases and bugs.</li><li>Once verified we created a <a href="https://github.com/react-native-community/react-native-camera/pull/2769">PR</a> that has a nice discussion over it. Maintainers and collaborators were quick to respond, they reviewed code and requested for changes or any other clarification.</li><li>After approval, they merged it. Unfortunately, it got some bugs that we might have missed while testing but thanks to the open source community they quickly fixed those bugs and added that same feature in IOS too.</li></ol><p>But contribution is not limited to adding features or bugs. Contribution can also be done by raising issues or fixing grammar mistakes in documentation. Likewise, we have also raised many issues during that project so can be your contribution. After this incident, my respect for the open source community has raised more. And thanks to react-native-community, they have so granularized modules that it’s easy for us to contribute.</p><h3>Learning</h3><p>So, what I felt with these experiences is that need or attitude that makes you do it anyway helps you to contribute more i.e fix bugs or add a feature you need otherwise we’ll drop that library or tools thinking that it doesn’t provide feature we want and search for other or say it’s not possible like I used to do during my college days. But I think the attitude that I have to fix it or add that feature helps motivate you more into contribution. So, my suggestion would be to not be limited to resources provided by others rather create your resource or modify others.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e175d64ca9f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Python Virtual Environment]]></title>
            <link>https://sminmgr.medium.com/setting-up-python-virtual-environment-f1cc2f6fc9ec?source=rss-5f0aae0fba01------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1cc2f6fc9ec</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[virtual-environment]]></category>
            <dc:creator><![CDATA[Asmin Budha]]></dc:creator>
            <pubDate>Sat, 29 Feb 2020 11:36:23 GMT</pubDate>
            <atom:updated>2020-02-29T11:36:23.042Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was just starting to learn Python, my python environment was messy with unnecessary packages and libraries. Every time when some tutorial says you to install some packages or library I used to install directly into device environment. Over time it became messy with unnecessary packaged which I didn’t know whether I still need it or not.</p><p>So, how do we manage those packages? Solution to this is creating virtual environment where you can install packages which will be separate from device environment. Not only for above issue, we can also setup environment when we need to create a separate project which will depend on setup environment packages.</p><p>One easy solution to create a virtual environment is by creating project in <a href="https://www.jetbrains.com/pycharm/download/"><strong>Pycharm IDE</strong></a><strong>. </strong>In terminal, there exist already activated environment.</p><p>But if you want to setup from scratch then follow this tutorial below:</p><p><strong>Setup virtual environment</strong></p><p>Navigate to folder where you want to setup your virtual environment.</p><pre># macOS/Linux<br># You may need to run sudo apt-get install python3-venv first<br>python3 -m venv .venv<br><br># Windows<br># You can also use py -3 -m venv .venv<br>python -m venv .venv</pre><p><strong>Activate virtual environment</strong></p><p>You can activate python environment by using following command:</p><pre># macOS/Linux<br>source .venv/bin/activate<br><br># Windows<br>.venv\Scripts\activate</pre><p><strong>Deactivate virtual environment</strong></p><p>You can deactivate python environment by simply using deactivate command.</p><pre>deactivate</pre><p>From now on, if you want to add package then you have to use <a href="https://en.wikipedia.org/wiki/Pip_(package_manager)">pip</a>. If you don’t know what is pip, <strong>pip</strong> is a <em>de facto</em> standard package-management system used to install and manage software packages written in Python.</p><p>For example:</p><pre>pip3 install numpy</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1cc2f6fc9ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Palindrome Check Algorithm]]></title>
            <link>https://sminmgr.medium.com/optimizing-palindrome-check-algorithm-ad761ff8fc6b?source=rss-5f0aae0fba01------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad761ff8fc6b</guid>
            <category><![CDATA[string]]></category>
            <category><![CDATA[palindrome]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Asmin Budha]]></dc:creator>
            <pubDate>Sat, 25 May 2019 11:28:19 GMT</pubDate>
            <atom:updated>2019-06-03T05:13:15.455Z</atom:updated>
            <content:encoded><![CDATA[<p>During my early programming days, one of the problem that I used to solve was:</p><pre>Given a string check whether it was palindrome or not</pre><p>It was the basic problem and I think almost all of the programmers has solved while learning to code.</p><p>One of the naive solution is to reverse the string and compare with original string.</p><pre>function isPalindrome(s){<br> let temp=’’;<br> for(let i=s.length-1;i&gt;=0;i — ){<br> temp+=s.charAt(i);<br> }<br> return temp===s;<br>}</pre><pre>console.log(isPalindrome(‘madam’));</pre><p>whose time complexity is <strong>O(n)</strong> in both best case and worst case.</p><p>Ever thought about optimizing it. Yeah, we can optimize it in best case but cannot be optimized in worst case since we have check for every letter in string until end or just return false when two string does not match.</p><h3><strong>Two Pointer Method:</strong></h3><p>In this method, we take two extreme indexes and check whether character in that indexes match or not until they meet up in center.</p><pre>function isPalindromeWithTwoPointer(s){<br> let l=0,r=s.length-1;<br> while(l&lt;r){<br> if(s.charAt(l)!==s.charAt(r)){<br> return false;<br> }<br> l++;<br> r — ;<br> }<br> return true;<br>}</pre><p>If two characters are different at the two ends then directly it returns false. So, time complexity in best time is Ω<strong>(1)</strong>.</p><h3>Expand Around Center:</h3><p>This method is just opposite to above two pointer method where we check from center to the end points.</p><pre>function isPalindromeWithExpandAroundCenter(s){<br> let r=Math.floor(s.length/2)<br> let l=s.length%2==0?r-1:r;<br> while(l&gt;=0 &amp;&amp; r&lt;s.length){<br> if(s.charAt(l)!==s.charAt(r)){<br> return false;<br> }<br> l — ;<br> r++;<br> }<br> return true;<br>}</pre><p>If two characters are different at the center then directly it returns false. So, time complexity in best time is Ω<strong>(1)</strong>.</p><p>Though these two methods does not improve time complexity in worst case but they help to optimize while solving harder problems like palindromic sub string.</p><p>This was all for this post. Stay tuned for Palindromic sub string problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad761ff8fc6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A-Z sorting in JavaScript]]></title>
            <link>https://sminmgr.medium.com/a-z-sorting-in-javascript-bda4be32adb?source=rss-5f0aae0fba01------2</link>
            <guid isPermaLink="false">https://medium.com/p/bda4be32adb</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[sorting]]></category>
            <dc:creator><![CDATA[Asmin Budha]]></dc:creator>
            <pubDate>Sat, 04 May 2019 08:34:35 GMT</pubDate>
            <atom:updated>2019-05-04T08:34:35.029Z</atom:updated>
            <content:encoded><![CDATA[<p>One of my project has a requirement of A-Z sorting items in list. I have list of something like below:</p><pre>[ &#39;mw-1&#39;, &#39;mw-11&#39;, &#39;mw-12&#39;, &#39;mw-1a&#39;, &#39;mw-1b&#39;, &#39;mw-2&#39; ]</pre><p>And requirement was to sort it like below:</p><pre>[ &#39;mw-1&#39;, &#39;mw-1a&#39;, &#39;mw-1b&#39;, &#39;mw-2&#39;, &#39;mw-11&#39;, &#39;mw-12&#39; ]</pre><p>One of the easy solution that came to my mind was:</p><pre>const a=[&#39;mw-1&#39;,&#39;mw-2&#39;,&#39;mw-1a&#39;,&#39;mw-11&#39;,&#39;mw-12&#39;,&#39;mw-1b&#39;]; <br>console.log(a.sort())</pre><p>But it didn’t solve the problem as output will be something like this:</p><pre>[ &#39;mw-1&#39;, &#39;mw-11&#39;, &#39;mw-12&#39;, &#39;mw-1a&#39;, &#39;mw-1b&#39;, &#39;mw-2&#39; ]</pre><p>which is not what we want.</p><p>So, I came up with this solution:</p><pre><strong>function sortAlphaNumeric(first, second) { <br>   let firstVal = first.toLowerCase(); <br>   let secondVal = second.toLowerCase(); <br>  <br>   let re1 = /([0-9]+)/g; <br>   let re2 = /([0-9]+)/g; <br>   let match1 = null; <br>   let match2 = null; <br>  <br>   while ((match1 = re1.exec(firstVal)) != null &amp;&amp; (match2 = re2.exec(secondVal))) { <br>     const strPart1 = firstVal.substr(0, match1[&#39;index&#39;]); <br>     const strPart2 = secondVal.substr(0, match2[&#39;index&#39;]); <br>  <br>     if (strPart1 !== strPart2) { <br>        return strPart1.localeCompare(strPart2); <br>     } <br>     const numPart1 = parseInt(match1[0]); <br>     const numPart2 = parseInt(match2[0]); <br>  <br>     if (numPart1 !== numPart2) { <br>       return numPart1 - numPart2; <br>     } <br>  <br>     firstVal = firstVal.substr(re1.lastIndex); <br>   } <br>   return firstVal.substr(re1.lastIndex).localeCompare(secondVal.substr(re2.lastIndex)); <br>} <br>  <br>const a=[&#39;mw-1&#39;,&#39;mw-2&#39;,&#39;mw-1a&#39;,&#39;mw-11&#39;,&#39;mw-12&#39;,&#39;mw-1b&#39;]; <br>console.log(a.sort(sortAlphaNumeric))</strong></pre><p>Let’s first break down our problem and I will explain about the above code snippet.</p><p>Built-in sort comparison in JavaScript use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare">localeCompare</a> which sorts mw-11 before mw-2 but we need mw-2 before mw-11.</p><p>So we want our own comparison function for this problem. So we have to compare string and number independently as we need string having 1 before 2 and 2 before 11 and so on. One of the idea to split the string would be with a.split(‘-’) and compare string and number recursively but it is not great idea as our string might be something like ‘mw2’. In this case we will not be able to split string so we will use regex to find number in string below:</p><pre><strong>let re1 =</strong> <strong>/([0-9]+)/g<br>let re2 =</strong> <strong>/([0-9]+)/g</strong></pre><p>Let’s split string before numbers</p><pre><strong>let match1 = re1.exec(firstVal); <br>let match2 = re2.exec(secondVal);</strong></pre><pre><strong>const strPart1 = firstVal.substr(0, match1[&#39;index&#39;]);<br>const strPart2 = secondVal.substr(0, match2[&#39;index&#39;]);</strong></pre><p>Now we compare this string with one another if they are not equal.</p><pre><strong>if (strPart1 !== strPart2) { <br>      return strPart1.localeCompare(strPart2); <br>}</strong></pre><p>Else we can compare currently found number as:</p><pre><strong>const numPart1 = parseInt(match1[0]); <br>const numPart2 = parseInt(match2[0]); <br>  <br>if (numPart1 !== numPart2) { <br>     return numPart1 - numPart2; <br>}</strong></pre><p>If this number part are also equal then we can traverse forward to follow same process until number is found. Finally, if no number is found then we are only left with string. Now we can just localeCompare these two remaining string. In the above code snippet, <strong>re1.exec(firstVal) </strong>should directly remove the traversed string from firstVal which is working fine in case of secondVal but firstVal is not working as it was supposed to. So, I am putting simple hack inside while loop i.e <strong>firstVal = firstVal.substr(re1.lastIndex);</strong></p><p>firstValThat was all. Also, it may not be optimized solution as it’s time complexity is around n²log(n) which I think can be optimized using Trie.</p><p>Comments are welcome and I would be grateful if anyone will give me better optimized solution.</p><p>References:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare">String.prototype.localeCompare() - JavaScript | MDN</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions">Regular expressions - JavaScript | MDN</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bda4be32adb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>