188 TILs and counting...

Run a bash script from Powershell

You can execute a bash script from Powershell on Windows by typing bash if you’ve enabled WSL. For example bash ./new-til.sh. Some caveats though: Make sure you use / instead of \ in the file path Make sure the bash script was saved with unix line-endings You can also make a wrapper script for scripts you regularly execute like new-til.ps1: bash ./new-til.sh $args If you don’t or can’t enable WSL, you can use sh.exe that’s optionally installed with Git for Windows. For example sh ./new-til.sh ...

Create new files faster

You can use ctrl+shift+a to open the new quick add dialog in VS 2022: https://devblogs.microsoft.com/visualstudio/adding-new-files-just-got-a-lot-faster/

 · 1 min · 

Hide a table in sql server management studio

Apparently in sql server you can mark any table as a system table using EXEC sys.sp_MS_marksystemobject and then Management studio will hide it automatically. I ran into this because the docs say that Entity Framework 6 stores its code-first migration snapshots in a table called __MigrationHistory but I couldn’t find it because it’s hidden since it’s marked as a system table.

Use ChatGPT to explain bash scripts

Today I learned that chatGPT is pretty good at explaining cryptic bash scripts and commands. I was trying to understand exactly how a git prepare-commit-msg hook was working so I asked chatGPT to “explain the following git hook to me” and it did a pretty good job. For example, it returned tidbits like: [[ $BRANCH_NAME =~ $BRANCH_REGEX ]]: This conditional statement checks if the branch name matches the BRANCH_REGEX pattern. If the branch name starts with one or more digits, this condition will be true. and: sed -i.bak -e "1s/^#${BASH_REMATCH[1]}: //I" $1: This line uses the sed command to replace the branch number (captured by the BRANCH_REGEX pattern) and a colon at the beginning of the commit message with an empty string. The I flag makes the replacement case-insensitive. The -i.bak option creates a backup of the original commit message file with a .bak extension. ...

Use a table variable to hold a list of values

You can store a “list” of values in sql with a table variable. DECLARE @listOfIDs TABLE(id INT); INSERT INTO @listOfIDs SELECT id FROM Transactions WHERE USER='bob';

Stacking context affects z-index

In CSS, the stacking context can impact which elements display on top of each in addition to the z-index. So if you end up in a situation where cranking up the z-index doesn’t seem to work, the stacking context is likely the issue. I technically learned this a while ago but completely forgot about it until I was just reminded about it by a coworker dealing with this issue. Josh Comeau explains it well in his post on stacking contexts.

GetUnderlyingType

In c# Nullable.GetUnderlyingType(type)will return null if the type is not Nullable<T>. For some reason this is not what I expected.

Use core.hooksPath for shared hooks

Sometime around 2019, git added the core.hooksPath config setting to change the directory where git will look for hooks. This is handy for commiting shared hooks into a repo so you no longer need workarounds like a script to copy them into the default $GIT_DIR/hooks folder or creating symlinks or relying on tools like Husky. This post is a good example of how you can use it.