<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="/feeds/rss-style.xsl"?>
<rss version="2.0" 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">
    <channel>
        <title>Suraj Yadav</title>
        <link>https://ysuraj.com</link>
        <description>Suraj's personal space</description>
        <lastBuildDate>Wed, 03 Jun 2026 13:03:25 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>Astro Chiri Feed Generator</generator>
        <language>en-US</language>
        <copyright>Copyright © 2026 Suraj Yadav</copyright>
        <atom:link href="https://ysuraj.com/rss.xml" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Recursion]]></title>
            <link>https://ysuraj.com/recursion</link>
            <guid isPermaLink="false">https://ysuraj.com/recursion</guid>
            <pubDate>Tue, 06 Jan 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>Prerequisites</h2>
<ul>
<li>Javascript arrow functions</li>
<li>Factorial</li>
</ul>
<h2>Dialogue</h2>
<p>Do you know recursion?</p>
<ul>
<li>Yes</li>
</ul>
<p>Do you really know recursion?</p>
<ul>
<li>Yeah, I would say so</li>
</ul>
<p>No, but do you <em>really</em> know recursion?</p>
<ul>
<li>Alright, I’ll bite</li>
</ul>
<p>Show me the Factorial <em>structure</em></p>
<ul>
<li>Here you go</li>
</ul>
<pre><code class="language-javascript">// factorial
(n) =&gt; {
  // base case
  if (n === 0) {
    return 1
  }
  // recursive case
  return n * factorial(n - 1)
}
</code></pre>
<p>Could you do it if the language did not support recursion?</p>
<ul>
<li>I don’t know… yet but I can try</li>
</ul>
<p>What would be a good starting point?</p>
<ul>
<li>Eliminating the recursive call</li>
</ul>
<p>How would you do that?</p>
<ul>
<li>By abstracting out the recursive part</li>
</ul>
<pre><code class="language-javascript">// factorialStructure
(toBeDetermined) =&gt; {
  return (n) =&gt; {
    if (n === 0) {
      return 1
    }
    return n * toBeDetermined(n - 1)
  }
}
</code></pre>
<ul>
<li>How can we infer <code>toBeDetermined</code>?</li>
</ul>
<p>Lets try to reverse engineer. Can you tell that this behaves like <code>factorial0</code> for input <code>n = 0</code>?</p>
<ul>
<li>Of Course, because that’s the base case</li>
</ul>
<p>Does that mean we have <code>factorial0</code>?</p>
<ul>
<li>Yes, as long as we never reach the recursive case</li>
</ul>
<hr />
<h3>Assumption: <code>Infinity</code></h3>
<p>To keep the focus of this write up on Recursion, we will assume that Infinity is a function that never produces a value.</p>
<pre><code class="language-javascript">const infinity = () =&gt; {
  return infinity()
}
</code></pre>
<hr />
<p>So can we call this <code>factorial0</code>?</p>
<pre><code class="language-javascript">((toBeDetermined) =&gt; {
  return (n) =&gt; {
    if (n === 0) {
      return 1
    }
    else {
      return n * toBeDetermined(n - 1)
    }
  }
})(infinity)
</code></pre>
<ul>
<li>After <em>reducing</em> it to the following,</li>
</ul>
<pre><code class="language-javascript">// factorial0
(n) =&gt; {
  if (n === 0) {
    return 1
  }
  else {
    return n * infinity(n - 1)
  }
}
</code></pre>
<ul>
<li>It matches the behavior of <code>factorial0</code>, and hence we can call it <code>factorial0</code></li>
</ul>
<p>Now that we have <code>factorial0</code>, can we write <code>factorialLessThanOrEqualTo1</code> as the following?</p>
<pre><code class="language-javascript">// factorialLessThanOrEqualTo1?
(n) =&gt; {
  if (n === 0) {
    return 1
  }
  else {
    return n * factorial0(n - 1)
  }
}

// which reduces to
(n) =&gt; {
  if (n === 0) {
    return 1
  }
  else {
    return n * ((o) =&gt; {
      if (o === 0) {
        return 1
      }
      else {
        return o * infinity(o - 1)
      }
    })(n - 1)
  }
}

</code></pre>
<p>Given that this follows the behavior of factorial for input n = 0 and n = 1, it can be called <code>factorialLessThanOrEqualTo1</code></p>
<p>So, is the following function <code>factorialLessThanOrEqualTo2</code>?</p>
<pre><code class="language-javascript">// factorialLessThanOrEqualTo2?
(n) =&gt; {
  if (n === 0) {
    return 1
  }
  else {
    return n * ((o) =&gt; {
      if (o === 0) {
        return 1
      }
      else {
        return o * ((p) =&gt; {
          if (p === 0) {
            return 1
          }
          else {
            return p * infinity(p - 1)
          }
        })(o - 1)
      }
    })(n - 1)
  }
}
</code></pre>
<ul>
<li>Yeah, but this seems a lot. There is a lot of repetition here.</li>
</ul>
<p>Yes, I agree we can abstract out the repeating bit</p>
<p>What does this look like?</p>
<pre><code class="language-javascript">((makeFactorial) =&gt; {
  return makeFactorial(infinity)
})(
  (factorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * factorial(n - 1)
      }
    }
  }
)
</code></pre>
<ul>
<li>I don’t know yet, I’ll have to evaluate this</li>
</ul>
<p>How would you do that?</p>
<ul>
<li>I would do a single substitution. That would give us</li>
</ul>
<pre><code class="language-javascript">((factorial) =&gt; {
  return (n) =&gt; {
    if (n === 0) {
      return 1
    }
    else {
      return n * factorial(n - 1)
    }
  }
})(infinity)
</code></pre>
<p>Can we reduce it further?</p>
<ul>
<li>Yes we can. That would give us…</li>
</ul>
<pre><code class="language-javascript">(n) =&gt; {
  if (n === 0) {
    return 1
  }
  else {
    return n * infinity(n - 1)
  }
}
</code></pre>
<ul>
<li>That looks exactly like <code>factorial0</code></li>
</ul>
<p>Correct, So can we write <code>factorialLessThanOrEqualTo1</code> using <code>makeFactorial</code> as the following?</p>
<pre><code class="language-javascript">// factorialLessThanOrEqualTo1
((makeFactorial) =&gt; {
  return makeFactorial(
    makeFactorial(infinity)
  )
})(
  (factorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * factorial(n - 1)
      }
    }
  }
)
</code></pre>
<p>(please try reducing this with pen and paper if possible)</p>
<p>What about <code>factorialLessThanOrEqualTo2</code>?</p>
<ul>
<li>Here you go</li>
</ul>
<pre><code class="language-javascript">// factorialLessThanOrEqualTo2
((makeFactorial) =&gt; {
  return makeFactorial(
    makeFactorial(
      makeFactorial(infinity)
    )
  )
})(
  (factorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * factorial(n - 1)
      }
    }
  }
)
</code></pre>
<p>So is recursion a bunch of pending operations stacked on top of each other?</p>
<ul>
<li>
<p>True while executing</p>
</li>
<li>
<p>That does work but how far can we keep going? We wouldn’t want to manually compose <code>makeFactorial</code> to get <code>factorialLessThanEqualToN</code></p>
</li>
</ul>
<p>I agree, lets see if we can automate this composition to work for all <code>n</code> values</p>
<ul>
<li>Where would we start?
<code>makeFactorial</code></li>
</ul>
<p>Since it doesnt matter what we pass to <code>makeFactorial</code> for the base case i.e. <code>factorial0</code>, can we give it <code>makeFactorial</code> instead of <code>infinity</code>?</p>
<ul>
<li>Sure, that would give us <code>factorial0</code> as</li>
</ul>
<pre><code class="language-javascript">// factorial0
((makeFactorial) =&gt; {
  return makeFactorial(makeFactorial)
})(
  (factorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * factorial(n - 1)
      }
    }
  }
)
</code></pre>
<p>Can we use the name <code>makeFactorial</code> instead of <code>factorial</code>?</p>
<ul>
<li>Sure, that doesn’t change the meaning. So factorial0 would look like</li>
</ul>
<pre><code class="language-javascript">// factorial0
((makeFactorial) =&gt; {
  return makeFactorial(makeFactorial)
})(
  (makeFactorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * makeFactorial(n - 1)
      }
    }
  }
)
</code></pre>
<ul>
<li>But why would we want to do that?</li>
</ul>
<p>Because some names are more equal than others</p>
<p>Can we use the else branch to generate a recursive case?</p>
<pre><code class="language-javascript">// ?
((makeFactorial) =&gt; {
  return makeFactorial(makeFactorial)
})(
  (makeFactorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * makeFactorial(infinity)(n - 1)
      }
    }
  }
)
</code></pre>
<ul>
<li>Yes, this gives us <code>factorialLessThanOrEqualTo1</code> because <code>makeFactorial(infinity)</code> reduces to a function that behaves like <code>factorial0</code> as we saw above</li>
</ul>
<p>Can we do this more than once?</p>
<ul>
<li>How would we do that?</li>
</ul>
<p>How about feeding makeFactorial to itself?</p>
<pre><code class="language-javascript">// ?
((makeFactorial) =&gt; {
  return makeFactorial(makeFactorial)
})(
  (makeFactorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * makeFactorial(makeFactorial)(n - 1)
      }
    }
  }
)
</code></pre>
<ul>
<li>This feels unnatural</li>
</ul>
<p>Is it because up until now, we were feeding makeFactorial a function that behaves like factorial for smaller inputs?</p>
<ul>
<li>BINGO</li>
</ul>
<p>Well, makeFactorial <em>IS</em> the creator of such functions</p>
<ul>
<li>Ooo, but does it actually work?</li>
</ul>
<p>Lets try, whats the output for input n = 0?</p>
<pre><code class="language-javascript">// ?
((makeFactorial) =&gt; {
  return makeFactorial(makeFactorial)
})(
  (makeFactorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * makeFactorial(makeFactorial)(n - 1)
      }
    }
  }
)
</code></pre>
<ul>
<li>We can unwind this to get a flat function before applying for the input n = 0. Lets try substituting the arguments step by step</li>
</ul>
<pre><code class="language-javascript">((makeFactorial) =&gt; {
  return (n) =&gt; {
    if (n === 0) {
      return 1
    }
    else {
      return n * makeFactorial(makeFactorial)(n - 1)
    }
  }
})(
  (makeFactorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * makeFactorial(makeFactorial)(n - 1)
      }
    }
  }
)
</code></pre>
<p>Can we reduce it even further?</p>
<ul>
<li>Yes we can</li>
</ul>
<pre><code class="language-javascript">// reducedStructure
(n) =&gt; {
  if (n === 0) {
    return 1
  }
  else {
    return n *
      ((makeFactorial) =&gt; {
        return (n) =&gt; {
          if (n === 0) {
            return 1
          }
          else {
            return n * makeFactorial(makeFactorial)(n - 1)
          }
        }
      })(
        (makeFactorial) =&gt; {
          return (n) =&gt; {
            if (n === 0) {
              return 1
            }
            else {
              return n * makeFactorial(makeFactorial)(n - 1)
            }
          }
        }
      )(n - 1)
  }
}
</code></pre>
<p>Do you know the answer for n = 0 now?</p>
<ul>
<li>Yes, its clearly the base case i.e. 1</li>
</ul>
<p>What about n = 1?</p>
<ul>
<li>We can work it out. For n = 1, it will return the else branch i.e.</li>
</ul>
<pre><code class="language-javascript">1 *
  ((makeFactorial) =&gt; {
    return (n) =&gt; {
      if (n === 0) {
        return 1
      }
      else {
        return n * makeFactorial(makeFactorial)(n - 1)
      }
    }
  })(
    (makeFactorial) =&gt; {
      return (n) =&gt; {
        if (n === 0) {
          return 1
        }
        else {
          return n * makeFactorial(makeFactorial)(n - 1)
        }
      }
    }
  )(1 - 1)
