Skip to content

Instantly share code, notes, and snippets.

View tenderlove's full-sized avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
# -*- encoding: utf-8 -*-
#
# -
require 'psych'
ary = ["Jakub Kuźma", "Timo Rößner"]
p ary.first.encoding
builder = Psych::Visitors::YAMLTree.new({})
# Note the differences between this and https://gist.github.com/2938965 are that
# we're making 10k groups with 2 examples each vs 10k group w/ 1 example.
if $0 =~ /rspec$/
10_000.times do |i|
describe "loltest #{i}" do
it "does #{i}" do
i.should eq i
end
require 'active_support/inflector'
require 'benchmark'
# QUICK HACK
class RuleSet
def initialize
@rules = []
@regexp = nil
end
require 'active_support/inflector'
require 'benchmark'
# QUICK HACK
class RuleSet
def initialize
@rules = []
@regexp = nil
end
@tenderlove
tenderlove / example_class.rb
Created May 24, 2011 16:31 — forked from joemsak/example_class.rb
instance has?
class Example < ActiveRecord::Base
#...
# would this be cool to have, or am I daft?
def has? *args
args.any? { |a| send(a.to_sym) }
end
# irc chan said to drop the to_sym but I like having the failsafe
@tenderlove
tenderlove / gccmock.rb
Created May 5, 2011 19:43 — forked from michaelfeathers/gccmock.rb
Generate stubs that tell you when they are called. Helpful when componentizing for test.
# gccmock - generate exploding link stubs from linker error messages
#
# Usage: gcc [files] 2>&1 ruby gccmock.rb > [filename].c
LINK_SYMBOL = /.*"_([_a-z0-9]*)",/
puts "#include <assert.h>\n"
puts "#define EXPLODE(name) void name() { assert(!\"unexpected call\"); }"
puts ARGF.grep(LINK_SYMBOL) { |string| "EXPLODE(#{$1})" } \
.uniq \
# Install the psych gem and uncomment the following line.
#gem 'psych'
require 'psych'
stuff = Psych.load_file ARGV[0] || 'newrelic.yml'
p stuff['production']['enabled']
Run options: --seed 27810
# Running tests:
F.
Finished tests in 0.003334s, 599.8800 tests/s, 599.8800 assertions/s.
1) Failure:
test_syck(SadnessTest) [yaml_bug.rb:14]:
# encoding: UTF-8
alias :✐ :puts
☺ = true
✐ "Cool" if ☺
@tenderlove
tenderlove / omg.rb
Created January 6, 2011 05:51 — forked from mojombo/omg.rb
require 'nokogiri'
doc = Nokogiri.HTML DATA
doc.xpath('//div//text()').map { |x| x.content = x.content.to_s }
p doc.serialize(:save_with => Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
__END__
<div>&nbsp;<span>x</span></div>