Skip to content

Instantly share code, notes, and snippets.

View Trott's full-sized avatar

Rich Trott Trott

View GitHub Profile

In test/parallel/test-os.js:

  • Two instances of == that are better as ===
  • Several instances of .indexOf() that can be rewritten using .includes() for more clarity
  • Bonus optional change: The os module has an undocumented and deprecated function os.getNetworkInterfaces() that is not tested at all. Write a minimal test for it.
@Trott
Trott / test-globals-descriptors.js
Created December 22, 2016 04:29
sample test for proposed change to Node.js global
'use strict';
require('../common');
const assert = require('assert');
assert(!Object.keys(global).includes('global'),
'global should be non-enumerable');
@Trott
Trott / diff.txt
Created November 17, 2017 07:15
Node.fz vs. nodejs master conflicts
diff --cc .gitignore
index 5951901b65,3d6b7a51a3..0000000000
--- a/.gitignore
+++ b/.gitignore
@@@ -1,20 -1,4 +1,24 @@@
++<<<<<<< HEAD
+# Whitelist dotfiles
+.*
+!deps/**/.*
+!test/fixtures/**/.*
$ nvm use 8.11.3
Now using node v8.11.3 (npm v5.6.0)
$ node
> path.win32.resolve('D:\\work\repl', '/SOME_SOMEELSE_2018-10-11T00-37-36.html') 
'D:\\SOME_SOMEELSE_2018-10-11T00-37-36.html'
> path.win32.resolve('D:\\work\\repl', 'SOME_SOMEELSE_2018-10-11T00-37-36.html') 
'D:\\work\\repl\\SOME_SOMEELSE_2018-10-11T00-37-36.html'
> 
const { Worker, isMainThread, parentPort } = require('worker_threads');
if (isMainThread) {
// This code is executed in the main thread and not in the worker.
// Create the worker.
const worker = new Worker(__filename);
// Listen for messages from the worker and print them.
worker.on('message', (msg) => { console.log(msg); });
} else {
// This code is executed in the worker and not in the main thread.
'use strict';
const min = 2;
const max = 1e7;
const primes = [];
function generatePrimes(start, range) {
let isPrime = true;
let end = start + range;
for (let i = start; i < end; i++) {
for (let j = min; j < Math.sqrt(end); j++) {
if (i !== j && i%j === 0) {
'use strict';
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const min = 2;
let primes = [];
function generatePrimes(start, range) {
let isPrime = true;
let end = start + range;
for (let i = start; i < end; i++) {
for (let j = min; j < Math.sqrt(end); j++) {
if (i !== j && i%j === 0) {
@Trott
Trott / test.js
Created January 14, 2019 04:29
Only assigns available ports
// Testing for macOS, which supplies available ports sequentially.
var net = require('net');
createServer(0, function () {
var port = this.address().port;
console.log('server was assigned port ' + port);
createServer(port+1, function () {
var port = this.address().port;
console.log('server was assigned port ' + port);
'use strict'
const individualTrack = require('music-routes-data/data/individual_track.json')
const tracks1 = []
const tracks2 = []
const individuals1 = []
const individuals2 = []
const allIndividuals = require('music-routes-data/data/individuals.json')
// Use Node.js 11.7.0 or newer to avoid having to use --experimental-workers flag
'use strict'
const { Worker } = require('worker_threads')
const individualTrack = require('music-routes-data/data/individual_track.json')
const tracks = [[], []]
const individuals = [[], []]