Skip to content

Instantly share code, notes, and snippets.

View TheLonelyGhost's full-sized avatar

David Alexander TheLonelyGhost

View GitHub Profile
@TheLonelyGhost
TheLonelyGhost / git-line-stat
Created September 9, 2021 07:44
determine how many lines added and removed from a given commit-ish (ref, brach, whatever)
#!/usr/bin/env bash
set -euo pipefail
git diff --numstat "$@" | awk '{ sum_plus+=$1; sum_minus+=$2 } END { print("+++++ ", sum_plus); print("----- ", sum_minus); }'
@TheLonelyGhost
TheLonelyGhost / list-paths
Created September 9, 2021 07:42
list all the places in one's PATH where a command might be. More reliable than `whence` in a cross-platform setting
#!/usr/bin/env bash
set -euo pipefail
if [ $# -lt 1 ]; then
printf 'USAGE: list-paths <command>\n' 1>&2
exit 1
fi
bin="$1"
found=0
@TheLonelyGhost
TheLonelyGhost / ansi-escape-string
Created September 9, 2021 07:40
Remove all ANSI escape sequences from a given string
#!/usr/bin/env python3
import fileinput
import re
# 7-bit C1 ANSI sequences
ansi_escape = re.compile(r'''
\x1B # ESC
(?: # 7-bit C1 Fe (except CSI)
[@-Z\\-_]
@TheLonelyGhost
TheLonelyGhost / recruiter_seive.py
Created September 9, 2021 03:37
Compose valid Seive code (Fastmail filters) for recruiter spam
from typing import List
import json
def is_wildcard(email) -> bool:
return bool('*' in email)
def main():
@TheLonelyGhost
TheLonelyGhost / com.thelonelyghost.fix-jamf-firefox.plist
Created September 9, 2021 03:34
Fix ZApp injection to override Firefox settings
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.thelonelyghost.fix-jamf-firefox</string>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>-c</string>
@TheLonelyGhost
TheLonelyGhost / user-data-logging
Created September 9, 2021 03:31
Log user_data output to file
# Send the log output from this script to user-data.log, syslog, and the console
# From: https://alestic.com/2010/12/ec2-user-data-output/
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
@TheLonelyGhost
TheLonelyGhost / create-outlook-app.sh
Created September 9, 2021 03:29
Create electron app for outlook
#!/usr/bin/env bash
set -euo pipefail
nativefier --name Outlook --disable-dev-tools --disable-context-menu --single-instance --counter --bounce https://outlook.office.com/mail/inbox --internal-urls '.*?\.(microsoft|okta|office)\.com.*?'
@TheLonelyGhost
TheLonelyGhost / README.md
Last active June 12, 2019 00:17
Global state versus variable shadowing (python)

Example of Shadowing versus Global Shared State in Python

$ python ./main.py
PRE-CHANGE
First (direct): I am first
First (attribute): I am first
Second (direct): I am second
Second (attribute): I am second
CHANGE 1
@TheLonelyGhost
TheLonelyGhost / rcm.sh.patch
Last active December 15, 2016 20:36
Fix for hooks being run out of order in RCM
134,136c134,136
< -exec \
< sh -c 'cd "`dirname $1`" && ./"`basename $1`"' arg0 '{}' \
< \;
---
> | sort | while read file; do
> sh -c 'cd "`dirname $1`" && ./"`basename $1`"' arg0 "$file"
> done

Keybase proof

I hereby claim:

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

To claim this, I am signing this object: