Skip to content

Instantly share code, notes, and snippets.

@cagerton
cagerton / diff.ts
Created Sep 24, 2020
Git based diff utility for NodeJS
View diff.ts
import {join} from 'path';
import fs from "fs";
import os from "os";
import {spawnSync} from "child_process";
/**
* Use the local `git` executable to render a diff between two strings.
* This is intended for test/development environments. Consider using
* `jsdiff` if you need to compare potentially malicious strings.
*/
@cagerton
cagerton / README.md
Created Jun 10, 2020
Test Certificate Generator
View README.md

TinyCA

This is handy for genrating transient keys and certificates used for unit tests.

Notable files generated by running tinyca.sh:

  • ca.pem - This is the root CA which should be added to the test client's trust store.
  • server.key - This is your server's secret key.
  • server.pem - This is your server's certificate, good for example.com and *.example.com.
  • expired.pem - This is an expired version of the server certificate.
  • ca - This directory contains the ca secrets and internals.
@cagerton
cagerton / yolo_redis.ts
Created Jan 27, 2020
Redis cluster demo example
View yolo_redis.ts
import {spawn} from 'child_process';
import fs from 'fs';
import os from 'os';
function mkConfigs(port: number) {
return `
bind 127.0.0.1
port ${port}
cluster-enabled yes
cluster-config-file nodes-${port}.conf
@cagerton
cagerton / colorfade.py
Created May 15, 2019
Simple example for using udmx to control a monoprice rgbaw-uv dmx light
View colorfade.py
"""
Simple rgb color fade tested with the monoprice rgbawuv
Requires python3.7 for the async coroutine syntax; should be trivial to backport though
Requires:
libusb==1.0.22b4
numpy==1.16.3
pyusb==1.0.2
scikit-image==0.15.0
@cagerton
cagerton / no_push_f_master.rb
Last active Jan 11, 2020
pre receive hook
View no_push_f_master.rb
#!/usr/bin/env ruby
# pre-receive hook to block 'push -f' on master
# For Phabricator, save this as:
# $REPO/hooks/pre-receive-phabricator.d/no_push_f_master.rb
# Remember to chmod +x
# Ref: http://git-scm.com/book/en/Customizing-Git-An-Example-Git-Enforced-Policy
args = STDIN.readline.chomp.split(" ")
$oldrev, $newrev, $refspec = args
@cagerton
cagerton / mail.py
Created Aug 6, 2014
this saves 3 months of vpn setup
View mail.py
from flask import Flask, redirect, render_template, url_for, request
from flask_bootstrap import Bootstrap
import redis
import json
app = Flask(__name__)
Bootstrap(app)
r = redis.Redis()
@cagerton
cagerton / fetch_hostkey.py
Last active Aug 29, 2015
Simple script to fetch an ssh host key.
View fetch_hostkey.py
#!/usr/bin/env python2.7
"""Usage: fetch_hostkey.py <host> [<port>]"""
import paramiko, docopt
opt = docopt.docopt(__doc__)
host = opt['<host>']
port = int(opt['<port>'] or 22)
t = paramiko.Transport((host, port))
t.connect()
@cagerton
cagerton / hijack_touch.js
Created Dec 13, 2013
Generate click events on touchstart; kill the mouse events that the browser cooks 200+ms afterwards.
View hijack_touch.js
(function touchJack(){
var lastTouch = 0;
document.addEventListener("touchstart", function(e){
lastTouch = Date.now();
var touch = e.touches[0],
synth_event = document.createEvent("MouseEvents");
synth_event.fab=true;
synth_event.initMouseEvent("click", true, true, window,
0, touch.screenX, touch.screenY, touch.clientX, touch.clientY,
View packages.sls
#!yaml
#
# Postgres 9.3 packages salt state
#
# Created 9/9/13
#
# author: Micah Hausler, micah.hausler@akimbo.io
postgres-pkgs:
pkg:
@cagerton
cagerton / 0.check_keys.py_example.md
Last active Dec 25, 2015
Little python3.3 script to show information about ssh public keys from key files or known_hosts files.
View 0.check_keys.py_example.md

SSH key info for pubkeys, known_hosts, and github users

Usage:
  check_keys.py hosts [<FILE>]
  check_keys.py key [<FILE>...]
  check_keys.py github <user>


$ check_hosts.py github cagerton
[