<?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"><channel><title><![CDATA[gumshoe@hashnode:~$ init blog]]></title><description><![CDATA[gumshoe@hashnode:~$ init blog]]></description><link>https://blog.gumshoe.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 22:14:05 GMT</lastBuildDate><atom:link href="https://blog.gumshoe.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Quirk Regarding Type Assertions and Switch Statements in Go]]></title><description><![CDATA[During my journey of learning Go, I've come across a confusing yet interesting quirk regarding type assertions.]]></description><link>https://blog.gumshoe.dev/a-quirk-regarding-type-assertions-and-switch-statements-in-go</link><guid isPermaLink="true">https://blog.gumshoe.dev/a-quirk-regarding-type-assertions-and-switch-statements-in-go</guid><category><![CDATA[Go Language]]></category><category><![CDATA[General Programming]]></category><category><![CDATA[software development]]></category><category><![CDATA[coding]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[Matthew Smilansky]]></dc:creator><pubDate>Tue, 02 Jan 2024 03:56:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1704167912990/a2d4e9ae-7f9f-49cd-9d57-c60f7ef82538.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>During my journey of learning Go, I've come across a confusing yet interesting quirk regarding type assertions.</p>
<p>I've learned that when running a <code>switch</code> statement on a value's type, <strong>you can match a type that is different than the value's declared type if the value's underlying type satisfies the matched type.</strong></p>
<p>That might have been a mouthful, but I'll explain exactly what I mean in great detail.</p>
<p>Take the following code for example:</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>

<span class="hljs-keyword">type</span> Color <span class="hljs-keyword">struct</span> {
    name <span class="hljs-keyword">string</span>
}

<span class="hljs-keyword">type</span> Join <span class="hljs-keyword">interface</span> {
    Mix(o Color)
}

