Skip to content

Instantly share code, notes, and snippets.

View jeremywadsack's full-sized avatar

Jeremy Wadsack jeremywadsack

View GitHub Profile
@jeremywadsack
jeremywadsack / duplicate-cross-company.sql
Last active December 14, 2022 05:03
Employees with duplicate phone numbers that are cross-company
select
e.phone_number,
e.name,
e.public_id as employee_public_id,
c.name as company_name,
c.public_id as company_public_id,
d.name as division_name,
d.public_id as division_public_id
from customers_employee e
left join customers_company c on e.company_id = c.id
@jeremywadsack
jeremywadsack / retry_stripe_webhook.rb
Created May 29, 2019 17:37
Retry failed Stripe Webhook events
# frozen_string_literal: true
# Stripe will retry failed webhooks seven times with exponential backoff. If that has been exceeded
# then the webhook event is marked "failed" and won't be retried. We can resend the event by [retrieving
# the event data and posting it to the
# webhook](https://groups.google.com/a/lists.stripe.com/forum/#!topic/api-discuss/N33ZXqp3NzI).
#
# To use this, configure your endpoint URL below, then run this in providing event IDs on the command line.
WEB_HOOK = "YOUR ENDPOINT HERE"
@jeremywadsack
jeremywadsack / pg_mem.sh
Last active July 5, 2018 17:57
Metrics of postgres temporary file size and memory use
#!/usr/bin/env bash
# Records a line with the following space-separated fields
# date-time k-pg-tmp-work-mem k-pg-uss k-pg-pss k-pg-rss
cat <(du -sk /data/pgsql/9.5/data/base/pgsql_tmp/) <(/usr/local/bin/smem -u | grep postgres) | paste -s | awk '{print strftime("%FT%TZ") " " $1 " " $6 " " $7 " " $8}'
@jeremywadsack
jeremywadsack / bigquery-schema-load.rb
Created January 4, 2018 00:40
Schema#load implementation suggestion
class Schema
def load source
...
add_fields_to_schema(schema, source_fields)
self
end
def add_fields_to_schema schema, fields
@jeremywadsack
jeremywadsack / gem_cleaner.rb
Created August 28, 2017 19:59
Remove unused rvm gemsets
# Safely cleans up your rvm Gemsets with the following:
# - Deletes gemsets associated with older rubies than the latest (if more than one)
# - Runs `bundle clean` to remove unused gems in latest gemsets
# - Removes rubies (and related gemsets) that are no longer used by a gemset
gemsets = Dir["#{ENV['HOME']}/.rvm/gems/*"].select do |folder|
folder.include?("@")
end
gemsets = gemsets.map do |folder|
File.basename(folder)
@jeremywadsack
jeremywadsack / k82-resource-summary.sh
Last active June 8, 2017 17:56
K8s resource requests by node
# Kuberentes doesn't provide information about resource resquest in the `get` command, even in JSON mode
# This is the best I've got for getting a report of the total resource request allocation per node
kubectl describe nodes | egrep -A 4 '^Name:|^Allocated resources' | egrep '^Name:|Requests|%)'
@jeremywadsack
jeremywadsack / load_balancer
Created March 28, 2017 21:54
Create a Google Cloud HTTPS Load Balancer (with Cloud CDN) that fronts a Kubernetes service hosted in a GKE cluster exposed on a NodePort.
#!/usr/bin/env bash
# TODO: Fill in these details for the cluster and project:
# The GKE cluster
CLUSTER=
# Assume the app is named the same as the working directory
APP=$(basename $(pwd))
# The GKE tag that identifies the cluster nodes
CLUSTER_TARGET_TAG=
# Expects to have `tls.crt` and `tls.key` in this folder
@jeremywadsack
jeremywadsack / all-memory-deployment.yaml
Last active December 5, 2016 16:39
Kubernetes configuration files for kubernetes/kubernetes#37995 issue
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: all-memory-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: bash
@jeremywadsack
jeremywadsack / pg_graphite.sh
Created November 16, 2016 18:49
Get postgres memory usage and send it to graphite
#!/usr/bin/env bash
# Uses du to track the amount of disk space that postgres is using to hold queries that don't fit in memory.
# Uses smem to track USS, PSS, and RSS for the postrgres user for various views of how much memory it is using.
# Add this to crontab to run every minute.
# * * * * * /path/to/pg_graphite.sh
# Configure for your graphite host
PORT=2003
SERVER=carbon.hostedgraphite.com
API_KEY=11111111-2222-3333-4444-5555555555
@jeremywadsack
jeremywadsack / assets.rake
Last active May 5, 2016 18:43
Rails 4.2, Capistrano 3.4 local asset precompilation using rsync
# lib/capistrano/tasks/assets.rake
namespace :deploy do
desc "Precompile assets locally and then rsync to web servers"
task :compile_assets => [:set_rails_env] do
run_locally do
with rails_env: :production do
execute "bundle exec rake assets:precompile"
end
end