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 / 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
@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 / branch_handling.md
Last active October 31, 2017 19:15
some options & shortcuts to make git branch management simple and sane

Run these once to setup git options:

git config --global push.default current
git config --global merge.defaultToUpstream true
git config --global branch.autosetupmerge true
git config --global branch.autosetuprebase remote
git config --global alias.cb 'checkout -b'
git config --global alias.ps 'push -u'
git config --global alias.pl '!git fetch -p && git rebase'

Use them like this:

@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 / 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 / inside.sh
Created November 26, 2013 13:11
inside the heroku beast
~/projects$ h run bash
Running `bash` attached to terminal... up, run.2192
~ $ uname -a
Linux 7fa29fb1-2e9c-4510-a0a7-df92cfaff4c8 3.8.11-ec2 #1 SMP Fri May 3 09:11:15 UTC 2013 x86_64 GNU/Linux
~ $ free -m
total used free shared buffers cached
Mem: 34302 29994 4307 0 1927 8232
-/+ buffers/cache: 19835 14466
Swap: 34815 732 34083
@tjmcewan
tjmcewan / instructions.md
Last active December 26, 2015 11:59
Ninefold db updates

This is a quick way to Push or Pull your app database between your local machine and your Ninefold app server. "Pushing" is useful in the early stages of app development when you need to update seed data. "Pulling" is eternally useful for debugging.

  1. setup public key authentication (the SSH username is "user"). NB ensure you don't remove the existing SSH key - it's needed by the Ninefold Portal.

  2. obtain your database password from the "database" tab in the Ninefold portal.

  3. put the password where Postgres can find it (on the database server): echo "localhost:*:*:app:<PASSWORD>" > ~/.pgpass then chmod 0600 .pgpass more info on password files