Skip to content

Instantly share code, notes, and snippets.

View beezly's full-sized avatar

Andrew Beresford beezly

View GitHub Profile
@beezly
beezly / gcd.rs
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 = split.next().unwrap().parse().unwrap();
@beezly
beezly / main.py
Created January 13, 2019 18:19
ESP32 Hardware Interrupts in micropython
import machine
import sys
import utime
# Error buffer for inside ISRs
import micropython
micropython.alloc_emergency_exception_buf(100)
class Run():
def __init__(self):
@beezly
beezly / gist:9b2de3749d687fdbff3f
Last active April 19, 2023 13:14
Log Nest temperatures into a Google Spreadsheet. Update the username and password values and create a resource trigger to call "getData" at regular intervals.
function performLogin(email, password) {
var payload = {
"username" : email,
"password" : password
};
var options = {
"method" : "post",
"payload" : payload
};
@beezly
beezly / gist:4250079
Created December 10, 2012 11:24
Google Script Spreadsheet function to iterate over all cells and insert the value 0 if the cell is blank
function zeroCells() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheets()[0];
var selection=sheet.getDataRange();
var columns=selection.getNumColumns();
var rows=selection.getNumRows();
for (var column=1; column < columns; column++) {
for (var row=1; row < rows; row++) {
var cell=selection.getCell(row,column);
if (cell.isBlank()) {
@beezly
beezly / gist:267b80557900b865bc92
Last active February 17, 2021 10:37
Find the SSL/TLS version clients are negotiate with your SSL server. Adapt the "src port 443" part as per your requirements. Uses tshark from https://www.wireshark.org
tshark -f 'src port 443 and ether[0x42]=0x16 and ether[0x47]=0x02' -T fields -e ip.dst_host -e ssl.handshake.version
@beezly
beezly / ssm-rdp.sh
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
REMOTE_PORT=3389
target_id=$1
aws ssm start-session --region eu-west-1 --target "${target_id}" --document-name AWS-StartPortForwardingSession --parameters "localPortNumber=${LOCAL_PORT},portNumber=${REMOTE_PORT}" &
SESSION_PID=$!
RD_TEMP=$(mktemp -d)
@beezly
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
beezly / op-wrapper.sh
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
beezly / aws-rotate-key.sh
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
beezly / TLS_on_RDS_Postgres.md
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