Skip to content

Instantly share code, notes, and snippets.

View NickNaso's full-sized avatar
🎯
Focusing

Nicola Del Gobbo NickNaso

🎯
Focusing
View GitHub Profile
{
"targets": [
{
"target_name": "example_addon",
"sources": [ "example_addon.c" ],
"include_dirs": [ "<!@(node -p \"require('node-addon-api').include\")" ],
"dependencies": [ "<!@(node -p \"require('node-addon-api').gyp\")" ]
}
]
}
@NickNaso
NickNaso / nodejs-custom-es6-errors.md
Created January 19, 2018 14:45 — forked from slavafomin/nodejs-custom-es6-errors.md
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@NickNaso
NickNaso / load-from-stream.c
Created March 29, 2018 20:22 — forked from jcupitt/load-from-stream.c
test libvips load from stream
/* test load from stream
*
* compile with:
*
* gcc -g -Wall load-from-stream.c `pkg-config vips --cflags --libs`
*
* test with:
*
* cat k2.jpg k4.jpg | ./a.out
*/
@NickNaso
NickNaso / event-emitter-usage.js
Last active May 15, 2018 14:54
How to use Event Emitter
'use strict'
const { EventEmitter } = require('events')
function print(evt) {
console.log('#####')
console.log('Event: ', evt.name)
if (evt.data) {
console.log(evt.data)
}
@NickNaso
NickNaso / node-install.sh
Created April 29, 2018 11:53
Node.js Installation script for Linux
#!/bin/bash
echo "Node Linux Installer by www.github.com/taaem"
echo "Need Root for installing NodeJS"
sudo sh -c 'echo "Got Root!"'
echo "Get Latest Version Number..."
{
wget --output-document=node-updater.html https://nodejs.org/dist/latest/
@NickNaso
NickNaso / gist:181974062972fb83b877e586c9b97687
Created May 22, 2018 20:57 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
'use strict'
const EventEmitter = require('events').EventEmitter
const addon = require('bindings')('emit_from_cpp')
const emitter = new EventEmitter()
emitter.on('start', () => {
console.log('### START ...')
})
#include<napi.h>
#include <chrono>
#include <thread>
#include <iostream>
Napi::Value CallEmit(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Function emit = info[0].As<Napi::Function>();
emit.Call({Napi::String::New(env, "start")});
@NickNaso
NickNaso / inherits-from-event-emitter.js
Created May 25, 2018 18:09
Inherits from Event Emitter
'use strict'
const EventEmitter = require('events').EventEmitter
const NativeEmitter = require('bindings')('native_emitter').NativeEmitter
const inherits = require('util').inherits
inherits(NativeEmitter, EventEmitter)
const emitter = new NativeEmitter()
@NickNaso
NickNaso / native-emitter-implementation.cc
Created May 25, 2018 18:13
Native emitter implementation
#include <chrono>
#include <thread>
#include <iostream>
#include "native-emitter.h"
Napi::FunctionReference NativeEmitter::constructor;
Napi::Object NativeEmitter::Init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);