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 / SecureRandomPassword.php
Last active August 29, 2015 14:18
Generate a secure random password in the the "Base32" alphabet
<?php
// Generate a secure random password in the the "Base32" alphabet
// Uses openssl secure random function for RNG generation
// Because the set of characters has 32 = 2^5 distinct values, characters can be
// easily selected, without bias (i.e. each character has the same chance
// of being selected), by using 5 bits of randomness per character.
// Note: strlen(base32_alphabet) MUST be exactly 2^bits_per_value
@pmeulen
pmeulen / accountgen.php
Created July 19, 2015 13:49
Generate user accounts for SimpleSAMLphp example-userpass
<?php
/*
$config: php config array
$group: account name prefix
$email: A pollibly existing email addres so you can receive mail
$scope: Used as schachome, EPPN scope and names
$count: number of accounts to generate
Example:
@pmeulen
pmeulen / shibmd-1.0.xsd
Last active October 20, 2016 20:09
XML Schema for urn:mace:shibboleth:metadata:1.0 namespace
<?xml version="1.0" encoding="US-ASCII"?>
<schema targetNamespace="urn:mace:shibboleth:metadata:1.0"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
version="1.0">
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
@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] == '-':
@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 / 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 / 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 / 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 / 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 / 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