</code></pre>
<p>which will reduce to…</p>
<pre><code class="language-javascript">1 *
  ((n) =&gt; {
    if (n === 0) {
      return 1
    }
    else {
      return n *
        ((makeFactorial) =&gt; {
          return (n) =&gt; {
            if (n === 0) {
              return 1
            }
            else {
              return n * makeFactorial(makeFactorial)(n - 1)
            }
          }
        })(
          (makeFactorial) =&gt; {
            return (n) =&gt; {
              if (n === 0) {
                return 1
              }
              else {
                return n * makeFactorial(makeFactorial)(n - 1)
              }
            }
          }
        )(n - 1)
    }
  })(0)
</code></pre>
<p>Does this seem familiar?</p>
<ul>
<li>Yeah, its the same structure that we started with, applied to a smaller input</li>
</ul>
<pre><code class="language-javascript">1 * reducedStructure(0)
</code></pre>
<ul>
<li>Since we already established that <code>reducedStructure(0)</code> evaluates to <code>1</code>, we can conclude that <code>reducedStructure(1)</code> evaluates to <code>1 * 1 =&gt; 1</code></li>
</ul>
<p>Can you try evaluating the same for input n = 2?
(Please try this on paper)</p>
<p>Did you actually do it?</p>
<ul>
<li>Yes, it seems that no new structures appear and it self replicates until it reaches the base case at which point recursion ends and we get the output</li>
</ul>
<p>Did we cook recursion at home?</p>
<ul>
<li>
<p>Yes, yes we did, YAYYYY</p>
</li>
<li>
<p>But can we do this for any recursive pattern instead of just factorial?</p>
</li>
</ul>
<p>Yes, I recommend you check out <a href="https://mitpress.mit.edu/9780262560993/the-little-schemer/">The Little Schemer</a>. Thank you Daniel P. Friedman and Matthias Felleisen</p>
<p>Is everything a function?</p>
<ul>
<li>Always has been</li>
</ul>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[In Place Quick Sort]]></title>
            <link>https://ysuraj.com/in-place-quick-sort</link>
            <guid isPermaLink="false">https://ysuraj.com/in-place-quick-sort</guid>
            <pubDate>Sat, 06 Sep 2025 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<ul>
<li>Do you know Quicksort?</li>
</ul>
<p>Yes I do, because I am recursion God who has cracked the <code>Y Combinator</code> thanks to <code>The Little Schemer</code> but lets hope no one asks me that in an interview.</p>
<p>Also here’s my quicksort implementation.</p>
<pre><code class="language-python">def quicksort(array):
	if len(array) &lt;= 1:
		return array
	# use last element as pivot
	pivot = array[-1]
	# assuming no duplicates
	left = [x for x in array if x &lt; pivot]
	right = [y for y in array if y &gt; pivot]
	return quicksort(left) + [pivot] + quicksort(right)
</code></pre>
<p>But people squint at me and accuse me of using extra memory.</p>
<ul>
<li>How do you respond to those people?</li>
</ul>
<p>I take a deep breath and pull out my whiteboard and scribble IN PLACE QUICKSORT</p>
<ul>
<li>How would you do it “in place”?</li>
</ul>
<p>Since this requires partitioning, I suppose we could partition the array in place into 2 parts and recursively sort the partitions in place.</p>
<ul>
<li>How would you partition it?</li>
</ul>
<p>I guess we could split the array into 2 partitions by having 1 boundary. We can traverse the array and move <code>items &lt; pivot</code> to the left side of the partition, and naturally the only items in the right partition will be <code>items &gt; pivot</code>, assuming there are no duplicates going further.</p>
<ul>
<li>How would you move the items in place?</li>
</ul>
<p>Easy, Swap them.</p>
<ul>
<li>Can I see an example?
Sure, I am a visual learner so here you go.</li>
</ul>
<pre><code>[ 7 2 1 8 6 3 5 4 ]
</code></pre>
<p>Considering the last item as pivot(More on that later), we can partition the array as left having 0 items.</p>
<pre><code>[ ][ 7 2 1 8 6 3 5 ] 4
     ^               ^
</code></pre>
<p>Since <code>7 &gt; 4</code>, 7 can stay on the right partition</p>
<pre><code>[ ][ 7 2 1 8 6 3 5 ] 4
      ^             ^
</code></pre>
<p><code>2 &lt; 4</code>, we can move it to the left partition</p>
<pre><code>[ 2 ][ 7 1 8 6 3 5 ] 4
         ^           ^
</code></pre>
<p>The first iteration of quicksort will result in the following array</p>
<pre><code>[ 2 1 3 ][ 7 8 6 5 ] 4
</code></pre>
<ul>
<li>But how do you do swaps?</li>
</ul>
<p>I guess we could maintain an index as boundary. At the beginning, since we don’t have any items on the left we can use 0 as the boundary. So for the first item &lt; pivot with index, we would swap out item[index] and item[boundary]</p>
<pre><code class="language-python">array = [...]
def inplace_quicksort(...):
	...
	boundary = 0
	# use last element as pivot
	pivot = array[-1]
	# iterate till second last element
	for index in range(len(array) - 2):
		item = array[index]
		if item &lt; pivot:
			array[boundary], array[index] = array[index], array[boundary]
	...
</code></pre>
<ul>
<li>Where does boundary lie, in the left or right partition?</li>
</ul>
<p>Right</p>
<ul>
<li>What if the first element &lt; pivot and thus needs to be in the left partition?</li>
</ul>
<p>No worries, we iterate from the beginning that would result in the same swap. No harm done.</p>
<ul>
<li>Can you code that up?</li>
</ul>
<pre><code class="language-python">array = [23, 87, 5, 99, 42]

def inplace_quicksort(left, right):
	global array
	if left &gt; right:
		return
	if right - left + 1 &lt;= 1:
		return
	# use last element as pivot
	pivot = array[right]
	boundary = left
	# iterate till second last element
	for index, item in enumerate(array[left:right]):
		index = left + index
		if item &lt; pivot:
			array[boundary], array[index] = array[index], array[boundary]
			boundary = boundary + 1
	inplace_quicksort(left, boundary - 1)
	inplace_quicksort(boundary, right - 1)
	# place pivot in between left &amp; right partitions
	# by shifting it from extreme right to the boundary position
	while right &gt; boundary:
		array[right], array[right - 1] = array[right - 1], array[right]
		right = right - 1
</code></pre>
<ul>
<li>Does pivot always has to be the last item?</li>
</ul>
<p>No, we can use any random item from the array as pivot. Although, a good pivot partitions left and right equally.</p>
<ul>
<li>How can I get the best pivot?</li>
</ul>
<p>Finding the med…
<a href="https://stackoverflow.com/questions/164163/quicksort-choosing-the-pivot">https://stackoverflow.com/questions/164163/quicksort-choosing-the-pivot</a> here you go.</p>
<ul>
<li>Are you a god?</li>
</ul>
<p>I might be.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bits by Bits]]></title>
            <link>https://ysuraj.com/bits-by-bits</link>
            <guid isPermaLink="false">https://ysuraj.com/bits-by-bits</guid>
            <pubDate>Sun, 09 Jun 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Bits by Bits</h1>
