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 / carray2slice.go
Created November 19, 2019 17:57 — forked from nasitra/carray2slice.go
Convert 'C' array to golang slice
func carray2slice(array *C.int, len int) []C.int {
var list []C.int
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&list)))
sliceHeader.Cap = len
sliceHeader.Len = len
sliceHeader.Data = uintptr(unsafe.Pointer(array))
return list
}
@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 / 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 / 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");

It is not usually recommended to reuse errors since the stack trace is attached whenever the error is instantiated.

However in some cases the overhead of doing that may affect performance, especially if the error is an exception that is known to occur frequently and is handled.

Only in these cases it may be advantagous to reuse the created Error. In all other cases getting a full stacktrace created at the time the exception occurs is to be preferred as it gives much better information needed to debug the problem.

Run

➝ node errors.js

Summary

Tried to improve debugging when an express middleware is wrapped to auto-handle errors of an asnync function.

Turns out the below reads a bit better than a return Promise.catch() implementation, but still, once we reach the central express error handler, the line of the wrapped function that caused the error isn't included.

Implementation

'use strict'
@NickNaso
NickNaso / .generating-xcode-via-gyp.md
Created August 26, 2018 15:05 — forked from thlorenz/.generating-xcode-via-gyp.md
Generating Xcode projects from Node.js binding repos via gyp

This is specifically tailored to Node.js binding projects in which case the C++ layer is always a library.

Clone gyp:

git clone --depth 1 https://chromium.googlesource.com/external/gyp.git gyp

Add the below common.gypi file in the root of the project.