Skip to content

Instantly share code, notes, and snippets.

View ismasan's full-sized avatar

Ismael Celis ismasan

View GitHub Profile
/*
The MIT License (MIT)
Copyright (c) 2014 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
@ismasan
ismasan / sourced_subtasks.rb
Last active November 26, 2025 12:19
Example Sourced flow with subtasks as separate streams
# The main worflow
class MarksFlow < Sourced::Actor
include Sourced::CommandMethods
state do |id|
{ id:, status: :new, tasks: {} }
end
command :start_step1 do |state, cmd|
raise "invalid transition" unless state[:status] == :new
@ismasan
ismasan / exif.rb
Created July 2, 2025 11:01
Ruby extract EXIF data from JPEG images
require 'exif'
require 'geocoder'
require 'time'
def coord(deg, min, sec, _ref)
(deg + (min / 60) + (sec / 3600)).to_f # * (ref == "S" || ref == "W") ? -1 : 1
# %(#{deg.to_i}°#{min.to_i}'#{sec.to_f}"#{ref})
end
def coords(gos)
@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