Skip to content

Instantly share code, notes, and snippets.

View gabetax's full-sized avatar

Gabe Martin-Dempesy gabetax

  • Zendesk
  • San Francisco
  • 05:48 (UTC -07:00)
View GitHub Profile
@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 / .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 / 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 / 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 / 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 / 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
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
/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
@gabetax
gabetax / Anchor.ino
Last active December 16, 2015 21:29 — forked from mganucheau/gist:5499453
// LPD8806 LED Code for our Yacht Club's Anchor
/*************************************************************************************/
#include "LPD8806.h" // Library Here: https://github.com/adafruit/LPD8806
#include "SPI.h"
int totalLEDs = 14;
int dataPin = 2;
int clockPin = 3;
LPD8806 strip = LPD8806(totalLEDs, dataPin, clockPin);
@gabetax
gabetax / pretzel.rb
Last active December 19, 2015 00:29
https://twitter.com/garybernhardt/status/349920138889404416
[1] pry(main)> class Object; alias_method :&, :method; end
=> Object
With standard symbol to proc, &:foo evaluates to:
{ |x| x.foo }
With the "pretzel bun", &foo&:bar evaluates to: