Skip to content

Instantly share code, notes, and snippets.

Avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
View advanced_error_handling.ml
let failwithf f = Printf.ksprintf failwith f
(*
t -> bool | int
e -> true | false
| 0 | 1 | 2 | …
| e : t
| if e then e else e
View composable_error_handling_in_ocaml.ml
(* 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
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
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
%{
#include <stdio.h>
#include "parser.h"
%}
%%
[ \r\n\t]* { continue; /* Skip blanks. */ }
[0-9]+ { sscanf(yytext, "%d", &yylval->value); return TOKEN_NUMBER; }
"*" { return TOKEN_STAR; }
View verboseRegExp.js
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
.PHONY: build install
ifeq ($(PREFIX),)
INSTALL_FLAGS=
else
INSTALL_FLAGS=--prefix=$(PREFIX)
endif
build:
dune build
View Makefile
.PHONY: always_run
%.exe: %.s always_run
@arm-linux-gnueabihf-gcc -static -o $@ $<
@-qemu-arm-static $@; echo $$?
@rm -f $@
@keleshev
keleshev / ctrl.reg
Created Oct 22, 2019
Windows Registry script for mapping Caps Lock to Ctrl
View ctrl.reg
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
View length.ml
let rec compare_lengths l1 l2 =
match l1, l2 with
| [], [] -> 0
| [], _ -> -1
| _, [] -> 1
| _ :: l1, _ :: l2 -> compare_lengths l1 l2
let rec compare_length_with l n =
match l with