Ashish Chaudharyhttps://ashishchaudhary.in2024-01-31T15:46:28+00:00Ashish Chaudharyhttps://ashishchaudhary.in/hacker-blogme@ashishchaudhary.inAlternative to enums in Typescripthttps://ashishchaudhary.in/typescript-replace-enums2021-10-31T00:00:00+00:00<p>Sometimes when adding types to an existing codebase it becomes difficult to use Enums when you want to type something that should have been an Enum.</p> <p>Consider the following component:</p> <div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">FilterComponent</span> <span class="o">=</span> <span class="p">({</span> <span class="nx">filterType</span> <span class="p">})</span> <span class="o">=></span> <span class="p">{</span>...Webassembly to the rescuehttps://ashishchaudhary.in/awesome-wasm2020-01-28T00:00:00+00:00<p>While working on pointclouds for <a href="https://ashishchaudhary.in/amphion-zethus">Amphion and Zethus</a>, I came across an interesting problem.</p> <p>Consider the following scenario:</p> <ol> <li>a stream of messages containing an evolving pointcloud</li> <li>the messages contain certain fields like <code class="language-plaintext highlighter-rouge">x</code>, <code class="language-plaintext highlighter-rouge">y</code>, <code class="language-plaintext highlighter-rouge">z</code>, <code class="language-plaintext highlighter-rouge">color</code>, <code class="language-plaintext highlighter-rouge">intensity</code> compacted...Robotics in the browser! - Zethus + Amphionhttps://ashishchaudhary.in/amphion-zethus2020-01-28T00:00:00+00:00<p>The browser is perhaps the most versatile and approachable platform that has ever existed. Marrying it to robotics makes sense. For the last few months at work, I have been working in this direction with two open-source projects <a href="https://github.com/rapyuta-robotics/zethus/">Zethus</a> and <a href="https://github.com/rapyuta-robotics/amphion/">Amphion</a>.</p> <p><strong>Amphion</strong> - A library that ingests <a...Announcing three-freeform-controlshttps://ashishchaudhary.in/announcing-three-freeform-controls2020-01-19T00:00:00+00:00<p>For the last few months I have been working (on/off) on a controls library for <code class="language-plaintext highlighter-rouge">THREE.js</code> objects. Finally got the time to finish the docs and api reference.</p> <p>It provides 6-dof rotation and translation controls and is built to be fully customisable (something that I found to be...Typescript on steroids: Implementing Promisifyhttps://ashishchaudhary.in/typescript-on-steroids-implementing-promisify2018-08-07T00:00:00+00:00<p>Typescript 2.8 introduced conditional types and the <code class="language-plaintext highlighter-rouge">infer</code> keyword. A conditional type performs a pattern match on a generic variable and based on the match it can assign a type value. We can use this pattern matching to extract the types of arguments supplied to a function.</p> <p>For...Game Of Thrones Visualizations With Neo4j graph DBhttps://ashishchaudhary.in/game-of-thrones-visualization2018-05-10T00:00:00+00:00<p>Dataset: <a href="https://github.com/jeffreylancaster/game-of-thrones/blob/master/data/characters.json">game-of-thrones/characters.json at master · jeffreylancaster/game-of-thrones · GitHub</a>.</p> <p>Source code: <a href="https://github.com/tocttou/got-visual">tocttou / got-visual</a></p> <h2 id="interesting-finds">Interesting finds</h2> <p>Someone who does not know about the show can enjoy it too :D</p> <p><strong>Right click on image and “View Image” or “Open Image In New Tab” to see the zoomed version.</strong></p> <h3...Smart Image Resizing Using Seam Carvinghttps://ashishchaudhary.in/smart-image-resizing-using-seam-carving2018-03-13T00:00:00+00:00<p><a href="https://people.csail.mit.edu/mrub/talks/SeamCarving_6.865.pdf">Seam carving</a> is a fascinating technique to scale up/down an image.</p> <p><strong>Demo</strong></p> <p><em>This was a web-service.</em> [dead!] http://seam.ashishchaudhary.in:8080/</p> <p>The code is available at: <a href="https://github.com/tocttou/smartresizing">tocttou/smartresizing</a></p> <p>Overview of the application (kotlin): <a href="https://i.imgur.com/DJv24cT.png">https://i.imgur.com/DJv24cT.png</a></p> <p>The algorithm implementation is available directly at: <a href="https://github.com/tocttou/smartresizing/blob/master/src/main/kotlin/in/ashishchaudhary/smartresizing/task/SeamCarver.kt">SeamCarver.kt</a></p> <p><strong>Results</strong></p> <p>Results are fascinating (mostly).</p> <p><em>Reduction</em></p> <p><img src="https://i.imgur.com/vfoWtCE.png"...Better Error Handling In Kotlin With Either Typehttps://ashishchaudhary.in/better-error-handling-in-kotlin-with-either-type2018-02-17T00:00:00+00:00<p>Here is a nice experiment (borrowed from FP languages). Define the Either type:</p> <figure class="highlight"><pre><code class="language-kotlin" data-lang="kotlin"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1 2 3 4 </pre></td><td class="code"><pre><span class="k">sealed</span> <span class="kd">class</span> <span class="nc">Either</span><span class="p"><</span><span class="k">out</span> <span class="nc">T</span><span class="p">></span> <span class="p">{</span> <span class="kd">data class</span> <span class="nc">Error</span><span class="p">(</span><span class="kd">val</span> <span class="py">message</span><span class="p">:</span> <span class="nc">String</span><span...Implementing C-Style For-Loops In Kotlinhttps://ashishchaudhary.in/implementing-c-style-for-loops-in-kotlin2017-12-12T00:00:00+00:00<p>Kotlin does not have <a href="http://wiki.bash-hackers.org/syntax/ccmd/c_for">C-style for-loops</a>. This is fine because I prefer using the idiomatic for-loops (built to use iterators) anyway. But there is a problem: Kotlin does not allow dynamic limiting conditions in its for-loops (<a href="https://discuss.kotlinlang.org/t/for-loop-with-dynamic-condition/57">discussion</a>).You have to use a while loop to achieve the same functionality....Extending An Object's API With Delegation In Kotlinhttps://ashishchaudhary.in/extending-an-objects-api-with-delegation-in-kotlin2017-12-12T00:00:00+00:00<p><strong>Task</strong>: Expose extra API methods for an object.</p> <p><strong>Methods</strong>:</p> <ol> <li> <p>Derive a new class from the class of that object, implement the extra functionality, make a new object from that new class.</p> <p>This method is suitable in cases where the new class has an “is-a” relationship with the actual...