Skip to content

Instantly share code, notes, and snippets.

@stevenhaddox
stevenhaddox / Image.rb
Created May 29, 2009 19:47
Paperclip Polymorphism Issue
class Image < ActiveRecord::Base
# associations
belongs_to :image_attachment, :polymorphic => true
# virtual attributes
attr_accessor :image_styles
def after_initialize
self.image_styles=(set_image_styles)
# set an obvious fake to test param passing works
# File permissions
run "chmod 755 ."
%w(public log tmp).each do |dir|
run "chmod -R 755 #{dir}"
end
# Remove unnecessary files
%w(README public/index.html public/favicon.ico public/robots.txt).each do |file|
run "rm #{file}"
module Notable
def self.included(base)
base.has_many :notes, :as => :notable
base.accepts_nested_attributes_for :notes
end
end
class User < ActiveRecord::Base
include Notable
end
export RUBY_HEAP_MIN_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=250000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=100000000
export RUBY_HEAP_FREE_MIN=1000000
require "rubygems"
require 'directory_watcher'
commands = [
{ :tell => "Firefox", :to => "activate" },
{ :tell => "System Events", :to => "keystroke \"1\" using command down" },
{ :tell => "System Events", :to => "keystroke \"r\" using command down" },
{ :tell => "TextMate", :to => "activate" }
]
This is an example of using RVM's Project .rvmrc file
to have it automatically bootstrap your environment, including bundler.
This could be further expanded to do anything you require :)
The important thing to remember is that the purpose of these files is
to allow you to very easily have your 'project context' (aka 'environment')
loaded automatically for you when you enter the project in the shell (cd).
def _authenticate_oauth_echo
require 'httparty'
# header auth only for now; also lock down the auth provider endpoint so we can't spoof
if(request.env["HTTP_X_AUTH_SERVICE_PROVIDER"] != 'https://api.twitter.com/1/account/verify_credentials.json' || request.env["HTTP_X_AUTH_SERVICE_PROVIDER"].blank?)
return false
else
auth_service_provider = request.env["HTTP_X_AUTH_SERVICE_PROVIDER"]
verify_credentials_authorization = request.env["HTTP_X_VERIFY_CREDENTIALS_AUTHORIZATION"]
end
class Boot
def run
load_initializer
extend_environment
Rails::Initializer.run(:set_load_path)
end
def extend_environment
Rails::Initializer.class_eval do
old_load = instance_method(:load_environment)
@stevenhaddox
stevenhaddox / code_setup.md
Created June 30, 2011 08:32
undefined method `[]' for nil:NilClass in OmniAuth Custom Strategy

RESOLVED

Figured out this error, please DISREGARD! We were forgetting to redirect to the callback_url at the end of the request_phase as we thought that was handled by OmniAuth (oops...)

To replicate this error you should be able to do the following:

@stevenhaddox
stevenhaddox / server_certificates_to_pem.md
Last active December 14, 2023 05:42
Convert .crt & .key files into .pem file for HTTParty

Two ways to do it, but only worked for me so I'll put it first and the second for reference:

$ openssl pkcs12 -export -in hostname.crt -inkey hostname.key -out hostname.p12
$ openssl pkcs12 -in hostname.p12 -nodes -out hostname.pem

Other options for this method in comments below:

# Note, the -certfile root.crt appends all CA certs to the export, I've never needed these so it's optional for my personal steps
$ openssl pkcs12 -export -in hostname.crt -inkey hostname.key -certfile root.crt -out hostname.p12

Note, I've always had my hostname.crt as part of my .pem, so I keep my certs but apparently you may not have to, hence the nocerts flag being an extra option in this sample