Skip to content

Instantly share code, notes, and snippets.

View nathanalderson's full-sized avatar

Nathan Alderson nathanalderson

View GitHub Profile
@nathanalderson
nathanalderson / purgehostkey.zsh
Last active June 17, 2021 22:14
zsh function for deleting the bad host key from the previous ssh command
# delete the bad host key from the previous ssh command
purgehostkey() {
cmd=$history[$((HISTCMD-1))]
lineno=$(eval $cmd 2>&1 | grep -oP 'known_hosts:\K\d+')
known_hosts=~/.ssh/known_hosts
host=$(sed -n "${lineno}p" $known_hosts | cut --delimiter=' ' --fields=1)
sed -i -e "${lineno}d" $known_hosts
echo "Deleted $host from known_hosts:$lineno 🖥️🔑💥"
eval $cmd -o StrictHostKeyChecking=accept-new
}
@nathanalderson
nathanalderson / table_parser.py
Created September 19, 2019 19:14
Parse a certain type of text-based table in python
from typing import List, Tuple
def parse_table(table: str) -> Tuple[Tuple, List[Tuple]]:
"""
Uses the second row of the table to determine column locations, then returns the headers and
records based on that. See testcase at bottom.
"""
rows = table.splitlines()
spans = _get_spans(rows[1])
headers = _span_vals(rows[0], spans)
» strace bcompare
execve("/usr/bin/bcompare", ["bcompare"], 0x7ffd78084240 /* 65 vars */) = 0
brk(NULL) = 0x55e71f458000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd33a19250) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=206302, ...}) = 0
mmap(NULL, 206302, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0eb2e70000
close(3) = 0
openat(AT_FDCWD, "/usr/lib/libreadline.so.8", O_RDONLY|O_CLOEXEC) = 3
@nathanalderson
nathanalderson / keybase.md
Created September 1, 2018 16:18
verifying myself on keybase.io

Keybase proof

I hereby claim:

  • I am nathanalderson on github.
  • I am nathanalderson (https://keybase.io/nathanalderson) on keybase.
  • I have a public key ASBP9xFSfLVNtJGyW29cOTqbgbOxY3BQL8yydMCT3A3rqAo

To claim this, I am signing this object:

@nathanalderson
nathanalderson / clipboard-md-to-html.sh
Created May 5, 2018 04:00
Tansform clipboard contents from markdown to HTML
#!/usr/bin/env bash
xclip -selection clipboard -o | pandoc --from markdown --to html | xclip -selection clipboard -target text/html