Skip to content

Instantly share code, notes, and snippets.

View NickNaso's full-sized avatar
🎯
Focusing

Nicola Del Gobbo NickNaso

🎯
Focusing
View GitHub Profile
@NickNaso
NickNaso / binding.cpp
Last active November 8, 2019 21:15
Pass object to AsyncWorker
#include<napi.h>
#include <chrono>
#include <thread>
use namespace Napi;
class EchoWorker : public AsyncWorker {
public:
EchoWorker(Function& callback, Object& options, std::string& echo)
@NickNaso
NickNaso / upload.js
Created September 26, 2019 16:08 — forked from virolea/upload.js
Tracking file upload progress using axios
upload(files) {
const config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
console.log(percentCompleted)
}
}
let data = new FormData()
data.append('file', files[0])
@NickNaso
NickNaso / nvm-node-nightlies.md
Created August 13, 2019 13:09 — forked from chicoxyzzy/nvm-node-nightlies.md
Installing Node Nightlies via nvm

You can install Node Nightlies/RCs via nvm using NVM_NODEJS_ORG_MIRROR environment variable.

Install latest Node RC

NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/rc/ nvm i node

Install latest Node.js Nightly

NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly/ nvm i node
@NickNaso
NickNaso / addon.js
Created June 27, 2019 17:16 — forked from gabrielschulhof/addon.js
Send modules to native
const addon = require('bindings')('addon');
addon.receiveModule('fs', require('fs'));
addon.receiveModule('crypto', require('crypto'));
console.log(addon.sendModule('fs') === require('fs'));
console.log(addon.sendModule('crypto') === require('crypto'));
@NickNaso
NickNaso / CMakeLists.txt
Created June 12, 2019 15:50
CMake file to build cerberus addon with cmakejs
cmake_minimum_required(VERSION 2.8)
set (CMAKE_CXX_STANDARD 11)
# Name of the project (will be the name of the plugin)
project(Cerberus)
set(VLC_LIB_DIR ${CMAKE_SOURCE_DIR} "libvlcpp/vlcpp")
if(MSVC)
@NickNaso
NickNaso / webpack-bundle-for-node.js
Last active May 27, 2019 08:27
Configuration sample to create bundle for node.js application using webpack
const path = require('path')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
module.exports = {
entry: {
server: './server.js',
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
@NickNaso
NickNaso / closures-basic.c
Created March 17, 2019 22:19 — forked from vidarh/closures-basic.c
A number of ways to implement closures in C, in preparation of an upcoming blog post
#include <stdio.h>
#include <stdlib.h>
struct closure {
void (* call)(struct closure *);
int x;
};
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {
@NickNaso
NickNaso / express-axios-example.js
Last active October 31, 2018 20:50
Example how to use axios from Node.js
'use strict'
const axios = require('axios')
const express = require('express')
const app = express()
app.use((err, req, res, next) => {
console.error('Error happened ...')
console.log(err)
res.status(500).json({error: 'Error happened on your application', code: 'E500'})
@NickNaso
NickNaso / binding.cc
Created September 19, 2018 18:44 — forked from gabrielschulhof/binding.cc
Doing extends on the native side
#include <stdio.h>
#include <node.h>
static void
NativeClassConstructor(const v8::FunctionCallbackInfo<v8::Value>& info) {
}
static void
NativeClassProtoMethod(const v8::FunctionCallbackInfo<v8::Value>& info) {
fprintf(stderr, "NativeClassProtoMethod was called\n");