Skip to content

Instantly share code, notes, and snippets.

View dperuo's full-sized avatar

Derek Peruo dperuo

View GitHub Profile

Source

  1. No loops
  2. No IF statements
  3. Functions are a single return
  4. No side effects
  5. No assignment in functions
  6. No arrays
const { fromEvent, pipe } = Rx;
const { scan, throttleTime } = RxOperators;
const tick = () => scan(next => next + 1, 0);
const throttled = () => throttleTime(500);
const paced = () => pipe(throttled(), tick());
fromEvent(document, 'click').pipe(paced());
export const environment = (...features: ReadonlyArray<Record<string, unknown>>) => ({
redirectTo: {
pwa: 'http://localhost:8100',
},
...features.reduce((acc, next) => ({ ...acc, ...next}), {})
} as const);
// environment(withFoo(), withBar(), ...)
@dperuo
dperuo / range.ts
Last active August 30, 2023 15:21
const range = ({ min = 0, max = 10, step = 1}): number[] => {
return min > max ? [] : [min, ...range({ min: min + 1, max, step})].filter(item => item % step === 0);
}
@dperuo
dperuo / backoff.ts
Last active January 16, 2024 15:49
const backoff = (config?: { readonly scale?: number; readonly count?: number; }): readonly number[] => {
return [...Array(config?.count ?? 4).keys()].map(item => 2 ** item * (config?.scale ?? 1));
}
const backoff$ = (config?: { readonly delay?: number; readonly count?: number; readonly scale?: number;}) => {
return from([...Array(config?.count ?? 4).keys()]).pipe(
concatMap(next => timer((config?.scale ?? 2) ** next * (config?.delay ?? 500)))
)
}
TypeScript Type Definitions Files

Logo

{{ Project Title }}

{{ Project Tag Line }}

const url = 'https://gist.githubusercontent.com/dperuo/7d93a334ce56fe8c746d4c6da92c2ee3/raw';
console.log(`deno run ${url}`);