Skip to content

Instantly share code, notes, and snippets.

# Working with low-level git primitives is done through these client method groupings:
# https://octokit.github.io/octokit.rb/Octokit/Client/Objects.html
# https://octokit.github.io/octokit.rb/Octokit/Client/Commits.html
# https://octokit.github.io/octokit.rb/Octokit/Client/Refs.html
#
# The 'contents' endpoints provide a slightly higher-level interface that may be appropriate
# for some things.
# https://octokit.github.io/octokit.rb/Octokit/Client/Contents.html
def push_github_edit
@davehughes
davehughes / spine.redshift.sql
Last active February 12, 2023 19:46
Date spines
WITH
-- create initial data
seq0 AS (
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
#!/bin/bash
MINION_NAME=${minion_name}
MASTER_HOST=${master_host}
# -----------------------------------------------------------------------------
# Set hostname matching minion name by updating /etc/hostname and /etc/hosts
# -----------------------------------------------------------------------------
hostnamectl set-hostname $MINION_NAME
@davehughes
davehughes / plots.py
Created August 31, 2018 19:16
Basic matplotlib plotting
import math
import numpy as np
import matplotlib.pyplot as plt
# Points
def plot_points(subplot, points, fx=lambda x: x):
xs = points
ys = map(fx, xs)
@davehughes
davehughes / apply-f.zion
Last active July 16, 2018 13:44
Zion generic function application example
module _
fn square(x any T) any T {
return x * x
}
fn apply(f (fn(y any T) any T), x any T) any T {
return f(x)
}
@davehughes
davehughes / flatten.py
Created July 12, 2017 21:11
Flatten simple Python objects to a list of K-V pairs
'''
Flattens a 'JSON' object (really, a simple potentially nested object
composed of dicts, lists, and scalars) into a list of key-value pairs.
Example usage (from http://json.org/example.html):
> import json
> flatten_json(json.loads(SAMPLE_JSON))
[(u'glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso.0', u'GML'),
@davehughes
davehughes / README.md
Last active March 29, 2017 17:25
Sketch of basic metric rollup table and queries

This is a description of a scheme I've used a few times for representing time series data on a fairly small scale. In a nutshell, it uses a single table to house multiple data series on multiple scales and is designed to make it easy to display those series.

Sample Data:

series timescale timestamp value
active-users weekly 2016-03-05 487
active-users daily 2016-03-05 75
active-users daily 2016-03-06 43
@davehughes
davehughes / tor_hs_keygen.py
Created October 28, 2016 23:18
Simple example of generating private_key/hostname for tor hidden services.
'''
Based on https://gist.github.com/DonnchaC/d6428881f451097f329e, including
a very helpful comment attached to that gist.
'''
import base64
import hashlib
import os
from Crypto.PublicKey import RSA
@davehughes
davehughes / lets-encrypt-nginx.sls
Created October 1, 2016 23:42
Salt state for setting up Let's Encrypt with Nginx
nginx:
pkg.installed: []
service.running:
- reload: true
# SSL setup via letsencrypt, based on the following article:
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
letsencrypt:
pkg.installed: []
@davehughes
davehughes / README.md
Last active February 18, 2019 05:44
CLI helper for multifactor authentication

What's the point?

Stop fumbling for your phone every time you need to log in to a site with multi-factor authentication. Just run mfa token <profile> | pbcopy and paste the verification code.

(You do need to be able to grab the TOTP key for the site you're logging into, which is usually available somewhere near the QR code when setting up MFA).

Setup:

  • Install oathtool for your platform.