Skip to content

Instantly share code, notes, and snippets.

View rimian's full-sized avatar

Rimian Perkins rimian

View GitHub Profile
module RackHeaderHack
def set_headers(headers)
driver = page.driver
def driver.env
@env.merge(super)
end
def driver.env=(env)
@env = env
end
driver.env = headers
@steveclarke
steveclarke / capybara.md
Created April 10, 2012 17:32
RSpec Matchers

Capybara

save_and_open_page

Matchers

have_button(locator)
@rks
rks / gist:2577339
Created May 2, 2012 15:12
Wrapping exceptions in Ruby
class CustomError < StandardError
def initialize(e = nil)
super e
set_backtrace e.backtrace if e
end
end
def run
r = Runner.new
r.fail
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@juike
juike / restore.sql
Created November 21, 2014 06:40
Restoring a 'template1' database in PostgreSQL. (https://wiki.postgresql.org/wiki/Adventures_in_PostgreSQL,_Episode_1)
UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';
\c template0
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = 'template0';
\c template1
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template0';