<p><strong>What is a bit?</strong></p>
<p>A bit can be <code>1</code> or <code>0</code></p>
<p><strong>What are bits?</strong></p>
<p>A sequence of bits. <code>10110100</code></p>
<p><strong>Can we only have 8 bits at a time?</strong></p>
<p>No, we can have infinite length of bits</p>
<p><strong>What is bit size of  <code>10110100</code>?</strong></p>
<p>8, since it has 8 bits</p>
<p><strong>What do bits represent?</strong></p>
<p>Bits can be <code>set</code> ie <code>1</code> or <code>unset</code> ie <code>0</code></p>
<h1>OPERATIONS</h1>
<p><strong>Can we toggle bits from set to unset and vice versa?</strong></p>
<p>Yes we can. Thanks <code>NOT</code> operation</p>
<p><strong>What is NOT of <code>10110100</code>?</strong></p>
<p><code>01001011</code></p>
<p><strong>Is there a shorthand for <code>NOT OPERATION</code>?</strong></p>
<p>Yes, there is. <code>~</code>. <code>~10110100</code> = <code>01001011</code></p>
<p><strong>What are other ways we can combine 2 bits?</strong></p>
<p>We can set the result bit if and only if both the bits are set. Thanks <code>AND</code> Operation.</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Bits A</td>
<td>1</td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
<td>1</td>
<td><strong>1</strong></td>
<td>1</td>
</tr>
<tr>
<td>Bits B</td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td>1</td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
</tr>
<tr>
<td>Result</td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
</tr>
</tbody>
</table>
<p><strong>Is there a shorthand for <code>AND OPERATION</code>?</strong></p>
<p>Yes, there is. <code>&amp;</code>. <code>11010111 &amp; 01011010</code> = <code>01010010</code></p>
<p><strong>Can we set a bit if either of the bits are set?</strong></p>
<p>Yes, thanks <code>OR</code> Operation</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Bits A</td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td>0</td>
</tr>
<tr>
<td>Bits B</td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td>0</td>
</tr>
<tr>
<td>Result</td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td>0</td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td>0</td>
</tr>
</tbody>
</table>
<p><strong>Is there a shorthand for <code>OR OPERATION</code>?</strong></p>
<p>Yes, there is. <code>|</code>. <code>11010110 | 01011010</code> = <code>11011110</code></p>
<p><strong>Can we set a bit if and only if both the bits are different?</strong></p>
<p>Yes, thanks <code>Exclusive Or</code>(<code>XOR</code>) Operation</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Bits B</td>
<td><strong>0</strong></td>
<td>1</td>
<td>0</td>
<td>1</td>
<td><strong>1</strong></td>
<td><strong>0</strong></td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>Result</td>
<td><strong>1</strong></td>
<td>0</td>
<td>0</td>
<td>0</td>
<td><strong>1</strong></td>
<td><strong>1</strong></td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Bits A</td>
<td><strong>1</strong></td>
<td>1</td>
<td>0</td>
<td>1</td>
<td><strong>0</strong></td>
<td><strong>1</strong></td>
<td>1</td>
<td>0</td>
</tr>
</tbody>
</table>
<p><strong>How about shifting bits left or right?</strong></p>
<p>Yes, thanks to <code>LEFT SHIFT</code> and <code>RIGHT SHIFT</code> Operations</p>
<p>Shifting <code>11010110</code> left by 1 = <code>10101100</code></p>
<p>Shifting <code>11010110</code> right by 1 = <code>01101011</code></p>
<p><strong>How can we shift 2 bits to left for <code>11010110</code>?</strong></p>
<p>We can drop left 2 bits and pad right 2 bits by <code>0</code></p>
<p><strong>How about shifting right 2 bits?</strong></p>
<p>We can drop right 2 bits and pad left 2 bits by <code>0</code></p>
<p><strong>Are there shorthands for <code>LEFT SHIFT</code> and <code>RIGHT SHIFT</code>?</strong></p>
<p>Yes, <code>LEFT SHIFT</code> is <code>&lt;&lt;</code> and <code>RIGHT SHIFT</code> is <code>&gt;&gt;</code></p>
<p>Shifting <code>11010110</code> left by 1 = <code>11010110 &lt;&lt; 1</code> = <code>10101100</code></p>
<p>Shifting <code>11010110</code> right by 1 = <code>11010110 &gt;&gt; 1</code> = <code>01101011</code></p>
<h1>BIT MASKS</h1>
<p><strong>What is a bit mask?</strong></p>
<p>A bit mask is a bit pattern. <code>1</code>s in the mask defines the bits we want to keep and <code>0</code>s we want to discard</p>
<p><strong>What does this bit mask represent <code>00010000</code>?</strong></p>
<p>It preserves the 5th bit from right and discards the rest</p>
<p><strong>How can we get the 5th bit of a bit pattern?</strong></p>
<p>By using a bit mask which preserves the 5th bit</p>
<p><strong>How do we use this bit mask on a bit pattern?</strong></p>
<p>Lets solve this issue for a simple case for the bit pattern <code>1</code></p>
<p><strong>How can I check if the bit is set or unset?</strong></p>
<p>By using the bit mask <code>1</code></p>
<p><strong>How do I use the bit mask <code>1</code> on bit pattern <code>1</code> to get the first bit?</strong></p>
<p>By using <a href="#what-are-other-ways-we-can-combine-2-bits"><code>AND</code></a> operation</p>
<p><strong>So, how would we get the 5th bit of a bit pattern?</strong></p>
<p>By <code>BIT_PATTERN &amp; 00010000</code></p>
<p><strong>How would we know if the 5th bit is set using the above operation?</strong></p>
<p>If any of the bit is set, it means the 5th bit is set</p>
<p><strong>Is there any other way to achieve the same result?</strong></p>
<p>We could use bit shifts</p>
<p><strong>And how would we do that?</strong></p>
<ul>
<li>By <a href="#how-about-shifting-bits-left-or-right">shifting</a> 5th bit to the 1st position and apply <code>AND</code> with <code>1</code></li>
</ul>
<p><code>(BIT_PATTERN &gt;&gt; 4) &amp; 1</code></p>
<p><strong>Can we generalize it?</strong></p>
<p><code>NTH_BIT = (BIT_PATTERN &gt;&gt; (n - 1)) &amp; 1</code></p>
<p><strong>How can we set the 5th bit?</strong></p>
<p><strong>How can we toggle the 5th bit?</strong></p>
<p><strong>How can we compose bit masks?</strong></p>
<p>By using <a href="#can-we-set-a-bit-if-either-of-the-bits-are-set">OR</a></p>
<p><strong>How can we subtract bit masks?</strong></p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Testing Recipes]]></title>
            <link>https://ysuraj.com/react-testing-recipes</link>
            <guid isPermaLink="false">https://ysuraj.com/react-testing-recipes</guid>
            <pubDate>Sat, 11 Feb 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>You want to setup jest</h2>
<h3>A minimal config</h3>
<p><em>jest.config.js</em></p>
<pre><code class="language-javascript">module.exports = {
 transform: {
   "^.+\\.jsx?$": `&lt;rootDir&gt;/jest-preprocess.js`,
 },
 moduleNameMapper: {
   '^.+\\.(css|style|less|sass|scss)$': 'identity-obj-proxy',
 },
 transformIgnorePatterns: [ '!node_modules/',],
 testEnvironmentOptions: {
   url: `http://localhost`,
 },
}
</code></pre>
<h4>Further Reading</h4>
<ul>
<li>Jest configuration docs
<ul>
<li><a href="https://jestjs.io/docs/configuration">https://jestjs.io/docs/configuration</a></li>
</ul>
</li>
<li><code>identity-obj-proxy</code> docs
<ul>
<li><a href="https://github.com/keyz/identity-obj-proxy">https://github.com/keyz/identity-obj-proxy</a></li>
</ul>
</li>
</ul>
<p><em>jest.preprocess.js</em></p>
<pre><code class="language-javascript">const babelOptions = {
  // your babel config goes here
};

module.exports = require('babel-jest').default.createTransformer(babelOptions);
</code></pre>
<h4>Further Reading</h4>
<ul>
<li>Babel docs
<ul>
<li><a href="https://babeljs.io/docs/en/presets/">https://babeljs.io/docs/en/presets/</a></li>
<li><a href="https://babeljs.io/docs/en/plugins">https://babeljs.io/docs/en/plugins</a></li>
</ul>
</li>
</ul>
<h3>You want coverage reports</h3>
<p><em>jest.config.js</em></p>
<pre><code class="language-javascript">module.exports = {
...
 collectCoverage: true,
 coverageDirectory: 'coverage',
 reporters: ['default', ['jest-junit', { outputDirectory: 'reports' }]],
...
}
</code></pre>
<h4>Further reading</h4>
<ul>
<li>Reporters
<ul>
<li><a href="https://jestjs.io/docs/configuration#reporters-arraymodulename--modulename-options">https://jestjs.io/docs/configuration#reporters-arraymodulename--modulename-options</a></li>
</ul>
</li>
</ul>
<h3>You want to enable/add path alias support</h3>
<p><em>jest.config.js</em></p>
<pre><code class="language-javascript">const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./jsconfig.json'); // or tsconfig.json

const paths = pathsToModuleNameMapper(compilerOptions.paths, {
  prefix: '&lt;rootDir&gt;/',
});

module.exports = {
...
    moduleNameMapper: {
        ...paths,
        // other path aliases you want to add manually
    }
    ...
}
</code></pre>
<h3>Your project uses other file extensions ie svg/gql/…</h3>
<p>You need transformers
Here’s how you would add transformers for <code>.gql</code> &amp; <code>.svg</code> files. You will need to add them as dev dependencies.</p>
<p><em>jest.config.js</em></p>
<pre><code class="language-javascript">module.exports = {
...
  transform: {
    '\\.(gql|graphql)$': '@graphql-tools/jest-transform',
    '^.+\\.svg$': 'jest-transformer-svg',
    ...
  },
...}
</code></pre>
<h4>Further Reading</h4>
<ul>
<li>Transformers
<ul>
<li><a href="https://jestjs.io/docs/code-transformation">https://jestjs.io/docs/code-transformation</a></li>
</ul>
</li>
</ul>
<h3>Setup file</h3>
<ul>
<li>Why you need this?
<ul>
<li>When you have Provider wrappers in your app ie <code>SnackbarProvider</code>, <code>ThemeProviders</code>, you might need to setup a custom render function which automatically wraps your Component to be tested with the necessary wrappers.</li>
</ul>
</li>
</ul>
<p><em>jest.setup.js</em></p>
<pre><code class="language-javascript">import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect'; // needed for assertions
import React from 'react';
import { render } from '@testing-library/react';
// import all your Providers here

const AllTheProviders = ({ children }) =&gt; {
  return &lt;Provider&gt;{children}&lt;/Provider&gt;;
};

const customRender = (ui, options) =&gt;
  render(ui, { wrapper: AllTheProviders, ...options });

export * from '@testing-library/react';

export { customRender as render };
</code></pre>
<h2>You want to run jest</h2>
<pre><code class="language-bash">npx jest
</code></pre>
<p>Add it as a script to <code>package.json</code>
<em>package.json</em></p>
<pre><code class="language-json">{
  "scripts": {
    "test": "jest"
  }
}
</code></pre>
<h3>Further Reading</h3>
<ul>
<li>Jest CLI options
<ul>
<li><a href="https://jestjs.io/docs/cli">https://jestjs.io/docs/cli</a></li>
</ul>
</li>
</ul>
<h2>You want to see how tests are written?</h2>
<ul>
<li><a href="https://www.youtube.com/@Codevolution">Codevolution</a>
<ul>
<li><a href="https://www.youtube.com/watch?v=T2sv8jXoP4s&amp;list=PLC3y8-rFHvwirqe1KHFCHJ0RqNuN61SJd">React Testing Tutorial</a></li>
</ul>
</li>
<li><a href="https://www.youtube.com/@NetNinja">The Net Ninja</a> &amp; <a href="https://www.youtube.com/channel/UCyLNhHSiEVkVwPSFKxJAfSA">Laith Academy</a>
<ul>
<li><a href="https://www.youtube.com/watch?v=7dTTFW7yACQ&amp;list=PL4cUxeGkcC9gm4_-5UsNmLqMosM-dzuvQ">React Testing Library Tutorial</a></li>
</ul>
</li>
</ul>
<h2>While testing</h2>
<h3>You want to test Apollo graphql</h3>
<ul>
<li>Here’s how to set it up
<ul>
<li><a href="https://www.apollographql.com/docs/react/development-testing/testing/">https://www.apollographql.com/docs/react/development-testing/testing/</a></li>
</ul>
</li>
<li>Here’s a really neat way to set it up along with preliminary debugging
<ul>
<li><a href="https://www.swarmia.com/blog/debugging-apollo-graphql-mockedprovider/">https://www.swarmia.com/blog/debugging-apollo-graphql-mockedprovider/</a></li>
</ul>
</li>
<li>Is there any way to make this easier?
<ul>
<li>I pass my <code>mocks</code> as second argument to the <code>render</code> function</li>
<li>I have a utility to create the mock request-response entity</li>
<li>Here’s how it looks like<pre><code class="language-javascript">const {...} = render(&lt;Component {...props}/&gt;, MakeResponses({
  'query-name': {
    params: // query params go here,
    data: // response goes here
  },
  ...
}))
</code></pre>
</li>
</ul>
</li>
</ul>
<h3>You want to simulate browser events - Click/Change/…</h3>
<ul>
<li><a href="https://www.pluralsight.com/guides/simulate-browser-events-react-react-testing-library">https://www.pluralsight.com/guides/simulate-browser-events-react-react-testing-library</a></li>
</ul>
<h3>You are facing <code>SOME_ENV_VAR</code> not defined</h3>
<p>You can define global variables by
<em>jest.config.js</em></p>
<pre><code class="language-javascript">module.exports = {
  ...,
  globals: {
    ENV_VAR_NAME: VALUE
  },
  ...
}
</code></pre>
<h4>Further Reading</h4>
<ul>
<li>Globals Object
<ul>
<li><a href="https://jestjs.io/docs/configuration#globals-object">https://jestjs.io/docs/configuration#globals-object</a></li>
</ul>
</li>
</ul>
<h2>You want to mock</h2>
<h3>You want to mock a npm dependency</h3>
<p>If the dependency is a commonjs module, you can do</p>
<pre><code class="language-javascript">jest.mock('dependency', () =&gt; ({
  default: jest.fn(),
}));
</code></pre>
<p>Assuming the dependency is exported as default</p>
<ul>
<li>For named exports, you can do</li>
</ul>
<pre><code class="language-javascript">jest.mock('dependency', () =&gt; ({
  namedExportedFunction: jest.fn(),
}));
</code></pre>
<ul>
<li>If the dependency is es6 module, you can do</li>
</ul>
<pre><code class="language-javascript">jest.mock('dependency', () =&gt; ({
  __esModule: true,
  default: jest.fn(),
  namedExportedFunction: jest.fn(),
}));
</code></pre>
<h4>Further Reading</h4>
<ul>
<li>Jest Mocks
<ul>
<li><a href="https://jestjs.io/docs/mock-functions">https://jestjs.io/docs/mock-functions</a></li>
<li><a href="https://medium.com/@rickhanlonii/understanding-jest-mocks-f0046c68e53c">https://medium.com/@rickhanlonii/understanding-jest-mocks-f0046c68e53c</a></li>
</ul>
</li>
</ul>
<h3>You want to mock a Component</h3>
<p>For example,
You want to mock Route to bypass authentication.
Assuming you have the following folder structure and Route is the default export</p>
<pre><code>...
|-Route
  |- index.js
