Remember the Milk Alfred Workflow

This uses rtm-cli which you can install with npm.

query=$1
logfile="/Users/bakert/u/scratch/rtm.log"
rtm=/opt/homebrew/bin/rtm
max_lines=1000

# Log the query
echo "[$(date)] $query" >> "$logfile"

# Ensure the logfile does not grow beyond $max_lines
tail -n $max_lines "$logfile" > "$logfile.tmp" && mv "$logfile.tmp" "$logfile"

# Send the task to Remember the Milk
"$rtm" add $query

if [ $? -ne 0 ]; then
  echo "SOMETHING WENT WRONG! Please check that rtm-cli is installed: npm install -g rtm-cli"
else
  echo "[Added] $query"
fi

Gmail Conversations Archiving Has Gotten Worse

You can search for emails in Gmail, “Select All” and Gmail will prompt you, “do you want to select all conversations that match this search?” rather than just the 100 you can see. Then if you do something like use the Archive keyboard shortcut it says “do you want to apply this to all conversations selected?” Previously this was instant. Now it says, “We archived some conversations. We’ll do the same for any remaining conversations in a few minutes. This might take longer, depending on how many conversations are selected.” And if you go back to your Inbox they’re still there. A real downgrade!

assertRaises in table-driven tests

This is what I want to do but it fails passing None to assertRaises:

tests = [
   (0, None),
   (1, None),
   (-1, TooFewException),
   (99, None),
   (100, TooManyException),
]
for n, exc in tests:
    with self.assertRaises(exc):
        results = my_code(n)
        assert len(results) == n

Here’s a version of assertRaises that will let you do that:

    def assert_raises(self, exception: Type[Exception]):
        if exception:
            return self.assertRaises(exception)
        return contextlib.nullcontext()

Line Count

Number of lines in a (python + js) codebase:

#!/bin/zsh

# This script counts the number of non-blank lines of code in a directory and its subdirectories
# for Python and JavaScript code only

# Set the directory to search for code files
dir='.'

# Count the number of non-blank lines of code for Python and JavaScript files
num_lines=$(find "$dir" -type f \( -name '*.py' -or -name '*.js' \) -not -path '*venv*' -not -path '*node_modules*' -exec grep -he '^[^[:space:]]' {} + | awk 'NF{count++} END{print count}')

echo "Number of non-blank lines of code: $num_lines"

Number of lines per-file in a (python + js) codebase:

#!/bin/zsh

# This script counts the number of non-blank lines of code in a directory and its subdirectories
# for Python and JavaScript code only

# Set the directory to search for code files
dir='.'

# Count the number of non-blank lines of code for Python and JavaScript files
num_lines=$(find "$dir" -type f \( -name '*.py' -or -name '*.js' \) -not -path '*venv*' -print0 | xargs -0 grep -cve '^[[:space:]]*
)

echo "Number of non-blank lines of code: $num_lines"

Queries on local so much faster than queries on server

I was encountering a situation where big aggregating queries that took seconds on local were taking minutes or even hours on prod. After trying about a million things this Stack Exchange post finally cleared things up.

Setting innodb_buffer_pool_size = 5G in MariaDB’s configuration and restarting instantly changed the queries to taking seconds. The default is 128M which is … not useful 🙂

Change Terminal Background Color When ssh’ed – Mac

Save this as “ssh” somewhere on your $PATH ahead of /usr/bin/ssh and make it executable

#!/bin/sh

HOSTNAME=$(echo $@ | sed 's/.*@//')

set_theme () {
    osascript -e "tell application \"Terminal\" to set current settings of first window to settings set \"$1\""
}

on_exit () {
    set_theme "Solarized Light"
}

trap on_exit EXIT

case $HOSTNAME in
  # These all do the same thing but we could have different themes for different locations
  hb|pd|decksite) set_theme "Solarized Dark" ;;
  *) set_theme "Solarized Dark" ;;
esac

