Skip to content

Instantly share code, notes, and snippets.

@Shoggomo
Shoggomo / match.ts
Last active April 14, 2025 12:11
Simple Rust-like match function in typescript, that is fully typed. It requires a default value.
type Matches<T, U, V> = [...[T | boolean, U][], ["default", V]];
/* Rust-like match function, that checks values or predicates and returns the first match. */
export function match<T, U, V>(value: T, ...pairs: Matches<T, U, V>): U | V {
const defaultValue = pairs[pairs.length - 1][1];
return (
pairs.find(
([condition]) => value === condition || condition === true,
)?.[1] ?? defaultValue
);
@Shoggomo
Shoggomo / Setup.md
Last active August 12, 2024 19:21
Move Images on a Frameo From PC Without App or Internet Connection

Prerequisites

Setup your Frameo to be available in your network, but not have an internet connection:

  1. Connect to your Wifi
  2. Prevent internet access in your router. This is router specific, but most support this.

Enable USB debugging

  • Settings → About → toggle Beta Program on → toggle ADB Access on
@Shoggomo
Shoggomo / promiseAllReducer.ts
Last active June 28, 2024 13:44
How to use Promise.all() in a map(), filter() chain without wrapping the whole thing
/**
* Reducer function, that acts like `Promise.all` that resolves an array of promises.
* Use like this `arrayOfPromises.reduce<MyType>(...promiseAllReducer())`.
*/
export const promiseAllReducer = <T>() =>
[
(_1: Promise<T[]>, _2: unknown, _3: unknown, array: Promise<T>[]) =>
Promise.all(array),
Promise.resolve<T[]>([]),
] as const;
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: