Skip to content

Instantly share code, notes, and snippets.

View theipster's full-sized avatar
🎣
Capabilities (teach a man to fish) > solutions (give a man a fish)

Alan Ip theipster

🎣
Capabilities (teach a man to fish) > solutions (give a man a fish)
  • @HLTech @HargreavesLansdown
  • Bristol, UK
  • 15:31 (UTC +01:00)
View GitHub Profile
@theipster
theipster / tfc-data-only-changes.log
Last active May 24, 2024 02:00
Reproduction steps for TFC data-only changes failing to be applied.
$ echo -en "data \"null_data_source\" \"this\" {}\n" > data.tf
$ echo -en "resource \"null_resource\" \"this\" {}\n" > resources.tf
$ echo -en "terraform {\n cloud {}\n}\n" > versions.tf
$ tail *.tf
==> data.tf <==
data "null_data_source" "this" {}
@theipster
theipster / main.sh
Created January 28, 2024 23:14
Tool for validating whether a Terraform plan is a pure refactor (i.e. zero changes)
#!/bin/sh
# Given a terraform plan at plan.json...
is_refactor=$(jq --exit-status -null-input '[inputs | .resource_changes[].change.actions[] | test("^(read|no-op)$")] | all' plan.json)
# If it's a refactor, do something - e.g. auto-approve a pull request.
@theipster
theipster / build-install-provider.sh
Last active July 30, 2023 02:43
Install custom built Crossplane provider on EKS (via CloudShell and ECR)
# In CloudShell...
# Checkout custom provider Git repo
CUSTOM_PROVIDER_PATH=... # repo-org/repo-path
CLONE_DIR=custom-provider
BRANCH_NAME=...
git clone https://github.com/$CUSTOM_PROVIDER_PATH.git --branch $BRANCH_NAME $CLONE_DIR
cd $CLONE_DIR
# Build custom provider from the directory containing the crossplane.yaml file
@theipster
theipster / better-git-subtree.sh
Created February 26, 2023 19:21
Better git subtree
#!/bin/sh
# Example of how to import Flyway migration scripts sourced in a separate repo
git fetch $(cat path/to/repo/url) refs/tags/<tag>:refs/tags/<tag>
git read-tree --prefix=db -u refs/tags/<tag>
git rm -r src/main/resources/db
git mv db/ src/main/resources/
git commit
git tag -d <tag>
@theipster
theipster / fix-wsl-ubuntu-time-draft.sh
Created February 4, 2023 21:08
Fix for WSL Ubuntu's time drift.
#!/bin/sh
# Despite the [official line](https://github.com/microsoft/WSL/issues/5324) reporting that the issue is fixed... it isn't.
# Fortunately, the solution documented at https://1kko.com/2460635 works, and is nicer than alternatives because it doesn't
# involve fiddling with the host. Here is that solution scripted up.
test "$(id -u)" != 0 && echo "Please run as root/sudo." && exit 1
sed --follow-symlinks -i.bak "s/^ConditionVirtualization=\!container/#\0/" /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
systemctl daemon-reload
@theipster
theipster / m3u8.js
Last active January 1, 2022 03:18
Parser for "simple" m3u8 playlists (skips integrity checks, etc.)
const downloadPlaylist = async (playlistUrl) => {
const playlist = await (await fetch(playlistUrl)).text();
const segmentUrls = playlist.split(/\r?\n/)
.map((line, index, lines) => /^#EXTINF: *([0-9]+(\.[0-9]+)?)(,.*)?/.test(line) && lines[index + 1])
.filter(segment => segment != false)
.map(segment => new URL(segment, playlistUrl).href);
const sleep = sec => new Promise(res => setTimeout(res, sec * 1000));
const segmentBlobs = [];
const now = Date.now();
@theipster
theipster / install-docker-compose.sh
Last active January 19, 2020 20:50 — forked from lmakarov/install-docker-compose.sh
Install docker-compose in boot2docker 1.7.0+
#!/bin.sh
DOCKER_COMPOSE_VERSION=1.20.1
# Download docker-compose to the permanent storage
echo 'Downloading docker-compose to the permanent VM storage...'
sudo mkdir -p /var/lib/boot2docker/bin
sudo curl -sL https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` -o /var/lib/boot2docker/bin/docker-compose
sudo chmod +x /var/lib/boot2docker/bin/docker-compose
sudo ln -sf /var/lib/boot2docker/bin/docker-compose /usr/local/bin/docker-compose