</code></pre>
<p>You can add the Route mock at <code>Route/__mocks__/index.js</code></p>
<p><em>Route/<strong>mocks</strong>/index.js</em></p>
<pre><code class="language-javascript">function MockRoute({children}) {
  return (
    &lt;&gt;{children}&lt;/&gt;
  );
};
</code></pre>
<p>Route can be automatically mocked by placing the following snippet in your test file</p>
<pre><code class="language-javascript">jest.mock('path/to/Route');
</code></pre>
<h3>You want to mock a Context</h3>
<p>AuthProvider has the following state</p>
<pre><code class="language-javascript">const AuthContext = React.createContext({
  user: null,
  login: () =&gt; {},
  logout: () =&gt; {},
});
</code></pre>
<p>You can mock AuthProvider by
<em>AuthProvider/<strong>mocks</strong>/index.js</em></p>
<pre><code class="language-javascript">const AuthContext = React.createContext();
const AuthState = {
  user: null,
  login: jest.fn(),
  logout: jest.fn(),
};

export default function AuthProvider(){
  return (&lt;AuthContext.Provider value={{
    user: null,
    login: () =&gt; {},
    logout: () =&gt; {},
  }}&gt;
    {children}
  &lt;/AuthContext.Provider&gt;);
}
</code></pre>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Trackball Journey]]></title>
            <link>https://ysuraj.com/my-trackball-journey</link>
            <guid isPermaLink="false">https://ysuraj.com/my-trackball-journey</guid>
            <pubDate>Sat, 21 Jan 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>How?</h2>
<p>The day I started working out my arms were fucked for some days and I thought it was ergonomics.</p>
<h2>Why trackball?</h2>
<p>In the thrill of trying something new, on the <code>10th of January 2023</code> my lizard brain bought a <code>Logitech Ergo M575</code> because trackballs are better than mice for health.</p>
<p><img src="https://resource.logitech.com/w_692,c_limit,q_auto,f_auto,dpr_1.0/d_transparent.gif/content/dam/logitech/en/products/mice/ergo-m575/gallery/ergo-m575-gallery-graphite-1-new.png?v=1" alt="Logitech M575" /></p>
<h2>How is it different from a traditional mouse?</h2>
<p>This is a thumb trackball mouse. The other variant of trackball mice are finger trackballs.</p>
<p><img src="https://cdn.shopify.com/s/files/1/1123/7482/products/BlackBall-WhiteBackground1a_540x.jpg?v=1639593799" alt="Gameball" /></p>
<p>Finger trackballs look better for precision relative to thumb trackballs but thats just from watching people playing with it on youtube.</p>
<h2>How have I been using it?</h2>
<p>I use my trackball for both gaming and work.
When I am gaming, the trackball stays on the usual position ie right side of the keyboard.
When I am working, it stays below the keyboard because its better for me to move from home row toward myself.</p>
<p><img src="./images/Trackball_placement.jpg" alt="Trackball placement" /></p>
<p>I have a 45 degree tent for the trackball so my palm is at around 90 degrees from the tray.</p>
<p><img src="./images/Tent.jpg" alt="Trackball tent" /></p>
<h3>Have I been using acceleration?</h3>
<p>Yes, I use Jump acceleration. No I do not know the difference between the types of acceleration but Jump feels the best for me. I use rawaccel for acceleration settings. I haven’t setup acceleration on linux yet.
Most of the trackballers in the community use acceleration as well.</p>
<h3>Whats the curve?</h3>
<p><img src="./images/Curve.png" alt="Acceleration curve" /></p>
<h2>What is my conclusion for now?</h2>
<p>For work, its the best for me as a programmer. Its good for productivity and certain types of games where you don’t need reflexes. I had alot of fun on this playing Civilization.</p>
<h2>What am I looking upto next?</h2>
<p>I am going to play games on this thing for a while and record my observations.
I am also going to buy a finger trackball soon so I can play better.</p>
<h2>Do I have a youtube channel where I play with the trackball?</h2>
<p><a href="https://www.youtube.com/@jarusll">Jarusll</a></p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Discoverability in Codebase]]></title>
            <link>https://ysuraj.com/discoverability</link>
            <guid isPermaLink="false">https://ysuraj.com/discoverability</guid>
            <pubDate>Thu, 04 Aug 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Discoverability in Codebase</h1>
<h2>What is it?</h2>
<p>Code discoverability is how easy it is for a developer to find existing functionalities and dependent functionalities.</p>
<h2>How to rate discoverability</h2>
<ul>
<li>How easy is to traverse indirections?</li>
<li>How declarative is the business logic?
<ul>
<li>Declarative code describes “what” as opposed to imperative code which describes “how”. It describes the code intent closer to business logic.</li>
</ul>
</li>
</ul>
<h2>How to achieve it?</h2>
<h3>Code Browsers</h3>
<p>Code browsers index all the primitive components of codebase. It could be Classes or functions or any abstraction provided by the language.
Some of the best code browsers I’ve used are the</p>
<h4>Pharo’s system browser</h4>
<p><img src="https://files.pharo.org/web-images/carousel/navigation.gif" alt="" /></p>
<p><em>Credit - <a href="https://files.pharo.org/">https://files.pharo.org/</a></em></p>
<h4>Eclipse’s Java browsing perspective</h4>
<p><img src="https://querix.com/go/beginner/Content/Resources/Images/05_workbench/01_ls/02_interface/01_perspectives/java/java_browsing_perspective_00_thumb_600_0.png" alt="" /></p>
<p><em>Credit <a href="https://querix.com/">https://querix.com/</a></em></p>
<h4>Visual Studio’s object browser</h4>
<p><img src="https://matthiasfriedrich.gallerycdn.vsassets.io/extensions/matthiasfriedrich/visualbasictoolsforvisualstudio/1.6.6/1505850909956/151077/1/object-browser.png" alt="" /></p>
<p><em>Credit - <a href="https://matthiasfriedrich.gallerycdn.vsassets.io">https://matthiasfriedrich.gallerycdn.vsassets.io</a></em></p>
<p>Edit: 19/02/2023</p>
<h3>Outliners</h3>
<h4>VSCode’s Outline view</h4>
<p>I heavily use the outline view to have a birds eye on the file although its not as beneficial in React</p>
<h3>Regex</h3>
<p>Good’ol Grep/Ripgrep REGEX RULES!!!
Regex would be my last option along with data wrangling.</p>
<h3>Tag browser</h3>
<p>Tags generated by <code>ctags</code> can be used as well to navigate the codebase.</p>
<h3>Intuitive interfaces</h3>
<p>For functional programming It would be sensible function signatures like <a href="https://hoogle.haskell.org/">Hoogle</a>.</p>
<p>For OO It would be Interfaces. I believe you could search classes by receives and sends clause. Pharo’s supports this.</p>
<p>Here’s a <a href="https://news.ycombinator.com/item?id=32365660">thread</a> where I asked developers how they go about getting comfortable with a new codebase.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux Primer]]></title>
            <link>https://ysuraj.com/redux-primer</link>
            <guid isPermaLink="false">https://ysuraj.com/redux-primer</guid>
            <pubDate>Fri, 10 Jun 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Redux Primer</h1>
<p><strong>What do you start with?</strong></p>
<h2>Actions</h2>
<p><strong>What are <code>Actions</code>?</strong></p>
<ul>
<li>User interactable actions</li>
<li>Events in the application logic</li>
</ul>
<p><strong>What does an action look like?</strong></p>
<p>Its a javascript object</p>
<pre><code class="language-json">{
	"type": String,
	"payload": JSONValue
}
</code></pre>
<p>The <code>type</code> is a string constant typically representing an action name. The <code>payload</code> is the data associated with the action event</p>
<p>Eg</p>
<pre><code class="language-json">{
	"type": "ADD_POST",
	"payload": {
		"tags": ["primer"],
		"text": "What do you start with?..."
	}
}
</code></pre>
<p><strong>Would it be convenient if we had helper functions to create the action objects?</strong></p>
<p>Yes, they are called action creators</p>
<pre><code class="language-javascript">function addPost({tags, text}){
	return {
		type: "ADD_POST",
		payload: {
			tags,
			text
		}
	}
}
</code></pre>
<p><strong>Can we do better?</strong></p>
<p>Yes, <code>createAction</code>, thanks <code>@reduxjs/toolkit</code></p>
<pre><code class="language-javascript">const { createAction } = require('@reduxjs/toolkit')

addPost = createAction('ADD_POST')

addPost({tags: ["primer"], text: "What do you start with?..."})
	{
		type: 'ADD_POST',
		payload: {
			tags: [ 'primer' ],
			text: 'What do you start with?...'
		}
	}
