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 / linux_virtualbox_running_windows_vm.md
Last active November 21, 2023 22:09
Linux VirtualBox running Windows VM
View linux_virtualbox_running_windows_vm.md
@CMCDragonkai
CMCDragonkai / capital_one_wifi_on_linux.md
Created November 20, 2023 23:10
Capital One WiFi on Linux
View capital_one_wifi_on_linux.md
@CMCDragonkai
CMCDragonkai / cryptolink.txt
Created October 24, 2023 23:48
Cryptolink between Polykey Keynode and Github Identity
View cryptolink.txt
@CMCDragonkai
CMCDragonkai / virtualbox_shared_folders.md
Last active October 17, 2023 22:14
VirtualBox Shared Folders
View virtualbox_shared_folders.md
@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
View promises.ts
// 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
View crypto.ts
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
CMCDragonkai / what_is_trust.md
Created April 12, 2023 02:39
What is Trust?
View what_is_trust.md

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
CMCDragonkai / wework_wifi_on_linux_with_nmcli.md
Last active November 20, 2023 23:08
WeWork WiFi on Linux with `nmcli`
View wework_wifi_on_linux_with_nmcli.md

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:

@CMCDragonkai
CMCDragonkai / tagged_unions_in_typescript.md
Created November 6, 2022 05:50
Tagged Unions in TypeScript #typescript #adt
View tagged_unions_in_typescript.md

There are number of ways of creating tagged unions.

type X = { type: A, prop: number } | { type: B, prop: string };

type Y = { type: A, data: { prop: number } } | { type: B, data: { prop: string } };

type Z = ['A', { prop: number }] | ['B', { prop: string }];
@CMCDragonkai
CMCDragonkai / validate_public_key_noble.ts
Created October 5, 2022 05:48
Validate Public Key #ed25519
View validate_public_key_noble.ts
import * as nobleEd25519 from '@noble/ed25519';
/**
* Checks if the public key is a point on the Ed25519 curve
*/
function validatePublicKey(publicKey: Buffer): boolean {
try {
nobleEd25519.Point.fromHex(publicKey);
return true;
} catch {