Skip to content

Instantly share code, notes, and snippets.

View emilien-jegou's full-sized avatar
:shipit:

Emilien Jegou emilien-jegou

:shipit:
View GitHub Profile
@emilien-jegou
emilien-jegou / class-functions.ts
Created February 28, 2025 05:04
typed class inheritance through functions in typescript
///// Example usage of inheritance using class functions
///// Demonstrates how object-oriented programming
///// can be achieved through clever use of functional
///// programming patterns.
type Ty = { symbol: symbol; parent?: Ty };
type Class = { __ty: Ty };
type Constructor = (...args: any) => Record<string, any>;
type ClassInterface<C extends Constructor> = ((...args: Parameters<C>) => ReturnType<C> & Class) & {
isInstance(obj: Class): obj is ReturnType<C> & Class;
@emilien-jegou
emilien-jegou / result.ts
Created February 24, 2025 14:31
Typescript error handling
import type { Prettify } from 'ts-essentials';
export type Result<T = unknown, E = unknown> = Success<T> | Failure<E>;
export interface Success<T> {
kind: 'success';
value: T;
}
export interface Failure<E> {
@emilien-jegou
emilien-jegou / server.py
Created July 18, 2024 00:04
docker proxy demo
from http.server import BaseHTTPRequestHandler, HTTPServer
import ssl
import base64
# Test of the docker login authentication mechanism for building an authentication proxy.
# NB: you may want to remove the SSL configuration below or generate certificate using:
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./server.key -out ./server.crt
#
# USAGE:
# python server.py
{ pkgs ? import <nixpkgs> {} }:
let
version = "1.0.5";
src = pkgs.fetchurl {
url = "https://github.com/localstack/localstack-desktop/releases/download/${version}/LocalStack-Desktop-community-${version}.AppImage";
sha256 = "sha256-Q6lnv8OGGztqMVVisLhU/lh5qmsG2FqH21lhKupwzys=";
};
in
pkgs.buildFHSUserEnv {
@emilien-jegou
emilien-jegou / matchk.ts
Last active February 17, 2024 16:42
Pattern matching on key
export type ObjectPick<
T extends Record<string, unknown>,
K extends keyof T,
V extends T[K],
> = T extends Record<K, infer U> ? ([U] extends [V] ? T : never) : never;
type ObjectOmit<
T extends Record<string, unknown>,
K extends keyof T,
V extends T[K],