This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PoltergeistNetworkMonitor | |
require 'pstore' | |
require 'uri' | |
require 'fileutils' | |
def initialize(page) | |
@page = page | |
end | |
def print_requests(longer_than_seconds:) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CapybaraHooks | |
def after_page_change | |
end | |
Capybara::Session::DSL_METHODS.each do |method| | |
define_method method do |*args, &block| | |
old_page = page.current_url | |
super(*args, &block) | |
new_page = page.current_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
production="refs/heads/production" | |
apikey="0001230120301203012030120301230" | |
application_id="1234567" | |
user=$(git config user.name) | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$remote_ref" == $production ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
%w[create migrate rollback seed setup version migrate:status].each do |command| | |
desc "Rake db:#{command}" | |
task command do | |
on roles(:app) do | |
within "#{current_path}" do | |
with rails_env: :production do | |
execute :rake, "db:#{command}" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
ActionController::Renderers.add :csv do |collection, options| | |
self.content_type ||= Mime::CSV | |
self.headers['Content-Disposition'] = "attachment; filename=#{options[:filename]}.csv" if options[:filename] | |
self.response_body = collection.to_csv | |
end | |
module CsvRenderer | |
def to_csv(options={}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def batch(iterable, n=1): | |
l = len(iterable) | |
for ndx in range(0, l, n): | |
yield iterable[ndx:min(ndx+n, l)] | |
import sendwithus | |
import csv | |
max_count = 100 # keep this as or around 100 for batch requests | |
csv_location = './customers.csv' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addEvent(element, eventName, fn) { | |
if (element.addEventListener) | |
element.addEventListener(eventName, fn, false); | |
else if (element.attachEvent) | |
element.attachEvent('on' + eventName, fn); | |
} | |
var wasEnterPressed = function(e){ | |
return e.which == 13 || e.keyCode == 13; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :exceed_query_limit do |expected| | |
supports_block_expectations | |
match do |block| | |
query_count(&block) > expected | |
end | |
failure_message_when_negated do |actual| | |
"Expected a maximum of #{expected} queries, got #{@recorder.count}:\n\n#{@recorder.log_message}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/db.rake | |
namespace :db do | |
desc "Dumps the database to db/APP_NAME.dump" | |
task :dump => :environment do | |
cmd = nil | |
epoch = Time.now.to_i | |
with_config do |app, host, db, user| | |
cmd = "pg_dump --verbose #{pg_login_config(host, user)} --clean --format=c #{db} > #{Rails.root}/db/#{app}-#{epoch}.dump" | |
end | |
puts cmd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AuthHelper | |
module Feature | |
def basic_auth(login, password) | |
if page.driver.respond_to?(:basic_auth) | |
page.driver.basic_auth(login, password) | |
elsif page.driver.respond_to?(:basic_authorize) | |
page.driver.basic_authorize(login, password) | |
elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize) | |
page.driver.browser.basic_authorize(login, password) | |
else |
NewerOlder