Skip to content

Instantly share code, notes, and snippets.

View trevnorris's full-sized avatar

Trevor Norris trevnorris

View GitHub Profile
@trevnorris
trevnorris / loop_to_timeseries.cc
Last active October 5, 2023 22:58
Convert discrete data from irregular duration event loop iterations to time series data using a Poisson window function
/* Calculate the exponential moving average using the Poisson window function
* combined with a time constant adjustment so even though the calculation is
* only done once every loop, the smoothing curve acts as if it was time-series
* data.
*
* The expanded equation for this is:
*
* /-ΔT \
* |----|
* \ τ /
diff --git a/test/test-list.h b/test/test-list.h
index 13c96d1d..81f2aa25 100644
--- a/test/test-list.h
+++ b/test/test-list.h
@@ -556,6 +556,7 @@ TEST_DECLARE (utf8_decode1_overrun)
TEST_DECLARE (uname)
TEST_DECLARE (metrics_info_check)
+TEST_DECLARE (metrics_fs_events)
TEST_DECLARE (metrics_idle_time)
@trevnorris
trevnorris / example_output.log
Created November 16, 2022 19:33
Use async_hooks to automatically create stack traces of resources
8 TickObject
at AsyncStackTrace.initFn (index.js:89:18)
6 TCPWRAP
at AsyncStackTrace.initFn (index.js:89:18)
3 TCPSERVERWRAP
at AsyncStackTrace.initFn (index.js:89:18)
at Object.<anonymous> (test/http-noop.js:11:4)
// Call this function with the number of levels in the queue.
// It will return the weighted random position.
function getPosition(n) {
return n - tRoot(randomT(n));
}
function triangular(n) {
return n * (n + 1) / 2;
}
Example Event Loop Execution Timeline
L₁ L₂ L₃ L₄
(1) ━━━┪ ┏━━━━━━━━━━━━━━╈┳━━━━━━━━━┯━━━━━━━━━━━╈┳━━━━┓ ┢━━━━━
┃ ┃ e₁ ┃┃ e₂ │ e₃ ┃┃ e₄ ┃ ┃ e₅
───┨ ┠──────────────┨┠─────────┼───────────╂╂────┨ ┠─────
(2) ┄┄┄┺━━━╃┄┄┄┄┄┄┄┄┄┄┄┄┄┄┺╃┄┄┄┄┄┄┄┄┄┴┄┄┄┄┄┄┄┄┄┄┄┺╃┄┄┄┄┺━━━━╃┄┄┄┄┄
│ [e₂] [e₃] │ [e₄] │ │
[e₁] [e₂] [e₄] [e₅]
[e₃]
@trevnorris
trevnorris / 01_pass_template_fn_to_fn_ptr.cc
Last active January 27, 2020 21:36
various c++ code examples demonstrating different techniques
// Demonstrates how to pass a template function to a non-template function
// pointer by specifying the template parameter when it's assigned.
// This allows the void* to be safely cast when the function is called.
#include <cstdio>
struct A { int val = 42; };
struct B { int foo = 0; int val = 45; };
void (*cbp)(void*);
@trevnorris
trevnorris / git_cheat_sheet.md
Last active January 29, 2020 00:09
cheat sheet of git commands I use

note: A lot of this assumes a repo has already been forked.

Basics

First make sure all your commits have your name/email:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL"
@trevnorris
trevnorris / build_steps.txt
Last active August 10, 2018 20:30
How to build node with shared libuv
libuv:
$ ./gyp_uv.py -f make -Dlibrary=shared_library
$ BUILDTYPE=Release make -j6 -C out
node:
$ ./configure --shared-libuv --shared-libuv-includes=$LIBUV_PATH/include --shared-libuv-libpath=$LIBUV_PATH/out/Release
$ make -j6
binary build:
$ CONFIG_FLAGS="--shared-libuv --shared-libuv-includes=$LIBUV_PATH/libuv/include --shared-libuv-libpath=$LIBUV_PATH/out/Release" DISTTYPE=custom CUSTOMTAG="$(date +'%s')" make -j6 binary
diff --git a/test/addons/async-hello-world/binding.cc b/test/addons/async-hello-world/binding.cc
index da2bd41..5ddd61f 100644
--- a/test/addons/async-hello-world/binding.cc
+++ b/test/addons/async-hello-world/binding.cc
@@ -44,13 +44,11 @@ void AfterAsync(uv_work_t* r) {
v8::Local<v8::Function>::New(isolate, req->callback);
callback->Call(isolate->GetCurrentContext()->Global(), 2, argv);
+ printf("did rethrow: %s\n", !try_catch.ReThrow().IsEmpty() ? "true" : "false");
+
'use strict';
Error.stackTraceLimit = Infinity;
const dgram = require('dgram');
const print = process._rawDebug;
// Problem doesn't exist with localhost, so plug in a Google server's IP.
const HOST = '172.217.5.110';
const client = dgram.createSocket('udp4');
const message = Buffer.alloc((1 << 16) - 29);