Skip to content

Instantly share code, notes, and snippets.

View jamesmcdonald's full-sized avatar

James McDonald jamesmcdonald

View GitHub Profile
- name: my play that does stuff
hosts: all
vars_prompt:
username: "enter a username"
or
vars_prompt:
- username: "enter a username"
default: someone
@jamesmcdonald
jamesmcdonald / ynabimport.pl
Last active August 22, 2016 07:55
Convert Skandiabanken export data to something YNAB will import
#!/usr/bin/perl -w
# ynabimport.pl
# James McDonald <james@jamesmcdonald.com>
# Cook data from skandiabanken for import into YNAB. Entirely based on
# guesswork and reverse-engineering from failures, so ymmv.
# To use this, follow these steps:
#!/bin/bash
# post-receive hook to trigger r10k over ssh on updates to puppet control repo
# Set SSHTARGET in ~/.config/puppet-update to eg:
# root@puppet.example.com
# The ssh target should have an authorized_key with eg:
# command="/usr/local/sbin/puppet-update.sh"
# That script need simply call:
# /path/to/r10k deploy environment $SSH_ORIGINAL_COMMAND
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
/* 101 bytes - the 102nd is the \n */
#define BYTES "This line of text has been engineered by " \
"only the very finest, wisest squirrels to contain 102 bytes."
void usage(char *progname)
{
// Overcomplicated "healthy" metric generator
package main
import (
"fmt"
"math/rand"
"net/http"
"os"
"strconv"
"time"
#!/usr/bin/env python
"""
Wrap i3status to add things to your i3bar
You need to have dbus-python installed.
Right now this will prepend
* Spotify status that looks like "Artist > Song".
The > will be replaced with an _ if Spotify is paused.

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@jamesmcdonald
jamesmcdonald / jsonlog.py
Last active March 22, 2019 10:58
Format json logs as plain text
#!/usr/bin/env python3
"""Read a stream of one-per-line json events and print them in a more human-readable format"""
import json
import sys
import string
import argparse
class SkipFormatter(string.Formatter):
"""A string.Formatter that returns '-' for missing fields"""
@jamesmcdonald
jamesmcdonald / 98-monitorswitch.rules
Last active March 26, 2019 07:32
Monitor plug autodetection for i3
# This should go in /etc/udev/rules.d
KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/monitorswitch.sh"
function kn() {
local context=$1
shift
local namespace=$1
shift
if [[ -z "$context" ]]; then
echo "usage: kn <context> [namespace]" >&2
return 1
fi
if ! kubectl config get-contexts $context >/dev/null 2>&1; then