Skip to content

Instantly share code, notes, and snippets.

View trevnorris's full-sized avatar

Trevor Norris trevnorris

View GitHub Profile
@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 / 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*);

Notes:

  • Text in [[ ]] are the internal libuv function call.
  • Text in {{ }} are the Node functions that are affected.
  • Text in ( ) are notes about what is happening.
  • While the Windows event loop has minor variations, I don't believe any of those affect Node.

On process.nextTick():

@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
native-stream.js uses the reference implementation, compiled with babel to run
on latest io.js.
stream-bluebird.js is exactly the same as native-stream.js except it uses the
latest bluebird Promise implementation.
node-stream.js uses the node stream implementation and forced to be async by
using process.nextTick() (which is functionally equivalent to the microtask
processor)
@trevnorris
trevnorris / all-my-knowledge.md
Last active December 9, 2017 00:39
Here's a rundown of everything I use to do performance analysis in Node.

Introduction

Here is a collection of tips and tricks I've picked up about doing performance analysis on Node. Included is a build script that should get a base install of Ubuntu fully functional and ready for all the things we'll be going through.

The script pulls a lot of code from the latest master of each repository. So it's possible that something may fail, but to date I haven't had any issues.

First, go ahead and run the script. Then go take a nice long break. It'll

#include <stdio.h>
#include <assert.h>
#include "uv.h"
#define ITER 1e6
#define ACCESS_ONCE(type, var) \
(*(volatile type*) &(var))
static uv_mutex_t mutex;
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);
@trevnorris
trevnorris / binding.gyp
Created December 1, 2016 22:28
Example of returning all values from uv_rusage() as tuples w/ no overhead. Values are only valid until getrusage() is called again.
{
"targets": [{
"target_name": "addon",
"sources": [ "main.cc" ]
}]
}