I’m doing a little project in my free time of re-reading K&R’s “The C Programming Language” and completing all of the exercises. It’s pretty time consuming, but I think worthwhile. Thankfully it’s a short book, so it’s not as daunting as it could be.

Really digging this sort-of-retro terminal theme and font combo I’ve got going. The theme is Gruvbox and and the font is Input Mono Narrow Medium.

Really digging this sort-of-retro terminal theme and font combo I’ve got going. The theme is Gruvbox and the font is Input Mono Narrow Medium.

Even if you don’t care about the topic, this post on how to name servers is worth reading just to get his script which turns 8-bit images into ASCII art.

Things I’m Doing Since the Lockdown

Next week will be my third working from home, and there’s no clear date when it will end. I’m still not used to it, but I’m trying to do what I can to stay healthy while we’re all stuck at home. My time has consisted of at least a few of these each day.

  1. Going on at least one thirty minute walk a day.
  2. Trying to get my father to stay home.
  3. Playing guitar.
  4. Reading old books about old computers.
  5. Blogging and tweeting more.
  6. Trying to reassure people who are more worried than I am (and I’m pretty worried).
  7. Buying books from my favorite bookstore online so that hopefully they don’t go away forever.
  8. Realizing I have to keep in touch with friends better.

This is pretty rough. I have a lot thoughts, and a lot of feelings. It’s hard not to feel anxious all the time, and I can feel things like sleep quality decline.

I know that I’m incredibly lucky to have the kind of job I do and to be in the position I am in. I can’t stop thinking about all the people who aren’t so lucky though. It hurts to think about so many people suffering as much as I’m afraid they might.

BitBar: Easy Custom Menu Bar Apps

BitBar is a free app for macOS which — essentially — lets you create custom menu bar apps from shell scripts or other command line tools. If you can write a program or script (in Shell, Python, C, Swift) and print, you can put something in the menu bar. BitBar also lets you define how often it should automatically refresh each specific script.

My favorite thing I’ve made uses the speedtest-cli tool to refresh what my current download and upload speeds are and show colorized output based on the results.

2020 20 03 bitbar speedtest

The script might look strange if you’re not used to awk, but the main thing to know is that $2 (the second space separated for the line) represents the result number and $0 represents the whole line. So I’m grabbing the number and then printing the whole line with a color based on the value. Also, awk is cool and you should learn it.

#!/usr/bin/env zsh

echo "⏱"
echo "---"

/opt/local/bin/speedtest-cli |
awk '/Download/ {
        if ($2 < 25) {
            print $0, "|", "color=red"
        } else if ($2 < 90) {
            print $0, "|", "color=orange"
        } else {
            print $0, "|", "color=green"
        }
    }
    /Upload/ {
        if ($2 < 4) {
            print $0, "|", "color=red"
        } else if ($2 < 9) {
            print $0, "|", "color=orange"
        } else {
            print $0, "|", "color=green"
        }
    }'

More Parseable Output, Please.

Since reading Unix: A History and a Memoir by Brian Kerninghan (of K&R), I’ve been a little enamored with the idea of writing small command line tools. This article titled Hints for Writing Unix Tools hits on a bunch of things, and is worth reading, but one that really jumped out at me was this:

Output should be simple to parse and compose. This usually means representing each record as a single, plain-text formatted line of output whose columns are separated by whitespace. (No JSON, please.) Most venerable Unix tools—grep, sort, and sed among them—assume this.

Trying to parse the output of something like this on the command line is incredibly frustrating:

{
    myThing = "Blah"
    percent = 0.5
    ...
}

However, if the output is tab delimited:

myThing     blah
percent     0.5

Parsing it with Awk, sed, or other Unix filter tool can usually be done as easily as awk '/myThing/ { print $2 }'. I wish more tools paid attention to this. Maybe if you were writing Unix from scratch today, you’d have processes communicate using structured data (I think this is what PowerShell does?), but you have to work with the system you have.

Everyone knows that regular expressions are terrible, but what my theory presupposes, is that a large percentage of the “how can I parse …” questions on places like Stack Overflow that are solved by a crazy regex wouldn’t exist if more tools had sane output.

The Growth of Command Line Options, 1979-Present

This post shows the growth of arguments for a bunch of the most common Unix commands over time. The author demonstrates how we went from 99 in 1979 (Version 7 Unix), to 393 in 1996 (Slackware), to 700+ today (Ubuntu). After that, they make the argument that maybe that isn’t inherently a bad thing? Super thought provoking if you think about design or use a shell all day.

I don’t necessarily want to say I’m one of histories great innovators for having the idea to label power adapters with the name of the thing they came with… but I think it’s pretty smart.

Added a new pin to my denim jacket which I’m pretty into 😉 Wondering if anyone will notice I have the BBEdit icon on my jacket around work? If they do, I guess I’ll know that I should become friends with that person.

