Skip to content

Instantly share code, notes, and snippets.

View jsoendermann's full-sized avatar

Jan Söndermann jsoendermann

View GitHub Profile
@jsoendermann
jsoendermann / mongo.md
Last active April 24, 2017 05:58
Mongo styleguide

MongoDB Style Guide

General

  • Don't mix types. Do be conservative in what you write liberal in what you accept
  • Don't use the empty string or 0 for their falsiness. Do make non-casting, explicit comparisons

Enums

  • Don't use numbers, booleans or any other types to model enumerations. Do model them as uppercase string constants, e.g. "WAITING", "IN_PROGRESS" and "COMPLETED".
@jsoendermann
jsoendermann / cluster.js
Created March 21, 2017 08:26
Simple clustering
const EPSILON = 0.1
const cluster = (array, threshold) => {
for (const e of array) {
return array.filter(e_ => Math.abs(e - e_) < EPSILON).length / array.length >= threshold
}
}
if (
cluster([0, 0.0001, 0.01, 0.0, 9], 0.5) &&
@jsoendermann
jsoendermann / result.ts
Last active January 6, 2021 15:44
TypeScript Result type
interface IValue<T> {
type: 'value'
value: T
}
interface IError<E extends Error> {
type: 'error'
error: E
}
@jsoendermann
jsoendermann / decoratorTest.ts
Created November 30, 2016 00:12
TypeScript decorator that changes method type signature
// tsconfig.json:
// {
// "compilerOptions": {
// "target": "es6",
// "experimentalDecorators": true
// }
// }
const decorator = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
const originalMethod = descriptor.value;

Keybase proof

I hereby claim:

  • I am jsoendermann on github.
  • I am jsoendermann (https://keybase.io/jsoendermann) on keybase.
  • I have a public key whose fingerprint is 9AD4 1092 7FC9 294A 8F7C 0488 66C4 BA6A D452 476A

To claim this, I am signing this object: