Skip to content

Instantly share code, notes, and snippets.

View ismasan's full-sized avatar

Ismael Celis ismasan

View GitHub Profile
@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'
@ismasan
ismasan / sse.go
Last active February 27, 2025 00:15
Example SSE server in Golang
// Copyright (c) 2017 Ismael Celis
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
<!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 = {};
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 / validations_for.rb
Created June 26, 2019 09:22
Declarative AM validations depending on arbitrary attributes
# class Page
# include ValidationsFor
#
# validations_for page_type: 'offer' do
# validates :amount, presence: true
# end
#
# validations_for page_type: 'page' do
# validates :title, presence: true
# end
@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
@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