130 TILs and counting...

npmpackage.info

I recently discovered this handy site that aggregates all usual info I tend to look at when deciding whether or not I want to pull in an NPM package as a dependency. npmpackage.info Some things I tend to look at: When was the last version published? How many sub-dependencies does it have? With the rise in supply chain attacks, newer packages try to minimize these with some advertising zero dependencies How much will it add to bundle size? I usually check Bundlephobia and this displays the stats from there along with everything else How widely used is it?

 · 1 min · Brandon Pugh

uv package manager

I recently came across this post, Uv has a killer feature you should know about, which led me to discover the uv package and project manager for Python. This seems to be the new preferred tool for managing python versions/dependencies as it’s faster and can replace pyenv, pip, virtualenv, and others. It just saved me some headache as I tend to mostly use python for various tools and I tried to install a package the other day with pip install but it failed with some inscrutable error. Then I realized the package wouldn’t work with python 3.13 which I’d been using — and python 3.12 was causing a sub dependency to throw warnings — but 3.11 turned out to be the lucky version which uv made it easy to setup with: ...

 · 1 min · Brandon Pugh

A single input in a form can submit

Today I learned that if you have a single text field in a form then browsers will automatically submit it when you press enter. <form> <label> Search <input type="text"> </label> </form> This is kinda handy since normally you need to add a submit button to be able to submit a form — but, you should be aware that if you add another field then you do need to add a submit button for the form to work. ...

 · 1 min · Brandon Pugh

Type check and cast

Today I learned that you can use pattern matching in C# to check for a type and cast to it in the same expression. See the docs for more details. Microsoft even has a lint rule for it. if (x is Fruit) // Noncompliant { var f = (Fruit)x; // or x as Fruit // ... } if (x is Fruit fruit) { // ... }

 · 1 min · Brandon Pugh

Selectively restoring changes from another branch or commit

Today I learned that you can use the --patch parameter with several git commands. The --patch parameter is probably most known for interactively staging changes from the cli, but I’ve never really used it because I find GUI clients are much more convenient for this. But apparently you can also use it with restore/checkout to grab specific changes from another branch. git restore --source=branch-name --patch This is something I haven’t seen easily done in any git client. ...

 · 1 min · Brandon Pugh

Personal git ignore per repository

Today I learned that git has a $GIT_DIR/info/exclude file can contain additional patterns of files to ignore but isn’t committed to the repository. For me this is handy for some tooling configuration files that I use personally but don’t want to clutter the main .gitignore of the repo. If there are some files that you want to always ignore, then you can specify a global ignore file in your git config with core.excludesFile. ...

 · 2 min · Brandon Pugh

Raw string literals in C# 11

Today I learned about raw string literals introduced in C# 11. The big improvement to me is that you don’t need to escape double quotes. So no more of this noise if you need a json string: string json = @" { ""number"": 42, ""text"": ""Hello, world"", ""nested"": { ""flag"": true } }"; You can now write: string json = """ { "number": 42, "text": "Hello, world", "nested": { "flag": true } } """; The other nice feature is that an extraneous indentation will stripped out based on the location of the closing """. 🔥 ...

 · 1 min · Brandon Pugh

SRI integrity hash algorithms

Today I learned that you can actually specify different hash algorithms for Subresource Integrity (SRI) hashes. If you aren’t familiar with SRI, this post does a good job explaining why it’s useful and how it would have mitigated the recent pollyfill.io incident. I needed to add the hashes to some scripts from a third party CDN that didn’t provide them and I came across this handy generator which let’s you choose which algorithm to use and defaults to SHA-384 and report-uri has a generator that just includes all 3 different hashes in the integrity value. ...

 · 1 min · Brandon Pugh

Use URLSearchParams() to build a query string

Today I learned that javascript has a handy built-in function called URLSearchParams() that you can use to build a url query string from an object. const petfinderData = { key: "12345", shelterID: "abc00", count: 20, animals: ["dogs", "cats"], }; const query = new URLSearchParams(petfinderData); // returns "key=12345&shelterID=abc00&count=20&animals=dogs%2Ccats" const queryString = query.toString(); Read more: https://gomakethings.com/how-to-build-a-query-string-from-an-object-of-data-with-vanilla-js/ You’ll want to be careful with complex object list arrays since it serializes to a form like animals=dogs,cats, which not be the format the server expects. Asp.net model-binding for instance, by default expects a format like animals=dogs&animals=cats (and some other variations). ...

 · 1 min · Brandon Pugh

Edit commit message with git reword

I discovered that a reword option was added to --fixup back in git 2.32 The basic command looks like git commit --fixup=reword:<commit> and you can use it like you would the other autosquash commands. I recommend creating an alias for it though. Thanks to this post, I’ve had a fixup alias that uses fzf to select form recent commits so I created a similar one for reword: [alias] reword = "!git log -n 50 --pretty=format:'%h %s' --no-merges | fzf | cut -c -7 | xargs -o -I{} git commit --fixup=reword:{}" Note, if you’re on Windows, you can install fzf via Chocolatey. And you might also be interested in PSFzf which a Powershell module that wraps fzf. ...

 · 1 min · Brandon Pugh