Skip to content

Instantly share code, notes, and snippets.

@evanlucas
evanlucas / tap-async-hooks-bug.js
Created April 28, 2022 13:53
tap test with async_hooks abort
'use strict'
const {EventEmitter, once} = require('events')
const fs = require('fs/promises')
const {
setImmediate: defer
, setTimeout: sleep
} = require('timers/promises')
const tap = require('tap')
'use strict'
const fs = require('fs').promises
const path = require('path')
async function* getPaths(p, depth = 0) {
const dir = await fs.opendir(p, {
bufferSize: 1
})
@evanlucas
evanlucas / node.diff
Created July 21, 2020 13:50
diff that gets tests working on arm64
diff --git a/deps/v8/src/base/platform/platform-macos.cc b/deps/v8/src/base/platform/platform-macos.cc
index bee6b30f7c..055da2605e 100644
--- a/deps/v8/src/base/platform/platform-macos.cc
+++ b/deps/v8/src/base/platform/platform-macos.cc
@@ -49,7 +49,7 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
for (unsigned int i = 0; i < images_count; ++i) {
const mach_header* header = _dyld_get_image_header(i);
if (header == nullptr) continue;
-#if V8_HOST_ARCH_X64
+#if V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64
@evanlucas
evanlucas / c_cpp_properties.json
Last active June 25, 2020 11:27
WIP vscode configuration for Node.js core
{
"configurations": [
{
"name": "Mac",
"intelliSenseMode": "clang-x64",
"cppStandard": "gnu++14",
"includePath": [
"src/**",
"deps/histogram/src/",
"deps/uvwasi/include/",
@evanlucas
evanlucas / index.js
Last active July 1, 2020 09:02
Node proxy
'use strict'
const http = require('http')
const url = require('url')
function random(ar) {
return ar[Math.floor(Math.random() * ar.length)]
}
function createDownstream() {
@evanlucas
evanlucas / require.js
Last active December 26, 2018 02:17
See your most expensive requires
'use strict'
const Module = require('module')
const original = Module.prototype.require
const items = new Map()
function sorter(a, b) {
if (a < b) return -1
if (a > b) return 1

Hack to log when a React component gets rendered

Set localStorage.debug = 'react'.

Make sure you install this before calling ReactDOM.render()

@evanlucas
evanlucas / test.js
Created February 1, 2018 16:31
async-listener fails with promisified sleep
'use strict'
const {promisify} = require('util')
const args = process.argv.splice(2)
for (const arg of args) {
if (arg === 'async-listener') require('async-listener')
}
const sleep = promisify(setTimeout)
@evanlucas
evanlucas / ee-debug.js
Created December 19, 2017 19:41
Show every event that is emitted
'use strict'
const EE = require('events')
const emit = EE.prototype.emit
EE.prototype.emit = function(name, ...args) {
if (this.constructor) {
console.log('EMIT', this.constructor.name, name)
} else {
console.log('EMIT', '<unknown>', name)
}
@evanlucas
evanlucas / after.js
Last active November 16, 2017 22:54
testing
// After
const {test} = require('tap')
test('GET /users', async (t) => {
const user_state = {}
const {body: org} = await request
.post('/organizations')
.expect(200)