Skip to content

Instantly share code, notes, and snippets.

name: Lint, Test, Push, Release
on:
push:
branches:
- master
- main
tags:
- 'v*'
@Shoggomo
Shoggomo / gist:ee6bbb845fd856590fdd00a0be2a39e9
Created September 16, 2020 12:15
Type-safe method to transform a nested object into a nested array
export type NestedObject<TValue> = {[key: string]: (TValue | NestedObject<TValue>)}
export type NestedList<TValue> = Array<TValue | NestedList<TValue>>;
/**
* Turns a nested object (e.g. {a: 1, b:2, c: {d: undefined, e: 4}} into lists and removes undefined (e.g. [1, 2, [4]])
* @param o The nested object
* @param pred A predicate that verifies the entries type (e.g. x => typeof x === "number"). This must work with all entries except the nesting ones.
*/
nestedObjectToNestedList<TValue extends unknown>(o: NestedObject<TValue | undefined>, pred: (o: any) => o is TValue): NestedList<TValue> {
return Object.values(o).filter((v): v is NestedObject<TValue | undefined> => typeof v !== "undefined").map(v => pred(v) ? v : Tools.nestedObjectToNestedList(v, pred));
@Shoggomo
Shoggomo / RenameFilesToTimestamp.ps1
Last active January 11, 2020 22:06
Renames all files in a directory according to the earliest timestamp that can be found on the file. (Requires Exiftool)
<#
Description:
Renames all files in a directory according to the earliest timestamp that can be found on the file.
This can be useful, if images from different devices and with different naming conventions are collected.
The timestamp is evaluated with the DateTimeOriginal CreateDate and ModifyDate metadates, which should be present on most images and videos.
IMPORTANT:
To use this script exiftool (exiftool.org) must be installed or present in the same directory as this file.
Usage: