Skip to content

Instantly share code, notes, and snippets.

@wisq
wisq / gist:0fa021df52a3bd2485ac
Last active June 3, 2023 04:18
Protip: Bisecting a single commit

Situation: Some commit (on master, but not necessarily head of master) has broken things, but it's a big commit and it's not clear what part broke things.

% git checkout master
% git checkout -b bisect-branch
% git revert <offending commit>

(test here to make sure reverting fixed your problem)

% git bisect start
defmodule CertChecker do
alias X509.Certificate, as: Cert
def check_file(file) do
[cert | chain] = read_pem_file(file)
check_certs(cert, chain)
end
def check_certs(cert, chain) do
cert_map = chain |> map_by_subject()
#!/bin/sh
SAS='/opt/brew/bin/SwitchAudioSource'
DOCK='CalDigit Thunderbolt 3 Audio'
EXT_MIC='External Microphone'
EXT_PHONES='External Headphones'
HEADSET='WH-1000XM3'
MAC_MIC='MacBook Pro Microphone'
MAC_SPEAKERS='MacBook Pro Speakers'
-- Record current app so we can switch back to it after.
tell application "System Events"
set frontmostApplicationName to name of 1st process whose frontmost is true
end tell
-- Switch to Discord and hit cmd-shift-M.
-- This is a built-in keybind and does not require any setup.
tell application "Discord" to activate
tell application "System Events"
keystroke "m" using {command down, shift down}
@wisq
wisq / quicklook.scpt
Created October 21, 2022 02:21
MacOS "Quick Look" from the command line, with full editing capability, unlike `qlmanage -p`
on run argv
if (count of argv) = 1 then
set p to (item 1 of argv) as text
else
log "(development mode)"
set p to "/tmp/test.png"
end if
# Reveal the file in Finder.
# If QuickLook is already open, this will change it to the new file.
@wisq
wisq / gist:1507733
Created December 21, 2011 21:14
Why I love zsh (and hate being forced to use bash)

Why I love zsh (and hate being forced to use bash)

  • Smarter completion. A few examples:
  • context sensitive -- if you have file "name1" and directory "name2", "cd nam<TAB>" completes to "name2/"
  • "tar xf <TAB>" completes to tarballs only. "unrar x <TAB>" completes to RARs only. etc.
  • rsync / scp completion: "rsync host:anything/<TAB>" shows you files on host under anything/
  • also works with rsync:// URLs
  • SSH host completion from ~/.ssh/config & ~/.ssh/known_hosts
  • lots of other smart completions: Rake tasks, git commands & SHAs, dpkg packages, dash-options for most commands, etc etc.
@wisq
wisq / zshenv.sh
Created December 21, 2011 22:06
My zshrc & zshenv
# Custom PATH to avoid every utility prepending more duplicate entries to it:
export PATH="$HOME/bin:$HOME/.rbenv/shims:$HOME/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
@wisq
wisq / fix-filenames.exs
Last active April 9, 2020 03:37
Quick and dirty Elixir script to fix filenames with invalid unicode
#! /usr/bin/env elixir
defmodule Fixer do
def parse_args(["-n" | args]), do: {false, args}
def parse_args(["-f" | args]), do: {true, args}
def parse_args(args), do: {false, args}
def fix_all({rename, files}) do
{:ok, stdout} = File.open("/dev/stdout", [:write])
Process.register(stdout, :stdout_binary)
@wisq
wisq / advent-2018.sh
Last active January 1, 2019 12:53
Fetch the winning game titles from the RPS Advent Calendar 2018
#!/bin/sh
wget -nc -r --accept-regex='https://www.rockpapershotgun.com/2018/12/[0-9]+/the-rps-advent-calendar-2018-dec-[^/]+/$|https://www.rockpapershotgun.com/tag/the-rps-advent-calendar-2018/page/[0-9]+/$' https://www.rockpapershotgun.com/tag/the-rps-advent-calendar-2018/
echo
echo "===================================="
find www.rockpapershotgun.com/2018 -name 'index.html' -print0 | sort -z | xargs -0 grep "</a>!</p>" | cut -d/ -f2-4,8- | sed "s#/www#>#g" | cut -d'>' -f1,3 | cut -d'<' -f1 | sed -e "s/>/: /" -e "s#/#-#g" -e "s/&#8217;/'/g"
echo "===================================="
echo
defmodule StrNext do
@character_ranges [
{'A', 'Z'},
{'a', 'z'},
{'0', '9'}
]
@characters Enum.map(@character_ranges, fn {a, z} ->
hd(a)..hd(z)
|> Enum.to_list()
end)