<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Duncan McArdle on Medium]]></title>
        <description><![CDATA[Stories by Duncan McArdle on Medium]]></description>
        <link>https://medium.com/@duncan-mcardle?source=rss-8a0ae3058048------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aQ3fDncTTyYvTT_C</url>
            <title>Stories by Duncan McArdle on Medium</title>
            <link>https://medium.com/@duncan-mcardle?source=rss-8a0ae3058048------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:52:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@duncan-mcardle/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to write beautiful, interactive Slack posts (Slack Block Kit)]]></title>
            <link>https://duncan-mcardle.medium.com/how-to-write-beautiful-interactive-slack-posts-slack-block-kit-bdd7313c5f6e?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdd7313c5f6e</guid>
            <category><![CDATA[slack-formatting]]></category>
            <category><![CDATA[slack-tips-and-tricks]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[slack-message]]></category>
            <category><![CDATA[slack-block-kit]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Mon, 21 Nov 2022 09:01:56 GMT</pubDate>
            <atom:updated>2022-11-21T09:01:56.633Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wanted to convey information via Slack in a more visually appealing way? Slack makes it super simple to add emphasis to your messages in typical ways (bold, italics, underline, strikethrough, etc.), but fails to go beyond the basics, and doesn’t even implement the full range of formatting options available in the markdown concept that it utilises.</p><p>What they do to bridge this gap however, is to provide a tool called Block Kit. Think of Slack’s Block Kit as a tool to create beautiful and interactive messages, 1 block at a time, and then send them to whoever / wherever you want, all from a web interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LxaObTFGnVAuamsId8MgQ.png" /><figcaption>Before (typical formatted Slack message)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWv0nFanTBFSO0sfkqieWA.png" /><figcaption>After (Slack Block)</figcaption></figure><h3><strong>Benefits of a Slack Block</strong></h3><p>The first and most important benefit of a Slack Block is the visuals it enables you to create. Visuals are massively important when it comes to increasing engagement and ensuring your messages get seen, and by embedding images and varying layouts you can keep your posts fresh and eye-catching.</p><p>Arguably the most important improvement to visuals is the ability to embed images. Typically with Slack, any image placed into a message will appear as a thumbnail at the bottom of a message, with limited / no ability for you to decide how and where it gets displayed. With Block Kit, you’re in complete control over where the images go, and can embed different sized images (and even hyperlink them) in order to really jazz things up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*s_EEOvB_-p44WYMH-qanbA.png" /><figcaption>How a text / image post normally looks (image underneath the text)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Su4qnbvmLeZWquE3jx-Lg.png" /><figcaption>Here’s how a text / image post can look with Slack’s Block Kit (text before and after the image)</figcaption></figure><p>In addition to getting your messages seen, you can also help ensure they’re interacted with. Block Kit allows you to embed interactive elements, such as buttons and text inputs, or even full forms, to make it incredibly simple for your readers to interact with your message. Doing this means your users are kept in the context / window of Slack, and makes them much more likely to complete an action than if they have to click a link to an entirely different website.</p><h3><strong>Making a Slack Block</strong></h3><p>Block Kit works by structuring your message into blocks, using a text format called JavaScript Object Notation, or JSON for short. If you’re in the world of engineering you’ll no doubt be more than familiar with JSON, but if you’re not then don’t worry, it isn’t especially hard to learn (<a href="https://www.freecodecamp.org/news/what-is-json-a-json-file-example/">here’s a tutorial to follow</a>). Additionally Slack provide a simple GUI to help you build your messages, so you may be able to get by without knowing it, especially if you’re only looking to make simple blocks or to edit the contents of existing ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8B_eoL-Lgw0bU54IMkCqwQ.png" /><figcaption>Slack preview on the left, JSON on the right</figcaption></figure><p>As you change your code, you’ll see that not only does the preview on the side change, but so too does the URL. This is because rather than have you log in and store your Blocks, Slack’s Block Kit instead stores all of the information in the URL itself. This means that you can easily share a Slack Block with anyone by sending them the (often incredibly long) URL. Even better: they can open it up, make changes, and it’ll only affect their version, which they’ll then have a new URL for.</p><h3><strong>Tips</strong></h3><p>Block Kit is a fantastic resource, but it isn’t exactly user friendly. Here’s a few tips and tricks I’ve learnt from my short time experimenting with it.</p><h4><em>Bookmark your Slack Block URLs</em></h4><p>Because the URL is updating every time you make a change, there is a super simple way to keep your Slack Blocks: bookmarking.</p><p>Rather than downloading the JSON code and storing it somewhere, simply bookmark your Slack Block with a helpful title. Next time you want to make a Block, open up whichever one most closely resembles the new Block you want to make, start editing, and then bookmark the finished product.</p><p>Do remember though that if Slack were ever to change the process, or if you were to lose your bookmark, then that Slack Block would be <strong>very</strong> difficult to recover. So perhaps save a copy of the Slack Blocks that you absolutely cannot afford to lose.</p><h4><em>Never start from scratch</em></h4><p>The thing about Slack Blocks is that whilst they provide fantastic functionality not normally available in Slack, they take an incredibly long time compared with the alternative. It’s obviously not worth an hour of effort to make a post that only 4 people take 30 seconds to read, so a big tip I have is to never start from scratch.</p><p>When you need a Block, go back through your bookmarks (see above) and find one that most closely resembles the Block you wish to make. Next, make the changes required to get what you need. Finally, bookmark the modified version so that it’s ready for you to use again next time.</p><p>By following this process you take your Block construction time down from minutes/hours to seconds/minutes, and build a library of great looking Blocks whilst you’re at it.</p><h4><em>Images (and their sizes)</em></h4><p>Whilst Slack don’t publish official advice on what size to make your image, I’d recommend going big and allowing it to be scaled down. I typically make my images 1,200px wide, which is much bigger than they’re ever likely to be displayed.</p><p>Once you’ve created your image, you’ll need to upload it to an externally visible image host like Imgur, in order to embed it into your Blocks.</p><h4><em>Send it to yourself first</em></h4><p>You might think you’ve created something truly wonderful, but whilst the Block Kit preview is helpful, I’ve found it only <em>mostly</em> shows you how it’ll look on Slack. For a more accurate representation and to make <em>absolutely sure</em> there aren’t any spelling mistakes, you can set yourself as the target when sending a Block to Slack, which will allow you to preview it exactly as it will appear in a channel.</p><h4><em>Break the JSON to stop it updating</em></h4><p>Whilst the live updating preview window can be super helpful for seeing how your changes will look in a real message, it can also be frustrating when it blocks you from making changes whilst it re-renders the preview. To “pause” the live preview from updating, just throw an extra } at the end of the code, which will cause it to be invalid JSON and thus stop the preview from working or updating.</p><p>Just don’t forget to remove the } once you’re ready for it to update, and especially before you send it!</p><h3><strong>We’ve only scratched the surface here</strong></h3><p>Slack Blocks can become incredibly complicated and incredibly powerful tools that form integral parts of (or even entirely replace) your existing workflows. I’ve not gone into detail on the various powerful features they offer here because it would be a huge topic, but what I will do is link you to the <a href="https://api.slack.com/block-kit/building">official Slack documentation</a>, which will take you through various tutorials on Block building and interactivity, as well as a bunch of templates to help you get started.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdd7313c5f6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quantifying Happiness — by listing 3 positive things per day]]></title>
            <link>https://duncan-mcardle.medium.com/quantifying-happiness-by-listing-3-positive-things-per-day-1350bce31d19?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/1350bce31d19</guid>
            <category><![CDATA[happiness]]></category>
            <category><![CDATA[shawn-achor]]></category>
            <category><![CDATA[the-happiness-advantage]]></category>
            <category><![CDATA[quantifying-happiness]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Thu, 17 Mar 2022 17:19:35 GMT</pubDate>
            <atom:updated>2022-03-17T17:19:35.839Z</atom:updated>
            <content:encoded><![CDATA[<h3>Quantifying Happiness — by listing 3 positive things per day</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*b141EQdbIRzegygk" /></figure><p>Several months back I read what quickly became one of my favourite books of all time, <a href="https://www.shawnachor.com/books/happiness-advantage/"><em>The Happiness Advantage</em>, by Shawn Achor</a>. The reason I loved it so much? It did something I didn’t think possible: it <em>quantified</em> happiness.</p><p>Now, quantifying things is something my number-minded brain loves. I can’t easily pick between two identical looking umbrellas on Amazon, but if one of them has 1,000 reviews at 4.9/5.0, and the other has 2,000 reviews at 3.8/5.0, then I’m buying the first one.</p><p>But there are certain things in life you simply can’t quantify, and it’s typically the important stuff: love, health, happiness, etc. However what you can do, is analyse people’s opinions and experience on these subjects, and then quantify that analysis, and that’s exactly what Shawn Achor did.</p><p>Now I won’t go too much into Shawn’s book — other than to repeat that it is absolutely fantastic and that you should read it — but what I did want to do was to report back on one of the exercises Shawn suggests you do.</p><h4>The exercise</h4><p>In the book, Shawn suggests that you note down 3 positive things every day. These can be absolutely anything (so long as it truly happened) and can have had as a big an impact as to make you leap for joy, or as little as to make you crack a small smile. If it made you happy, it can go on the list.</p><p>So I set a daily reminder right before I went to sleep, to look back over the course of the day and find 3 positive things. I then completed this task without fail for around 6 months, adding the entries each day into an (eventually very long) list.</p><p>The idea behind this exercise is that it makes you consciously aware of what makes you happy throughout your day. The intention is that over time, you learn to recognise <em>what</em> makes you happy, and perhaps even to realise just <em>how many</em> things make you happy.</p><p>If I’m honest, that didn’t happen for me.</p><p>In reality what I found was that whilst writing down these things did force me to think back over my day and really look for sources of happiness, what it really did was to quickly highlight days where I actually struggled to find 3 positive things.</p><p>Now, this isn’t a slight on… my life. For most of this experiment I was working a job I enjoyed in a part of the world I love, surrounded by family and friends. But the sad reality of life (especially mid-COVID life) is that some days you really don’t have anything good going on. Some days are… normal workdays, and you might genuinely not crack a smile or leave the house.</p><p>Of course, those days are few and far between, and it’s <strong>far</strong> more likely that I simply didn’t <em>recall</em> smiling at the end of the day, rather than that it never happened in the first place.</p><h4>Categorising the results</h4><p>Whilst the results of this experiment were interesting, they weren’t at all quantifiable, and once again: I’m powered by numbers. So, I set about categorising the entries in order to allow me then quantify the results.</p><p>It’s worth pointing out that there was a lot of crossover here (if you went for a coffee walk with friends, was that “socialising”, “outdoors” or “food/drink”?), so the data isn’t perfect, but here are the categories I decided upon:</p><ul><li>Family</li><li>Food &amp; Drink</li><li>Gaming</li><li>Health &amp; Fitness</li><li>Money (saving)</li><li>My newborn child</li><li>My wife</li><li>Other</li><li>Outdoors</li><li>Personal Progression</li><li>Productivity</li><li>Socialising</li><li>Tesla</li><li>Work</li></ul><p>Before we continue, it’s probably worth pointing out a few things here:</p><ol><li>Part-way through the experiment I bought a Tesla, and am a massive Tesla geek. Unsurprisingly, this had an impact</li><li>Also part-way through the experiment, my first child was born. Again, this had an impact. More of an impact than the Tesla? Well, I like to refer to them both as my babies, and one of them is <em>much</em> quieter than the other</li><li>These categories were decided <em>after</em> the experiment rather than before, as I really had no idea what would end up in this list beforehand</li></ol><h4>The results</h4><p>Not all that surprisingly (for me at least), food &amp; drink proved to be the single biggest source of happiness over the experiment. Now, if you’re my wife or child, you may be a little offended here, but rest assured that in most cases those incidents of food and drink <em>included</em> you (and if that fails… I’m very sorry).</p><p>What was interesting however was that although my professional work ranked highly (11.4% of all happiness), it did not come close to representing the amount of my time spent on it (roughly 36% of my waking time, and 24% of my total time). Now, I’m in the lucky group of people who actually <em>enjoy</em> my work, but something about these numbers leads me to question if I’m enjoying it enough? Is a salary justification enough for an underrepresented amount of happiness? It’s an interesting question, albeit perhaps a little too philosophical for this post, so I’ll get back to the numbers.</p><p>Another noteworthy category was productivity, which caused more than double the amount of happiness as health &amp; fitness. This was an interesting one for me, as I consider myself fairly fond of health &amp; fitness, however I can understand it, given my love for doing things better and more efficiently (I’m real fun at parties, honest).</p><p>Everything else was more or less expected. My newborn child, family and my new Tesla all ranked highly, but see for yourself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*mKJRITSC9VQUqn23t_ixJQ.png" /></figure><h4>Did the experiment help or change anything?</h4><p>I had hoped going into this that I might come out of it with a newfound sense of “Well, turns out I love &lt;thing&gt;, so I’ll do more of that!”, however that sadly hasn’t been the case. Whilst food &amp; drink ranked highly, it isn’t practical for me to eat out or experiment with some new recipe 3 times a day, and it’s even less likely that those experiments would go perfectly (and thus result in a point of happiness) every single time.</p><p>It has however helped me to identify day-to-day when “happy” things occur, and has made me somewhat more aware and appreciative of them.</p><p>So a <em>good</em> outcome, but not a life-changing one, unfortunately.</p><h4>Unexpected bonus: Looking back at your happy moments</h4><p>One thing that I really enjoyed from this experiment, was the ever-growing list of unusual points of happiness I recorded. It’s a list I will likely keep forever, and one I will look back at periodically for a reminder of the things that brought a smile to my face.</p><p>Case in point: several months back, I apparently had a “good avocado experience”… 🥑</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1350bce31d19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating from GitLab to GitHub]]></title>
            <link>https://duncan-mcardle.medium.com/migrating-from-gitlab-to-github-623d70b7b842?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/623d70b7b842</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[acquisition]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Wed, 23 Feb 2022 15:06:46 GMT</pubDate>
            <atom:updated>2022-02-23T15:06:46.430Z</atom:updated>
            <content:encoded><![CDATA[<p>Having recently undergone an acquisition, I was tasked with the fairly standard post-merger task of migrating our existing codebase over to the new parent company. Luckily for me, both sides used Git. Unluckily for me, one side used GitLab (us), and the other used GitHub (them).</p><p>Now, given that both use Git, you’d be right for assuming that this is not <em>that</em> hard of a thing to accomplish. However, below are a few of the tips and tricks I learned along the way to <em>improve </em>the quality of the migration.</p><p><strong>Note:</strong> This article is by no means a representation of the <em>best</em> way to perform this migration, but rather my findings from the way I did it.</p><h3>The Method of Code Migration</h3><p>Unsurprisingly, there are a variety of ways to migrate projects in this Git-centric environment.</p><h4>GitHub Importer</h4><p>GitHub themselves, keen to pull in as many new (ideally paying) users as possible, provide a simple import tool:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*rEFLgFkuVMx-6FjcCCYrHw.png" /><figcaption>How to access the GitHub importer</figcaption></figure><p>You simply specify the URL of the existing repository, as well as a few key details, and then let it do the rest for you.</p><p>It’s worth mentioning however that for this to work, you’ll need your existing repository to be open to the internet (which, if you’re using an on-prem instance of GitLab, it probably isn’t). You’ll also need to have 2FA turned off (which, unless you’re a monster, you will have on), or to use a 2FA code generated by GitLab.</p><p>All in all this method works very well. It’s highly compatible with different version control systems, pulls through all the branches, and is reasonably quick. However, it’s a manual process, which if you’re importing a large number of repositories will get tedious very quickly. In addition, the need to open your GitLab environment up to the open internet may mean this is a non-starter for you.</p><h4>3rd Party Migration Tools</h4><p>There are of course other tools for this process available on the internet. Typically they work by checking out your projects and pushing them to GitHub — much like the next section — but what I personally found was that I had a hard time trusting these tools. Those that were open-source tended to be semi-abandoned, and those that were closed-source were… closed-source.</p><p>When it comes to migrating what is of course a software company’s most valuable asset, I didn’t really want to take the risk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*cVrszHfLNpUfNwuW" /><figcaption>There’s little more important to a software company than its code.</figcaption></figure><h4>Scripts</h4><p>I’m a software engineer, so of course the idea of writing my own script came to mind. In addition, <a href="https://docs.github.com/en/rest">the GitHub API</a> is truly wonderful. It covers just about every conceivable thing you could do on GitHub, and covers it well.</p><p>Accordingly, I wrote a script that did a variety of things:</p><ol><li>It checked out all existing repositories from GitLab, re-pointed them to a GitHub of my choosing, and pushed them all (the actual migration)</li><li>It checked out all GitLab and GitHub repositories side-by-side (for ensuring the migration had worked successfully)</li><li>It deleted all repositories on the target GitHub server (for clean-up after test runs — note that this script only worked on non-production GitHub’s, or else I’d risk deleting some valuable corporate property!)</li></ol><p>In the end, this was the approach I went with. It was straightforward enough to do in minimal time, but versatile enough to allow me to account for the various additional requirements of our specific migration. In addition, it was scalable enough to allow me to migrate anywhere from 1 to 1,000 repositories in a few seconds per repo (depending on size).</p><p>P.S. As this script was written on company time, I won’t be posting it here for public consumption, though I will include some snippets below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*2QDEdRAFKevgqfux" /><figcaption>If you want something done right, do it yourself (even Git migration scripts)</figcaption></figure><h4>A Note on Merge Requests</h4><p>Unfortunately, GitLab Merge Requests (MRs) and GitHub Pull Requests (PRs) are not the same. They’re very similar, but they don’t follow a standard implementation like Git itself does. What that means is that MRs cannot be drag-and-dropped onto GitHub. Conversion must take place.</p><p>In the end, I decided this was more hassle than it was worth, and opted to drop the MRs themselves (much like the GitHub importer does). Obviously, the code commits that came from those MRs still exist, so you could argue little was lost, but if you are adamant about keeping MRs, you may wish to consider another option.</p><h3>Pre-Migration Activities</h3><p>In addition to running the actual migration, there are a few pre-migration activities I’d definitely recommend carrying out.</p><h4>A Spreadsheet (who doesn’t love a spreadsheet?)</h4><p>As a lover of spreadsheets, this one was a no-brainer. Before I started anything, I created a spreadsheet and entered all my repositories into it. This then gave me a central point in which to manage not only the migration progress of each repository, but also to automate the creation of certain things, such as JSON data.</p><p>My migration scripts all ran on JSON data (no surprise there), but rather than enter it all myself, I had the spreadsheet create it for me. To give you an example, I wanted to apply topics for each repository (to be covered in more detail later), but some of these topics were project-specific. By flagging this in the spreadsheet, I was able to generate an array of topics to be applied to each project, and insert it right into the JSON data for that repository.</p><p>As another example, when the migration was over, the spreadsheet was also used to generate the Git switching commands (covered later) that were given to each developer.</p><p>This isn’t to say this sort of thing couldn’t be done in the migration script itself (it definitely could have been). But by using a spreadsheet I was able to present a non-technical, high-level overview of the overall migration, and distribute it to the relevant people, including those who were only interested in the number of projects remaining.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*i0z15GG__up-7yv1" /><figcaption>Those Excel formulas you learned in high school finally have a chance to shine</figcaption></figure><h4>Renaming Projects</h4><p>One thing I needed to address early on, was the fact that repositories on the target GitHub followed a naming convention that ours didn’t currently adhere to. This was a trivial thing to address with a formula in the spreadsheet, which then output the new name into the JSON data, which in turn was fed to the migration script.</p><p>What I actually found however was that it made more sense to rename the repositories on the existing source control (GitLab) <em>before</em> migrating. This meant there were no confusing mid-migration-renames to worry about, and that the development team only had to redirect their projects post-migration, not rename them as well.</p><h4>Adding Secondary Emails</h4><p>One issue with migrating from an on-prem GitLab instance to a cloud-based GitHub one, was that user accounts were not consistent across the two. If a developer committed to GitLab with amy@yourcompany.com, they probably didn’t also have a GitHub account under the same email. So, when the migration was done, you had an existing user of amy@yourcompany.com, and a new user of amy@gmail.com going forward.</p><p>Now, this is obviously only an issue if your users switch to personal GitHub accounts post-migration, however that is what I would personally recommend they do. The reason for that is that then all of their GitHub activity is in one place, and they have easy access to other projects they may have published or contributed to, which may in turn aid their development.</p><p>Some users will prefer to keep their professional and personal programming separate, and of course that’s absolutely fine. However, in cases such as ours (the company being acquired), they may still be changing emails to one belonging to the new company, and thus will still face the same issue.</p><p>So what I realised early on was that in GitHub, you can add as many additional emails as you like, and that will then link you to any commit made under any of those addresses. This means that you can, to your personal GitHub account, add your work email, and your new work email (if going through an acquisition). Then, once the migration is over, all commits made under any of these email addresses will link back to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*Thd-1l6yDpqw-5ryjQYD4A.png" /><figcaption>How my GitHub account looked for the migration (with emails redacted)</figcaption></figure><p>Of course, it’s important you ask your developers to do this prior to the migration. But it’s a fairly trivial task and will ensure they have GitHub access early on, which is definitely something worth doing.</p><h4>Test Runs</h4><p>I’d like to think this point is too obvious to say, but I’ll say it anyway: You should always test your migration to a non-production environment first. Ideally, you should also test migrating <em>from</em> a non-production environment, but I appreciate that’s a little more cumbersome to set up.</p><p>It’s quick and easy to set up a GitHub (if you haven’t already got one), and you can use your own as a target for testing the migration. Just make sure you adjust the target URLs to your account, set the projects to private, and ensure you delete everything after you’re done.</p><h3>Post-Migration Activities</h3><p>Getting your code across may be all you need to achieve. But below are some additional things I had to take care of.</p><h4>Assigning Topics</h4><p>One feature that the target GitHub made use of which didn’t exist in GitLab was topics. Most were a fairly generic company-division topic, but others were project-specific. The way I managed the creation of the list of topics was to (mostly) automate it on the master spreadsheet, which in turn generated an array of topics as part of the JSON used to feed the migration. Once again, spreadsheets to the rescue!</p><p>The actual application of the topics was a fairly simple API request:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7aee1271a213321d443655022b1e72f/href">https://medium.com/media/c7aee1271a213321d443655022b1e72f/href</a></iframe><h4>Assigning Teams</h4><p>Much like with topics, there was also a requirement to assign each repository to a target team. This was preferable to assigning individual users as it meant each repository could be assigned a team, and then the team’s members could be managed in one place. Once again this was auto-populated by the spreadsheet, and so could be manipulated to separate projects into different teams.</p><p>GitHub API to the rescue once again:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d15b497a34ca193498cb41047d4d0e5/href">https://medium.com/media/3d15b497a34ca193498cb41047d4d0e5/href</a></iframe><h4>Checking / Testing</h4><p>So you’ve just migrated the core of your company’s assets across the open internet, and are ready to decommission its old home. But before you do, you obviously want to test that everything has moved as expected.</p><p>The obvious answer here would be to run your automated tests, to build new versions and make sure they work, etc. However we all know there will be at least 1 repository in your arsenal that doesn’t have these facilities, and so it’s time to go old-school.</p><p>What I did, was to write a script to check out every project from its old home on GitLab, and every project from its new home on GitHub, and then manually ran a diff using <a href="https://winmerge.org/">WinMerge</a>. This (after some time) eventually confirmed that aside from the .git directories (which we can safely ignore), all of the code matched. The transfer had been a success.</p><p><strong>Note:</strong> If your repositories are named the same before and after migration, and you check out all GitLab projects to a folder called GitLab, and all GitHub projects to a folder called GitHub, you can just highlight the two folders and run WinMerge across everything. Running it manually per-project will take <strong>a lot</strong> longer!</p><h4>Redirecting the Development Team</h4><p>Once the code had moved across, it was time to notify the development team. But of course, they now had to begin working from the new GitHub environment.</p><p>The easy way to do this was just to have them delete their local copies and check them out fresh from GitHub, and that is exactly what I encouraged everyone to do. Nice clean checkouts, who doesn’t love a bit of spring cleaning?</p><p>But of course, some will be midway through developing a feature, or will have local stashes they don’t want to lose. Time to shine, Git:</p><pre>git remote set-url origin <a href="https://github.com/advancedcsg/isosec-commonsrc.git">https://github.com/gitHubOrganisation/target-repository.git</a></pre><p>When executed from within a repository checked out from GitLab, this simple command completely re-points it to its new home on GitHub, and the developer can carry on working as if nothing happened.</p><p>And of course, thanks to that spreadsheet we made earlier, these commands can be generated automatically for each and every repository.</p><h4>Locking GitLab</h4><p>Finally, it’s time to lock and / or close down GitLab. Don’t be scared, you’ve done your tests, confirmed the code is safely in its new home, and of course, you’ve backed up your GitLab instance just in case, right?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=623d70b7b842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating from MediaWiki to Confluence]]></title>
            <link>https://duncan-mcardle.medium.com/migrating-from-mediawiki-to-confluence-b56b74fc44f7?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/b56b74fc44f7</guid>
            <category><![CDATA[confluence]]></category>
            <category><![CDATA[wikimedia]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[acquisition]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Wed, 23 Feb 2022 14:46:33 GMT</pubDate>
            <atom:updated>2022-02-23T15:13:38.954Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most valuable assets a software company holds, is its documentation. Although not as important as the code itself, documentation can enable handovers, assist support enquiries, and just generally make life simpler for anyone and everyone associated with the software.</p><p>Whilst modern version control systems have popularised the use of markdown-based README files, and in some cases proprietary Wikis, most software companies make use of separate documentation systems. For some, this might be a collection of Word documents, or a labyrinth of interconnected Google Docs, and for others a more sophisticated system like Confluence.</p><p>In our case, we made use of MediaWiki, the underlying technology behind Wikipedia, and a very popular way of holding large amounts of documentation in an interconnected manner. Advanced on the other hand, used Confluence. Hence, a migration was required.</p><h3>Surely there’s a tool for this?</h3><p>By far the most common question at this point will be whether a tool exists for performing such a migration, and the answer is of course yes. There are a variety of options that will convert your Wikitext formatted MediaWiki content into a Confluence style, and then port it over.</p><p>But what we found, as do many companies that make use of MediaWiki, was that over time our documentation had become a little outdated, and in some cases outright incorrect. In addition, there were some orphaned pages (pages not linked to anywhere else), and some pages that belonged on a separate Confluence space entirely.</p><p>In addition, and as you might expect, the process of converting from Wikitext to Confluence is… not perfect. Despite performing the initial migration automatically, you would still be required to go in and proofread everything, fixing links and re-uploading images as you went, and doing the various other tasks required to refine the finished product.</p><p>In the end, <em>despite</em> utilising a tool, you’re still going to have to check everything manually.</p><p>So we decided to just do it manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*uNRAIzkVydP-Ziza.png" /><figcaption>Sometimes there’s no replacement for manual (digital) labour</figcaption></figure><h3>Manually migrating an entire documentation system? Really!?</h3><p>I can definitely understand if this seems unpalatable, especially if you’re staring at a MediaWiki instance with articles numbering in the thousands (or maybe more!). Luckily for us we were only looking at just over a hundred, and the exercise actually proved to be a useful activity for refining, culling and just generally updating our documentation. In fact, it represented the single biggest refinement of our documentation in its history, which can only be a good thing, especially during the acquisition and integration phase.</p><p>Now of course, I’m not here to suggest that a manual migration is the right answer for everyone. Instead, I am simply reporting some of my findings from the process, in the hope that someone out there might find it helpful.</p><h3>Lessons learned from manually migrating 100+ articles from MediaWiki to Confluence</h3><h3>Lesson #1: Using categories (and a lack thereof) to track our migration</h3><p>Luckily for us, our MediaWiki did not make use of categories. This meant I was able to create 3 categories to track how our migration was progressing:</p><ul><li>Migrated to Confluence space 1</li><li>Migrated to Confluence space 2</li><li>Not being migrated to Confluence</li></ul><p>In this example, we were splitting our MediaWiki between 2 Confluence spaces, but of course you could use more (or less). We also found that quite a few articles had become so outdated or irrelevant that they weren’t worth the trouble of migrating them, but we still needed a way of marking them as “done”, so a category was created for that.</p><p>Each time a page was migrated, we would select one of the above categories, insert the below code into the top of the article, and then un-comment the relevant line:</p><p><a href="https://gist.githubusercontent.com/DuncanMcArdle/48774b88c152d6323afdc2a0bc85d3ff/raw/f7054f7cfb1729e7f4fab6f3eeb1b9830fc0ffde/blog_migrating_from_mediawiki_to_confluence.wikitext">https://gist.githubusercontent.com/DuncanMcArdle/48774b88c152d6323afdc2a0bc85d3ff/raw/f7054f7cfb1729e7f4fab6f3eeb1b9830fc0ffde/blog_migrating_from_mediawiki_to_confluence.wikitext</a></p><p>What this did was 2-fold:</p><p>First, it categorised the page appropriately, and meant that page no longer appeared in the “uncategorised pages” section found in MediaWiki’s infamous “Special Pages” area. This meant that the “uncategorised pages” feature effectively became a migration tracker, ticking down page by page as each was migrated, until eventually there were none left, and we knew we were done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/0*hVVk9uStzMo-wP-5.png" /><figcaption>The moment this message finally appeared was a truly wonderful one</figcaption></figure><p>Second, it marked each page as migrated in unmissable red text, notifying viewers (and would-be editors) not to waste their time there on the Wiki.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/0*ucgG6rZ5-VfPeVSj.png" /><figcaption>How the top of each migrated page looks</figcaption></figure><p><strong>A quick note:</strong> We did also consider linking directly to the new post-migration Confluence URL for each page, however as the plan was always to decommission the MediaWiki instance soon after migration, we decided it probably wasn’t worth the effort.</p><h3>Lesson #2: Copy-pasting is incredibly effective (thanks Confluence!)</h3><p>It may sound a little cliché to suggest that the best way of moving content from one system to another is to copy-paste it, but surprisingly, it really is.</p><p>Confluence have done a fantastic job of making their system capable of converting incoming content to their format. As a result, even some of our most complicated MediaWiki pages were more than 90% correct after simply highlighting all the content, hitting copy, switching to Confluence, and hitting paste ( <strong>note:</strong> you should do this from viewing mode, not edit mode, or you’ll get raw Wikitext).</p><p>You will have to do some checks afterward to ensure everything went over as expected, and you may encounter issues around things like image alignment and captions, but overall this method was surprisingly accurate.</p><h3>Lesson #3: Image quality is massively reduced</h3><p>If you do use the above method of copy-pasting content, bear in mind that the image quality sent over will be the one currently on display on the Wiki, not the original, which may or may not be completely different resolutions.</p><p>The good news however, is that if you click into the image on your MediaWiki, you’ll be able to see the original quality version. You can then copy that, and paste it over the top of the newly transferred one in Confluence.</p><p>Copy-paste to the rescue (again)!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*YsgzzoWoNCTzgt-_.png" /><figcaption>See the “Original file” link at the bottom-left</figcaption></figure><h3>Lesson #4: Articles in Confluence will be owned by whoever transfers them</h3><p>One thing I only discovered after migrating 100+ articles, is that the person who migrates them then owns them in the eyes of Confluence, and is therefore subscribed to email alerts every time someone makes a change.</p><p>Every. Single. Time.</p><p>In an ideal world, you would ask the original creators of the MediaWiki articles to perform the migration, thus retaining them as the owner. But in reality this may simply not be possible, and you should instead simply unsubscribe to the articles as and when you create them in Confluence.</p><h3>Lesson #5: URLs may need to be updated (but are relatively easy to find)</h3><p>Given that MediaWiki is a system of interconnected documents, it’s a fair bet that your articles feature many internal links. This of course is a problem when you move to Confluence, as you don’t want users being sent back to the legacy MediaWiki instance when they click a link (especially after that system is decommissioned).</p><p>Luckily Confluence make it very easy to find instances where the old link has been used. By simply searching for the old URL on Confluence, it will highlight every page where the URL was used, and you can then go about tracking down the specific references, and updating them.</p><p>In addition, this is also a great time to update any references to legacy systems. In our case, <a href="https://duncan-mcardle.medium.com/migrating-from-gitlab-to-github-623d70b7b842">we also migrated from GitLab to GitHub</a>, so this same method presented a great way of updating those links in our MediaWiki / Confluence content, too.</p><h3>In closing</h3><p>All in all, the migration took around 5–15 minutes per article. That’s a small price to pay for ensuring your content is up to date, but I could see why the prospect may be a little more daunting if your articles number in the thousands.</p><p>If however, you do decide to do it manually, then I hope the above is of some help to you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b56b74fc44f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The ONLY correct way to handle users changing their email address]]></title>
            <link>https://duncan-mcardle.medium.com/the-only-correct-way-to-handle-users-changing-their-email-address-ef023bc4731f?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef023bc4731f</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[email-address]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[email-verification]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Tue, 27 Jul 2021 19:02:23 GMT</pubDate>
            <atom:updated>2021-07-27T19:02:23.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wLqqqCAScHb7DPNzvwkr-w.jpeg" /><figcaption>Hey, <em>you</em> try finding a photo of email changing!</figcaption></figure><p>Like many people who have been on the internet for more than 5 years, I have been burdened with an outdated email address for some time now. This is a common problem, whether it be something as embarrassing as an email ending “@aol.com”, or one of the equally common teenage-years “x_x_happychick101_x_x@hotmail.com” or… you get the idea.</p><p>So recently I decided it was finally time to move to a more modern email provider, which was a fairly simple thing. However what proved <em>not</em> to be a simple thing was the act of changing my email on all of my many, many accounts (200+ by my last count).</p><p>This led me on a journey that at best, took only a few minutes per website, and at worst, led to me submitting GDPR requests to delete my account data. My intention of course was a simple one: “change my email address”. But below are the realities I encountered on this journey.</p><h3>Wrong way #1: No ability to change email whatsoever</h3><p>This one really made me laugh, and happened <strong>a lot</strong>. Even some of the biggest companies in the world simply do not provide an ability to change your email address with them. Their only option is that you register a new account with your new email, and then… use that one.</p><p>The first issue with this is that you then lose access to all of your past data. Ordering groceries and want to see what you ordered last week? Log into last week’s account then. Spent weeks setting up your profile so your flight bookings are super simple? Tough luck, do it all again on your new account.</p><p>The second issue is that you end up with an orphaned old account, potentially filled with data that has no reason to exist. This led to numerous requests on my part for my old data and accounts to be deleted, which is a slow and painful process (though it has thankfully been made a <em>little</em> easier thanks to laws like GDPR).</p><p>The weirdest thing about this is that it damages the data the company hold too. Instead of having data on a user’s complete journey with them, they have multiple split records containing different pieces of data, and an additional obligation to delete some of those older accounts as they become inactive.</p><p>The only reason for this approach is because your company is lazy. Stop it.</p><h3>Wrong way #2: Requiring staff to facilitate email changes</h3><p>Sometimes I would go to change my email only to be told that I must submit a request, go on live chat, or in the worst case; pick up a phone and call in.</p><p>You might think this was more common with more sensitive accounts such as online banking, but in reality it was some of the more tedious accounts that had such restrictions (all of my bank accounts actually allowed me to change my email address without issue).</p><p>This approach does allow companies to impose a little more security, but it also makes your users unhappy, and takes up the time both of them and of your own staff.</p><p>Once again, this approach typically points to lazy system design. Stop it.</p><h3>Wrong way #3: No validation</h3><p>This was by far the most common scenario I encountered. You log into your account, click “edit” next to your email, put in the new one, and click “save”. Done.</p><p>This was heavenly and made my job 10x easier, but it isn’t in the least bit secure. For one thing, if someone were to access your account maliciously, and try to change your email address to one they have control over, this method does absolutely nothing to stop them.</p><p>Another issue is that it doesn’t verify you have access to the new email either. Oftentimes it wouldn’t even ask for you to type confirmation of the email (which is fine — who manually types emails in these days anyway!?). So I expect numerous cases of users putting the wrong new email address in and then losing access to the account.</p><h3>Wrong way #4: One-way validation</h3><p>A less common approach (but still a regular one) was for the website to verify you have access to the new email address by sending you a code or verification link. In even less common cases, they instead asked me to perform the same action on my old email, but not on my new one.</p><p>This is obviously an improvement on the above methods, but it still isn’t enough. If I’m a malicious attacker, proving I have access to the new email offers no security whatsoever. Likewise if I prove I have access to my old email, and then spell my new email wrong, I’m still screwed.</p><h3>The (only) correct way: Double validation</h3><p>As you may have guessed from the above methods, the correct way to offer email changing is to do so only once a user verifies they have access both to their old and new email accounts. This means attackers who have a user’s password but no access to their email address can’t steal their account, and stops users from innocently entering an incorrect new email, losing access to their account in doing so.</p><p>Of course, implementing this method does mean that if users lose access to their old email address, they won’t be able to change it themselves, and will instead need to contact you to verify their identity. But I personally would argue that this is far less cumbersome than the mess that will come from a user having their account (which is potentially filled with sensitive information) stolen from them because you didn’t implement basic verification measures.</p><p>One additional minor issue with this approach comes when websites use verification links rather than codes. Don’t get me wrong, I like verification links; they’re simple and pretty elegant. However the flow then becomes that you click “verify old email”, then you check your old emails and click a button, which opens a new tab, then you click “verify new email”, and repeat the process. By the time you’re done you have at least 3 tabs open, and if you only have access to your emails on a mobile device this means multiple sessions too. Codes you can type in on the initial account management tab are great at avoiding this issue.</p><h3>In closing</h3><p>So there you have it. This article represents weeks of pent-up frustration with poor UX, and even worse data protection and privacy policies. But hey, if even a single person reads this article and thinks “Oh, I should really implement double-verification”, I’ll feel like it was all for a good cause.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef023bc4731f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is LeetCode, and why do I post solutions to it on Medium?]]></title>
            <link>https://duncan-mcardle.medium.com/what-is-leetcode-and-why-do-i-post-solutions-to-it-on-medium-d40fb958bbc2?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/d40fb958bbc2</guid>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[faang]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Mon, 25 Jan 2021 19:01:15 GMT</pubDate>
            <atom:updated>2022-03-09T16:22:53.099Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is LeetCode, and why do I post solutions to it online?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ywhUR4Mw374d75Bu74N6fA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@olav_ahrens?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Olav Ahrens Røtne</a> on <a href="https://unsplash.com/license?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A few months back, I entered the crazy world of <a href="https://leetcode.com/">LeetCode</a>.</p><h3>What is LeetCode</h3><p>For those of you who don’t know, LeetCode is a site that posts thousands of coding problems at varying difficulties, and asks you to solve them, whilst providing various test cases that your solution must pass. Additionally (and in my opinion most valuably), LeetCode also has a big community of users who share and comment on solutions to said problems.</p><p>LeetCode’s most common user is someone seeking employment at one of the world’s biggest tech companies, all of whom utilise coding problems (AKA algorithmic coding) as a means of picking out the best candidates in the thousands of daily applicants they receive.</p><p>Now, the rationale here isn’t that you need to be able to come up with complicated algorithmic solutions in order to work at Google or Facebook, but rather that by learning such algorithms and applying them whilst interviewing, you show that you’re willing to go above and beyond to get the job. It’s a bit like asking 100 people interviewing to be a chef to count to 1,000,000 — you may never actually need to do it, but by trying (and potentially succeeding), you’ve differentiated yourself from the rest of the applicants.</p><p>Now that isn’t to say that you won’t ever use the kind of complex algorithms and data structures you find on LeetCode in the real world. In fact, there are some concepts, such as “Big O Notation”, that really can change your day-to-day work as an engineer. In addition, depending on the team you end up working in, graph traversal or LinkedList manipulation <em>may</em> be as common a task as writing unit testing. These companies aren’t saying you <em>will</em> use such methods during your time with them, but they want to know that if they need you to, you <em>can.</em></p><h3>Why would I want to share LeetCode solutions?</h3><p>To some, the act of posting a solution to a problem on the open internet may seem a little odd. It’s a bit like posting the answers to a test; yes readers will be able to answer the questions, but if they’re asked an even slight variation of the original question, they’ll be stumped.</p><p>But in reality, these problems rarely have a single correct answer. In fact, the process is typically more about identifying methods and applying concepts than it is arriving at a single correct solution. Even if you <em>do</em> provide a perfect solution, and one that beats out every other submission in terms of timing, you still might find another solution in the comments that makes you say “Oh, that’s a <em>much</em> better way of doing it!”.</p><p>To give you a great example; <a href="https://leetcode.com/problems/two-sum/">this LeetCode problem</a> asks you to find all pairs of numbers in an array that add to a given number. The most obvious solution to me was to loop through the array twice (one inside the other), and add all possible pairs together. This solution worked, was pretty quick for the example case of 4 numbers, and was easy to understand. But lo and behold, my submission was incredibly slow compared to others, unusably so with a bigger dataset. So I quickly jumped into the discussion and found a method that’s infinitely better; (Hash)Maps! Now not only do I have a better solution to submit, but the next time I’m writing similar code in my day-to-day work, I stop and think; “Would a Map be better here?”. None of this would be possible without sharing solutions.</p><h3>Why I started posting the solutions online</h3><p>So we’ve established what LeetCode is, as well as why you might share solutions for their problems. But why, you may be thinking, post them online?</p><h4>1. Because the LeetCode discussion section is… meh</h4><p>Although a fantastic resource for finding solution and guidance, at the end of the day the “Discuss” tab on each LeetCode problem is a fairly typical, short-form post and reply system. The vast majority of responses are short, most submissions are uncommented and underexplained, and generally speaking the whole thing is geared more towards people who are already familiar with the process, and are looking to say “Oh that approach is a little better” rather than “How on earth do I even <em>start</em> to solve this?”.</p><p>Now, that isn’t to say that every discussion is like this. Some users go out of their way to take you through their solution step-by-step, some post video walkthroughs, and some just comment their code extensively. There are plenty of great posters on LeetCode who do not fit the description above.</p><h4>2. Because it helps me learn (and not cut corners)</h4><p>When faced with a difficult problem on LeetCode, I will often (after staring at the wall for ~10 minutes) switch to the “Discuss” tab and start looking at solutions. If I’m lucky, I’ll soon have a working submission inspired by another poster, and can move onto the next problem.</p><p>But the issue here, is that taking this shortcut often leads to under-understanding a solution. Instead of coming up with it organically, and understanding the full process from start to finish, I only really understand how the solution solves the problem (it’s a bit like saying “I know 2 + 2 = 4, but I don’t know <em>why</em>”).</p><p>The fix I have come up with to this issue is to write up my solutions in a way that can guide others from start to finish. What this means is that I have to be able to fully understand the solution, in a way that would have allowed me to solve it from scratch, and to a depth at which I am capable of explaining it to the next person in the chain.</p><p>It is a strange situation where in order to understand something, I must be able to teach it to others, and I’ve found this really works for me.</p><h4>3. Because I like writing</h4><p>As a long-time amateur writer, and frequent online poster on a variety of formats, I enjoy the act of writing. Typically this has been via fiction, but I’ve found it interesting explaining technical solutions in written form, and as per my point above, have found that writing it out aids my own understanding at the same time.</p><h3>When will I stop?</h3><p>There are currently almost 2,000 problems on LeetCode. I’ll be surprised if I ever write up 10% of them, not least because beyond that point you’re often repeating the same approach in a slightly modified way.</p><p>In truth; I’ll probably stop writing up LeetCode solutions when it stops benefitting me to do so, though it sounds a little selfish to put it that way, doesn’t it?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d40fb958bbc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sorting algorithms 101]]></title>
            <link>https://duncan-mcardle.medium.com/sorting-algorithms-101-4b22a3f4064e?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b22a3f4064e</guid>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[sort]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[sorting]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Sat, 16 Jan 2021 10:34:28 GMT</pubDate>
            <atom:updated>2022-03-09T15:47:37.042Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of programming, there are many ways to sort data. For the average engineer, you might just use .sort(), perhaps with a slightly modified sorting function to return your data in a specific way. But that’s probably about the most you do.</p><p>If however you’ve ever taken an algorithms class, used LeetCode, or just dived down a little deeper into sorting performance of a platform, you’ve probably heard of sorting algorithms.</p><p>Now, make no mistake, your favourite language’s .sort() (or equivalent) already uses one of these algorithms. In fact, if we’re being honest, it probably uses it in a way that’s faster than what you’re going to write anyway. But that doesn’t mean you won’t occasionally come up against a situation where writing a custom-sorting algorithm wouldn’t benefit you.</p><p>So, in this article, I’m going to give a quick overview of the most common sorting-algorithms out there. Over time, I’ll be posting more implementation articles for sorting, and will add links to them here.</p><h4>Stable vs unstable sorting</h4><p>Before we dive in, a quick note on stable and unstable sorting. In the sorting world, we’ll often come up against multiple instances of the same value. In the array [1, 5, 7, 5, 3, 5] for example, we’ll encounter 5 three times, and so our algorithm may be doing wasted work on comparing such values together and (potentially) rearranging them.</p><p>In a <strong>stable</strong> sort, our duplicate values will remain in their original order, with no time spent rearranging them for no reason.</p><p>In an <strong>unstable</strong> sort, our duplicate values will be rearranged, with time having been spent on this during the sort.</p><p>Below is an example of this, with letters added to the duplicate values to indicate the order pre and post-sort (these letters would not be in the real data and would thus have no bearing on the actual sort):</p><p>Stable sort: [1, 5a, 7, 5b, 3, 5c] → [1, 3, 5a, 5b, 5c, 7]</p><p>Unstable sort: [1, 5a, 7, 5b, 3, 5c] → [1, 3, 5c, 5a, 5b, 7]</p><h4>1. Quick sort</h4><p>This algorithm relies on a simple premise; we sort a single value in an array of data, and then another one, and another one, until we sort the entire array. Each time we do this, we mark the now sorted point as a “pivot”, move all numbers <em>lower</em> than it to its left, move all numbers <em>higher </em>than it to its right, and then repeat the algorithm on either side of that point.</p><p>Quick sorts are great if you want to do an in-memory sort, as we are constantly swapping existing data, but picking the “right” pivot point can be the difference between a fast and slow sort. In addition, this algorithm is an unstable one.</p><p>This algorithm has a typical time complexity of O(n log n), but a worst-case of O(n²). The space complexity however is just O(log n).</p><p><strong><em>Note:</em></strong><em> You can see my post on quick-sort implementations </em><a href="https://duncan-mcardle.medium.com/quick-sort-javascript-2a8cb3a24226"><em>here</em></a><em>.</em></p><h4>2. Merge sort</h4><p>Here we split our to-be-sorted data into 2, right down the middle. Then, we run each half through the merge-sorting algorithm again, where it will be split recursively until we have just 2 pieces of data (1 on each side). From there, we re-combine each side in sorted order, until we eventually return to the top level with a sorted dataset.</p><p>This algorithm is fast, but as it involves re-creating data and lots of moving around, its perhaps not as fast as some others. It is however highly customisable and a personal favourite of mine. Oh, and it’s a stable sort, too!</p><p>Merge sorts have a time complexity of O(n log n), but a space complexity of O(n).</p><p><strong><em>Note:</em></strong><em> You can see my post on merge-sort implementations </em><a href="https://duncan-mcardle.medium.com/merge-sort-javascript-e1ee58bf5f46"><em>here</em></a><em>.</em></p><h4>3. Bucket sort</h4><p>In this algorithm, we divide our dataset into ordered buckets, sort each bucket, and then concatenate the buckets to give us a fully sorted set. This can make for a very elegant solution, especially if we pick the right number of buckets, however just like with quick-sort, picking the wrong number of buckets can slow things down significantly.</p><p>It’s also worth mentioning that once we’ve split our data into buckets, we still have to sort each bucket. This may be done with a recursive bucket sort, or we may combine bucket sort with another algorithm (common implementations seem to involve combining bucket and insertion sorts).</p><p>Bucket sorts can be fast if we pick the right number of buckets, and are also very easy to understand and implement. In addition, they are a stable sorting method.</p><p>Bucket sorts have a typical time complexity of O(n + k) (where k is the number of buckets), but a worst case of O(n²). The space complexity if O(n*k) in the worst case.</p><p><strong><em>Note:</em></strong><em> GeeksforGeeks does a great 3 minute video on bucket sort </em><a href="https://www.youtube.com/watch?v=VuXbEb5ywrU"><em>here</em></a><em>.</em></p><h4>4. Bubble sort</h4><p>In this sorting algorithm, we are simply comparing values with their immediate neighbours. The way we do this is that we loop through the dataset, and we compare the value at i with the value at i + 1 . If i is higher, than we swap the two values and increment i. After the first run, we will have identified the biggest value in the data, and moved it all the way to the right. Now on the next run, we will identify the second biggest value, and can ignore the already correctly placed value at the end of the array.</p><p>Bubble sort is an easy and intuitive algorithm to implement. It performs the sort in-place, and is stable.</p><p>In terms of complexity, the worst case for time is O(n²), however the space complexity is a wonderful O(1).</p><p><strong><em>Note: </em></strong><em>Michael Sambol does a great 2 minute video on bubble sort </em><a href="https://www.youtube.com/watch?v=xli_FI7CuzA"><em>here</em></a><em>.</em></p><h4>5. Insertion sort</h4><p>Much like with bubble sort, insertion sort loops through the values of an array, but this time it compares it with the number to its left. If the left-hand number is lower, then those two values are sorted (for now), and we move onto the next one. Once we find a value that is not lower than the one to its left, we loop through the values on its left until we can find (and place it in) its correct position.</p><p>Insertion sort is once again a very easy algorithm to implement, and is also a stable one.</p><p>For complexity, insertion sort has a worst-case time complexity of O(n²) (where the original data was presented in descending order and thus every value has to be swapped), but has a space complexity of O(1).</p><p><strong><em>Note: </em></strong><em>Michael Sambol does a great 2 minute video on insertion sort </em><a href="https://www.youtube.com/watch?v=JU767SDMDvA"><em>here</em></a><em>.</em></p><h4>And beyond</h4><p>There are a huge number of additional sorting algorithms out there, and I hope to add more to this article in the future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b22a3f4064e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode problem #39: Combination Sum (JavaScript)]]></title>
            <link>https://duncan-mcardle.medium.com/leetcode-problem-39-combination-sum-javascript-389a8a9f884?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/389a8a9f884</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 20:43:49 GMT</pubDate>
            <atom:updated>2021-01-11T20:43:49.193Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://leetcode.com/problems/combination-sum/">this LeetCode problem</a>, we’re given an array of numbers, and a target. Our job is to come up with every possible unique way to make that target by adding the numbers in the array. We can use the numbers multiple times, and the arrangement is considered unique if the quantity of at least one number is different.</p><p>For example, given the array of numbers [2, 5, 6] and a target of 12, the solutions include [2, 2, 2, 2, 2, 2], [2, 2, 2, 6] , [2, 5, 5] and [6, 6,]. [6, 2, 2, 2] is not an option because it is simply a rearrangement of the 2nd solution and thus is not unique.</p><h4>Solution: Backtracking</h4><p>The main solution here is not all that far from the brute-force option. We start at the first number, and we keep adding it until we hit the target, like so:</p><p>[2] — not enough (2)<br>[2, 2] — not enough (4)<br>[2, 2, 2] — not enough (6)<br>[2, 2, 2, 2] — not enough (8)<br>[2, 2, 2, 2, 2] — not enough (10)<br>[2, 2, 2, 2, 2, 2] <strong>— bingo! (12)</strong></p><p>Now that we have a correct combination, we can swap out the last number for each of the remaining options, like so:</p><p>[2, 2, 2, 2, 2, 5] — too much(15)<br>[2, 2, 2, 2, 2, 6] — too much(16)</p><p>Now that we’ve exhausted that, we remove that last number and try all combinations of the previous number:</p><p>[2, 2, 2, 2, 5] — too much(13)<br>[2, 2, 2, 2, 6] — too much(14)</p><p>We repeat this process until we have exhausted all possibilities starting with 2, and then we move onto the next number, following the same process.</p><p>Now, one thing you may have noticed is that even when we’ve found a combination that is greater than or equal to the solution, we continue to try other numbers, even if they’re bigger (and are thus impossible combinations). We can solve this problem by first sorting the array, which then allows us to break from the current batch once we have met or exceeded the target. Once we have done that, our complete flow looks like this:</p><p>[ 2 ]<br>[ 2, 2 ]<br>[ 2, 2, 2 ]<br>[ 2, 2, 2, 2 ]<br>[ 2, 2, 2, 2, 2 ]<br>[ 2, 2, 2, 2, 2, 2 ] <strong>— success!</strong><br>[ 2, 2, 2, 5 ]<br>[ 2, 2, 2, 6 ]<strong> — success!</strong><br>[ 2, 2, 5 ]<br>[ 2, 2, 6 ]<br>[ 2, 5 ]<br>[ 2, 5, 5 ]<strong> — success!</strong><br>[ 2, 6 ]<br>[ 5 ]<br>[ 5, 5 ]<br>[ 5, 6 ]<br>[ 6 ]<br>[ 6, 6 ]<strong> — success!</strong></p><p>As you can see, we have tried 18 different combinations, significantly less than the 27 possible combinations from the 3 provided numbers, and we have been able to do so by exiting early on some combinations, thanks to our pre-sorting.</p><p>Now that the theory’s out of the way, here’s the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c84e6d389e6f84a2a0c5df1a6e57180/href">https://medium.com/media/7c84e6d389e6f84a2a0c5df1a6e57180/href</a></iframe><p>Not great on readability (backtracking rarely is), but incredibly simple, huh?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=389a8a9f884" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode problem #237: Delete node in a Linked List (JavaScript)]]></title>
            <link>https://duncan-mcardle.medium.com/leetcode-problem-237-delete-node-in-a-linked-list-javascript-6c2277d180bb?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c2277d180bb</guid>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 20:03:23 GMT</pubDate>
            <atom:updated>2021-01-07T20:03:23.168Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://leetcode.com/problems/delete-node-in-a-linked-list/">this LeetCode problem</a>, we’re asked to delete a node from a Linked List. However, we aren’t given the Linked List’s head, and are instead provided with the node that needs to be deleted.</p><p>To be honest, this question is a little <em>too </em>simple. Thanks to the question guaranteeing that you won’t be given the tail node of a Linked List, there aren’t even any edge cases to handle, so the solution comes in at a whopping 2 lines.</p><h4>Solution #1: Replace the node with the next one</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc3b4a5ef427d5df65a4dabe0c16ffb6/href">https://medium.com/media/fc3b4a5ef427d5df65a4dabe0c16ffb6/href</a></iframe><p>This incredibly simple solution simply replace the to-be-deleted node’s value with the next one in the Linked List, as well as the next value also. This technically deletes the <em>next </em>node in the list after copying its contents, but in doing so achieves the original goal of deleting the supplied node.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c2277d180bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode problem #234: Palindrome Linked List (JavaScript)]]></title>
            <link>https://duncan-mcardle.medium.com/leetcode-problem-234-palindrome-linked-list-javascript-fc7293155c11?source=rss-8a0ae3058048------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc7293155c11</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[leetcode-solution]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Duncan McArdle]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 20:03:14 GMT</pubDate>
            <atom:updated>2021-01-07T20:03:14.702Z</atom:updated>
            <content:encoded><![CDATA[<p>In this LeetCode problem, we’re given a Linked List, and asked to determine whether or not it (or rather, its values) represents a palindrome.</p><p><strong>Revision point 1:</strong> A linked list is a data structure that consists of two properties; next which points to the next node in the list, and val which tells you the current node’s value.</p><p><strong>Revision point 2:</strong> A palindrome is something that is the same when reversed. For example, “dad” is a palindrome, as is “12321”, but “test” is not, and nor is “123”.</p><p>What we’re being asked here then, is to get the values from a Linked List, reverse them, and see if they remain the same. For example, in the Linked List 1 -&gt; 2 -&gt; 1, if we pull out the values to make the array [1, 2, 1], and then reverse it, we can see it remains the same and is thus a palindrome.</p><h4>Solution #1: Array of values</h4><p>Much like in the above explanation, our approach here will be first to loop through the values of the supplied Linked List, adding them to an array, and then to determine whether or not that array represents a palindrome.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2510630dae338a9cbbd54768e72a9d8f/href">https://medium.com/media/2510630dae338a9cbbd54768e72a9d8f/href</a></iframe><p>This approach is fast, but it isn’t great on memory, as we’re creating a new block of data that is proportionate to the original Linked List.</p><h4>Solution #2: Recursive</h4><p>In this solution, we first make a recursive call that traverses its way through the supplied Linked List. Then, as each call begins to finish (starting with the final node), we compare it with the original head. In other words, we compare the first node with the last, and then move both inward.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28d7941ae01bba913e4d85b8131df740/href">https://medium.com/media/28d7941ae01bba913e4d85b8131df740/href</a></iframe><p>It’s a clever approach and comes without the memory intensity of the former one. It’s also readable and very compact.</p><h4>Solution #3: Reversing the second-half</h4><p>Another popular approach is to reverse the Linked List from the middle point onwards, and then compare the start and end nodes, moving inwards each time. This can be done using either a recursive or iterative approach, but here we’ve done it iteratively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdfea547c6a66d4321843b0849abfc0e/href">https://medium.com/media/cdfea547c6a66d4321843b0849abfc0e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc7293155c11" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>