Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Wadsack jeremywadsack

View GitHub Profile
@jeremywadsack
jeremywadsack / retry_stripe_webhook.rb
Created May 29, 2019
Retry failed Stripe Webhook events
View retry_stripe_webhook.rb
# 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 Jul 5, 2018
Metrics of postgres temporary file size and memory use
View pg_mem.sh
#!/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 Jan 4, 2018
Schema#load implementation suggestion
View bigquery-schema-load.rb
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 Aug 28, 2017
Remove unused rvm gemsets
View gem_cleaner.rb
# 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 Jun 8, 2017
K8s resource requests by node
View k82-resource-summary.sh
# 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 Mar 28, 2017
Create a Google Cloud HTTPS Load Balancer (with Cloud CDN) that fronts a Kubernetes service hosted in a GKE cluster exposed on a NodePort.
View load_balancer
#!/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
View all-memory-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: all-memory-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: bash
@jeremywadsack
jeremywadsack / pg_graphite.sh
Created Nov 16, 2016
Get postgres memory usage and send it to graphite
View pg_graphite.sh
#!/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
Rails 4.2, Capistrano 3.4 local asset precompilation using rsync
View assets.rake
# 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
@jeremywadsack
jeremywadsack / covertToLocalDate.js.coffee
Created Jul 14, 2015
Covert UTC time to local time on browser
View covertToLocalDate.js.coffee
# A jQuery plugin to convert UTC times to local times on the browser.
#
# You can apply this to any element on the page like this:
#
# $('#message').covertToLocalDate();
#
# This looks for one or more date-time strings in the original element
# and replaces them. The existing dates must be in the format
# 2015-07-14 16:30:00 UTC
# It replaces them with an <abbr> element (which is usually styled with