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] : ''),
),
@miyaokamarina
miyaokamarina / conditions.js
Last active March 9, 2023 15:31
Type-level conditions in Flow https://is.gd/OPsJBd
// Licensed under CC BY 4.0.
type $If<X: boolean, Then, Else = empty> = $Call<
& ((true, Then, Else) => Then)
& ((false, Then, Else) => Else),
X,
Then,
Else,
>;
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
@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 / 00-README.md
Last active April 6, 2021 23:59
Arch package list generator

Known bugs

  • Incorrectly handles packages with Provides field.

Usage

  • ./native.sh > native.txt
  • ./external.sh > external.txt
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 / 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;
@miyaokamarina
miyaokamarina / UTF-8: Unmasked.md
Last active December 24, 2020 12:03
UTF-8: Unmasked

UTF-8: Unmasked

NB: This explanation assumes you are familiar with Unicode and differences between Unicode itself and encodings.

When I tried to understand UTF-8, first I read some decoders sources. They use bitwise masks and control flow, which is good for performance, but kind of bad for understanding.

So, here is UTF-8 explanation without masks. (And with PEG.js grammar.)

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