Skip to content

Instantly share code, notes, and snippets.

👨‍💻
coding

Sagiv Ofek sagivo

👨‍💻
coding
Block or report user

Report or block sagivo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 3.cc
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());
}
View hello.js
var addon = require('./build/Release/addon');
console.log(addon.hello()); // will print 'world'
View binding.gyp
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ]
}
]
}
View 2.cc
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
View 1.cc
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
View gist:878c563cbc81ebe350db
```cpp
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
```
View gist:77f9e8e9314947500e88
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
View hello.cc
#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 Aug 29, 2015
mergesort async with limit
View gist:2b8b81e9cf1b3d48ce51
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
View gist:2398b4ace8f830ad4d56
$ 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
You can’t perform that action at this time.