<span class="hljs-keyword">type</span> Combine <span class="hljs-keyword">interface</span> {
    Mix(o Color)
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(c *Color)</span> <span class="hljs-title">Mix</span><span class="hljs-params">(otherColor Color)</span></span> {
    fmt.Printf(<span class="hljs-string">"%v mixed with %v = %v-%v!"</span>, c, otherColor, c, otherColor)
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> blue Combine = &amp;Color{<span class="hljs-string">"blue"</span>}

    <span class="hljs-keyword">switch</span> v := blue.(<span class="hljs-keyword">type</span>) {
    <span class="hljs-keyword">case</span> Join: 
        fmt.Printf(<span class="hljs-string">"%v is a Join."</span>, v)
    <span class="hljs-keyword">case</span> Combine: 
        fmt.Printf(<span class="hljs-string">"%v is a Combine."</span>, v)
    }
}
</code></pre>
<p>Here, we have a struct <code>Color</code> and two interfaces, <code>Join</code> and <code>Combine</code>, that both contain the same method signature, <code>Mix(o Color)</code>.</p>
<p>Below these definitions, we define a function <code>Mix</code> whose receiver type is <code>*Color</code>. This means that <code>*Color</code> satisfies both the <code>Join</code> and <code>Combine</code> interfaces due to its implementation of the <code>Mix</code> method.</p>
<p>Now, here's where things get confusing (and interesting):</p>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> blue Combine = &amp;Color{<span class="hljs-string">"blue"</span>}

    <span class="hljs-keyword">switch</span> v := blue.(<span class="hljs-keyword">type</span>) {
    <span class="hljs-keyword">case</span> Join: 
        fmt.Printf(<span class="hljs-string">"%v is a Join."</span>, v)
    <span class="hljs-keyword">case</span> Combine: 
        fmt.Printf(<span class="hljs-string">"%v is a Combine."</span>, v)
    }

}
</code></pre>
<p>What do you think the output of this code should be? This, right?</p>
<p><code>&amp;{blue} is a Combine</code></p>
<p>Wrong! We get this instead:</p>
<p><code>&amp;{blue} is a Join</code></p>
<p>But why? The answer lies in what I stated before:</p>
<p>"<strong>You can match a type that is different than the value's declared type if the value's underlying type satisfies the matched type.</strong>"</p>
<p>So let's go over this in greater detail:</p>
<p>Here are the facts:</p>
<ul>
<li><p>The value against whose type we're matching: <code>blue</code></p>
</li>
<li><p>The value's declared type: <code>Combine</code></p>
</li>
<li><p>The value's underlying type: <code>*Color</code></p>
</li>
<li><p>The type the value matched: <code>Join</code></p>
</li>
</ul>
<p>Due to the fact that the value's (<code>blue</code>) underlying type (<code>*Color</code>) satisfies the matched type (<code>Join</code>), it will match <code>Join</code> and not the expected type (i.e., the declared type <code>Combine</code>). It's really that simple.</p>
<p>I thought this was an interesting quirk and I'm doing my due diligence by documenting my learning process here so that others may avoid the headache of misunderstanding later on.</p>
<p>Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Understanding git diff Output]]></title><description><![CDATA[git diff output can be extremely confusing. This article seeks to demystify the command's output syntax.]]></description><link>https://blog.gumshoe.dev/understanding-git-diff-output</link><guid isPermaLink="true">https://blog.gumshoe.dev/understanding-git-diff-output</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[version control]]></category><category><![CDATA[Technical writing ]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Matthew Smilansky]]></dc:creator><pubDate>Sun, 18 Jun 2023 21:28:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/wX2L8L-fGeA/upload/e97ac92078f6fb93e818f123b252964d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><code>git diff</code> can be a confusing command to understand. In this tutorial, I aim to demystify the command by clarifying its ambiguities and clearly outlining its syntax so you never have to go "huh?" when it comes to <code>git diff</code> ever again.</p>
<h1 id="heading-what-is-a-diff">What is a Diff?</h1>
<p>In Git, a diff shows the changes between two different states of your repository. These are some common comparisons that can be made using the <code>git diff</code> command:</p>
<ul>
<li><p>The working tree (or working directory) and the index (the staging area)</p>
</li>
<li><p>The working tree and another tree</p>
</li>
<li><p>The main branch and a feature branch</p>
</li>
<li><p>The local repository and the remote repository</p>
</li>
</ul>
<p>A good way to internalize the purpose of <code>git diff</code> is to remember that it is meant to show us the <em>difference</em> between two specific states of your project at different stages. If you wanted to know the <em>difference</em> or <em>diff</em> between your working directory and your staging area, you would use <code>git diff</code> to portray this <em>difference</em>.</p>
<p>As I've already stated, you can use <code>git diff</code> to show the changes between the different states of your repository. For the sake of this tutorial's main purpose, which is to clarify the <code>git diff</code> output syntax, I will demonstrate a basic example that uses <code>git diff</code> without arguments. In this form, <code>git diff</code> shows changes between the working tree and the index, also known as the working directory and staging area, respectively.</p>
<h1 id="heading-code-along-example">Code-Along Example</h1>
<p>For this example, I urge you to code along, but it is not required.</p>
<h2 id="heading-step-1-create-a-new-git-repository">Step 1: Create A New Git Repository</h2>
<ul>
<li><p>From anywhere on your computer (this example will assume we are starting from our home directory), run the following commands, which will:</p>
<ul>
<li><p>Create a new directory named <code>git_diff_tutorial</code>.</p>
</li>
<li><p>cd into that directory.</p>
</li>
<li><p>Initialize a new Git repository.</p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-bash">mkdir git_diff_tutorial
<span class="hljs-built_in">cd</span> git_diff_tutorial
git init
</code></pre>
<h2 id="heading-step-2-create-a-new-file-and-add-content">Step 2: Create a New File and Add Content</h2>
<ul>
<li><p>Run the following commands, which will:</p>
<ul>
<li><p>Create a new file, <code>a.txt</code>.</p>
</li>
<li><p>Add content to <code>a.txt</code>.</p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># From within ~/git_diff_tutorial, run these commands:</span>
touch a.txt
<span class="hljs-built_in">echo</span> <span class="hljs-string">"This is the change in the staging area."</span> &gt; a.txt
</code></pre>
<h2 id="heading-step-3-add-the-change-to-the-staging-area">Step 3: Add the Change to the Staging Area</h2>
<ul>
<li><p>Run the following command, which will:</p>
<ul>
<li>Add <code>a.txt</code> to the staging area:</li>
</ul>
</li>
</ul>
<pre><code class="lang-bash">git add a.txt
</code></pre>
<h2 id="heading-step-4-add-more-content-to-the-file">Step 4: Add More Content to the File</h2>
<ul>
<li>Now that you've added content (i.e. made changes) to the file and staged the file with said changes to the staging area, let's add some more content to the file, which will result in a <em>difference</em> between the version of the file as it exists in the staging area and the version of the file in the working directory:</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># For the curious, -e enables interpretation of backslash escapes; this allows us to add an escape sequence for a newline (\n) so that we have two lines in our file.</span>
<span class="hljs-built_in">echo</span> -e <span class="hljs-string">"\nThis is the change in the working directory."</span> &gt;&gt; a.txt
</code></pre>
<ul>
<li>Now, run <code>git status</code> so that we may see the current status of our working directory:</li>
</ul>
<pre><code class="lang-bash">$ git status                                                             

On branch main

No commits yet

Changes to be committed:
  (use <span class="hljs-string">"git rm --cached &lt;file&gt;..."</span> to unstage)
    new file:   a.txt 

Changes not staged <span class="hljs-keyword">for</span> commit:
  (use <span class="hljs-string">"git add &lt;file&gt;..."</span> to update what will be committed)
  (use <span class="hljs-string">"git restore &lt;file&gt;..."</span> to discard changes <span class="hljs-keyword">in</span> working directory)
    modified:   a.txt
</code></pre>
<ul>
<li><p>As you can see, we have two kinds of changes on our hands:</p>
<ol>
<li><p>Changes to be committed (i.e., changes you've made to the file and ran <code>git add</code> on). These changes are now in your <em>index</em>, also known as the staging area.</p>
</li>
<li><p>Changes not yet staged for commit (i.e., any changes you've made to the file after the last <code>git add</code>). These changes are located in your <em>working tree</em>, also known as the working directory.</p>
</li>
</ol>
</li>
</ul>
<h2 id="heading-step-5-run-git-diff">Step 5: Run <code>git diff</code></h2>
<ul>
<li>We are now ready to run <code>git diff</code> to see our changes! Go ahead and run <code>git diff</code> without any arguments like so:</li>
</ul>
<pre><code class="lang-bash">git diff
</code></pre>
<ul>
<li>Your output should look something like this:</li>
</ul>
<pre><code class="lang-diff">diff --git a/a.txt b/a.txt
index 9db7f57..d3612ef 100644
<span class="hljs-comment">--- a/a.txt</span>
<span class="hljs-comment">+++ b/a.txt</span>
@@ -1 +1,2 @@
 This is the change added to the staging area
<span class="hljs-addition">+This is the change in the working directory</span>
</code></pre>
<ul>
<li>This is the meat of this tutorial, so let's dissect it.</li>
</ul>
<h1 id="heading-the-structure-of-git-diff-output">The Structure of <code>git diff</code> Output:</h1>
<ul>
<li>Let's go line by line:</li>
</ul>
<h2 id="heading-line-1-the-header">Line 1 - The Header</h2>
<pre><code class="lang-diff">diff --git a/a.txt b/a.txt
</code></pre>
<ul>
<li><p><code>diff</code> - This indicates the command used to generate the diff.</p>
</li>
<li><p><code>--git</code> - This indicates that the diff was produced by the Git version control system.</p>
</li>
<li><p><code>a/a.txt b/a.txt</code> - This part represents the two versions of the file being compared.</p>
<ul>
<li><p><code>a/a.txt</code> - This is version A of the file. It is the "original" or "older" version of the file. In our scenario, this is the version of the file that's sitting in the <em>index</em> or staging area.</p>
</li>
<li><p><code>b/a.txt</code> - This is version B of the file. It is the "new" or "modified" version of the file. In our scenario, this is the version of the file that's sitting in the <em>working tree</em> or working area.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-line-2-metadata">Line 2 - Metadata</h2>
<pre><code class="lang-diff">index 9db7f57..d3612ef 100644
</code></pre>
<p>This line provides some metadata about the diff.</p>
<ul>
<li><p><code>index</code> - Although "index" in the context of Git is a term that often refers to the staging area, in this context, it is being used in a similar way to how it's used in other systems that track changes, like databases or search engines. It's indicating that what follows is an indexed or key identifier of the data.</p>
</li>
<li><p><code>9db7f57..d3612ef</code> - These are the two SHA-1 hash identifiers that Git uses to refer to specific versions of the content. They are essentially "indexes" in Git's internal database of file contents, hence the preceding use of the term "index."</p>
<ul>
<li><p><code>9db7f57</code> - This SHA-1 hash identifies the "before" (version A) state of the file.</p>
</li>
<li><p><code>..</code> - These two dots are used to represent a range from one state to another. You'll see this two-dot notation in various places while using Git. Think of it this way: "the difference between <code>9db7f57</code> and <code>d3612ef</code>" or "from to <code>9db7f57</code> and <code>d3612ef</code>."</p>
</li>
<li><p><code>d3612ef</code> - This SHA-1 hash identifies the "after" (version B) state of the file.</p>
</li>
</ul>
</li>
<li><p><code>100644</code> - This is the mode of the file in octal representation, indicating it's a normal, non-executable file. On the other hand, a mode of <code>100755</code> represents an executable file. For more information on modes, you can find an explanation in <a target="_blank" href="https://git-scm.com/book/en/v2/Git-Internals-Git-Objects">Git Internals - Git Objects</a> section of the Git documentation. Using the search function (Ctrl+f or Command+f on Mac) in your browser and typing "mode" should get you where you need to go.</p>
</li>
</ul>
<h2 id="heading-line-3-file-paths">Line 3 - File Paths</h2>
<pre><code class="lang-diff"><span class="hljs-comment">--- a/a.txt</span>
<span class="hljs-comment">+++ b/a.txt</span>
</code></pre>
<p>This line shows the file paths of the files before and after the change.</p>
<ul>
<li><p><code>---</code> - These three signs are used as a matter of convention. The reason that three are used is to clearly distinguish the markers from content lines that might start with one or two minus or plus signs. For all intents and purposes, these three <code>-</code> signs represent the state of the file as it existed in its original state.</p>
</li>
<li><p><code>a/a.txt</code> - The original state of the file. The <code>a</code> before the <code>/</code> is an arbitrary identifier of the "before" state, and <em>does not</em> refer to a directory or path, even though it may seem so; it is simply a label that is used in the same way as it was in line 1.</p>
</li>
<li><p><code>+++</code> - These three <code>+</code> signs represent the state of the file as it exists after the changes.</p>
</li>
<li><p><code>b/a.txt</code> - The updated state of the file.</p>
</li>
</ul>
<p>Essentially, these lines always refer to the same file, however, they represent <em>different</em> states of that file. You could say that <code>--- a/&lt;file&gt;</code> represents where the changes "come from", while <code>+++ b/&lt;file&gt;</code> represents where the changes "go to".</p>
<h2 id="heading-line-4-hunk-header">Line 4 - Hunk Header</h2>
<pre><code class="lang-diff">@@ -1 +1,2 @@
</code></pre>
<p>To me, this is the most confusing part of the entire output. Let's dissect it:</p>
<ul>
<li><p><code>@@</code> - This marks the beginning (and later, the end) of the hunk header. It serves as a delimiter that Git uses to identify the hunk header.</p>
</li>
<li><p><code>-1</code> - This part indicates the changes in the original file (denoted by <code>-</code>). The <code>1</code> signifies that the changes begin from the first line. If, for instance, you see something like <code>-1,3</code>, it means that the changes start from the first line and span the next 3 lines in the original file. In this case, the <code>3</code> refers to the number of lines affected from the starting line onward.</p>
</li>
<li><p><code>+1,2</code> - This part indicates the changes in the updated file, as denoted by the <code>+</code> symbol. Here, the <code>1</code> indicates that the changes begin from the first line, and <code>2</code> signifies that from that starting point, there are 2 lines in the updated file, including the first line itself (thus, lines 1 and 2 are the two lines). If you encounter something like <code>+4,5</code>, it means the changes commence from the fourth line, and from there, the updated file includes a span of 5 lines (lines 4, 5, 6, 7, and 8). This span includes both the actual changes and the context around them in the new file.</p>
</li>
<li><p><code>@@</code> - This marks the end of the hunk header.</p>
</li>
</ul>
<h3 id="heading-further-clarifying-the-hunk-header">Further Clarifying the Hunk Header</h3>
<p>One crucial aspect of understanding hunks is that they include not only the changes to the file but also the <strong><em>context</em></strong> around those changes.</p>
<p>Remember that I indicated that the hunk in the updated file (<code>+1,2</code>) <em>starts</em> from the first line and includes 2 lines from that point? This hunk header doesn't imply that the first line was edited or added, but rather that the first line is the starting point for the <em>comparison</em> in this hunk.</p>
<p>When the hunk header says <code>+1,2</code>, it doesn't mean that actual changes/modifications to the file were made on both lines 1 and 2. Instead, it represents the section of the file, or the "hunk", that the changes are a part of, including both the <em>context</em> and the actual modifications. In our case, the change - an addition - is on line 2, but the hunk starts from line 1 to include some context.</p>
<p>At this point, you may be wondering why the hunk header isn't <code>+2,2</code> to indicate that the change starts and ends at line 2. The reason the hunk starts at line 1 is, again, to provide <em>context</em> (more on this below) for understanding the change; <em>context</em> enables you to see what the content looked like <em>before</em> the addition (the first line was <code>This is the change added to the staging area</code>), as well as see what the content looks like <em>after</em> the addition (<code>This is the change in the working directory</code>).</p>
<p>Another thing to be aware of is that the numbers delimited by the comma in <code>+1,2</code> do not mean "lines 1 to 2", but rather "starting from line 1, there are now 2 lines." It's about how many lines there are starting from the specified line, not a range of lines. So even if the actual addition was only the second line, <code>+1,2</code> just means there are 2 lines in the updated file starting from line 1. This is a huge source of confusion, so try to keep this in mind when reading the output.</p>
<h2 id="heading-lines-5-and-6-diff-lines-or-diff-content">Lines 5 and 6 - Diff Lines (or Diff Content):</h2>
<pre><code class="lang-diff"> This is the change added to the staging area.
<span class="hljs-addition">+This is the change in the working directory.</span>
</code></pre>
<p>Before we delve into the specific example we are dealing with, let's categorize the three types of diff lines:</p>
<ol>
<li><p><strong>Context lines</strong>: Lines that haven't changed between the two versions. These lines help you understand where in the file the changes are happening. In our example, <code>This is the change added to the staging area</code> is a context line. These lines are not preceded by any symbol.</p>
</li>
<li><p><strong>Deletion lines</strong>: Lines that were present in the old version but are not present in the new version. These lines are preceded by a <code>-</code>. Our current example does not contain such lines.</p>
</li>
<li><p><strong>Addition lines</strong>: Lines that are present in the new version but were not present in the old version. These lines are preceded by a <code>+</code>. In our example, <code>This is the change in the working directory</code> is an addition line.</p>
</li>
</ol>
<p>The diff content essentially provides a before-and-after snapshot of your file. You can see the context (what parts of the file remained unchanged), the deletions (what parts were removed), and the additions (what parts were added). In other words, the diff content shows what was, what is, and what has changed between the two compared versions. Pretty powerful stuff, eh?</p>
<p>Let's try to interpret our diff lines further:</p>
<p>Going back to the hunk header, we can comprehend that the changes in the old file started at the first line and did not extend beyond that line (<code>-1</code>):</p>
<pre><code class="lang-diff">@@ -1 +1,2 @@
</code></pre>
<p>Having interpreted our hunk header, we can clearly observe the message it communicates:</p>
<pre><code class="lang-diff"> This is the change added to the staging area
<span class="hljs-addition">+This is the change in the working directory</span>
</code></pre>
<p>The changes in the old file <em>started</em> at the first line <code>This is the change added to the staging area</code> and did not extend beyond that line. The <code>This is the change in the working directory</code> line is not part of the original (old) file's content; it represents an addition to the new version of the file. Think of it this way: due to the fact that the <code>This is the change in the working directory</code> line didn't exist in the old version, there's no way for the changes to extend that far.</p>
<p>On the other hand, the new version <em>does</em> know about the <code>This is the change added to the staging area</code> line. In fact, it uses that line as context to describe where the new change has taken place. The <code>This is the change in the working directory</code> line is then an addition made in the new file, as shown by the <code>+</code> prefix. The hunk header tells us that starting from the first line in the new file, there are now two lines (<code>+1,2</code>), which includes the original context line and the newly added line.</p>
<p>Hence, the hunk header and the following lines together give us a complete picture of the difference between the old and the new file: the context where the change has happened, what was removed or modified from the old file, and what was added in the new file. This allows us to clearly understand the evolution of the file from its old state to its new state.</p>
<h1 id="heading-another-example">Another Example</h1>
<p>Let's look at a slightly more complex example that illustrates the inclusion of deletion lines. Suppose you have the following diff:</p>
<pre><code class="lang-diff"><span class="hljs-meta">@@ -1,3 +1,3 @@</span>
<span class="hljs-deletion">-This is the old first line</span>
 This is the second line
<span class="hljs-deletion">-This is the old third line</span>
<span class="hljs-addition">+This is the new third line</span>
</code></pre>
<p>The hunk header here is <code>@@ -1,3 +1,3 @@</code>. This means that Git started comparing from the first line in both versions of the file. Note that in both the original and new versions, there were 3 lines starting from the first line.</p>
<p>Now, you might be wondering why there are four lines shown in the hunk when the hunk headers imply changes that include only three lines in both the original (<code>-1,3</code>) and updated versions (<code>+1,3</code>) of the file. This discrepancy arises because the hunk includes a <strong><em>context line</em></strong> that is unchanged in both versions of the file.</p>
<p>Remember, the hunk is not just about the changes (additions and deletions), but about the entire section of the file that those changes impact, including the context around the changes.</p>
<p>Let's dissect each part in more detail. For convenience, I will include the addition (<code>+</code>) and deletion (<code>-</code>) symbols when referencing the diff lines.</p>
<h3 id="heading-13"><code>-1,3</code></h3>
<p>The <code>-1,3</code> part of the hunk header indicates that starting from the first line of the original version of the file, there are 3 lines that are pertinent to understanding the changes that took place. These lines are:</p>
<ol>
<li><p><code>-This is the old first line</code> - This line was removed in the new version; hence, it is no longer part of the updated file. However, it is most certainly part of our old file, since it was present there.</p>
</li>
<li><p><code>This is the second line</code> - This line is present in both versions of the file; therefore, it is a context line, providing information to understand the changes better. In the updated file, this has become the first line due to the removal of the old first line.</p>
</li>
<li><p><code>-This is the old third line</code> - This line was removed in the new version of the file. However, this line was present in our old file.</p>
</li>
</ol>
<p>Some things to note:</p>
<ul>
<li><p><code>-This is the old first line</code> and <code>-This is the old third line</code> were both part of the original file but have been removed in the updated version. They are included in the diff output to demonstrate what content was deleted.</p>
</li>
<li><p>The line <code>This is the second line</code>, while unchanged in both versions, is considered part of the 3 lines starting from the first line in the original version that help us understand what changes were made. This explains the <code>-1,3</code> in the hunk header.</p>
</li>
</ul>
<p>In short, the original file, in this context, started from <code>-This is the old first line</code> and included 3 lines to fully understand the changes that took place:</p>
<ul>
<li><p><code>-This is the old first line</code> (remember, the first line is inclusive)</p>
</li>
<li><p><code>This is the second line</code>,</p>
</li>
<li><p><code>-This is the old third line</code></p>
</li>
</ul>
<p>You may be asking, what isn't this line included: <code>+This is the new third line</code>? Well, that line is part of the new version, which our old version never even knew about! Again, if a line didn't exist in the old version of a file, there's no way for the changes to extend that far.</p>
<h3 id="heading-13-1"><code>+1,3</code></h3>
<p>Looking at the new version of the file, the <code>+1,3</code> in the hunk header might seem confusing at first, because you might think it implies that three lines were added. However, remember that the numbers in the hunk header include both the changes and the context around them.</p>
<p>Here, <code>+1,3</code> tells us that from the first line of the new version of the file, there are 3 lines that are relevant to understand the changes that took place. These lines are:</p>
<ol>
<li><p><code>This is the second line</code> - This line is present in both versions of the file; therefore, it is a context line, providing information to understand the changes better. In the updated file, this has become the first line due to the removal of the old first line.</p>
</li>
<li><p><code>-This is the old third line</code> - This line was removed in the new version.</p>
</li>
<li><p><code>+This is the new third line</code> - This line was added in the new version.</p>
</li>
</ol>
<p>Even though <code>This is the second line</code> was not changed, it is included in the hunk because it provides context for the change that did occur. And although <code>-This is the old third line</code> doesn't exist in the new version, it is included in the diff output to show that it was removed. So in total, there are 3 lines starting from the first line in the new version of the file that help us understand what changes were made.</p>
<p>Again, you may be asking, why does <code>-This is the old third line</code> appear within the scope of the new version's changes? That line was part of the old file, and it was removed in the new file, so why does it appear in the span of the new changes?</p>
<p>The reason <code>-This is the old third line</code> is shown in the span of the new changes is to convey the complete picture of the transformations that took place. It's included in the <code>git diff</code> output as it allows us to understand what exactly was removed to make way for the new content.</p>
<p>I cannot stress this enough: the goal of <code>git diff</code> is not only to show us the <em>new</em> lines but also to illustrate what lines were removed or replaced. This comprehensive view of alterations, both deletions and additions, is what enables us to fully comprehend the evolution from the old version to the new one.</p>
<p>So, in the new version, while it is true that <code>-This is the old third line</code> no longer exists, its appearance in the diff output is crucial to help us understand that it was a part of the original file but was subsequently removed in the new version. Context is key.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>And that's it. I hope you enjoyed this tutorial and were able to gain some insight into how <code>git diff</code> works. I encourage you to play around in your own Git repositories and experiment with <code>git diff</code> on your own. The more <code>git diff</code> outputs you read, the better you will become at comprehending its comparisons. Take care and happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[How to Block Distractions While Coding]]></title><description><![CDATA[How to keep yourself focused while coding.]]></description><link>https://blog.gumshoe.dev/how-to-block-distractions-while-coding</link><guid isPermaLink="true">https://blog.gumshoe.dev/how-to-block-distractions-while-coding</guid><category><![CDATA[Productivity]]></category><category><![CDATA[software development]]></category><category><![CDATA[coding]]></category><category><![CDATA[life-hack]]></category><category><![CDATA[helpful]]></category><dc:creator><![CDATA[Matthew Smilansky]]></dc:creator><pubDate>Fri, 16 Dec 2022 16:27:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1671207903846/UZcXCmdK0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I'll be the first to admit: I sometimes have trouble staying focused while coding. Even though my intentions are good, I often still falter at the slightest chance of distracting myself. And to perform well doing intense and precise work such as software development, distraction isn't good - we need to remain in the context of our work environment for as long as possible without drifting off.</p>
<p>Here are some resources I use to keep myself focused while coding:</p>
<h1 id="heading-1-leechblockhttpschromegooglecomwebstoredetailleechblock-ngblaaajhemilngeeffpbfkdjjoefldkokhlen-us">1) <a target="_blank" href="https://chrome.google.com/webstore/detail/leechblock-ng/blaaajhemilngeeffpbfkdjjoefldkok?hl=en-US">LeechBlock</a></h1>
<p>You may have heard of or even used this browser extension before. It's one of the quickest and easiest ways to block unwanted websites, and it's free to boot (in fact, every resource mentioned in this article is free.)</p>
<p>Here are a few quick tips to get you started with it:</p>
<p>First, you'll need to know how to efficiently define blocked sites. In the settings page, you'll find this area where you can enter definitions of domains you want to block:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1665805705846/J_nX11I7G.png" alt="block-area.png" /></p>
<p>See the "Tip" at the bottom? It lists symbols you can use to list more specific entries. For example, if I wanted to block all subreddits on reddit.com except for r/Programming, I would define these two entries:</p>
<pre><code class="lang-plaintext">*.reddit.com
+reddit.com/r/Programming
</code></pre>
<p>This way, the distracting part of Reddit is blocked while the more useful and productive part is accessible.</p>
<p>I highly suggest you review the <a target="_blank" href="https://www.proginosko.com/leechblock/faq/">FAQ</a> for more tips.</p>
<h1 id="heading-2-distraction-free-youtubehttpschromegooglecomwebstoredetaildf-tube-distraction-freemjdepdfccjgcndkmemponafgioodelnahlen">2) <a target="_blank" href="https://chrome.google.com/webstore/detail/df-tube-distraction-free/mjdepdfccjgcndkmemponafgioodelna?hl=en">Distraction-Free YouTube</a></h1>
<p>I know, I know... how are you supposed to get any work done if you're using YouTube <em>at all?</em> Well, It's not that simple. Oftentimes, we need to use websites that can be both productive <em>and</em> distracting. YouTube is filled with some amazing resources that can boost your knowledge and skills. At the same time, the app preys on your compulsiveness with video feeds filled with clickbait titles and thumbnails.</p>
<p>The Distraction-Free YouTube extension allows you to access YouTube without all those unnecessary bells and whistles. After installation, click on the extension tray icon and choose which components of YouTube you want to hide/disable. Personally, I choose to enable all options as my default experience:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1671205031752/rt1M98GQ8.png" alt class="image--center mx-auto" /></p>
<p>This is what my YouTube homepage looks like at all times:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1671204659498/l8pg7iCRP.png" alt class="image--center mx-auto" /></p>
<p>Pretty boring, huh? As it should be!</p>
<h1 id="heading-3-minimalist-twitterhttpschromegooglecomwebstoredetailminimal-theme-for-twitterpobhoodpcipjmedfenaigbeloiidbflphlen">3) <a target="_blank" href="https://chrome.google.com/webstore/detail/minimal-theme-for-twitter/pobhoodpcipjmedfenaigbeloiidbflp?hl=en">Minimalist Twitter</a></h1>
<p>I know how we all feel about Twitter... it's the devil, it's a snake pit, nothing good ever happens on Twitter... but some people use Twitter to network, and I want to talk about a tool that can enable such people to use Twitter for what they need and avoid what they don't.</p>
<p>Minimalist Twitter gets rid of a lot (albeit not all) of the distracting features Twitter provides by default. Here's what the options menu looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1671206817822/S7gvjUUy0.png" alt class="image--center mx-auto" /></p>
<p>As you can see, the extension affords you a lot of flexibility in how you want to experience Twitter. Want to get rid of gratuitous stats such as like and follower counts? Sick of the app constantly shoving unsolicited recommendations in your face? Maybe you don't even want to see your feed at all (Zen Mode) and just want to focus on writing that witty tweet for the day. Whatever it is you're trying to avoid (or not), Minimalist Twitter's got you covered. I really do love this extension, and since I've started using it, I've noticed that I click around randomly a lot less. My experience is more purposeful and focused rather than scattered and distracted.</p>
<p>So there you have it. These extensions can help you stay focused in a distracted world. Hope it helps!</p>
]]></content:encoded></item><item><title><![CDATA[Rename Exported Notion Files With This Simple Python Script]]></title><description><![CDATA[Get rid of those ugly, auto-generated file and folder names with this simple script.]]></description><link>https://blog.gumshoe.dev/rename-exported-notion-files-with-this-simple-python-script</link><guid isPermaLink="true">https://blog.gumshoe.dev/rename-exported-notion-files-with-this-simple-python-script</guid><category><![CDATA[Python]]></category><category><![CDATA[python beginner]]></category><category><![CDATA[software development]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[Programming Tips]]></category><dc:creator><![CDATA[Matthew Smilansky]]></dc:creator><pubDate>Fri, 14 Oct 2022 20:02:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/D9Zow2REm8U/upload/v1665777590645/UMKxTP2ya.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-the-problem">The Problem</h1>
<p>When you export files from Notion, the name of each exported file and folder is appended with an ugly GUID (yuck!):</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1665777001096/CWHg27A2N.png" alt="Notion Export - Raw Output.png" /></p>
<h1 id="heading-the-solution">The Solution:</h1>
<p>Place the folder containing your newly exported Notion files into a folder that contains this file: (you'll need to create this file and copy/paste the code below into it)</p>
<p>notion-export-file-renamer.py</p>
<pre><code><span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> re 

file_regexp = r<span class="hljs-string">'( \w{32,32}\b)'</span>

def main():
    <span class="hljs-keyword">for</span> root, dirs, files <span class="hljs-keyword">in</span> os.walk(os.getcwd(), topdown=False):
            <span class="hljs-keyword">for</span> f <span class="hljs-keyword">in</span> files:
                f_path = os.path.join(root, f)
                subtitute_f_path = re.sub(file_regexp, <span class="hljs-string">''</span>, os.path.abspath(f_path))
                os.renames(f_path, subtitute_f_path)

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
    main()
</code></pre><p>For reference, please note that the folder containing your exported Notion files will be named something like this:</p>
<ul>
<li>Export-95fc3bc8-a529-4c39-b414-16d278c7d197</li>
</ul>
<p>Your working directory folder structure should now look like this:</p>
<pre><code>root/
├─ Export<span class="hljs-number">-95</span>fc3bc8-a529<span class="hljs-number">-4</span>c39-b414<span class="hljs-number">-16</span>d278c7d197/
├─ notion-<span class="hljs-keyword">export</span>-file-renamer.py
</code></pre><p>Now, Run the Python script from the root dir - again, this script should be placed in the same folder as the folder containing your exported Notion files:</p>
<pre><code>python3 notion-<span class="hljs-keyword">export</span>-file-renamer.py
</code></pre><p>Success! Your output should look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1665777354505/zOPEFkYAh.png" alt="Notion Export - Renamed Output.png" /></p>
<p>Enjoy!</p>
]]></content:encoded></item><item><title><![CDATA[How to Get the Most Out of Udemy Courses]]></title><description><![CDATA[How to get the most out of your Udemy courses.]]></description><link>https://blog.gumshoe.dev/how-to-get-the-most-out-of-udemy-courses</link><guid isPermaLink="true">https://blog.gumshoe.dev/how-to-get-the-most-out-of-udemy-courses</guid><category><![CDATA[learning]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[General Advice]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Matthew Smilansky]]></dc:creator><pubDate>Mon, 18 Apr 2022 18:46:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1665778452631/7Bx9iqfD3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We live in an amazing time; the amount of resources available to developers is at an all-time high, and there's simply no excuse to find yourself in the dark when it comes to obtaining the knowledge you need to foster the skills you desire. Udemy is one of the best resources for learning on the web and my personal favorite, and their courses are effectively "permanently on sale" (there's no reason to buy a course at full price, just wait a few days for the inevitable "sale"). Heck, there's a sale going on as I'm writing this article!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650131604813/chWRCxEte.png" alt="Udemy Sale.png" /></p>
<p>So how do we maximize this potential for learning? Here's a few tips on how to get the most out of your Udemy courses.</p>
<h2 id="heading-take-notes">Take Notes</h2>
<p>The absolute best way to get the most bang for your buck out of Udemy is to relentlessly take notes during the course. But don't worry, you don't necessarily have to write out all the notes by hand. At the bottom of the media player, there's a button called "Transcript":</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650307748429/kfzxjvIl1.png" alt="Transcripts.png" /></p>
<p>Click on that and it will bring up, well, the transcript of the entire video. From there you can go ahead and copy/paste the relevant text into your notes. The only problem is that the text you copy includes all the line breaks as well, so what I personally do is use one of my favorite tools for merging text lines: <a target="_blank" href="https://www.browserling.com/tools/join-lines">https://www.browserling.com/tools/join-lines</a> Paste your copied text in the box, click "Join Lines", then click "Copy to Clipboard". Now you have text from your lecture with no line breaks, all ready to be pasted into your note-taking app of choice. Neat, eh?</p>
<h2 id="heading-watch-at-a-slower-speed">Watch At a Slower Speed</h2>
<p>I know, I know - you're taking a 48 hour course and that's long enough as it is. I hear you! But hear me out... There's a few good reasons you should (not always, but sometimes) watch your lectures at a slower speed. </p>
<p>For one, there are some lecturers out there who simply talk too fast; in that case, watching at a slower speed is almost essential. But here's the biggest reason: the knowledge you're consuming is <em>complicated</em>. I mean, that's the prime reason you're taking a course in the first place, right? To learn about something you don't understand well if at all. Watching lectures at a slower speed will enable you to focus better on each part of the lecture rather than letting the words blow you by. I've found that if the lecture is too fast and the content is complicated, I tend to rewind the video anyway so I can hear it for a second or third time.</p>
<h2 id="heading-watch-lectures-multiple-times">Watch Lectures Multiple Times</h2>
<p>The great thing about taking an online course is that you can not only work at your own pace, but you can view the content as many times as you like. Take advantage of this fact. It sometimes takes me three or more sit-throughs to fully absorb the material presented. There's no need to feel discouraged or demoralized by the fact that it's not clicking on the first watch. Again, these lectures can be complicated. I remember watching Jonas Schmedtmann's explanation of the concept of JavaScript closures several times before I began to understand it even a little. </p>
<p>(by the way, please take <a target="_blank" href="https://www.udemy.com/user/jonasschmedtmann/">Jonas Schmedtmann's courses</a> on Udemy if you are a beginner web developer (or even an experienced one.) He is one of the best instructors on the platform, if not the entire web.)</p>
<h2 id="heading-supplement-your-learning-with-outside-resources">Supplement Your Learning With Outside Resources</h2>
<p>This is a big one. Oftentimes, I'll find that a certain lecture just doesn't cut it. Either the lecture fails at explaining a core concept in an effective way, or I fail to understand the explanation. Either way, knowledge isn't being imparted. In this case, I would highly suggest that you supplement the courses you're taking with other resources. Honestly, you should be doing this anyway. Sometimes it takes just one other person explaining a concept in a certain way for it to click in a way that just isn't being done in the course by the lecturer. And that's fine so long as <em>most</em> of the course content is clicking. If not, you might find yourself with a course that isn't doing for you what you thought it would. Luckily, Udemy provides a "30-Day Money Back Guarantee" policy on all courses, so make sure to take advantage of that as well.</p>
<h2 id="heading-read-the-qandampa-section">Read the Q&amp;A Section</h2>
<p>The Q&amp;A section has saved me a lot of frustration throughout my time on Udemy. You can filter questions by lecture, which lets you tackle problems specific to the content you're currently watching. Not only that, lecturers and their TA's will often respond directly to questions, comments, and concerns.</p>
<p>So there you have it. I hope this article leaves you armed with the tools needed to make the most out of your Udemy courses.</p>
]]></content:encoded></item></channel></rss>