Skip to content

Instantly share code, notes, and snippets.

View rakeshta's full-sized avatar

Rakesh Ayyaswami rakeshta

View GitHub Profile
@rakeshta
rakeshta / enumerate-subsets.ts
Last active November 21, 2022 08:13
A utility function to enumerate all subsets of a given set
/**
* Counts the number of `true` (or `1`) bits in the given integer.
*
* @remarks This is an efficient algorithm that works for 32-bit integers only.
*
* @param i The integer to count the number of `true` bits in.
* @returns The number of `true` bits in the given integer.
*
* @see {@link https://stackoverflow.com/a/109025/11236} for the source of this algorithm.
* @see {@link https://en.wikipedia.org/wiki/Hamming_weight} for explanations & other efficient implementations.
@rakeshta
rakeshta / LeafKeyPaths.ts
Created May 20, 2022 05:53
Awesome utility type copied from `native-base` that extracts the key paths to the leaves of a nested object type into a new type
/**
* Joins two types with a `.`.
*
* _Pure inspirational typescript wizardry!_
* @note this was copied from the type system of `native-base`.
*/
export type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${'' extends P ? '' : '.'}${P}` : never : never;
/**
* Recursively flattens the keys in the object to key-paths of the leaf nodes.
0eNq03d2yZMdxpulbkeEYbNv+E+4ROuw5nxsYk7WRVEmCCQJoINQ9mra+96kigSKIylWIN+KroxbJXl650yNj5X4+3yv+91d/+PY/3/3ph2+++/F//OH77//9q3/833/7b/781T/+P7/4jx/+t2/++P13f/2v//zNv373+28//Hc//tef3n31j1998+O7//jq66+++/1/fPhPP/z+m2+/+j9ff/XNd//87v/96h/t/3z925d8/4fv//T9Dz/+4jLfuOwP3/zr7959++6PP/7wzR9/96fvv333i+tj55/9+1ea/+efvv7q3Xc/fvPjN+/++pP+5T/81//47j//4w/vfnj/o3y88o//+cP/fPfPv/tLga+/+tP3f35/zfffffiHPrz08K+/+q+v/nHk2/vi//zND+9f4V/+1/rwmn5V0z/W/POP78v967/9+Fi1/1o11t9X9RdVY/OV5sMrjRc1c69mkJ9+7P70QX762nyl5Kfv7T75+qlq/H3VflF1blfN8bqqvai6/m6F/+6P//b7b7773U+fhReV67/9XNv+2/jtd8LetptG3goz8qrD+/lVv3pPbPuDFuSttt1PmtdPRWujaO5+fOfHoq/KjP3V1a9/5PGq7ObHy8fb6x/5Zfd78zPr+broq33A5m5R0py1v/wf3tVXnyp/2920PttzR58iH/HxUzR+/Sl69Y66/33554/nGywc22t1/Fy4N8rmftkGZfc/WWOBsrVdtgyU3b93VYCy+zevIi1b+2VBy+JtvyxoWdh22QYti/2vhQ1aFvufsgYti/1PWZOW7X/KmrRs/1M2Scv2P2WTtGz/UzZJy/Y/ZRO0LPc/ZRO0LPc/ZQu0LPc/ZQu0LPc/ZQu0LPc/ZYu0bP9TtkjLtj9l8UZa1vtlScvmflnSsv3vim+gZWP/N7A30LKx/SkLAy0b+795GWjZiP2yoGUj98uSlu1Lh5GW1aeG9uILzU/OMezVrwyjN2qEfb7G/l3Kx2cLrc/o3rOJvS/2/rp37//dP3z