Skip to content

Instantly share code, notes, and snippets.

View felix-lipski's full-sized avatar
🛠️

felix-lipski

🛠️
View GitHub Profile
(load "pmatch.scm")
(define eval-expr
(lambda (expr env)
(pmatch expr
[,n (guard (number? n)) n]
[,x (guard (symbol? x))
(env x)]
[(lambda (,x) ,body)
(lambda (arg)
const numWithOpacity = (nums, by) =>
"#" +
nums.map((x) => Math.round(x + (255 - x) * (1 - by)).toString(16)).join("");
const hexWithOpacity = (rgbHex, by) =>
numWithOpacity(
[rgbHex.slice(1, 3), rgbHex.slice(3, 5), rgbHex.slice(5, 7)].map((hex) =>
parseInt(hex, 16)
),
by
@felix-lipski
felix-lipski / PolysemyStateIO.hs
Last active June 12, 2022 19:07
Simple example of interleaving State and IO in Polysemy
{-# LANGUAGE TemplateHaskell, LambdaCase, BlockArguments, GADTs, FlexibleContexts, TypeOperators, DataKinds, PolyKinds, ScopedTypeVariables, TypeApplications #-}
import Polysemy
import Polysemy.State
data Teletype m a where
ReadTTY :: Teletype m String
WriteTTY :: String -> Teletype m ()
SetState :: Integer -> Teletype m ()
#include <stdio.h>
#include <math.h>
#include <alsa/asoundlib.h>
int main() {
snd_pcm_t *pcm;
snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0);
snd_pcm_hw_params_t *hw_params;
snd_pcm_hw_params_alloca(&hw_params);
@felix-lipski
felix-lipski / DeepImplicitIndex.ts
Created February 14, 2023 09:33
Deeply casts interfaces to type aliases in TypeScript
/**
* Deeply casts interfaces to type aliases
*/
export type DeepImplicitIndex<I> = {
[P in keyof Pick<I, keyof I>]: Pick<I, keyof I> extends Record<any, any>
? DeepImplicitIndex<Pick<I, keyof I>[P]>
: Pick<I, keyof I>[P];
};