Skip to content

Instantly share code, notes, and snippets.

View CMCDragonkai's full-sized avatar

Roger Qiu CMCDragonkai

View GitHub Profile
CMCDragonkai / cryptolink.txt
Created May 3, 2024 09:30
Cryptolink between Polykey Keynode and Github Identity
CMCDragonkai /
Last active January 14, 2024 13:38
ADTs in TypeScript/JavaScript

ADTs in TypeScript/JavaScript

Here are the different ways of creating an algebraic datatype or a tagged value.

type Type = 'A' | 'B';
type Value = any;

type ADTTuple = [Type, Value];
type ADTNamed = { type: Type } & {};
CMCDragonkai / private_key_to_public_key.ts
Created December 8, 2023 01:31
Ed25519 Derive Public Key from Private Key
// Extracted from
// This is a minimal implementation of taking a 32 byte (256 bit) private key and deriving the public key
const hashed = await crypto.subtle.digest('SHA-512', privateKey); // data is Uint8Array or ArrayBuffer
type Bytes = Uint8Array;
const head = hashed.slice(0, 32); // slice creates a copy, unlike subarray
head[0] &= 248; // Clamp bits: 0b1111_1000,
head[31] &= 127; // 0b0111_1111,
head[31] |= 64; // 0b0100_0000
const mod = (a: bigint, b = P) => { let r = a % b; return r >= 0n ? r : b + r; }; // mod division
CMCDragonkai /
Last active November 21, 2023 22:09
Linux VirtualBox running Windows VM
CMCDragonkai /
Created November 20, 2023 23:10
Capital One WiFi on Linux
CMCDragonkai /
Last active October 17, 2023 22:14
VirtualBox Shared Folders
CMCDragonkai / promises.ts
Last active June 15, 2023 12:54
Sequentially map an action (function that returns a promise) to an array of items #javascript
// I've deliberately named this `forP_` becaus it matches Haskell's `forP_` too
function forP_<T, P extends PromiseLike<void> = Promise<void>>(
items: readonly T[],
f: (item: T) => PromiseLike<void>,
seed?: P
): P {
return items.reduce((pChain, item) => {
return pChain.then(() => f(item));
}, seed ?? Promise.resolve()) as P;
CMCDragonkai / crypto.ts
Last active June 21, 2023 13:23
Crypto generation of RSA, ECDSA and Ed25519 KeyPairs using Node Crypto and Webcrypto
import type { JsonWebKey } from 'crypto';
import crypto from 'crypto';
* Generates equivalent to RSASSA-PKCS1-v1_5 keypair
async function generateKeyPairRSA(): Promise<{
publicKey: JsonWebKey,
privateKey: JsonWebKey
}> {
CMCDragonkai /
Created April 12, 2023 02:39
What is Trust?

What is Trust?

It's the relationship between entities that allow them to co-operate with each other.

For trust to be required, there must be vulnerability, as in chance that the counter party might cheat.

At the same time, for trust to exist, one must believe that the counter party has an incentive to co-operate instead of cheating.

If there is no vulnerability, there is no need for trust.

CMCDragonkai /
Last active May 3, 2024 03:57
WeWork WiFi on Linux with `nmcli`

WeWork WiFi on Linux

When using nmcli device wifi connect 'WeWorkWiFi' password '...', you'll get something like:

Error: Failed to add/activate new connection: Failed to determine AP security information

To actually use it, you need to create a connection first and configure it: