Skip to content

Instantly share code, notes, and snippets.

@Aex12
Aex12 / hybrid-sleep.sh
Last active May 19, 2025 22:47
hybrid-sleep
#!/bin/sh
# hybrid-sleep
# specify how many seconds to sleep before hibernation in each battery range
# format is THRESHOLD=TIME ...
# when battery is below THRESHOLD, sleep for TIME and then hibernate
# it must go from 100 to 0 to work properly.
# example: 100=3600 50=1800 20=600 10=0
# that represents:
# - if battery is between 100 and 51%, then sleep 1h, then hibernate
@Aex12
Aex12 / literal-deep-keys.ts
Created April 9, 2023 23:21
typescript template literals and deep key inferring
// type Untokenize<S extends string, T extends string[] = []> = S extends `${infer R}.${infer U}` ? Untokenize<U, [...T, R]> : [ ...T, S];
type GetKeyPaths <T extends object> = {
[P in keyof T]: P extends string
? T[P] extends object
? `${P}.${GetKeyPaths<T[P]>}` | P
: P
: never
}[keyof T]