Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Sigafoos BrianSigafoos

View GitHub Profile
@BrianSigafoos
BrianSigafoos / application_component.rb
Created Dec 21, 2020
Fetch or fallback for Rails ViewComponent
View application_component.rb
# frozen_string_literal: true
class ApplicationComponent < ViewComponent::Base
private
# Reference: https://www.youtube.com/watch?v=YVYRus_2KZM&t=302s
def fetch_or_fallback(allowed_values, given_value, fallback)
if allowed_values.include?(given_value)
given_value
else
View keybindings.json
[
{
"key": "cmd+q",
"command": "-workbench.action.quit",
},
{
"key": "alt+cmd+.",
"command": "workbench.action.terminal.focusAtIndex1"
},
{
@BrianSigafoos
BrianSigafoos / README.md
Last active Sep 3, 2020
Rails module to manage Stripe subscriptions from Stripe Checkout
View README.md

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
View change_all_tables.sql
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;';
View unused_indexes.sql
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 Sep 20, 2019 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
View stimulus.md
View reload-db.sh
#!/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 Jun 23, 2019 — forked from benbonnet/nginx_source_pagespeed_passenger_ubuntu.md
nginx from source with pagespeed and passenger on ubuntu 16.04 and above
View nginx_source_pagespeed_passenger_ubuntu.md
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 — forked from khalilgharbaoui/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
View db.rake
# 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 Feb 4, 2019 — forked from vasansr/aws_create_users_ubuntu.sh
AWS User Data Script to create users when launching an Ubuntu server EC2 instance
View aws_create_users_ubuntu.sh
#!/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