<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Devil is in the Details - Medium]]></title>
        <description><![CDATA[Sharing ideas for improvement - Medium]]></description>
        <link>https://medium.com/devil-is-in-the-details?source=rss----9291377a9864---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Devil is in the Details - Medium</title>
            <link>https://medium.com/devil-is-in-the-details?source=rss----9291377a9864---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 20:40:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/devil-is-in-the-details" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Soft Search That Taught Machines to Understand]]></title>
            <link>https://medium.com/devil-is-in-the-details/the-soft-search-that-taught-machines-to-understand-c324f0c5d5de?source=rss----9291377a9864---4</link>
            <guid isPermaLink="false">https://medium.com/p/c324f0c5d5de</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Shreejit Rajbanshi]]></dc:creator>
            <pubDate>Mon, 20 Jul 2026 03:22:48 GMT</pubDate>
            <atom:updated>2026-07-20T03:27:39.082Z</atom:updated>
            <content:encoded><![CDATA[<h4>The breakthrough behind ChatGPT wasn’t smarter machines — it was softer search.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9kXxuKSH4YITEEOj" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The biggest breakthrough in AI wasn’t giving machines a bigger brain but rather teaching them to stop looking for perfect answers.</p><p>Every large language model, from ChatGPT to Claude and Gemini, rests on one deceptively simple idea: a dictionary lookup that stopped insisting on exact matches. A small shift that changed everything.</p><blockquote>“You’re probably looking for cat, but maybe kitten. Perhaps even pet. Here’s a little of each.”</blockquote><h3><strong>The Search You Already Understand</strong></h3><p>Think about a Python dictionary:</p><pre>sounds = {&quot;cat&quot;: &quot;meow&quot;, &quot;dog&quot;: &quot;woof&quot;, &quot;cow&quot;: &quot;moo&quot;}<br>sounds[&quot;cat&quot;]   # -&gt; &quot;meow&quot;</pre><p>Every dictionary lookup is really a conversation between three players:</p><p>The <strong>query</strong> is &quot;cat&quot; — What you&#39;re looking for.<br>The <strong>keys</strong> are &quot;cat&quot;, &quot;dog&quot;, &quot;cow&quot; — the labels you match against.<br>The <strong>values</strong> are &quot;meow&quot;, &quot;woof&quot;, &quot;moo&quot; — What you actually get back.</p><p><strong>The match is unforgiving.</strong> Ask for, &quot;cat&quot; and you get &quot;meow&quot;. Ask for &quot;kitten&quot; and you get nothing. That brittleness is perfect for code but useless for language, where almost nothing matches exactly.</p><h3>What If “Almost” Counted?</h3><p>Attention keeps the same query–key–value but changes one thing: <strong>nothing has to match perfectly.</strong></p><p>Instead of asking <em>“Does my query equal this key?”</em>, it asks <em>“How similar is my query to each key?”</em> — and then returns a blend of all the values, weighted by that similarity. Query &quot;kitten&quot; against &quot;cat&quot;, &quot;dog&quot;, &quot;cow&quot; Nothing crashes. &quot;cat&quot; scores high, &quot;dog&quot; and &quot;cow&quot; score low, and you get back mostly &quot;meow&quot; with a faint trace of the rest. A weighted average instead of a single hit.</p><pre> Query “kitten” <br>cat ██████████████████████████████████████████████████████████████████████ 82% <br>dog ████████████ 14% <br>cow █████ 4%</pre><h3>Representations Attention: <strong>Tokens to Queries, Keys, and Values</strong></h3><p>Just like in the case of a dictionary, every token is projected into three vectors, each serving a different purpose:</p><p><strong>Query (Q):</strong> the question it asks.<br><strong>Key (K):</strong> the description others use to find it.<br><strong>Value (V):</strong> the information it shares once it’s found.</p><p>Every word plays all three roles at once, because every word is both searching for context <em>and</em> offering itself as context to others.</p><h4>Why One Vector Isn’t Enough</h4><p>A single embedding captures a token’s meaning. But attention asks every token to do more than simply <em>be</em> something.</p><p>Take the word <em>it</em>:</p><pre>“The animal didn’t cross the street because it was tired.”</pre><p>To understand <em>it</em>, the model must search for the noun it refers to:</p><ul><li>It points <strong>back to a noun</strong> — <em>which thing am I?</em> (“animal,” not “street”)</li><li>It’s the <strong>subject of a verb</strong> — <em>what am I doing?</em> (“was tired”)</li><li>It sits in a <strong>local neighborhood</strong> of words that shade its meaning (“because,” “tired”)</li><li>And it holds its <strong>own identity</strong> as a pronoun, ready to be referred to in turn</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SX4HzXeB3ej_ByJrynfMBQ.png" /></figure><p>A word is a bundle of simultaneous relationships<strong>.</strong> It has to decide <strong>what information it’s looking for</strong>, advertise <strong>what information it can offer</strong>, and carry <strong>the information that should be shared</strong>. Those are fundamentally different jobs, and expecting a single vector to perform all three would blur them together. If we compared raw embeddings directly, we’d only get one dull answer: <em>how similar do these two words look on the surface?</em> By that measure, <strong>“it”</strong> and <strong>“animal”</strong> have almost nothing in common, and the relationship we actually care about would never emerge.</p><p>That’s why one vector isn’t enough. A word has to do more than <em>be</em> something — it has to <em>ask</em>, <em>offer</em>, and <em>give</em> enough to track many relationships at once.</p><h4><strong>The Role of Query, Key, and Value</strong></h4><p>The three vectors all come from the same token, but each plays a different role during attention.</p><ul><li><strong>Query (Q)</strong> — <em>What am I searching for?</em><br> For <strong>“</strong>it<strong>”</strong>, the query might be: <em>“I’m a pronoun — who do I refer to?”</em></li><li><strong>Key (K)</strong> — <em>How can I be found?</em><br><strong>“</strong>animal<strong>”</strong> advertises itself as: <em>“I’m a noun that could be what you’re referring to.”</em></li><li><strong>Value (V)</strong> — <em>What information do I provide?</em><br>Once <strong>“</strong>animal<strong>”</strong> is selected, its value carries the information that <strong>“</strong>it<strong>”</strong> needs.</li></ul><h4>Projecting Tokens into Q, K, and V</h4><p>None of these three vectors are hand-designed. They’re all built from the same starting token vector by passing it through three separate learned matrices — call them W_Q, W_K, and W_V:</p><pre>Q = token_embedding × W_Q<br>K = token_embedding × W_K<br>V = token_embedding × W_V</pre><p>Think of each matrix as a lens. The same word goes in, and each lens pulls out a different aspect of it —one optimized for asking, one for being found, and one for carrying information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSuXgAKu1l7GK0HFnLxihQ.png" /></figure><p>These matrices start as random numbers and get tuned during training, alongside everything else in the model. That’s what frees attention from surface-level similarity. If we compared raw embeddings, “it” and “animal” would look unrelated and stay that way. But because the model can shape W_Q and W_K however it likes, it can learn to bend the space so that a pronoun’s query lines up with a noun’s key — even when the two words look nothing alike. The matrices are where the model learns what ‘similar’ really means.</p><h3>The similarity is just multiplication</h3><p>Given we have a query and a set of keys, a soft lookup consists of a dot product<strong>, </strong>giving us one number for how well a query matches each key — a similarity score.</p><p>For two vectors of dimension dₖ, it&#39;s a sum of element-wise products:</p><pre>q · k = Σᵢ qᵢkᵢ = q₁k₁ + q₂k₂ + … + q_dₖ k_dₖ</pre><h4>Why does adding up products measure similarity?</h4><p>Imagine each vector describes how strongly a word expresses a few features:</p><pre>    [royalty, feline, furriness]<br><br>king  = [0.9, 0.0, 0.1]<br>queen = [0.9, 0.0, 0.2]<br>cat   = [0.0, 0.9, 0.9]</pre><p>Now compute the dot product:</p><pre>king · queen = 0.81 + 0 + 0.02 = 0.83   → high<br>king · cat   = 0    + 0 + 0.09 = 0.09   → low</pre><p>Each multiplication measures agreement on a single feature. A feature contributes a large value only when both vectors score highly on it. King and queen strongly agree on royalty, so 0.9 × 0.9 = 0.81 dominates the score. King and cat barely agree on any important feature, so every contribution stays small.</p><p>The final sum is simply the total amount of agreement between the two vectors.</p><h4>From scores to output</h4><p>After multiplying <strong>QKᵀ</strong>, each query has a score for every token in the sentence. For <strong>“</strong>it<strong>”</strong>, that might look something like this:</p><pre>animal   4.0<br>street   0.2<br>because -1.3<br>tired    1.8</pre><p>These numbers tell us how well each key matches the query, but we can’t use them directly.</p><p>Some are negative, which makes little sense as <em>“how much attention should I pay?”</em> Others are arbitrarily large, and together they don’t add up to anything meaningful. They aren’t weights yet — they’re just scores.</p><p><strong>Introducing Softmax: </strong>What we really want is a set of weights that are:</p><ul><li>all positive,</li><li>add up to 1, and</li><li>Assign more weight to better matches.</li></ul><p>That’s exactly what softmax does. Softmax fixes that by transforming the scores into a probability distribution.</p><pre>softmax(s)ᵢ = e^{sᵢ} / Σⱼ e^{sⱼ}<br><br>e^4.0   = 54.60<br>e^0.2   =  1.22<br>e^-1.3  =  0.27<br>e^1.8   =  6.05<br><br>sum = 62.14<br><br>animal   = 54.60 / 62.14 = 0.879<br>street   =  1.22 / 62.14 = 0.020<br>because  =  0.27 / 62.14 = 0.004<br>tired    =  6.05 / 62.14 = 0.097</pre><p>Now they’re a probability distribution: all positive, adding to 1. “animal” gets 87% of the attention; everything else is a sliver — but nothing is exactly zero.</p><p><strong>Why not just pick the best match?<br></strong> It might seem simpler to ignore every word except the highest-scoring one.</p><p>Choosing the single best match (argmax) creates a hard yes-or-no decision. The winning token gets a weight of 1. Every other token gets 0.</p><p>At the beginning of training, attention scores are almost random. If the model commits to one random word, it has no smooth way to discover that another word should have won instead.</p><pre>Raw attention scores (Q · Kᵀ)<br>Dot product between the query vector for &quot;it&quot;<br>and the key vector for each token.<br><br>Q(it) · K(animal)   = 4.0<br>Q(it) · K(street)   = 2.0<br>Q(it) · K(tired)    = 1.0</pre><p>Then, after argmax:</p><pre>Attention weights (argmax)<br><br>           animal   street   tired<br>Q(it)  →      1        0        0</pre><p>Now imagine training nudges the score for the street upward.</p><pre>Attention scores            Argmax output<br>------------------------------------------------<br>animal 4.0                 animal 1<br>street 2.0      ─────▶     street 0<br>tired  1.0                 tired  0<br><br>animal 4.0                 animal 1<br>street 2.5      ─────▶     street 0<br>tired  1.0                 tired  0<br><br>animal 4.0                 animal 1<br>street 3.9      ─────▶     street 0<br>tired  1.0                 tired  0<br><br>animal 4.0                 animal 0<br>street 4.1      ─────▶     street 1<br>tired  1.0                 tired  0</pre><p>Notice what happens. For every small change in the score, the output stays the same. It only changes at the instant “street” overtakes “animal”. During backpropagation, gradients are multiplied by this derivative. Since it’s zero, no gradient reaches the losing tokens, so the model receives no signal telling it how to increase their scores.</p><p>Softmax avoids that trap. Each token maintains a small, nonzero weight, so each token receives a small gradient during training. Over millions of updates, the correct relationships gradually strengthen while the incorrect ones fade away.</p><h3>Why “soft” is the whole point</h3><p><strong>The blend: </strong>Each attention softmax weight multiplies its corresponding Value vector, and the results are added together:</p><pre>output_it =<br>  0.879 · V_animal +<br>  0.020 · V_street +<br>  0.004 · V_because +<br>  0.097 · V_tired....</pre><p>The result is a single new vector for <strong>“</strong>it<strong>.”</strong> Because “animal<strong>”</strong> received almost all the attention, its information dominates the output, while the other words contribute only small amounts. Here’s the thing to hold onto: attention never <em>picks</em> a word. Its output is a blend — a weighted sum of <em>every</em> word’s value. Nothing is dropped; every word contributes something, however small. That “keep everyone” choice is what makes the mechanism powerful, and it’s worth seeing exactly why.</p><h4><strong>Understanding usually needs more than one source.</strong></h4><p>A word’s meaning is rarely determined by a single other word. More often, it emerges from several relationships at once, and blending is what lets attention combine them.</p><p>Consider:</p><pre>“She sat on the bank and watched the river.”</pre><p><strong>“</strong>River<strong>”</strong> suggests the riverside meaning. “Sat on<strong>”</strong> reinforces that it’s a physical place rather than a financial institution. Neither clue is enough on its own, but together they remove the ambiguity. Because attention is soft, “bank” can blend information from both words instead of choosing just one. The result isn’t a copy of river or sat. It’s a new representation that means “bank” in the context of a river. A weighted sum can do something a copy can’t: land at a point in the space that <em>none</em> of the inputs occupy.</p><p>Everything we’ve just walked through is part of <em>Attention Is All You Need, </em>the part the authors call <strong>Scaled Dot-Product Attention</strong>. The formula they print there is the one we assembled piece by piece:</p><pre>Attention(Q, K, V) = softmax( QKᵀ / √dₖ ) V</pre><p>The only piece left is the √dₖ divisor. Longer queries and key vectors naturally produce larger dot products, which can make softmax overly confident and cause it to collapse. Dividing by √dₖ keeps the scores on a consistent scale, allowing softmax to remain smooth and train effectively.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c324f0c5d5de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devil-is-in-the-details/the-soft-search-that-taught-machines-to-understand-c324f0c5d5de">The Soft Search That Taught Machines to Understand</a> was originally published in <a href="https://medium.com/devil-is-in-the-details">Devil is in the Details</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building iterable objects in Python]]></title>
            <link>https://medium.com/devil-is-in-the-details/building-iterable-objects-in-python-e6a41a8cb78d?source=rss----9291377a9864---4</link>
            <guid isPermaLink="false">https://medium.com/p/e6a41a8cb78d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Shreejit Rajbanshi]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 02:45:18 GMT</pubDate>
            <atom:updated>2022-11-20T02:49:05.416Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using __len__ &amp; __getItem__</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4UTM6VP5lhGLGD0q" /><figcaption>Photo by <a href="https://unsplash.com/@tristan_gevaux?utm_source=medium&amp;utm_medium=referral">Tristan Gevaux</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Python data model is different from other programming languages such that it calls special methods to perform basic object operations, often triggered by special syntax.</p><blockquote>Those method names always lead, and trail with double underscores (i.e __len__).</blockquote><p>There are many special methods, __init__ being the most common one of them. We, as programmers, don’t invoke them directly. But adding them to our class allows us to append some of python’s core functionalities with ease.</p><h4>Step 1 : __len__ method</h4><p>Presuming hypothetically, we want to create a Library object housing a list of books, the object and its functions would look something like this:</p><pre>class Library: <br>    def __init__(self):<br>        self._books = [<br>             &quot;Atomic Habits&quot;, <br>             &quot;Shoe Dog&quot;,<br>             &quot;Deep Work&quot;, <br>             &quot;Zero to One&quot;]<br>    <br>    def book_count(self): <br>        &#39;&#39;&#39; Custom function returning the no of books &#39;&#39;&#39;<br>        return len(self._books)</pre><pre>&gt;&gt;&gt; library = Library()<br>&gt;&gt;&gt; library.book_count()<br>4</pre><p>The implementation is correct. But as an iterable class, a better approach would be allowing users to pass the object into the len() function. Having a standardized function means users of our class don’t have to memorize arbitrary function name or search for it, specially for standard operations like this.</p><p>Adding __len__ instead of our custom function and we have done it.</p><pre>class Library: <br>    def __init__(self):<br>        self._books = [<br>             &quot;Atomic Habits&quot;, <br>             &quot;Shoe Dog&quot;,<br>             &quot;Deep Work&quot;, <br>             &quot;Zero to One&quot;]<br>    <br>    def __len__(self): <br>        return len(self._books)</pre><pre>&gt;&gt;&gt; library = Library()<br>&gt;&gt;&gt; len(library) # Returns 4</pre><h4>Step 2: __getItem__ method</h4><p>With our approach to compute length finalized, it gets better. [] operator used for accessing based on index, delegates the task of finding the item to __getitem__ function.</p><pre>class Library: <br>    def __init__(self):<br>        self._books = [<br>             &quot;Atomic Habits&quot;, <br>             &quot;Shoe Dog&quot;,<br>             &quot;Deep Work&quot;, <br>             &quot;Zero to One&quot;]<br>    <br>    def __len__(self): <br>        &#39;&#39;&#39; Custom function returning the no of books &#39;&#39;&#39;<br>        return len(self._books)<br><br>    def __getitem__(self, position):<br>        return self._books[position]</pre><p>Rather than trying to reinvent the wheel we just inherited the array like behaviour into our own objects.</p><pre>&gt;&gt;&gt; library = Library()<br>&gt;&gt;&gt; library[1]<br>Shoe Dog</pre><p>Should we create a method to pick a random book? No need. Python already has a function to get a random item from a sequence: rondom.choice. We can now use it on our object.</p><pre>&gt;&gt;&gt; from random import choice<br>&gt;&gt;&gt; choice(library)<br>Deep Work</pre><p>Slicing operation are also readily available to our custom object just by adding a single method.</p><pre>&gt;&gt;&gt; library[:3]<br>[&#39;Atomic Habits&#39;, &#39;Shoe Dog&#39;, &#39;Deep Work&#39;]</pre><p>You would not want to reverse a library object, there is literally no meaning to it. But if you ever wanted to, addition of __getitem__ has the added benefit of the reversed method.</p><pre>&gt;&gt;&gt; [book for book in reversed(library)]<br>[&#39;Zero to One&#39;, &#39;Deep Work&#39;, &#39;Shoe Dog&#39;, &#39;Atomic Habits&#39;]</pre><h3>Conclusion</h3><p>Effectively using Python data model allows us with minimum lines of code to inherit some of the most useful functionalities of Python. There are many more special methods in python giving us even more freedom to define our custom objects, that can take advantage of or work with standard methods that we already use on a daily bases.</p><p>Thank you!!!</p><p><a href="https://medium.com/devil-is-in-the-details/filtering-arrays-using-type-predicates-in-typescript-cf554afc76a3">Type predicates: Filtering arrays in Typescript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a41a8cb78d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devil-is-in-the-details/building-iterable-objects-in-python-e6a41a8cb78d">Building iterable objects in Python</a> was originally published in <a href="https://medium.com/devil-is-in-the-details">Devil is in the Details</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type predicates: Filtering arrays in Typescript]]></title>
            <link>https://medium.com/devil-is-in-the-details/filtering-arrays-using-type-predicates-in-typescript-cf554afc76a3?source=rss----9291377a9864---4</link>
            <guid isPermaLink="false">https://medium.com/p/cf554afc76a3</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Shreejit Rajbanshi]]></dc:creator>
            <pubDate>Tue, 15 Nov 2022 15:58:52 GMT</pubDate>
            <atom:updated>2022-11-20T02:43:23.074Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uL2MA68c225CzqNH" /><figcaption>Photo by <a href="https://unsplash.com/@wadeaustinellis?utm_source=medium&amp;utm_medium=referral">Wade Austin Ellis</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Typescript has made developing in javascript more predictable. It provides warnings about any unhandled types in our code, that might result in an exception at runtime. Most common example being null checks that we miss often.</p><p>Amazing as it maybe, typescript does have features that are a little harder to get around. Filtering arrays for a specific type is one of them.</p><p>Filtering elements of an array in javascript is uncomplicated . The build in function filter handles everything, with our only task being passing a function that validates the elements.</p><pre>const names = [&quot;John&quot;, &quot;Ray&quot;, null ,&quot;Nancy&quot;]<br><br>// returns false if the value of name is null, giving us a list of strings<br>const filteredNames = names.filter((name) =&gt; !name) </pre><p>Taking the same approach in typescript lands us with a red squiggly line.</p><p>Let us assume a simple function accepting an array of strings. Given a array that contain null, we need to filter it before passing it to the function.</p><pre>const printNames = (names: string[]) =&gt; {<br>  console.log(names);<br>}<br><br>const names: (string | null)[]= [&quot;John&quot;, &quot;Ray&quot;, null ,&quot;Nancy&quot;]<br>const filteredNames = names.filter((name) =&gt; !name)<br><br>// TypeError: (string | null)[] is not assignable to string[]<br>printNames(filterednNames)</pre><p>The workings of the code is absolutely correct, it does filter out all the null values. But, typescript still indicates an error.</p><p>Although true, we have filtered out the null values, there is no way for typescript to know that. The filter function accepts a validation function. It doesn’t understand its content nor, filter operations that are performed. Hovering over to check the type of filteredNames in VS code, will give its type as (string | null)[].</p><h3>Using Type predicate</h3><p>Defining a function that returns a type predicate helps us get around the error.</p><pre>const filteredNames = names.filter((name): name is string =&gt; !name)</pre><p>The name is string portion of the function is the type predicate. It takes the form of parameterName is Type. where parameterName must be the name of a parameter from the current function signature.</p><p>Functions that are declared as type predicate, must return a boolean. It provides the typescript compiler information.</p><p>When the return value is true, TypeScript assumes that the return type is the one that&#39;s declared in the type predicate. This is true for custom types too.</p><pre>type Circle = { radius: number}<br>type Square = { length: number}<br><br>type Shape = Circle | Square<br><br>const isCircle = (shape: Shape): shape is Circle =&gt; {<br>  // Any condition we want for filtering<br>  return &#39;radius&#39; in shape;<br>};<br><br>const circles = shapes.filter(isCircle);</pre><p>If this function returns true, TypeScript assumes that the provided argument is of type Circle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf554afc76a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devil-is-in-the-details/filtering-arrays-using-type-predicates-in-typescript-cf554afc76a3">Type predicates: Filtering arrays in Typescript</a> was originally published in <a href="https://medium.com/devil-is-in-the-details">Devil is in the Details</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency array in useEffect hook]]></title>
            <link>https://medium.com/devil-is-in-the-details/dependency-array-in-useeffect-hook-d73e0ef2ab33?source=rss----9291377a9864---4</link>
            <guid isPermaLink="false">https://medium.com/p/d73e0ef2ab33</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Shreejit Rajbanshi]]></dc:creator>
            <pubDate>Mon, 09 May 2022 17:08:50 GMT</pubDate>
            <atom:updated>2022-11-20T02:41:41.424Z</atom:updated>
            <content:encoded><![CDATA[<h4>The value passed matters more than you think</h4><p>React hooks have simplified how we write code. The <strong>useEffect</strong> hook alongside <strong>useState</strong>, helps functional component handle states, removing the need for class components.</p><p>Understanding <strong>useEffect</strong> hook will help us avoid bugs, that might keep our head scratching for hours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sIDF5JI_WyIMGg0f" /><figcaption>Photo by <a href="https://unsplash.com/@jannerboy62?utm_source=medium&amp;utm_medium=referral">Nick Fewings</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Dependency Array</h4><p>One of the arguments that the <strong>useEffect</strong> accepts, after the callback function is the dependency array. This array defines the list of variables that if changed will trigger the callback function.</p><pre>useEffect(() =&gt; {<br>    // Callback function<br>}, [dependencyArray])</pre><p>Let us take a look at some of the parameters that can be passed in place of the dependency array, and how it affects the hook itself.</p><h4>1. Skipping the argument:</h4><p>We may skip passing the second argument. If we choose to do so then our hook will trigger the callback function on each re-render of the component. Any unrelated state change will trigger the callback function to execute inducing bugs, and compromising performance.</p><pre>useEffect(() =&gt; {<br>    // Runs in each re-render of the component<br>})</pre><h4><strong>2. Empty Array ( [] )</strong></h4><p>An empty array simply means that there are no dependencies that will trigger the callback within it. Our code inside the callback will run once when the component gets registered, and that is it. The <strong>useEffect</strong> hook acts like <strong>componentDidMount</strong> method if an empty array is passed as the dependency array.</p><pre>useEffect(() =&gt; {<br>    // Runs only when the component is registered<br>}, [])</pre><h4><strong>3. Array of dependencies ( [variable1, variable2] )</strong></h4><p>This might be the most common form used with <strong>useEffect</strong>. We pass an array filled with all the dependencies that should trigger the callback function to run. Change in any of the variable in the list will execute the callback.</p><p>Often these include the states that have been created using <strong>useState</strong> hook.</p><pre>const [x, setX] = useState();<br>const [y, setY] = useState();</pre><pre>useEffect(() =&gt; {<br>    // Runs if x or y changes<br>}, [x, y])</pre><h4><strong>Conclusion</strong></h4><p>Hopefully this has given you some more insight on how <strong>useEffect</strong> hook performs based on its second parameter, and why it is important for us to understand it.</p><p><a href="https://medium.com/devil-is-in-the-details/filtering-arrays-using-type-predicates-in-typescript-cf554afc76a3">Type predicates: Filtering arrays in Typescript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d73e0ef2ab33" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devil-is-in-the-details/dependency-array-in-useeffect-hook-d73e0ef2ab33">Dependency array in useEffect hook</a> was originally published in <a href="https://medium.com/devil-is-in-the-details">Devil is in the Details</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 ways of stealing data using SQL injection]]></title>
            <link>https://medium.com/devil-is-in-the-details/3-ways-of-stealing-data-using-sql-injection-71893672efcf?source=rss----9291377a9864---4</link>
            <guid isPermaLink="false">https://medium.com/p/71893672efcf</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hacker]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Shreejit Rajbanshi]]></dc:creator>
            <pubDate>Mon, 27 Jul 2020 00:07:54 GMT</pubDate>
            <atom:updated>2020-07-27T09:22:39.472Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understand the attack logic so as to prevent it</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L6Cfm8VAdh42Uugi" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Seeing your companies private data all over the internet is not a happy sight to see. Yes, you get free publicity but not in a positive sense. Building an application takes a lot of work but without security, it acts as a door without a lock, anyone can come in as they please.</p><p>SQL injection is one of the most common types of attacks used to hack a web application and yet many of us still know very little about it and how it works. It is a web security vulnerability, attackers use by interfering with the queries that an application makes to its database resulting in a data breach.</p><h4>What Creates SQL Vulnerability?</h4><p>As we will later see through multiple examples the main cause that creates such a harmful nitch for hackers is due to dynamic SQL query generation. It sounds like something complex but it simply means to create SQL query through concatenation.</p><pre><strong>var Query = &quot;SELECT * FROM users WHERE username = &quot; ${user} &quot;AND password =&quot; ${password}; </strong></pre><p>If you have written something similar to the above example in your application then it is highly likely that your application is susceptible to an attack.</p><p>This SQL statement is passed to a function that sends the string to the connected database where it is parsed, executed and returns a result. But before all that, the query itself is generated within the application.</p><p>Now let’s dive in and learn through examples, how dynamically generating queries, as shown above, can impose serious risks to your data.</p><h4>1. Retrieving Hidden Data</h4><p>Suppose we have a shopping application selling a verity of items with one category being “watches”. Clicking on it triggers an action to request the URL:</p><p><strong>https://shopingspot.com/products?category=watches</strong></p><p>This causes the application to make an SQL query to the database:</p><p><strong>SELECT * FROM products WHERE category = &#39;watches&#39; AND released = 1</strong></p><p>This query retrieves data as:</p><ul><li>all details (*)</li><li>from the products table</li><li>where the category is <strong>watches</strong></li><li>and released is 1.</li></ul><p>The restriction <strong>released = 1</strong> is being used to hide products that are not released. For unreleased products, presumably <strong>released = 0</strong>.</p><p>The application doesn’t implement any defenses against SQL injection attacks, so an attacker can construct an attack like:</p><p><strong>https://shopingspot.com/products?category=watches&#39;--</strong></p><p>This results in the SQL query:</p><p><strong>SELECT * FROM products WHERE category = &#39;watches&#39;--&#39; AND released = 1</strong></p><p>The key thing here is that the double-dash sequence <strong>--</strong> indicating a comment in SQL. Anything after it is simply interpreted as a comment.</p><p>This effectively removes the remainder of the query, so it no longer includes <strong>AND released = 1</strong>. This means that all products are displayed, including unreleased products.</p><p>Going further, an attacker can cause the application to display all the products in any category, including categories that they don’t know about:</p><p><strong>https://shopingspot.com/products?category=watches&#39;+OR+1=1--</strong></p><p>This results in the SQL query:</p><p><strong>SELECT * FROM products WHERE category = &#39;watches&#39; OR 1=1--&#39; AND released</strong> <strong>= 1</strong></p><p>The modified query will return all items where either the category is <strong>watches</strong>, or 1 is equal to 1. Since <strong>1=1</strong> is always true, the query will return all items.</p><h4>2. Subverting application logic</h4><p>Consider a simple bank application that lets users log in with an email and password. Only by adding a proper email and a valid password for the username can someone access any information related to the bank account.</p><p>Our emails are public but our password is not something that we share. An application usually generates a query as shown below for a given username and password which let&#39;s assume is <strong>weilder@gmail.com</strong> and<strong>bluerose</strong>.</p><p><strong>SELECT * FROM users WHERE email = &#39;weilder@gmail.com&#39; AND password = &#39;bluerose&#39;</strong></p><p>Here, an attacker can log in as any user without a password simply by using the SQL comment sequence <strong>--</strong> to remove the password check from the <strong>WHERE </strong>clause of the query. For example, submitting the email <strong>weilder@gmail.com&#39;--</strong> and a blank password results in the following query:</p><p><strong>SELECT * FROM users WHERE email = &#39;weilder@gmail.com&#39;--&#39; AND password = &#39;&#39;</strong></p><p>This query returns the user whose email is <strong>weilder@gmail.com</strong>and successfully logs the attacker in as that user with all the access to your bank account that you have.</p><h4>3. Retrieving data from other database tables</h4><p>An attacker may leverage an SQL injection vulnerability to retrieve data from other tables within the database. This is done using the <strong>UNION </strong>keyword, which lets you execute an additional <strong>SELECT </strong>query and append the results to the original query.</p><p>For example, if an application executes the following query containing the user input <strong>watches</strong>:</p><p><strong>SELECT name, description FROM products WHERE category = &#39;watches&#39;</strong></p><p>then an attacker can submit the input:</p><p><strong>&#39; UNION SELECT username, password FROM users--</strong></p><p>This will cause the application to return all usernames and passwords along with the names and descriptions of products.</p><h3>Some final words</h3><p>I hope this gave you a better understanding of how SQL injection works and how hackers misuse them to gain data access and privileges in an application that normally should not be allowed. And please don’t go and hack away at random applications online. It might lead you to unwanted troubles.</p><p>Demo: <a href="https://www.hacksplaining.com/exercises/sql-injection#/hack-complete"><strong><em>https://www.hacksplaining.com/exercises/sql-injection#/hack-complete</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71893672efcf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devil-is-in-the-details/3-ways-of-stealing-data-using-sql-injection-71893672efcf">3 ways of stealing data using SQL injection</a> was originally published in <a href="https://medium.com/devil-is-in-the-details">Devil is in the Details</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My unusual way of working from home and what I learned from it]]></title>
            <link>https://medium.com/devil-is-in-the-details/my-unusual-way-of-working-from-home-850f62b46df4?source=rss----9291377a9864---4</link>
            <guid isPermaLink="false">https://medium.com/p/850f62b46df4</guid>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Shreejit Rajbanshi]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 15:32:11 GMT</pubDate>
            <atom:updated>2020-07-17T00:21:22.341Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>The pandemic set in… and with it came the practice of working from home</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TV_fc6wY3RdsHmii" /><figcaption>Photo by <a href="https://unsplash.com/@israahilles?utm_source=medium&amp;utm_medium=referral">Israa Hilles</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I really hated it when the company I work in announced a WFH (working from home) drill for a week. But sadly due to the rapid progress of the pandemic had to be extended indefinitely.</p><p>Hi, I am a software engineer and remote working is nothing new in our line of work. But the idea of working from home has never really excited me. Yes, you get to stay home in your trousers with no one monitoring you but I could never move past that awful back pains. The humdrum life of going to the office and interacting with my team and colleagues has always been how I prefer to work.</p><p>The new policy was set into motion and with it, my daily motion came to a halt. The new policy was to protect all of us from COVID-19 and I knew that, but it would still not please me. The first week began and it was just as I anticipated it to be, a hateful experience.</p><p>I felt lonely, unmotivated, and the back pains almost made me cry. We had slack and zoom for communication but the interactions that we had on a daily basis were missing. Sync up in the morning and chat messages for any queries that we had were fairly common and that had to do for now in terms of interaction. We were in the middle of a freaking pandemic what choice did we have.</p><blockquote>Being productive does not always require us to follow the standard practices, sometimes trying something new might be for you.</blockquote><p>But then things started to change and I can relate this change to the one line from Jurassic Park “Life finds a way”. As time passed, I and my team started using calls for communication replacing chats. For every little discussion that arose, we called each other rather than text. The interaction that I missed due to WFH was finally coming back with such frequent calls.</p><p>How can 2-minute calls change things?</p><p>Well, our calls lasted for more than a few minutes. To be a bit more precise, one of my longest calls lasted for 7 straight hours. Believe me, we were not goofing but working. Yes, we did joke around but it felt exactly like working side by side with my team member in the office. We were on the call but we were still busy with our own tasks.</p><p>So, what did I learn from the experience?</p><h4>1. Remote working is not a barrier to communication</h4><p>I would not recommend my methods to everyone but it proves that we can bypass the communication gap created from working remotely.</p><p>Remote working does not have to be the end of effective communication. At this day and age Zoom, Slack, WhatsApp, and many more can easily be used for work without being physically present.</p><p>It is true that remote working is not applicable for all professions but knowing the fact that it works without communication being a major problem should open up many more opportunities to a lot of people in different parts of the world.</p><h4>2. Establishing rapport through games while working remotely</h4><p>Many people fail to realize how playing games can actually help build a bond. This is especially important while working remotely as we cannot go out for a cup of coffee and have a nice conversation with our colleagues.</p><p>Games like Scribble and Ludo are fun to play with your team and can not only freshen you up but also helps you connect with your team members.</p><h3>Wrapping it up</h3><p>This is my and my colleague&#39;s unusual way of working from home, being on the call regardless of whether we were working on the same problem or not. It is the little things that make life actually worth living and even though this might not be the best or the most effective way of working remotely, for me this is what I loved most about it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=850f62b46df4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devil-is-in-the-details/my-unusual-way-of-working-from-home-850f62b46df4">My unusual way of working from home and what I learned from it</a> was originally published in <a href="https://medium.com/devil-is-in-the-details">Devil is in the Details</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>