Skip to content

Instantly share code, notes, and snippets.

🐉

Bo Jeanes bjeanes

🐉
Block or report user

Report or block bjeanes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View command.rb
require 'command/result'
require 'command/result/switch'
module Command
def self.included(klass)
klass.extend Command::ClassMethods
end
module ClassMethods
def call(**options, &block)
@bjeanes
bjeanes / uuid64.rb
Last active Dec 19, 2016
Compact URL-safe UUID representation. It might almost be worth having a base66 version (there are 66 url-safe chars)
View uuid64.rb
require 'securerandom'
require 'base64'
module UUID64
extend self
def generate
encode SecureRandom.uuid
end
View README.md
$ ruby generate_cloudfront_ip_regex.rb
/(?-mix:13\.3[2-3]\.[0-9]{1,3}\.[0-9]{1,3})|(?-mix:52\.46\.([0-5]{0,1}[0-9]|6[0-3])\.[0-9]{1,3})|(?-mix:52\.8[4-5]\.[0-9]{1,3}\.[0-9]{1,3})|(?-mix:52\.222\.(12[8-9]|1[3-9][0-9]|2[0-5][0-9])\.[0-9]{1,3})|(?-mix:54\.182\.[0-9]{1,3}\.[0-9]{1,3})|(?-mix:54\.192\.[0-9]{1,3}\.[0-9]{1,3})|(?-mix:54\.230\.[0-9]{1,3}\.[0-9]{1,3})|(?-mix:54\.239\.(12[8-9]|1[3-8][0-9]|19[0-1])\.[0-9]{1,3})|(?-mix:54\.239\.(19[2-9]|2[0-1][0-9]|22[0-3])\.[0-9]{1,3})|(?-mix:54\.240\.(12[8-9]|1[3-8][0-9]|19[0-1])\.[0-9]{1,3})|(?-mix:204\.246\.16[4-7]\.[0-9]{1,3})|(?-mix:204\.246\.(16[8-9]|17[0-1])\.[0-9]{1,3})|(?-mix:204\.246\.17[4-5]\.[0-9]{1,3})|(?-mix:204\.246\.(17[6-9]|18[0-9]|19[0-1])\.[0-9]{1,3})|(?-mix:205\.251\.(19[2-9]|2[0-1][0-9]|22[0-3])\.[0-9]{1,3})|(?-mix:205\.251\.249\.[0-9]{1,3})|(?-mix:205\.251\.25[0-1]\.[0-9]{1,3})|(?-mix:205\.251\.25[2-3]\.[0-9]{1,3})|(?-mix:205\.251\.254\.[0-9]{1,3})|(?-mix:216\.137\.(3[2-9]|[4-5][0-9]|6[0-3])\.[0-9]{1,3})/
View cloudfront_ips.rb
require 'ipaddr'
require 'json'
require 'net/https'
require 'uri'
module CloudfrontIPs
IP_LIST = URI.parse('https://ip-ranges.amazonaws.com/ip-ranges.json')
class << self
# For Rails 4, when we have it, this is sufficient for their whitelisting.
@bjeanes
bjeanes / anon.rb
Created Aug 3, 2016
Low effort anonymisation script a `rails-erd` generated `.dot` file (which I used to submit a Graphviz bug report)
View anon.rb
dot = ARGF.read
matches = Hash.new { |h, k| h[k] = "Anonymized_#{rand 9999}" }
replaced1 = dot.gsub(/\b"?m_([A-Za-z0-9_:]+)"?\b/) { |m| m.sub(%r|\b#{$1}\b|, matches[$1]) }
regexp = Regexp.union(matches.keys.map { |k| Regexp.new(k) })
replaced2 = replaced1.gsub(regexp) { |m| matches[m] }
puts replaced2
View anon.dot
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 Jun 13, 2016
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.
View db-subset.rb
#!/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
QUery to find all `varchar` columns in the database and return query strings that can be run to change them to `text` types Raw
View generate_text_alters.sql
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
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)
View docker-buildkite-ubuntu-14.04.sh
#!/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
Attempt to add a Heroku labs feature to specified app(s) until
View labs-enable.sh
#!/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() {
You can’t perform that action at this time.