</code></pre>
<p><strong>Whats the next step?</strong></p>
<h2>Reducers</h2>
<p><strong>What are reducers?</strong></p>
<p>Reducers manage your state using <code>prevstate</code> and <code>action</code> to give you <code>nextstate</code></p>
<p><code>PrevState + Action =&gt; NextState</code></p>
<p><strong>What do they look like?</strong></p>
<p>Here’s a trivial example of a reducer</p>
<pre><code class="language-javascript">let initialState = 0
function counterReducer(state = initialState, action){
	switch(action.type){
		case "INCREMENT":
			return state + 1
		case "DECREMENT":
			return state - 1
		default:
			return state
	}
}

counterReducer(10, {type: "INCREMENT"})
</code></pre>
<pre><code>11
</code></pre>
<p><strong>Can we do better?</strong></p>
<p>Yes, <code>createReducer</code>, thanks again <code>@reduxjs/toolkit</code></p>
<pre><code class="language-javascript">const { createReducer } = require('@reduxjs/toolkit')

let increment = createAction('counter/increment')
let decrement = createAction('counter/decrement')

initialState = 0
counterReducer = createReducer(initialState, (builder) =&gt; {
	builder
	.addCase(increment, (state, action) =&gt; state + 1)
	.addCase(decrement, (state, action) =&gt; state - 1)
})

counterReducer(10, increment())
</code></pre>
<pre><code>11
</code></pre>
<p><strong>Can we couple counter actions &amp; counter reducer for convenience?</strong></p>
<p>Yes, its called a <code>slice</code></p>
<p><strong>Why is it called slice?</strong></p>
<p>Because they are a slice of the global state</p>
<pre><code class="language-javascript">const { createSlice } = require('@reduxjs/toolkit')

initialState = 0
const counterSlice = createSlice({
	name: 'counter',
	initialState,
	reducers: {
		increment: (state) =&gt; state + 1,
		decrement: (state) =&gt; state - 1
	},
})

increment = counterSlice.actions.increment
counterReducer = counterSlice.reducer
counterReducer(10, counterSlice.actions.increment())

</code></pre>
<pre><code>11
</code></pre>
<p><em>From this point on, <code>reducers</code> and <code>slices</code> may be used interchangeably</em></p>
<p><strong>How to decide what reducers to make?</strong></p>
<p>Every reducer in the store(global state) is associated with a key</p>
<p>Eg - The value returned by <code>counterReducer</code> will be associated with key <code>count</code> in global state.</p>
<pre><code class="language-json">{
	"count": counterReducer
}
</code></pre>
<p>So one good way to figure out the reducers is by determining the states you will access.</p>
<p><strong>Whats the next part?</strong></p>
<h2>Store</h2>
<p><strong>Whats a store?</strong></p>
<p>The store is the global state</p>
<p><strong>How do you make a store?</strong></p>
<pre><code class="language-javascript">const { configureStore } = require('@reduxjs/toolkit')
const store = configureStore({
	reducer: {
		count: counterSlice.reducer
	}
})
</code></pre>
<p><strong>How do you change state?</strong></p>
<p>By dispatching actions</p>
<pre><code class="language-javascript">store.dispatch(increment())

{ type: 'counter/increment', payload: undefined }
</code></pre>
<p><strong>How do you access the state?</strong></p>
<pre><code class="language-javascript">store.getState()

{ count: 1 }
</code></pre>
<p><strong>Has <code>redux</code> come a long way?</strong></p>
<p>Yes, thanks <code>@reduxjs/toolkit</code></p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1D Peak finding]]></title>
            <link>https://ysuraj.com/peak-finding-1-d</link>
            <guid isPermaLink="false">https://ysuraj.com/peak-finding-1-d</guid>
            <pubDate>Fri, 10 Jun 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>1D Peak finding</h1>
<p><strong>What is a 1D peak?</strong></p>
<p>An element in a 1D array which is greater than its neighbour</p>
<p><strong>Which element has the least number of neighbours?</strong></p>
<p>A one without any, Singleton</p>
<p><strong>Is <code>7</code> a peak in <code>[7]</code>?</strong> – <code>Base case 1</code>**</p>
<p>Yes, an uncontested victory.</p>
<p><strong>Whats the peak in <code>[7, 8]</code>? – <code>Base case 2</code></strong></p>
<p><code>8</code>, max(array) if array has only 2 elements</p>
<p><strong>What the next element which has the least number of neighbours?</strong></p>
<p>Edges, since they have only 1 neighbour</p>
<p><strong>Is <code>7</code> a peak in <code>[7, 3, ...]</code>? – <code>Base case left edge</code></strong></p>
<p>Yes, since <code>7 &gt; 3</code></p>
<p><strong>Is <code>7</code> a peak in <code>[..., 3, 7]</code>? – <code>Base case right edge</code></strong></p>
<p>Yes</p>
<p><strong>Is <code>7</code> a peak in <code>[..., 3, 7, 4, ...]</code>? – <code>Base case mid</code></strong></p>
<p>Yes, <code>7 &gt; 3</code> and <code>7 &gt; 4</code></p>
<p><strong>Whats the peak in <code>[1, 2, 3, 4, 5]</code>, a strictly increasing array?</strong></p>
<p>5</p>
<p><strong>Whats the peak in <code>[5, 4, 3, 2, 1]</code>, a strictly decreasing array?</strong></p>
<p>5</p>
<p><strong>Whats the peak in <code>[5, 5, 5, 5, 5]</code>, a strictly leveled array?</strong></p>
<p>5</p>
<p><strong>Is <code>7</code> a peak in <code>[..., 3, 7, 9, ...]</code>?</strong></p>
<p>No, since <code>9 &gt; 7</code></p>
<p><strong>Where should we look for a peak next?</strong></p>
<p><code>[9, ...]</code>, since it has atleast 1 peak</p>
<p>Reason, for the array <code>[9, x, ...]</code></p>
<ul>
<li>Considering <code>x is less than 9</code>, in this case <code>9</code> is a peak</li>
<li>Considering <code>x is equal to 9</code>, in this case <code>9</code> is a peak</li>
<li>Considering <code>x is greater than 9</code>, then the slice <code>[x, ...]</code> contains the peak element – <code>Case right</code></li>
</ul>
<p><strong>Whats the peak in <code>[]</code>? – <code>Base Case 0</code></strong></p>
<p>None</p>
<p><strong>How about finding all the peaks?</strong></p>
<p>Can be done using the same code and complete search</p>
<pre><code>peak([...])
	[] =&gt; None -- Base case 0
	[x] =&gt; x -- Base case 1
	[a, b, ...] and a &gt;= b =&gt; a -- Base case start
	[..., y, z] and y &lt;= z =&gt; z -- Base case end
	[..., k, l, m, ...] and k &lt;= l and l &gt;= m =&gt; l -- Base case mid
	[..., k, l, m, ...] and k &gt;= l =&gt; peak([..., k]) -- case left
	[..., k, l, m, ...] and l &lt;= m =&gt; peak([m, ...]) -- case right
</code></pre>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximum subarray sum]]></title>
            <link>https://ysuraj.com/maximum-subarray-sum</link>
            <guid isPermaLink="false">https://ysuraj.com/maximum-subarray-sum</guid>
            <pubDate>Tue, 31 May 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>Maximum Subarray Sum</h2>
<p><strong>What is maximum subarray sum of <code>{}</code>?</strong></p>
<ul>
<li>0</li>
</ul>
<p><strong>What is maximum subarray sum of <code>{1}</code>?</strong></p>
<ul>
<li>1</li>
</ul>
<p><strong>What is maximum subarray sum of <code>{1, -2}</code>?</strong></p>
<ul>
<li>1, because including -2 will make the sum negative</li>
</ul>
<p><strong>What is the subarray sum of <code>{1}</code> in the considered array <code>{1, ...}</code>?</strong></p>
<ul>
<li>The sum of subarray <code>{1}</code> is 1</li>
</ul>
<p><strong>Assuming there is potential positive sum subarray head, should we include the subarray <code>{1}</code> in the array <code>{1, ...}</code>?</strong></p>
<ul>
<li>if we include <code>{1}</code>, it will bring the subarray sum up by <code>1</code></li>
<li>So yes</li>
</ul>
<p><strong>Should we include the first two elements <code>{1, -2}</code> for subarray sum in the array <code>{1, -2, ...}</code>?</strong></p>
<ul>
<li>The sum of the two elements is <code>-1</code></li>
<li>Assuming there is a potential positive sum subarray ahead, including the elements will bring down the sum by <code>1</code></li>
<li>So no</li>
</ul>
<p><strong>What about <code>{4, -3}</code> in the array <code>{4, -3, ...}</code>?</strong></p>
<ul>
<li>The sum of <code>{4, -3}</code> is <code>1</code>, so yes</li>
</ul>
<p><strong>What about <code>{4, -3}</code> in the array <code>{4, -3, 1}</code>?</strong></p>
<ul>
<li>If we do add the subarray sum <code>{4, -3}</code>, it will bring up the subarray sum of <code>{1}</code> by 1.</li>
<li>But clearly <code>4</code> is the maximum subarray sum</li>
<li>We need more clarity</li>
</ul>
<p><strong>What about <code>{4, -3}</code> in the array <code>{4, -3, 10}</code>?</strong></p>
<ul>
<li>If we do add the subarray sum <code>{4, -3}</code>, it will bring up the subarray sum of <code>{10}</code> by 1.</li>
<li>In this case, the subarray <code>{4, -3}</code> did help</li>
</ul>
<p><strong>How do we overcome this ambiguity?</strong></p>
<ul>
<li>By storing the subarray sum at every point in traversal</li>
</ul>
<p><strong>What is the maximum subarray sum for the following array?</strong></p>
<pre><code>|       |   |    |   |
|-------|---|----|---|
| Array | 4 | -3 | 1 |
</code></pre>
<ul>
<li>
<p>Starting with the first element, since its positive</p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-3</th>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p><code>4 + -3</code> = <code>1</code>. Since <code>1 &gt; 0</code>, we do not reset the sum</p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-3</th>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td>1</td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p><code>1 + 1</code> = <code>2</code>.</p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-3</th>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><strong>We have calculated all the subarray sums. <code>Max(4, 1, 2) = 4</code>. Hence the maximum subarray sum for <code>{4, -3, 1}</code> is 4</strong></p>
<p><strong>What about the array</strong></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Array</td>
<td>4</td>
<td>-5</td>
<td>3</td>
<td>-2</td>
<td>17</td>
</tr>
</tbody>
</table>
<ul>
<li>
<p>Same for first element</p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-5</th>
<th>3</th>
<th>-2</th>
<th>17</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p><code>4 + -5 = -1</code>. Since <code>-1 &lt; 0</code>, we reset the subarray sum to 0.</p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-5</th>
<th>3</th>
<th>-2</th>
<th>17</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td>-1</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p>Since sum has been reset, it’ll be <code>3</code> for <code>{3}</code></p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-5</th>
<th>3</th>
<th>-2</th>
<th>17</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td>-1</td>
<td>3</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p><code>3 + -2 = 1</code>, which can increase the sum of potential subarray ahead</p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-5</th>
<th>3</th>
<th>-2</th>
<th>17</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td>-1</td>
<td>3</td>
<td>1</td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p><code>1 + 17 = 18</code></p>
<table>
<thead>
<tr>
<th>Array</th>
<th>4</th>
<th>-5</th>
<th>3</th>
<th>-2</th>
<th>17</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subarray Sums</td>
<td>4</td>
<td>-1</td>
<td>3</td>
<td>1</td>
<td>18</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><strong><code>Max(4 , -1 , 3 ,  1 , 18) = 18</code>, Hence <code>18</code> is the maximum subarray sum</strong></p>
<p><strong>Is this better than 0(n<sup>2</sup>)?</strong></p>
<ul>
<li>Yes, because its linear. Thanks Kadane.</li>
</ul>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Next permutation]]></title>
            <link>https://ysuraj.com/next-permutation</link>
            <guid isPermaLink="false">https://ysuraj.com/next-permutation</guid>
            <pubDate>Mon, 30 May 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>Next Permutation</h2>
