-
posts
-
TIL: Neovim Double Filetype
Sometimes you want to identify certain types not just by their base format but by a higher level format. For example, GitHub Actions are YAML, but they are a special kind of YAML and if you know that you can do added checks on it etc. Neovim (and maybe Vim as well?) has the ability to mark files with multiple file types at once by joining them with a dot. This is most useful for adding a kind of filetype annotation. For example, I can create the type yaml.ghaction which will denote that the file is YAML so it gets...
-
TIL: Aqua CLI Version Manager
When I worked on the SLSA project I came across the Aqua CLI version manager. It’s a pretty cool tool that acts sort of like a package manager for CLI binaries. The aqua generate -i command allows you to search for commands via the Aqua registry and saves the tool dependency in aqua.yaml. checksum: enabled: true require_checksum: true supported_envs: - all registries: - type: standard ref: v4.333.3 # renovate: depName=aquaproj/aqua-registry packages: - name: rhysd/actionlint@v1.7.7 - name: koalaman/shellcheck@v0.10.0 - name: jqlang/jq@jq-1.7.1 - name: mvdan/sh@v3.11.0 - name: JohnnyMorganz/StyLua@v2.0.2 - name: Kampfkarren/selene@0.28.0 Another thing that’s cool is that it can keep a checksum...
-
TIL: Go's errors.Unwrap doesn't work with errors.Join
Go 1.20 included the ability to wrap multiple errors at once.
joinWrapped := fmt.Errorf("%w:%w", errors.New("error1"), errors.New("error2"))
However, this is implemented using errors.Join which returns an error that implements the Unwrap() []error method. This means that the returned error cannot be used with errors.Unwrap.
fmt.Println(errors.Unwrap(joinedErr)) // nil
There doesn’t seem to be an equivalent to errors.Unwrap for errors returned by errors.Join so it seems impossible to traverse errors using only errors.Unwrap. You’ll need to cast the error to an interface that implements Unwrap []error.
type joinedError interface {
Unwrap() []error
}
jw := joinWrapped.(joinedError)
fmt.Println(jw.Unwrap()) // [error1 error2]
-
TIL: Go's sort.Find function
Today I learned about the sort.Find function in the Go standard library. It performs a binary search over a sorted array when provided with a comparator function.
sorted := make([]string, 150)
slices.SortFunc(sorted, strings.Compare)
// Search for target in sorted from [0,n)
target := "some query"
n := len(sorted)
if i, found := sort.Find(n, func(i int) int {
return strings.Compare(target, sorted[i])
}); found {
fmt.Println("value found at index %d", i)
}
This worked well for a searching simple dictionary index in the go-stardict library I’ve been working on.
-
TIL: Grouping Dependabot updates
Today I learned, Dependabot has a way to group updates by type. This page has some examples of how to do this. Optimizing the creation of pull requests for Dependabot version updates I had some experience using Renovate to group updates when working on slsa-github-generator (renovate.json) but I didn’t realize that Dependabot has this feature too. I think it’s a somewhat recent feature. For npm I group minor and patch updates into PRs by development dependencies and production dependencies. Major version updates get their own PRs. - package-ecosystem: "npm" directory: "/" schedule: interval: "monthly" groups: # Group all dependencies by...
-
Today I Learned
I’ve added this new section to the site which will include short posts on things
that I’ve learned recently. I was inspired by Simon Willison’s TIL
site
(repository), which was inspired by Josh
Branchaud’s post “How I Built a Learning
Machine” (and
his TIL repository jbranchaud/til), which
itself was inspired by the idea of “Learn in
Public”.
Hopefully, it will be a place where I can write down my thoughts to help them
solidify in my mind without too much overhead.