Skip to content

Instantly share code, notes, and snippets.

View CMCDragonkai's full-sized avatar
🚀
Lightspeed

CMCDragonkai

🚀
Lightspeed
View GitHub Profile
@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
}> {
@CMCDragonkai
CMCDragonkai / what_is_trust.md
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
CMCDragonkai / wework_wifi_on_linux_with_nmcli.md
Last active December 11, 2024 17:21
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:

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

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
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
/**
* 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
#!/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

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

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
@CMCDragonkai
CMCDragonkai / compound_growth_rate.md
Created February 10, 2022 00:45
Compound Growth (Interest) Rate

Compound Growth (Interest) Rate

Suppose something grew 300% over 20 years, and you want to know what was the annual growth rate.

Use the compound interest rate formula:

A = P(1 + r/n)^(n*t)