126 TILs and counting...

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鈥檝e 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鈥檛 seen easily done in any git client....

November 21, 2024 路 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鈥檛 committed to the repository. For me this is handy for some tooling configuration files that I use personally but don鈥檛 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....

November 19, 2024 路 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鈥檛 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 """....

November 18, 2024 路 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鈥檛 familiar with SRI, this post does a good job explaining why it鈥檚 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鈥檛 provide them and I came across this handy generator which let鈥檚 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....

November 12, 2024 路 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鈥檒l 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....

November 7, 2024 路 1 min 路 Brandon Pugh

View transitions API

Today I learned about the new view transitions API and I was pretty impressed with how much of the heavy lifting the browser will now do for you to animate between states. Adam Argyle has a fun talk where he shows what you can do with this new API. I only had to add a couple of lines of javascript to animate reordering a list of items that would have required a more complicated technique like FLIP (first last invert play) in the past....

October 22, 2024 路 1 min 路 Brandon Pugh

Console.trace()

Today I learned about console.trace() when I needed to find out where a global function was being overridden: Object.defineProperty(window, 'setErrorMessage', { set(value) { console.trace('Global variable set:', value); } }); This little snippet outputs a stack trace anywhere code was trying to define this global function and let me right to the culprit. See more about .trace()

October 10, 2024 路 1 min 路 Brandon Pugh

History API state

Today I learned that you can actually store state in the browser history via the history API (note this is not the query string). I came across in this post that uses it as a clever method for temporarily storing form data.

October 7, 2024 路 1 min 路 Brandon Pugh

Chain-of-Thought Prompting

Today I learned about Chain-of-Thought Prompting which is a technique to get potentially better results from an LLM where you craft your prompt with an example of the chain of thought or steps in reasoning to solve a complex problem. This gives a good explanation: https://www.promptingguide.ai/techniques/cot

September 20, 2024 路 1 min 路 Brandon Pugh

HTTP files

Today I learned about .http files that you can use to make/test requests to any api endpoint from within most IDEs/editors. This started with the Rest client vscode extension and then Visual Studio 2022 added support somewhat recently. It kinda acts like an alternative to something like Postman but without leaving your editor, but for me the nice thing is it can act like a runnable form of documentation for your api that you can commit alongside your code....

September 13, 2024 路 1 min 路 Brandon Pugh