Skip to content

Instantly share code, notes, and snippets.

// Type and StructType both inherit Napi::ObjectWrap.
// And they both have a static member called constructor `static inline Napi::FunctionReference constructor;`
void StructType::Init(Napi::Env env, Napi::Object &exports) {
Napi::HandleScope scope(env);
Napi::Function super_func = Type::constructor.Value();
napi_value super_ctor = napi_value(super_func);
Napi::Function func = DefineSubClass(env, super_ctor, "StructType", {
StaticMethod("create", &StructType::create),
InstanceMethod("setBody", &StructType::setBody)
});
const data = {
cities: [
["New York", 40.66361111111111, -73.93861111111111],
["Los Angeles", 34.019444444444446, -118.41083333333334],
["Chicago", 41.837500000000006, -87.68166666666667],
["Houston", 29.78666666666667, -95.39083333333333],
["Phoenix", 33.57222222222222, -112.08999999999999],
["Philadelphia", 40.00944444444445, -75.13333333333334],
["San Antonio", 29.472499999999997, -98.525],
["San Diego", 32.81527777777777, -117.135],
int maxSubSequence(int arr[], int n)
{
int sum = 0, maxSum = 0;
for (int i = 0; i < n; i++)
{
sum += arr[i];
if (sum > maxSum)
maxSum = sum;
else if (sum < 0)
{
@ApsarasX
ApsarasX / sort.cpp
Last active March 11, 2018 13:40
各种排序方法(C/C++语言版本)
#include <iostream>
#include <math.h>
using namespace std;
//-------------------------------------------------------------------------------------
// 直接插入排序
void insertionSort(int arr[], int n, int g)
{
for (int i = g; i < n; i++)
{
@ApsarasX
ApsarasX / copy.js
Last active September 2, 2017 12:42
Node Learning
const fs = require('fs');
function copy(src, dst) {
//小文件拷贝
fs.writeFileSync(dst,fs.readFileSync(src));
//大文件拷贝
//fs.createReadStream(src).pipe(fs.createWriteStream(dst));
}
function main(argv) {
copy(argv[0], argv[1]);
@ApsarasX
ApsarasX / gcd-lcm.js
Created August 30, 2017 12:56
about gcd and lcm(关于最大公约数和最小公倍数)
function gcd(x, y) {
while (y) {
[x, y] = [y, x % y];
}
return x;
}
const lcm = (x,y) => x * y / gcd(x,y);
function multipleLCM(...nums) {
@ApsarasX
ApsarasX / generatePrimes.js
Last active August 30, 2017 12:04
About Prim(关于质数的一些操作)
function generatePrimesList(num) {
let ret = [];
if (num >= 2)
ret.push(2);
for (let i = 3; i <= num; i++) {
let flag = true;
for (let j = 0; j < ret.length; j++) {
if (i % ret[j] === 0) {
flag = false;
break;
@ApsarasX
ApsarasX / intToRoman.js
Created August 28, 2017 13:33
Int to Roman(整数转为罗马数字)(1-3999999)
function convert(num) {
// suppose num>0&&num<4000000
if(!Number.isInteger(num)) {
throw 'Sorry, there are only integers in Rome numerals.';
} else if(num<0) {
throw 'Sorry, there is no negative in Roman numerals.';
} else if(num===0) {
throw 'Sorry, there is no zero in Roman numerals.';
} else if(num>=4000000) {
throw 'Sorrt, 4000000 and more are too high.';