Skip to content

Instantly share code, notes, and snippets.

View qmacro's full-sized avatar

DJ Adams qmacro

View GitHub Profile
@qmacro
qmacro / lxc-container-setup
Last active September 5, 2024 16:18
Set up new LXC container on Crostini, with Tailscale and Docker
#!/usr/bin/env bash
# This is to set up what I need in a new LXC container on Crostini.
# Step 1
# In termina, create the container and jump into it like this:
# lxc launch images:debian/12 mycontainer && lxc exec mycontainer bash
# Step 2
# Generate a Tailscale auth key at
@qmacro
qmacro / request.test.sh
Created July 12, 2024 08:07
request-test script for the July Developer Challenge
#!/usr/bin/env bash
set -eo pipefail
# Tester options (empty by default), possible values: nolog
declare TESTER_OPTIONS="${TESTER_OPTIONS:-}"
# Tester service is <tester-service-base>/tester
declare TESTER_SERVICE_BASE="${TESTER_SERVICE_BASE:-https://developer-challenge-2024-07.cfapps.eu10.hana.ondemand.com}"
declare TESTER_SERVICE="$TESTER_SERVICE_BASE/tester"
@qmacro
qmacro / google-oauth
Created May 8, 2024 14:52
Single script to obtain an OAuth bearer token to use in Google API calls
#!/usr/bin/env bash
set -eo pipefail
# CLIENT_ID and CLIENT_SECRET should be in .env
set -a; test -f .env && source .env; set +a
declare REDIRECT_URI="http://127.0.0.1"
declare SCOPE="${SCOPE:-https://www.googleapis.com/auth/spreadsheets}"
declare OAUTH_BASE_URL="https://accounts.google.com/o/oauth2"
@qmacro
qmacro / Dockerfile
Created January 18, 2024 19:00
Dockerfile heredoc test
# syntax=docker/dockerfile:1
# Definition of 'false': 'does nothing, unsuccessfully' (i.e. emits an error exit code)
FROM alpine as old-way
RUN \
echo hello && \
false && \
echo goodbye
@qmacro
qmacro / solution.jq
Created December 2, 2022 14:26
AOC2022 Day 1
#!/usr/bin/env jq
# Run with:
# -R (read raw strings, not JSON texts)
# -s (slurp all inputs into an array)
# i.e. jq -f solution.jq -R -s input.dat
# When initially read in, the input will look like this:
# "1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000\n"
@qmacro
qmacro / cols.awk
Last active September 29, 2022 00:52
# Output fields in a nicely arranged columnar format.
# Takes two optional variables:
# COLS: comma-separated list of column nrs (fields) to output (default: all)
# GAP: gap required between each column (default: 1)
# Take care of the GAP default
BEGIN {
if (GAP == "") GAP=1
}
@qmacro
qmacro / episodes-A.js
Last active April 13, 2020 11:36
Code at Home Ep.8
const episodes = [
{
number: 1,
title: 'Setting up for our first challenge'
},
{
number: 2,
title: 'Fizz-Buzz and Fibonacci'
},
{
// -----------------------------------------------------
// Globals, contants
// -----------------------------------------------------
TASKLIST = "DJ's list";
LABEL_PENDING = "newtask";
LABEL_DONE = "newtaskdone";
// -----------------------------------------------------
// getTasklistId_(tasklistName)
// Returns the id of the tasklist specified
@qmacro
qmacro / fixposts.js
Last active December 24, 2018 08:41
/**
* From previous conversions from WordPress to Ghost, I have a lot of posts
* with links to other posts, where the link is actually incorrect. The
* incorrect links are missing the day (dd) part of the URL.
*
* This script is a quick and dirty way of fixing them, in-place:
* 1) read all the posts, and work out a slug-to-anchor mapping
* 2) go through all the posts, using regexes to find incorrect links
* and replace them with the correct ones, referencing the mapping
* from the first step.