Skip to content

Instantly share code, notes, and snippets.

View sylvaindesve's full-sized avatar

Sylvain Desvé sylvaindesve

View GitHub Profile
@sylvaindesve
sylvaindesve / EventEmitter.mjs
Created January 19, 2022 17:02
Implémentation de EventEmitter
("use strict");
/**
* Le type des fonctions d'écoute d'un événement.
*
* @typedef Listener
* @type {(...unknown) => void}
*/
/**
@sylvaindesve
sylvaindesve / Either.ts
Last active August 5, 2021 13:32
Simple Maybe, Either and State implementations in TypeScript
import { Monad } from "./Monad";
interface EitherType<L, R> extends Monad<R> {
isLeft(): boolean;
isRight(): boolean;
}
class Left<L, R> implements EitherType<L, R> {
constructor(public readonly left: L) {}
@sylvaindesve
sylvaindesve / logging.ts
Last active January 9, 2020 11:00
Winston
import * as winston from "winston";
const { Console, File } = winston.transports;
const { combine, timestamp, logstash, colorize, padLevels, printf, label } = winston.format;
const consoleFormat = combine(
colorize(),
padLevels(),
timestamp(),
printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
@sylvaindesve
sylvaindesve / domain_probe.ts
Created January 6, 2020 16:07
Domain Probe
// DOMAIN
// ------
interface ShoppingCartDomainProbe {
applyDiscountCode(): void;
discountCodeLookupFailed(error: string): void;
discountCodeLookupSucceeded(): void;
discountApplied(amountDiscounted: number): void;
}
@sylvaindesve
sylvaindesve / index.html
Created October 17, 2019 19:21
Sauvegarde Reactive
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="utf-8">
<title>Sauvegarde Reactive</title>
</head>
<body>
<h1>Sauvegarde Reactive</h1>
<p>Types d'accidents</p>
<input id="typesAccidents" type="text" />
@sylvaindesve
sylvaindesve / functionReduction.js
Created November 9, 2018 09:14
Javascript: right function reduction
const fn = [(x) => x + "a", (x) => x + "b", (x) => x + "c", (x) => x + "d"].reduceRight(
(accumulator, currentFn) => {
return ((x) => currentFn(accumulator(x)));
}
);
console.log(fn("test"));