Skip to content

Instantly share code, notes, and snippets.

@camlspotter
camlspotter / bsky_lexicon.ml
Created July 12, 2023 02:34
BlueSky Lexicon type defs in OCaml
type unknown
type blob
type cid_link
type 'a nullable = 'a option
type actor_adultContentPref = {
enabled: bool }
@camlspotter
camlspotter / bluesky.sh
Created July 4, 2023 02:39
Access BlueSky
# You need
#
# - curl
# - jq
# Your handle, ex xxxx.bsky.social or your custom handle like dailambda.jp.
# No '@' mark.
HANDLE=hogehoge.bsky.social
# Your App password: Settings > App password > Add App password
(* a + b (mod m) *)
let addmod a b m =
assert (0 <= a && 0 <= b);
let a = a mod m in
let b = b mod m in
if a < m - b then
(* Case A: a + b < m *)
a + b
else
(* Case B: a + b >= m
@camlspotter
camlspotter / lablgtk_resize.ml
Created June 29, 2022 02:31
Small program to detect window resize
let () =
ignore @@ GMain.Main.init ();
let window = GWindow.window ~width:100 ~height:100 () in
ignore @@ window#event#connect#configure ~callback:(fun ev ->
let open GdkEvent.Configure in
prerr_endline (Printf.sprintf "Configure %dx%d+%d+%d"
(width ev)
(height ev)
(x ev)
(y ev));
@camlspotter
camlspotter / haha.md
Last active July 4, 2018 09:44
OCaml zippy tutorial in Japanese
hahaha
(** Generation of typerep methods for tag-checking *)
(* XXX simply moved to sig.ml ? *)
open Typerep_lib.Std
module Sig = struct
open Sig
type res = [%import: Sig.res]
and ftypekind = [%import: Sig.ftypekind]
match x with
| OpeExp (e1, op, e2) ->
begin match op with
| Plus -> ...
| Minus -> ...
end
| Root (e1, e2) -> ...
(let
((Fib/0
(let*
((fib/1008
(lambda (n/1009)
(if (not (equal n/1009 0))
(if (not(equal n/1009 1))
(+ (funcall fib/1008 (- n/1009 1)) (funcall fib/1008 (- n/1009 2)))
1)
0))))
@camlspotter
camlspotter / gist:6c8a70ddd2b5fce04d6a
Last active October 14, 2015 15:53
How fib is compiled in OCaml, and a hand compilation of it to Elisp
let rec fib = function | 0 -> 0 | 1 -> 1 | n -> fib (n-1) + fib (n-2)
(* Output of -dlambda *)
(setglobal Fib!
(letrec
(fib/1008
(function n/1009
(if (!= n/1009 0)
(if (!= n/1009 1)
@camlspotter
camlspotter / gist:a8952a5fdf7298c59b9b
Last active October 2, 2015 17:54
hov_box vs box
open Format
let rec hovb ppf = function
| 0 -> ()
| n ->
fprintf ppf "(@[<hov>-----------------------------------%03d@," n;
hovb ppf (n-1);
fprintf ppf "@])"
let rec b ppf = function