Skip to content

Instantly share code, notes, and snippets.

Trevor Norris trevnorris

View GitHub Profile
@trevnorris
trevnorris / 01_pass_template_fn_to_fn_ptr.cc
Last active Jan 27, 2020
various c++ code examples demonstrating different techniques
View 01_pass_template_fn_to_fn_ptr.cc
// 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 Jan 29, 2020
cheat sheet of git commands I use
View git_cheat_sheet.md

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 / watched-anime_2017-10.txt
Created Apr 24, 2019
List of all anime I've watched
View watched-anime_2017-10.txt
.hack//Roots
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.
.hack//SIGN
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
trevnorris / build_steps.txt
Last active Aug 10, 2018
How to build node with shared libuv
View build_steps.txt
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
View main.cc
#include <v8.h>
#include <node.h>
#define NEW_FROM_ONEBYTE(iso, name) \
v8::String::NewFromOneByte( \
iso, \
reinterpret_cast<const uint8_t*>(name), \
NewStringType::kInternalized).ToLocalChecked()
#define RUNTIME_TESTS(V) \
@trevnorris
trevnorris / fn_ptr_trampoline.cc
Created Sep 2, 2017
Use a recast function pointer in a lambda trampoline to allow arbitrary callback signatures
View fn_ptr_trampoline.cc
// Hypothetical asynchronous C library call
typedef void (*future_cb)(void* data);
void call_in_the_future(future_cb cb, void* data) {
cb(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/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");
+
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 = '172.217.5.110';
const client = dgram.createSocket('udp4');
const message = Buffer.alloc((1 << 16) - 29);
@trevnorris
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.