Skip to content

Instantly share code, notes, and snippets.

View CMCDragonkai's full-sized avatar
🚀
Lightspeed

Roger Qiu CMCDragonkai

🚀
Lightspeed
View GitHub Profile
@CMCDragonkai
CMCDragonkai / cryptolink.txt
Created August 22, 2024 13:14
Cryptolink between Polykey Keynode and Github Identity
@CMCDragonkai
CMCDragonkai / cryptolink.txt
Created June 12, 2024 00:35
Cryptolink between Polykey Keynode and Github Identity
@CMCDragonkai
CMCDragonkai / cryptolink.txt
Created May 3, 2024 09:30
Cryptolink between Polykey Keynode and Github Identity
@CMCDragonkai
CMCDragonkai / adts_in_typescript_javascript.md
Last active June 7, 2024 16:41
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
CMCDragonkai / private_key_to_public_key.ts
Created December 8, 2023 01:31
Ed25519 Derive Public Key from Private Key
// Extracted from https://github.com/paulmillr/noble-ed25519/blob/main/index.ts
// 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
CMCDragonkai / linux_virtualbox_running_windows_vm.md
Last active November 21, 2023 22:09
Linux VirtualBox running Windows VM
@CMCDragonkai
CMCDragonkai / capital_one_wifi_on_linux.md
Created November 20, 2023 23:10
Capital One WiFi on Linux
@CMCDragonkai
CMCDragonkai / virtualbox_shared_folders.md
Last active October 17, 2023 22:14
VirtualBox Shared Folders
@CMCDragonkai
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
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
}> {