Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@solnic
solnic / bare-bone-fp-ruby-objects.rb
Created June 3, 2021 21:03
Bare bone, no-library, no-error handling, just the very core idea behind FP objects in Ruby
class CreateStuff
def initialize(stuff_repo)
@stuff_repo = stuff_repo
end
def call(params)
@stuff_repo.create(params)
end
end
@solnic
solnic / .devcontainer.json
Created May 30, 2021 10:58
VS Code configs
{
"name": "app",
"dockerComposeFile": "docker-compose.yml",
"service": "dev",
"workspaceFolder": "/usr/local/src/app",
"extensions": [
"eamodio.gitlens",
"sleistner.vscode-fileutils",
"rebornix.Ruby",
"castwide.solargraph",
@solnic
solnic / tasks.json
Created October 13, 2020 11:29
VS Code tasks.json with custom shell configured
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"shell": {
"executable": "/usr/local/bin/zsh",
"args": ["-l", "-c"]
}
},
require 'logger'
require 'byebug'
require 'dry/monads'
require 'dry/monads/do'
require 'dry/matcher/result_matcher'
module Dry
module Transaction
module Steps
require 'dry/validation'
require 'dry/types'
require 'dry/struct'
module Types
include Dry::Types()
end
class OrderContract < Dry::Validation::Contract
params do
@solnic
solnic / __info.md
Last active November 13, 2018 09:38
rom vs ar benchmark on MRI 2.6.0 with and without jit
git clone https://github.com/rom-rb/rom.git
cd rom/core
bundle install
createdb rom
ruby benchmarks/basic_bench.rb
ruby benchmarks/basic_bench.rb --jit
@solnic
solnic / dry-monitor-example.rb
Created January 5, 2018 12:15
A simple dry-monitor example
require 'dry/monitor/notifications'
module MyApp
def self.notifications
@__notifications__ ||= Dry::Monitor::Notifications.new(:my_app)
end
notifications.register_event("users.created")
class Logger
require 'rom'
require 'rom-repository'
require 'rom-sql'
require 'logger'
config = ROM::Configuration.new(:sql, 'sqlite::memory')
conn = config.gateways[:default].connection
conn.create_table(:users) do
@solnic
solnic / rom-sql-ar-like-polymorphic-associations.rb
Last active May 14, 2021 05:33
[rom-sql] AR-like polymorphic associations (PLEASE DON'T USE IT UNLESS YOU HAVE A LEGACY SCHEMA)
require 'rom-repository'
require 'rom-sql'
require 'logger'
config = ROM::Configuration.new(:sql, 'sqlite::memory')
config.gateways[:default].connection.create_table(:songs) do
primary_key :id
column :title, String
end
********************************************************************************
SEEDING 1000 users
SEEDING 3000 tasks
********************************************************************************
********************************************************************************
INSERTED 1000 users via ROM/Sequel
INSERTED 3000 tasks via ROM/Sequel
INSERTED 9000 tags via ROM/Sequel
********************************************************************************