Skip to content

Instantly share code, notes, and snippets.

digraph Regroup {
rankdir = "LR";
ranksep = "0.5";
nodesep = "0.4";
pad = "0.4,0.4";
margin = "0,0";
concentrate = "true";
labelloc = "t";
fontsize = "13";
fontname = "Arial BoldMT";
@bjeanes
bjeanes / db-subset.rb
Created June 13, 2016 12:27
Incomplete script to generate schema hints for 18F's rdbms-subsetter tool. However, when running their tool, I kept getting Python exceptions that implied the dependent libraries couldn't deal with constraints in our DB schema, so I tabled it for now.
#!/usr/bin/env ruby
###############################################################################
#
# Uses https://github.com/18F/rdbms-subsetter to pull a subset of data from the
# production database. Because Rails databases rarely define foreign keys, this
# inspects the models for in-Ruby declared associations and generates a config
# file for `rdbms-subsetter` to use for understanding the schema.
#
###############################################################################
@bjeanes
bjeanes / generate_text_alters.sql
Last active May 31, 2016 04:26
QUery to find all `varchar` columns in the database and return query strings that can be run to change them to `text` types Raw
WITH targets AS (
SELECT 'ALTER TABLE "'||table_name||'"' as "table",
string_agg(
'ALTER COLUMN "'||column_name||'" TYPE text'||CASE
WHEN character_maximum_length IS NULL THEN ''
WHEN character_maximum_length >= 255 THEN ''
ELSE
E',\n ADD CONSTRAINT '||column_name||E'_length \n '||
'CHECK (LENGTH("'||column_name||'") <= '||character_maximum_length||') '||
'NOT VALID'
@bjeanes
bjeanes / docker-buildkite-ubuntu-14.04.sh
Last active May 30, 2016 06:08
Little script for me to pipe over SSH to a fresh Ubuntu VPS/VM to get it running a docker agent (used with cloudatcost.com as cheap build boxes)
#!/usr/bin/env bash
if [ -z "$BUILDKITE_AGENT_TOKEN" ]; then
echo
>&2 echo "No buildkite agent token set! Set BUILDKITE_AGENT_TOKEN"
exit 1
fi
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
@bjeanes
bjeanes / labs-enable.sh
Last active May 23, 2016 15:36
Attempt to add a Heroku labs feature to specified app(s) until
#!/usr/bin/env bash
### Attempt to add a Heroku labs feature to specified app(s) until success
# Originally created for limited availability `http-sni` to try to get in as allocation opened up.
# Call with ./labs-enable.sh <lab-feature> <app1> [<app2> ...]
feature=$1
enable_apps() {
@bjeanes
bjeanes / email.sql
Created April 7, 2016 01:44
Email domain type for postgres
CREATE EXTENSION IF NOT EXISTS citext;
-- http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
CREATE DOMAIN email AS citext
CHECK (
VALUE IS NULL OR (
-- is not more than 254 chars
length(VALUE) <= 254 AND
-- vaguely looks like an email address
@bjeanes
bjeanes / Čorli.md
Last active January 24, 2016 11:44

Čoli / Čorli / Chorli

A (Croatian?) card game played with two decks of regular playing cards, including Jokers.

Rules of the Game

Overview

The goal of the game is to reach a chosen number of points, usually 500 or 1000.

@bjeanes
bjeanes / nzbget-quota-checker.sh
Created March 19, 2015 08:33
A scheduler script for NZBGet which pauses the queue if using too much of my allocated monthly quota from Internode. E.g. if 30% through the month but used more than 30% of quota, pause, otherwise unpause.
#!/usr/bin/env sh
##############################################################################
### NZBGET SCHEDULER SCRIPT ###
# Pause queue when using too much of Internode monthly quota.
#
# It will also unpause the queue once we're behind expected usage.
#
# Note: this script requires the `xmllint` binary (e.g.: from xmllib2-utils)
require "lifx" # http://rubydoc.info/github/lifx/lifx-gem/master/frames
def calculate_color(i) # 0 <= i <= 1
h = [40 * 2 * i, 40].min # will be 40 (yellow) at i=1/2 and stay there
s = 1.0 - [(i - 0.5) * 2, 0].max # will be 1 until i=1/2 and then go down to 0
b = i
LIFX::Color.hsbk(h, s, b, LIFX::Color::KELVIN_MIN)
end
duration = 30 * 60 # seconds
@bjeanes
bjeanes / gist:ac0b0a7c6a1b51ef97fe
Created July 24, 2014 03:23
Webpass traceroute
$ traceroute github.com
traceroute to github.com (192.30.252.128), 64 hops max, 52 byte packets
1 router (192.168.11.1) 1.299 ms 1.090 ms 0.960 ms
2 10.0.4.17 (10.0.4.17) 1.835 ms 1.791 ms 1.850 ms
3 10.0.3.177 (10.0.3.177) 1.927 ms 1.764 ms 1.787 ms
4 10.0.23.241 (10.0.23.241) 2.130 ms 2.037 ms 2.232 ms
5 10.0.23.164 (10.0.23.164) 2.572 ms 2.461 ms 3.836 ms
6 * * *
7 * * *
8 * * *