Skip to content

Instantly share code, notes, and snippets.

View alexec's full-sized avatar
😀

Alex Collins alexec

😀
View GitHub Profile
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
package proc
import "sync"
var locks = &sync.Map{}
// KeyLock return a mutex for the key.
// This func never frees un-locked mutexes. It is only suitable for use-cases with a small number of keys.
func KeyLock(key string) *sync.Mutex {
actual, _ := locks.LoadOrStore(key, &sync.Mutex{})
@alexec
alexec / lsof.go
Last active January 3, 2023 04:26
//go:build darwin
package lsof
/*
#include <netinet/in.h>
#include <arpa/inet.h>
#include "fcntl.h"
#include "libproc.h"
*/
@alexec
alexec / tcpkill.md
Created June 29, 2021 17:16
How to use tcpkill with Docker

How to use tcpkill to simulate network failure (e.g. for FMEA testing) by breaking network connections between your pod and a remote service.

I'm assuming your pod runs as non-root.

You'll need to add your user to the sudoers file, so in your Dockerfile:

FROM ubuntu
# ...
RUN adduser --disabled-password --uid 9653 runner
@alexec
alexec / run.sh
Created June 29, 2021 17:10
How to find out what files are on a Docker image without a shell
docker export $(docker run -d ubuntu) | tar -t
{
"version": "latest"
}
{
"parameters": [
{
"name": "my-param",
"value": "my-value"
}
]
}
#! /bin/sh
set -eu
export ARGOCD_UI_PATH=$ARGOCD_PATH/../argo-cd-ui
[ ! -d $ARGOCD_PATH ] && echo "$ARGOCD_PATH does not exist" >&2 && exit 1
[ ! -d $ARGOCD_UI_PATH ] && echo "$ARGOCD_UI_PATH does not exist" >&2 && exit 1
scale() {
set -eu
#!/bin/sh
set -Eeuo pipefail
get_xml_attribute() {
set -Eeuo pipefail
name=$1
while read line ; do
echo $line | sed "s/.*$name=\"\([^\"]*\)\".*/\1/"
done
}