Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
@dhilst
dhilst / index.html
Last active August 28, 2024 02:06
html from js
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</head>
<body>
<script>
function html(text, ...values) {
const html = text.flatMap((text, i) => {
return [text, values[i]?.outerHTML || values[i]]
@dhilst
dhilst / tco.py
Last active June 23, 2023 02:03
tco python with exceptions
from typing import ParamSpec, TypeVar, Callable, reveal_type
T = TypeVar("T")
P = ParamSpec("P")
def tco(f: Callable[P, T]) -> Callable[P, T]:
unwind = False
@dhilst
dhilst / monadproto.py
Created June 17, 2023 17:06
Py Monad Protocol
from typing import *
from typing_extensions import ParamSpec
A = TypeVar("A")
B = TypeVar("B")
C = TypeVar("C")
D = TypeVar("D")
E = TypeVar("E")
F = TypeVar("F")
G = TypeVar("G")
@dhilst
dhilst / grammar.y.rb
Created November 4, 2022 01:51
Getting started with racc (ruby LALR(1) parser lib)
class Calcparser
prechigh
left '*' '/'
left '+' '-'
preclow
options no_result_var
rule
target: expr
@dhilst
dhilst / lcdbjn.ml
Last active September 7, 2022 21:39
open Format
type term =
| Var of int
| Lamb of term
| App of term * term
let rec shift i depth = function
| Var x when x < depth -> Var x
| Var x -> Var (x + i)
@dhilst
dhilst / unicode_to_utf8.ml
Last active September 2, 2022 23:46
OCaml Unicode codepoints to UTF-8 string
open Printf
let (%) = Int.logor
let (<<) = Int.shift_left
let (>>) = Int.shift_right
let (&) = Int.logand
let utf_8_bytes_of_unicode i =
if i <= 0x007F
then
(**
* Closed Terms Lambda Caulcus with De Bruijn Indexes
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)
open Format
type term =
| Var of int
| Lamb of int * term
import sys
from functools import partial
class Pipe:
def __init__(self, f, *args, **kwargs):
self.f = f
self.args = args
self.kwargs = kwargs
def __call__(self, replacement):
args = [arg if arg is not Ellipsis else replacement
from typing import *
import ast
from dataclasses import dataclass
@dataclass(frozen=True)
class FuncSig:
name : str
args : list[str]
ret: str
open Printf
type term = F of string * (term list) | V of string
let rec subst term ((name, replacement) as sub) =
match term, name with
| V x, V y when String.equal x y -> replacement
| V x, V y when not (String.equal x y) -> term
| F (x, args), V y -> F (x, List.map (fun arg -> subst arg sub) args)
| _, _ -> assert false