Skip to content

Instantly share code, notes, and snippets.

View dperuo's full-sized avatar

Derek Peruo dperuo

View GitHub Profile
@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)))
)
}

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);
}
const url = 'https://gist.githubusercontent.com/dperuo/7d93a334ce56fe8c746d4c6da92c2ee3/raw';
console.log(`deno run ${url}`);

Markdown Footnotes

Nullam id dolor id nibh1 ultricies vehicula ut id elit. Donec id2 elit non mi porta gravida at eget metus. Aenean lacinia bibendum nulla sed consectetur. Donec ullamcorper nulla non metus auctor fringilla. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.


1 Nullam id dolor id nibh ultricies vehicula ut id elit.

2 Donec sed odio dui.

Issue Tickets 💎

  • If any

Details 📝

  • Breaking changes, related pull requests, build logs and other details go here

Related 🔍