Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
tjmcewan / Hack Assembler.rs
Last active January 14, 2024 01:45
Hack Assembler in Rust
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{Read, Write};
fn predefined_symbols() -> HashMap<&'static str, u16> {
let mut symbols: HashMap<&str, u16> = HashMap::new();
symbols.insert("SP", 0);
symbols.insert("LCL", 1);
symbols.insert("ARG", 2);
@tjmcewan
tjmcewan / migration.sql
Last active December 31, 2023 17:13
Supabase Auth Hook for MFA/TOTP/AAL2 account lock
-- create a table to track failed MFA verification attempts
create table if not exists hub_admin.mfa_failed_verification_attempts(
user_id uuid not null references auth.users(id) on delete cascade
, factor_id uuid not null
, failed_at timestamp with time zone not null default now()
, deleted_at timestamp with time zone
);
create index if not exists idx_mfa_failed_verification_attempts_user_id on hub_admin.mfa_failed_verification_attempts(user_id);
-- a database function that takes a jsonb event and returns a jsonb response
@tjmcewan
tjmcewan / easy-copy.js
Created September 6, 2022 16:06
Bookmarklet to copy EasyRetro cards to your clipboard as markdown
javascript:
!(() => document.querySelectorAll('.easy-card-list').length < 1
? window.alert('EasyRetro board columns not found')
: (() => {
/* show all the comments first */
document.querySelectorAll('[aria-label="New comment"]').forEach(el => el.click());
navigator.clipboard.writeText(
[...document.querySelectorAll('.easy-card-list')]
/* for each column: get column header */
.map(l => [`# ${l.querySelector('.column-header').textContent.trim()}\n`]
@tjmcewan
tjmcewan / slack.sh
Created July 18, 2021 11:01 — forked from andkirby/slack.sh
Shell/Bash script for sending slack messages.
#!/usr/bin/env bash
####################################################################################
# Slack Bash console script for sending messages.
####################################################################################
# Installation
# $ curl -s https://gist.githubusercontent.com/andkirby/67a774513215d7ba06384186dd441d9e/raw --output /usr/bin/slack
# $ chmod +x /usr/bin/slack
####################################################################################
# USAGE
# Send message to slack channel/user
@tjmcewan
tjmcewan / localtunnel
Last active October 12, 2016 03:13
localtunnel restarter. all props to @michaelkeenan. slightly modified to be run as a executable & to remove ordinal numbers. original here: https://github.com/localtunnel/localtunnel/issues/81#issuecomment-218320442
#!/usr/bin/env ruby
require 'optparse'
options = {:subdomain => 'defaultdomain', :port => 3000}
parser = OptionParser.new do|opts|
opts.banner = "Usage: localtunnel [options]"
opts.on('-s', '--subdomain subdomain', 'Subdomain') do |subdomain|
options[:subdomain] = subdomain;
@tjmcewan
tjmcewan / awsm.json
Created October 27, 2015 01:07
Excerpt from awsm.json that shows CORS setup for an API Gateway endpoint.
"default": {
"statusCode": "200",
"headers": {
"Access-Control-Allow-Origin": {
"type": "string"
}
},
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'http://CORSdomain.com'"
},
@tjmcewan
tjmcewan / aws_route53_cleaner_instructions.md
Last active August 29, 2015 14:27
Want to delete a lot of old hosted zones on Route53? This should take the pain away.

AWS Route53 Hosted Zone Cleaner

Why?

My org buys lots of domains and configure lots of records on AWS. Removing them is a pain though; you have to remove each record set before you can remove the hosted zone. This makes it much more straightforward.

Feel free to use this; but you're on your own. I am not responsible if you break something.

Setup

You'll need ruby/ruby-gems and your AWS API credentials.

@tjmcewan
tjmcewan / keybase.md
Created April 28, 2015 23:50
keybase proof

Keybase proof

I hereby claim:

  • I am tjmcewan on github.
  • I am tjmcewan (https://keybase.io/tjmcewan) on keybase.
  • I have a public key whose fingerprint is 77AB E45C 44A2 6B7E C691 2F1F C16A 1AC7 7FAF 79D6

To claim this, I am signing this object:

@tjmcewan
tjmcewan / destroyer.rb
Created April 10, 2015 14:05
nation builder tag cleaner
require "spec_helper"
NATION = "my-nation"
EMAIL = "admin@example.com"
PASSWORD = "Password1"
TAG_PATTERNS_TO_DELETE = [
/^mass_tag_/,
/^valuable_member_/,
]
@tjmcewan
tjmcewan / thing.sh
Created February 19, 2015 09:14
find the 10 longest git commit **messages** (not changesets) in a repo
git log --pretty=oneline --abbrev-commit | awk '{print length() "\t" $1 }' | sort -rn | head -n 10