Skip to content

Instantly share code, notes, and snippets.

@dbuenzli
dbuenzli / work_queue.ml
Created Oct 30, 2022
Webworker work queue
View work_queue.ml
(*---------------------------------------------------------------------------
Copyright (c) 2022 The brr programmers. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
---------------------------------------------------------------------------*)
open Brr
open Brr_webworkers
open Brr_io
module type WORK = sig
@dbuenzli
dbuenzli / buffer_add_json.ml
Created Oct 11, 2022
Buffer.add_json function
View buffer_add_json.ml
(* Simple Buffer.add_json function. *)
type json =
[ `Null | `Bool of bool | `Float of float | `String of string
| `Array of json list | `Object of (string * json) list ]
let rec buffer_add_json b = function
| `Null -> Buffer.add_string b "null"
| `Bool bool -> Buffer.add_string b (if bool then "true" else "false")
| `Float f -> Buffer.add_string b (Printf.sprintf "%.16g" f)
@dbuenzli
dbuenzli / trojansource.ml
Last active Nov 8, 2021
Trojan source for OCaml
View trojansource.ml
(* OCaml Port of fig. 5-6 of https://trojansource.codes/trojan-source.pdf *)
let access_level = "user"
let main () =
if access_level <> "user‮⁦ (* Check if admin *)⁩⁦" then
Printf.printf "You are an admin.\n"
let () = main ()
View uunf_data.ml
(*---------------------------------------------------------------------------
Copyright (c) 2015 The uunf programmers. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
---------------------------------------------------------------------------*)
(* WARNING do not edit. This file was automatically generated. *)
open Uunf_tmapbool;;
let v000 = snil
View opam #4445
> opam switch create 4.06.0 --debug-level=3
00:00.003 GSTATE LOAD-GLOBAL-STATE @ /Users/dbuenzli/.opam
00:00.004 SYSTEM LOCK /Users/dbuenzli/.opam/lock (none => read)
00:00.004 SYSTEM LOCK /Users/dbuenzli/.opam/config.lock (none => write)
00:00.004 FILE(config) Read ~/.opam/config in 0.000s
00:00.005 RSTATE LOAD-REPOSITORY-STATE @ /Users/dbuenzli/.opam
00:00.008 FILE(repos-config) Read ~/.opam/repo/repos-config in 0.003s
00:00.008 SYSTEM LOCK /Users/dbuenzli/.opam/repo/state.cache (none => read)
00:00.108 RSTATE Loaded /Users/dbuenzli/.opam/repo/state.cache in 0.099s
00:00.264 SYSTEM LOCK /Users/dbuenzli/.opam/repo/state.cache (read => none)
@dbuenzli
dbuenzli / landmark.md
Created Oct 22, 2020
How to landmark
View landmark.md
echo 'true : package(landmarks.ppx,landmarks)' >> _tags
export OCAML_LANDMARK=auto
topkg build 

topkg run exe

@dbuenzli
dbuenzli / ocaml-deprecate.md
Last active Nov 11, 2019
Deprecation procedure for OCaml
View ocaml-deprecate.md

Deprecation procedure for OCaml

In order to deprecate a feature from the OCaml system the following steps are taken:

  1. Introduce a workaround for the deprecation (if needed). Document the workaround, see below.
  2. When Debian stable has the version in which the workaround was introduced, start deprecating the feature with a visible warning
@dbuenzli
dbuenzli / readmeta.ml
Last active Oct 15, 2019
Read cma/cmxa/cmxs link metadata
View readmeta.ml
(*
ocamlfind ocamlopt -o readmeta -linkpkg \
-package dynlink,compiler-libs.optcomp,compiler-libs.bytecomp readmeta.ml
*)
let read_cma ic =
let lib =
let toc_pos = input_binary_int ic in
seek_in ic toc_pos;
(input_value ic : Cmo_format.library)
@dbuenzli
dbuenzli / ocamlib.md
Last active Aug 22, 2022
OCaml compiler support for library linking
@dbuenzli
dbuenzli / ocaml-emacs.md
Last active Aug 11, 2022
Emacs setup for ocaml
View ocaml-emacs.md

Install the following opam packages:

opam install caml-mode merlin ocp-indent

Tweak your .emacs file with some or all of the following:

; shift tab to complete
(global-set-key (kbd "S-<tab>") 'company-complete)