Skip to content

Instantly share code, notes, and snippets.

View laat's full-sized avatar
💤

Sigurd Fosseng laat

💤
View GitHub Profile
@laat
laat / 1-json-schema.fsx
Last active October 13, 2022 20:54
JsonSchema.Net validation in F#
#!/usr/bin/env -S dotnet fsi --quiet
#r "nuget: JsonSchema.Net"
//
// This file contains a basic example of json schema validation
//
open Json.Schema
open System.Text.Json
let schema =
@laat
laat / episodes_in_wrong_series.sql
Last active May 14, 2021 19:02
Episodes in wrong TV Series.
WITH
external_data
/*
In an external system, we have some episode to series relations.
An episode can be in multiple series.
The SERIES_ID is monotonically increasing database ID.
*/
AS (SELECT 10 SERIES_ID, 1 EPISODE_ID FROM dual UNION ALL
SELECT 2 SERIES_ID, 1 EPISODE_ID FROM dual),
transformed_data

Invert Binary Tree in F#

graph graph-inverted

An inverted Binary Tree is a Binary Tree with left and right children of all non-leaf nodes interchanged.

type Node =
  { Value: int
import mime from "mime";
import { stat } from "node:fs/promises";
import http2, { Http2ServerRequest, Http2ServerResponse } from "node:http2";
import { join } from "node:path";
export type Http2Handler = (
next?: (
req: Http2ServerRequest,
res: Http2ServerResponse
) => Promise<void> | void
@laat
laat / sse.http2.ts
Last active February 9, 2022 09:40
Server-Sent Events over HTTP/2 on Node.JS
Relays messages published on a redis channel over Server-Sent Events.
const arr = [1, 4, 4, 54, 56, 54, 2, 23, 6, 54, 65, 65];
const reduceSum = arr => arr.reduce((acc, val) => acc + val);
const forEachSum = arr => {
let sum = 0;
arr.forEach(el => sum += el);
return sum;
};
const forSum = arr => {
let sum = 0;
for (let i = 0; i < arr.length; i++ ) sum += arr[i];
const sleep = (s) =>
new Promise((resolve) =>
setTimeout(() => resolve(s), s * 1000)
);
const sleepSort = async (arr) => {
const res = [];
await Promise.all(
arr
.map(sleep)