Skip to content

Instantly share code, notes, and snippets.

@grodowski
grodowski / schema_validations_extractor.rake
Last active January 27, 2021 18:37
Codegen script to extract explicit ActiveModel validators from SchemaValidations::ActiveRecord
# frozen_string_literal: true
namespace :validations do
desc 'List all model validations defined by schema_validations'
task list: :environment do
LIST_OUTPUT = STDOUT
VALIDATIONS = Hash.new
# monkey patch SchemaValidations to extract validation metadata instead of applying them
# gem source: lib/schema_validations/active_record/validations.rb
@grodowski
grodowski / take_1.rb
Last active August 18, 2024 16:14
Shopify package matcher
# Package matcher
# Description
# As the owner of an online store, you need to fulfill orders everyday. To optimize the packing of each order, you decide to write an algorithm to match boxes and items based on their respective sizes.
# You have access to the following two boxes:
# - A medium box (identifier: M)
# - A large box (identifier: L)
# When possible, you should try to fit multiple items in the same box but boxes can only contain one type of product.
# This is the list of items you sell along with associated boxes:
# - Camera (identifier: Cam): one can fit in a medium box, and up to two can fit in a large box