Skip to content

Instantly share code, notes, and snippets.

Tom Clark Whitespace

Block or report user

Report or block Whitespace

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Whitespace
Whitespace / postgres.sql
Last active Dec 20, 2016
Common Postgres SQL Troubleshooting Queries
View postgres.sql
-- Heroku has a bunch of awesome queries
-- https://github.com/heroku/heroku-pg-extras/tree/master/commands
-- View slow queries for widgets table
SELECT query, total_time/calls AS avg_time
FROM pg_stat_statements
WHERE query LIKE 'SELECT%'
AND query LIKE '%widgets%'
ORDER BY avg_time DESC;
View bench_rails_memory_usage.rb
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@Whitespace
Whitespace / capybara.md
Last active Aug 29, 2015
Setup Rails app to use Capybara
View capybara.md

Background

Not every app is setup to run capybara tests, but many have an existing testing framework that we'll have to integrate with. Here are some common frameworks we'll come across.

Rspec

If there's no existing testing framework, let's setup this app with rspec, which is preferred.

View long_running_transactions.sql
SELECT userid, dbid, left(query, 100), total_time, rows FROM pg_stat_statements WHERE total_time >= 1000 ORDER BY total_time DESC;
@Whitespace
Whitespace / types.rb
Created Apr 13, 2015
Gradual Type Checking for Ruby
View types.rb
# inspired by http://gogotanaka.github.io/rubype.github.io/
module Types
def self.included(base)
class << base
def typesig method, signature_hash
arg_types, ret_type = signature_hash.to_a[0]
self.send(:alias_method, "__#{method}".to_sym, method)
define_method method do |*args|
View keybase.md

Keybase proof

I hereby claim:

  • I am whitespace on github.
  • I am whitespace (https://keybase.io/whitespace) on keybase.
  • I have a public key whose fingerprint is C9B9 3355 72A5 6AF5 008D 43AE 082C 9F6A F98D 34C9

To claim this, I am signing this object:

@Whitespace
Whitespace / monad.rb
Created Apr 9, 2013
Couldn't sleep, so I added some monads to Ruby
View monad.rb
require "minitest/autorun"
module Monad
def return(val)
self.class.new(val)
end
def bind(&block)
self.return yield @value
end
@Whitespace
Whitespace / heroku.sh
Created Apr 2, 2013
Some helper functions for heroku deploys. This uses the heroku cli's -r feature to run commands on a git remote, so you need git remotes for production and staging to respectively named.
View heroku.sh
function p {
command=$1
shift 1
heroku $command -r production $@
}
function s {
command=$1
shift 1
heroku $command -r staging $@
@Whitespace
Whitespace / cleanup.sh
Created Aug 28, 2012 — forked from jessedearing/cleanup.sh
Git branch cleanup
View cleanup.sh
git checkout master
git fetch
git remote prune origin
git branch --merged master | grep -v 'master$' | xargs git branch -d
echo "The following remote branches are fully merged and will be removed:"
git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$'
git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$' | xargs -I% git push origin :%
You can’t perform that action at this time.