Skip to content

Instantly share code, notes, and snippets.

Ethan Erchinger erchn

Block or report user

Report or block erchn

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
@erchn
erchn / ipv4 regex.txt
Last active Feb 5, 2019
Match Cloudflare IPs with regex
View ipv4 regex.txt
# https://www.cloudflare.com/ips/
# this is not meant to catch malformed IPs
/(103\.21\.24[4567]\.[0-9]+ # 103.21.244.0/22
|103\.22\.20[0123]\.[0-9]+ # 103.22.200.0/22
|103\.31\.[4567]\.[0-9]+ # 103.31.4.0/22
|104\.(1[6789]|2[0-9]|3[01])\.[0-9]+ # 104.16.0.0/12
|108\.162\.(19[2-9]|2[0-9]+)\.[0-9]+ # 108.162.192.0/18
|131\.0\.7[2345]\.[0-9]+ # 131.0.72.0/22
|141\.101\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]+ # 141.101.64.0/18
@erchn
erchn / fizzbuzz.sql
Last active Oct 15, 2018
Athena FizzBuzz
View fizzbuzz.sql
SELECT val,
CASE
WHEN by5+by3 = 0 THEN 'FizzBuzz'
WHEN by5 = 0 THEN 'Fizz'
WHEN by3 = 0 THEN 'Buzz'
ELSE cast(val AS varchar)
END AS fizzbuzz_test
FROM
(SELECT val,
mod(val, 5) AS by5,
@erchn
erchn / _etc_profile.d_rbenv.sh
Created Feb 1, 2017
Running rbenv in production using RPMs (tested on centos 6)
View _etc_profile.d_rbenv.sh
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1:${PATH:+"$PATH:"}"
fi
}
# rbenv setup
export RBENV_ROOT=/opt/rbenv
pathadd /opt/rbenv/bin
@erchn
erchn / retry.sh
Created Sep 26, 2016
retry running things with a few arguments, goes well with the Cronitor wrapper.
View retry.sh
#!/bin/bash
num=5
retrycode=99
sleep=300
usage() {
cat <<EOF
$0 [-r retry_exit_code] [-s sleep_secs] [-n times_to_loop]
@erchn
erchn / 01_rails.rb
Last active Aug 29, 2015
Redefinition of Rails.env to support a hierarchy of environments, tested on 3.2.17
View 01_rails.rb
# Override Rails.env so we can have a env method that support this environment plus or minus other environments as true
# This initializer file is named 01_rails so it executes before any others
module Rails
# Mini-helper class which subclasses String, duplicating the base of ActiveSupport::StringInquirer
# Adds support for comparing hierarchy of environments, the method_name vs. current Rails.env
#
# Rails.env # => "development"
# Rails.env.development? # => true
@erchn
erchn / cronitor.sh
Last active Oct 10, 2019
Cronitor wrapper script for start/stop notifications, shamelessly stolen from the now defunct Proby
View cronitor.sh
#!/bin/bash
#
# This script surrounds the command passed in with start and finish notifications
# to the cronitor monitoring application.
#
# === SETUP
#
# * Make sure the cronitor script is executable.
#
# chmod +x cronitor
@erchn
erchn / consumer.sls
Created May 6, 2014
Sharing state information
View consumer.sls
# Get logs from other states
{% set mylogs = [] %}
{% for myfile in salt['cp.list_master']() %}
{% if myfile.split('/')[-1] == "log.incl" %}
{% include myfile %}
{% endif %}
{% endfor %}
# {{ mylogs }}
@erchn
erchn / myenv.py
Created Jan 23, 2014
Custom grain based on hostname
View myenv.py
# _grains/myenv.py
import sys
import socket
import re
import platform
# Extend the default list of supported distros. This will be used for the
# /etc/DISTRO-release checking that is part of platform.linux_distribution()
from platform import _supported_dists
@erchn
erchn / top.sls.yaml
Created Nov 24, 2013
auto-assign states to a minion based on cluster name if they exist on the master. The concept shamelessly copied from another community member.
View top.sls.yaml
{# ######################################################################################### #}
{# ######################################################################################### #}
{# this block of code auto applies salt states to a given minion if they exist on the master #}
{% set id = grains['id'] %}
{# web01 host id = 'web' cluster id, allow a custom grain or pillar named 'cluster' to override #}
{% set cluster = salt['config.get']('cluster', id.split('.')[0].rstrip('0123456789')) %}
{# all available states on the master #}
{% set states = salt['cp.list_master']() %}
View salt-script-runner.sls
trigger script when updated:
file.managed:
- name: /usr/local/bin/script.sh
- source: salt://script.sh
- mode: 700
cmd.wait:
- name: /usr/local/bin/script.sh
- cwd: /tmp
- watch:
You can’t perform that action at this time.