Lock Screen Keyboard Shortcut on OSX
TIL that you can easily go to the lock(sleep) screen on OSX with the following keyboard shortcut:
Ctrl + Command + Q
TIL that you can easily go to the lock(sleep) screen on OSX with the following keyboard shortcut:
Ctrl + Command + Q
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)
───────┴────────────────────────────────────────────────────────────────────────────────────────────────
Output:
$ cd rails_app
direnv: loading ~/dev/rails_app/.envrc
direnv: export +API_KEY +STRIPE_PK
echo $API_KEY
qwertyuiop
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.
Sed can remove a line in a file by its number with '<line number>d'
:
printf "a\nb\nc\n" > file.txt
sed '2d' file.txt
a
c
You need the env var ASDF_RUBY_BUILD_VERSION
to be set to master
ASDF_RUBY_BUILD_VERSION=master asdf install ruby 3.1.1
I’m trying to be one of those cool kids that doesn’t have to tak their hands off the keyboard. You know the type. So I looked up GitHub’s keyboard shortcuts (which are expansive).
Turns out they have a command palette reminiscent of spotlight on mac. Open with (ctrl || cmd)+k
.
Have you ever wanted to script a shell? Do you use kitty? Well then the kitty @
messaging system is your friend. Check out the tutorial, or just use kitty @ --help
.
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
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:
#!/bin/bash
# Keep last 5 files ending in .dump
# Don't forget to
# Installation
# 1. cp pg-backups.sh /usr/local/bin/
# 2. chmod u+x /usr/local/bin/pg-backups.sh
# 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/pg-backups.sh
DB=mydatabase
BACKUP_DIR=/mnt/object/production/db-backups
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
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:
heroku buildpacks:add --index 1 heroku-community/apt
Then create an apt file:
# Aptfile
libsqlite3-dev
libsqlite3-0
Did you know that you can quickly and easily display or send someone your SSH public keys located on Github?
Just got to https://github.com/[USERNAME].keys
So in my case retrieving https://github.com/mattpolito.keys
would provide all of the public keys I have added to Github.
You can view the last modified time of a file with the date
program and -r
flag:
$ date -r Gemfile.lock
Fri Nov 5 11:10:42 EDT 2021
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 com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
osascript -e 'tell application "Visual Studio Code" to quit'
osascript -e 'tell application "Visual Studio Code" to activate'
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
213
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.
When developing permission settings on an iPad or iOS device, you can reset permissions at
Settings >
General >
Transfer or Reset (iPhone|iPad) >
Reset >
Reset Location & Privacy
I’ve always opened a browser’s “Web Developer Tools” the with ⌥⌘I
, but it is a lot faster to open the tool with just F12
🍄
You can encrypt a zip when archiving by using the -e, --encrypt
flag:
zip -e secrets.zip journal.txt
Enter password:
Verify password:
adding: journal.txt
cURL can save response headers to file (useful in shell scripts) with the -D
flag
curl -D response-headers.txt https://example.com
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)"
ARCHIVE_PATH="$BOB_THE_BUILD_DIR/MyApp-$(date|md5).xcarchive"
xcodebuild -scheme MyApp -workspace "MyApp.xcworkspace" archive -configuration release -archivePath "$ARCHIVE_PATH"
Example opening Xcode’s organizer window:
osascript -e 'tell application "Xcode" to activate' -e 'tell application "System Events" to keystroke "o" using {command down,shift down,option down}'
scp ~/.ssh/id_rsa.pub edgerouterx:f
ssh edgerouterx
configure
loadkey dillon f
commit
save
exit
rm f
exit
Shortcut:
⌘+k
s
To save a file in VSCode without formatting press ⌘
+ k
, release, and then pressing s
Thanks to joshbranchaud and gabrielreis for these:
Fuzzy git checkout (alias in git config):
[alias]
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!
https://github.com/rizzatti/dash.vim
Makes for looking up API information while navigating Vim that much easier! Still playing with it, but running :Dash
will automatically open a search for the term under your cursor.
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)
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.
Today I found out that we can use Shift
key to change the scroll orientation from vertical to horizontal. That’s very useful if your mouse does not have the capability to scroll horizontally just like mine.
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
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.
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 "zoom.us"
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 "zoom.us"
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.
On macOS, you can get detailed network statistics in the WiFi menu by holding the option
key and clicking on the Wifi network icon in the top right corner.
H/T N.L.
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
.
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.
I often accidentally close a browser tab I meant to keep, and then walk through an inefficient ‘help’ search or menu-clicking journey to reopen that tab on whatever browser I happen to be using. No more! In Chrome, Firefox, and Safari for MacOS, you can reopen a closed tab with: ⌘ + SHIFT + T
.
h/t Phil Capel
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.
You can screenshot only the touchbar by using the keyboard shortcut Cmd ^
Note: I’ve tested this on a 15” MBP, no idea on how this will work on other macs
If you are using Vimium, the Hacker’s Browser, I have a nice pro tip via Hashrocket alumnus Josh Branchaud. Hit yy
on an webpage to copy the current URL into your paste buffer.
This little alert in the lower right of my Firefox tells me it worked:
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.
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
Add this to your settings.json
:
"terminal.integrated.shell.osx": "/usr/local/bin/fish"
Et voila!
And a helpful gif:
Sources:
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.
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:
destroy crystals
In The End, I died.
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.
CMD + SHIFT + .
focuses VS Code’s breadcrumb feature and allows you to move quickly through blocks/methods in a file.
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
Sometimes I will have two workspaces open in VSCode, a client app workspace and a server workspace. I learned there is a shortcut to quickly move between each workspace:
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.
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”!
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:
~/
tmpfile1.txt
tmpfile2.txt
tmpfile3.txt
tmpfile4.txt
do-not-delete/
secrets.yml
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
~/
do-not-delete/
secrets.yml
Because the directory error message comes over stderr, we can simply redirect it to /dev/null
to ignore it:
rm * 2> /dev/null
rm
has no built-in way to exclude files, but you can use a negative pattern:
$ ls
=> bar.txt foo.txt secrets.yml
$ rm !("bar.txt"|"secrets.yml")
$ ls
=> bar.txt secrets.yml
This approach is very error-prone and could have unexpected results. There are safer alternatives.
VSCode can render markdown without an extension by using the keyboard shortcut ⌘k
then pressing v
while editing a markdown file.