Today I Learned

A Hashrocket project

212 posts about #workflow

Duplicating tabs in iTerm

If you want to open a new tab in iTerm in your same working directory, you can use the following steps:

  1. Navigate to preferences or use (⌘,).
  2. Click on the Keys settings.
  3. Hit + in the bottom left corner to add a new shortcut.
  4. Record a shortcut of your choosing
  5. Using the dropdown menu for Action: select ‘Duplicate Tab”

Now your new shortcut will open a new iTerm tab in whatever directory you have currently open.

Saving screenshots to clipboard on Mac

Have you ever needed to take a screenshot just to send it to somebody, but then you are left with the cumbersome chore of having to actually delete the screenshot before they pile up on your desktop like a pile of dirty laundry?

Well, I am here to save you those 5 seconds you’ve been missing out on so you can enjoy that next sip of coffee—guilt free.

When taking a screenshot with CMD + shift + 3, hold down control as well.

When taking a screenshot with CMD + shift + 4, hold down control while dragging the crosshairs to select a section of screen to capture.

Now, instead of saving to your default screenshot location, it will just copy it to your clipboard. You can now just paste the image into your message with no cleanup necessary.

Hold down control when taking a screenshot to copy it to the clipboard.

Use encrypted env vars with direnv

Direnv can execute shell scripts, so given that your env file is encrypted, you can automatically have it become decrypted for you:

       │ File: .env
   1   │ STRIPE_PK="123456789"
   2   │ API_KEY="qwertyuiop"

Say is was encrypted:

ansible-vault encrypt --vault-password-file config/master.key .env
cat .env
       │ File: .env
   1   │ $ANSIBLE_VAULT;1.1;AES256
   2   │ 35306466356632363334643432343132356662376462333964366534393462366333623764336161
   3   │ 6131336435323834623539323462626235383330346562660a323534656133653237656634346235
   4   │ 30653635663438313931393966383266663535313361613339396234373164323830373262633661
   5   │ 6262356131306530350a643362623636323762656132326363323736633431396463616137343139
   6   │ 66666438623230333636373563393165333562633964616536663363323334343235386465346663
   7   │ 3365643263643766323835356230636539353034643034346136

Now that we have an encrypted .env file, we just need direnv to decrypt it whenever we’re in our directory:

       │ File: .envrc
   1   │ export $(ansible-vault decrypt --vault-password-file config/master.key --output - .env | xargs)


$ cd rails_app
direnv: loading ~/dev/rails_app/.envrc
direnv: export +API_KEY +STRIPE_PK
echo $API_KEY

Now whenever we enter the directory, we will have the unencrypted env vars, but the file remains encrypted on disk. For whatever that’s worth.

Resize Window Keyboard Shortcuts in Windows 10

After using Magnet, a window manager in OSX, I remembered hearing that there was a similar facility built into Windows. Turns out, they are very easy-to-remember shortcuts for resizing windows.

  • Win + Right Arrow - Snap to right half of screen**
  • Win + Left Arrow - Snap to left half of screen**
  • Win + Up Arrow - Maximize current window
  • Win + Down Arrow - Minimize window if not currently maximized

**(will maximize the window if it is currently split on the opposite side of the screen)

There’s a few others too, but these 4 I’m finding super useful. If you’re interested in other Windows shortcuts, I found some other cool ones in this Lifewire article

Keep 5 most recent files in a directory

One can keep the most recent n files in a directory with just three shell programs: ls, tail, and xargs.

Here is an example to use in a nightly database backup cron job:

# Keep last 5 files ending in .dump
# Don't forget to 

# Installation
# 1. cp /usr/local/bin/
# 2. chmod u+x /usr/local/bin/
# 3. Set the DB variable
# 4. Set the BACKUP_DIR variable

# Example usage for cron to run at 4:05 am every day:
# 5 4 * * * /usr/local/bin/


DATE=$(date "+%Y-%m-%d_%H%M")
pg_dump -Fc $DB > $BACKUP_DIR/$DATE.dump

