Skip to content

Instantly share code, notes, and snippets.

View michaelkitson's full-sized avatar

Mike Kitson michaelkitson

View GitHub Profile
@michaelkitson
michaelkitson / totp.sh
Last active September 5, 2024 16:22
A bash function to generate TOTP codes
#!/usr/bin/env bash
set -euo pipefail
# Dependencies: openssl, xxd, base32 (coreutils)
# generate_totp key [time_sec [digits]]
generate_totp() {
key=$1
key_hex=$(base32 -d <<<"$key" | xxd -plain)
time_sec=${2:-$(date +%s)}
@michaelkitson
michaelkitson / dnsip.sh
Last active July 10, 2024 11:46
dnsip.io/dnsip.dev - A very simple xip.io clone
DIR=`pwd`
read -p 'Acme Account Thumbprint: ' ACME_THUMBPRINT
# Basics
sudo apt update
sudo apt upgrade -y
# Turn off systemd DNS resolver
sudo sed -ri 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf
sudo sh -c 'rm /etc/resolv.conf && ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf'
@michaelkitson
michaelkitson / sprockets.rb
Created May 26, 2023 22:06
A quick and dirty sprockets extension example to transform images between formats.
# config/initializers/sprockets.rb
class ImageTransformer
def call(input)
filename, content_type = input.values_at(:filename, :content_type)
new_extension = content_type.split('/').last
converted = ImageProcessing::Vips.source(filename).convert!(new_extension)
{ data: converted.read, charset: nil }
ensure
converted&.unlink
end
@michaelkitson
michaelkitson / sourcemap_to_tar.rb
Created April 2, 2021 18:11
A quick ruby script to extract sources from a JS sourcemap
require 'json'
require 'rubygems/package'
unless ARGV.length == 1
puts "Usage: ruby sourcemap_to_tar.rb <sourcemap_file>"
exit 1
end
sourcemap_filename = ARGV.shift
sourcemap = JSON.parse(File.read(sourcemap_filename))
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *
@michaelkitson
michaelkitson / keybase.md
Created October 9, 2014 17:43
Keybase Proof

Keybase proof

I hereby claim:

  • I am michaelkitson on github.
  • I am michaelkitson (https://keybase.io/michaelkitson) on keybase.
  • I have a public key whose fingerprint is 4A86 FBDD 4083 57C0 83AE 8A2A 434E 0259 A6FE 17CA

To claim this, I am signing this object: