Skip to content

Instantly share code, notes, and snippets.

View craigfe's full-sized avatar

Craig Ferguson craigfe

View GitHub Profile
@craigfe
craigfe / dune-expand.sh
Created February 25, 2022 11:25
Simple script for expanding OCaml PPXes (in a readable way)
#!/usr/bin/env sh
# A .merlin must be present nearby the file.
# With dune it can be generated by calling `dune build @check`.
FILE="$1"
dune build @check
ocamlmerlin single dump -what ppxed-source -filename "$FILE" < "$FILE" | jq -r '.value' | ocamlformat --name="$FILE" -
(** [sort_corresponding_arrays cmp xs ys] is equivalent to
[Stdlib.Array.sort xs] but also applies the same reordering of indices to
the elements of [ys], ensuring that all pairs of elements that share an
index {i before} the sort still do so afterwards. Equivalent to:
{[
let a3 = Array.combine xs ys in
Array.sort (fun (x1, _) (x2, _) -> cmp x1 x2);
Array.iteri (fun i (x, y) ->
xs.(i) <- x;
(* Example due to @emillon. Mistakes my own. *)
type conf = { precision : int }
effect Get_conf : conf
let with_conf (conf: conf) ~f =
try f () with effect Get_conf k -> continue k conf
let get_precision () = (perform Get_conf).precision
diff --git a/bin/dune b/bin/dune
index b96f1a0..2e2b973 100644
--- a/bin/dune
+++ b/bin/dune
@@ -8,7 +8,7 @@
(public_name ocaml-mdx)
(package mdx)
(modules :standard \ cli)
- (libraries cli mdx))
+ (libraries cli mdx fmt))
@craigfe
craigfe / welford.ml
Created June 15, 2020 12:35
Welford algorithm for online computation of mean and variance statistics.
(* Welford algorithm for online computation of mean and variance statistics. *)
module Moments : sig
type t
val empty : t
val add : t -> float -> t
type stats = {
count : int;
[ERROR] HTTP.GIT 5 Basic operations on watches.
[OK] HTTP.GIT 6 Basic merge operations.
[OK] PACK 11 Private node manipulation.ices.
[OK] HTTP.GIT 7 Basic operations on slices.
[OK] HTTP.FS 2 Basic operations on commits.
[ERROR] HTTP.GIT 8 Tree caches and hashconsing..
[OK] PACK 12 High-level store operations.
[OK] HTTP.FS 3 Basic operations on branches.
[ERROR] HTTP.GIT 9 Complex histories.d exceptions.
[OK] HTTP.GIT 10 Empty stores.
This file has been truncated, but you can view the full file.
test alias test/irmin-http/runtest (exit 2)
(cd _build/default && test/irmin-http/test.exe -v)
pwd=/home/craigfe/t/irmin/_build/default
Executing: "cd ../.. && _build/default/test/irmin-http/test.exe serve 0 &"
+33897us application [DEBUG] waiting for the server to start...
S+37349us application [DEBUG] pwd: /home/craigfe/t/irmin
S+37383us application [DEBUG] Got server: MEM, root=
S+37929us application [DEBUG] write PID 23579 in /tmp/irmin-http-test.pid
+134073us application [DEBUG] read PID 23579 fomr /tmp/irmin-http-test.pid
+134105us irmin.tree [INFO] Tree.Cache.clear