Skip to content

Instantly share code, notes, and snippets.

View agibralter's full-sized avatar
:shipit:

Aaron Gibralter agibralter

:shipit:
View GitHub Profile
@agibralter
agibralter / alternative_hack.rb
Created June 21, 2012 05:48
rspec-rails hack for *not* rendering rabl views (no longer necessary as of rabl 0.7.0)
# -*- encoding : utf-8 -*-
# HACK:
# https://github.com/rspec/rspec-rails/issues/565#issuecomment-6474362
module RSpec
module Rails
module ViewRendering
class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
def find_all(*args)
original_path_set.find_all(*args).collect do |template|
@agibralter
agibralter / gist:2933494
Created June 14, 2012 22:49
rabl pagination without object roots?
# @object is a paginated array of questions
collection @object, root: 'collection', object_root: false
attributes :question_text, :created_at, :updated_at
#=> {"collection": [{"question_text": "foo bar", "created_at": "...", "updated_at": "..."}, {...}, {...}]}
# I want this:
#=> {"collection": [{"question_text": "foo bar", "created_at": "...", "updated_at": "..."}, {...}, {...}], "page": 1, "total_pages": 10}
module Helpers
def self.constantize(camel_cased_word)
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
@agibralter
agibralter / image.rb
Created May 16, 2012 02:17
monkey patch for carrierwave to make updates remove previous images when activerecord's identity map is enabled
# -*- encoding : utf-8 -*-
class Image < ActiveRecord::Base
mount_uploader :image, ImageUploader
private
#############################################################################
# CarrierWave's behavior as of 0.5.8 is not compatible with ActiveRecord's
# identity map. This is a monkey patch.
@agibralter
agibralter / gist:2694791
Created May 14, 2012 16:10
has_one through does not provide `create_child` method?
class User < ActiveRecord::Base
has_one :image_assignment, as: :imageable
has_one :image, through: :image_assignment
end
class ImageAssignment < ActiveRecord::Base
belongs_to :image
belongs_to :imageable, polymorphic: true
end
server {
listen 8000;
server_name foo.com;
root /mnt/foo/current/public;
# Allow all assets to be cached by CloudFront and browsers.
add_header Cache-Control public;
# Default expires of 1 hour.
expires 1h;
# haproxy => [a few app servers]
# more specifically:
# haproxy => [nginx => unicorn (502 when busy)]
# Will this try a second app server when the first returns 502?
upstream haproxy {
server 127.0.0.1:85;
server 127.0.0.1:85 backup;
}
upstream haproxy {
server 127.0.0.1:85;
}
server {
server_name example.com;
# ... other stuff (locations, etc.)
location / {
rs_tools 'rightscale_lbtools-0.13.6.tgz'
package 'haproxy' do
action :install
end
service 'haproxy' do
supports(:restart => true, :reload => true)
action [:enable]
end
server {
listen 8000;
server_name <%= @server_name %>;
root <%= @root %>;
# Allow all assets to be cached by CloudFront and browsers.
add_header Cache-Control public;
# Default expires of 1 hour.
expires 1h;