This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# | |
# Run parallel commands and fail if any of them fails. | |
# | |
set -eu | |
pids=() | |
for x in 1 2 3; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Created by Martin Jambon and placed in the Public Domain on June 1, 2019. | |
Print a tree or a DAG as tree, similarly to the 'tree' command. | |
*) | |
open Printf | |
let rec iter f = function | |
| [] -> () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Generic = struct | |
(* generic expr type used for matching *) | |
type expr = | |
| A | |
| B of expr * expr [@lang a] | |
| C of expr [@lang b c] | |
| Unsupported of string [@fallback] | |
end | |
(*** Generated from the above ***) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Interactive approach | |
-------------------- | |
You can copy-paste code into `utop`, provided you load the lwt.unix | |
package: | |
#use "topfind";; | |
#thread;; (* only needed in the plain `ocaml` toplevel, not in `utop`. *) | |
#require "lwt.unix";; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type kind = [ | |
| Root (* class name conflict *) | |
| Thing of int | |
| WOW <json name="wow"> | |
| Amaze <json name="!!!"> of string list | |
] | |
type root = { | |
id: string; | |
await: bool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
import json | |
# type t = A | B of int | |
class T: | |
pass | |
class T_A(T): | |
def __repr__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Arithmetic with Binary numbers (unsigned, arbitrary precision!) *) | |
type digit = Zero | One | |
type t = digit list | |
let rec eq a b = | |
match a, b with | |
| [], [] -> true | |
| da :: a, db :: b when da = db -> eq a b | |
| _ -> false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Evaluate the performance of a stack-safe implementation of List.map. | |
Run with: | |
ocamlopt -o list_map unix.cmxa list_map.ml | |
./list_map | |
*) | |
open Printf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Extra string operations for OCaml | |
Conventions: | |
- all operations are failsafe: no exceptions are raised | |
- negative index i is equivalent to positive index (length - i) | |
- from/until indicate inclusive ranges like in 'for' loops | |
(for i = from to until do ... done) | |
- does not replicate or override the standard String module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# | |
# Remove a single git commit from history. | |
# | |
set -eu | |
usage() { | |
cat <<EOF | |
Usage: $0 <commit ID> |
NewerOlder