Skip to content

Instantly share code, notes, and snippets.

# Sometimes you need to reindex all Rails Models. The reindex() method
# is specific to the SearchKick gem for ElasticSearch, and it only exists
# on ElasticSearch-indexed tables. We do a check for its existence below,
# or it would throw an error.
Dir[Rails.root.join('app/models/*.rb').to_s].each do |filename|
klass = File.basename(filename, '.rb').camelize.constantize
next unless klass.ancestors.include?(ActiveRecord::Base)
next if klass.abstract_class?
@rbrooks
rbrooks / uuid-valid.rb
Created August 12, 2022 20:03
UUID is valid?
class Uuid
class << self
def valid?(uuid: uuid)
uuid =~ /^[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}$/i
end
end
@rbrooks
rbrooks / get-code-owner.sh
Last active October 5, 2022 16:47
Get Code Owner from CODEOWNERS
# Given a path on CODEOWNERS file, returns the username of code owner.
# CODEOWNERS file is either space or Tab-delimated. Hence the 2nd `cut` that slices on Tab.
# That's an actual Tab char between the ' '. It wouldn't accept '\t'.
# Here it is working on a Tab-deleimited line:
grep app/interactors/account/assign_reports_to/ .github/CODEOWNERS | cut -f2- -d ' ' | cut -f2- -d ' '
# @templeman15