This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
current_level=$(pmset -g batt|grep InternalBattery-0|sed -n 's#.*[[:space:]]\([[:digit:]]\{1,\}\)%.*#\1#p') | |
[[ -z ${current_level} ]] && current_level='--' | |
echo ${current_level} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type OptionalTypeOrNull<T> = T | undefined | null; | |
type Nullish = undefined | null; | |
type Falsy = false | "" | 0 | 0n | Nullish; | |
type Truthy<T> = T extends Falsy ? never : T; | |
type AnyCollection = ArrayLike<unknown>; | |
type AnyObject = { [p: string]: AnyObject | AnyCollection | unknown }; | |
type Maybe<T> = T | Nullish; | |
type MaybePromise<T> = Promise<T> | T; | |
type Immutable<T> = { | |
readonly [K in keyof T]: Immutable<T[K]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const isString = (obj: unknown) => | |
obj !== undefined | |
&& obj !== null | |
&& (obj instanceof String || typeof obj === 'string'); | |
export const isNone = (v?: unknown): boolean => v === undefined || v === null; | |
export const isUndefined = (v?: unknown): boolean => v === undefined; | |
export const isBool = val => 'boolean' === typeof val; | |
export const asBool = (v?: unknown): boolean => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {format as dateFmt} from 'date-fns' | |
export const getRelativeTime = (locale: string, d1: Date, d2: Date = new Date()): string => { | |
// in milliseconds | |
const units = { | |
year: 24 * 60 * 60 * 1000 * 365, | |
month: 24 * 60 * 60 * 1000 * 365 / 12, | |
day: 24 * 60 * 60 * 1000, | |
hour: 60 * 60 * 1000, | |
minute: 60 * 1000, |
OlderNewer