Skip to content

Instantly share code, notes, and snippets.

View BrianSigafoos's full-sized avatar

Brian Sigafoos BrianSigafoos

View GitHub Profile
@BrianSigafoos
BrianSigafoos / README.md
Last active February 23, 2023 19:58
Rails module to manage Stripe subscriptions from Stripe Checkout

Stripe CLI

  • Install the Stripe CLI with: brew install stripe/stripe-cli/stripe
  • Login to our Stripe account: stripe login
  • Listen for Stripe webhooks using Latest API version and forward to:
    • yarn stripe:listen, which does:
    • stripe listen --latest --forward-to http://localhost:3000/webhook_events/stripe
  • Replay events locally with stripe trigger <event type>:
  • stripe trigger checkout.session.completed
@BrianSigafoos
BrianSigafoos / change_all_tables.sql
Created February 13, 2020 20:55
Postgresql snippets
SELECT tablename FROM pg_tables WHERE schemaname = 'public';
-- Move out of public
DO
$$
DECLARE
row record;
BEGIN
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = 'public' -- and other conditions, if needed
LOOP
EXECUTE 'ALTER TABLE public.' || quote_ident(row.tablename) || ' SET SCHEMA valimail_defend_stage_reporting_20181127_super;';
@BrianSigafoos
BrianSigafoos / unused_indexes.sql
Last active August 21, 2020 12:09
Find unused indexes that can be pruned. Reference: https://wiki.postgresql.org/wiki/Index_Maintenance
SELECT
t.schemaname,
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(indexrelname)::text)) AS index_size,
pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(t.tablename)::text) AS table_size_raw,
pg_relation_size(quote_ident(t.schemaname)::text || '.' || quote_ident(indexrelname)::text) AS index_size_raw,
CASE WHEN indisunique THEN 'Y'
@BrianSigafoos
BrianSigafoos / stimulus.md
Created September 20, 2019 15:33 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
@BrianSigafoos
BrianSigafoos / reload-db.sh
Created August 28, 2019 14:31
Reload database
#!/bin/sh
DB_DUMP=$HOME/<filename>.dump
DB_NAME=<db name>
if [ -f $DB_DUMP ]; then
echo Creating database: $DB_NAME
createdb $DB_NAME > /dev/null 2>&1
if [ "$?" != "0" ]; then
@BrianSigafoos
BrianSigafoos / nginx_source_pagespeed_passenger_ubuntu.md
Created June 23, 2019 15:52 — forked from benbonnet/nginx_source_pagespeed_passenger_ubuntu.md
nginx from source with pagespeed and passenger on ubuntu 16.04 and above
sudo apt-get -y update
sudo apt-get install -y build-essential libcurl4-openssl-dev unzip software-properties-common git libpcre3-dev libpcre3

adding zlib, openssl and pcre

cd && mkdir sources && cd sources
wget https://downloads.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz && tar xzvf pcre-8.41.tar.gz
@BrianSigafoos
BrianSigafoos / db.rake
Created May 9, 2019 13:32 — forked from khalilgharbaoui/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# Original source: https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# Merged with: https://gist.github.com/kofronpi/37130f5ed670465b1fe2d170f754f8c6
# Benefits of: https://gist.github.com/e12e/e0c7d2cc1d30d18c8050b309a43450ac
# And fixes of: https://gist.github.com/joelvh/f50b8462611573cf9015e17d491a8a92
namespace :db do
desc 'Dumps the database to backups'
task dump: :environment do
dump_fmt = ensure_format(ENV['format'])
dump_sfx = suffix_for_format(dump_fmt)
backup_dir = backup_directory(Rails.env, create: true)
@BrianSigafoos
BrianSigafoos / aws_create_users_ubuntu.sh
Created February 4, 2019 15:43 — forked from vasansr/aws_create_users_ubuntu.sh
AWS User Data Script to create users when launching an Ubuntu server EC2 instance
#!/bin/bash
#
# Initial script to create users when launching an Ubuntu server EC2 instance
#
declare -A USERKEY
#
# Create one entry for every user who needs access. Be sure to change the key to their
# Remove local branches that have gone remotes - https://stackoverflow.com/a/33548037/967115
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done
@BrianSigafoos
BrianSigafoos / capybara.md
Created August 31, 2017 20:55 — forked from remi/capybara.md
RSpec Matchers

Capybara

save_and_open_page

Matchers

have_button(locator)