Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / rand.bash
Created April 6, 2017 15:49
Bash - generate random base64 string
openssl rand -base64 32
@mattmc3
mattmc3 / IOrderedDictionary.cs
Last active September 4, 2023 14:06
OrderedDictionary
// https://stackoverflow.com/questions/2629027/no-generic-implementation-of-ordereddictionary/9844528?noredirect=1#comment135796623_9844528
// https://choosealicense.com/licenses/mit
// or https://choosealicense.com/licenses/unlicense
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace mattmc3.Common.Collections.Generic
{
public interface IOrderedDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IOrderedDictionary
@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 February 25, 2023 03:09
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 / tasks.json
Created April 6, 2017 00:44
VSCode tasks for running a Makefile
// Makefile
// ${workspaceRoot} the path of the folder opened in VS Code
// ${file} the current opened file
// ${fileBasename} the current opened file's basename
// ${fileDirname} the current opened file's dirname
// ${fileExtname} the current opened file's extension
// ${cwd} the task runner's current working directory on startup
{
"version": "0.1.0",
"command": "bash",
@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 / logger.py
Last active December 2, 2022 01:12
Python - basic console logger
import logging
# setup simple console logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
# handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s',
'%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)