Skip to content

Instantly share code, notes, and snippets.

@nilsmehlhorn
nilsmehlhorn / matcher.ts
Last active January 31, 2020 17:31
Small and configurable full-text search on objects in TypeScript
export type Matcher<T> = (query: string) => T[];
export type ValueProject<T> = (target: T) => Array<string | number>;
export type MatcherFactory = <T>(targets: T[], project: ValueProject<T>) => Matcher<T>;
export const defaultProject = <T>(target: T) => Object.values(target);
const isMatchable = prop => typeof prop == 'number' || typeof prop == 'string'
@jsonberry
jsonberry / helpful-javascript-utilities.js
Last active September 20, 2022 01:33
Helpful JavaScript Utilities
// zip arrays together
// Catalin Dumitru @colin_dumitru
// Jason Awbrey @jsawbrey
const zip = (a, b) => a.map((n, i) => [n, b[i]])
// merge objects in an array together
// caution: properties are overridden if duplicated
// @a [{a},{b}]
// @returns [{a, b}]
// Jason Awbrey @jsawbrey
@jsonberry
jsonberry / onload.js
Last active July 3, 2023 14:10
Window vs. Document Loading Events
/**
Taken from: http://stackoverflow.com/questions/588040/window-onload-vs-document-onload
According to Parsing HTML documents - The end,
The browser parses the HTML source and runs deferred scripts.
A DOMContentLoaded is dispatched at the document when all the HTML has been parsed and have run. The event bubbles to the window.
The browser loads resources (like images) that delay the load event.
A load event is dispatched at the window.
Therefore, the order of execution will be
DOMContentLoaded event listeners of window in the capture phase
DOMContentLoaded event listeners of document
@Dorus
Dorus / index.js
Last active May 6, 2021 11:18 — forked from xgrommx/index.js
How we can make methods of observable via other methods
const flatMap = (fn, stream, resultSelector) =>
stream.flatMap((x, xi) => fn(x).map((y, yi) => resultSelector(x, y, xi, yi)));
const flatMapLatest = (fn, stream) =>
stream.publish(s => s.flatMap(v => fn(v).takeUntil(s)));
const flatMapLatest = (fn, stream, resultSelector) => stream.publish(s => {
return s.flatMap(v => fn(v), resultSelector).takeUntil(s));
});
@staltz
staltz / introrx.md
Last active November 21, 2024 16:58
The introduction to Reactive Programming you've been missing