Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / modern_sql_style_guide.md
Last active April 8, 2024 22:53
Modern SQL Style Guide
layout author title revision version description
default
mattmc3
Modern SQL Style Guide
2019-01-17
1.0.1
A guide to writing clean, clear, and consistent SQL.

Modern SQL Style Guide

@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 / zsh-strings.md
Last active April 1, 2024 22:44
Zsh - string utilities

zsh strings

Fish has a utility for [string maniplulation][string].

This is how you can do the same things with Zsh builtins.

References:

  • [Zsh regex][3]
  • [String modifiers][1]
  • [String expansion][2]
@mattmc3
mattmc3 / split.zsh.md
Last active March 31, 2024 15:34
ZSH - split string into array

Example splitting string on slash character in ZSH.

$ str=part1/part2/part3
$ parts=(${(@s:/:)str})
$ echo $parts
part1 part2 part3
$ echo ${#parts[@]}
3
@mattmc3
mattmc3 / gist-backup.py
Last active March 25, 2024 19:46 — forked from fedir/gist-backup.py
Clone or update all user's gists #backup #github #gists #management
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -LJO https://gist.githubusercontent.com/mattmc3/b9f314f29add32330b2ee359e2ad5aba/raw/0068945bf19bc50b9847d5938286c74953aa97e3/gist-backup.py
# chmod 755 ./gist-backup.py
# USER=mattmc3 python3 gist-backup.py
from __future__ import absolute_import, division, print_function, unicode_literals
import json
import urllib
from subprocess import call
@mattmc3
mattmc3 / stdin2args.zsh
Created January 3, 2024 03:15
convert piped input to args
# convert piped input to args
if [[ ! -t 0 ]] && [[ -p /dev/stdin ]] && (( $# == 0 )); then
set -- "${(@f)$(cat)}"
fi
@mattmc3
mattmc3 / 1-setopts.zsh
Last active January 2, 2024 15:47
ZSH - options by framework
## ZSH Options
# http://zsh.sourceforge.net/Doc/Release/Options.html
# Changing Directories
# http://zsh.sourceforge.net/Doc/Release/Options.html#Changing-Directories
setopt auto_cd # if a command isn't valid, but is a directory, cd to that dir
setopt auto_pushd # make cd push the old directory onto the directory stack
setopt pushd_ignore_dups # don’t push multiple copies of the same directory onto the directory stack
setopt pushd_minus # exchanges the meanings of ‘+’ and ‘-’ when specifying a directory in the stack
@mattmc3
mattmc3 / README.md
Last active January 2, 2024 00:50
zsh: zstyle examples

zstyle booleans

Setup foo,bar,baz boolean vars

zstyle ':example:foo' doit yes
zstyle ':example:bar' doit no
# leave baz unset
@mattmc3
mattmc3 / 01 - test_834.edi
Last active December 24, 2023 00:55
AWK - convert HIPAA 5010 X12 834 Benefit Enrollment to TSV
ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
GS*PO*4405197800*999999999*20101127*1719*1421*X*004010VICS
ST*834*0179
BGN*00*1*20050315*110650****4
REF*38*SAMPLE_POLICY_NUMBER
DTP*303*D8*20080321
N1*P5*COMPAN_NAME*FI*000000000
INS*Y*18*030*20*A
REF*0F*SUBSCRIBER_NUMBER
NM1*IL*1*JOHN DOE*R***34*1*0000000
@mattmc3
mattmc3 / find_bigrams.md
Last active December 1, 2023 14:35
Find common bigrams

Find common bigrams

Bigrams are 2-letter combos. When designing a keyboard layout, it's common to optimize for comfort and speed by analyzing bigrams. Here's a simple shell script to do a quick-and-dirty bigram analysis.

Instructions

Download Shai's corpus for Colemak: