What is the relationship between event loop and Promise [duplicate]

Each event loop has a microtask queue and a macrotask queue. A microtask is a task that is originally to be queued on the microtask queue rather than a task queue. Refer to https://www.w3.org/TR/html51/webappapis.html#microtask-queue. There are two kinds of microtasks: solitary callback microtasks, such as Promiseļ¼Œ and compound microtasks, such as Object.observe, MutationObserver and process.nextTick … Read more

“const correctness” in C#

I’ve come across this issue a lot of times too and ended up using interfaces. I think it’s important to drop the idea that C# is any form, or even an evolution of C++. They’re two different languages that share almost the same syntax. I usually express ‘const correctness’ in C# by defining a read-only … Read more

Is the C99 preprocessor Turing complete?

Well macros don’t directly expand recursively, but there are ways we can work around this. The easiest way of doing recursion in the preprocessor is to use a deferred expression. A deferred expression is an expression that requires more scans to fully expand: #define EMPTY() #define DEFER(id) id EMPTY() #define OBSTRUCT(…) __VA_ARGS__ DEFER(EMPTY)() #define EXPAND(…) … Read more

How to test randomness (case in point – Shuffling)

Statistics. The de facto standard for testing RNGs is the Diehard suite (originally available at http://stat.fsu.edu/pub/diehard). Alternatively, the Ent program provides tests that are simpler to interpret but less comprehensive. As for shuffling algorithms, use a well-known algorithm such as Fisher-Yates (a.k.a “Knuth Shuffle”). The shuffle will be uniformly random so long as the underlying … Read more

Is it possible for a computer to “learn” a regular expression by user-provided examples?

Yes, it is possible, we can generate regexes from examples (text -> desired extractions). This is a working online tool which does the job: http://regex.inginf.units.it/ Regex Generator++ online tool generates a regex from provided examples using a GP search algorithm. The GP algorithm is driven by a multiobjective fitness which leads to higher performance and … Read more