Skip to content

Instantly share code, notes, and snippets.

@mdelillo
mdelillo / run-func-on-dirs-in-parallel.sh
Created August 5, 2020 14:43
Runs a bash function on all child directories in parallel
#!/usr/bin/env bash
set -euo pipefail
do_something() {
dir=$1
echo "doing something with $dir"
sleep 1
}
@mdelillo
mdelillo / mkexec.sh
Created July 23, 2020 20:55
Bash function for creating `fly exec` scripts from concourse task config files
mkexec() {
if [[ $# != 1 ]]; then
echo "Usage: ${FUNCNAME[0]} </path/to/task/config.yml>"
return 1
fi
task_config=$1
if ! [[ -f "${task_config}" ]]; then
echo "Could not find file ${task_config}"
@mdelillo
mdelillo / create-builder
Last active July 21, 2020 21:01
Create a builder from specified buildpacks, buildpackages, and mixins
#!/usr/bin/env bash
set -euo pipefail
timestamp="$(date +%s)"
builder_name="builder-${timestamp}"
mixins=""
buildpackages=()
buildpacks=()
@mdelillo
mdelillo / open-tracker-story.kmmacros
Created May 11, 2020 21:23
Keyboard Maestro - Open Tracker Story
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Activate</key>
<string>Normal</string>
<key>CreationDate</key>
<real>610923730.30395901</real>
<key>Macros</key>
@mdelillo
mdelillo / cf-deployment-with-cats.yml
Created March 17, 2020 20:13
Concourse pipeline for getting a cf-deployment with the toolsmiths-env-resource and running CATS
---
resource_types:
- name: toolsmiths-envs
type: docker-image
source:
repository: cftoolsmiths/toolsmiths-envs-resource
resources:
- name: cf-deployment-env
type: toolsmiths-envs
@mdelillo
mdelillo / loop.sh
Created January 10, 2020 20:40
Function to run a command in parallel batches
#!/usr/bin/env bash
loop() {
total_runs=$1
runs_per_loop=$2
shift
shift
int_regex='^[0-9]+$'
#!/usr/bin/env bash
for pipeline in $(fly -t "$target" pipelines --json | jq -r '.[].name'); do
for job in $(fly -t "$target" jobs -p "$pipeline" --json | jq -r '.[].name'); do
for build in $(fly -t "$target" builds -j "$pipeline/$job" -c 10 --json | jq -r '.[] | select(.status != "pending" and .status != "started").name'); do
( fly -t "$target" watch -j "$pipeline/$job" -b "$build" | grep -q "$SEARCH_PATTERN" && echo "$pipeline/$job/$build" ) &
done
done
done
@mdelillo
mdelillo / parallel-jobs-in-batches.sh
Last active April 30, 2019 18:56
Run batches of bash things in parallel
#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -ne 1 ]; then
echo "Usage: $(basename "$0") <number-of-times-to-run-job>"
exit 1
fi
total_runs="$1"
@mdelillo
mdelillo / insert-lines.sh
Last active March 14, 2020 01:33
Insert multiple lines containing trailing slashes after a matching line in a file
#!/usr/bin/env bash
set -euo pipefail
cat >file.txt << 'EOF'
LINE 1 \
LINE 2 \
LINE 5
EOF
@mdelillo
mdelillo / certs.go
Created July 22, 2018 21:44
Create a self-signed CA and use it to create a signed certificate
package main
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"