Skip to content

Instantly share code, notes, and snippets.

View NickNaso's full-sized avatar
🎯
Focusing

Nicola Del Gobbo NickNaso

🎯
Focusing
View GitHub Profile
#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")});
'use strict'
const EventEmitter = require('events').EventEmitter
const addon = require('bindings')('emit_from_cpp')
const emitter = new EventEmitter()
emitter.on('start', () => {
console.log('### START ...')
})
@NickNaso
NickNaso / gist:181974062972fb83b877e586c9b97687
Created May 22, 2018 20:57 — forked from stuart11n/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
@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 / 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 / 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 / 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

{
"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 / README.md
Created January 9, 2018 23:26 — forked from joyrexus/README.md
Node.js streams demystified

A quick overview of the node.js streams interface with basic examples.

This is based on @brycebaril's presentation, Node.js Streams2 Demystified

Overview

Streams are a first-class construct in Node.js for handling data.

Think of them as as lazy evaluation applied to data.

@NickNaso
NickNaso / svg-to-vector-pdf.sh
Created January 6, 2018 13:48 — forked from tpitale/svg-to-vector-pdf.sh
Loop to rsvg-convert all SVG files to Vector PDF
for i in `ls *.svg`
rsvg-convert -f pdf -o PDF/${i}.pdf $i