Skip to content

Instantly share code, notes, and snippets.

View ismasan's full-sized avatar

Ismael Celis ismasan

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSON form</title>
<script>
function jsonForm(form) {
form.addEventListener('submit', function(event) {
event.preventDefault();
var data = {};
@ismasan
ismasan / Gemfile
Last active March 6, 2025 21:55
Demo progress bar using Ruby, Rack and Datastar
# frozen_string_literal: true
source "https://rubygems.org"
gem 'puma'
gem 'datastar'
require 'thread'
def work(queue, &block)
Thread.new do
block.call(queue)
queue << :done
rescue StandardError => e
queue << e
end
end
@ismasan
ismasan / loans.rb
Created January 16, 2025 11:46
Parse and validate loans CSV using Plumb
# Adapter from https://gist.github.com/thedumbtechguy/9e6d9abfbd0393804f185118196ea678
require 'csv'
require 'plumb'
require 'date'
require 'debug'
require 'active_support/core_ext/string'
module Types
include Plumb::Types
@ismasan
ismasan / Claude.mkd
Created January 10, 2025 14:53
Discord DDD-CQRS-ES aggregate boundaries discussion
  1. The discussion started with a question about when to use strong consistency (aggregates) versus eventual consistency, using a dinner reservation system as an example.

  2. Main insights about consistency and design:

  • Consistency boundaries should generally be kept small, ideally supporting single-concurrent-user operations
  • Eventual consistency can sometimes provide better business solutions, allowing for compensatory measures (like waitlists or discounts) rather than simple rejections
  • Consistency boundaries are discovered rather than defined, based on what decisions need to be made together
  1. Key principles about aggregates:
@ismasan
ismasan / job_queue.sql
Created December 5, 2024 14:24
Postgres-based job queue using FOR UPDATE SKIP LOCKED
WITH next_job AS (
SELECT
id,
type,
payload,
created_at
FROM jobs
WHERE created_at <= ?
ORDER BY created_at
FOR UPDATE SKIP LOCKED
@ismasan
ismasan / enumerator_io.rb
Last active August 22, 2024 10:50
Turn a Ruby Enumerator into an IO-like object
# frozen_string_literal: true
# Wraps an enumerator that yields chunks of content into an IO object. It
# The IO is NOT rewindable.
# implements some essential IO methods:
#
# * IO#read
# * IO#readpartial
# * IO#gets
# * IO#size
@ismasan
ismasan / .nvimrc
Created June 4, 2024 17:25
NeoVim: run Rubocop on buffer save
" Run Rubocop on save
" Requires vim.o.xrc = true in NeoVim config
lua << EOF
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = "*",
callback = function()
local file = vim.fn.expand('%:p')
vim.fn.system('your-command ' .. file)
end,
})
@ismasan
ismasan / params_validator_step.rb
Last active March 24, 2024 22:08
Input validator step using Parametric
# https://github.com/ismasan/parametric
require 'parametric'
class InputValidator
def initialize(&block)
@schema = Parametric::Schema.new(&block)
end
# @param result [Result]
@ismasan
ismasan / concurrent_processing.rb
Last active August 27, 2024 21:59
Practical Railway-oriented Pipeline for Ruby
# A Pipeline extension to process steps concurrently
# Example
# class ConcurrentPipeline < Pipeline
# include ConcurrentProcessing
# end
#
# MyPipeline = ConcurrentPipeline.new do |pl|
# pl.step ValidateInput
#
# # These steps run concurrently