Skip to content

Instantly share code, notes, and snippets.

View ysbaddaden's full-sized avatar

Julien Portalier ysbaddaden

View GitHub Profile
@ysbaddaden
ysbaddaden / stw.cr
Last active June 19, 2024 11:17
stw.cr
class STW
def initialize
@running = true
@started = Atomic(Int32).new(0)
@count = Atomic(Int32).new(0)
@threads = [] of Thread
end
def start_thread
@threads << Thread.new do
@ysbaddaden
ysbaddaden / gen_search_json.cr
Created June 10, 2024 09:06
crystal docs: gen search.json from index.json
require "json"
def cleanup_constant(type : JSON::Any)
type.as_h.select! do |key, _|
{
"id",
"name",
"value",
"doc",
"summary",
require "c/sys/time"
lib LibC
KQUEUE_CLOEXEC = O_CLOEXEC
# todo: constants
# EV_ADD = ...
# EV_ENABLE = ...
# ...
lib LibC
EPOLL_CLOEXEC = 0o2000000
EPOLLIN = 0x001_u32
EPOLLPRI = 0x002_u32
EPOLLOUT = 0x004_u32
EPOLLRDNORM = 0x040_u32
EPOLLRDBAND = 0x080_u32
EPOLLWRNORM = 0x100_u32
EPOLLWRBAND = 0x200_u32
@ysbaddaden
ysbaddaden / abi.cr
Last active May 24, 2024 12:55
Parse LLVMDataLayout string + alignof, sizeof & offsetof ints, floats & aggregates + ABI for Crystal::Type(s)
require "./data_layout"
# I must require the WHOLE COMPILER just to load crystal/types, and then it
# takes as long as compiling the compiler to compile just this file and to do
# nothing.
require "compiler/requires"
class Crystal::ABI
@nil_type : DataLayout::Aggregate?
@proc_type : DataLayout::Aggregate?
@ysbaddaden
ysbaddaden / bus.cr
Last active September 21, 2023 22:24
A GenServer in Crystal
class Bus(A, M)
include GenServer
def initialize
@listeners = [] of A
end
# public interface
def subscribe(listener : A) : Nil
@ysbaddaden
ysbaddaden / stop-the-world.c
Last active June 21, 2022 14:12
Stop the World in C
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ucontext.h>
@ysbaddaden
ysbaddaden / rebar2_rewrite_github_git_protocol_to_https.patch
Created April 5, 2022 16:58
Fix for Rebar2 that transparently rewrites git://github.com into https://github.com (useful to bootstrap old legacy Erlang projects)
commit 921120d96c175d997d815805bdeced4b4fbb0cfa (HEAD -> fix/transparently-rewrite-unauthenticated-github-url-to-https)
Author: Julien Portalier <julien@portalier.com>
Date: Tue Apr 5 18:37:34 2022 +0200
Fix: rewrite GitHub unauthenticated URL
Rewrites the URL on-the-fly and transparently from git://github.com
to https://github.com because GitHub no longer supports the
unauthenticated git protocol anymore.
@ysbaddaden
ysbaddaden / earl_scheduler.rb
Last active January 8, 2021 09:34
A basic Scheduler for Ruby 3, leveraging the NIO and timers gems
# frozen_string_literal: true
require "fiber"
require "nio"
require "timers"
module Earl
class Scheduler
def initialize
@selector = NIO::Selector.new
@ysbaddaden
ysbaddaden / jwt
Created June 19, 2019 14:42
WINDEV: create JWT with HS256 signature
// Crée un JSON Web Token pour l'extranet, signé via HMAC SHA 256, permettant
// d'identifier le CaC sur l'extranet comme utilisateur ayant accès à toutes les
// données.
PROCÉDURE CréerTokenExtranet()
// header du token (algorithm, type) :
taHeader est un tableau associatif de chaînes
taHeader["alg"] = "HS256"
taHeader["typ"] = "JWT"