This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use with await to have synchrone delay | |
*/ | |
const delay = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms)) | |
/** | |
* Retry a promise a number of times if it failed | |
*/ | |
async function retry<T>(promise: Promise<T>, maxRetries: number, delayBetweenRetriesMs: number = 0) { | |
let res: T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// High availability apps require that no distinction be made between local and remote services. | |
// Attached resources should be accessed by environment variables, | |
// and in doing so allow you to swap out one attached resource for another. | |
// Let's setup a reverse proxy that directs image path requests and routes them through a defined server URL. | |
// By doing so, we decouple server requests for images which allows for easy switching | |
// from locally served image assets to a CDN by simply updating an environment variable. | |
import * as express from 'express' | |
import * as proxy from 'express-http-proxy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pipe's operator function maps an Observable<T> to an Observable<R> | |
// lift's operator function maps an Observer<R> to an Observer<T> | |
// | |
// This is just another way to represent the idea of either: | |
// building an Observable chain down from the source to the sink | |
// or building an Observer chain up from the sink to the source | |
// | |
// Pipe Implementation | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Clamp number between min and max | |
*/ | |
@function clamp($value, $min, $max) { | |
@return if($value > $max, $max, if($value < $min, $min, $value)); | |
} | |
/** | |
* Get a list from all possible abbreviations of a string | |
* Ex : abbr(yolo) => (y, yo, yol, yolo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Defines a getter on a specified object that will be created upon first use. | |
* | |
* https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/XPCOMUtils.jsm#defineLazyGetter() | |
* https://dxr.mozilla.org/mozilla-central/source/js/xpconnect/loader/XPCOMUtils.jsm#120 | |
*/ | |
function defineMemoizedGetter(object: any, prop: string, fn: Function) { | |
let redefining = false | |
Object.defineProperty(object, prop, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$id": "https://lerna.js.org/", | |
"type": "object", | |
"properties": { | |
"version": { | |
"$id": "/properties/version", | |
"type": "string", | |
"description": "The current version of the repository.", | |
"examples": [ | |
"1.1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gives a class constructor the possibility to be invoked | |
* with or without the `new` keyword, like built-in constructors. | |
* | |
* @param class_ class whose constructor will be proxified. | |
* @param constructorName if we need an accurate `constructor.name` property. | |
*/ | |
export function makeNewOptional<C extends new (...args: any[]) => any>(class_: C, constructorName?: string) { | |
type NoNew<T extends C> = (...args: ConstructorParameters<T>) => InstanceType<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate class helpers for size properties such as margin, padding, font-size | |
// Usage : | |
// @include marginer(5, 60, 5) | |
// .mt5 will then add margin-top:5px to the element, | |
// and so on for each side, from 5px to 60px with a 5px step. | |
@mixin marginer($min, $max, $step) { | |
.mt#{$min} {margin-top: $min*1px} | |
.mb#{$min} {margin-bottom: $min*1px} | |
.ml#{$min} {margin-left: $min*1px} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.typescriptlang.org/docs/handbook/advanced-types.html | |
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html | |
/** | |
* Enlève les clés K de T (plus précis que le Omit natif). | |
*/ | |
type OmitStrict<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | |
/** | |
* Récupère la version promisifiée d'une fonction. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure you have json-summary as a coverage reporter in your jest config. | |
// coverageReporters: ['json-summary', 'text', 'lcov'] | |
import { readFileSync, mkdirSync, writeFileSync } from 'fs' | |
import { join } from 'path' | |
import { get } from 'https' | |
import { ok } from 'assert' | |
Promise.resolve().then(async () => { | |
const outputDir = join(process.cwd(), 'badges') |
OlderNewer