Skip to content

Instantly share code, notes, and snippets.

Trevor Norris trevnorris

Block or report user

Report or block trevnorris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View simple-string-search.cc
#include <v8.h>
#include <node.h>
#include <node_buffer.h>
#include <string.h>
using v8::FunctionCallbackInfo;
using v8::Handle;
using v8::Isolate;
using v8::Local;
using v8::Object;
View http-recovery.js
var http = require('http');
var tracing = require('tracing');
var PORT = 8001;
var cntr = 0;
tracing.addAsyncListener({
create: function onCreate(stor, type) {
return type;
},
error: function onError(ctx, stor, err) {
View async-parent-worker.c
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "uv.h"
#define RUNS 1e6
typedef struct {
uv_async_t parent;
@trevnorris
trevnorris / hello-world.js
Created Apr 11, 2014
Playing the "who's bigger" hello world game.
View hello-world.js
var TCP = process.binding('tcp_wrap').TCP;
var SlowBuffer = require('buffer').SlowBuffer;
var util = require('util');
var err;
var headers = 'HTTP/1.1 200 OK\r\n' +
'Connection: Keep-Alive\r\n' +
'Content-Type: text/plain; charset=latin-1\r\n' +
'Content-Length: 12\r\n\r\n' +
'hello world\n';
@trevnorris
trevnorris / perf-workshop-snippets.md
Last active Aug 29, 2015
(do not delete) Snippets for performance workshops
View perf-workshop-snippets.md
/**
 * Ordered fastest to slowest.
 * Different ways to extract data from a Buffer in C++.
 */

void RunMe(const FunctionCallbackInfo<Value>& args) {
  /*
  Local<Object> buf = args[0].As<Object>();
  char* data = static_cast<char*>(buf->GetIndexedPropertiesExternalArrayData());
@trevnorris
trevnorris / irhydra-fix.diff
Created Oct 1, 2014
Patch to fix IRHydra support by back porting the patch to 3.28
View irhydra-fix.diff
diff --git a/deps/v8/src/codegen.cc b/deps/v8/src/codegen.cc
index 6b12d64..a24220d 100644
--- a/deps/v8/src/codegen.cc
+++ b/deps/v8/src/codegen.cc
@@ -190,7 +190,7 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
function->end_position() - function->start_position() + 1;
for (int i = 0; i < source_len; i++) {
if (stream.HasMore()) {
- os << AsUC16(stream.GetNext());
+ os << AsReversiblyEscapedUC16(stream.GetNext());
@trevnorris
trevnorris / falling-body.js
Last active Aug 29, 2015
Crazy physics done in integer space, to prevent floating point calculations.
View falling-body.js
// Distance is in 100nm segments. Will be rounding values in order to keep them
// in integer space. Hopefully no values exceed +/-2^53.
var D = 1e7;
var G = 9.80665 * D;
// Amount of time to calculate for.
var T = 10;
// Number of segments to divide time (60 fps).
var S = 60 * T;
// Initial velocity in m/sec
View domain-abort.patch
diff --git a/lib/domain.js b/lib/domain.js
index afaa922..39e90f4 100644
--- a/lib/domain.js
+++ b/lib/domain.js
@@ -33,7 +33,11 @@ var endMethods = ['end', 'abort', 'destroy', 'destroySoon'];
events.usingDomains = true;
// let the process know we're using domains
-process._usingDomains();
+// The return value let's us know whether --abort-on-uncaught-exception was
View cp-mem-growth.js
var dgram = require('dgram');
var fork = require('child_process').fork;
var PORT = 7845;
var ITER = 1e4;
var MS = 100;
var SHUTDOWN = 1000 * 60;
var cntr = 0;
if (process.argv[2] === 'child') {
View sample-ah-code.js
var async_wrap = process.binding('async_wrap');
var b = {};
function initHook() {
this._asyncQueue = {};
}
function preHook() {
throw new Error('preHook');
}
You can’t perform that action at this time.