Skip to content

Instantly share code, notes, and snippets.

View sledorze's full-sized avatar

Stéphane Le Dorze sledorze

View GitHub Profile
@sledorze
sledorze / ArrayElemIntersection.ts
Created March 26, 2019 20:39
ArrayElemIntersection
type ArrayElemIntersection<T extends any[]> = ({ [k in keyof T]: (x: T[k]) => void })[number] extends (
a: infer A
) => any
? A
: never
// Example
type A = [{ x: '5' }, { y: '8' }]
/**
* ResolveURI helps resolving the URI for a Type
* Usage: type U = ResolveURI<Option<any>> // 'Option'
*/
export type ResolveURI<X> = { [k in keyof URI2HKT<any>]: URI2HKT<any>[k] extends X ? k : never }[keyof URI2HKT<any>]
export type ResolveURI2<X> = {
[k in keyof URI2HKT2<any, any>]: URI2HKT2<any, any>[k] extends X ? k : never
}[keyof URI2HKT2<any, any>]
@sledorze
sledorze / Fold.ts
Last active July 17, 2023 10:10
Type safe Typescript definition of an ad'hoc Fold for a Tagged Sum Type (multiple tags supported)
// Definition
type Compact<A> = { [k in keyof A]: A[k] }
type FStruct<R extends Record<any, any>, K extends keyof R = keyof R> = {
[k in K]: { [kv in R[k]]: R extends { [r in k]: kv } ? Compact<R> : never }
}
type Match<StructK, R> = { [KV in keyof StructK]: (v: StructK[KV]) => R }
@sledorze
sledorze / read-status.ts
Last active February 11, 2018 00:34
Sketch of 'ReadStatus' using fp-ts / io-ts
import * as t from 'io-ts'
import { Chain1 } from 'fp-ts/lib/Chain'
import { Foldable1 } from 'fp-ts/lib/Foldable'
import { Functor1 } from 'fp-ts/lib/Functor'
import { Monad1 } from 'fp-ts/lib/Monad'
import { Monoid } from 'fp-ts/lib/Monoid'
import { Plus1 } from 'fp-ts/lib/Plus'
import { Semigroup } from 'fp-ts/lib/Semigroup'
declare module 'fp-ts/lib/HKT' {
@sledorze
sledorze / GuidGenerator.cs
Created January 29, 2018 11:04 — forked from jageall/GuidGenerator.cs
Guid from name
public class GuidGenerator
{
public static Guid CreateGuidFromName(Guid @namespace, string name)
{
return CreateGuidFromName(@namespace, name, 5);
}
//Implements rfc 4122
public static Guid CreateGuidFromName(Guid @namespace, string name, int version)
{
@sledorze
sledorze / gist:57c45b27aa57d2971227ba5ac5f41edf
Last active December 1, 2017 11:42
Adapted version of io-ts (95 branch) with testcheck integration
import * as tc from "testcheck";
import * as t from "./index";
/**
* This file provides an API to derive a testcheck Generator from an io-ts definition.
*
* Supported combinators:
* - interface
* - string
* - number
* - boolean
@sledorze
sledorze / iots-testcheck.ts
Created November 30, 2017 08:49
testcheck Generator generation from io-ts definition (pre 0.9.0)
import * as tc from 'testcheck'
import * as t from 'io-ts'
/**
* This file provides an API to derive a testcheck Generator from an io-ts definition.
*
* Supported combinators:
* - interface
* - string
* - number
@sledorze
sledorze / projections.ts
Last active July 8, 2019 02:22
Wip TS interface for (Get)EventStore Projections
function options(o: Options): void
interface Options {
// Overrides the default resulting stream name for the outputState() transformation, which is $projections-{projection-name}-result.
resultStreamName?: string
// Configures the projection to include / exclude link to events.Default: false
$includeLinks?: boolean
// When reorderEvents is turned on, this value is used to compare the total milliseconds between the first and last events in the buffer and if the value is equal or greater, the events in the buffer will be processed. The buffer is an ordered list of events. Default: 500ms
// Only valid for fromStreams() selector
processingLag?: number

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@sledorze
sledorze / abstractions.md
Created December 9, 2015 21:40 — forked from arobson/abstractions.md
Rabbit.MQ + Node.js Notes

Abstraction Suggestions

Summary: use good/established messaging patterns like Enterprise Integration Patterns. Don't make up your own. Don't expose transport implementation details to your application.

Broker

As much as possible, I prefer to hide Rabbit's implementation details from my application. In .Net we have a Broker abstraction that can communicate through a lot of different transports (rabbit just happens to be our preferred one). The broker allows us to expose a very simple API which is basically:

  • publish
  • request
  • start/stop subscription