Skip to content

Instantly share code, notes, and snippets.

View davesnx's full-sized avatar

David Sancho davesnx

View GitHub Profile
@davesnx
davesnx / SOUND_MODE_DESIGN.md
Last active September 18, 2026 15:45
A sound TypeScript mode — design draft

A sound TypeScript mode

If TypeScript says a value is a string, calling a function shouldn't silently turn it into a number. Even with strict mode, that can happen through another reference to the same object.

The sound mode adds stronger checks to the existing compiler. It keeps structural typing and ordinary JavaScript output. Code that the compiler cannot prove safe needs a different implementation, more type information, or an explicit unchecked operation.

@davesnx
davesnx / LICENSE.txt
Last active July 23, 2026 14:29
gh-fix-ci OpenCode skill
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@davesnx
davesnx / main.ml
Created September 28, 2025 16:31
Simple typed lambda calculus interpreter with de bruijn indices and beta reduction
module Index = struct
type t = int * string
let create i s = (i, s)
let eq t1 t2 = fst t1 = fst t2
let enter_level (i, s) = (i + 1, s)
let pp_index i = Format.sprintf "%s" (snd i)
end
type typ = Tvar | Tpoly | Tfun of typ * typ
@davesnx
davesnx / main.ml
Created September 28, 2025 16:17
effects.ml
type _ io =
| Sync : (unit -> 'a) -> 'a io
| FlatMap : 'a io * ('a -> 'b io) -> 'b io
| Async : ((('a -> unit) -> unit) -> unit) -> 'a io
| All : 'a io list -> 'a list io
| Sleep : float -> unit io
let flatMap f io = FlatMap (io, f)
let map f io = flatMap (fun a -> Sync (fun () -> f a)) io
[@@@warning "-27"]
let get_memory_info () =
let ic = open_in "/proc/self/status" in
let rec read_lines rss vmsize =
try
let line = input_line ic in
if String.starts_with ~prefix:"VmRSS:" line then
let rss_kb = String.sub line 6 (String.length line - 9) |> String.trim |> int_of_string in
read_lines (Some rss_kb) vmsize
@davesnx
davesnx / ppx.ml
Created February 3, 2025 15:07
a few functions to replace of_yojson dependency
(*
TODO: If we want to remove the dependency on of_json, we need to implement the json decoder manually.
TODO: Maybe use a custom deriving called "rsc" or similar where it handles the JSON/Promise/React.element. *)
let rec make_of_json ~loc (type_ : core_type) value =
match type_.ptyp_desc with
| Ptyp_constr ({ txt = Lident "int"; _ }, _) -> value
| Ptyp_constr ({ txt = Lident "string"; _ }, _) -> value
| Ptyp_constr ({ txt = Lident "bool"; _ }, _) -> value
| Ptyp_constr ({ txt = Lident "float"; _ }, _) -> value
@davesnx
davesnx / Responsive.re
Created July 25, 2024 11:00
Random design for "Adaptative" component
/* This type defines a value that 'depends' on the screen size, and changes based on `window.matchMedia` */
type dependant('value) = {
default: 'value,
mobile: option('value), /* 800px */
desktop: option('value), /* 1200px */
huge: option('value) /* 1900px */
};
type t('value) =
| Fixed('value)
@davesnx
davesnx / Makefile
Last active January 3, 2024 17:14
importMaps are cool
dev:
npx http-server -o .
open Ppxlib
module Builder = Ast_builder.Default
type target = Native | Js
let mode = ref Native
module Effect = struct
(* TODO: [%effect] is a little incomplete, only works with useEffect0 (not other useEffectX, neither useLayoutEffects) *)
let extractor = Ast_pattern.(__')
@davesnx
davesnx / print-rescript-parsetree.sh
Last active December 4, 2023 14:11
ReScript Parsetree print
npx bsc -dparsetree wat.res
npx bsc -dparsetree wat.ml
npx bsc -format wat.ml