This file contains hidden or 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 ApiPageHelper | |
PAGINATE_OPTIONS = { | |
:default_page_size => 10 | |
} | |
PAGINATE_PARAMS = [ "page", "offset", "size" ] | |
def paginate(coll, options = {}) | |
options = PAGINATE_OPTIONS.merge(options) | |
if params[:page] | |
page = params[:page].to_i | |
size = (params[:size] || options[:default_page_size]).to_i |
This file contains hidden or 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
# Rails 4 | |
require 'action_view/helpers/asset_url_helper' | |
module ActionView | |
module Helpers | |
module AssetUrlHelper | |
def accept_encoding?(encoding) | |
request = self.request if respond_to?(:request) | |
return false unless request |
This file contains hidden or 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
namespace :assets do | |
# uploads assets to s3 under assets/githash, deletes stale assets | |
task :uploadToS3, [ :to ] => :environment do |t, args| | |
from = File.join(Rails.root, 'public/assets') | |
to = args[:to] | |
hash = (`git rev-parse --short HEAD` || "").chomp | |
logger.info("[#{Time.now}] fetching keys from #{to}") | |
existing_objects_hash = {} |
This file contains hidden or 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 OauthController < ApplicationController | |
class ApiOAuthError < StandardError | |
attr_accessor :code, :description, :uri, :state | |
def initialize(code, description, uri = nil, state = nil) | |
@code = code | |
@description = description | |
@uri = uri |
This file contains hidden or 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
CarrierWave.configure do |config| | |
... | |
end | |
Mongoid::Document::ClassMethods.send(:include, DelayedImageProcessing) | |
module CarrierWave | |
# http://sleeplesscoding.blogspot.com/2011/09/recreate-single-version-of.html | |
# Note: is_processing_delayed should be set before calling recreate_version! if the version depends on it. |
This file contains hidden or 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 App | |
def initialize(options) | |
@try = ['', *options.delete(:try)] | |
@static = ::Rack::Static.new( | |
lambda { [404, {}, []] }, | |
options) | |
end | |
def call(env) |
This file contains hidden or 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 Garb | |
module Model | |
def all(profile, options = {}, &block) | |
limit = options.delete(:limit) | |
total = 0 | |
while ((rs = results(profile, options)) && rs.any?) | |
rs.each do |r| | |
yield r | |
total += 1 | |
break if limit and total >= limit |
This file contains hidden or 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
# inspired by https://github.com/rspec/rspec-core/pull/596 | |
require 'rspec/core/formatters/base_formatter' | |
module RSpec | |
module Core | |
module Formatters | |
class FailuresFormatter < BaseFormatter | |
def dump_failures | |
return if failed_examples.empty? |
This file contains hidden or 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
# | |
# Insert an automatic text MIME part into HTML e-mail. | |
# (c) Daniel Doubrovkine, Art.sy 2012 | |
# MIT License | |
# | |
class ActionMailerWithTextPart < ActionMailer::Base | |
def collect_responses_and_parts_order(headers) | |
responses, parts_order = super(headers) | |
html_part = responses.detect { |response| response[:content_type] == "text/html" } |
This file contains hidden or 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 each_by(by, &block) | |
idx = 0 | |
total = 0 | |
set_limit = options[:limit] | |
while ((results = ordered_clone.limit(by).skip(idx)) && results.any?) | |
results.each do |result| | |
return self if set_limit and set_limit >= total |