View something_lookup.rb
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 SomethingLookup < ApplicationRecord | |
self.table_name = 'something_lookups' | |
belongs_to :something, polymorphic: true | |
def self.load_schema! | |
# rubocop:disable Naming/MemoizedInstanceVariableName | |
@columns_hash ||= {} | |
# rubocop:enable Naming/MemoizedInstanceVariableName | |
end |
View custom_json_formatter.rb
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
# frozen_string_literal: true | |
require "rspec/core/formatters/base_text_formatter" | |
class CustomJsonFormatter | |
# This registers the notifications this formatter supports, and tells | |
# us that this was written against the RSpec 3.x formatter API. | |
RSpec::Core::Formatters.register self, :example_started | |
def initialize(output) |
View initials_avatar.rb
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 "mini_magick" | |
# require "initials_avatar" | |
# InitialsAvatar.new(initials: "PC").avatar_path | |
class InitialsAvatar | |
BACKGROUND_COLORS = [ | |
"#C53030", "#9C4221", "#975A16", "#2F855A", "#2C7A7B", "#2B6CB0", "#434190", "#553C9A", "#97266D" | |
] | |
def initialize(initials:) |
View arel_benchmark.rb
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 'benchmark/ips' | |
ActiveRecord::Base.logger = nil | |
def pagy_count(collection) | |
(c = collection.count(:all)).is_a?(Hash) ? c.size : c | |
end | |
def pagy_count2(collection) | |
result = collection.count(:all) |
View time_zone_enum_type.rb
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
Types::TimeZoneEnumType = GraphQL::EnumType.define do | |
name "TimeZoneEnum" | |
ActiveSupport::TimeZone.all.uniq! {|tz| tz.tzinfo.identifier }.map { |tz| | |
symbol = tz.tzinfo.identifier.gsub(/[^_a-zA-Z0-9]/, '_').squeeze('_').upcase! | |
value("TZ_#{symbol}", tz.tzinfo.identifier, value: tz.name) | |
} | |
end |
View game.rb
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 'drawille' | |
class Ceil < Struct.new(:x, :y, :state) | |
def alive? | |
state == 1 | |
end | |
end | |