Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Matt Metzger is typing

Matt Metzger almostwhitehat

💭
Matt Metzger is typing
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am almostwhitehat on github.
  • I am almostwhitehat (https://keybase.io/almostwhitehat) on keybase.
  • I have a public key whose fingerprint is 82E7 6B8D 4751 19C0 C1E1 942F 85FA A1AF BC14 E33D

To claim this, I am signing this object:

@almostwhitehat
almostwhitehat / view_finder.rb
Created Jan 27, 2017
Add HTML comments to rendered templates and views to discover where content is coming from
View view_finder.rb
# Drop this in as a rails initializer and resstart rails
# View the source of pages - you'll see which template and views are used when rendering pages
module ActionView
class TemplateRenderer
alias_method :original_render, :render
def render(context, options)
rendered_content = original_render(context, options)
# Random string makes it easier to jump between matching start / stop when viewing source of the page
View shared_connection.rb
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
View gist:1722cd54c09d034274b5
require 'benchmark/ips'
ARRAY = [*1..100]
def slow
ARRAY.select { |x| x.eql?(50) }.last
end
def fast
ARRAY.reverse.detect { |x| x.eql?(50) }
View gist:368d9cb4fe06f850529e
require 'benchmark/ips'
ARRAY = [*1..100]
def slow
ARRAY.select { |x| x.eql?(80) }.last
end
def fast
ARRAY.reverse.detect { |x| x.eql?(80) }
View gist:89370eb8eb856c93f835
Before do |scenario|
tagged_as_a_bug = scenario.source_tag_names.any? { |tag| tag.start_with? '@Bug-' }
if tagged_as_a_bug
STDOUT.puts 'Skipped - Bug'
scenario.skip_invoke!
end
end
View gist:031fe6b6f3737a4b3671
Pry.editor = proc { |file, line| "rubymine #{file} --line #{line} #{file}" }
Pry::Commands.create_command "rm" do
description "Launches rubymine at the current point"
def process
run 'edit --current'
end
end