Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@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",
@mattmc3
mattmc3 / ignore_markdown_dollar.sh
Created October 3, 2024 15:16
Bash + ble.sh - fix markdown copy/paste commands by stripping leading dollar sign '$'
# Strip leading dollar signs. Fixes commands pasted from markdown.
# Requires ble.sh: https://github.com/akinomyoga/ble.sh
# shellcheck disable=SC2016
ble/function#advice around ble/widget/default/accept-line '
if [[ "${_ble_edit_str:0:2}" == "$ " ]]; then
ble/widget/beginning-of-logical-line
ble/widget/insert-string "${_ble_edit_str:2}"
ble/widget/kill-forward-logical-line
fi
ble/function#advice/do
@mattmc3
mattmc3 / README.md
Last active September 23, 2024 19:00
colorschemes

colorschemes

Description

Simplistic theme fuzzy finder using themes from iterm2colorschemes.com, jq, and fzf.

Usage

$ colorschemes -h
@mattmc3
mattmc3 / dollarzero.zsh
Last active December 4, 2024 00:23
Zsh dollar zero $0
# Use %N in a file
0=${(%):-%N}
echo "dollar zero: $0"
# Use :a to get the absolute path
echo "dollar zero abs path: ${0:a}"
# Use :A to get the absolute path resolving symlinks
echo "dollar zero abs path: ${0:A}"
@mattmc3
mattmc3 / contains.sh
Last active December 4, 2024 11:27
POSIX helper functions
# Fish-like contains (https://fishshell.com/docs/current/cmds/contains.html)
contains() {(
while getopts "i" opt; do
case "$opt" in
i) o_index=1 ;;
*) return 1 ;;
esac
done
shift $(( OPTIND - 1 ))