<p><strong>Do you know what a permutation is?</strong></p>
<p>Yes</p>
<p><strong>Can you tell the next lexicographic permutation for <code>{2, 1, 3}</code>?</strong></p>
<ul>
<li>No</li>
</ul>
<p><strong>What is the permutation of <code>{1, 2, 3}</code>?</strong></p>
<ul>
<li><code>{1, 2, 3}</code></li>
<li><code>{1, 3, 2}</code></li>
<li><code>{2, 1, 3}</code></li>
<li><code>{2, 3, 1}</code></li>
<li><code>{3, 1, 2}</code></li>
<li><code>{3, 2, 1}</code></li>
</ul>
<p><strong>What are the bounds of the above permutations?</strong></p>
<p>From <code>{1, 2, 3}</code>,strictly increasing to <code>{3, 2, 1}</code>,strictly decreasing.</p>
<p><strong>Can we say that a strictly decreasing arrangement has run out of its permutation?</strong></p>
<p>Yes</p>
<p><strong>What is the direction of making a permutation?</strong></p>
<p>From left to right</p>
<p><strong>Whats the direction of backtracking a permutation?</strong></p>
<p>From right to left</p>
<p><strong>Whats a strictly decreasing arrangement in <code>{1, 3, 2}</code> from end?</strong></p>
<ul>
<li><code>{3, 2}</code></li>
</ul>
<p><strong>Whats a strictly decreasing arrangement in <code>{2, 1, 3}</code> from end?</strong></p>
<ul>
<li>
<p><code>{3}</code></p>
<table>
<thead>
<tr>
<th>Arrangement</th>
<th>Vacant</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>{2, 1}</code></td>
<td><code>{3}</code></td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><strong>Have we run out of arrangements for <code>1</code>?</strong></p>
<p>Yes</p>
<p><strong>What should replace <code>1</code>?</strong></p>
<p>The next successor in the vacant pool</p>
<pre><code>| Arrangement | Vacant |
|-------------|--------|
| `{2, 3}`    | `{1}`  |
</code></pre>
<p><strong>What should the next step be?</strong></p>
<p>Appending sorted Vacant to the Arrangement because every new permutation starts sorted</p>
<pre><code>| Arrangement | Vacant |
|-------------|--------|
| `{2, 3, 1}` | `{}`   |
</code></pre>
<p><strong>Is <code>{2, 3, 1}</code> the next permutation after <code>{2, 1, 3}</code>?</strong></p>
<p>Yes</p>
<p><strong>Heres another, <code>{4, 6, 2, 3, 8, 5, 1}</code></strong></p>
<pre><code>| Arrangement             | Vacant |
|-------------------------|--------|
| `{4, 6, 2, 3, 8, 5, 1}` | `{}`   |
</code></pre>
<p><strong>Determining the strictly decreasing arrangement from end</strong></p>
<pre><code>| Arrangement               | Vacant |
|---------------------------|--------|
| `{4, 6, 2, 3, *8, 5, 1*}` | `{}`   |
</code></pre>
<p><strong>Moving the strictly decreasing to Vacant space</strong></p>
<pre><code>| Arrangement    | Vacant      |
|----------------|-------------|
| `{4, 6, 2, 3}` | `{8, 5, 1}` |
</code></pre>
<p><strong><code>3</code> has run out of its arrangements, its successor in Vacant space is <code>5</code>. Replacing <code>3</code> with <code>5</code></strong></p>
<pre><code>| Arrangement    | Vacant      |
|----------------|-------------|
| `{4, 6, 2, 5}` | `{8, 3, 1}` |
</code></pre>
<p><strong>Sorting Vacant space and appending to Arrangement</strong></p>
<pre><code>| Arrangement             | Vacant |
|-------------------------|--------|
| `{4, 6, 2, 5, 1, 3, 8}` | `{}`   |
</code></pre>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Middle of Linked List]]></title>
            <link>https://ysuraj.com/middle-of-linked-list</link>
            <guid isPermaLink="false">https://ysuraj.com/middle-of-linked-list</guid>
            <pubDate>Sun, 29 May 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>Middle of Linked list</h2>
<p><strong>In the list <code>1-&gt;2-&gt;3-&gt;4-&gt;5</code>, <code>S</code> and <code>F</code> point to 1. What are <code>S</code> and <code>F</code> when <code>S</code> moves by 1 element and <code>F</code> moves by 2 elements?</strong></p>
<ul>
<li><code>S</code> is slow pointer and <code>F</code> is fast pointer</li>
</ul>
<p><strong>Will <code>S</code> travel half the distance of <code>F</code> at any given point?</strong></p>
<ul>
<li>Yes, since <code>F</code> is twice as fast as <code>S</code></li>
</ul>
<p><strong>Will <code>S</code> be at middle of list when <code>F</code> is at the end?</strong></p>
<ul>
<li>Yes</li>
</ul>
<p><strong>Do we have our base case and reduction case?</strong></p>
<ul>
<li>Yes we do</li>
</ul>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate Permutations]]></title>
            <link>https://ysuraj.com/generate-permutations</link>
            <guid isPermaLink="false">https://ysuraj.com/generate-permutations</guid>
            <pubDate>Sat, 28 May 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h2>What is a permutation?</h2>
<p><strong>What is the permutation of <code>{ }</code>?</strong></p>
<p><code>{ }</code></p>
<p><strong>What is the permutation of <code>{1}</code>?</strong></p>
<p><code>{1}</code></p>
<p><strong>What is the permutation of <code>{1, 2}</code>?</strong></p>
<ul>
<li><code>{1, 2}</code></li>
<li><code>{2, 1}</code></li>
</ul>
<p><strong>What is the permutation of <code>{1, 2, 3}</code>?</strong></p>
<ul>
<li><code>{1, 2, 3}</code></li>
<li><code>{1, 3, 2}</code></li>
<li><code>{2, 1, 3}</code></li>
<li><code>{2, 3, 1}</code></li>
<li><code>{3, 1, 2}</code></li>
<li><code>{3, 2, 1}</code></li>
</ul>
<p><strong>Which of them start with <code>1</code>?</strong></p>
<ul>
<li><code>{1, 2, 3}</code></li>
<li><code>{1, 3, 2}</code></li>
</ul>
<p><strong>What are the rest of these elements?</strong></p>
<ul>
<li><code>{2, 3}</code></li>
<li><code>{3, 2}</code></li>
</ul>
<p><strong>Do they resemble something?</strong></p>
<ul>
<li>No</li>
</ul>
<p><strong>What about the permutation of <code>{2, 3}</code>?</strong></p>
<ul>
<li>Yes</li>
</ul>
<p><strong>What is <code>append x</code> on <code>{y, z}</code>?</strong></p>
<ul>
    <li>{`{x, y, z}`}</li>
</ul>
<p><strong>What is <code>append x</code> on each of <code>{y, z}</code>?</strong></p>
<ul>
<li><code>{x, y}</code></li>
<li><code>{x, z}</code></li>
</ul>
<p><strong>Can we say the permutation of <code>{1, 2, 3}</code> = <code>{append 1 on each permutation of {2, 3}}, {append 2 on each permutation of {1, 3}}, {append 3 on each permutation of {1, 2}}</code>?</strong></p>
<ul>
<li>That’s a mouthful.</li>
</ul>
<p><strong>What is <code>{append 1 on each permutation of {2, 3}}</code>?</strong></p>
<ul>
<li><code>{append 1 on each permutation of {2, 3}}</code></li>
<li><code>{append 1 on each {{2, 3}, {3, 2}}}</code></li>
<li><code>{{1, 2, 3}, {1, 3, 2}}</code></li>
</ul>
<p><strong>What about <code>{append 2 on each permutation of {1, 3}}</code> and <code>{append 3 on each permutation of {1, 2}}</code>?</strong></p>
<ul>
<li><code>{{2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}</code></li>
</ul>
<p><strong>What do we get when we combine them all?</strong></p>
<ul>
<li><code>{{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}</code></li>
<li>i.e., <code>permutation of {1, 2, 3}</code></li>
</ul>
<p><strong>Do you know what a permutation is now?</strong></p>
<ul>
<li>Yes</li>
</ul>
<p><strong>Did you have fun?</strong></p>
<ul>
<li>Go have some cookies.</li>
</ul>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My mobile/tablets until now]]></title>
            <link>https://ysuraj.com/my-mobile-phones-until-now</link>
            <guid isPermaLink="false">https://ysuraj.com/my-mobile-phones-until-now</guid>
            <pubDate>Sat, 16 Apr 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>My mobile phones until now</h1>
