Skip to content

Instantly share code, notes, and snippets.

View blackandred's full-sized avatar
Let's change the world

Andrew Johnson blackandred

Let's change the world
  • Non-profit, activist
  • Saskatoon, Canada
View GitHub Profile
@blackandred
blackandred / create-chroot.sh
Created January 21, 2023 15:32
Helper script to create a chroot environment
#!/bin/bash
# ------------------------------------------------------------------------------------------------
# Creates a minimum operating system environment required for selected binaries to run
# Usage: chroot-create.sh "/path/where/to/store/environment" list-of-binaries psql pg_restore
#
# After the environment is created just do as the regular user: fakechroot fakeroot chroot /path/where/to/store/environment /bin/sh
# or directly: fakechroot fakeroot chroot /path/where/to/store/environment psql --help
# ------------------------------------------------------------------------------------------------
@blackandred
blackandred / cancel-context-when-process-fails.go
Last active April 6, 2022 06:47
Cancel Context, when exec.Command{} process fails
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 July 6, 2020 19:27
Watch given directory for changes, then execute a command
#!/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 July 6, 2020 19:28
Wait until the last container of docker-compose will be stopped
#!/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 July 6, 2020 06:23
Add host to known hosts by GIT url - supports both https and ssh url / to be used with eg. Ansible
#!/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 July 6, 2020 19:29
Apply letsencrypt certificates to the OKD/OpenShift 3.11+
#!/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 December 18, 2019 19:01
Experiments with HTTP requests aborting in Python & PHP
php -S 0.0.0.0:8001 ./Serve.php
sudo python ./client.py
@blackandred
blackandred / postgres-replication-test.sh
Created November 25, 2019 19:35
Debug PostgreSQL replication
#!/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 July 1, 2019 07:24
Use dockerized java easily, instead of running java on host. Keeps gradle cached packages in a mapped volume.
#!/bin/bash
SUDO=${SUDO:-sudo}
IMAGE=${IMAGE:-openjdk:8-jre-stretch}
PARAMS="$@"
if [[ ! ${PARAMS} ]]; then
PARAMS="exit 1"
fi
@blackandred
blackandred / Makefile
Created October 11, 2018 04:54
Makefile template
.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"