Skip to content

Instantly share code, notes, and snippets.

View Dziejo93's full-sized avatar
😎

Andrzej Dziejo93

😎
View GitHub Profile
// TODO: make `pages` optional and measure the div when unspecified, this will
// allow more normal document flow and make it easier to do both mobile and
// desktop.
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
@Dziejo93
Dziejo93 / recursion.ts
Created January 12, 2022 23:03
Simple recursion getting unique numbers from object
// hack as self-circulating types are not working in 4.5.4
interface Tree extends Record<string, number | Tree> { }
type Subtree = Tree[keyof Tree]
const uniqueNumbersSet = new Set<number>();
const getUniqueSortedNumbers = (tree: Tree) => {
Object.values(tree).forEach((subtree: Subtree) => {
if (typeof subtree === "number") {
return !uniqueNumbersSet.has(subtree) && uniqueNumbersSet.add(subtree);
@Dziejo93
Dziejo93 / console.ts
Created January 12, 2022 23:02
Example of how to extend console.log
1.
console.log = function (this: Function, ...args: unknown[]) {
const remappedArgs = [...args.map((elementToLog) => [elementToLog, typeof elementToLog])].flat()
this.apply(console, remappedArgs);
}.bind(console.log);
console.log('123', [1, 2], 12, Symbol('symbol'), { hello: 1 }, undefined, null, BigInt(9007199254740991));
// 123 string (2) [1, 2]0: 11: 2length: 2[[Prototype]]: Array(0) object 12 number Symbol(symbol) symbol {hello: 1} object undefined undefined null object 9007199254740991n bigint