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 | |
env = | |
File. | |
read('.env'). | |
split("\n"). | |
reject { |str| str =~ /^\s*#/ }. | |
map { |str| str.split('=') }. | |
to_h |
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
# Called by wrapping arbitrary code-to-be-logged in a block. Its return value | |
# will be the return value of whatever's in the block. e.g. | |
# require '/Users/jack/lib/trace_logger' | |
# def my_method | |
# ... | |
# foo = some_buggy_method | |
# ... | |
# 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
Pry.config.commands.command 'trace_point', 'Enables trace point logging' do | |
next unless defined? Rails | |
$logger = Logger.new(Rails.root.join('log', 'trace_point.log')) | |
$trace_point = | |
TracePoint.trace(:call) do |it| | |
next unless it.path[Rails.root.to_s] | |
json = { |
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 Async | |
def initialize | |
self.read_io, self.write_io = IO.pipe | |
raise(LocalJumpError, 'no block given (yield)') unless block_given? | |
self.pid = | |
Process.fork do | |
read_io.close | |
Marshal.dump(yield, write_io) | |
write_io.close |
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 FamilyTree | |
def family_tree | |
{ name => (subclasses.sort_by(&:name).map(&:family_tree).reduce(&:merge) || {}) } | |
end | |
end | |
ActionController::Base.extend(FamilyTree) | |
Rails.application.eager_load! |
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 Analyze | |
def analyze | |
connection.execute("EXPLAIN ANALYZE #{to_sql}").values.flatten | |
end | |
end | |
ActiveRecord::Relation.include(Analyze) |
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 'pstore' | |
module Transporter | |
BUCKET_NAME = 'REPLACE ME' | |
def self.transport!(object_name) | |
s3_object_key = File.join('tmp', "#{object_name}.pstore") | |
pathname = Rails.root.join(s3_object_key) |
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 | |
module Raise | |
def raise(*args) | |
error_class = args.find { |it| it.is_a?(Class) } | |
message = | |
args | |
.find { |it| it.is_a?(String) } | |
.to_s |
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 | |
################################################################################ | |
# class MyClass | |
# include Attributable | |
# attr(:foo) { SecureRandom.uuid } | |
# attr(:bar) { Time.current } | |
# attr(:baz) { MyClass.new } | |
# 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
# frozen_string_literal: true | |
Rails.application.eager_load! | |
class MyFind | |
LIMIT = 1000.0 | |
class << self | |
def call(*args) | |
new(*args).call |
NewerOlder