Skip to content

Instantly share code, notes, and snippets.

View miyaokamarina's full-sized avatar
😶

Marina Miyaoka miyaokamarina

😶
View GitHub Profile
@miyaokamarina
miyaokamarina / gist.js
Last active April 9, 2018 21:48
Multi-line regexps in JS made easy
const regexp = (xs, ...ys) => (xs2, ...ys2) =>
new RegExp(
String.raw(xs, ...ys).replace(
// Find additional escape sequences,
// spaces, line breaks, comments:
/\\[#\n ]|#.*$|[\n ]/gm,
// Remove spaces, line breaks, comments,
// unescape additional sequences:
x => (x[0] === '\\' ? x[1] : ''),
),
type DeepReadonly<T> =
T extends [infer A] ? DeepReadonlyObject<[A]> :
T extends [infer A, infer B] ? DeepReadonlyObject<[A, B]> :
T extends [infer A, infer B, infer C] ? DeepReadonlyObject<[A, B, C]> :
T extends [infer A, infer B, infer C, infer D] ? DeepReadonlyObject<[A, B, C, D]> :
T extends [infer A, infer B, infer C, infer D, infer E] ? DeepReadonlyObject<[A, B, C, D, E]> :
T extends [infer A, infer B, infer C, infer D, infer E, infer F] ? DeepReadonlyObject<[A, B, C, D, E, F]> :
T extends [infer A, infer B, infer C, infer D, infer E, infer F, infer G] ? DeepReadonlyObject<[A, B, C, D, E, F, G]> :
T extends (infer A)[] ? DeepReadonlyArray<A> :
T extends Function ? T : // can change to never to forbid functions
ssh-keygen
Set-Alias ssh-agent "$env:ProgramFiles\git\usr\bin\ssh-agent.exe"
Set-Alias ssh-add "$env:ProgramFiles\git\usr\bin\ssh-add.exe"
Start-SshAgent -Quiet
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub | Set-Clipboard
@miyaokamarina
miyaokamarina / 01.sh
Last active September 23, 2018 00:42
su
mount /dev/nvme0n1p3 /mnt
mkdir /mnt/boot
mount /dev/nvme0n1p2 /mnt/boot
mkdir /mnt/boot/efi
mount /dev/nvme0n1p1 /mnt/boot/efi
@miyaokamarina
miyaokamarina / json.ts
Created October 1, 2018 15:23
Safe JSON type in TypeScript
interface JsonArray extends Array<JsonValue> {}
interface JsonObject {
[key: string]: JsonValue;
}
export type JsonValue = null | boolean | number | string | JsonArray | JsonObject;

antimicro authenticator davinci-resolve emoji-keyboard grub2-editor-frameworks grub2-theme-preview hardcode-fixer-git hardcode-tray kotlin-native-bin kwin-effect-shapecorners-git

su
mount /dev/sda4 /mnt
mkdir /mnt/boot
mount /dev/sda2 /mnt/boot
mkdir /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi
#!/usr/bin/env zsh
while true; do
sleep 0.5
xprop \
-id "`xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5`" \
-f _KDE_NET_WM_BLUR_BEHIND_REGION 32c \
-set _KDE_NET_WM_BLUR_BEHIND_REGION 0
done
@miyaokamarina
miyaokamarina / Await.ts
Created June 6, 2019 15:10
Recursive Promise unwrapper for TypeScript
// Works exactly as `await`/`then` in JavaScript, but for types!
// Of course, it can’t handle deep nesting (≥45±n levels) due to
// TypeScript limitations. But 45 is enough.
// License: MIT.
type Await<a> = {
0: Await<a extends PromiseLike<infer b> ? b : never>,
1: a,
}[a extends PromiseLike<any> ? 0 : 1];
@miyaokamarina
miyaokamarina / path.ts
Created June 7, 2019 08:30
Almost type-safe `path` function for TypeScript
type Falsy = '' | 0n | 0 | false | null | undefined | void;
type If<c, t, f> = c extends Falsy ? f : t;
type Cast<a, b> = a extends b ? a : b;
type Size<t> = t extends readonly any[] ? t['length'] : never;
type Head<t> = t extends readonly [any, ...any[]] ? t[0] : never;
type Last<t> = t extends readonly any[] ? t[Size<Tail<t>>] : never;
type Init<t, x = readonly []> = { 0: Init<Tail<t>, Append<x, Head<t>>>; 1: x }[If<Size<Tail<t>>, 0, 1>];
type Append<t, e> = Concat<t, readonly [e]>;
type Reverse<t, x = readonly []> = { 0: Reverse<Tail<t>, Prepend<Head<t>, x>>; 1: x }[If<Size<t>, 0, 1>];