Skip to content

Instantly share code, notes, and snippets.

fc.assert(
fc.property(
fc.nat(), fc.nat(),
(a, b) => lcm(a, b) * gcd(a, b) === a * b));
@dubzzz
dubzzz / unicode-lower-diff.js
Created February 3, 2019 20:18
Moreover, the lower or upper case value of a character depends on the locale...
'Istanbul'.toLocaleLowerCase('US') // result: 'istanbul'
'Istanbul'.toLocaleLowerCase('TR') // result: 'ıstanbul'
@dubzzz
dubzzz / jest-typings-for-tobeinstanceof.ts
Last active April 2, 2019 21:29
jest-typings-for-tobeinstanceof
class A {
a() { }
}
class B {
b() { }
}
class C extends B {
c() { }
}
class HasStaticNameMethod {
export const map2 = function<UU extends URIS>(functor: Apply1<UU>) {
return function<
TypeUUA extends Type<UU, any>,
TypeUUB extends Type<UU, any>,
R
>(
fa: TypeUUA, fb: TypeUUB, f: (a: TypeUUA['_A'], b: TypeUUB['_A']) => R): Type<UU, R> {
return functor.ap(
functor.map(
fa,
// success(depth: number, numTries: number, q: number)
//
// Compute the probability to generate at least one tree with depth superior to `depth`
// Given we tried `numTries` times with a probality of having a node of q
//
// with:
// type Tree<T> = Node<T> | Leaf<T>
// type Node<T> = { left: Tree<T>, right: Tree<T> }
// type Leaf<T> = T
//
// Update of tree-depth-proba.js
// Supposed to allow to deal with higher values of depth (approximations are done)
// success(depth: number, q: Frac)
//
// Compute the probability to generate at least one tree with depth superior to `depth`
// Given we tried 1 times with a probality of having a node of q
//
// with:
// type Tree<T> = Node<T> | Leaf<T>
@dubzzz
dubzzz / config-vscode-jest-fast-check.json
Created September 26, 2019 07:20
Configuration of VSCode to run Jest tests of fast-check locally
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Unit Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
@dubzzz
dubzzz / enable_if.ts
Created November 5, 2019 23:14
EnableIf or enable_if in TypeScript
type EnableIf<T, U, ErrorMessage extends string = never> = T extends true ? U : ErrorMessage;
type IsArrayOf<T, U> = T extends U[] ? true : false;
function enableIf<T, U>(t: T, u: EnableIf<IsArrayOf<T, U>, U, 'T has to be an array of U'>) {
// Code
}
enableIf([1, 2], 3);
enableIf([1, 2], '3');
type EnableIf<T, U, ErrorMessage extends string = never> = T extends true ? U : ErrorMessage;
type Not<T> = T extends true ? false : true;
type And<T, U, V = true, W = true, X = true> = T extends true ? U extends true ? V extends true ? W extends true ? X extends true ? true : false : false : false : false : false;
type Or<T, U> = T extends true ? true : U extends true ? true : false;
type Extends<T, U> = T extends U ? true : false;
type IsPrimitive<T> = T extends object ? false : true;
type IsNever<T> = [T] extends [never] ? true : false
// Log everything
function logAllCalls(ClassType) {
for (const k in ClassType.prototype) {
try {
if (typeof ClassType.prototype[k] !== "function") {
continue;
}
}
catch(err) {