Skip to content

Instantly share code, notes, and snippets.

View nruth's full-sized avatar

Nicholas Rutherford nruth

View GitHub Profile
@nruth
nruth / Makefile
Created April 9, 2012 14:24
gecode gcc makefile
all: send-more-money donald
# use git clean -f for make clean, but confirm action
define gitCLEAN
puts 'ARE YOU SURE (git clean -f) ? y/n'; \
puts %x(git clean -n); \
exec('git clean -f') if gets.chomp =~ /^y/i
endef
clean:
@nruth
nruth / Sitemap.rb
Last active December 12, 2015 03:19
basic rails sitemap generator
# -*- encoding : utf-8 -*-
class Sitemap
def self.static_view_templates
require 'fileutils'
template_paths = []
FileUtils.cd Rails.root.join 'app', 'views', 'static_pages' do
erb_html_files = File.join "**", "*.html.erb"
template_paths = Dir.glob(erb_html_files)
end
remove_html_erb!(template_paths)
@nruth
nruth / routes.rb
Last active December 12, 2015 03:19
simple rails static page renderer
# last entry:
#static page routes
get '/home' => redirect('/')
root :to => 'static_pages#home'
get '*page', :to => 'static_pages#show', :constraints => {:page => %r{[\w\-\/]+}}
@nruth
nruth / screenshots.rb
Last active November 12, 2020 19:27
show_me_the_pages: screenshot various screen resolutions with capybara to review responsive design
RSpec.configure do |config|
config.filter_run_excluding :show_me_the_pages unless ENV["SHOW_ME_THE_PAGES"]
end
class Screenshots
include Capybara::DSL
attr_accessor :resolutions
attr_accessor :output_path
@nruth
nruth / pay_stripe_helper.rb
Last active March 7, 2023 00:21
capybara selenium webdriver stripe.js checkout test helper
# -*- encoding : utf-8 -*-
module PayStripeHelpers
# must be used with driver: :selenium (or :sauce?)
def pay_stripe
sleep(0.7) # wait for the js to create the popup in response to pressing the button
within_frame 'stripe_checkout_app' do # must be selenium
# fill_in 'card_number', with: '4242424242424242' no longer works
4.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4242')}
# fill_in 'cc-exp', with: '5/2018' no longer works
@nruth
nruth / admin_policy_spec.rb
Last active August 29, 2015 14:05
role scoped pundit spec for rspec 3
# -*- encoding : utf-8 -*-
# attempting to get something like http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec again
require 'rails_helper'
RSpec.describe AdminPolicy, type: :policy do
subject { AdminPolicy }
def self.permits(action)
permissions action do
it { expect(subject).to permit(current_admin, admin) }
@nruth
nruth / Vagrantfile
Created February 11, 2015 02:50
vagrant ubuntu 14.04 rbenv mysql for rails
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = 'ubuntu/trusty64'
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 3000, host: 3000
@nruth
nruth / application.html
Last active August 29, 2015 14:28
capybara ensure page changed
<!DOCTYPE html>
<html lang="en">
<head>
<# only include in the test env to avoid uuid generation slowing down every rendered page in production %>
<% if Rails.env.test? %>
<meta name='test-page' content="<%= SecureRandom.uuid %>">
<% end %>
<%# etc, all your usual content %>
</head
</html>
@nruth
nruth / email-screener-google-safebrowsing.yml
Last active September 14, 2015 19:56
ruby/rails user signup email screening with google safebrowsing api -- catch phishing domain typos in user email addresses
---
http_interactions:
- request:
method: get
uri: https://sb-ssl.google.com/safebrowsing/api/lookup?appver=1&client=your-app-name-here&key=abc123fakekey&pver=3.1&url=gmai.com
body:
encoding: US-ASCII
string: ''
headers:
Accept:
@nruth
nruth / migration-error.md
Created January 19, 2016 03:07
rails migration pg_dump: invalid option -- 'i'

If you start to see something like this, e.g. on Heroku since they installed the postgres 9.5 client libraries on their dynos

/usr/lib/postgresql/9.5/bin/pg_dump: invalid option -- 'i'
Try "pg_dump --help" for more information.
rake aborted!
Error dumping database
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'