Skip to content

Instantly share code, notes, and snippets.


Trevor Norris trevnorris

View GitHub Profile
View triangular_weighted_random.js
// 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;
View unicode_event_loop.txt
Example Event Loop Execution Timeline
L₁ L₂ L₃ L₄
(1) ━━━┪ ┏━━━━━━━━━━━━━━╈┳━━━━━━━━━┯━━━━━━━━━━━╈┳━━━━┓ ┢━━━━━
┃ ┃ e₁ ┃┃ e₂ │ e₃ ┃┃ e₄ ┃ ┃ e₅
───┨ ┠──────────────┨┠─────────┼───────────╂╂────┨ ┠─────
(2) ┄┄┄┺━━━╃┄┄┄┄┄┄┄┄┄┄┄┄┄┄┺╃┄┄┄┄┄┄┄┄┄┴┄┄┄┄┄┄┄┄┄┄┄┺╃┄┄┄┄┺━━━━╃┄┄┄┄┄
│ [e₂] [e₃] │ [e₄] │ │
[e₁] [e₂] [e₄] [e₅]
View 0a8c1c53..e8effd45.diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 088121ff..2abbca03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -418,6 +418,7 @@ if(LIBUV_BUILD_TESTS)
+ test/test-metrics.c
trevnorris /
Last active Jan 27, 2020
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 /
Last active Jan 29, 2020
cheat sheet of git commands I use

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


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

git config --global "YOUR NAME"
git config --global "YOUR EMAIL"
trevnorris / watched-anime_2017-10.txt
Created Apr 24, 2019
List of all anime I've watched
View watched-anime_2017-10.txt
In the online RPG know as "The World," Haseo and his guild mates are on the search for a legendary item. When a rival team challenges them, the conflict has deep repercussions both inside and outside the game, and threatens to change the players forever.
Tsukasa wakes up inside The World, a massive online role-playing game full of magic and monsters, and finds himself unable to log out. How did he end up stuck in this digital realm, and what, exactly, is going on in the real world?
A Certain Magical Index
In a world where magic is as real as science, high-school student Kamijo comes to the aid of a young nun named Index. She's on the run from a magic society that covets the massive library of forbidden knowledge stored in her memory.
A Certain Scientific Railgun
trevnorris / build_steps.txt
Last active Aug 10, 2018
How to build node with shared libuv
View build_steps.txt
$ ./ -f make -Dlibrary=shared_library
$ BUILDTYPE=Release make -j6 -C out
$ ./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
#include <v8.h>
#include <node.h>
#define NEW_FROM_ONEBYTE(iso, name) \
v8::String::NewFromOneByte( \
iso, \
reinterpret_cast<const uint8_t*>(name), \
#define RUNTIME_TESTS(V) \
trevnorris /
Created Sep 2, 2017
Use a recast function pointer in a lambda trampoline to allow arbitrary callback signatures
// Hypothetical asynchronous C library call
typedef void (*future_cb)(void* data);
void call_in_the_future(future_cb cb, void* data) {
template <class C>
struct Base {
template <typename DataType = void*>
void run(void (*cb)(C*, DataType*) = nullptr, DataType* ptr = nullptr) {