Skip to content

Instantly share code, notes, and snippets.

View sapslaj's full-sized avatar

Justin Roberson sapslaj

View GitHub Profile
import { Construct } from 'constructs';
function renderConstructTree(scope: Construct, renderNode?: (construct: Construct) => string): string {
let result = '';
function renderBranch(tree: Construct, branch: string) {
if (renderNode === undefined) {
renderNode = (c: Construct) => `${c.constructor.name} [${c.node.id}]`;
}
const isGraphHead = branch.length === 0;
if (!isGraphHead) {
@sapslaj
sapslaj / imds
Created May 30, 2024 13:24
AWS EC2 IMDS helper script
#!/bin/sh
set -e
TOKEN=`curl -sSL -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/$1
echo
@sapslaj
sapslaj / output
Created February 21, 2024 23:15
cdktf-aws-cdk idempotency issue
$ npx ts-node repro.ts
/home/sapslaj/code/github.com/sapslaj/scratch/cdktf-adapter-repro/node_modules/constructs/src/construct.ts:447
throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
^
Error: There is already a Construct with name 'bucket43879C71' in TerraformHost [adapter]
at Node.addChild (/home/sapslaj/code/github.com/sapslaj/scratch/cdktf-adapter-repro/node_modules/constructs/src/construct.ts:447:13)
at new Node (/home/sapslaj/code/github.com/sapslaj/scratch/cdktf-adapter-repro/node_modules/constructs/src/construct.ts:71:17)
at new Construct (/home/sapslaj/code/github.com/sapslaj/scratch/cdktf-adapter-repro/node_modules/constructs/src/construct.ts:499:17)
at new TerraformElement (/home/sapslaj/code/github.com/sapslaj/scratch/cdktf-adapter-repro/node_modules/cdktf/lib/terraform-element.ts:36:5)
at new TerraformResource (/home/sapslaj/code/github.com/sapslaj/scratch/cdktf-adapter-repro/no
@sapslaj
sapslaj / disable_yt_subtitles.js
Last active September 9, 2024 17:09
Auto-disable subtitles with Enhancer for YouTube
// 1. copy/paste this into the Custom Script in Enhancer for YouTube
// 2. enable "Automatically execute the script when YouTube is loaded in a tab"
// 3. ???
// 4. profit
const ccbutton = document.querySelector('.ytp-subtitles-button');
if (ccbutton && ccbutton.attributes['aria-pressed'].value === 'true') {
// note: set the above to `=== 'false'` if you want subtitles to always enable
ccbutton.click();
}
@sapslaj
sapslaj / black_pprint.py
Last active May 18, 2024 00:47
Pretty print Python object with Black
import black
import black.mode
def pprint(o):
mode = black.mode.Mode(target_versions={black.mode.TargetVersion.PY311})
print(black.format_str(repr(o), mode=mode))

Write a Terraform module that creates an AWS Route53 record that does active-active failover to two backend servers with healthchecks.

Sure, I can help you with that! Here's an example Terraform module that creates an AWS Route53 record that does active-active failover to two backend servers with healthchecks.

First, create a variables.tf file to define the input variables for the module:

variable "zone_id" {
  type        = string
  description = "The ID of the Route53 hosted zone"
@sapslaj
sapslaj / INSTRUCTIONS.md
Last active July 21, 2022 02:26
Standalone script to help manage notes
  1. Create git repo mkdir notes && cd notes && git init
  2. Copy note.py (with or without the .py file extension) into git repo
  3. Run ./note --new My First Note to create a new note
  4. Run ./note --save to commit.

Optional steps:

  • Set EDITOR and do ./note --new --open ... to immediate open the new note in your editor
  • Create a private repo on git remote service (e.g. GitHub, GitLab, etc.) and set that as remote origin.
  • This means you can do ./note --save --push to immediately commit and push the new commit to the remote.
@sapslaj
sapslaj / automount-sshfs.service
Last active November 7, 2021 21:52
complicatedly automount sshfs mounts
# /home/sapslaj/.config/systemd/user/automount-server.service
# sudo systemctl daemon-reload && systemctl --user enable --now automount-server.service
[Unit]
Description=automount sshfs
StartLimitIntervalSec=60
StartLimitBurst=4
[Service]
ExecStart=/home/sapslaj/.local/bin/automount_sshfs
Restart=on-failure
@sapslaj
sapslaj / extract-to-folder.nemo_action
Last active November 21, 2023 01:59
Extract To Folder Nemo Action
[Nemo Action]
Active=true
Name=Extract to %f
Comment=Extract to new folder called "%f"
Exec=<extract-to-folder.py %F>
Icon-Name=gnome-mime-application-x-compress
Selection=any
Extensions=zip;7z;ar;cbz;cpio;exe;iso;jar;tar;tar;7z;tar.Z;tar.bz2;tar.gz;tar.lz;tar.lzma;tar.xz;apk;
Quote=double
@sapslaj
sapslaj / renew-atlassian-letsencrypt-cert.sh
Last active May 9, 2018 05:31
Script to renew Atlassian (Jira, Confluence, etc) applications that use a Let's Encrypt certificate
SITE=jira.example.com
PASS=muhpassword
KEYTOOL=/opt/atlassian/jira/jre/bin/keytool
KEYSTORE=/home/jira/.keystore
SERVICE=jira
# pull down nginx since it uses port 80
systemctl stop nginx
# Use port 80 to renew the cert