173 TILs and counting...

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.

Vim sets auto marks

Today I learned that Vim has some special marks which it sets automatically: Command Description `. jump to position where last change occurred in current buffer `" jump to position where last exited current buffer `0 jump to position in last file edited (when exited Vim) `1 like `0 but the previous file (also `2 etc) '' jump back (to line in current buffer where jumped from) `` jump back (to position in current buffer where jumped from) '[ or '] jump to beginning/end of previously changed or yanked text '< or '> jump to beginning/end of last visual selection The funny thing is VsVim displays these in the gutter by default and I never knew what the symbols meant. Vscode-vim has an option to display marks in the gutter but only the regular marks and not these.

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

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

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 · 

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