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.gyp
Created December 24, 2017 22:22
bcrypt-napi binding.gyp
{
'targets': [
{
'target_name': 'bcrypt_napi',
'sources': [
'src/blowfish.cc',
'src/bcrypt.cc',
'src/bcrypt_node.cc'
],
'cflags!': [ '-fno-exceptions' ],
@NickNaso
NickNaso / bcrypt_node.cc
Created December 24, 2017 22:35
bcrypt-napi init
Napi::Object init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "gen_salt_sync"), Napi::Function::New(env, GenerateSaltSync));
exports.Set(Napi::String::New(env, "encrypt_sync"), Napi::Function::New(env, EncryptSync));
exports.Set(Napi::String::New(env, "compare_sync"), Napi::Function::New(env, CompareSync));
exports.Set(Napi::String::New(env, "get_rounds"), Napi::Function::New(env, GetRounds));
exports.Set(Napi::String::New(env, "gen_salt"), Napi::Function::New(env, GenerateSalt));
exports.Set(Napi::String::New(env, "encrypt"), Napi::Function::New(env, Encrypt));
exports.Set(Napi::String::New(env, "compare"), Napi::Function::New(env, Compare));
return exports;
};
@NickNaso
NickNaso / bcrypt_node.cc
Created December 24, 2017 22:48
bcrypt-napi
class SaltAsyncWorker : public Napi::AsyncWorker {
public:
SaltAsyncWorker(Napi::Function& callback, std::string seed, ssize_t rounds)
: Napi::AsyncWorker(callback), seed(seed), rounds(rounds) {
}
~SaltAsyncWorker() {}
void Execute() {
char salt[_SALT_LEN];
@NickNaso
NickNaso / hertzy.js
Created January 3, 2018 21:42
Hertzy example
'use strict'
const const Hertzy = require('hertzy')
// Obtain or create new frequency, a channel where you can emit or listen for an
// event issued by other modules
const usr = Hertzy.tune('user')
// Listen for event 'user:add'
usr.on('user:add', function (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
@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.

{
"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 / helpers.cc
Created September 6, 2017 22:27 — forked from AnnaMag/helpers.cc
Helper functions for printing V8 Local-wrapped objects
#include "v8.h"
#include "helpers.h"
#include <iostream>
using v8::Local;
using v8::String;
using v8::Array;
void PrintLocalString(v8::Local<v8::String> key){