Skip to content

Instantly share code, notes, and snippets.

@zbroyar
zbroyar / cohttp_tls.ml
Created June 3, 2024 22:58
Auth your cohttp request with x509 certificate
(* ocamlfind ocamlopt -thread -package lwt,tls,x509,cohttp,cohttp-lwt,lwt_ppx,cohttp-lwt-unix -linkpkg cohttp_tls.ml *)
open Lwt
open Printf
open Cohttp
open Cohttp_lwt_unix
let ca_file = "ca-chain.crt"
let cert_file = "your.crt"
let key_file = "your_private.key"

Приклади діаграм в Org-файлах.

@zbroyar
zbroyar / dot.emacs.el
Created December 3, 2021 11:37
My .emacs
;;
;; Paths for Emacs itself
;;
;(setq merlin-debug 'message)
(setq
opam-prefix
(substring
(shell-command-to-string "/usr/local/bin/opam config var prefix 2>/dev/null") 0 -1))
(setq opam-bin (concat opam-prefix "/bin"))
@zbroyar
zbroyar / mmap.ml
Last active January 3, 2019 21:29
Simple wrapper around Unix.mmap. Mainly used to work with matrices.
open Unix
open Hashtbl
open Bigarray
open Bigarray.Array2
module type Params = sig
type a
type b
type c
val kind : (a,b) Bigarray.kind
@zbroyar
zbroyar / wal.ml
Created April 21, 2017 01:05
Naїve Command Write-Ahead Log implementation
open Unix
open Printf
exception EOF
exception WriteError
module BE = EndianString.BigEndian
module M = Map.Make(struct type t = int let compare = compare end)
type entry = Todo of (int * string) | Done of int
#use "topfind"
#require "unix"
open Printf
let _ =
let ts = Unix.gettimeofday () in
let str = sprintf "%0.5f" ts in
printf "%b\n" (ts = float_of_string str);
let str = sprintf "%0.6f" ts in
@zbroyar
zbroyar / ocaml.el
Last active February 17, 2016 08:48
OCaml editing mode, require ocp-indent to work properly
;;
;; OCaml mode
;;
(setq
opam-share
(substring
(shell-command-to-string "opam config var share 2>/dev/null") 0 -1))
(setq load-path
@zbroyar
zbroyar / sockserv.ml
Created February 2, 2016 13:20
Socket server over select with requests count and history
open Unix
open Printf
module SM = Map.Make(struct type t = Unix.file_descr let compare = compare end)
type context = {
buf : string;
smap : socket_context SM.t;
count : int;
history : string list;
@zbroyar
zbroyar / sum_type.ml
Created January 22, 2016 21:47
Sum type example
(*ocamlfind ocamlopt -o sum_type -package xml-light sum_type.ml -linkpkg*)
open Printf
module X = Xml
type amazon_response_content = Xml of Xml.xml | Raw of string
let dump_response_content =
function
| Xml xml ->
@zbroyar
zbroyar / fcm.ml
Created January 10, 2014 20:58
Використання поліморфних структур разом з першокласними модулями дозволяють інкапсулювати варіанти реалізації. У прикладі нижче модулі TI та TF будуть реалізовані окремими файлами.
open Printf
module type T = sig
type t
val init : unit -> t
val get_msg : t -> t * string
end
type 'a global_context = {
g : float; (* global part of context *)