Skip to content

Instantly share code, notes, and snippets.

View aks's full-sized avatar
💭
Working

Alan Stebbens aks

💭
Working
View GitHub Profile
@aks
aks / query_new_columns_for_diffs.sql
Last active April 3, 2018 18:00
SQL query to scan new ID columns for different values than the corresponding originals
-- this query will probe all tables for any ID columns prefixed with "new_" that are different
-- than the corresponding original columns.
-- it reports the tables containing such columns as they are being checked
DO $$
DECLARE
temp record;
stmt varchar;
recs integer;
BEGIN
FOR temp IN
@aks
aks / run-migrations-singly
Last active March 15, 2018 15:03
Bash script to run rails migrations singly interactively
#!/usr/bin/env bash
# run-migrations-singly
PROG=${0##*/}
DIR=${0%/*}
export PATH=$PATH:$HOME/bin:$HOME/lib
# see github.com/aks/bash-lib
source talk-utils.sh
source run-utils.sh
@aks
aks / squash-all
Last active November 7, 2019 18:43
Bash script to squash all commits in the current branch (against master)
#!/usr/bin/env bash
# squash-all [BASE_BRANCH]
PROG="${0##*/}"
DIR="${0%/*}"
talk() { echo 1>&2 "$*" ; }
vtalk() { (( verbose )) && talk "$*" ; }
error() { talk "$*" ; exit 1 ; }
@aks
aks / start-sidekiq
Created March 8, 2018 21:59
Bash scripts to make it easy to start, stop, and watch sidekiq server
#!/bin/bash
PROG="${0##*/}"
def_config="-C config/sidekiq.yml"
def_log="-L log/sidekiq.log"
def_pid="-P tmp/pids/sidekiq.pid"
def_queue="-q data_migration"
usage() {
cat <<MSG
@aks
aks / collect-bucket-info.sh
Last active February 28, 2018 19:38
Bash script to collect bucket names and associated encryption info, and produce diff reports.
#!/usr/bin/env bash
# collect-bucket-info
PROG="${0##*/}"
DIR="${0%/*}"
usage() {
cat 1>&2 <<EOF
usage: $PROG [options]
This script collects bucket names and encryption configuration for each bucket, and produces
a report of the differences against the previous run. If -m ADDR is given, the report is
@aks
aks / thor-template.rb
Created February 23, 2018 22:03
A template for a new ruby thor-based command-line utility
#!/usr/bin/env ruby
#
# THOR template
$PROG = File.basename($PROGRAM_NAME)
$DIR = File.dirname($PROGRAM_NAME)
# Possibly modify the LOAD_PATH
# $LOAD_PATH << File.join(__dir__, '..', 'lib/migrations')
@aks
aks / README-migration-apis.md
Created February 23, 2018 21:54
ActiveRecord Migration actions (methods)

ActiveRecord::Migration API Notes

The ActiveRecord::Migration class is used to manage Rails migration scripts. When writing these scripts, there are many class methods that can be used to make schema changes, which are described below in several sections.

Migration Methods

Create Methods Arguments Notes Rev
create_join_table table1, table2, options Creates a join table Y
create_table name, options Creates a table Y
@aks
aks / permanently-remove-files-from-repo.sh
Created February 23, 2018 18:27
Permanently remove files from a repo
#!/bin/bash
# wanted to remove "doc" directory and all of it's contents
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch -r -f doc'
@aks
aks / bash-cli-template.sh
Created February 21, 2018 23:22
A template for bash command-line utility
#!/usr/bin/env bash
# my-script some-args
# set the name and directory of this program
PROG="${0##*/}"
DIR="${0%/*}"
# include ~/bin and ~/lib to get my bash scripts
export PATH=$PATH:$HOME/bin:$HOME/lib
@aks
aks / postgres_queries_and_commands.sql
Last active April 23, 2018 16:01 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
-- SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
-- FROM pg_stat_activity
-- WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
-- ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'