Skip to content

Instantly share code, notes, and snippets.

View ismasan's full-sized avatar

Ismael Celis ismasan

View GitHub Profile
@ismasan
ismasan / io-watch.rb
Created July 1, 2026 09:51
Reload running script on file changes with io-watch
bundle add io-watch
bundle exec io-watch app config -- bundle exec falcon serve --bind http://localhost:3000 --count 1
@ismasan
ismasan / router.rb
Last active March 19, 2026 23:25
Minimal, Sinatra-style Rack router for small apps and web dashboards
# frozen_string_literal: true
require 'rack'
require 'rack/session/cookie'
module Sourced
module UI
# A minimal Rack-compatible router with a Sinatra-style DSL and
# trie-based dispatch.
#
module Energy
class Comparison
module LoadProfileGapFiller
module_function
# Public API
def fill_gaps(annual_coefficients:, customer_profile:)
# 1. Compute observed totals
observed_total = customer_profile.values.sum
raise "Customer profile is empty" if observed_total.zero?
/*
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