Skip to content

Instantly share code, notes, and snippets.

View Bannerets's full-sized avatar
🌺
h

Bannerets

🌺
h
  • ʻOumuamua
View GitHub Profile
@Bannerets
Bannerets / glicko2.ml
Last active February 17, 2024 20:24
Glicko-2 implementation in OCaml
(* dump of the unused code written in dec 2022, not thoroughly tested *)
open! Base
(* Implementation of the Glicko-2 algorithm: http://www.glicko.net/glicko/glicko2.pdf
Written with inspirations from
https://github.com/lichess-org/lila/blob/668814b/modules/rating/src/main/Glicko.scala
and https://github.com/TaylorP/Glicko2/blob/c117dea05/glicko/rating.cpp. *)
@Bannerets
Bannerets / 0-hex-bookmarklet.md
Last active April 29, 2023 10:13
A bookmarklet to convert Hex boards from Board Game Arena to HexWorld

Create a bookmark with this URL:

javascript:void function(){const e="https://hexworld.org/board/#",r=window.location.href,n=r.match(/\/table\?table=(\d+)/),o=r.match(/\/gamereview\?table=(\d+)/),t=r.match(/\/replay\/.*?\/\?table=\d+/);function a(e){return e.match(/\/(\d+\/hex)\?table=(\d+)/)}const i=a(r);let s="";function l(e){let r,n;return e.reduce((e,r)=>[...e,...r.data],[]).map(({type:e,args:o,log:t})=>{if("message"===e&&o.size){o.red&&!r?r=String(o.red):console.warn('No "args.red"');const e=o.size.match(/(\d+)x\d+/);if(e)return e[1]+"c1,"}if("playToken"===e){r||(r=o.player_id);const e=n==o.player_id?":p"+o.coord:o.coord;return n=o.player_id,e}return"swapPieces"===e?(n=o.player_id,":s"):"pass"===e?(n=o.player_id,":p"):"resign"===e||"playerConcedeGame"===e?o.player_id==r?":rb":":rw":void 0}).join("")}function c(e){return fetch(window.location.origin+e,{cache:"no-cache",headers:{"X-Request-Token":s}})}function d(e,r,n){return c(e?`/archive/archive/logs.html?table=${r}`:`/${n}/hex/notificationHistory.ht

Comparison of abstracting over monads in OCaml and Haskell.

Defining monads in OCaml first:

module type Monad = sig
  type 'a t
  val return : 'a -> 'a t
  val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
end
@Bannerets
Bannerets / .flowconfig
Created July 7, 2019 12:56
$Flow$ModuleRef
[ignore]
[include]
[libs]
[lints]
[options]
module.system=haste
@Bannerets
Bannerets / flow-computed.js
Last active April 19, 2019 00:23
Computed object properties in Flow
/*
https://flow.org/try/#0FAFwngDgpgBA8jAvDA3jA2gcgIaYLoBcMAziAE4CWAdgOYwC+MAZKhpgEb5FUCuAtuyhkGMAPSiYAewDWMABQADLADpVXGKuUKYFYjGxUdVACZQAHkICUwYKYDGAG2xlYAN2dSicANw3vcyWVsbn5BMksxCSEySWE5c2g7EChja39A4JJyahoI8SlpPwDldhCBK0iC4HSSolJKWjyoshi4hKgklMsgA
*/
type O = { ['a']: string } & { ['b']: number } // ok (`['...']: ...` is an indexer)
declare var o: O;
;(o.a: number) // error (expected)
;(o.a: string) // ok
@Bannerets
Bannerets / contravariant.js
Last active July 1, 2022 12:33
Contravariant predicates in JavaScript + Flow with correct type inference
// https://flow.org/try/#0FA4FwTwBwUwAgAoCcYBMBiA7APAWgCoB8cAvHPqcQEYD2NANjAIaYgDG9TAzl3AMI1MYJE2Ro8ROAG9gcOAGooALkQoMOIgG5ZcHW0FdhAVzZgaSOAAplqtFmxEAlNLhgAFgEsuAOiik4fgC+IHIA5jBgYqiWjipR9pJScChgRkiYrp4+QTp6gsJMALZMUA4AjISWAGaYKvhllOSx-PkiUeXEMnJyKWkZmDAA7i1CbWqWAB6N7l6+1ZiTjks6wcHAAPTrcACqXEzhSsD6mIZwXgCiAG4wGWQDwwKjouNTJMRTAKRwAEykJGQABmcmxGBXamCMhSoMCQhCOBjAZy4VxuAGVhP4LtdMN5jgVilBrEwkFwYABJITAraPMFqbCGJAeTChOHHU5QNSY5HY9FIbzhSLjKm2dT04RMlnwk6I2gMfwctCWADk3yVjilXAYMG89BooUssvoVLeriQRhgQA
// Contravariant functor.
// type Contravariant<-T> = {
// contramap<T1>(fn: (T1) => T): Contravariant<T1>
// }
// See also https://github.com/fantasyland/fantasy-land#contravariant
type PredFn<-T> = T => boolean
@Bannerets
Bannerets / .flowconfig
Last active July 28, 2018 10:18
flow wtf #1
[ignore]
[include]
[libs]
[lints]
[options]
use @pony_ctx[Pointer[None] iso]()
use @AES_init_ctx[None](
ctx: _AESCTX,
key: Pointer[U8 val] tag)
use @AES_init_ctx_iv[None](
ctx: _AESCTX,
key: Pointer[U8 val] tag,
iv: Pointer[U8 val] tag)
@Bannerets
Bannerets / gen-methods-from-tl.js
Last active June 4, 2022 17:19
generate flow types for tl methods
#!/usr/bin/env node
// @flow
const fs = require('fs')
const jsonfile = process.argv[2]
const json = JSON.parse(fs.readFileSync(jsonfile).toString())
/*::
@Bannerets
Bannerets / flow-types-from-tl.js
Last active April 6, 2018 17:49
generate flow types from tl schema (in json)
#!/usr/bin/env node
// @flow
// https://gist.github.com/Bannerets/cc3ff0689869e6777ee18917388003e8
const fs = require('fs')
const jsonfile = process.argv[2]
const json = JSON.parse(fs.readFileSync(jsonfile).toString())