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"
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"
I recently discovered the Pretty Typescript errors Vscode extension that makes complicated Typescript errors much more readable in Vscode
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. ...
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: ...
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”. ...
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.
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.
I just learned that git reset has a --keep parameter. This works the same as --hard except that it won’t discard any uncommitted changes. It’s meant to be used when we want to remove some of the last commits in the current branch but if there could be conflicts between the changes in the commits we want to remove and our uncommitted changes, then the reset is blocked. I’d been using git reset --hard and just double checking I didn’t have anything uncommitted but I’ll be defaulting to --keep except if I’m intentionally trying to clear out my changes.
I recently learned that there are actually several ways to add comments in JSX in React. I had known about the {/* comment */} syntax but didn’t realize you could use // within a jsx element: function MyComponent() { return ( <div> <Hello message="Hello, World!" // message prop requires a string /> </div> ) }
You can search through git history not only by the text of a commit message but by the contents of the diff of commits. This is commonly referred to as the git pickaxe and you invoke it with the -S parameter to git log i.e. git log -S 'public void SomeMethod and you’ll get every commit that touched that method signature or even one that deleted it. Some git clients will expose this as an option in a search field but if that fails the git cli lets you include additional filters like author or file path or even use regex with the --pickaxe-regex switch. ...