188 TILs and counting...

Null values in javascript interpolated strings

Today I learned about a key difference between how javascript handles null values in interpolated strings compared to a language like C# In C#: var param1 = null; var queryString = $"param1={param1}"; // => param1= In Javascript var param1 = null; var queryString = `param1=${param1}`; // => param1=null the latter is probably not what you want since your api will likely set param1 to a string value of “null”.

 · 1 min · 

Object.fromEntries

Today I learned about Object.fromEntries() in javascript which essentially lets you convert a list of key/value pairs into an object (this is the same as the lodash function fromPairs). This came in handy when I needed to convert a list of entities into a lookup object like: Object.fromEntries( users.map((user) => { return [user.id, user.isSelected]; }) ); // => { '1': true, '2': false, '3': false }

 · 1 min · 

Emulate page focus

Today I learned about a devtools feature that helped me debug the styling of an element that would disappear when the input element lost focus which happens when you click over to the devtools. If you press ctrl+shift+p to open the command palette in DevTools, and type “focus”, you’ll see a command to “Emulate a focused page” which will leave the focus on the element in the page even when you click into the DevTools. ...

 · 1 min · 

Ternary in C# string interpolation

Today I learned you can have ternary expressions inside of interpolated strings, you just need to wrap it in parenthesis: $"{timeSpan.Hours} hour{(timeSpan.Hours > 1 ? "s" : "")} ago"

Pretty Typescript errors Vscode extension

I recently discovered the Pretty Typescript errors Vscode extension that makes complicated Typescript errors much more readable in Vscode

 · 1 min · 

Ignore commits in Git Blame with –ignore-revs-file

Today I learned that you can ignore commits in Git blame on Github with a .git-blame-ignore-revs file in the root of your repo! I’d known about the git config blame.ignoreRevsFile config option where you can point it to a file with a list of commit IDs to ignore which is especially useful for those annoying commits in a repo where whitespace was cleaned up or every tab in the codebase was replaced with spaces. You have to run the config command locally but now apparently Github does it automatically. ...

Git branch –force

Today I learned about the --force parameter of git branch which will take an existing branch and point it to a different commit. This is another handy alternative to git reset --hard for some common scenarios. For example, if I forgot to create a new feature branch and accidentally made some commits onto main, I can run the following: git checkout -b new-branch # create the new branch and switch to it git branch --force main origin/main # fix main back to what it should be vs what I would do before: ...

Find all CSS changes in Chrome DevTools

Today I learned about the Changes tab in Chrome devtools. When you’re tweaking CSS styles in Chrome DevTools, you can see all the changes you’ve made by clicking the “Changes” tab in the bottom “drawer” in DevTools. It’s especially nice because you can then copy the changes to your clipboard and paste them into your actual source file. You can open it from the command palette (ctrl+shift+p) and typing “show changes”. ...

 · 1 min · 

Javascript Array.prototype.with()

I just discovered the with() method which takes an index value and a value to insert at that index and returns a new array with the value inserted at the index. const arr = [1, 2, 3, 4, 5]; const newArr = arr.with(2, 'a'); console.log(newArr); // [1, 2, 'a', 4, 5] You could do this before with something like arr[2] = 'a' but that would modify the original array. The with() method became widely supported in 2021. Read more about the with() method and alternatives in Stefan Judis’ post.

 · 1 min · 

Awesome AZD templates

Today I discovered the Awesome AZD templates site which is essentially a curated gallery of a bunch of templates for deploying to Azure with the new Azure developer cli. There are even several for integrating with ChatGPT like ChatGPT + Enterprise Data with Azure OpenAI and Cognitive Search.