View levenshtein.ml
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
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 |
View pp_list.ml
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
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 = [ |
View Makefile
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
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 |
View advanced_error_handling.ml
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
(* https://keleshev.com/advanced-error-handling-in-ocaml *) | |
let failwithf f = Printf.ksprintf failwith f | |
(* | |
t -> bool | int | |
e -> true | false | |
| 0 | 1 | 2 | … |
View composable_error_handling_in_ocaml.ml
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
(* https://keleshev.com/composable-error-handling-in-ocaml *) | |
open Printf | |
let (>>=) = Result.bind | |
let (let*) = Result.bind | |
module Exceptions_example (X: sig | |
type tree |
View cli.ml
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
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; | |
} |
View HMAC.ml
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 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 |
View Lexer.l
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
%{ | |
#include <stdio.h> | |
#include "parser.h" | |
%} | |
%% | |
[ \r\n\t]* { continue; /* Skip blanks. */ } | |
[0-9]+ { sscanf(yytext, "%d", &yylval->value); | |
return TOKEN_NUMBER; } |
View verboseRegExp.js
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
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, ''); |
View Makefile
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
.PHONY: build install | |
ifeq ($(PREFIX),) | |
INSTALL_FLAGS= | |
else | |
INSTALL_FLAGS=--prefix=$(PREFIX) | |
endif | |
build: | |
dune build |
NewerOlder