I made a mistake with my git config recently, and ended up creating all the commits in a branch with the wrong email address. I can fix it up with a neat one-liner.| www.emoses.org
TL;DR My dotfiles are checked into a git repo I want to avoid checking in sensitive, work-specific config to a public git repo I updated my git and emacs configs to check for local overrides in ~/.local Like many folks, I check my dotfiles into a git repo to share them across multiple machines. When I set up a new machine I can simply clone that repo, run an install script that adds some symlinks, and get to work with my happy personalized config.| www.emoses.org
Here’s a puzzle for Go developers. How can the following code possibly panic with a nil pointer dereference? var someThing *SomeStruct // various things happen, including possibly assigning to someThing if someThing != nil && someThing.Body != nil { fmt.Printf("%s", something.Body) } Think about it for a minute. I’ll wait. OK are you done? I don’t want to spoil it for you. The Answer Here’s the definition of SomeStruct, type SomeStruct struct { *http.| www.emoses.org
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 ca...| www.emoses.org
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| www.emoses.org
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`.| www.emoses.org
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 when I really was trying to save the current buffer with :w . :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 .| www.emoses.org
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].| www.emoses.org