Skip to content

Instantly share code, notes, and snippets.

View hugoaboud's full-sized avatar

Hugo Aboud hugoaboud

  • WatchGuard
  • Pindamonhangaba, SP
View GitHub Profile
@hugoaboud
hugoaboud / TypeFlatten.ts
Created March 31, 2023 00:54
Generic Type that recursively flattens a Type by merging property names with dots
type DeepKeys<M> = {
[J in keyof M as `${J & string}${
M[J] extends Record<string, any> ?
M[J] extends {constructor: M[J]} ? '' :
M[J] extends Array<any> ? '' :
`.${keyof DeepKeys<M[J]> & string}` : ''
}`]:
M[J] extends Record<string, any> ? M : M[J]
}
@hugoaboud
hugoaboud / dirtree.py
Last active February 19, 2023 02:32
Build a directory tree, including files, for a given path
import os
def dirtree(path):
steps = list(os.walk(path))
def _tree():
_, child_dirs, files = steps.pop(0)
obj = { child: _tree() for child in child_dirs }
obj['__files__'] = files
return obj
return _tree()