/usr/bin/ssh "$@"

Set Up a New Mac (August 2023 Edition)

Previously:
July 2019,
July 2022

  • Upgrade to latest OSX.
  • Restore u directory from Backblaze backup. Restore dotfiles, .ssh dir, .vim dir, maybe other dot directories from Backblaze backup. Restore ~/Library/Application Support/Alfred 4/*.
  • Alfred (and give it Accessibility access, add license key).
  • Set new hostname with:
    # Respectively, fully-qualified hostname, Bonjour hostname, the user-friendly computer name you see in Finder, flush the DNS cache …
    $ sudo scutil --set HostName agrajag.bluebones.net
    $ sudo scutil --set LocalHostName agrajag
    $ sudo scutil --set ComputerName agrajag
    $ dscacheutil -flushcache
    
  • Dock: remove everything, hiding on, magnification on.
  • Sublime Text 4 (add license key, set "trim_trailing_white_space_on_save": true in sublime prefs, install Package Control, install Solarized Theme).
  • subl commandline sublime.
    $ ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/u/bin/subl
  • sublime-git-ignorer: (1) add Package Control repo https://github.com/apc999/sublime-text-gitignore (2)
    add package sublime-text-gitignore (3) use menu item : File->Exclude Git-ignored (4) Give this a keyboard shortcut in Sublime, Preferences, Key Bindings with { "keys": ["super+shift+i"], "command": "exclude_ignored" }
  • Keyboard shortcut to toggle word wrap in Sublime Text. Preferences, Key Bindings { "keys": ["super+shift+w"], "command": "toggle_setting", "args": { "setting": "word_wrap" } }
  • Install FiraCode and add it to Sublime Text prefs with "font_face": "Fira Code".
  • Hide Desktop icons
    $ defaults write com.apple.finder CreateDesktop false
    $ killall Finder
  • Solarized theme for Terminal and make default in preferences.
  • “Use Option as Meta Key” in Terminal to make left Alt work as Esc.
  • Terminal, Settings, Advanced, un-check “Audible bell” and “Only when sound is muted”
  • System Preferences, Sound, turn “Alert volume” all the way down
  • Use Ctrl-f7 to enable keyboard navigation of dialogs
  • Homebrew. (Installs OSX commandline tools.)
  • brew install mariadb
  • brew install npm
  • brew install apache2. Docker Desktop (below) uses port 8080 so edit /opt/homebrew/etc/httpd/httpd.conf to use port 8081 and remember that you did it.
  • brew install php. Enable in Apache with LoadModule, FilesMatch and DirectoryIndex directives as per homebrew output and brew services restart apache2.
  • brew install gh
  • brew install composer
  • Docker Desktop.
  • Discord.
  • Change all .txt to open with Sublime Text.
  • Show hidden files in Finder. Cmd-Shift-.
  • WhatsApp.
  • 1Password.
  • Chrome. (Log in to Chrome to get uBlock Origin and other extensions.)
  • Skitch.
  • Backblaze.
  • Parallels Desktop + MTGO
  • npm install -g rtm-cli
  • Disable Ask Siri in System Preferences, Siri
  • Turn on “tap to click” in System Preferences, Trackpad.
  • Disable long-press (it’s wayyyyy too annoying when selecting text in Chrome): defaults write -g ApplePressAndHoldEnabled -bool false
  • Zoom.
  • Skype.
  • IntelliJ IDEs for languages that you’re currently using from the list below. Install Solarized theme and switch to Fira Code as editor font for each.
    • PyCharm.
    • GoLand.
    • WebStorm.
    • PHPStorm.
  • Spotify.
  • Slack.
  • git clone important repos (ff, pd, server)
  • Restore any local databases for dev (ff, decksite, logsite)
  • ln -s ~/ff/src/www /opt/homebrew/var/www/ff
  • GRANT ALL ON ff.* TO ff@localhost IDENTIFIED BY *REDACTED*
  • pd setup