Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
๐Ÿ
Python!

mattmc3 mattmc3

๐Ÿ
Python!
View GitHub Profile
@mattmc3
mattmc3 / myscript.zsh
Created March 24, 2026 13:16
Zsh - test for antidote
echo "myscript.zsh gist"
@mattmc3
mattmc3 / simple-dark-mode-toggle.js
Last active March 18, 2026 14:01
TamperMonkey script to toggle dark mode
// ==UserScript==
// @name Simple Dark Mode Toggle
// @namespace http://tampermonkey.net/
// @version 2.3
// @description Toggle dark mode on any site with UI pill toggle and keyboard shortcut
// @match *://*/*
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_getValue
// @grant GM_setValue
@mattmc3
mattmc3 / smart-up-and-down.zsh
Last active January 8, 2026 13:37
Fish like up/down history/buffer navigation in Zsh
# 0 = history mode, 1 = edit mode
typeset -g __editing=0
# Up: history until editing begins
function smart-up() {
if (( __editing )); then
zle up-line-or-history
else
zle up-history
fi
@mattmc3
mattmc3 / expandShortFlags.go
Created September 4, 2025 01:00
Go expandShortFlags
// turn -abc5 into -a -b -c5
// ex:
// takesValue := map[rune]bool{'c': true}
// expandedArgs := expandShortOpts(os.Args[1:], takesValue)
func expandShortFlags(args []string, withValue map[rune]bool) []string {
var out []string
doubledash := false
for _, arg := range args {
if doubledash {
out = append(out, arg)
@mattmc3
mattmc3 / normalize_flags.sh
Last active June 17, 2025 02:44
Bash getopts - normalize flags
#!/usr/bin/env bash
# Normalize --long-flags to -s short ones for use with getopts.
normalize_flags() {
local shortopt longopt
local -a args=()
local -A spec=()
# Process option definitions until we hit the -- separator
while [[ "$#" -gt 0 && "$1" != -- ]]; do
@mattmc3
mattmc3 / colorize-paths.awk
Last active March 8, 2025 20:36
awk - Colorize any path in command output
#!/usr/bin/awk -f
# colorize-path - add color to paths in specified field
# usage:
# command | ./bin/colorize-paths
# git ls-tree -r HEAD | ./bin/colorize-paths -v field=4
# ls -la | ./bin/colorize-paths -v field=9
#
BEGIN {
@mattmc3
mattmc3 / magic-enter.xsh
Created February 26, 2025 21:02
Xonsh magic enter
from xonsh.built_ins import XSH
$MAGIC_ENTER_GIT_COMMAND = "git status -sb ."
$MAGIC_ENTER_OTHER_COMMAND = "ls -lahF ."
$MAGIC_ENTER_RUN_COMMAND = ""
@events.on_transform_command
def magic_enter(cmd, **_):
"""Custom Enter key behavior: runs 'ls' if no command was given."""
if not cmd.strip():
@mattmc3
mattmc3 / get-script-dir.fish
Created February 26, 2025 13:21
Fish: Get directory of current script
#!/usr/bin/env fish
path resolve (status --current-filename)/..
@mattmc3
mattmc3 / prompt.sh
Created February 26, 2025 12:48
Bash prompt bottom padding
# 5 lines from the bottom
PS1=$'\n\n\n\n\n\e[5A'"$PS1"
@mattmc3
mattmc3 / alter_table.sql
Created February 21, 2025 00:35
Add audit fields to pg table
ALTER TABLE public.mytable
ADD COLUMN add_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN add_user VARCHAR(255) NOT NULL DEFAULT current_user,
ADD COLUMN change_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN change_user VARCHAR(255) NOT NULL DEFAULT current_user;