This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written by https://github.com/macreery (c) Art.sy, 2012, MIT License | |
module ApiConditionalGetHelper | |
# Borrows generously from http://themomorohoax.com/2009/01/07/using-stale-with-rails-to-return-304-not-modified | |
# See also RFC 2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.4 | |
# for explanation of how If-Modified-Since and If-None-Match request headers are handled. | |
def fresh?(metadata = {}) | |
self.last_modified = metadata[:last_modified] | |
self.etag = metadata[:etag] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written (mostly) by https://github.com/macreery (c) Art.sy, 2012, MIT License | |
module ApiCache | |
# cache wrapper, yields an executable block | |
def self.cache(options = {}) | |
# options set default expiration time and force a miss if specified | |
options = standardize_options(options) | |
cache_options = options[:cache_options] || {} | |
cache_options[:expires_in] = 24.hours if not cache_options[:expires_in] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// from http://waffle.codeplex.com/workitem/10034 | |
// | |
package waffle.servlet.spi; | |
import java.io.IOException; | |
import java.security.Principal; | |
import java.util.Date; | |
import java.util.Enumeration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView | |
module Helpers | |
module DateHelper | |
# returns a date range in English | |
# July 3-5, both days are the same month | |
# July 3 - August 5, days are different months | |
# December 20, 2010 - January 10, 2012, days are over a year apart | |
def date_range_in_words(start_date, end_date) | |
# convert to date | |
start_date = start_date.to_date if start_date && start_date.respond_to?(:to_date) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mongoid | |
class Criteria | |
def sample(n = 1) | |
indexes = (0..self.count-1).sort_by{ rand }.slice(0,n).collect! | |
if n == 1 | |
return self.skip(indexes.first).first | |
else | |
return indexes.map{ |index| self.skip(index).first } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DelayedJobObserver < Mongoid::Observer | |
observe Delayed::Job | |
class << self | |
attr_accessor :total_processed | |
attr_accessor :total_errors | |
attr_accessor :enabled | |
def enabled? | |
!! DelayedJobObserver.enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mongoid/collection' | |
module Mongoid | |
class Collection | |
alias_method :_update, :update | |
def update(selector, document, options = {}) | |
document.deep_fetch("_id").each do |value| | |
if value.nil? | |
Rails.logger.error "Invalid nil _id in #{document}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
sessions: | |
default: | |
database: mydb_development | |
hosts: | |
- localhost:27017 | |
options: | |
safe: true | |
test: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mongoid | |
module Slug | |
class UniqueSlug | |
alias_method :_find_unique, :find_unique | |
# by default Mongoid::Slug returns id-1 if you try to get a slug from the model's ID | |
def find_unique attempt = nil | |
if ! attempt | |
candidate = url_builder.call(model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here are the settings that are common to all environments | |
common: &default_settings | |
# ============================== LICENSE KEY =============================== | |
# You must specify the license key associated with your New Relic | |
# account. This key binds your Agent's data to your account in the | |
# New Relic service. | |
license_key: '<%= ENV["NEW_RELIC_LICENSE_KEY"] %>' | |
# Agent Enabled (Rails Only) |