Skip to content

Instantly share code, notes, and snippets.

View aks's full-sized avatar
💭
Working

Alan Stebbens aks

💭
Working
View GitHub Profile
#!/bin/bash
#
# add ssh keys
PROG=${0##*/}
KEY_DIR=~/.ssh
PUB_SFX='.pub'
# on non-MacOS systems, comment this line out
@aks
aks / git-copy
Created June 29, 2021 04:00
Bash script to copy a file in a git repo with history preservation
#!/usr/bin/env bash
# git-copy [options] SOURCEFILE NEWFILE
usage() {
cat 1>&2 <<USAGE
usage: git-copy [options] SOURCEFILE NEWFILE
Copies a SOURCEFILE within a git repo to a NEWFILE in a way
that preserves the change history so that changes in SOURCEFILE
are still viewable in NEWFILE.
@aks
aks / there-can-be-only-one.rb
Created November 12, 2020 02:53
Little ruby test script to make sure that Redis SET NAME VALUE NX:TRUE locking really works
#!/usr/bin/env ruby
#
require 'redis'
require 'securerandom'
require 'awesome_print'
class RedisTest
attr_reader :name, :redis
HOW_MANY = (1..5)
@aks
aks / .git-aliases.sh
Created October 16, 2020 15:26
Bash script to define useful functions and aliases for easier git operations
# Git helpers
alias gadd='git add'
alias gci='git commit'
alias gco='git checkout'
alias gdiff='git diff'
alias gpull='git pull'
alias gpush='git push'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
@aks
aks / fast-table-size-query.sql
Created April 21, 2020 15:59
Fast query for table size
-- query a large table for its size without doing a full-table scan
-- replace the table name as needed
SELECT to_char(reltuples::bigint,'999,999,999,999') AS estimate
FROM pg_class
WHERE relname='BIG_TABLE';
@aks
aks / pgctl
Created April 6, 2020 17:59
Bash script for running multiple versions of `pg_ctl`, using `asdf` to manage the postgres versions
#!/usr/bin/env bash
PROG="${0##*/}"
DIR="${0%/*}"
current_pg_version() {
asdf current postgres | cut -d' ' -f1
}
DEFAULT_PG_VERSION=`current_pg_version`
@aks
aks / default_cert_file.sh
Created April 4, 2020 23:22
Default CERT file
ruby -ropenssl -e "p OpenSSL::X509::DEFAULT_CERT_FILE"
@aks
aks / freeze_time.rb
Created March 12, 2020 17:11
Rspec shared_context to freeze time
FREEZE_DATETIME = '2020/02/20 10:20:30 GMT'
shared_context 'freeze_time' do
around do |example|
Timecop.freeze(FREEZE_DATETIME)
example.run
Timecop.return
end
end
@aks
aks / wait.rb
Created March 12, 2020 17:02
Ruby Wait class for waiting for things to happen or not happen
# frozen_string_literal: true
#
# Wait.until { expr } -- waits until expr is true
# Wait.while { expr } -- waits while expr is true
#
# Each iteration contains a `sleep(sleep_time)`, where the default sleep time is
# Wait::DEFAULT_SLEEP_TIME (0.1 seconds).
#
# The sleep interval can be specified with the `sleep_time` argument:
#
@aks
aks / merge-branches
Last active November 6, 2019 16:02
Bash script to merge a set of branch names into a target branch
#!/usr/bin/env bash
# merge-branches [options] -f BRANCHES_FILE TARGET_BRANCH
PROG="${0##*/}"
DIR="${0%/*}"
GCLOG='.git/gc.log'
usage() {
if (( $# > 0 )) ; then