Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff McCune jeffmccune

View GitHub Profile
View lock_automation.yaml
blueprint:
name: Lock Automation
description: Create automations to react to lock actions
domain: automation
input:
device:
name: Lock Device
description: Lock Device
selector:
@jeffmccune
jeffmccune / README.md
Last active Jun 29, 2021
Lookup a GCP role given a permission
View README.md

Lookup a GCP role given a permission

The GCP docs generally list necessary permissions. For example the private service access docs state the servicenetworking.services.addPeering permission is needed, but doesn't mention which role has this permission.

Use this script to find the roles which grant a specific permission.

gcloud iam roles list '--format=value(name)' > roles.lst
xargs -n1 gcloud iam roles describe --format=json < roles.lst | tee roles.all
@jeffmccune
jeffmccune / max_write.ini
Last active Feb 25, 2021
Filestore Performance
View max_write.ini
# https://cloud.google.com/filestore/docs/performance#testing_performance
# https://github.com/portworx/fio-tools
# https://gist.githubusercontent.com/wallnerryan/cb8f9946a6fb9bdc0aabd403d9550e08/raw/seqwrite.fio
[global]
ioengine=sync
direct=0
fsync_on_close=1
randrepeat=0
nrfiles=1
@jeffmccune
jeffmccune / with_gcp_creds
Created Jan 5, 2021
Execute a command with Google Service Account credentials and cleanup after
View with_gcp_creds
#! /bin/bash
#
# Execute a command with GOOGLE_APPLICATION_CREDENTIALS set to point to a
# Google Service Account key JSON file. The key data is managed by vault and
# the lease is released on exit.
#
# Requires: vault, jq, base64
: "${VAULT_ADDR:=https://vault.example}"
: "${DEPLOY_ENV:=dev}"
View consolesave.user.js
// ==UserScript==
// @name Console Save
// @namespace https://gist.github.com/jeffmccune/f5fa4a15445cee0a3795d28d5371622b
// @updateUrl https://gist.githubusercontent.com/jeffmccune/f5fa4a15445cee0a3795d28d5371622b/raw/consolesave.user.js
// @downloadUrl https://gist.githubusercontent.com/jeffmccune/f5fa4a15445cee0a3795d28d5371622b/raw/consolesave.user.js
// @version 1.0.1
// @description Save an object in the console
// @author Jeff McCune
// @match https://home.personalcapital.com/*
// @grant none
@jeffmccune
jeffmccune / holdings.rb
Created Oct 5, 2020
Transform the holdings data from Personal Capital into CSV for spreadsheet processing
View holdings.rb
#! /usr/bin/env ruby
#
#
require 'json'
def run!
h = Holdings.new; h.load("holdings.json")
h.table.each do |row|
puts row.join("\t")
end
@jeffmccune
jeffmccune / atom_zfs.md
Last active Sep 23, 2020
Atom Gigabit ZFS encryption
View atom_zfs.md

Write:

tank% bash -x /data/media/fio-test /data/media/local-test
+ fio --filename=/data/media/local-test --name=write --ioengine=posixaio --rw=write --bs=128k --size=16GB --numjobs=1 --iodepth=128 --runtime=60 --time_based --group_reporting --eta-newline=1
write: (g=0): rw=write, bs=(R) 128KiB-128KiB, (W) 128KiB-128KiB, (T) 128KiB-128KiB, ioengine=posixaio, iodepth=128
fio-3.12
Starting 1 process
write: Laying out IO file (1 file / 16384MiB)
Jobs: 1 (f=1): [W(1)][6.6%][w=368MiB/s][w=2941 IOPS][eta 00m:57s]
View setup_server
#! /bin/bash
#
# Initial setup of a server. Run this as root.
apt -qq -y install curl git sudo rsync
set -eu
install -o0 -g0 -m0700 -d /root/.ssh
tmpfile="$(mktemp)"
@jeffmccune
jeffmccune / avoid_ remove_old_addr.sh
Last active Sep 16, 2020
Work around dhclient -x breaking policy routing when google-guest-agent starts
View avoid_ remove_old_addr.sh
#!/bin/bash
#
# See https://github.com/GoogleCloudPlatform/guest-agent/issues/76
tmpfile="$(mktemp)"
cat <<"EOF" >"$tmpfile"
logmessage "Skipping ip -4 addr del ${old_ip_address:-}/${old_prefix:-} dev ${interface:-} to work around https://github.com/GoogleCloudPlatform/guest-agent/issues/76"
exit_with_hooks 0
EOF
install -o 0 -g 0 -m 0755 "$tmpfile" /etc/dhcp/dhclient-down-hooks
rm -f "$tmpfile"
@jeffmccune
jeffmccune / stub_ip.sh
Created Sep 16, 2020
Stub IP to troubleshoot dhclient
View stub_ip.sh
#! /bin/bash
if ! [[ -f /jeff/ip ]]; then
mkdir /jeff
mv /sbin/ip /jeff/ip
fi
cat <<"EOF" > /sbin/ip
#! /bin/bash
#
read -a st < /proc/$$/stat
read -a ppid < /proc/${st[3]}/stat