Skip to content

Instantly share code, notes, and snippets.

Avatar

Pieter van der Meulen pmeulen

View GitHub Profile
@pmeulen
pmeulen / public_encrypt_decrypt.php
Created Feb 21, 2020
Functions for encrypting and decrypting data with RSA public key crypto using the PHP openssl_* functions.
View public_encrypt_decrypt.php
<?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 Jul 9, 2020
Script to create and restore snapshots of Azure VMs using azure-cli (az)
View snapshot.sh
#!/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 Sep 22, 2017
Script to repair a Time Machine network volume
View repair-timemachine-disk-network.sh
#!/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 Sep 9, 2017
A spamassassin plugin that calls clamav
View clamav.pm
## 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 Aug 19, 2017
Making random opaque strings much more easy to compare by giving them a backgroud color that is derived from the value of the sring
View HTMLColorFingerprint.php
<?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 Nov 26, 2018
Create a brare git repository in dropbox that can be used as a remote
View git_remote_in_dropbox.md

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 Nov 3, 2018
Python script to represent a list of CIDR network ranges in the smallest number of CIDR subnets. Subnets can be added and substracted.
View cidr_merge.py
#!/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 / shibmd-1.0.xsd
Last active Oct 20, 2016
XML Schema for urn:mace:shibboleth:metadata:1.0 namespace
View shibmd-1.0.xsd
<?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 / accountgen.php
Created Jul 19, 2015
Generate user accounts for SimpleSAMLphp example-userpass
View accountgen.php
<?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 / SecureRandomPassword.php
Last active Aug 29, 2015
Generate a secure random password in the the "Base32" alphabet
View SecureRandomPassword.php
<?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
You can’t perform that action at this time.