Skip to content

Instantly share code, notes, and snippets.

View sagivo's full-sized avatar
👨‍💻
coding

Sagiv Ofek sagivo

👨‍💻
coding
View GitHub Profile
@sagivo
sagivo / 3.cc
Created September 30, 2015 16:47
void Method(const FunctionCallbackInfo<Value>& args) {
v8::String::Utf8Value nameFromArgs(args[0]->ToString());
std::string name = std::string(*nameFromArgs);
std::string response = "hello " + name;
args.GetReturnValue().Set(Nan::New(response).ToLocalChecked());
}
@sagivo
sagivo / hello.js
Last active September 30, 2015 16:53
var addon = require('./build/Release/addon');
console.log(addon.hello()); // will print 'world'
@sagivo
sagivo / binding.gyp
Last active September 30, 2015 16:53
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ]
}
]
}
@sagivo
sagivo / 2.cc
Created September 30, 2015 16:45
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
@sagivo
sagivo / 1.cc
Last active September 30, 2015 16:44
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
```cpp
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
```
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
#include <node.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
@sagivo
sagivo / gist:2b8b81e9cf1b3d48ce51
Last active August 29, 2015 14:14
mergesort async with limit
func merge_sort_async(l []int, c chan []int) {
if len(l) < 2 {
c <- l
return
}
if len(l) < 500 { //TUNE THIS NUMER AND DONT CREATE EXTRA WORK UNLESS IT'S BIGGER
c <- merge_sort(l)
return
}
mid := len(l) / 2
@sagivo
sagivo / gist:2398b4ace8f830ad4d56
Created February 4, 2015 06:39
benchmark #2 go
$ go test -bench=. -benchtime 10s mergesort_test.go
testing: warning: no tests to run
PASS
BenchmarkMSAsync 1 88944871528 ns/op
ok command-line-arguments 92.272s