Skip to content

Instantly share code, notes, and snippets.

@schneems
schneems / validate_facebook_signature.rb
Created December 20, 2010 20:37
validate facebook signed_request in ruby
require 'base64'
def base64_url_decode(str)
str += '=' * (4 - str.length.modulo(4))
Base64.decode64(str.gsub("-", "+").gsub("_", "/"))
end # source: https://github.com/ptarjan/base64url/blob/master/ruby.rb
require 'hmac'
require 'hmac-sha2' ## used to decode facebook return values
@szimek
szimek / capybara_select_dates_and_times.rb
Created August 31, 2010 09:26
Cucumber steps for selecting time and date (using Capybara)
require "xpath" # XPath is a separate gem now
module Cucumber
module Rails
module CapybaraSelectDatesAndTimes
def select_date(field, options = {})
date = Date.parse(options[:with])
selector = %Q{.//fieldset[contains(./legend, "#{field}")]}
within(:xpath, selector) do
find(:xpath, '//select[contains(@id, "_1i")]').find(:xpath, ::XPath::HTML.option(date.year.to_s)).select_option