<p>I have timestamped them with my school grades because I don’t remember exact years.</p>
<h2>Nokia 3310c</h2>
<ul>
<li>5th - 7th grade</li>
</ul>
<p><img src="https://3.allegroimg.com/s1024/0c4bb1/6aa36b5d483792bbbf8201a916e3" alt="Nokia 3310c" /></p>
<p><em>Credit</em> - <a href="https://archiwum.allegro.pl/oferta/nokia-3310c-plus-i7246256743.html">https://archiwum.allegro.pl/oferta/nokia-3310c-plus-i7246256743.html</a></p>
<p>My first ever personal phone. It was Java based. I rocked this for about 2 years. I played so many games on this thing. Some of the ones I can recall is Spiderman, Street fighter ripoffs, Tomb raider. And ofc bounce.</p>
<p>I used to spend hours downloading apps &amp; games. And it actually took time because I had to find the ones for my phones resolution. Yes, Apps came with their own resolution. And not only that, app compatibility wasn’t guaranteed. The only way to know it was to run it.
Some of the best apps I can recall for this phone are Facebook, Ebuddy, Opera Mini, UCBrowser. Gameloft games were big on Java.</p>
<h2>Samsung Corby Pro B5310</h2>
<ul>
<li>7th grade - 9th grade</li>
</ul>
<p>{/* FIXME corby <em>/}
{/</em> <img src="./images/corby.webp" alt="Samsung Corby Pro B5310" /> */}</p>
<p>*Credit - <a href="https://www.techspot.com/products/smartphones/samsung-gt-b5310-corby-pro-genio-slide.35659/">https://www.techspot.com/products/smartphones/samsung-gt-b5310-corby-pro-genio-slide.35659/</a></p>
<p>The first touch &amp; multitasking phone for me. I discovered that feature after a year. I din’t even know Java phones had multitasking. And ofcourse the slider keyboard.</p>
<p>Having this thing in my pocket I no longer felt like a boy, I was a grown up man.</p>
<h2>Nokia N91</h2>
<ul>
<li>9th grade - 10th grade</li>
</ul>
<p><img src="https://fdn.gsmarena.com/imgroot/news/19/12/flashback-nokia-n91/-727/gsmarena_002.jpg" alt="Nokia N91" /></p>
<p><em>Credit - <a href="https://www.gsmarena.com/flashbacknokian91-news-40659.php">https://www.gsmarena.com/flashbacknokian91-news-40659.php</a></em></p>
<p>My first Symbian phone. This was during when N95 was the coolest phone around. But I couldn’t get one so I got an N91.</p>
<p>This thing was a chonky boi. I learnt alot with this phone. I tried jailbreaking &amp; emulation. I used to emulate sega genesis &amp; doom on this. And if you rotated &amp; mapped the music buttons It actually felt like a handheld, just like N95.</p>
<p>This would be end of T9 layout for me.</p>
<h2>Samsung Galaxy Y GT-S5360</h2>
<ul>
<li>10th Grade</li>
</ul>
<p><img src="https://drop.ndtv.com/TECH/product_database/images/530201330723PM_635_samsung_galaxy_y.png?downsize=*:420&amp;output-quality=80" alt="Galaxy Y" /></p>
<p><em>Credit - <a href="https://gadgets360.com/samsung-galaxy-y-556">https://gadgets360.com/samsung-galaxy-y-556</a></em></p>
<p>My first Android phone. I explored rooting &amp; custom roms with it.</p>
<p>Installing Tablet roms on the small screen was fun.</p>
<h2>Iball Slide Tablet</h2>
<ul>
<li>10th grade - 12th grade</li>
</ul>
<p><img src="https://drop.ndtv.com/TECH/product_database/images/415201643705PM_635_iball_slide_co_mate.jpeg?downsize=*:420&amp;output-quality=80" alt="Iball Slide" /></p>
<p><em>Credit - <a href="https://gadgets360.com/iball-slide-co-mate-3439">https://gadgets360.com/iball-slide-co-mate-3439</a></em></p>
<p>My first tablet, I bought this to read. I only used this to read, didn’t really tinker around with it.
I read alot.</p>
<h2>Micromax Bolt A064</h2>
<ul>
<li>11th grade - 2nd year Uni</li>
</ul>
<p><img src="https://drop.ndtv.com/TECH/product_database/images/103201434000PM_635_micromax_bolt_ao64.jpeg?downsize=*:420&amp;output-quality=80" alt="Micromax Bolt A064" /></p>
<p><em>Credit - <a href="https://gadgets360.com/micromax-bolt-a064-2026">https://gadgets360.com/micromax-bolt-a064-2026</a></em></p>
<p>This was during the time When I got my first PC &amp; I lost interest with mobile tinkering.</p>
<p>I still tinkered with it with Xposed modules. This was the peak of android mods. I maximised my battery life with Greenify, Amplify. Customized my ui with XBlast, hide my details with XPrivacy.</p>
<h2>Vivo Y20</h2>
<ul>
<li>2nd year Uni - Current</li>
</ul>
<p><img src="https://fdn2.gsmarena.com/vv/pics/vivo/vivo-y20-2021-1.jpg" alt="Vivo Y20" /></p>
<p><em>Credit - <a href="https://www.gsmarena.com/vivoy202021-pictures-10658.php">https://www.gsmarena.com/vivoy202021-pictures-10658.php</a></em></p>
<p>I do not mess around with this phone. Its my daily driver &amp; I want stability. I do not care about launchers or battery life or performance because it has it all. I want things to just work and it does.</p>
<p>I plan to use it as long as I can. When I get another phone(which is not anytime soon), this will become my emulation phone. I’ll buy a telescopic controller &amp; play games on it.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cool emacs gifs site]]></title>
            <link>https://ysuraj.com/emacs-gifs</link>
            <guid isPermaLink="false">https://ysuraj.com/emacs-gifs</guid>
            <pubDate>Sun, 10 Apr 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Cool emacs gifs site</h1>
<p><a href="https://emacsgifs.github.io/">Cool emacs gifs</a></p>
<p>I plan to make something like this. Someday.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My list of Emacs packages]]></title>
            <link>https://ysuraj.com/my-list-of-emacs-packages</link>
            <guid isPermaLink="false">https://ysuraj.com/my-list-of-emacs-packages</guid>
            <pubDate>Fri, 08 Apr 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>My list of Emacs packages</h1>
<h2>magit</h2>
<p>The best git interface I’ve ever used. I cannot imagine using anything else but this for git.</p>
<h2>which-key</h2>
<p>Shows completion keybinds for incomplete keys. Gets you familiar with modes.</p>
<h2>ivy + ivy-rich</h2>
<p>Completion engine for emacs. Comes with rich observability features like</p>
<ul>
<li>Entities(command, function, variable…) docstring</li>
<li>Keybind of commands</li>
</ul>
<p>and much more features to make using the minibuffer easy.</p>
<h2>golden-ratio</h2>
<p>Automatically expands the window you switch to. Very big, split like crazy and stop caring.</p>
<h2>helpful</h2>
<p>A better *help* buffer. Just because its better.</p>
<h2>keycast</h2>
<p>A nice to have utility to see which commands are being executed.</p>
<p>There are other modes as well which I use, I only included utility packages here. You can check out my .emacs config <a href="https://github.com/jarusll/dotfiles/blob/master/.emacs" title=".emacs config ">here</a></p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatically resize focused emacs window to Golden ratio]]></title>
            <link>https://ysuraj.com/golden-ratio</link>
            <guid isPermaLink="false">https://ysuraj.com/golden-ratio</guid>
            <pubDate>Thu, 07 Apr 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Automatically resize focused emacs window to Golden ratio</h1>
<p><img src="https://camo.githubusercontent.com/475a4debfc2ae85201baf6b5eceb47693bf6e76267572b9f4db5003bc3753cef/68747470733a2f2f7261772e6769746875622e636f6d2f726f6d616e2f676f6c64656e2d726174696f2e656c2f6173736574732f676f6c64656e5f726174696f5f656c2e676966" alt="Golden Ratio" /></p>
<p>Golden Ratio - <a href="https://github.com/roman/golden-ratio.el">https://github.com/roman/golden-ratio.el</a></p>
<p>Says what it does, gets my thumbs up.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mechanical keyboard sounds]]></title>
            <link>https://ysuraj.com/mech-sounds</link>
            <guid isPermaLink="false">https://ysuraj.com/mech-sounds</guid>
            <pubDate>Wed, 06 Apr 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Mechanical keyboard sounds</h1>
<p><img src="https://camo.githubusercontent.com/064a15f8aa697f91aefae44c108b80e03c0a8bf4b3c4b9e78dabc385c2f106c5/68747470733a2f2f692e696d6775722e636f6d2f37387155554c412e6a7067" alt="MechVibes" /></p>
<p><a href="https://github.com/hainguyents13/mechvibes" title="MechVibes">MechVibes</a> is a cool program to emulate mechanical keyboard sounds.</p>
<p>Get here <a href="https://github.com/hainguyents13/mechvibes">MechVibes</a></p>
<p>I use for my youtube videos.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Show keybinds in minibuffer completions]]></title>
            <link>https://ysuraj.com/show-command-keybind-ivy</link>
            <guid isPermaLink="false">https://ysuraj.com/show-command-keybind-ivy</guid>
            <pubDate>Wed, 06 Apr 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Show keybinds in minibuffer completions</h1>
<h2>Prereq</h2>
<ul>
<li>ivy</li>
</ul>
<h2>Steps</h2>
<p>Enable <code>counsel-mode</code> in your init.el or .emacs by
<code>(counsel-mode 1)</code></p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What motivates me (I think)]]></title>
            <link>https://ysuraj.com/what-motivates-me-i-think</link>
            <guid isPermaLink="false">https://ysuraj.com/what-motivates-me-i-think</guid>
            <pubDate>Sun, 27 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>What motivates me (I think)</h1>
<p>2 things</p>
<ul>
<li>Variety</li>
<li>Speed</li>
</ul>
<h2>Variety</h2>
<p>I have noticed about myself that I like heterogeneity whether it comes to programming or food or games. They are like flavours I want to try and I want to try all of them. It helps me grow as an individual. Its the same reason why I tried Object oriented programming when I was a hardcore functional programmer, why I mix my food unevenly so that every bite will taste different and why I explore every part of the game so that I don’t miss out on an experience. Maybe its evolution playing that I am constantly on the hunt for something new.</p>
<h2>Speed</h2>
<p>This one’s easy, I just don’t want to be slow. I have very limited time and I want to be good at my art which means being efficient. I am speedrunning experiences. It could be as simple as navigating my computer to planning my future. Its the same reason I use <code>i3wm</code> and remap every shortcut I can utilize to make my life easier. Its the same reason why I try to overengineer and abstract my code to keep it lean.</p>
<p>It turns out that everything I do in my life tries to maximize variety and minimize time.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I made a public diary]]></title>
            <link>https://ysuraj.com/why-i-made-a-public-diary</link>
            <guid isPermaLink="false">https://ysuraj.com/why-i-made-a-public-diary</guid>
            <pubDate>Thu, 24 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Why I made a public diary</h1>
<p>I have kept things to myself all my life, because I found it hard to open up to people.
And that did not help. Communication is what makes us humans(probably).</p>
<p>I have definitely matured to open up.
Now, I try to be an open book. I want people to see me as me. I want them to know where I come from.</p>
<p>This diary will be my own corner. Also it’ll help me keep track of things.</p>
<p>Have a good one stranger.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A game which I will make(someday)]]></title>
            <link>https://ysuraj.com/a-game-which-i-will-make-someday</link>
            <guid isPermaLink="false">https://ysuraj.com/a-game-which-i-will-make-someday</guid>
            <pubDate>Sat, 19 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>A game which I will make(someday)</h1>
