Skip to content

Instantly share code, notes, and snippets.

View jsugarman's full-sized avatar

Joel Sugarman jsugarman

  • Digital Services
  • London
View GitHub Profile
@jsugarman
jsugarman / hash_extension.rb
Created March 1, 2018 12:46
Hash extensions
module HashExtension
def all_keys
each_with_object([]) do |(k, v), keys|
keys << k
keys.concat(v.select { |el| el.is_a?(Hash) }.flat_map(&:all_keys)) if v.is_a? Array
keys.concat(v.all_keys) if v.is_a? Hash
end
end
def all_values_for(key)
@jsugarman
jsugarman / cccd_db_upgrade.sh
Last active October 17, 2018 23:32
database upgrade bash script for CCCD
#!/bin/bash
# *********************************************************** #
# Ideal path to minimise downtime is:
# - [recommended] perform `VACUUM (VERBOSE, ANALYZE);` on db
# * to improve speed of db generally
# - [recommended] create manual snapshot
# * to improve speed of upgrade process's automated snapshots
# - put site in maintenance mode
# - perform VACUUM; of postgres DB (this can be done before too but may place heavy load on db)
@jsugarman
jsugarman / postgres_local_upgrade.md
Last active October 19, 2018 11:51
Guide on upgrading local postgres database

Postgresql Mac OSX upgrade

Figure out what verion of postgres your homebrew data directory currently has:

$ cat /usr/local/var/postgres/PG_VERSION
9.6
@jsugarman
jsugarman / fix_dump_file.sh
Created October 19, 2018 11:47
fix cccd dump file
# find and replace search path in ADP dump file
gunzip -3 -f adp_gamma_dump.psql.gz
fgrep 'search_path' adp_gamma_dump.psql -m1
sed -i -e "s/SELECT pg_catalog.set_config('search_path', '', false)/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true)/" adp_gamma_dump.psql
fgrep 'search_path' adp_gamma_dump.psql -m1
gzip adp_gamma_dump.psql
@jsugarman
jsugarman / patience_helper.rb
Last active April 5, 2019 21:24
Wait for ajax, javascript or page loading around any expectation in a cucumber step definition
# helper to capture certain errors and expectation failures
# and retry until timeout reached.
# Idea taken from:
# https://github.com/makandra/spreewald
#
module PatienceHelper
RETRY_ERRORS = %w[
Capybara::ElementNotFound
Spec::Expectations::ExpectationNotMetError
RSpec::Expectations::ExpectationNotMetError
read AWS_ACCESS_KEY_ID ARN URL AWS_SECRET_ACCESS_KEY <<<$(kubectl --context <context> -n <namespace> get secret <secret> -o json | jq -r '.data[] | @base64d'); printf "$AWS_ACCESS_KEY_ID\n$ARN\n$URL\n$AWS_SECRET_ACCESS_KEY"
@jsugarman
jsugarman / laa-fee-calculator-pyenv-setup.md
Last active July 18, 2020 13:16
laa-fee-calculator pyenv setup

Setup fee calculator with pyenv

Setup pyenv globally

Create a virtual env

In fee calculator app root dir create a virtual env for a specific version of python (I am using 3.8.3, latest at time of writing), and give it a name.

$ cd .../laa-fee-calcultor
@jsugarman
jsugarman / .pryrc
Last active December 7, 2020 14:17
Custom pry with command aliases and custom rails prompt
# place in ~/.pryrc
if defined?(Pry)
Pry.config.color = true
Pry.config.prompt_name = 'Pry:' + File.basename(Dir.pwd)
Pry.commands.alias_command 'wami', 'whereami'
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
@jsugarman
jsugarman / python-version-management-with-pyenv.md
Created September 20, 2021 11:07
python version maagement with pyenv

Python version management with pyenv

Information

  pyenv help
  pyenv version
  pyenv versions
  pyenv version-origin
@jsugarman
jsugarman / debug-github-action.md
Created May 23, 2022 16:55
Debug github action

Debug github actions

see debugging with tmate

TLDR;

Add this after github action step you want to interactively debug

- uses: actions/checkout@v3
- name: Setup tmate session