Skip to content

Instantly share code, notes, and snippets.

Avatar
Let's change the world

Andrew Johnson blackandred

Let's change the world
View GitHub Profile
@blackandred
blackandred / cancel-context-when-process-fails.go
Last active Apr 6, 2022
Cancel Context, when exec.Command{} process fails
View cancel-context-when-process-fails.go
type ReadCloserWithCancellationWhenProcessFails struct {
Parent io.ReadCloser
Process *exec.Cmd
Cancel func()
}
func (r ReadCloserWithCancellationWhenProcessFails) Read(p []byte) (n int, err error) {
return r.Parent.Read(p)
}
@blackandred
blackandred / watch-and-exec.sh
Created Jul 6, 2020
Watch given directory for changes, then execute a command
View watch-and-exec.sh
#!/bin/bash
# Copyright 2020 RiotKit Tech Collective
# ======================================
# 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
@blackandred
blackandred / until-compose-env-running.sh
Last active Jul 6, 2020
Wait until the last container of docker-compose will be stopped
View until-compose-env-running.sh
#!/bin/bash
# Copyright 2020 RiotKit Tech Collective
# ======================================
# 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
@blackandred
blackandred / add-known-host-by-git-url.py
Last active Jul 6, 2020
Add host to known hosts by GIT url - supports both https and ssh url / to be used with eg. Ansible
View add-known-host-by-git-url.py
#!/usr/bin/env python3
# Apache License 2.0
#
# Read full license text at: http://www.apache.org/licenses/LICENSE-2.0
# Copyleft (c) 2020 RiotKit Tech Collective
#
# About RiotKit
#
# We are grassroot activists for social change, we respond to the needs of grassroot organizations,
@blackandred
blackandred / letsencrypt-openshift-certificates-apply.sh
Last active Jul 6, 2020
Apply letsencrypt certificates to the OKD/OpenShift 3.11+
View letsencrypt-openshift-certificates-apply.sh
#!/bin/bash
# Copyright 2020 RiotKit Tech Collective
# ======================================
# 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
@blackandred
blackandred / README.md
Created Dec 18, 2019
Experiments with HTTP requests aborting in Python & PHP
View README.md
php -S 0.0.0.0:8001 ./Serve.php
sudo python ./client.py
@blackandred
blackandred / postgres-replication-test.sh
Created Nov 25, 2019
Debug PostgreSQL replication
View postgres-replication-test.sh
#!/bin/bash
#
# Perform a test replication into the /tmp/wal-test directory
# This command will tell you what is wrong with the replication
#
pg_receivewal -h 127.0.0.1 -p 5444 --user replication -D /tmp/wal-test/
@blackandred
blackandred / jvm
Last active Jul 1, 2019
Use dockerized java easily, instead of running java on host. Keeps gradle cached packages in a mapped volume.
View jvm
#!/bin/bash
SUDO=${SUDO:-sudo}
IMAGE=${IMAGE:-openjdk:8-jre-stretch}
PARAMS="$@"
if [[ ! ${PARAMS} ]]; then
PARAMS="exit 1"
fi
@blackandred
blackandred / Makefile
Created Oct 11, 2018
Makefile template
View Makefile
.SILENT:
# Colors
COLOR_RESET = \033[0m
COLOR_INFO = \033[32m
COLOR_COMMENT = \033[33m
## This help screen
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
@blackandred
blackandred / doctrine.php
Last active Sep 9, 2018
Doctrine: Automatic mapping for entities in multiple directories (DDD)
View doctrine.php
<?php declare(strict_types=1);
/*
* Doctrine auto-mapping
*/
if (!function_exists('generateDoctrineMappings')) {
function generateDoctrineMappings(): array
{
$domains = glob(__DIR__ . '/../../src/Domain/*/Entity');