This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Binding(const FunctionCallbackInfo<Value>& args) { | |
Environment* env = Environment::GetCurrent(args); | |
Local<String> module = args[0]->ToString(env->isolate()); | |
node::Utf8Value module_v(env->isolate(), module); | |
Local<Object> cache = env->binding_cache_object(); | |
Local<Object> exports; | |
if (cache->Has(module)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a template for the global object and set the built-in global functions | |
Local<ObjectTemplate> global = ObjectTemplate::New(isolate); | |
global->Set( | |
String::NewFromUtf8(isolate, "log"), | |
FunctionTemplate::New(isolate, LogCallback) | |
); | |
// Each processor gets its own context so different processors do not affect each other | |
Persistent<Context> context = Context::New(isolate, NULL, global); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new context. | |
Local<Context> context = Context::New(isolate); | |
// Enter the context for compiling and running the hello world script. | |
Context::Scope context_scope(context); | |
// Create a string containing the JavaScript source code. | |
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
// Compile the source code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Mocha Guide to Testing | |
// Objective is to explain describe(), it(), and before()/etc hooks | |
// 1. `describe()` is merely for grouping, which you can nest as deep | |
// 2. `it()` is a test case | |
// 3. `before()`, `beforeEach()`, `after()`, `afterEach()` are hooks to run | |
// before/after first/each it() or describe(). | |
// | |
// Which means, `before()` is run before first it()/describe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function CustomError(message, extra) { | |
Error.captureStackTrace(this, this.constructor); | |
this.name = this.constructor.name; | |
this.message = message; | |
this.extra = extra; | |
}; | |
require('util').inherits(module.exports, Error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nodejs encryption with GCM | |
// Does not work with nodejs v0.10.31 | |
// Part of https://github.com/chris-rock/node-crypto-examples | |
var crypto = require('crypto'), | |
algorithm = 'aes-256-gcm', | |
password = '3zTvzr3p67VC61jmV54rIYu1545x4TlY', | |
// do not use a global iv for production, | |
// generate a new one for each encryption | |
iv = '60iP0h6vJoEa' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part of https://github.com/chris-rock/node-crypto-examples | |
// Nodejs encryption of buffers | |
var crypto = require('crypto'), | |
algorithm = 'aes-256-ctr', | |
password = 'd6F3Efeq'; | |
var fs = require('fs'); | |
var zlib = require('zlib'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part of https://github.com/chris-rock/node-crypto-examples | |
var crypto = require('crypto'), | |
algorithm = 'aes-256-ctr', | |
password = 'd6F3Efeq'; | |
function encrypt(buffer){ | |
var cipher = crypto.createCipher(algorithm,password) | |
var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]); | |
return crypted; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part of https://github.com/chris-rock/node-crypto-examples | |
// Nodejs encryption with CTR | |
var crypto = require('crypto'), | |
algorithm = 'aes-256-ctr', | |
password = 'd6F3Efeq'; | |
function encrypt(text){ | |
var cipher = crypto.createCipher(algorithm,password) | |
var crypted = cipher.update(text,'utf8','hex') |