Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / piped_input_example.zsh
Created August 20, 2022 12:54
Zsh - append piped/redirected input to arg array
# Example to show how to append piped/redirected input to arg array
#
# More info:
# `man test` (lookup -t flag)
# `man zshbuiltins` (lookup set builtin)
#
# piped_input_example
# piped_input_example --flag arg
# piped_input_example --opt1 -x -y -z param1 param2 <<< "zzz"
# echo "abc" | piped_input_example --opt1 -x -y -z param1 param2
@mattmc3
mattmc3 / plugin-load.zsh
Last active July 30, 2022 14:33
Zsh Unplugged Enhanced
#!/usr/bin/env zsh
##? plugin-load - load plugins without a fancy plugin manager
##?
##? usage: plugin-load [-h|--help]
##? plugin-load [-n|--no-source] [-d|--defer] [-f|--fpath] [-p|--path]
##? [-u|--use-dir <plugin-subdir>] [<repo...>]
function plugin-load {
local use_dir flag_no_source flag_fpath flag_path flag_defer repos=()
@mattmc3
mattmc3 / frequency.zsh
Last active July 1, 2022 19:19
Colemak bigram assessment
function freq {
for c in $@; do
for c2 in $@; do
grep "$c$c2" /usr/share/dict/words | wc -l | tr -d '\n' && echo " $c$c2"
done
done
}
# least frequent home row bigrams
freq a r s t d h n e i o | sort -d | uniq | head -n 10
@mattmc3
mattmc3 / cd-ls.zsh
Created June 30, 2022 23:21
Zsh cd-ls
# 'ls' after every 'cd'
if ! (( $chpwd_functions[(I)chpwd_cdls] )); then
chpwd_functions+=(chpwd_cdls)
fi
function chpwd_cdls() {
if [[ -o interactive ]]; then
emulate -L zsh
ls
fi
}
@mattmc3
mattmc3 / gpginit.zsh
Created March 22, 2022 15:39
GPG home
#!/usr/bin/env zsh
GNUPGHOME=${XDG_DATA_HOME:-$HOME/.local/share}/gnupg
mkdir -p $GNUPGHOME
chown -R $(whoami) $GNUPGHOME
chmod 600 $GNUPGHOME/*
chmod 700 $GNUPGHOME
@mattmc3
mattmc3 / mfa.py
Created March 17, 2022 17:57
Python Google Authenticator code
#!/usr/bin/env python
"""
This is a Python implementation of the algorithm to generate
Google Authenticator multi-factor authentication tokens from
an MFA secret key.
usage:
secret=KUSJRAVCONHIBBKW
@mattmc3
mattmc3 / optparsing_demo.zsh
Last active April 5, 2024 21:22
Zsh option parsing example
# Manual opt parsing example
#
# Features:
# - supports short and long flags (ie: -v|--verbose)
# - supports short and long key/value options (ie: -f <file> | --filename <file>)
# - supports short and long key/value options with equals assignment (ie: -f=<file> | --filename=<file>)
# - does NOT support short option chaining (ie: -vh)
# - everything after -- is positional even if it looks like an option (ie: -f)
# - once we hit an arg that isn't an option flag, everything after that is considered positional
function optparsing_demo() {
@mattmc3
mattmc3 / aoc2021_day10.fish
Created December 10, 2021 17:24
Advent of Code 2021 - Day 10
function day10 \
--description "https://adventofcode.com/2021/day/10 - usage: day10 datafile.dat" \
--argument-names datafile
test -f "$datafile"; or echo >&2 "file expected" && return 1
# find corrupted lines
set --local data (cat $datafile)
set --local line_num 0
set --local total_error_score 0
@mattmc3
mattmc3 / aoc2021_day9.fish
Created December 9, 2021 21:26
aoc2021_day9.fish
function day9 \
--description "https://adventofcode.com/2021/day/9 - usage: day9 part1 datafile.dat" \
--argument-names part datafile
test -f "$datafile"; or echo >&2 "file expected" && return 1
set part (string match --regex '.$' $part)
day9part$part $datafile
end