Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -euo pipefail
ssh_client_ip=$(echo $SSH_CLIENT | awk '{print $1}')
w_json="$(w --pids $USER | jc --w)"
if [ -z "$w_json" ]; then
echo "error: 'w --pids | jc --w' didn't print anything!"
exit 1
fi
#!/bin/env -iS PATH=/bin bash --noprofile --norc -eou pipefail
HOME=~
# this will fubar your environment and maybe kill your shell if you source it
if (return 0 2>/dev/null); then
echo "do not source this script! execute it as its own process."
return 1
fi
@simonLeary42
simonLeary42 / rdr2_cook.ahk
Created November 12, 2024 08:45
cooking macro for red dead redemption 2
; Simon Leary
; 12/31/2021
; when you go to cook, as you click on the item to cook, press scrollLock to keep cooking
; to stop press scrollLock again
#maxthreadsperhotkey 2
ScrollLock::
{
def printable_length(x: str) -> int:
assert "\n" not in x and "\t" not in x, "no newlines or tabs allowed!"
# https://stackoverflow.com/q/14693701/12035739
ansi_be_gone = re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]")
return len(ansi_be_gone.sub("", x))
def fmt_table(table: list[list]) -> list[str]:
"""
I would use tabulate but I don't want nonstandard imports
def human_readable_size(size_in_bytes: int) -> str:
current_size = size_in_bytes
current_unit = "bytes"
if current_size == 0:
return "0 bytes"
for new_unit in ["KB", "MB", "GB", "TB", "PB"]:
new_size = current_size / 1000
if new_size < 1:
return f"{current_size:.2f} {current_unit}"
else:
import sys
import json
import yaml
import shutil
import subprocess
from ansible.plugins.action import ActionBase
"""
fails if bitwarden is not unlocked
@simonLeary42
simonLeary42 / stickies-always-match-style.json
Last active October 6, 2024 21:30
Karabiner: rebind ctrl+v to paste and match style in the Stickies app
{
"description": "ctrl+v -> ctrl+shift+option+v (only Stickies)",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.apple\\.Stickies$"
],
"type": "frontmost_application_if"
@simonLeary42
simonLeary42 / highlighted-diff.py
Created September 10, 2024 20:21
parses a patch file and adds highlighting for specific changes made within a block of text. May pass large strings into SequenceMatcher, which scales very poorly.
def _format_diff_strings(before: str, after: str) -> str:
before_lines = before.splitlines()
after_lines = after.splitlines()
diff = difflib.unified_diff(before_lines, after_lines, lineterm="")
output = ""
removed_lines = []
added_lines = []
def _format_added_removed():
# given the current state of the `added` and `removed` variables, add text to the `output`
@simonLeary42
simonLeary42 / diffr-python-strings.py
Last active September 10, 2024 20:24
Runs GNU Diff and [diffr](https://github.com/mookid/diffr) to compare strings without tempfiles. UNIX only.
import os
import threading
import subprocess
before = ""
after = ""
before_read_fd, before_write_fd = os.pipe()
after_read_fd, after_write_fd = os.pipe()
diff_proc = subprocess.Popen(
@simonLeary42
simonLeary42 / _do_paths_exist.py
Created September 3, 2024 14:44
don't use the `stat` module on each, that's too slow. Instead, do all at once
# ansible module
import os
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
argument_spec=dict(
paths=dict(type="list", required=True),
follow=dict(type="bool", default=True),
),