188 TILs and counting...

Import external stylesheet into a layer

I’m working on a legacy project that’s stuck on v3 of bootstrap and just loads the full minified css file. We wanted to make it a bit easier to override some of the builtin styles and figured that the new @layer feature of CSS would be perfect. I didn’t want to change too much about the stylesheets were aren’t and thankfully it turns out you can import a stylesheet into a layer: ...

Lowercase head behaves differently in git worktrees

Today I discovered that referencing HEAD in git commands should technically always be uppercase. On case-insensitive file systems you can use lowercase head most of the time and it just works… as long as you don’t use worktrees. If you use head while in a worktree then it resolves to the head of the main worktree and not the head of the worktree you’re currently in like you would expect. ...

You can use C# records in .NET Framework 4.x

Today I learned that you can use C# records that were introduced in C# 9 even if you’re not on .NET Core yet. NDepend has a post on how to do this which is slightly more involved. But per this Stack Overflow answer, all I did was add a file with the following: namespace System.Runtime.CompilerServices { internal class IsExternalInit { } } and that worked. I’ve been using them in unit tests like this post describes.

 · 1 min · 

You can backup your git stashes

As of Git 2.51 there is now a process for backing up your git stashes. The gist of it is there is now stash export command to export your stashes as a single reference and push them to a remote: git stash export --to-ref refs/stashes/my-stash git push origin refs/stashes/my-stash and then on another machine or a different clone of the repo: git fetch origin '+refs/stashes/*:refs/stashes/*' git stash import refs/stashes/my-stash Unfortunately this process isn’t that great for regular backups but can be useful if you need easily move lots stashes to another machine. For one off stashes though, it might be easier to create a patch file.

ICS end dates are exclusive

Today I learned that per the spec, the DTEND value in an ICS file is exclusive for all-day events. It makes sense but it’s not how most people think of date ranges. I ran into this while making a small node script that takes a json array of events and generates an ICS file. This has been the most convenient way I’ve found to quickly bulk create events in Google Calendar. The only issue is the multi-day events were coming up a day short. ...

 · 1 min · 

Apply a patch file

Today I learned how to create and apply a patch file with Git. If you want to quickly create patch a file from your current changes just run: git diff > mypatch.patch or if like me you just want specific changes then stage them and then run: git diff --cached > mypatch.patch then to apply the changes all you need is git apply mychanges.patch Unfortunately if there are conflicts then git will just give you an error: patch does not apply ...

Share git configuration in repo

Today I learned that you can share a git config file in a repository for easily sharing certain local config settings with your team. git config --local include.path ../.gitconfig This adds the following to your local config [include] path = ../.gitconfig and will load any config values set in that file. This has a couple advantages in that we only have to run a single git command and if we need to make future changes we only have to update the config file instead of requiring devs to run additional commands to get the update. ...

Quickly Fix A Misspelled Word

I just learned that you can have automatically fix a misspelled word with the top suggestion by typing: 1z= This is opposed to the regular z= command for opening the regular list of spelling correction options. Like Josh who I learned this from, I usually pick the first option so this is a bit more convenient.

Sudo for Windows

I just learned that Windows now has a builtin sudo command. You need to enable it from the Windows developer settings and then you use it similar to sudo on other operating systems. I’ve been using gsudo for some time and I still prefer as it overall has a nicer experience and is more fully featured, but if you’re looking for one less thing to install then the builtin sudo is decent. ...

Use skip-worktree to ignore modified files

Today I learned about the --skip-worktree command in git which will treat a file like it hasn’t been modified. This is useful if you have to modify a file locally but don’t ever want to commit it (config files are a common scenario). Like me, you may have seen --assume-unchanged used in this way but that’s not what it’s meant for since it’s “designed for cases where it is expensive to check whether a group of files have been modified”. As a result you’re likely to lose the changes you have made to those files. This post shows a good summary of the outcomes of common operations with each command. ...