Skip to content

Instantly share code, notes, and snippets.

View tomasbasham's full-sized avatar
🤓
I’d tell you a UDP joke... but you might not get it.

Tomas Basham tomasbasham

🤓
I’d tell you a UDP joke... but you might not get it.
View GitHub Profile
@tomasbasham
tomasbasham / bootstrap
Created May 22, 2023 23:07
Bootstrap Google Cloud Platform for Terraform
#!/usr/bin/env bash
set -eou pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
COMMAND=${0##*/}
DIRNAME=$(dirname "$0")
local threads = {}
function setup(thread)
table.insert(threads, thread)
end
function init(args)
count_2xx = 0
count_3xx = 0
count_400 = 0
@tomasbasham
tomasbasham / setup_server.sh
Last active May 17, 2022 12:28
Install Puppet agent and cloud-init on RHEL 8 (CentOS, RockyLinux, AlmaLinux)
#!/usr/bin/env bash
set -e
# Ensure the script is running as root
if [[ "$(id -u)" != '0' ]]; then
exec sudo "${BASH_SOURCE[0]:-$0}" "$@"
fi
try_install() {
@tomasbasham
tomasbasham / install_cloud_init.sh
Created May 16, 2022 18:50
Install cloud-init if not present on rhel 8
#!/usr/bin/env bash
set -e
# Ensure the script is running as root
if [[ "$(id -u)" != '0' ]]; then
exec sudo "$BASH_SOURCE" "$@"
fi
# Update the system
@tomasbasham
tomasbasham / install_puppet.sh
Created May 12, 2022 23:00
Install Puppet 7 on rhel 8 (Centos, RockyLinux, AlmaLinux)
#!/usr/bin/env bash
set -e
# Ensure the script is running as root
if [[ "$(id -u)" != '0' ]]; then
exec sudo "$BASH_SOURCE" "$@"
fi
# Update the system
@tomasbasham
tomasbasham / edge_cache.php
Created November 3, 2021 16:21
Control Cloudflare Edge Caching
/*
* Add a specific Cloudflare edge cache HTTP header to each HTTP response
* preventing defined pages from being cached at the edge. This is done
* selectively since some pages require dynamic content based on external
* factors such as geographic location of the request. All other static
* content will continue to be cached (i.e. JavaScript, CSS, images).
*
* To control the caching behaviour at the edge add a custom metadata field
* to the page:
*
require 'base64'
class SpanContext
def initialize(trace_id: '', span_id: '')
raise RuntimeError 'trace_id must be 16 bytes' unless trace_id.size == 16
raise RuntimeError 'span_id must be 8 bytes' unless span_id.size == 8
@version = [0]
@trace_id = [0] + trace_id.bytes # field id 0 + trace_id
@span_id = [1] + span_id.bytes # field id 1 + span_id
require 'digest'
require 'net/http'
password = ARGV[0] || 'Password'
hashed_password = Digest::SHA1.hexdigest password
# SHA1 hashes will be 40 characters long
prefix = hashed_password[0, 5].to_s.upcase # Get the first 5 characters
suffix = hashed_password[5..-1].to_s.upcase # Get the remaining 35 characters
@tomasbasham
tomasbasham / install.sh
Created May 23, 2018 12:41
rbenv install
CFLAGS='-g -O2' RUBY_CONFIGURE_OPTS=--with-openssl-dir=$(brew --prefix openssl) rbenv install

SSH agent forwarding and screen

When connecting to a remote server via SSH it is often convenient to use SSH agent forwarding so that you don't need a separate keypair on that server for connecting to further servers.

This is enabled by adding the

ForwardAgent yes

option to any of your Host entries in ~/.ssh/config (or alternatively with the -A option). Don't set this option in a wildcard Host * section since any user on the remote server that can bypass file permissions can now als use keys loaded in your SSH agent. So only use this with hosts you trust.