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
export type ICallback<T> = (data: T, envelope: IEnvelope<T>) => void; | |
/** Message enveloppe */ | |
export interface IEnvelope<T> { | |
/* Uses DEFAULT_CHANNEL if no channel is provided */ | |
channel?: string; | |
/** Topic name */ | |
topic: string; | |
/** Payload */ | |
data?: 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
/** | |
* Create a GUID | |
* @see https://stackoverflow.com/a/2117523/319711 | |
* | |
* @returns RFC4122 version 4 compliant GUID | |
*/ | |
export const uuid4 = () => { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { | |
// tslint:disable-next-line:no-bitwise | |
const r = (Math.random() * 16) | 0; |
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
/** | |
* Deep copy function for TypeScript. | |
* @param T Generic type of target/copied value. | |
* @param target Target value to be copied. | |
* @see Source project, ts-deepcopy https://github.com/ykdr2017/ts-deepcopy | |
* @see Code pen https://codepen.io/erikvullings/pen/ejyBYg | |
*/ | |
export const deepCopy = <T>(target: T): T => { | |
if (target === null) { | |
return target; |
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
/** | |
* Deep copy function for TypeScript. | |
* @param T Generic type of target/copied value. | |
* @param target Target value to be copied. | |
* @see Source project, ts-deepcopy https://github.com/ykdr2017/ts-deepcopy | |
*/ | |
export const deepCopy = <T>(target: T): T => { | |
if (target === null) { | |
return target; | |
} |
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
/** | |
* Create a GUID | |
* @see https://stackoverflow.com/a/2117523/319711 | |
* | |
* @returns RFC4122 version 4 compliant GUID | |
*/ | |
export const uuid4 = () => { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { | |
// tslint:disable-next-line:no-bitwise | |
const r = (Math.random() * 16) | 0; |
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
/** | |
* Create a cached version of a function. | |
* | |
* @example cachedCalcArea = cachify(calcArea); | |
* @param fn Function whose results you want to cache | |
* @see TypeScript version of https://dev.to/kepta/javascript-underdogs-part-1---the-weakmap-4jih | |
*/ | |
export const cachify = <T extends object, R>(fn: (arg: T) => R) => { | |
const cache = new WeakMap(); // Use Map() when dealing with non-object arguments | |
return (arg: 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
/** | |
* Convert RD (Rijksdriehoek) coordinates to WGS84 and vice versa. | |
* @see https://thomasv.nl/2014/03/rd-naar-gps/ | |
*/ | |
const projectionBetweenRdWgs84 = () => { | |
const x0 = 155000; | |
const y0 = 463000; | |
const f0 = 52.15517440; // f => phi | |
const l0 = 5.38720621; // l => lambda |
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
import fs from 'fs'; | |
import path from 'path'; | |
/** | |
* Recursively walk a directory asynchronously and obtain all file names (with full path). | |
* | |
* @param dir Folder name you want to recursively process | |
* @param done Callback function, returns all files with full path. | |
* @param filter Optional filter to specify which files to include, | |
* e.g. for json files: (f: string) => /.json$/.test(f) |
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
--- | |
version: '2' | |
services: | |
zookeeper: | |
image: confluentinc/cp-zookeeper | |
hostname: zookeeper | |
extra_hosts: | |
- "moby:127.0.0.1" | |
ports: | |
- "2181:2181" |
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
# Phoenix, by default, uses a Postgres database, so start one via docker | |
docker pull postgres | |
# Expose it on port 8432 | |
docker run -p 8432:5432 --name hello-postgres -e POSTGRES_PASSWORD=postgres -d postgres | |
# Install Erlang, Elixir, and now Phoenix | |
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez | |
# Create a new Phoenix app | |
mix phx.new hello | |
# Edit config/dev.exs and update your hostname. Add a port (default is 5432, but I've mapped it to 8432) |