Skip to content

Instantly share code, notes, and snippets.

View invisiblefunnel's full-sized avatar

Danny Whalen invisiblefunnel

View GitHub Profile
def within_navbar(&block)
within('.navbar', &block)
end
def within_navbar_dropdown(&block)
within_navbar do
find(:css, '.dropdown-toggle').click
within('.dropdown-menu', &block)
end
end
@invisiblefunnel
invisiblefunnel / active_admin-switch_user.md
Last active December 18, 2015 04:39
Sign in as any user with active_admin and switch_user

Install gems

# Gemfile
gem 'activeadmin'
gem 'switch_user'

Configure switch_user

class User
attr_accessor :name
def initialize(name); @name = name; end
end
class Collection
include Enumerable
def initialize(*elements)
@elements = elements
@invisiblefunnel
invisiblefunnel / benchmarks.rb
Created August 1, 2013 01:10
Relative require times of equivalent syntax
require 'benchmark'
require 'fileutils'
require 'debugger'
def N(&block)
100_000.times(&block)
end
CASES = {
'class-definition' => [
diff --git a/grammar.y b/grammar.y
index 3a76026..f05caf4 100644
--- a/grammar.y
+++ b/grammar.y
@@ -13,6 +13,7 @@ token TRUE FALSE NIL
token IDENTIFIER
token CONSTANT
token END
+token WHILE
@invisiblefunnel
invisiblefunnel / pluck_uniq.rb
Last active December 21, 2015 23:29
Pluck ordered, unique column values. Useful for select input collections.
class ActiveRecord::Base
def self.pluck_uniq(name, order = name)
select(name.to_s).uniq.order(order).pluck(name.to_sym)
end
end
vagrant@rails-dev-box:/vagrant/rails$ bundle exec rake test
/home/vagrant/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -w -I"lib:test" -I"/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib" "/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb"
/home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/openssl/ssl.rb:101: warning: assigned but unused variable - id
Run options: --seed 35377
# Running:
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@invisiblefunnel
invisiblefunnel / .simple-active-record-scratch-pad
Last active December 24, 2015 14:49
Simple Active Record Scratch Pad
We couldn’t find that file to show.
@invisiblefunnel
invisiblefunnel / require_known_universe.rb
Created October 21, 2013 00:03
require all the things
puts ObjectSpace.each_object(Class){}
$LOAD_PATH.each do |dir|
Dir[File.join(dir, '*.rb')].each do |path|
lib = File.basename(path).gsub(/\.rb$/, '')
next if %w(debug gauntlet_rubygems monitor dl profile).include?(lib)
begin
require lib
rescue LoadError
require 'pp'
require 'set'
def class_count
puts ObjectSpace.each_object(Class){}
end
SKIPS = %w(debug gauntlet_rubygems monitor dl profile).map{ |l| "#{l}.rb" }
def require_all_the_things