Skip to content

Instantly share code, notes, and snippets.

View jhmaster2000's full-sized avatar
👁️‍🗨️

jhmaster jhmaster2000

👁️‍🗨️
View GitHub Profile
@jhmaster2000
jhmaster2000 / irrationalarray.mts
Created October 6, 2023 02:53
Array with irrational number indexes, PoC
// Because JS isn't cursed enough :)
import util from 'node:util';
class IrrationalArray extends Array {
constructor(...args: any[]) {
super(...args);
const indexes = Object.keys(this).filter(key => !Number.isNaN(Number(key))).map(key => Number(key)).sort((a, b) => a - b);
for (const index of indexes) this._data.set(index, this[index]);
super.length = 0;
return new Proxy(this, {
@jhmaster2000
jhmaster2000 / entropy.mjs
Last active February 17, 2023 19:47
Basic string/buffer entropy calculator
function entropy(strOrBuf = '') {
const buf = typeof strOrBuf === 'string' ? Buffer.from(strOrBuf, 'utf8') : strOrBuf;
const counts = {};
for (const byte of buf) {
counts[byte] ??= 0;
counts[byte] += 1;
}
let totalEntropy = 0;
for (const byte in counts) if (counts[byte]) {
const prevalence = counts[byte] / buf.byteLength;
@jhmaster2000
jhmaster2000 / chainlog.mjs
Created February 16, 2023 07:25
Chainable console.log PoC implementation
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|=======================================================|
| Chainable console.log proof of concept implementation |
|=======================================================|
Conceptually, this would allow for libraries to plug into console.log like plugins,
rather than overriding each other without rules and breaking end programs using them.
@jhmaster2000
jhmaster2000 / wairo.mjs
Last active October 15, 2022 22:32
what-am-i-running-on
// what-am-i-running-on (wairo) microlibrary v1.0.0
// Simple utility to check which runtime your code is running on.
export default function wairo() {
if (typeof Deno === "object") return "deno";
if (typeof process === "object") {
if (process.isBun === 1) return "bun";
if (process.versions.v8) return "node";
}
if (typeof std === "object" && globalThis.scriptArgs instanceof Array) return "quickjs";
@jhmaster2000
jhmaster2000 / wslsafepath.ts
Last active July 30, 2022 00:06
WSLSafePath utility function for Node.js & Bun
import path from 'path';
/**
* Converts Windows paths to WSL Windows paths if on a WSL environment.
*
* - Paths that are already valid Linux paths or WSL Windows paths will not be modified.
* - If on Windows and outside of WSL, paths with backslashes will be converted to forward slashes.
* - Windows paths with mixed slashes are supported. Linux paths with mixed slashes are not.
* @example `C:\\root\\pop\\bob\\foobar.jpeg` -> `/mnt/c/root/pop/bob/foobar.jpeg`
* @param absolutePath The given path must be absolute,
@jhmaster2000
jhmaster2000 / types.h
Created May 24, 2022 06:58
Basic C++ typedefs
#pragma once
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
@jhmaster2000
jhmaster2000 / gitcex.ts
Last active November 15, 2022 08:39
GitCommitExtractor - Extracts every commit of a Git repository into folders of the repository at that commit's stage
// Usage:
// node --no-warnings --loader ts-node/esm gitcex.ts <REPOSITORY_GIT_URL>
// pass 'local' on <REPOSITORY_GIT_URL> to use an already fetched repository on ./repository folder.
//
//! WARNING: Very disk-intensive and disk space consuming for large repositories.
import fs from 'fs';
import { execSync as exec } from 'child_process';
const argv = process.argv.slice(2);
@jhmaster2000
jhmaster2000 / ianatldlist.ts
Last active May 24, 2022 06:39
IANA TLD List Fetcher
import fs from 'fs';
import got from 'got'; // npm install got
got.get('https://data.iana.org/TLD/tlds-alpha-by-domain.txt').then(response => {
const listData = response.body.split('\n');
const listVersion = listData.shift()!.slice(2);
listData.pop();
fs.writeFileSync('./tlds.json', JSON.stringify({ version: listVersion, tlds: listData }));
});
@jhmaster2000
jhmaster2000 / tzdate.ts
Last active November 6, 2021 23:56
Fast and simple JS/TS Date timezone conversion with no dependencies
const input = Number(process.argv[2]) || undefined;
function formatTZOffset(offset: number): string {
offset = Math.abs(offset);
let hours = Math.trunc(offset);
let mins = Math.round((offset - hours) * 60);
if (mins === 60) {
hours++;
mins = 0;
}
@jhmaster2000
jhmaster2000 / unicodedata.json
Created September 18, 2021 19:31
JSON-Formatted Official Unicode Data
This file has been truncated, but you can view the full file.
[
{
"code": 0,
"name": "<control>",
"category": "Cc",
"canonicalCombiningClass": 0,
"bidirectionalCategory": "BN",
"decompositionMapping": null,
"decimalDigitValue": null,
"digitValue": null,