Skip to content

Instantly share code, notes, and snippets.

View trevnorris's full-sized avatar

Trevor Norris trevnorris

View GitHub Profile
@trevnorris
trevnorris / ff-jsondb-example-n-comments.js
Created July 14, 2016 03:33
Simple usage of ff-jsondb and how it currently stores/saves data
'use strict';
const db = require('ff-jsondb')(db_path);
// This creates a file at db_path + '/data/file.json' of the stringified
// json_object.
db.set('/data/file', json_object);
// The reads in the file at db_path + '/data/file.json' and returns the parsed
// object.
@trevnorris
trevnorris / on-iso-8859-1.txt
Last active April 28, 2016 21:16
Little history and references on the evolution and existence of ISO-8859-1
ASCII, the American Standard Code for Information Exchange, (or the IANA
preferred US-ASCII) is a 7-bit encoding first standardized in 1960 as part of
the ASA, American Standards Association, X3.2. Though the most recent update
was in 1986 in the ANSI X3.4-1986 standard [1]. This was also standardized in
ISO/IEC 646:1991 [2] and later ratified by ECMA as ECMA-6 [3].
Since ASCII was first standardized there have been proprietary extensions that
use the full 8-bit space. First to do so was IBM and their introduction of
"code pages" (most commonly called character encodings). Those who've used
MS-DOS will recognize CP437 [4]. Along with IBM, other companies such as Apple
@trevnorris
trevnorris / main.cc
Created February 5, 2016 23:53
Run a callback when an object is GC'd
#include <v8.h>
#include <node.h>
using namespace v8;
typedef void (*FreeCallback)(Local<Object> object, Local<Function> fn);
class CallbackStuff {
public:
@trevnorris
trevnorris / set-header-bench.js
Last active February 3, 2016 21:25
Output the number of setHeader() operations per second
'use strict';
const http = require('http');
const net = require('net');
const print = process._rawDebug;
const FIELDS = isNaN(process.argv[2]) ? 128 : process.argv[2] >>> 0;
const PORT = 8080;
const headers =
'GET / HTTP/1.1\r\n' +
@trevnorris
trevnorris / proper_code_column_length.txt
Last active August 9, 2016 20:38
Quick notes on why constraining cpl is an advantage when writing source
While the standard 80 character limit for source code can be traced back to the
IBM punch card[1] it can still be seen as a good upper bound for how long lines
of text should be on modern high definition displays.
First thing we must acknowledge is that source code is not read in the
traditional sense. Instead developers scan the source using non-linear eye
movements[2] or stay fixated in a small area of code while working out the
logical details of code being written. The fixation on a single location, even
for more than a few seconds, leads to a loss of visual accuity. Which occurs
when the eyes do not perform frequent saccadic eye movements.[3] Further
'use strict';
const SlowBuffer = require('buffer').SlowBuffer;
let buf_arr = [];
let str_arr = [];
// Allocate a lot of buffers
for (let i = 0; i < 1024 * 4 * 4; i++) {
buf_arr.push(new SlowBuffer(1024 * 256));
}
#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;
# To display the perf.data header info, please use --header/--header-only options.
#
# Samples: 127K of event 'cycles'
# Event count (approx.): 88135668311
#
# Children Self Command Shared Object Symbol
# ........ ........ ....... ................... ..................................................................................................................................................................................................................................
#
59.57% 0.00% iojs [unknown] [.] 0x4736258d4c544155
|
'use strict';
const SlowBuffer = require('buffer').SlowBuffer;
const ITER = 1e7;
const SIZE = 65536;
let t = process.hrtime()
for (let i = 0; i < ITER; i++) {
new SlowBuffer(SIZE);
}
How to build/use
- Put these in the same folder then run
$ /path/to/nsolid/nsolid $(which node-gyp) rebuild --nodedir=/path/to/nsolid/../
If it builds properly then run
$ /path/to/nsolid/nsolid run.js