Josh Betz

Engineer, Solver of problems, Wisconsin Badger

Go Configure

I’ve been dabbling in Golang on and off for a little while now. Recently I was looking for a package to read and parse configuration files with the following requirements in mind:

  1. Be fast.
  2. Use environment variables and JSON files (in that order).
  3. Support hot reloading.

I looked at some of the popular configuration packages, but didn’t see anything that I loved. Many of them don’t meet the requirements I had in mind or are more complex than I’d like.

So, I decided to write config — I know, it’s a great name. It’s pretty simple. We cache values in memory to minimize disk IO. On SIGHUP (or any time you call config.Reload()), we clear the cache, so you can update the configuration without restarting your app.

Usage looks something like this:

There are more examples and details on the API in the README on Github.

If you have questions or ideas, issues and pull requests are welcome on Github. Let me know if you use it!

Writing Mode in Vim

I write quite a lot of Markdown on a daily or weekly basis. From meeting notes to documentation — most of the stuff I write for work that’s not code starts in Markdown. I used to use Byword, but it’s another app to switch between. After the last MacBook refresh, there were a few apps I installed immediately and it has pretty much stayed that way.

I’ve been using Vim to edit Markdown, which is fine, but was missing some things. So, I went hunting for the proper vimscript to enable things like soft line-wrapping and spell check. Needless to say, you can do more than that.

Goyo

One of the first things I found way Goyo. Goyo does “distraction-free writing in Vim” and does most of the work — disabling line numbers, vim-airline, soft-wrapping text at 80 characters, and centering it in the terminal window. You have to enable it with :Goyo after you open Vim, but I always want it enabled when I’m editing Markdown, so I wrote some vimscript:

" Goyo
function! s:auto_goyo()
    if &ft == 'markdown' && winnr('$') == 1
        Goyo 80
    elseif exists('#goyo')
        Goyo!
    endif
endfunction

function! s:goyo_leave()
    if winnr('$') < 2
        silent! :q
    endif
endfunction

augroup goyo_markdown
    autocmd!
    autocmd BufNewFile,BufRead * call s:auto_goyo()
    autocmd! User GoyoLeave nested call goyo_leave()
augroup END

vim-markdown

Next, I installed vim-markdown for syntax highlighting. Since most of my Markdown files have the .md extension, I need to tell Vim to treat them as Markdown.

autocmd BufNewFile,BufReadPost *.md set filetype=markdown

One of the vim-markdown features is to allow highlighting of other languages in code blocks:

let g:markdown_fenced_languages = ['javascript', 'go', 'php']

Spell Check

And, finally, I enabled spell checking in ~/.vim/ftplugin/markdown.vim with:

" Spell check
setlocal spell
highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline

josh.blog

I moved this site over to an awesome new .blog domain a few weeks ago. You can get your own at get.blog or any number of other registrars.

Today I decided to build a new WordPress theme to go along with the new domain. It’s been a while since I built a WordPress theme. For the last few years I had been using the default themes that ship with WordPress. It was fun to play designer again for a few hours.

I’m starting with something very simple — there’s not even support for comments yet. Though, I have a few ideas I’d like to experiment with if I have time. If you would like to use the theme or contribute, it’s over on GitHub.

2017 Resolutions

Happy New Year! I’ve spent the last week reflecting on 2016 and thinking about what I’d like to change in the coming year. You can probably see there’s an accidental theme. There are no professional goals, which wasn’t on purpose, but I think even one or two of these would positively impact my focus during the day.

Meditate regularly

I’m going to use Headspace at least once a week. The idea is to meditate every day before work, but I know I will miss some days and that’s fine.

Run a half marathon

And also train for it. I have this terrible habit of signing up for races with the idea that it will force me to run more and then just running the race out of shape.

The half marathon isn’t really in question. I guess the real resolution is to train for it.

Read more books and less news

I find books — especially paperbacks — to be more relaxing and calming. Right now I’m reading Modern Romance by Aziz Ansari. He writes in the same voice he performs and it’s pretty hilarious. I’m very late to the game on this one, but highly recommend it if you liked his Netflix special.

For news, I’d like an app that sends notifications about actual, important, breaking news. I had high hopes for the Apple News app, but they let publishers decide what justifies a push notification.

I’ve started to use the news as a crutch, like Facebook or Twitter, when I’m bored. The fact is that most of it isn’t important enough, also like Facebook and Twitter, that I need to know it in the next 24 hours — or ever.

Play more music

I tried to be specific for most of these, but the music thing is hard. Realistically, I have a couple months of Saturdays left until I’d rather be on a bike ride than playing guitar. I learned a few new songs over the holiday break and generally find it’s a good way to clear my mind when it’s too cold to go for a run.

GPG & Git

Back in April, Github added support for a long-standing git feature — commit signing. Technically you’ve been able sign commits with -S since git 1.7.9, but there was no UI for it on Github. This update led folks to start automatically signing all commits, but that’s not necessary.

The git tree is a directed acyclic graph — meaning every commit references its parent — and hashed with SHA-1. In practice, this means it’s impossible to change the history of a git repo without rewriting all succeeding commits. Said another way, if you trust the SHA-1 hash of the head of the tree, you can implicitly trust the entire tree.

What does this have to do with signed commits? Well, when you sign a commit, you’re also signing all previous commits. This is one of the reasons that git originally only allowed tags to be signed:

Signing each commit is totally stupid. It just means that you automate it, and you make the signature worth less. It also doesn’t add any real value, since the way the git DAG-chain of SHA1’s work, you only ever need _one_ signature to make all the commits reachable from that one be effectively covered by that one.

You can automatically sign all tags by adding the following to your .gitconfig file:

[tag]
gpgsign = true

If you don’t tag releases, another good place to sign commits is at the end of a pull request. After a long chain, one signed commit effectively signs the entire branch. You can even add an empty, signed commit with:

git commit --gpg-sign --allow-empty

This way, there’s no need to enter a GPG passphrase for each commit, but only when you need it.

Next Page »