<h2>Motivation</h2>
<p>I have been playing a lot of Oracle in Dota. I like the fact that he’s a double edged sword.
The spell combos feel like a mini game itself and I think I can make a game out of it.</p>
<h2>Gameplay loop</h2>
<p>For those who don’t know Oracle’s spells, heres a quick introduction</p>
<h3>Fortune’s End</h3>
<p>A channeled ability which roots the enemy. Can be casted on enemy or ally. When casted on ally, purges all debuffs. When casted on enemy, purges all buffs.</p>
<h3>Fate’s Edict</h3>
<p>Can be casted on ally as well as enemy. When casted, it disarms &amp; saves the player from magic damage.</p>
<h3>Purifying Flames</h3>
<p>Can be casted on ally as well as enemy. It gives a burst damage and then heals overtime. The heal is greater than the damage given.</p>
<h3>False Promise</h3>
<p>Can be casted on ally. It delays all the damage and healing during False Promise and healing is doubled.</p>
<h2>Combos</h2>
<h3>Heal allies</h3>
<p>Cast Fate’s Edict to save from magical damage, stack them with Purifying Flames so they get healing without any damage.</p>
<h3>Punish enemies</h3>
<p>Cast Purifying Flames, wait for cooldown, Cast one more Purifying Flames quickly followed by Fortune’s End to purge healing.</p>
<h2>Mobs</h2>
<p>Since it comes from Dota, enemies will have both magic and pure damage.</p>
<h2>Surrounding World</h2>
<p>I haven’t decided on the world. I would probably make it like mario’s worlds.</p>
<h2>2D or 3D?</h2>
<p>2D, since I will be the only one making it.</p>
<h2>Monetization?</h2>
<p>NO, since its Valve’s IP.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your best friends in Emacs]]></title>
            <link>https://ysuraj.com/your-best-friends-in-emacs</link>
            <guid isPermaLink="false">https://ysuraj.com/your-best-friends-in-emacs</guid>
            <pubDate>Mon, 14 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Your best friends in Emacs</h1>
<p><strong>In emacs, You are either</strong></p>
<ul>
<li>Invoking a function through a key press</li>
<li>Invoking a function manually</li>
</ul>
<h2>Describe Mode<a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Modes.html">^emacs-modes</a> <code>C-h m</code></h2>
<p>Describe mode gives you a list of all enabled Minor modes, functions in the major mode &amp; all their key binds.</p>
<p>I skim through <code>describe-mode</code> the first time I am using a mode.
The functions are generally named as <code>namespace-like</code>-<code>action-like</code>-<code>something-else</code>.
I remember the pattern so I can type out these functions with some autocompletion engine<a href="https://www.reddit.com/r/emacs/comments/n40lk8/poll_whats_your_ideal_minibuffer_completion_ui">^completion-engine</a>.
I lookup the keybind for that action as well, after using it for a couple of times it becomes second nature.</p>
<h2>Describe Function <code>C-h f</code></h2>
<p>Describe function brings up the documentation about a function by name.</p>
<p>I use this almost everytime to find out about a function.</p>
<h2>Describe Key <code>C-h k</code></h2>
<p>Describe key gives you the command associated with the key/chord in current mode.</p>
<p>I use this to find the function associated with a key/chord.</p>
<h2>Describe Symbol <code>C-h o</code></h2>
<p>Describe symbol gives you the documentation of elisp symbols.</p>
<p>Use this when you are writing elisp code &amp; want to find out about inbuilt symbols.</p>
<h2>Describe Variable <code>C-h v</code></h2>
<p>Describe variable brings up the documentation about a variable by name.</p>
<p>I rarely use this as I am not an advanced user. But its good to have for customization.</p>
<h2>Where is?</h2>
<p>The <code>where-is</code> function returns you the keybind of a function. Use it when you know the function but not its keybind.</p>
<h2>Completion engine &amp; Minibuffer goodies</h2>
<p>I would recommend any completion engine which works out for you.</p>
<p>I like expanded minibuffer so I can see suggestions at a time.</p>
<p>I personally use <code>ivy</code> because it comes with expanded minibuffer. There are many options for completion engines but an expanded minibuffer is very nice to have.</p>
<h2>Keycast mode</h2>
<p>This mode shows the keychord &amp; the associated function on the modeline.
I like having this so I can learn emacs. Totally optional but a nice to have.</p>
<h2>Why best friends?</h2>
<p>I believe that one of the biggest difference between a professional and a beginner is that the professional has gotten comfortable in an environment which is pretty hostile to them.</p>
<p>If you foster exploration<a href="http://xahlee.info/emacs/index.html">^xah-emacs-guide</a> for yourself, you can get comfortable really fast.</p>
<p>Godspeed</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I like Smalltalk - Part 2 of 100 - Intention revealing names]]></title>
            <link>https://ysuraj.com/why-i-like-smalltalk-2-of-100</link>
            <guid isPermaLink="false">https://ysuraj.com/why-i-like-smalltalk-2-of-100</guid>
            <pubDate>Sat, 12 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Why I like Smalltalk: Part 2 of 100 - Intention revealing names<a href="https://wiki.c2.com/?IntentionRevealingNames">^1</a></h1>
<p>A properly named message communicates well. The developer does not have to look for the implementation.
This has more to do with design, but it has been in Smalltalk’s genes since its inception.</p>
<p>What is an intention-revealing method?
A message which</p>
<ul>
<li>Reveals intention</li>
<li>Hides implementation</li>
<li>Gives return type hint</li>
</ul>
<p>Intention revealing names answer <code>what</code> instead of <code>how</code>.</p>
<p>Let’s decide on a name for a method which looks up by a <code>key</code> in a <code>Dictionary</code></p>
<ul>
<li><code>binarySearchByKey:</code> - Bad, reveals how it works, doesn’t hint at return type</li>
<li><code>searchValueAt:</code> - Communicates what it does, Good</li>
<li><code>valueAt:</code> - Able to communicate while being shorter, Better</li>
<li><code>at:</code> - Best, takes Dictionary in context as key-value pairs</li>
</ul>
<p>This might seem a very simple pattern, but If you can make this happen in your codebase, you are a god.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Editor Journey Till Now]]></title>
            <link>https://ysuraj.com/my-editor-journey-till-now</link>
            <guid isPermaLink="false">https://ysuraj.com/my-editor-journey-till-now</guid>
            <pubDate>Fri, 11 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>My Editor Journey Till Now</h1>
<h2>What did I start with?</h2>
<p><strong>2018</strong></p>
<p>My first editor was Emacs<a href="https://www.gnu.org/software/emacs">^emacs</a>. Why did I choose emacs? I couldn’t figure out how to exit Vim<a href="https://www.vim.org">^vim</a>.</p>
<p>I got really into programming with Scheme<a href="https://groups.csail.mit.edu/mac/projects/scheme/">^scheme</a>. And I liked it so much I decided to choose the editor with its roots in it.</p>
<p>Learning emacs was just getting comfortable with its keybinds. The power of emacs comes from extensibility. Although I am a casual lisp programmer, I never bothered to learn elisp and extend emacs to my liking.</p>
<h2>Why did I switch?</h2>
<p><strong>2020</strong></p>
<p>The elisp<a href="https://github.com/chrisdone/elisp-guide">^elisp</a> configs didn’t make any sense. I never got the grasp on emacs modes and I felt slow in emacs. Although I am partly to blamed for not harnessing its power.</p>
<p>I decided to switch to Vim in 2020.
I like that just about any action is 1-3+ click/s away. I felt fast, really fast.
I felt so fast that I started using it everywhere. I use Vimium in my browser.
I use i3wm which has vim-like keybinds. I use vim keybinds in online IDEs for prototyping. I wish it was everywhere.</p>
<h2>Why am I switching again?</h2>
<p><strong>2022</strong></p>
<p>I have recently been tinkering with smalltalk. The Pharo(or any smalltalk) IDE has been one of the best IDEs I have ever used. I know when I miss vim because I feel slow. But I never felt slow in Pharo’s IDE. Its because you are able to reach just about anywhere within few clicks. I realized I was getting more done and was managing very less code. It made me think about extensibility.</p>
<p>And this made me change my mind. Its about time I did emacs properly.</p>
<h2>What do I plan to achieve?</h2>
<p>One day I will start my day by opening emacs and I’ll end it by closing it.
This is what I am aiming for.</p>
<h2>What about Vim?</h2>
<p>I will use vim for quick edits. I will continue using it in my browser. Emacs support in browser is not functional. The motions in vim are very powerful and I plan to use Spacemacs after I get comfortable with elisp.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I like Smalltalk - Part 1 of 100 - Documentation]]></title>
            <link>https://ysuraj.com/why-i-like-smalltalk-1-of-100</link>
            <guid isPermaLink="false">https://ysuraj.com/why-i-like-smalltalk-1-of-100</guid>
            <pubDate>Fri, 11 Mar 2022 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<h1>Why I like Smalltalk: Part 1 of 100 - Documentation</h1>
<h2>Smalltalk Documentation follows CRC<a href="http://www.agilemodeling.com/artifacts/crcModel.htm">^1</a>(Class, Responsibilities &amp; Collaborators)</h2>
<ul>
<li>For those who don’t know what CRC is, it’s a tool that helps design objects.</li>
<li>A CRC card consists of Class name at the top, responsibilities on the left side &amp; collaborators on the right.</li>
<li>Since a card models only one object, it enables rapid prototyping. It is feasible to go through many iterations before settling on an implementation.</li>
<li><img src="./images/crc-example.gif" alt="A sample CRC card" /></li>
</ul>
<h2>Smalltalk Documentation talks to you</h2>
<p>I noticed this in Pharo’s<a href="https://pharo.org">^2</a> documentation.
Classes have comments as they talk to you. They give you an overview of what they are and what they can do. They also tell you how you get started with them with some examples.</p>
<h3>Example from Pharo’s documentation for <code>Point</code></h3>
<pre><code class="language-smalltalk:Point">    I represent an x,y pair of numbers usually designating a location on the screen.

    My instances are created either using the message `@` or `x:y:` or `r:degrees:` as follows:

    | pt |
    pt := 10@20.
    pt x
    &gt;&gt;&gt; 10
    pt y
    &gt;&gt;&gt; 20

    | pt |
    pt := Point x: 10 y: 20.
    pt x
    &gt; 10
    pt y
    &gt; 20

    I define many nice messages that deal with point such as:
    - arithmetic such as \+, \*, reciprocal, min, abs,
    - comparison \&lt;, \&lt;=, \=, \&gt;, \&gt;=, closeTo:
    - geometry such as sideOf:, to:intersects:to:,
    - polar coordinates,
    - extent such as scaleTo:
    - transformation such as negated, translatedBy:, scaleBy:
    - rounding with roundTo:, roundUpTo:, truncateTo:, truncated
</code></pre>
<p>How cool is that? That makes me wanna take Point for a coffee.
I have adopted this style of documentation for just about everything.</p>
<h2>Inbuilt support for documentation</h2>
<p>The Smalltalk IDE’s are one of the most mature IDEs I have ever used. They have inbuilt support for documentation along with the class. Although this might be more of an IDE feature, it has been since the beginning(probably).</p>
<p><img src="./images/documentation-in-pharo.png" alt="Documentation in Pharo" /></p>
]]></content:encoded>
        </item>
    </channel>
</rss>