Skip to content

Instantly share code, notes, and snippets.

View jsjohnst's full-sized avatar

Jeremy Johnstone jsjohnst

View GitHub Profile
read -r -p 'Secret Key: ' secret_key; dgst=$(printf '%016X' $(($(date -u '+%s') / ${TOTP_PERIOD_SECONDS:=30})) | xxd -r -p | openssl dgst -sha1 -mac hmac -macopt "hexkey:$(printf $secret_key | tr '[:lower:]' '[:upper:]' | base32 -d | xxd -p)"); offset=$(( 2 * 16#${dgst: -1} )); token=$(( ( 16#${dgst:offset:8} & 0x7fffffff ) % 10**${TOTP_DIGITS:=6} )); printf "%0${TOTP_DIGITS}d\n" "$token"
@jsjohnst
jsjohnst / fix-docker-mac-tcp-idle-timeout.sh
Created June 12, 2020 16:20
Docker for Mac has a default TCP idle timeout of 300 seconds. This script helps disable/restore that as needed
#!/usr/bin/env bash
opmode=$1
if [[ "x$opmode" == "x" ]]; then
echo "Usage:"
echo " ${0} <opmode>"
echo "Where <opmode> is either 'patch' or 'revert'"
exit 0;
fi
PD = .5;
s[t_, f_] := t^.6 - f
dt[cl_, ps_, sg_, hf_, dp_, f_, flag_] :=
Module[{sv, basePt},
{PointSize[ps],
sv = s[t, f];
Hue[cl (1 + Sin[.02 t])/2, 1, .3 + sg .3 Sin[hf sv]],
basePt = {-sg s[t, f] Sin[sv], -sg s[t, f] Cos[sv], dp + sv};
Point[basePt],
If[flag,
@jsjohnst
jsjohnst / Makefile
Created September 17, 2018 15:32
Have you ever needed to create SAN self-signed certificates before? This will help make the process easier. Duplicate line 18 and increment the counter for each additional `alt_name` you need in the cert.
all: internal-ssl.key internal-ssl.pem
internal-ssl.pem: internal-ssl.conf
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout internal-ssl.pem -out internal-ssl.pem -config internal-ssl.conf -extensions 'v3_req'
internal-ssl.key: internal-ssl.conf
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout internal-ssl.key -out internal-ssl.crt -config internal-ssl.conf -extensions 'v3_req'

Keybase proof

I hereby claim:

  • I am jsjohnst on github.
  • I am jsjohnst (https://keybase.io/jsjohnst) on keybase.
  • I have a public key ASBBhxKVheZIDl7uTgJleEIrPk1SaJy3mjI6f26RuHaIVQo

To claim this, I am signing this object:

import urllib
import json
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
state = "UT"
states = ['AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS',
'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV',
@jsjohnst
jsjohnst / EmailEveryone.applescript
Created August 9, 2016 17:59
Send emails to everyone in your address book
set senderName to "Sender Name"
set senderEmail to "sender@example.com"
on trim(txt)
repeat with i from 1 to (count txt) - 1
if (txt begins with space) then
set txt to text 2 thru -1 of txt
else
exit repeat
end if
@jsjohnst
jsjohnst / mongo_disk_usage.js
Last active November 21, 2020 05:48
Calculate total disk usage by MongoDB. storageSize is the actual used space, totalSize is the amount of disk space allocated.
db = db.getSiblingDB("admin");
dbs = db.runCommand({ "listDatabases": 1 }).databases;
storageSize = 0;
totalSize = 0;
dbs.forEach(function(database) {
db = db.getSiblingDB(database.name);
stats = db.stats();
1. Install: http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.8.dmg
2. Then launch XQuartz and open the preferences. On the output tab, click "Full-screen mode"
3. Follow instructions below to install and setup xmonad
$ brew install Caskroom/cask/haskell-platform
$ vim ~/.bash_profile
export PATH="$HOME/Library/Haskell/bin:$PATH"
$ PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig:$PKG_CONFIG_PATH \
LIBRARY_PATH=/opt/X11/lib:$LIBRARY_PATH \
CPPFLAGS="-I/opt/X11/include" \
@jsjohnst
jsjohnst / aws_iam_policy.json
Last active August 26, 2015 19:00 — forked from kixorz/aws_iam_policy.json
Update Route53 DNS records from your EC2 instance using this simple Ruby script. You can call it from rc.local after setting your hostname locally. First parameter is the desired <hostname>.<domain> Domain and other parameters are hardcoded. This script is useful for handling internal DNS changes in your systems after instance changes. Attached …
{
"Statement": [
{
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect": "Allow",
"Resource": [