Skip to content

Instantly share code, notes, and snippets.

View c-cube's full-sized avatar

Simon Cruanes c-cube

View GitHub Profile
@c-cube
c-cube / twine.md
Created May 22, 2024 16:50
twine short description

Twine

A data format designed to represent complex OCaml values. The format is designed for 0-copy parsing (or, not much copy anyway) and reasonable compactness.

The encoding relies on a first byte to disambiguate between values. The first byte is a bitfield [kind:4 low:4] where:

  • [kind] is the kind of value (int, float, etc.)
  • [low] is a small integer value whose meaning depends on the kind.
@c-cube
c-cube / dune
Created January 19, 2024 18:13
basic TCP server
(executable
(name basic_tcp_server)
(libraries unix threads))
@c-cube
c-cube / file_server.ml
Created December 11, 2023 15:20
ocaml-protoc service generation example
[@@@ocaml.warning "-27-30-39"]
type file_chunk = {
path : string;
data : bytes;
crc : int32;
}
type file_path = {
path : string;
@c-cube
c-cube / main.rs
Created December 4, 2023 16:13
coc terms in rust
use std::collections::{hash_map::Entry, HashMap};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Term(u32);
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Level(u8);
pub const DUMMY_TERM: Term = Term(u32::MAX);
@c-cube
c-cube / dune
Last active August 10, 2022 00:27
small IO benchmark
(executable
(name main)
(libraries unix))
open Eio.Std
module Buf = Eio.Buf_read
module Flow = Eio.Flow
open struct
let spf = Printf.sprintf
@c-cube
c-cube / output.txt
Last active February 23, 2022 21:53
terms embedded in sqlite
# module Fmt = CCFormat
module DB = Sqlite3_utils
# val db : Sqlite3.db = <abstr>
[…]
Term.all();;
let f = Term.var "f";;
let a = Te rm.var "a";;
let b = Term.var "b";;
@c-cube
c-cube / elfamosocoucou.ts
Created August 31, 2021 20:14
stupid deno irc bot
import {Client} from "https://deno.land/x/irc@v0.5.0/mod.ts";
import { readAll } from "https://deno.land/std@0.106.0/io/mod.ts";
import { cheerio } from "https://deno.land/x/cheerio@1.0.4/mod.ts";
const nick = 'ElFamosoCoucouuu';
const client = new Client({
nick,
channels: ['##arch-fr-free'],
});
@c-cube
c-cube / defer.rs
Created August 5, 2020 19:15
`defer` in pure rust
struct Defer<F: FnMut() + Sized>(F);
macro_rules! defer {
($($f: expr);+) => { let _d = Defer(|| {$($f);+}); }
}
impl<F:FnMut() + Sized> Drop for Defer<F> {
fn drop(&mut self) {
@c-cube
c-cube / dune
Created June 16, 2020 17:39
tiny hashconsing for ocaml
(executable
(name hashcons_test)
(libraries iter containers ppx_deriving.std)
(flags :standard -warn-error -a+8)
(preprocess (pps ppx_deriving.std)))