Skip to content

Instantly share code, notes, and snippets.

View Whitespace's full-sized avatar

Tom Clark Whitespace

View GitHub Profile
SELECT userid, dbid, left(query, 100), total_time, rows FROM pg_stat_statements WHERE total_time >= 1000 ORDER BY total_time DESC;
@Whitespace
Whitespace / capybara.md
Last active August 29, 2015 14:19
Setup Rails app to use Capybara

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.

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 / postgres.sql
Last active December 20, 2016 17:07
Common Postgres SQL Troubleshooting Queries
-- 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;