Skip to content

Instantly share code, notes, and snippets.

View blalor's full-sized avatar

Brian Lalor blalor

View GitHub Profile
@blalor
blalor / init.lua
Created December 6, 2021 13:53
Hammerspoon config for auto-typing passwords from the macOS Keychain
function password_from_keychain(service)
-- 'service' should be saved in the login keychain
local cmd = "/usr/bin/security 2>&1 >/dev/null find-generic-password -gs '" .. service .. "' | sed -En '/^password: / s,^password: \"(.*)\"$,\\1,p'"
local handle = io.popen(cmd)
local result = handle:read("*a")
handle:close()
return (result:gsub("^%s*(.-)%s*$", "%1"))
end
@blalor
blalor / README.md
Last active May 9, 2023 10:42
Tailscale Docker container as Nomad sidecar

This is possibly slightly incomplete as I stripped out an existing jobspec to share, but the meat is really in the run.sh template of the tailscale task. You'll need a reusable and ephemeral auth key.

@blalor
blalor / brewviz.sh
Created July 27, 2016 10:39
homebrew dependency tree with graphviz
#!/bin/bash
set -e -u -o pipefail
{
echo 'digraph G {'
brew list | while read cask; do
printf '"%s";\n' $cask
brew deps $cask | while read dep; do
@blalor
blalor / nomad-drain-and-wait.py
Last active September 27, 2020 17:54
systemd ExecStop script for Nomad
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
## in order to cleanly shut down a node with running jobs, the node needs to be
## drained, and then we need to wait for allocations to be migrated away. in
## this script, we:
## * set up a watch for node-update evals for the current node
## * wait for allocations currently running to complete
## * wait for allocations from the watched evals to start running
##
@blalor
blalor / gist:c325d500818361e28daf
Created May 2, 2014 04:37
redhat init script for consul
#!/bin/bash
#
# consul Manage the consul agent
#
# chkconfig: 2345 95 95
# description: Consul is a tool for service discovery and configuration
# processname: consul
# config: /etc/consul.conf
# pidfile: /var/run/consul.pid
@blalor
blalor / README.md
Last active January 7, 2020 15:21
download HashiCorp products (macOS)

dl.sh

Shell script for downloading HashiCorp binaries.

Requires jq (brew install jq) and gpg (brew cask install gpg-suite).

example

I structure all my binaries as ~/devel/HashiCorp/binaries/<product>-<version>/<product> and adjust paths as needed based on the project I'm working on.

@blalor
blalor / README.md
Last active January 7, 2020 15:14
Convert YAML to JSON

yaml2json

Quick and dirty CLI tool for converting yaml to json.

example

[:~] 1 $ yaml2json <( echo -e '---\nfoo:\n- bar\n- baz' )
{
 "foo": [
@blalor
blalor / README.md
Last active January 7, 2020 15:01
Diff for JSON data

jsondiff

Requires datadiff.

Also useful with yaml2json.

example

[:~] $ jsondiff &lt;( echo '{"foo":"bar"}' ) &lt;( echo '{"foo":"bar", "baz":"bap"}' )
@blalor
blalor / go_clone
Last active October 31, 2018 19:01
clones a Go project into a new directory and sets up the workspace with direnv
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
## clones a Go project into a new directory and sets up the workspace with direnv.
##
## example:
## $ go_clone git@github.com:hashicorp/nomad.git nomad
##
## * creates the "nomad" directory
## * creates a .envrc with "layout go" in it
@blalor
blalor / consul_handler.rb
Created July 2, 2015 14:03
Chef report handler for Consul
## chef report handler for Consul
## depends on a chef-client check being registered with the agent
## • pings TTL-style check with ok/warning status on chef run pass/fail
## • stores run report and node attributes in chef/reports/<datacenter>/<consul_node_name>
require "chef/handler"
require "rest_client"
class ConsulHandler < Chef::Handler
attr_reader :config