/bin/ls -t $BACKUP_DIR/*.dump | tail +6 | xargs rm

How to install sqlite3 on heroku

Using sqlite to persist data is superfluous on heroku, duh, but sometimes a third party service wants my rails app to read configuration in a sqlite db file. In order to read the read-only database file, I need to install the sqlite3 gem. To get this to work on heroku I needed to do two things:

  1. Install the apt buildpack
  2. Add an Aptfile in the root of the project
heroku buildpacks:add --index 1 heroku-community/apt

Then create an apt file:

# Aptfile

Enable key repeat in VSCode

Even if your operating system enables key repeat, VSCode will disable it. To turn it on you need to update a default value and restart vscode:

defaults write ApplePressAndHoldEnabled -bool false
osascript -e 'tell application "Visual Studio Code" to quit'
osascript -e 'tell application "Visual Studio Code" to activate'

Disable broken VSCode feature

TL;DR in the command palette choose “Workspaces: Configure Workspace Trust” and change “Start Prompt” to “never”

VSCode has a nice security feature warning about the risks of unknown file authors, but it is too naive to be useful; it actually has the reverse effect of being insecure (due to the fact most of these folders have been used in vscode for years before this feature was introduced). For example, I have over 200 projects on my machine:

ls ~/dev | wc -l

The start prompt is simply training me to continually click “Yes I trust this code” over and over again, not only does this have no effect, but actually has a negative effect of making VSCode think I gave careful consideration to the folder, when instead, I was just trying to open my files.

List cli xcodebuild archives in Xcode's organizer

When using a Makefile to build Xcode applications, it’s nice to have the archives listed in the Organizer window, for easy distribution. This can be accomplished with the -archivePath flag, using a specific directory:

BOB_THE_BUILD_DIR="~/Library/Developer/Xcode/Archives/$(date +%Y-%m-%d)"

xcodebuild -scheme MyApp -workspace "MyApp.xcworkspace" archive -configuration release -archivePath "$ARCHIVE_PATH"

How using fzf in new places rocks

Thanks to joshbranchaud and gabrielreis for these:

Fuzzy git checkout (alias in git config):

    fco = !git branch | fzf +m | awk '{print $1}' | xargs git checkout

Then just use git fco and get an interactive fzf session to look through the available branches!

Fuzzy rails routes:

rails routes | fzf

Fuzzy search your routes without needing to run rails routes multiple times!

About cool ways to use file marks

File marks in vim are just marks made with [A-Z]. They have the delightful property that they persist (via .viminfo) across sessions without needing a session (depending on your settings). I’ve known about them for a while, but I wasn’t sure if there was really a way that I could come up with the use them. So I went out looking and found something that I like!

`T -> project todo file
`V -> .vimrc

I’ll probably come up with some other ideas based on the invariant files that I frequently visit, but these two are definitely going into my rotation. I’m also thinking that at least one more should be added:

`L -> TIL file (ABT - always be TILin)

cReddit where credit is due

About nvim SHADA (Shared Data) file and Sessions

Ever stop your vim and get really depressed that you just lost your buffers? Cause I’ve done it twice today. The relevant details about sessions:

   The following command creates a session file:

    :mksession vimbook.vim

Later if you want to restore this session, you can use this command:

    :source vimbook.vim

If you want to start Vim and restore a specific session, you can use the
following command:

    vim -S vimbook.vim

This tells Vim to read a specific file on startup.  The 'S' stands for
session (actually, you can source any Vim script with -S, thus it might as
well stand for "source").

Your sessionoptions needs to include buffers. The SHADA file is like adding steroids. You can keep marks, register contents, and command line history.

Relevant documentation

🚯 Prevent development logs from bloating on macOS

I rarely need to refer to development.log or test.log when working on rails applications, but yet I end up keeping weeks or even years of records [gigabytes]. I’m used to working with logrotate, and I wanted to find a similar solution that was preinstalled with macOS. macOS comes preinstalled with a program called newsyslog that can keep file sizes in check. I just created a new file at /etc/newsyslog.d/rails.conf which limits all rail’s log files to just 10MB

# /etc/newsyslog.d/rails.conf
# logfilename                                                   [owner:group]      mode count size(KB)     when  flags [/pid_file] [sig_num]
/Users/<username>/dev/<rails projects>/*/log/*.log              <username>:staff   644  0     10000         *     G
# Mono repos
/Users/<username>/dev/<rails projects>/*/*/log/*.log            <username>:staff   644  0     10000         *     G
# Deeper mono repos
/Users/<username>/dev/<rails projects>/*/*/*/log/*.log          <username>:staff   644  0     10000         *     G

You can also perform a dryrun of the config for testing:

sudo newsyslog -v -n -f /etc/newsyslog.d/rails.conf

Clean Paste 🧼

When you copy text from the internet, a bunch of formatting and HTML gets copied, too. Copy a link’s text and paste it into Mac Notes, and there’s some of the text formatting of the website, plus the link.

I almost never want this extra stuff, so I use an alternate paste dubbed the ‘Clean Paste.’ On MacOS, instead of CMD + V, try CMD + OPTION + SHIFT + V. You’ll get just the text, minus all the extras.

Note: I learned this via the newsletter Recomendo, which I (pause for effect) recommend. It’s so helpful me and I’ve looked it up so many times, that I’m re-sharing it here.

Automate Applescript via Accessibility Description

While automating a few tasks I do frequently it became apparent that many apps do not title their UI elements. This makes it more of a trial and error process to figure out which button is where.

This leads to script that is not very descriptive:

tell application "System Events"
    tell process ""
        click button 3 of window 0
    end tell
end tell

I’ve always wanted to reference elements by their label or utilize accessibility attributes if they are available but could never figure out how.

I finally have!

tell application "System Events"
    tell process ""
        click (first button where its accessibility description = "Copy Invite Link") of window 0
    end tell
end tell

This is obviously a bit more verbose but infinitly more descriptive when looking back at what a script is doing.

My future self is already thanking me.

Tmux not starting after an upgrade

Recently upgraded my version of Tmux and after could no longer start a session. After banging my head on tmux’s config files it turned out that sessions that were currently in play were the problem.

So if you find yourself in this situation… make sure to stop all sessions and most likely you’ll have Tmux working again.

An easy way to kill everything would be tmux kill-server.

10x Your Playback Rate

Consuming pre-recorded conference talks, video tutorials, and podcasts at accelerated speeds is possible and addictive. Each week I send a newsletter containing at least one recent conference talk I’ve watched, and I wouldn’t be able to do this without the following hack:

Most videos players (YouTube, Vimeo, QuickTime) let you increase the playback rate, but often these controls are hard to find or have an arbitrary ceiling like 2x. If there’s a video element in the DOM, I like to bump up the rate in the DevTools console like this:

document.querySelector('video').playbackRate = 3

‘3’ equals three-times the normal speed, and that seems to be my limit for the moment.

playbackRate MDN docs

Inline MD codeblock with double backticks

A pair of single backticks signify an inline code block in Markdown. But if you need to put a backtick in that code block the backtick ends the codeblock!

Another way to signify an inline codeblock is with double backticks, two backticks in sequence on either side of the codeblock.

When using double backticks for a codeblock, a single backtick within the codeblock will be interpreted as just that, not the end of the codeblock.

Firefox Profiles for Work and Home 👤

I’m managing two Firefoxes on my laptop: one for work and one for after work. A feature that supports this well is Firefox profiles. Visit them in Firefox by typing about:profiles into the browser bar.

These work like Chrome People— separate sessions, histories, bookmarks, etc. I have styled the two browsers a little differently so I can quickly tell them apart.

I used to use Incognito/Private Windows for this setup, but those aren’t great for long-running browser sessions, because when you close or crash the browser, anything you’ve done in that browser is gone. Profiles give me the isolation I need with some persistence, too.

Perform on Zoom 🎸

Planning to use Zoom for something other than a meeting, like a reading or musical performance, that would benefit from room noise and a softer audio experience? If so, read on!

Zoom has several default audio features in place to make your business calls sound great. We don’t want those features in place in a performance setting. Jettison them by enabling ‘original sound’ under advanced audio settings:


All you need to do from here is turn on your best (quality and/or position) microphone option. For me, that’s my display audio.

h/t Suzanne Erin

Toggle Dark Reader 🌓

I really love the Dark Reader Browser plugin (h/t Chris Erin). It turns most websites into a dark mode that is really easy on my eyes. However, some sites just don’t look right in dark mode. Luckily, the plugin can be toggled on and off with ALT + SHIFT + D on Firefox and Chrome. I use it a couple of times a day on websites I encounter on the internet.

Bonus: Here’s an example of this plugin in action, that is very meta.


Dark Reader

How to fight the dragon

Tonight I learned how to fight the dragon in #Minecraft.


Nice to have:

  • armor with protection
  • bow with power
  • sword with sharpening
  • stength/health/regen potions
  • pumpkin head
  • snowballs

Must have:

  • golden apple, speed potion,
  • pickaxe, bow, arrows, sword & shield, armor
  • stack of dirt/cobblestone, buckets of water, ladders

I proceeded to The End. I picked a fight with a dragon and its pesky posse of ender men (pumpkin head helps). I learned to:

  • dodge the purple dragon breath
  • dodge or block dragon dives with the sheild
  • destroy crystals

    • with bow or snowballs for shorter towers
    • for taller towers, dump water at tower base, climb with ladder, then break crystal and fall into water
  • with a sword strike dragon’s feet when it sits on the pillar of bedrock
  • use looted ender pearls to teleport dodge

In The End, I died.

VSCode Select All Matches

I’ve been using VSCode for a while, and really love the shortcut CMD+Shift+D: if you have something selected, it will find and select the next match.


Today I accidentally pressed CMD+Shift+L, and serendipitously found out that it “Selects All Occurrences of Find Match.” Now I can remove those pesky quotations marks in this Ruby hash all at once! As written, the hash keys will be turned into symbols anyway, so the quote marks are noise.


Hat tip 🎩to Licecap for straightforward recording of gifs on any platform.

Turn on coordinates in Minecraft Realm

In a Minecraft Realm the option to turn on the coordinate system is not available without turning on cheats. That is not good because then you’ll lose achievements.

Many tutorials recommend downloading the realm locally, flipping the switch for coordinates, and then uploading that copy of your world back to the realm. Turns out that some server commands will work in the Realm… coordinates being one of them!

Enter this into your chat window to enable coordinates:

/gamerule showcoordinates true

You can, of course, turn them back off via:

/gamerule showcoordinates false

Mac Notes Default Text Size 🔎

I use Mac Notes a lot during pairing and brainstorming. It works, and it’s right there on the Mac!

One issue I’ve had is that the default text size on Mac Notes is unreadably small on a big monitor or iMac. I always end up creating a note, then bumping the text size with CMD-SHIFT ..

Of course, there’s a better way. Set the default font size in preferences.


Slack Hot-Keys Rock

Do you like slack? Chances are it doesn’t really matter whether you do or don’t. It’s a matter of course at this point that you will probably work with it. Because that’s the case, you should at least strive to be as aware of neat features as possible!

To that end, you should check out the built-in hot-key help using:

MacOS: Command + / Linux/Windows: Ctrl + /

I’m particularly fond of the “Navigation” and “Channels & Direct Messages”!

How to redirect standard error

2> Allows us to redirect standard error.

Taking advantage of rm’s ability to not delete files recursively can come in handy, especially when writing clean up scripts, but it can be noisy when you don’t care.

Give this file structure:


I may want to delete all the files, but not touch the directories (to keep file removal simple)

$ rm *
rm: cannot remove 'do-not-delete': Is a directory

$ ls

Because the directory error message comes over stderr, we can simply redirect it to /dev/null to ignore it:

rm * 2> /dev/null