Skip to content

Instantly share code, notes, and snippets.

View iHiD's full-sized avatar
💙

Jeremy Walker iHiD

💙
View GitHub Profile
@iHiD
iHiD / cloudfront.rb
Created May 4, 2011 14:57
Ruby Signed Expiring Cloudfront URL
# A simple function to return a signed, expiring url for Amazon Cloudfront.
# As it's relatively difficult to figure out exactly what is required, I've posted my working code here.
# This will require openssl, digest/sha1, base64 and maybe other libraries.
# In my rails app, all of these are already loaded so I'm not sure of the exact dependencies.
module CloudFront
def get_signed_expiring_url(path, expires_in, private_key_filename, key_pair_id)
# AWS works on UTC, so make sure you are not using local time
@iHiD
iHiD / application.rb
Created May 26, 2011 13:38
Table Name Bug in Rails 3
# config/application.rb
#...
config.autoload_paths += %W(#{config.root}/app/models/namespaces)
#...
@iHiD
iHiD / product_spec.rb
Created June 26, 2011 18:31
Basic rspec example
#spec/models/product_spec.rb
require 'spec_helper'
describe Product do
before :each do
@valid_attributes = {name: "Test Product",
user: mock_model(User)}
end
@iHiD
iHiD / application.rb
Created May 7, 2012 15:57
How to Build A Secure Website With Ruby On Rails
config.force_ssl = true
@iHiD
iHiD / coffee_script_route_parser.rb
Created June 6, 2012 15:16
Basic CS -> Rails routes converter.
require 'rails/application/route_inspector'
class Journey::Visitors::Formatter
def visit_SYMBOL node
key = node.to_sym
if value = options[key]
consumed[key] = value
value # Overritten this line to avoid escaping of characters
else
@iHiD
iHiD / application.rb
Created June 6, 2012 15:27
How to Build A Secure Website With Ruby On Rails 1
config.force_ssl = true
@iHiD
iHiD / csrf.js
Created June 6, 2012 15:28
How to Build A Secure Website With Ruby On Rails 2
var form_data = //.. Serialise a form
// Get token and param from the meta tags
var token = $('meta[name="csrf-token"]').attr('content');
var param = $('meta[name="csrf-param"]').attr('content');
// Create url of "/settings/profile?name=Jeremy+Walker&authenticity_token=askdsalewg303y09sd00dshb0b00ac0dffbafds"
document.location = "/settings/profile?_method=PUT&" + form_data + "&" + token + "=" + param;
@iHiD
iHiD / database_session_script.bash
Created June 6, 2012 15:28
How to Build A Secure Website With Ruby On Rails 3
rails generate session_migration
rake db:migrate
@iHiD
iHiD / heroku_setup.bash
Created June 6, 2012 15:29
How to Build A Secure Website With Ruby On Rails 4
heroku addons:add ssl:endpoint
heroku certs:add my_cerficate.crt site.key
@iHiD
iHiD / session_store.rb
Created June 6, 2012 15:29
How to Build A Secure Website With Ruby On Rails 5
Security::Application.config.session_store :active_record_store