Skip to content

Instantly share code, notes, and snippets.

Avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
View gist:3125592
# -*- encoding: utf-8 -*-
#
# -
require 'psych'
ary = ["Jakub Kuźma", "Timo Rößner"]
p ary.first.encoding
builder = Psych::Visitors::YAMLTree.new({})
View spec.rb
# 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
View gist:1805536
require 'active_support/inflector'
require 'benchmark'
# QUICK HACK
class RuleSet
def initialize
@rules = []
@regexp = nil
end
View gist:1805359
require 'active_support/inflector'
require 'benchmark'
# QUICK HACK
class RuleSet
def initialize
@rules = []
@regexp = nil
end
View example_class.rb
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 — forked from michaelfeathers/gccmock.rb
Generate stubs that tell you when they are called. Helpful when componentizing for test.
View gccmock.rb
# 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 \
View foo.rb
# 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']
View output
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]:
View new_coding_style.rb
# encoding: UTF-8
alias :✐ :puts
= true
"Cool" if
View 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>