Skip to content

Instantly share code, notes, and snippets.

View sbfaulkner's full-sized avatar

S. Brent Faulkner sbfaulkner

  • Shopify
  • Caledon, ON CANADA
View GitHub Profile
@sbfaulkner
sbfaulkner / to_yaml.rb
Created February 5, 2009 06:27
fix to_yaml when dumping ActiveRecord instances with nil association_proxies
module ActiveRecord
class Base
def to_yaml_with_nil_handling(opts = {})
# detect and remove any belongs_to association proxies
self.class.reflect_on_all_associations.find_all { |a| a.macro == :belongs_to }.each do |a|
ivar = "@#{a.name}"
remove_instance_variable(ivar) if instance_variable_defined?(ivar) && instance_variable_get(ivar).class.nil?
end
to_yaml_without_nil_handling(opts)
end
@sbfaulkner
sbfaulkner / to_yaml.rb
Created February 5, 2009 07:03
an alternate (more aggressive) approach to making to_yaml work
module ActiveRecord
class Base
def to_yaml_with_association_pruning(opts = {})
# detect and remove any cached associations
self.class.reflect_on_all_associations.each do |a|
ivar = "@#{a.name}"
remove_instance_variable(ivar) if instance_variable_defined?(ivar)
end
to_yaml_without_association_pruning(opts)
end
@sbfaulkner
sbfaulkner / getserp.rb
Created April 11, 2009 23:05
check serp of one or more sites on google for a number of keyword queries
#!/usr/bin/env ruby
#
# check google serp for multiple sites using provided queries
#
require 'rubygems'
require 'mechanize'
SITES = [
'moneyworks.ca',
#!/bin/sh
# Install ImageMagick on Snow Leopard: by kain, improved by mislav and samsoffes
# http://www.icoretech.org/2009/08/install-imagemagick-in-leopard-snow-leopard/
# Work with 64bit kernel mode
set -e
PREFIX=/usr/local
# Passenger users: amend your Apache global configuration with the following directive
# SetEnv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
require 'openssl'
def gen_key(name)
key = OpenSSL::PKey::RSA.new 1048
file = File.new(name, "w")
file.write(key)
file.close
end
def get_key(name)
# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
# A closure is a block of code which meets three criteria:
#
@sbfaulkner
sbfaulkner / cas-authentication.rb
Created July 7, 2015 13:27
cas authentication
require 'rubygems'
require 'faraday'
require 'faraday_middleware'
cas = Faraday.new(:url => 'http://cas.dev') do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.response :xml, :content_type => /\bxml$/
faraday.adapter Faraday.default_adapter
@sbfaulkner
sbfaulkner / crypto-tests.rb
Created July 7, 2015 13:29
cryptography tests
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
require 'builder'
require 'securerandom'
require 'faker'
tests = %i(rsa)
I18n.enforce_available_locales = true
@sbfaulkner
sbfaulkner / openssl.rb
Created July 7, 2015 13:31
openssl certificate/key operations
# DOMAIN='example.com'
# PASSWORD='my secure pass phrase goes here'
#
# KEYFILE = "#{DOMAIN}.key"
# CSRFILE = "#{DOMAIN}.csr"
#
################################################################################
# create a new key
# key = OpenSSL::PKey::RSA.new 2048
#
@sbfaulkner
sbfaulkner / crypt.rb
Created July 7, 2015 14:42
crypt tests
require 'rubygems'
require 'base64'
require 'encryptor'
require 'builder'
# private_key = OpenSSL::PKey::RSA.new(2048)
# public_key = private_key.public_key
# test data from TST
# key = Base64.decode64("NxQLMrUXaSKZYm0Ef3Ab1siRevbOxF5HLpvCKXPdZh4=")