Skip to content

Instantly share code, notes, and snippets.

Trevor Norris trevnorris

View GitHub Profile
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) {
View rethrow_without_verbose.diff
diff --git a/test/addons/async-hello-world/ b/test/addons/async-hello-world/
index da2bd41..5ddd61f 100644
--- a/test/addons/async-hello-world/
+++ b/test/addons/async-hello-world/
@@ -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");
View .tmux.conf
# basic configs #
setw -g mode-keys vi
set -g default-terminal "xterm-256color"
set -g history-limit 10000
# C-a is escape sequence #
unbind C-b
set -g prefix C-a
bind C-a last-window
bind a send-prefix
View udp_client.js
'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 = '';
const client = dgram.createSocket('udp4');
const message = Buffer.alloc((1 << 16) - 29);
trevnorris / fs-scan-n-read-bench.js
Last active Mar 11, 2017
Benchmark to show performance difference between fs sync and async calls
View fs-scan-n-read-bench.js
'use strict';
const MAX_DEPTH = 4;
const fs = require('fs');
const print = process._rawDebug;
const sep = require('path').sep;
const tmpdir = require('os').tmpdir() + sep + 'data-file-bench-' + genName();
const file_list = newDir();
var current_dir = file_list;
You can’t perform that action at this time.