Skip to content

Instantly share code, notes, and snippets.

View keleshev's full-sized avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
let distance' ~bound a b =
let n = String.length a and m = String.length b in
assert (n >= m);
if n - m > bound then None else
let fill_bound = min m bound in
let previous = Array.make (m + 1) max_int in
let printf = Format.printf
let fprintf = Format.fprintf
let dprintf = Format.dprintf
let pp_list ~sep pp =
Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf sep) pp
let pp_string ppf string = fprintf ppf "%S" string
let many = [
ast.exe: ast.c
gcc -Werror -Wswitch -Wimplicit-fallthrough ast.c -o ast.exe
clean:
rm -f *.o *.exe *.s a.out
test.s: ast.exe
./ast.exe > test.s
(* https://keleshev.com/advanced-error-handling-in-ocaml *)
let failwithf f = Printf.ksprintf failwith f
(*
t -> bool | int
e -> true | false
| 0 | 1 | 2 | …
(* https://keleshev.com/composable-error-handling-in-ocaml *)
open Printf
let (>>=) = Result.bind
let (let*) = Result.bind
module Exceptions_example (X: sig
type tree
@keleshev
keleshev / cli.ml
Last active November 25, 2020 22:27
open Printf
module CLI = struct
type t = {
verbose: bool;
max_files: int;
dir_to_list: string;
sort_order: [`alpha | `chrono | `owner] option;
args: string list;
}
module Make (X: sig
val block_size: int
val hash: string -> string (* binary, not digest *)
end) = struct
let o_pad = String.make X.block_size '\x5C'
let i_pad = String.make X.block_size '\x36'
let block_xor left right =
let result = Bytes.create X.block_size in
%{
#include <stdio.h>
#include "parser.h"
%}
%%
[ \r\n\t]* { continue; /* Skip blanks. */ }
[0-9]+ { sscanf(yytext, "%d", &yylval->value);
return TOKEN_NUMBER; }
function verboseRegExp(input) {
if (input.raw.length !== 1) {
throw Error('verboseRegExp: interpolation is not supported');
}
let source = input.raw[0];
let regexp = /(?<!\\)\s|[/][/].*|[/][*][\s\S]*[*][/]/g;
let result = source.replace(regexp, '');
.PHONY: build install
ifeq ($(PREFIX),)
INSTALL_FLAGS=
else
INSTALL_FLAGS=--prefix=$(PREFIX)
endif
build:
dune build