-
Home Assistant: using target in blueprints
TL;DR Here’s a snippet for use in Home Assistant for turning an arbitrary target selector into a list of entity ids Also here’s a low-battery warning Blueprint that uses it. I’ve been using tykeal’s Low Battery blueprint (github) in my Home Assistant setup for some time, to give me an alert on any sensor batteries that need changing. There are a number of sensors marked “battery” that I don’t care to track (for example iPhone batteries), and the blueprint has a spot where you can list entities you want to exclude.
Read more… -
Go Generics: Use Structs for Generic Arguments Lists
TL;DR I wanted to build reusable code for a pattern in Go I had to fight the type system a bit but I won in the end We can pack argument lists into structs to make the pattern generic over different sets of arguments to functions Skip to the end of the post for spoilers I have a preference for functional-style programming. I tend to model algorithms in my head as data and transforms of that data (versus, say, objects with behaviors).
Read more… -
Emacs Tidbit: rectangle-number-lines
Emacs has so many little features that do exactly what you need in very specific circumstances. Here’s one that I just found out about: rectangle-number-lines. I had some lines and I wanted to insert line-numbers for reference. I wanted this arguments list: [ team8721038424565681034 user fdff6f87-d876-4558-8d12-19e039e5a880 a foo secret alsothis b e46e2d16-b3ba-4f84-826f-5e3031465e21 ] To be this arguments list: [ 1 team8721038424565681034 2 user 3 fdff6f87-d876-4558-8d12-19e039e5a880 4 a 5 foo 6 secret 7 alsothis 8 b 9 e46e2d16-b3ba-4f84-826f-5e3031465e21 ] I started thinking about kmacros, which I rarely use but have an incrementing counter you can use for this, but I started googling and lo and behold I found a Stack Overflow post with the answer.
Read more… -
No I don't want 2, Emacs
This blog, and the vast majority of the code I write, is written in Emacs with evil (a vim emulation mode). I have a nasty habit of mashing :w2<ret> when I really was trying to save the current buffer with :w<ret> . :w2 writes the current buffer to a new file called 2, which I don’t believe I have ever done on purpose. So, I added this little gem to my .
Read more… -
Representing State as interfaces in Go
I made up a neat little pattern in Go the other day. It’s a way to represent a state change in a system by exposing different APIs for different states, while only holding state in a single underlying struct. I’m sure I’m not the first person to invent this, and it may already a name, so please let me know if you know of one [Update: apg on Lobsters pointed out the name “typestate”, which I like].
Read more… -
Building a custom Emacs auth-source
My employer, Okta, has recently been making security improvements to how we access all sorts of internal systems. As part of that hardening, we’ve been disallowed from using SSH keys and long-lived GitHub tokens to access our code on GitHub. In place of that, we’ve now got an internal tool that grants us short-lived tokens on demand, after SSOing (through Okta of course). This is a good idea even if it adds a little friction, and means that if you gain access to my machine somehow you won’t automatically have my privileges to access our code base.
Read more…