Skip to content

Instantly share code, notes, and snippets.

View beezly's full-sized avatar

Andrew Beresford beezly

View GitHub Profile
beezly /
Last active February 26, 2024 15:51
Demo rust code for calculating Greatest Common Denominators using Euclidian Algorithm
use std::time::Instant;
const ITERATIONS: i32 = 100000000;
fn main() {
let mut line = String::new();
println!("Input your numbers: ");
let _ = std::io::stdin().read_line(&mut line).unwrap();
let mut split = line.split_whitespace();
let a =;
beezly /
Created April 28, 2020 10:04
This pile of garbage will so SSM RDP on a Mac if you have the aws-cli and Microsoft RDP client installed. I'm not proud of this but it was useful to me.
#!/usr/bin/env zsh -e
LOCAL_PORT=$(( $RANDOM + 32767 )) # Handily $RANDOM gives a number between 0 and 32767, so this will give us a random port between 32767-65535
aws ssm start-session --region eu-west-1 --target "${target_id}" --document-name AWS-StartPortForwardingSession --parameters "localPortNumber=${LOCAL_PORT},portNumber=${REMOTE_PORT}" &
RD_TEMP=$(mktemp -d)
beezly / demo.c
Created April 11, 2020 17:11
MMX/SSE demo
On a VM I got...
Allocating 134217728 bytes of RAM and writing a pattern to it.
allocate_ram: Took 15770 cycles
before first x86_add: Address 0xafd54010: 00000000000000000000000000000000
after first x86_add: Address 0xafd54010: 02020202020202020202020202020202
after last x86_add: Address 0xafd54010: cacacacacacacacacacacacacacacaca
x86_add: Took 13213002422 cycles
beezly /
Last active February 20, 2020 11:03
1password CLI wrapper - caches your "my" login token
#!/bin/bash -e
# You can use this script in two ways
# 1. Source it in to an existing script to get access to your credentials
# e.g.
# #!/bin/bash
# . ~/bin/op-wrapper
# details=$(op get item 'Top Secret Password')
# 2. Wrap another script or command with this script
# e.g.
# ~/bin/op-wrapper ./myscript up down left right
beezly /
Last active February 12, 2020 15:01
My shonky script for rotating AWS CLI access credentials - requires jq
#!/bin/bash -e
# First step, backup the old creds
tsec=$(date +%s)
pushd ~/.aws >/dev/null
tar -zcf "credential-backup-${tsec}.tar.gz" config credentials
popd > /dev/null
# Get the current key ID
beezly /
Last active January 28, 2020 16:57
Correctly configuring TLS on RDS PostgreSQL instances

In an "out of the box" configuration, RDS PostgreSQL doesn't configure TLS in a safe way.

The server will allow non-TLS connections and most clients will not bother to validate the TLS certificates presented to it anyway.

But first...

Don't Panic

Assuming that you have configured other security measures like VPC Security Groups

beezly /
Created September 9, 2019 13:09
Use kpasswd to rotate through a number of passwords between your old and new passwords
#!/usr/bin/env bash
declare -a PASSWORDS
let last_cycle=CYCLE+1
for i in $(seq ${last_cycle}); do
echo $i
beezly /
Created January 13, 2019 18:19
ESP32 Hardware Interrupts in micropython
import machine
import sys
import utime
# Error buffer for inside ISRs
import micropython
class Run():
def __init__(self):
beezly /
Last active July 19, 2018 14:23
get a vault token using azure
#!/bin/bash -e
resource="https://<your resource URL>"
instance_data=$(curl -s -H 'Metadata: true' "${api_version}")
offer_data=$(curl -s -H 'Metadata: true' "${api_version}&resource=${resource}")
rg=$(jq -r .compute.resourceGroupName <<< $instance_data)
name=$(jq -er .compute.vmScaleSetName <<< $instance_data)
beezly / gist:52567aa8210fa16eae74a556ef14f0da
Created April 19, 2018 21:16
Delete One Password Items Duplicated by Title
op list items | jq -r 'group_by(.overview.title) | .[] | select(length > 1) | min_by(.updatedAt) | .uuid' | xargs -n 1 op item delete