Skip to content

Instantly share code, notes, and snippets.

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

mattmc3 mattmc3

๐Ÿ
Python!
View GitHub Profile
@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;
@mattmc3
mattmc3 / pop_dim_date.sql
Last active February 20, 2025 23:47
Create postgresql date dimension
create table public.dim_date
(
id integer not null
primary key,
date_value date not null
unique,
datetime_value timestamp not null,
calendar_year integer not null,
calendar_month integer not null,
calendar_day integer not null,
@mattmc3
mattmc3 / keychron_v2_ansi_layout_ansi_67_2025-02-16.json
Last active February 16, 2025 18:54
config.qmk.fm Extend layout
{
"version": 1,
"notes": "",
"documentation": "\"This file is a QMK Configurator export. You can import this at <https://config.qmk.fm>. It can also be used directly with QMK's source code.\n\nTo setup your QMK environment check out the tutorial: <https://docs.qmk.fm/#/newbs>\n\nYou can convert this file to a keymap.c using this command: `qmk json2c {keymap}`\n\nYou can compile this keymap using this command: `qmk compile {keymap}`\"\n",
"keyboard": "keychron/v2/ansi",
"keymap": "keychron_v2_ansi_layout_ansi_67_2025-02-16",
"layout": "LAYOUT_ansi_67",
"layers": [
[
"KC_ESC",