Skip to content

Instantly share code, notes, and snippets.

View b0tting's full-sized avatar
🔠

Mark Otting b0tting

🔠
  • Delft, the Netherlands
View GitHub Profile
@b0tting
b0tting / winwalk.py
Last active September 22, 2025 09:51
Python os.walk() alternative that treats windows junctions as symlinks and will not iterate into them.
import os
import stat
def is_reparse_point(path: str) -> bool:
"""
Return True if the given path is a Windows reparse point (junction, symlink, mount point, etc.).
On non-Windows, just use os.path.islink.
"""
try:
st = os.lstat(path)
@b0tting
b0tting / checkPackages.js
Last active September 16, 2025 19:57
Given a list of compromised NPM packages, check to see which have an updated or retracted version, or which are still compromised when pulling the most recent. Run with "node .\checkPackages.js .\packages.txt".
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const https = require('https');
// Cache latest version lookups per package to ensure only one fetch per unique package
/** @type {Map<string, Promise<string>>} */
const latestVersionCache = new Map();
@b0tting
b0tting / image_to_arrays.py
Created December 22, 2024 23:36
Python: Converts a PNG / JPG whatever file to a dictionary or array of arrays of RGB values
# Description: Converts a PNG / JPG whatever file to a dictionary or array of arrays of RGB values
from argparse import ArgumentParser
from pathlib import Path
import sys
from PIL import Image
class PNGConverter:
def __init__(self, file=None, verbose=False):
@b0tting
b0tting / create_whitelist.py
Last active March 13, 2025 10:00
Python script that extracts a flat list of sites from a mirrormanager website URL. The usecase is to generate a white list for everything that can be touched from a yum.repos.d directory. In case of Rockylinux, note you'll need both Rocky Linux and Fedora site mirrors!
# This will use beuaitful soup to get thet list of linux mirror sites from a linux mirror site. Usecase
# for me was to generate a whitelist for a proxy server.
import re
import sys
try:
import argparse
import requests
from bs4 import BeautifulSoup
except ImportError as e:
@b0tting
b0tting / gist:dcfdd4ca867a9fab9d2896e41645adaa
Created November 18, 2024 10:12
Generate a UUID in jinja
{%- macro uuid() %}
{%- set uuid_generate = namespace(uuid_template = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') %}
{%- set characterlist = "1234567890abcdef" %}
{%- set uuid_generate.new_uuid = '' %}
{%- for x in uuid_generate.uuid_template %}
{%- if x == 'x' %}
{%- set uuid_generate.new_uuid = uuid_generate.new_uuid + characterlist | random %}
{%- else %}
{%- set uuid_generate.new_uuid = uuid_generate.new_uuid + x %}
{%- endif %}
@b0tting
b0tting / gist:f1a83a8ecca42ae37cc2c40d6174cead
Last active July 5, 2024 09:13
Installing the AWS CFN helper scripts on Ubuntu 24.04. At the moment of writing, the aws-cfn-bootstrap-py3-latest.tar.gz helpers such as cfn-init and cfn-signal are not updated for python 3.12. A solution would be to use a virtual environment during bootstrapping or cloudinit.
# This should be able to run in cfn-init / EC2 userdata
export DEBIAN_FRONTEND=noninteractive
export VENV_DIR=/opt/aws/cfn-bootstrap-venv
export HELPER_SCRIPTS_BIN_DIR=/opt/aws/bin
# Install python 3.11 from deadsnakes, this will not be the default python, that will stay on 3.12
apt update
apt-get install -y tzdata software-properties-common # Maybe only required in docker?
add-apt-repository -y ppa:deadsnakes/ppa
apt update
@b0tting
b0tting / bgg_xml_api_demo.html
Last active May 5, 2024 18:42
An example of using the Boardgame Geek XML API to query, show a list of games and allow the user to select one
<html>
<head>
<title>Board game geek search demo</title>
</head>
<body>
<script>
</script>
<h1>Board game geek search demo</h1>
@b0tting
b0tting / DeleteKeyStorageItems.yml
Last active April 5, 2024 12:28
When working with the Rundeck key storage API you have a limited set of calls to work the tree with. I had a use case where I need to clear out a given path before syncing. This recursive ansible task walks the Rundeck key storag tree and deletes all items. Ansible will complain loudly about having to reuse the item loop_var, but you can safely …
- name: Calling out current path
debug:
msg: "Deleting path: {{ deleting_storage_path }}"
- name: Get path content
vars:
query_uri: "/api/{{ rundeck_api_version }}/storage/{{ deleting_storage_path }}/"
uri:
url: "{{ rundeck_url + (query_uri | urlencode) }}"
method: GET
@b0tting
b0tting / gitlab_clone_registry.py
Created December 18, 2023 10:11
Script used to move all container images from one Gitlab registry to another, including every tag. This script first pulls all containers with all tags to the system running the script, then retags with the new registry and pushes the images to the target repository.
import json
import sys
import requests
from docker.errors import DockerException
try:
import docker
except ImportError:
sys.exit("Please run 'pip install docker' first")
@b0tting
b0tting / letsencrypt_symlink_error.py
Last active January 19, 2021 23:37
Script to solve "/etc/letsencrypt/live/.../cert.pem to be a symlink Renewal configuration file /etc/letsencrypt/renewal/...conf is broken. " certbot problem.