Skip to content

Instantly share code, notes, and snippets.

View jeremywadsack's full-sized avatar

Jeremy Wadsack jeremywadsack

View GitHub Profile
@jeremywadsack
jeremywadsack / move_origin.sh
Last active August 29, 2015 14:05
Change git remote after renaming origin organization at GitHub
# A one-line script to change the origin organization name.
#
# After renaming our organization at GitHub, I had 25 repos I needed to update locally.
# This script finds the current "origin", removes it and replaces it with a new one
# with the organization changed.
#
# Just change OLD_ORG and NEW_ORG below to the old and new organization names and run
# this in each repository.
f=`git remote -v | grep '^origin' | cut -c 8- | cut -d' ' -f 1 | uniq`; git remote remove origin; git remote add origin ${f/OLD_ORG/NEW_ORG}
@jeremywadsack
jeremywadsack / rails_3.2.19
Created November 25, 2014 23:01
Postgres logs from rspec run under rails 3.2.19 and 4.1.8
[unknown]LOG: connection received: host=::1 port=58397
my-app-test LOG: connection authorized: user=jeremywadsack database=my-app-test
my-app-test LOG: statement: set client_encoding to 'UTF8'
my-app-test LOG: statement: set client_encoding to 'utf8'
my-app-test LOG: statement: SET client_min_messages TO 'WARNING'
my-app-test LOG: statement: SHOW client_min_messages
my-app-test LOG: statement: SET client_min_messages TO 'panic'
my-app-test LOG: statement: SET standard_conforming_strings = on
my-app-test LOG: statement: SET client_min_messages TO 'warning'
my-app-test LOG: statement: SET time zone 'UTC'
@jeremywadsack
jeremywadsack / covertToLocalDate.js.coffee
Created July 14, 2015 23:28
Covert UTC time to local time on browser
# 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
@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
@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 / 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 / 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 / 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 / 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 / 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}'