Script for Better Man Page Viewing

If you’re on macOS, you can open man pages in a separate, nicely formatted, window by using the x-man-page URL scheme.

Example Man Page

Typing x-man-page://ls, however, isn’t super convenient. This script lets you type xman command_one two... and open each page in a separate window. If it can’t find the command you asked for, it prints a message to stderr. Enjoy!

#!/usr/bin/env zsh

function xman() {
    for i in "$@"; do
        if [ $(command -v $i) ]; then
            open x-man-page://$i
        elif; then
            printf "Can't find command: %s\n" "$i" >&2
        fi
    done
}

I wrote seven tests today of my own free will to confirm all the variations of a string that could get returned based on a number of factors were what was expected. So I think I’ve finally gotten religion on testing.

It seems almost too obvious to say, but something I’m thinking and trying to do at work is to always leave code better than when I found it. Even if it’s just a tiny improvement. If something can be more clearly named, more testable, faster, I should just do it.

“I’ve ripped off very few songs in my life, but I’ve ripped off the Hot Pockets theme in like three songs.”

Jenny Lewis Tiny Desk Concert: www.npr.org/2020/02/2…

Filter Through Command in BBEdit

I’ve used BBEdit for a long time, but only recently started digging into the scripting side of it. If you’re willing to write your script against it’s scripting dictionary in AppleScript or JavaScript, you can do a lot, including attaching a script to every menu command in the app. You do however have to write a script and put it in the right place before you can use it. Sometimes I’d rather pipe my text through grep 'foo' | sort -u like you can on the command line, and have it format my text for me.

TextMate has exactly this command, so emulating that seemed like a good place to start:

FilterThroughCommand_TM.png

I figured out that I could build most of what TextMate has as a BBEdit Text Filter:

FilterThroughCommand_BB.png

Dr Drang had already done pretty much exactly the same thing, but I wanted my script to remember at least the last command I ran, which won’t work with his approach. To get that, I needed to make a proper AppleScript so that I could take advantage of persistent properties (which is a super useful thing AppleScript can do if they’re saved as an scpt file).

You can copy the script below into Script Editor and save it in script format to BBEdit’s Text Filters folder:

property default_command : "sort"

on RunFromBBEdit(_range)
	set shell_command to the text returned of (display dialog "Enter a shell command:" with title "Filter Through Command" default answer default_command)
	
	if shell_command is "" then
		quit
	end if
	
	set default_command to shell_command
	
	if _range as text = "" then
		set text_content to text of front document
		set results to executeCommand(shell_command, text_content)
		set text of front document to results
		return ""
	else
		set text_content to _range as text
		set results to executeCommand(shell_command, text_content)
		return results
	end if
	
end RunFromBBEdit

on executeCommand(shell_command, text_content)
	set AppleScript's text item delimiters to {ASCII character 13}
	set results_text to text items of (do shell script "echo " & quoted form of text_content & " | " & shell_command)
	set AppleScript's text item delimiters to {ASCII character 10}
	set return_text to text items of results_text as text
	set AppleScript's text item delimiters to {""}
	return return_text
end executeCommand

Set up MacPorts as a replacement for Homebrew last night. So far so good I think? The only package which wasn’t available so far was swiftlint, which I can build myself.

I’m trying to make a habit of saying “thank you” instead of “sorry” whenever it’s appropriate. For example, thanking someone for their time instead of apologizing for taking it.

Using os_signposts with Instruments is so cool and useful for seeing what your app is doing and zeroing in on specific operations. This post shows the kind of thing I’m talking about if you haven’t used signposts before: www.iosdev.recipes/os-signpo…

I’m looking for alternatives to Napkin for marking up and combining multiple images in a similarly flexible way and would welcome any suggestions. Most of these apps are either full blown image editors or only want to work on one screenshot at a time without a flexible canvas.

I’ve been using NetNewsWire on macOS for months, and I’m now using the iOS beta as well. Like the Mac beta last year, it already feels high quality and exactly how I want. New NetNewsWire is a different app than old, but it somehow captures what I’d missed using other readers.

Off to a good start exercising in 2020. Ring Fit Adventure is definitely making it a lot easier to keep the streak going on days I don’t walk or bike enough.

I’ve been playing Ring Fit Adventure each day for over a week, and am enjoying it. I don’t know how well it will work for getting in shape long-term, but with the number of overhead presses and squats I’m doing, my strength seems like it’s going to have to improve at least.

It’s been a wild and eventful week for me, which has involved a late night trip the emergency vet, and many trips to the regular one. Thankfully everyone is feeling better and things are finally back to normal.

Ever since NetNewsWire started putting out usable builds several months ago, my RSS reader has moved from the category of things where I try new ones all the time to being a solved problem. It’s just exactly what I want.

Every time I read an article about Drafts, I think I need to figure out how to use it more.

Drafts for Mac: It’s Action Time