Skip to content

Instantly share code, notes, and snippets.

View trevnorris's full-sized avatar

Trevor Norris trevnorris

View GitHub Profile
#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;
@trevnorris
trevnorris / hello-world.js
Created April 11, 2014 07:57
Playing the "who's bigger" hello world game.
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 August 29, 2015 14:03
(do not delete) Snippets for performance workshops
/**
 * 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(buf-&gt;GetIndexedPropertiesExternalArrayData());
@trevnorris
trevnorris / irhydra-fix.diff
Created October 1, 2014 20:58
Patch to fix IRHydra support by back porting the patch to 3.28
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 August 29, 2015 14:08
Crazy physics done in integer space, to prevent floating point calculations.
// 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
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
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') {
var async_wrap = process.binding('async_wrap');
var b = {};
function initHook() {
this._asyncQueue = {};
}
function preHook() {
throw new Error('preHook');
}
diff --git a/src/haywire/http_server.c b/src/haywire/http_server.c
index 6f18b9b..3591aca 100644
--- a/src/haywire/http_server.c
+++ b/src/haywire/http_server.c
@@ -78,6 +78,7 @@ void free_http_connection(http_connection* connection)
free_http_request(connection->request);
}
+ free(connection->thread);
free(connection);
@trevnorris
trevnorris / sem-bounce.c
Last active August 29, 2015 14:10
bounce back and forth between threads using semaphores
/* Compiled with
* clang -pthread -fno-omit-frame-pointer -Wall -g -fstrict-aliasing -O3 \
* -o sem-bounce sem-bounce.c libuv.a -Iuv/include
*/
#include "uv.h"
#define ITER 1e6
static uv_thread_t thread;