Skip to content

Instantly share code, notes, and snippets.

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

mattmc3 mattmc3

๐Ÿ
Python!
View GitHub Profile
@mattmc3
mattmc3 / better-defaults.el
Created July 25, 2023 17:37
Emacs better-defaults
;;; better-defaults.el --- Fixing weird quirks and poor defaults
;; Copyright ยฉ 2013-2020 Phil Hagelberg and contributors
;; Author: Phil Hagelberg
;; URL: https://git.sr.ht/~technomancy/better-defaults
;; Version: 0.1.4
;; Package-Requires: ((emacs "25.1"))
;; Created: 2013-04-16
;; Keywords: convenience
@mattmc3
mattmc3 / readme.md
Last active May 9, 2023 16:54
Fish Shell - Wordle Helper

Fish Wordle Helper

Wordle is a simple word game where you try to guess a 5-letter word each day. This gist contains a small Fish function to help you narrow down the list of possible answers based on the scores from each guess.

How To Play

Guess the Wordle in 6 tries.

  • Each guess must be a valid 5-letter word.
  • The color of the tiles will change to show how close your guess was to the word.
@mattmc3
mattmc3 / palette.sh
Last active March 5, 2023 00:21
Keyboard.io palette JSON generator
#!/bin/sh
# Author: mattmc3
# Copyright: 2023
# License: MIT
print_err() {
printf '%s\n' "$my_name: Error: $1" >&2
exit ${2:-1}
}
@mattmc3
mattmc3 / pipetest.md
Last active April 22, 2025 09:26
Python read stdin arguments from pipe

Pipetest

clitest and stdin don't always work well together. StackOverflow wasn't much help (shocked pikachu)! Buried deep in the interwebs is the bash advice to check for a TTY and whether stdin was piped with this: if [ ! -t 0 ] && [ -p /dev/stdin ];. Using this, I wanted to see how to do something similar in Python to make clitest work. Even deeper on the internet was this gem, which led me to the answer - use stat in Python to test whether stdin is a FIFO (pipe).

Thus, the answer to this hours long search is simply this function:

@mattmc3
mattmc3 / foo.zsh
Created February 3, 2023 01:38
Zsh collect args
# Collect args
# -- traditional, piped|, <redirected
function collect_args {
local data args=()
if [[ ! -t 0 ]]; then
while IFS= read -r data || [[ -n "$data" ]]; do
args+=("$data")
done
fi
@mattmc3
mattmc3 / frame-recenter.el
Created October 26, 2022 20:08
Emacs frame (window) re-center
;; https://christiantietze.de/posts/2022/04/emacs-center-window-current-monitor-simplified/
(defun my/frame-recenter (&optional frame)
"Center FRAME on the screen.
FRAME can be a frame name, a terminal name, or a frame.
If FRAME is omitted or nil, use currently selected frame."
(interactive)
(unless (eq 'maximised (frame-parameter nil 'fullscreen))
(modify-frame-parameters
frame '((user-position . t) (top . 0.5) (left . 0.5)))))
@mattmc3
mattmc3 / auto_dircmd.zsh
Created September 15, 2022 12:22
Zsh auto_cd-like feature implementation
setopt no_auto_cd
function auto_dircmd {
# Run a command when PS1 contains a valid directory, similar to auto_cd
if [[ -d "$PWD/$BUFFER" ]] &&
(( ! $+functions[$BUFFER] )) &&
(( ! $+commands[$BUFFER] ))
then
BUFFER="ls \"./$BUFFER\""
fi
@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 December 4, 2024 00:25
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=()