Skip to content

Instantly share code, notes, and snippets.

View gabetax's full-sized avatar

Gabe Martin-Dempesy gabetax

  • Zendesk
  • San Francisco
  • 20:39 (UTC -07:00)
View GitHub Profile
/vagrant/test_spec.rb:3:in `block in <top (required)>': undefined local variable or method `foo' for #<Class:0x000000020035c8> (NameError)
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/example_group.rb:244:in `module_eval'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/example_group.rb:244:in `subclass'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/example_group.rb:230:in `describe'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/dsl.rb:18:in `describe'
from /vagrant/test_spec.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/configuration.rb:789:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/configuration.rb:789:in `block in load_spec_files'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.1/lib/rspec/core/configuration.rb:789:in `each'
from /usr/local/rvm/gems/r
describe "show foo" do
let(:foo) { FactoryGirl.create :foo }
it "should load" do
visit foo_path(foo)
page.path.should == foo_path
page.status_code.should == 200
end
end
@gabetax
gabetax / benchmark.rb
Created March 9, 2013 02:50
FactoryGirl.build on a PORO with no defined attributes vs #new
require 'perftools'
TIMES = 100_000
Benchmark.bm do |bm|
bm.report 'FactoryGirl.build' do
PerfTools::CpuProfiler.start("factorygirl") do
TIMES.times { FactoryGirl.build :loans_search_form }
end
end
@gabetax
gabetax / string_bench.rb
Created February 13, 2013 19:08
ruby String#+ vs interpolation benchmark
require 'faker'
require 'benchmark'
times = 10000000
str = 'hello world'
Benchmark.bm do |b|
b.report("+ with space") do
times.times do
str + str
end
@gabetax
gabetax / gist:4447578
Created January 3, 2013 21:40
Custom holidays with the holidays gem
---
months:
0:
- name: Mardi Gras
regions: [bank]
function: easter(year)-47
11:
- name: Black Friday
week: -1
regions: [bank]
@gabetax
gabetax / gist:4074023
Created November 14, 2012 19:01
OTP key reuse vulnerability cracker
class String
# 'hello' ^ ' ' => 'HELLO'
def ^ s2
to_byte_array.zip(s2.to_byte_array).map { |s| s[0] ^ s[1] if s[1] }.reject(&:nil?).pack('C*')
end
# '68656c6c6f20776f726c64' => 'hello world'
def hex_string_to_binary_string
[self].pack 'H*'
end
@gabetax
gabetax / .profile
Created September 20, 2012 15:55
ssh-agent setup for bash .profile
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
@gabetax
gabetax / model.xpl
Created September 13, 2012 17:48
Orbeon test-case of query string encoding bug. View http://localhost:8080/ops/encoding-test/?message=it%E2%80%99s%20a%20message to trigger error
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:oxf="http://www.orbeon.com/oxf/processors">
<p:param name="instance" type="input" debug="model in"/>
<p:param name="data" type="output" debug="model out"/>
<p:processor name="oxf:request">
<p:input name="config">
<config>
<include>/request/parameters/*</include>
</config>
@gabetax
gabetax / orbeon-encoding-test.log
Created September 13, 2012 17:30
Output of Orbeon log when viewing http://localhost:8080/ops/encoding-test/?message=it%E2%80%99s%20a%20message
2012-09-13 12:30:02,150 INFO ProcessorService - /encoding-test/ - Received request
2012-09-13 12:30:02,252 INFO DebugProcessor - request parameters:
line 12, column 83 of oxf:/apps/encoding-test/model.xpl
<request>
<parameters>
<parameter>
<name>message</name>
<value>it???s a message</value>
</parameter>
@gabetax
gabetax / .gitconfig
Created May 31, 2012 21:12
my .gitconfig
[color]
diff = auto
status = auto
branch = auto
[color "diff"]
whitespace = red reverse
[core]
#whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
autocrlf = input
#safecrlf = true