Skip to content

Instantly share code, notes, and snippets.

View pmeulen's full-sized avatar

Pieter van der Meulen pmeulen

View GitHub Profile
@pmeulen
pmeulen / split_log.py
Last active May 14, 2025 11:15
Split a log file into multiple files based on the date at the start at each line. For that time when logrotate did not run...
#!/usr/bin/env python3
"""
Split a log file into multiple files based on the dates at the start at each line.
For that time when logrotate did not run...
See the help text for more information on using this script.
Limitations:
- The date must be at the start of each line must have a fixed length. This could be made more flexible by e.g. allowing
the user to provide a regex to match the date.
@pmeulen
pmeulen / macports_update_reminder.sh
Last active May 24, 2025 09:37
MacPorts update reminder. This is a script run from your shell profile (e.g. ~/.bash_profile). It prompts you to update MacPorts after 7 days every time you open a new terminal window and offers to run the update for you.
#!/usr/bin/env bash
# Copyright 2025 SURF bv
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@pmeulen
pmeulen / get-entity-by-scope.py
Last active June 25, 2024 11:09
Python script to get the first EntityDescriptor from a SAML 2.0 metadata file that has a shibmd:Scope Extension with the specified value and return the EntityDescriptor as XML
#!/usr/bin/env python3
"""
Script to get the first EntityDescriptor from a SAML 2.0 metadata file that has an IDPSSODescriptor with a shibmd:Scope
Extension with the specified value and return the EntityDescriptor as XML.
This allows you to get an EntityDescriptor for a identity provider from a large metadata file by the scope in its
EntityDescriptor.
This script uses XSLT to do the matching, so it can be easily modified to match on other criteria.
@pmeulen
pmeulen / public_encrypt_decrypt.php
Last active February 9, 2021 13:59
Functions for encrypting and decrypting data with RSA public key crypto using the PHP openssl_* functions.
<?php
/**
* Encrypt $plaintext using $rsa_public_key
*
* To decrypt the data the RSA private that corresponds to the $rsa_public_key is required.
*
* Because public key crypto is not suitable for arbitrary length data, encryption is done in two steps
* 1. Generate a random symmetric key and encrypt the plaintext with that key
@pmeulen
pmeulen / snapshot.sh
Last active June 18, 2024 14:53
Script to create and restore snapshots of Azure VMs using azure-cli (az)
#!/usr/bin/env bash
# Script to create and restore snapshots of the OS disk of Azure VMs
# Copyright 2018 SURFnet B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@pmeulen
pmeulen / repair-timemachine-disk-network.sh
Created September 22, 2017 17:58
Script to repair a Time Machine network volume
#!/bin/bash
set -e
###############################################################################
# This script tries to repair a Time Machine *network* backup (i.e. an APF
# share containing a sparsebundle) that is shared over a network using e.g. an
# Apple TimeCapsule, a NAS, Raspberry PI, ...
# The script must be run on the computer that created the backup
#
@pmeulen
pmeulen / clamav.pm
Created September 9, 2017 16:03
A spamassassin plugin that calls clamav
## A spamassassin plugin for calling clamav
# Version 2.0 was downloaded from https://wiki.apache.org/spamassassin/ClamAVPlugin
#
# # version 2.0, 2010-01-07
# - use SA public interface set_tag() and add_header, instead of
# pushing a header field directly into $conf->{headers_spam}
#
# # version 2.1, 2017-09-09 (pmeulen):
# - Allow ClamAV::Client, which is provided by debian package libclamav-client-perl, to be used
# in addition to File::Scan::ClamAV
@pmeulen
pmeulen / HTMLColorFingerprint.php
Created August 19, 2017 11:51
Making random opaque strings much more easy to compare by giving them a backgroud color that is derived from the value of the sring
<?php
/** Making opaque values like GUIDs or session identifiers easier to compare and distinguish
*
* By giving each opaque value a background color that is derived from the value itself, it
* becomes much easier to eyeball whether two values are likely to be the same. This really helps
* when reading logs or other diagnostic output that contain opaque identifiers like GUIDs or other
* opaque identifiers.
*
* Testing:
@pmeulen
pmeulen / git_remote_in_dropbox.md
Last active November 26, 2018 12:33
Create a brare git repository in dropbox that can be used as a remote

It is possible to use Dropbox as a "remote" repository. It is not perfect, updating or pushing to the remote from two location simultaniously will surely corrupt the repository. That being said it is a practical trick for syncing repositories between computers without both having write access to "origin" (i.e. github, gitlab or the like).

I store the repositories in a directory "git" in my dropbox folder. Create it if it does not yet exist, or make up you own name: mkdir ~/Dropbox/git/

  1. Change to the repository for which you want to create a remote
@pmeulen
pmeulen / cidr_merge.py
Last active November 3, 2018 21:58
Python script to represent a list of CIDR network ranges in the smallest number of CIDR subnets. Subnets can be added and substracted.
#!/usr/bin/env python
import argparse, sys
from netaddr import IPNetwork, IPSet
class IPNetworkArg:
def __init__(self, network):
network.strip()
self.add = True
if network[0] == '-':