Skip to content

Instantly share code, notes, and snippets.

View NickNaso's full-sized avatar
🎯
Focusing

Nicola Del Gobbo NickNaso

🎯
Focusing
View GitHub Profile
@cliffano
cliffano / gist:5465541
Created April 26, 2013 07:29
Node modules with latest version having gypfile: true
kingkong:/tmp/gypfilecheck$ time couchtato iterate -u http://host/registry -p 5000
retrieved 5000 docs - 0
>> LDAP 1.1.4 has gypfile: true
>> airtunes 0.1.3 has gypfile: true
>> aligned-buffer 0.1.2 has gypfile: true
>> allsync 0.0.3b has gypfile: true
>> ancillary 2.0.0 has gypfile: true
>> aplus 0.1.0 has gypfile: true
>> base128 0.1.0 has gypfile: true
>> bcrypt 0.7.5 has gypfile: true
@tpitale
tpitale / svg-to-vector-pdf.sh
Last active January 6, 2018 13:48
Loop to rsvg-convert all SVG files to Vector PDF
for i in `ls *.svg`
rsvg-convert -f pdf -o PDF/${i}.pdf $i
@jcupitt
jcupitt / load-from-stream.c
Last active March 29, 2018 20:22
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
*/
@indexzero
indexzero / bench.log
Created September 27, 2017 05:37
winston@3 gets very close to pino
Benchmark: ""pino"" is the fastest.
- winston1 faster than winston2 by 1.1696
- winston3 faster than winston1 by 1.5686
- bunyan faster than winston1 by 1.0245
- pino faster than winston1 by 1.8904
- winston3 faster than winston2 by 1.8347
- bunyan faster than winston2 by 1.1983
- pino faster than winston2 by 2.2109
- winston3 faster than bunyan by 1.5311
- pino faster than winston3 by 1.2051
@gabrielschulhof
gabrielschulhof / binding.cc
Last active July 6, 2018 13:16
GC behaviour wrt. native function vs. plain object vs. JS function
#include <stdio.h>
#include <node.h>
class WeakRef {
public:
WeakRef(v8::Isolate* isolate, v8::Local<v8::Value> func, const char* string):
string_(string) {
pers_.Reset(isolate, func);
pers_.SetWeak(this, DeleteMe, v8::WeakCallbackType::kParameter);
}
@thlorenz
thlorenz / .generating-xcode-via-gyp.md
Last active August 26, 2018 15:05
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.

@thlorenz
thlorenz / async-wrap-express-wrapper.md
Last active August 26, 2018 15:09
async/wrap express wrapper

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'
@thlorenz
thlorenz / Reusing Errors vs. creating new Error with stack attached.md
Last active August 26, 2018 15:12
Reusing Errors vs. creating new Error with stack attached

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
@gabrielschulhof
gabrielschulhof / binding.cc
Last active September 19, 2018 18:44
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");
@gabrielschulhof
gabrielschulhof / addon.js
Created June 27, 2019 17:02
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'));