Skip to content

Instantly share code, notes, and snippets.

View fokusferit's full-sized avatar
💭
I may be slow to respond.

Ferit Topcu fokusferit

💭
I may be slow to respond.
View GitHub Profile
@cathyxz
cathyxz / amp-interactivity-links.md
Last active August 22, 2019 19:33
Code sample master sheet for AMP interactivity talk @ Chicago
@tannerlinsley
tannerlinsley / onWindowFocus.ts
Last active January 30, 2024 09:37
A utility function to detect window focusing without false positives from iframe focus events
type State = {
added: boolean;
interval: false | ReturnType<typeof setInterval>;
inFrame: boolean;
callbacks: Array<SetFocusedCallback>;
};
type EnrichedHTMLIFrameElement = HTMLIFrameElement & { ___onWindowFocusHandled: boolean };
type SetFocusedCallback = (focused?: boolean) => void;
@busypeoples
busypeoples / validation.ts
Created February 10, 2020 11:52
Validation in TS
type ValidationResult<T, U> = Partial<{ [Key in keyof T]: U }>;
type Validation<T, U> = (input: T) => ValidationResult<T, U>;
const mergeAll = <T, U>(
results: ValidationResult<T, U>[]
): ValidationResult<T, U> =>
results.reduce((acc, a) => Object.assign(acc, a), {});
const validate = <T, U = boolean | string>(
validations: Validation<T, U>[]