Skip to content

Instantly share code, notes, and snippets.

View coorasse's full-sized avatar
❤️
I will react...but slowly

Alessandro Rodi coorasse

❤️
I will react...but slowly
View GitHub Profile
@coorasse
coorasse / old_files_killer.rb
Last active October 16, 2023 14:25 — forked from pelgrim/old_file_killer.rb
A Ruby on Rails script to delete files older than X days in a given directory.
# A Ruby On Rails script to delete files older than X days in a given directory.
# Quickly written by @coorasse
class FilesCleaner
def self.call(days = 1)
Dir.glob(Rails.root.join('path', 'to', 'folder', '*')).each do |filename|
File.delete(filename) if File.mtime(filename) < days.days.ago
end
end
end
@coorasse
coorasse / raven_initializer.rb
Last active June 8, 2018 07:46
Sending Sentry Raven events asynchronously with ActiveJob
Raven.configure(true) do |config|
config.async = ->(event) { SentryJob.perform_later(event) }
end
module FactoryGirl
module Syntax
module Methods
def find_or_create(name, attributes = {}, &block)
attributes = FactoryGirl.attributes_for(name).merge(attributes)
klass = FactoryGirl.factory_by_name(name).build_class
enums = klass.defined_enums
find_attributes = attributes.clone
find_attributes.keys.each do |key|