128 TILs and counting...

Blob URLs

Today I learned that in a web page, when you’re working with Blob or File objects you can call URL.createObjectURL() to create a Blob URL that can be used as the source for anything that normally takes a URL like images or download links. It’s also apparently a good alternative to base64 encoded Data-URIs especially when dealing with larger amounts of data since a base64 encoded file will be 33% larger than the raw binary....

November 2, 2023 · 1 min · Brandon Pugh

every() returns true for an empty array

Today I learned that the javascript array method .every() will always return true for an empty array. [].every((x) => x > 1); // true [].every(() => true); // true [].every(() => false); // true For me at least, this was a bit surprising and I realized I’d been thinking about this function works incorrectly. Your first thought might be that this is another one of javascript’s quirks, but this is actually how most languages implement similar functions including Rust, Python, and C#:...

November 1, 2023 · 1 min · Brandon Pugh

Calling an extension method on a null instance

Today I learned that you can call an extension method on a null instance of the type. I had always assumed without thinking about it too hard, that the reason string.IsNullOrEmpty isn’t defined as an extension method in the framework is because you would get NullReferenceException. But if we were to define an extension method like public static bool IsNullOrEmpty(this string s), and call it like if(s.IsNullOrEmpty()) this is just syntactic sugar for if(StringExtensions....

October 19, 2023 · 1 min · Brandon Pugh

Zeal offline documentation browser

Today I learned about a cool project called Zeal that let’s download and browse the documentation for a bunch of projects. I’ve always liked the idea being able to continue working even without internet.

October 18, 2023 · 1 min · Brandon Pugh

Conditional logic in pipelines YAML

Today I learned that you can have conditional expressions in Azure Pipelines YAML files: steps: - script: tool env: ${{ if parameters.debug }}: TOOL_DEBUG: true TOOL_DEBUG_DIR: _dbg ${{ else }}: TOOL_DEBUG: false TOOL_DEBUG_DIR: _dbg

October 16, 2023 · 1 min · Brandon Pugh

Toggle CSS classes in Devtools

Today I learned that the little .cls button in the Chrome devtools is a handy way to toggle classes on an element: I imagine the trend of using utility classes was the main motivation for this feature (although apparently it’s been there for a few years and I only just figured out what it was for).

October 13, 2023 · 1 min · Brandon Pugh

Copy git link extension

Today I learned about the Copy Git Link extension for Visual Studio which will give you the url of currently selected lines on your git hosting provider i.e azure devops or GitHub. Especially handy for quickly pointing a teammate to a particular part of the codebase.

October 11, 2023 · 1 min · Brandon Pugh

Git rerere

If you’ve ever had to abort a rebase or merge but didn’t want to waste the work you already did resolving merge conflicts, then you should enable the git rerere option: git global config rerere.enabled true It stands for Reuse Recorded Resolution, and it essentially remembers how you resolved a merge conflict and will automatically reapply if it sees it again. Resolving conflicts with git-rerere

October 5, 2023 · 1 min · Brandon Pugh

git-absorb

One of my favorite git plugins is git-absorb (which is a port of Mercurial’s absorb). It basically helps you create --fixup commits automatically, which you can then use an interactive rebase with autoSquash to “absorb” them into your previous commits. I tend to use it when I’ve made a bunch of small tweaks to my feature branch, especially from automated feedback from a PR bot, I’ll then stage the changes and git-absorb will find the previous commit on my branch that also modified those same lines....

October 4, 2023 · 1 min · Brandon Pugh

push.autoSetupRemote

Today I learned about the git config setting push.autoSetupRemote that was added in version 2.37.0. Like Tekin mentions in his post, I’ve had a git alias to do create my upstream branch but I still forget sometimes. To me this seems safe to enable by default with: git config --global --add --bool push.autoSetupRemote true and git will now set the upstream tracking branch for you!

October 3, 2023 · 1 min · Brandon Pugh