Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Lightspeed

Roger Qiu CMCDragonkai

🚀
Lightspeed
View GitHub Profile
@CMCDragonkai
CMCDragonkai / crypto.ts
Last active May 21, 2023 11:33
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 March 6, 2023 22:25
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 / cryptolink.txt
Created February 3, 2023 06:48
Cryptolink between Polykey Keynode and Github Identity
View cryptolink.txt
@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 {
@CMCDragonkai
CMCDragonkai / random.ts
Last active October 3, 2022 02:21
Get Random Bytes from Webcrypto #webcrypto #js
View random.ts
/**
* Webcrypto random bytes is limited to 65,536 in one call.
* The below functions will make repeated calls to acquire random bytes.
*/
const webcrypto = globalThis.crypto?.webcrypto || globalThis.window?.crypto;
async function sleep(ms: number): Promise<void> {
return await new Promise<void>((r) => setTimeout(r, ms));
}
@CMCDragonkai
CMCDragonkai / issue-migrate.sh
Last active July 24, 2022 05:58
Migrate Issues from GitLab to GitHub
View issue-migrate.sh
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit
count=0
glab api 'projects/:fullpath/issues?state=opened' --paginate | jq -c '.[]' | while read -r issue_object; do
@CMCDragonkai
CMCDragonkai / typescript_let_rec.md
Last active July 5, 2022 05:42
TypeScript Let Rec (Asynchronous Recursive Data Structures) #javascript #typescript
View typescript_let_rec.md

Imagine this...

async function main () {
  const config = await (async (
    a = 'a',
    b = 'b',
    c = `${a}/${b}`,
    d = ((
 e = 'e',
@CMCDragonkai
CMCDragonkai / reload_dns_cache_network_manager.md
Created June 19, 2022 06:39
Reload the DNS Cache in Network Manager
View reload_dns_cache_network_manager.md

Reload the DNS Cache in Network Manager

You may be using NetworkManager with dnsmasq as the DNS plugin. If so, it's being used as a local caching nameserver.

When its data is outdated, you can force it to reload its DNS cache with:

Use:

nmcli general reload dns-full