Skip to content

Instantly share code, notes, and snippets.

@fvilante
fvilante / AJSonDescribingTheJson.json
Created May 14, 2019 18:03
A Json format to describe the Json format: Aspects of Recurrency in Descriptive Programming
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
@fvilante
fvilante / StaticLenses.ts
Created May 20, 2019 13:58
Static Lenses prove of concept in Typescript
// =======================================================================
// Lenses
// =======================================================================
type Setter<A, B extends keyof A> = Func2<A, A[B], A[B]>
type Getter<A, B extends keyof A> = Func<A, A[B]>
type Property<A, B extends keyof A> = B
@fvilante
fvilante / Meiosis.ts
Last active July 8, 2021 09:54
Meiosis pattern in typescript (a simple example)
// uses 'flyd' stream micro-library
type Stream = (_: number) => Stream // this life is a simplification
interface Model {
value: number
}
interface Actions {
increment: () => void
@fvilante
fvilante / deno_test.ts
Last active May 29, 2019 05:01
Deno test
// Just a test of Deno
const aTable = { deno: 'Typescript', grupo: 'Typescript', nome: 'Flavio' }
console.log()
console.table(aTable)
console.log()
@fvilante
fvilante / groupBy.ts
Last active June 27, 2019 19:56
groupBy
let seniors = [
{
"id": 1,
"name": "Jack",
"active": true,
"level": "senior"
},
{
"id": 2,
@fvilante
fvilante / StaticDriver.ts
Last active July 29, 2019 13:21
A fully static driver configuration
import { CmppParamType, Milimeter, Space, Speed, Acceleration, MilimeterPerSecond, MilimeterPerSquareSecond, Pulse } from './application-types'
import { mapObjectIndexed } from '@nextrobot/core-utils';
//import { ParamMemmap } from './memmap-base';
// drive instance
// core
type AnyEntry = { readonly type: unknown }
@fvilante
fvilante / InterfaceIntrospection.ts
Last active July 31, 2019 21:06
Utility type to introspect an interface
// Author: Flavio
type __PairList<T> = {
[Key in keyof T]: {
readonly key: Key
readonly value: T[Key]
}
}
type __Pair<T> = __PairList<T>[keyof T]
@fvilante
fvilante / gist:7e5b468b77e21fdc811969b2020ef131
Created December 3, 2019 14:56
Can Typescript perform run-time check at compile-time ?
// Here we will put the solution.
// But before let's have a talk bellow.
@fvilante
fvilante / example.ts
Created December 15, 2019 06:23
css pre-processor using TS lang
// study on using typescript as a host language to pre-process CSS
import { Either, Left, Right } from "../monads/either";
import { Maybe, Just, Nothing } from "../monads/maybe";
type PX = {
readonly kind: 'px'
readonly value: number
}
@fvilante
fvilante / mytest.ts
Last active December 17, 2019 01:00
Typescript generics and subtypem
// Code used to answer bellow stackoverflow question:
// https://stackoverflow.com/a/59363875/8233039
// super class
type _Super<T> = {
readonly prop1: `bar`
readonly propT: T
}
const _super: _Super<string> = {