Skip to content

Instantly share code, notes, and snippets.

View nruth's full-sized avatar

Nicholas Rutherford nruth

View GitHub Profile
@nruth
nruth / unpod.rb
Last active September 3, 2019 18:12
Ember Shucker - unpodding old projects (stupid simple grep/mv ruby fileutils script)
# pods aren't really a thing going forward, and come up as a problem during paid code reivews
# there is/was an alternative in the works to do with modules, but it's best to be on the old
# default ember-cli directory structure so that any new codemods can work
require 'fileutils'
app_pods = "app/pods"
puts "Shucking Routes"
routes = Dir.glob(File.join(app_pods, "**", "route.js"))
@nruth
nruth / find_warn.rb
Last active July 17, 2019 09:39
Finding where deprecation warnings are coming from (Capybara, Rails, etc, anything that calls Kernel#warn)
TracePoint.trace(:c_call) do |tp|
# the various methods on tp tell you where warn is defined, but we want to know about the call stack,
# in particular the test code that the test library didn't like and decided to warn us about,
# so let's Array#grep the caller strings, filtering out the rspec library lines
if tp.method_id == :warn
app_lines = caller(0).grep(%r{enough-of-your-app-code-path-to-match/})
app_lines_without_reporter = app_lines.grep_v(/name-of-your-rspec-support-file-holding-this-code/)
p app_lines_without_reporter.join("\n")
p
end
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from 'medify-bmat-grader/config/environment';
export function prefixRootUrl([href]) {
if (config.environment !== 'production') {
return `${config.rootURL}${href}`;
} else {
return href;
}
}
@nruth
nruth / selenium.rb
Last active March 22, 2023 13:10
translating old capybara selenium/chrome preferences and switches to new
# load into test setup after `require 'capybara/rails'`
# some sources for below flags and profile settings
# https://stackoverflow.com/questions/43143014/chrome-is-being-controlled-by-automated-test-software/43145088
# https://sqa.stackexchange.com/questions/26051/chrome-driver-2-28-chrome-is-being-controlled-by-automated-test-software-notif
# http://stackoverflow.com/questions/12211781/how-to-maximize-window-in-chrome-using-webdriver-python
# update sources for new Options object
# https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings
# https://github.com/teamcapybara/capybara/blob/master/lib/capybara/selenium/driver.rb
begin
@nruth
nruth / redirector.js
Last active April 29, 2016 15:46
ember.js acceptance test window.location redirector abstraction service
import Ember from 'ember';
export default Ember.Service.extend({
redirectTo(href) {
window.location.href = href;
},
replace(href) {
window.location.replace(href);
},
reload() {
@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'
@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 / 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 / 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