Skip to content

Instantly share code, notes, and snippets.

View a7ul's full-sized avatar
🚀

Atul R a7ul

🚀
View GitHub Profile
@a7ul
a7ul / app.js
Last active July 15, 2018 07:07
blog-console-web-ui-color-output
const style = require('ansi-styles');
const express = require('express');
const hello = () =>`
${style.green.open}Hello Green!${style.green.close}
${style.red.open}Hello Red!${style.red.close}
`;
const app = express();
app.get('/hello', (req, res) => {
@a7ul
a7ul / complex.diff
Created June 15, 2018 10:56
blog-on-node-addon-complex-obj
diff --git a/cppsrc/Samples/classexample.cpp b/cppsrc/Samples/classexample.cpp
index 8dfa3cc..834f7ea 100644
--- a/cppsrc/Samples/classexample.cpp
+++ b/cppsrc/Samples/classexample.cpp
@@ -22,8 +22,17 @@ ClassExample::ClassExample(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Cl
Napi::HandleScope scope(env);
int length = info.Length();
- if (length != 1 || !info[0].IsNumber()) {
- Napi::TypeError::New(env, "Number expected").ThrowAsJavaScriptException();
@a7ul
a7ul / class.diff
Last active June 15, 2018 09:56
blog-on-node-addon-add-class-diff
diff --git a/binding.gyp b/binding.gyp
index 2d188af..031bf18 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -5,7 +5,9 @@
"cflags_cc!": [ "-fno-exceptions" ],
"sources": [
"cppsrc/main.cpp",
- "cppsrc/Samples/functionexample.cpp"
+ "cppsrc/Samples/functionexample.cpp",
@a7ul
a7ul / classexample.cpp
Last active August 18, 2019 09:55
blog-on-node-addon-class-wrapper
/* cppsrc/Samples/classexample.cpp */
#include "classexample.h"
Napi::FunctionReference ClassExample::constructor;
Napi::Object ClassExample::Init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Napi::Function func = DefineClass(env, "ClassExample", {
@a7ul
a7ul / actualclass.cpp
Created June 15, 2018 09:18
blog-on-node-addon-class
/* cppsrc/Samples/actualclass.cpp */
#include "actualclass.h"
ActualClass::ActualClass(double value){
this->value_ = value;
}
double ActualClass::getValue()
{
@a7ul
a7ul / add_function.diff
Created June 13, 2018 10:38
blog-on-node-addon-function-with-params
diff --git a/cppsrc/Samples/functionexample.cpp b/cppsrc/Samples/functionexample.cpp
index 0bd9bc2..37b7eb9 100644
--- a/cppsrc/Samples/functionexample.cpp
+++ b/cppsrc/Samples/functionexample.cpp
@@ -4,13 +4,33 @@ std::string functionexample::hello(){
return "Hello World";
}
+int functionexample::add(int a, int b){
+ return a + b;
@a7ul
a7ul / function.diff
Last active June 13, 2018 08:59
blog-on-node-addon-third
diff --git a/binding.gyp b/binding.gyp
index 23b9976..2d188af 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -4,7 +4,8 @@
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"sources": [
- "cppsrc/main.cpp"
+ "cppsrc/main.cpp",
@a7ul
a7ul / index.js
Last active June 13, 2018 07:18
blog-on-node-addons-second
//index.js
const testAddon = require('./build/Release/testaddon.node');
module.exports = testAddon;
@a7ul
a7ul / .gitignore
Last active June 13, 2018 07:09
blog-addons-first
node_modules
*.log
build
@a7ul
a7ul / launchTerminal.js
Last active March 24, 2020 04:18
Launch a command in new terminal - just like react native's metro bundler . This snippet is inspired from react-native source code
const path = require('path');
const childProcess = require('child_process');
const process = require('process');
const shelljs = require('shelljs');
const startServerInNewWindow = () => {
const scriptFile = /^win/.test(process.platform) ?
'startCommand.bat' :
'startCommand.command';