Skip to content

Instantly share code, notes, and snippets.

View keleshev's full-sized avatar
🐪

Vladimir Keleshev keleshev

🐪
View GitHub Profile
(* 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
from time import sleep
from flask import Flask, Response, request
app = Flask('hello')
@app.route('/')
def hello():
@keleshev
keleshev / fold.ml
Last active October 15, 2020 16:31
let (=>) left right = print_char (if left = right then '.' else 'F')
open Printf
let id x = x
let const x = fun _ -> x
let sum = List.fold_left (+) 0
let (>>) f g x = g (f x)
let () =
@keleshev
keleshev / xml.ml
Last active April 16, 2020 08:21
Simple XML pretty-printing in OCaml using Format module
#! /usr/bin/env ocaml
let fprintf = Format.fprintf
type t =
| Tag of {name: string; attributes: (string * string) list; body: t list}
| String of string
let format_attribute f (key, value) = fprintf f " %s=\"%s\"" key value
.PHONY: build install
ifeq ($(PREFIX),)
INSTALL_FLAGS=
else
INSTALL_FLAGS=--prefix=$(PREFIX)
endif
build:
dune build
.PHONY: always_run
%.exe: %.s always_run
@arm-linux-gnueabihf-gcc -static -o $@ $<
@-qemu-arm-static $@; echo $$?
@rm -f $@
@keleshev
keleshev / ctrl.reg
Created October 22, 2019 07:16
Windows Registry script for mapping Caps Lock to Ctrl
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