Skip to content

Instantly share code, notes, and snippets.

View Whitespace's full-sized avatar

Tom Clark Whitespace

View GitHub Profile
@Whitespace
Whitespace / keybase.md
Created March 31, 2014 22:53
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 / types.rb
Created April 13, 2015 13:11
Gradual Type Checking for Ruby
# 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|
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
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql84/bin/:/usr/local/mongodb/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export GIT_EDITOR="mate -w"
export MANPATH=/opt/local/share/man:$MANPATH
export PS1="\[\033[1;30m\]\w\[\033[0m\]\n\$(git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1 /')\$ "
if [ -s ~/.rvm/scripts/rvm ] ; then source ~/.rvm/scripts/rvm ; fi
alias ls='ls -G'
---
gem: --no-ri --no-rdoc
:benchmark: false
:update_sources: true
:backtrace: false
:bulk_threshold: 1000
:verbose: true
:sources:
- http://gemcutter.org/
- http://gems.rubyforge.org/
@Whitespace
Whitespace / steps.sh
Created June 20, 2012 02:13
Nimbus Connection Errors
# Checkout the storm repo at version 0.7.0 (the version I was using)
cd ~/code/test
git clone https://github.com/nathanmarz/storm.git
cd ~/code/test/storm
git checkout 3159347
# Install the ruby thrift gem
gem install thrift
# Create our test project
# We're going to store number that match in here
sum = 0
# Use a Range object to iterate over every number from 0 to 1000 (inclusive)
(0..1000).each do |n|
# Add n to the sum if n is a multiple of 5 or 3
sum += n if n % 5 == 0 || n % 3 == 0
end
# Print the answer
@Whitespace
Whitespace / heroku.sh
Created April 2, 2013 20:43
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.
function p {
command=$1
shift 1
heroku $command -r production $@
}
function s {
command=$1
shift 1
heroku $command -r staging $@