Skip to content

Instantly share code, notes, and snippets.

// Unility types begin
type Split<
S extends string,
Delimiter extends string
> = S extends `${infer Head}${Delimiter}${infer Tail}`
? [Head, ...Split<Tail, Delimiter>]
: S extends Delimiter
? []
: [S];
#!/bin/bash
ssh-keygen -t ed25519 -f ~/.ssh/id_faustienf
touch ~/.ssh/config
echo "
Host faustienf.github.com
HostName github.com
User faustienf
IdentityFile ~/.ssh/id_faustienf
const createQueue = () => {
let queue = Promise.resolve();
return <T extends () => any>(task: T) => {
queue = queue.then(() => task());
};
};
const queue = createQueue();
// example
@faustienf
faustienf / opaque.ts
Created March 22, 2022 13:07
Opaque type in TypeScript
declare const opaque: unique symbol;
type Opaque<T, OpaqueType> = T & { readonly [opaque]: OpaqueType };
// examples
type Timestamp = Opaque<number, 'Timestamp'>;
const timestamp: Timestamp = Math.random() // Type 'number' is not assignable to type 'Timestamp'
let scrollWidth: null | number = null;
export const getScrollWidth = (): number => {
if (scrollWidth !== null) {
return scrollWidth;
}
const el = document.createElement('div');
el.style.position = 'fixed';
el.style.zIndex = '-1';
import {
createRef,
useCallback,
useRef,
RefObject,
} from 'react';
type RefsMap<T> = Partial<Record<string, RefObject<T>>>;
type LinkRef<T> = (key: string) => RefObject<T>;
// copy from https://github.com/microsoft/TypeScript/issues/13298#issuecomment-513813788
type Overwrite<T, S extends any> = {[P in keyof T]: S[P]};
type TupleUnshift<T extends any[], X> = T extends any ? ((x: X, ...t: T) => void) extends (...t: infer R) => void ? R : never : never;
type TuplePush<T extends any[], X> = T extends any
? Overwrite<TupleUnshift<T, any>, T & {[x: string]: X}>
: never;
const obj = {
a: {
b: {
c: [1, 2, 3]
},
d: '',
f: true,
},
g: {
h: 2,
interface CalendarDay {
label: number;
timestamp: number;
isCurrentMonth: boolean;
}
type CalendarWeek = CalendarDay[];
type Calendar = CalendarWeek[];
/**
* @example
tplink archer t4u driver
https://askubuntu.com/questions/802205/how-to-install-tp-link-archer-t4u-driver