188 TILs and counting...

Dotnet StringSyntaxAttribute

Today I learned about the StringSyntaxAttribute added in .NET 7. It’s a handy attribute you can add to string properties to specify exactly what format the string should be in. This gives you extra IDE assistance like syntax highlighting and intellisense 🔥. And you can also use a comment like /*lang=xxx*/ for regular variables. Read Steve’s post for more detail.

 · 1 min · 

Use the element for light/dark images in markdown

Thanks to James’ post, today I learned that you can use the <picture> to display different images based on whether or not the set a preference for light or dark mode. The key is using the prefers-color-scheme CSS media query <picture> <source media="(prefers-color-scheme: dark)" srcset=" https://user-images.githubusercontent.com/25423296/163456776-7f95b81a-f1ed-45f7-b7ab-8fa810d529fa.png " /> <img alt="Shows an illustrated sun in light color mode and a moon with stars in dark color mode." src="https://user-images.githubusercontent.com/25423296/163456779-a8556205-d0a5-45e2-ac17-42d089e3c3f8.png" /> </picture> Since HTML is valid in markdown, you can easily use this technique in a number of places including Github—which apparently has allowed the use of the picture element since 2022. This is much better than the custom syntax they had before. ...

Use jq to get a list of deeply nested values from JSON

I needed the list of extensions from the extensions.json that looks like this: [ { "identifier": { "id": "asvetliakov.vscode-neovim" }, "version": "1.18.22", ... }, ... ] I hadn’t used jq before but knew this was exactly what it was made for. In this case all I needed was this: jq '.[].identifier.id' extensions.json Also they have a pretty cool Playground for experimenting or running one-off queries.

 · 1 min · 

Github supports alerts in markdown

Today I learned that Github supports alerts in markdown using the blockquote syntax: > [!NOTE] > Useful information that users should know, even when skimming content. This is an extension to the standard markdown syntax that I’ve seen supported more and more in various markdown tools like Obsidian and vscode (they’re also referred to as callouts or admonitions).

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?

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: ...

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. ...

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 · 

setSelectionRange in Safari will focus the input

Apparently in Safari, setSelectionRange() will focus the element even when not focused despite MDN stating that “The element must be focused for the call to have any effect”. According to this bug, this is considered intended behavior even though it’s inconsistent with MDN and the other browsers. It’s worth noting though, during my testing, I noticed that Chrome/Firefox will update the selection and cursor position you just won’t see it unless you programmatically call .focus() on the element.

Stash changes in the index

I just recently discovered that Git 2.35 added the --staged option to the git stash command. This makes it easy to quickly stash only the changes that you’ve staged.