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 Object | |
| def to_b | |
| self.in?(ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) | |
| end | |
| alias_method :to_bool, :to_b | |
| end |
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 Presenter | |
| class_attribute :presenter_options, instance_accessor: false | |
| self.presenter_options ||= {} | |
| attr_reader :object, :template, :options | |
| def initialize(object, template, options = {}) | |
| @object = object | |
| @template = template | |
| @options = options.reverse_merge(self.class.presenter_options) |
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 Enumerable | |
| def group_by_first | |
| inject({}) do |hash, element| | |
| key = yield(element) | |
| hash[key] ||= element | |
| hash | |
| end | |
| end | |
| def group_by_last(&block) |
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 Gravatar | |
| DEFAULTS = { | |
| default: :not_found, | |
| force_default: false, | |
| size: 100, | |
| secure: false | |
| }.freeze | |
| INSECURE_URL = 'http://www.gravatar.com/avatar/%{hash}' | |
| SECURE_URL = 'https://secure.gravatar.com/avatar/%{hash}' | |
| VALID_OPTIONS = :size, :default, :rating, :secure, :force_default |
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 FontAwesome::Icon < FontAwesome::Iconish | |
| VALID_OPTIONS = :shape, :direction, :outline, :spin, :size, :rotate, :flip, :inverse, :border, :fixed_width | |
| attr_reader :name | |
| def initialize(name, options = {}) | |
| @name = name | |
| @html_options = options.except(*VALID_OPTIONS) | |
| @options = options.slice(*VALID_OPTIONS).reverse_merge( | |
| border: false, |
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
| # Usage: | |
| # | |
| # object = MyObject.new | |
| # object.label = "Some content here..." | |
| # | |
| # object.try_first([:name, :label, :caption]) # => "Some content here..." | |
| # object.try_first(:description) # => nil | |
| class Object | |
| def try_first(method_names, *args, &block) |
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
| window.I18n ||= {} | |
| VALID_OPTIONS = ['scope', 'locale', 'default', 'fallbacks'] | |
| humanizeKeypath = (keypath) -> | |
| console.warn "I18n: no translation found for #{keypath}" | |
| _(keypath.split('.')).chain().last().humanize().value() | |
| sanitizeKeypath = (keypath) -> | |
| str = "" |
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 Object | |
| def is_one_of?(*classes) | |
| classes.any? { |klass| self.is_a?(klass) } | |
| end | |
| end |
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
| # This script is based on the C++ implementation by Sherlog <sherlog@t-online.de> and Jor <flcodec@jors.net> | |
| require 'active_support/all' | |
| require 'singleton' | |
| class FLCodec | |
| include Singleton | |
| class << self | |
| delegate :encode, :decode, :load_file, :decode_file, :encode_file, to: :instance |
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
| require 'active_support/all' | |
| require 'singleton' | |
| class FLHash | |
| include Singleton | |
| FLHASH_POLYNOMIAL = 0xa001; | |
| LOGICAL_BITS = 30; | |
| PHYSICAL_BITS = 32; |