Skip to content

Instantly share code, notes, and snippets.

@jsomara
jsomara / s3_signer.rb
Created August 18, 2016 22:01
S3 Signature Request Process v4, in ruby/rails
# Algorithm: http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html
# policy_params are the input policy as a rails request param object, which expects :conditions & :expiration
class S3Signer
def self.get_signature_key(key, date_stamp, region_name, service_name)
k_date = OpenSSL::HMAC.digest('sha256', "AWS4" + key, date_stamp)
k_region = OpenSSL::HMAC.digest('sha256', k_date, region_name)
k_service = OpenSSL::HMAC.digest('sha256', k_region, service_name)
k_signing = OpenSSL::HMAC.digest('sha256', k_service, "aws4_request")
@sgringwe
sgringwe / rails4_paperclip_default_url
Last active March 19, 2019 00:54
rails 4 paperclip asset_path precompiled default_url
I was having trouble setting the default_url for paperclip attachables while using rails 4 asset pipeline fingerprints.
What was not working for some reason:
default_url: ActionController::Base.helpers.asset_path('event_default.jpg')
What worked for me:
default_url: lambda { |image| ActionController::Base.helpers.asset_path('event_default.jpg') }
@bokmann
bokmann / ActiveRepository.rb
Created March 27, 2012 16:15
ActiveRepository Strawman
# MOTIVATION: As rails apps are growing, people are noticing the drawbacks
# of the ActiveRecord pattern. Several apps I have seen, and several
# developers I have spoken to are looking towards other patterns for object
# persistence. The major drawback with ActiveRecord is that the notion
# of the domain object is conflated with what it means to store/retrieve
# it in any given format (like sql, json, key/value, etc).
#
# This is an attempt to codify the Repository pattern in a way that would
# feel comfortable to beginner and seasoned Ruby developers alike.
#
# Rspec 1.3.2
# File mumble.rb
module Services
module Mumble
class Selector
end
end
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@bkimble
bkimble / gist:1365005
Last active September 28, 2025 09:57
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@mattheworiordan
mattheworiordan / capybara_webkit_screenshot_env.rb
Created August 19, 2011 12:26
Cucumber and Capybara-Webkit automatic screenshots on failure
def screen_shot_and_save_page
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
Capybara.save_page body, "#{path}.html"
page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
end
begin
After do |scenario|
screen_shot_and_save_page if scenario.failed?
@mcornell
mcornell / error_writer.rb
Created April 13, 2011 14:23
Making Your Cukes More Awesomer With Screenshots
module ErrorWriter
def scenario_name(scenario)
if scenario.instance_of?(Cucumber::Ast::OutlineTable::ExampleRow)
scenario_name = scenario.scenario_outline.name.gsub(/[^\w\-]/, ' ')
scenario_name += "-Example#{scenario.name.gsub(/\s*\|\s*/, '-')}".chop
else
scenario_name = scenario.name.gsub(/[^\w\-]/, ' ')
end
scenario_name