Skip to content

Instantly share code, notes, and snippets.

『開發互動式網站 + 程式設計』的(社團模式的)營隊

走路走 100km 的概念~

  • 我們希望可以讓有興趣的同學
  • 慢慢往前進,不斷的有進展,就可以學會學到好~
  • 要快速衝的話,就會到第一個脈絡之前就沒力氣了~

TA

  • 已經知道想要投入的 高中生/大學生/大人為主 (很有投入度/很有好奇心/願意學習的國中生當然也可以~)
@Domiii
Domiii / TypingClubAutotyper.js
Last active April 17, 2025 06:42
This script types for you automatically on www.typingclub.com: 1. Open the website 2. Blaze past the tutorials 3. Go into a level 4. Open Console 5. Paste the script and press ENTER
/**
* This script types for you automatically on www.typingclub.com:
* 1. Open the website
* 2. Blaze past the tutorials
* 3. Go into a level
* 4. Open Console
* 5. Paste the script and press ENTER
*/
// NOTE: When delay (in ms between two strokes) is too low, the site might bug out and the result page will not be shown
@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');
@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 / 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)); }
/**
*
/* 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 / 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');
@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 / RTK_Notes.md
Last active December 10, 2021 12:04
RTK Notes
@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