Skip to content

Instantly share code, notes, and snippets.

View TheMatt2's full-sized avatar

Matthew Schweiss TheMatt2

View GitHub Profile
@TheMatt2
TheMatt2 / unsafe_windows_ver.py
Created September 29, 2024 15:01
Hacky little Python script to get Windows Version directly out of running process memory. This is a toy. Not sure why you would really want to do this.
"""
Hacky little Python script to get Windows Version directly
out of running process memory.
This is a toy. Not sure why you would really want to do this.
Windows undocumented API: https://stackoverflow.com/a/79014708/8524178
Requires the unsafe.py file from https://github.com/DavidBuchanan314/unsafe-python/blob/main/unsafe.py
"""
@TheMatt2
TheMatt2 / errno_usages.py
Created September 22, 2024 16:58
Quick Python script to search UNIX man pages for what errno codes can be return by what system functions, and generates a CSV files with the results.
import re
import os
import csv
import sys
import textwrap
import subprocess
from io import StringIO
from colorama.ansitowin32 import AnsiToWin32 as AnsiToText
class AnsiToText:
@TheMatt2
TheMatt2 / strerror_.c
Last active September 27, 2024 02:13
// #include <stdio.h>
// #define XSTR(x) STR(x)
// #define STR(x) #x
// #pragma message "GLIBC " XSTR(__GLIBC__) "." XSTR(__GLIBC_MINOR__)
// strerror_.h
#ifndef STRERROR_H
#define STRERROR_H
@TheMatt2
TheMatt2 / toml_anywhere.py
Created February 9, 2024 03:18
A wrapper that allows any command line program to have a `--config` flag. No explicit support required!
"""
Toml Everywhere
A wrapper that allows any command line program to have a `--config` flag.
No explicit support required!
Call as:
$ toml_everywhere.py program [argument ...] --config config.cfg
@TheMatt2
TheMatt2 / pathtype_simplified.py
Last active October 20, 2023 00:42
Simplier PathType object for helping parse argparse inputs. Takes up less lines of code and removes rarely used features (still present on pathtype_v2.py)
"""
Simplified PathType
- Simplify for common case
- Only one type, no more (never used really)
- No dash support, just simplier
- No symilnk (never used)
A helper type for input validation in argparse for paths.
This provides a convienent way to check the path type and existance.
@TheMatt2
TheMatt2 / pathtype_v2.py
Created October 12, 2023 05:17
Python PathType helper type for input validation in argparse for paths.
"""
PathType
A helper type for input validation in argparse for paths.
This provides a convienent way to check the paths type, existance, and
potentially use "-" to reference stdin or stdout.
This class is provided as an alternative to argparse.FileType(), which
does not open the path, only validates it and supports directories.

Checkbox Tables in Markdown

An attempt to make a list of the supported ways to make a table with checkboxes in Markdown.

Results as of October 2023.


Below is the style element that formats the colors of the colored check mark emojis.

# Because it turns out writing files is hard
# Process can crash halfway through, and a collision can overwrite the file
# mid operation.
# https://stackoverflow.com/questions/7645338/how-to-do-atomic-file-replacement
# http://www.weirdnet.nl/apple/rename.html
import os
import hjson
import filelock
def safe_json_read(filename, timeout = None):
@TheMatt2
TheMatt2 / generator_pickler.py
Last active March 2, 2023 17:18
Make unused Python generators Pickle-able!
"""
Simply little utility function to make it possible to pickle generators.
While generator instances can not actually be pickled, this saves the generator
function and only creates a generator instance when the first value is accessed.
The goal is to make it possible to pass generators, with arguments, through multiprocessing
which uses pickling internally to move objects between Python processes.
import multiprocessing