Skip to content

Instantly share code, notes, and snippets.

View Domiii's full-sized avatar

Domi Domiii

View GitHub Profile
@Domiii
Domiii / devtools-snippet.js
Created February 27, 2024 12:03
Replay Devtools Breakpoint Visualizer + more snippets
/* global app, BigInt */
// chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/options.html#nav=5c343cce-0abe-4d62-8634-6e8aec7157ac+editor
/** ###########################################################################
* query frontend app
* ##########################################################################*/
const getPauseId = window.getPauseId = () => {
const state = app.store.getState();
/**
* Fixes the "muted errors problem" of Promise.all.
*
* {@link betterPromiseAll}
* @see https://gist.github.com/Domiii/41c1dc504025e789fd8741f78d3ac528
* @see https://dev.to/domiii/a-solution-to-the-deep-flaws-of-promiseall-1ldh
*/
async function betterPromiseAll(promises) {
const results = await Promise.allSettled(promises);
const values = [];
@Domiii
Domiii / porcupine-defender.md
Last active December 23, 2021 19:13
Porcupine Defender!

New kind of mini-/browser-game with a serious angle: "Porcupine Defender"!

When it comes to defending Taiwan, recent surveys show that most people think that they need to rely on the US once Winnie the Poo attacks. Many feel that they are helpless on their own, when facing the threat of an invasion. However, this way of thinking is not only a fallacy, but even more so, a good way to lose your personal freedom and democracy to a hostile force.

The idea that Taiwan can and must (to a large extent) defend itself is well established. Two buzzwords often arise in that context: (1) "asymetric warfare" and (2) the porcupine doctrine. The idea is simple: in order to defend itself, Taiwan does not need to "win a war" against a superior force, it only needs to make an attack sufficiently costly/difficult and/or dangerous (https://en.wikipedia.org/wiki/Republic_of_China_Armed_Forces#Strategy).

"Porcupine Defender" visualizes how that is possible. It visualizes (among other things), Taiwan's primary military assets, h

@Domiii
Domiii / RTK_Notes.md
Last active December 10, 2021 12:04
RTK Notes
@Domiii
Domiii / webpack.config.js
Last active November 26, 2021 13:36
Sample webpack build with Dbux
/**
* @file This config is supposed to be usable for many webpack build tasks, including `webpack/examples`.
* The following setup steps are for local development build on Windows.
*
* Setup:
yarn add --dev webpack-node-externals webpack webpack-cli
mkdir ..\..\node_modules\@dbux
mklink /J ..\..\node_modules\@dbux\babel-plugin ..\..\..\dbux\dbux-babel-plugin
mklink /J ..\..\node_modules\@dbux\runtime ..\..\..\dbux\dbux-runtime
@Domiii
Domiii / mocha-list-tests.js
Last active August 18, 2021 10:05
Convert mocha test list output to pure JSON
/**
* @file Workaround (conversion script) to address lack of proper mocha JSON output.
*
* @see https://gist.github.com/Domiii/ff89e1427ee51193721abdbb08842e58
* @see https://stackoverflow.com/questions/41380137/list-all-mocha-tests-without-executing-them/68829700#68829700
*/
const fs = require('fs');
const path = require('path');
/* trace console logging */
(function __traceConsole__() {
Object.entries(console)
.forEach(([name, fn]) => {
// console.debug(name);
if (!require('lodash/isFunction')(fn)) {
return;
}
console[name] = (...args) => {
const stack = new Error().stack.split('\n').join('\n ');
@Domiii
Domiii / memory-leak-example.js
Last active March 10, 2021 11:46
This code sample is used to explain how to find memory leaks in Node.js in this post: https://stackoverflow.com/questions/66473378/memory-leaks-in-node-js-how-to-analyze-allocation-tree-roots
// ###########################################################################
// util
// ###########################################################################
const N = 100e6;
// async function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
/**
*
@Domiii
Domiii / getLinesAroundOffset.js
Created September 25, 2020 08:01
getLinesAroundOffset.js
/**
* Gets the line at given offset in s, as well as `nLines` lines below and above.
* If a line is very long (e.g. in bundled/obfuscated files), i.e. if it exceeds `maxChars`, get at most `maxChars` more in each direction
*/
function getLinesAroundOffset(s, offset, nLines = 1, maxChars = 200) {
let start = offset - 1;
for (let i = 0; i < nLines; ++i) {
const newIdx = s.lastIndexOf('\n', start) - 1;
if (Math.abs(start - newIdx) > maxChars) {
@Domiii
Domiii / JSFunStuff.md
Created June 20, 2020 07:48
JS in depth - odd behavior

When are chained callbacks in promises resolved?

Promise.then's "onFulfilledHandler" is called asynchronously. Meaning the callback will enter the queue for immediate execution after current stack fully unraveled. Calling 1000 then's takes a few milliseconds:

function f(x) {
    if (x > 0) {
        return Promise.resolve(--x).then(f);
    }
 console.timeEnd('f');