Skip to content

Instantly share code, notes, and snippets.

View douglascayers's full-sized avatar

Doug Ayers douglascayers

View GitHub Profile
@douglascayers
douglascayers / github-cascade-backmerge.sh
Last active August 1, 2023 02:23
Iteratively backmerges pull requests in sequence using the GitHub and Git CLIs
#!/bin/bash
# For when you have a train of pull requests lined up like A -> B -> C -> D
# and you make a change to base D that you now want backmerged to C then B then A.
set -e
# ----------------------------------------------------------------------------
# List the pull request number (e.g. 42) in order that the backmerges
@douglascayers
douglascayers / loop.sh
Created November 15, 2022 19:49
Bash FOR loop with batched concurrency
#!/bin/bash
# https://unix.stackexchange.com/questions/103920/parallelize-a-bash-for-loop
NAMES=($(cat names.csv))
BATCH_SIZE=4
for NAME in ${NAMES[@]}; do
# Increment or reset our counter
@douglascayers
douglascayers / git-merge.sh
Last active October 14, 2022 15:33
Merge current branch into another then switch back
export HEAD=$(git branch --show-current) && \
git checkout -B staging origin/staging && \
git merge --no-ff $HEAD && \
git push && \
git checkout $HEAD
@douglascayers
douglascayers / sync-heroku-circleci-env-vars.sh
Created September 28, 2022 19:22
Sync Heroku config vars to CircleCI project env vars
#!/bin/bash
set -e
if [ -z "${CIRCLECI_API_TOKEN}" ]; then
echo "Missing required environment variable: CIRCLECI_API_TOKEN"
echo "You can create one at https://app.circleci.com/settings/user/tokens"
fi
ORG_NAME="your-gh-org"
@douglascayers
douglascayers / vspr.sh
Created September 27, 2022 22:44
Shell function to set the git config `branch.${branch}.github-pr-owner-number` for GitHub Pull Requests and Issues extension
# Workaround to force the GitHub Pull Requests and Issues extension
# to associate to the most recent, open pull request for the checked out branch.
# https://github.com/microsoft/vscode-pull-request-github/issues/3798#issuecomment-1259003851
function vspr() {
local branch=$(git branch --show-current)
local repo_json=$(gh repo view --json name,owner,parent,isFork)
local is_fork=$(jq -r '.isFork' <<< $repo_json)
local fork_owner=$(jq -r '.owner.login' <<< $repo_json)
local fork_repo=$(jq -r '.name' <<< $repo_json)
@douglascayers
douglascayers / set-circleci-envs.sh
Created September 15, 2022 19:00
Shell script to set CircleCI project environment variables
#!/bin/bash
# Export `CIRCLECI_API_TOKEN` env var by creating your own api token
# https://app.circleci.com/settings/user/tokens
ORG_NAME="changeme"
REPO_NAME="changeme"
PROJECT_SLUG="github/${ORG_NAME}/${REPO_NAME}"
ENV_KEY="FOO"
@douglascayers
douglascayers / docker-destroy.sh
Last active April 3, 2024 16:19
🗑 Delete all docker services, containers, images, and volumes
#!/usr/bin/env zsh
# Exit when any command fails
set -e
# https://docs.docker.com/engine/reference/commandline
SCRIPT_NAME=$(basename ${0})
DELETE_BUILDER_CACHE=0
@douglascayers
douglascayers / .bash_profile
Created July 16, 2022 21:57
Bash alias to open a git remote in your browser.
# Opens in a browser the git remote url
# specified by the given remote.
#
# Arguments:
# $1 = git remote name (default is 'origin')
#
# Usage:
# $ openg [remote]
#
# Examples:
@douglascayers
douglascayers / graph.ts
Created August 31, 2021 04:23
Graph class that implements depth-first search algorithm.
/**
* References:
* https://adelachao.medium.com/graph-topological-sort-javascript-implementation-1cc04e10f181
* http://peterknolle.com/page/51/
* https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search
*/
class Graph {
private vertices: Record<string, Array<string>>;
@douglascayers
douglascayers / async-poller.ts
Created December 23, 2019 05:25
Typescript async polling function. Simple proof-of-concept before I adopted the p-retry npm module.
/**
* The function you pass to `asyncPoll` should return a promise
* that resolves with object that satisfies this interface.
*
* The `done` property indicates to the async poller whether to
* continue polling or not.
*
* When done is `true` that means you've got what you need
* and the poller will resolve with `data`.
*