Skip to content

Instantly share code, notes, and snippets.

import requests
import urllib.parse
import xml.etree.ElementTree as ET
from ansible.errors import AnsibleError
from ansible.utils.display import Display
from ansible.plugins.lookup import LookupBase
DOCUMENTATION = """
name: incommon_scopes
author: Simon Leary <[email protected]>
import logging
from typing import Any, List
from ldap3 import BASE, MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE, Connection
from ldap3.core.exceptions import LDAPException
from ldap3.utils.log import ERROR, set_library_log_detail_level
"""
wrapper interface for ldap3
sacrifices performance for simlicity
- name: add gitlab to /root/.ssh/known_hosts
ansible.builtin.known_hosts:
name: "{{ (item | split())[0] }}"
key: "{{ item }}"
loop: "{{ lookup('pipe', 'ssh-keyscan gitlab.rc.umass.edu gitlab.unity.rc.umass.edu') | split('\n') | reject('match', '^#') }}"
#!/bin/bash
set -euo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
# usage: backup.bash /path/to/backup/dir num_backups_to_keep
# backup dir must contain a file called 'index' which must contain just a number
# this index number is used to delete older backup files
# if this script fails, the index will be modified so that no backups will be deleted in the future
# to re-enable deletion of old backups, overwrite index back to a number
# recommended usage is with cron jobs of varying frequency
# this way it is easy to keep logs from recently, yesterday, last week, last month, ...

3 layers:

  • default
    • there are no include rules
    • exclude rules are in one of ignore.d.workstation, ignore.d.server, or ignore.d.paranoid
      • exclude rule directory is based on "report level" in logcheck.conf
    • subject line option in logcheck.conf is EVENTSUBJECT
  • security/violations
    • include rules are in violations.d
  • exclude rules are in violations.ignore.d
#!/bin/bash
set -euo pipefail
trap 'git checkout -q main' EXIT
trap 'git checkout -q main' INT
git checkout -q main
for commit in $(git rev-list HEAD); do
git checkout -q "$commit"
if grep -q init webroot/admin/pi-mgmt.php; then
echo "init found! $commit"
exit
@simonLeary42
simonLeary42 / a_dark2light.py
Last active August 24, 2025 22:56
convert colors from dark mode to light mode
import re
import sys
import colorsys
def clamp(x, _min, _max):
return max(_min, min(x, _max))
def hsl_clamp_l(hex: str, _min: float, _max: float):
import sys
import shutil
import argparse
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument("path")
parser.add_argument("--width", type=int, default=None)
parser.add_argument("--height", type=int, default=None)
args = parser.parse_args()
def _cluster(sorted_nums_ids: list[tuple[int, str]], max_reduction: int) -> list[tuple[int, str]]:
"cluster integers by reducing them by no more than max_reduction"
# if the entire range can be reduced to equal the lowest number without violating max_reduction
if sorted_nums_ids[-1][0] - sorted_nums_ids[0][0] <= max_reduction:
new_num = sorted_nums_ids[0][0]
return [(new_num, _id) for _, _id in sorted_nums_ids]
# divide and conquer. split the range at the biggest gap
# for each element, the corresponding gap is the distance between it and the previous element
gaps = [-1]
for i, (num, _) in enumerate(sorted_nums_ids[1:], start=1):
todos_fixmes:
image: alpine
script:
- apk add ripgrep curl
- todo_count="$(rg TODO . | wc -l)"
- fixme_count="$(rg FIXME . | wc -l)"
- curl "https://shields.io/badge/TODOs-$todo_count-blue" > todos.svg
- curl "https://shields.io/badge/FIXMEs-$fixme_count-red" > fixmes.svg
artifacts:
paths: