Skip to content

Instantly share code, notes, and snippets.

View fhinkel's full-sized avatar

F. Hinkelmann fhinkel

View GitHub Profile
{
"metadata": {
"toolPackage": "@microsoft/api-extractor",
"toolVersion": "7.8.2-pr1796.0",
"schemaVersion": 1003,
"oldestForwardsCompatibleVersion": 1001
},
"kind": "Package",
"canonicalReference": "@google-cloud/video-intelligence!",
"docComment": "",
@fhinkel
fhinkel / maxGap.js
Last active January 11, 2019 17:17
const maxGap = (arr) => {
const n = arr.length;
let min = Number.POSITIVE_INFINITY;
let max = Number.NEGATIVE_INFINITY;
for (let i = 0; i < n; i++) {
min = Math.min(arr[i], min);
max = Math.max(arr[i], max);
}
let range = max - min;
@fhinkel
fhinkel / createComputeEngine.js
Last active May 24, 2018 13:28
Create minimal Compute Engine instance with Node.js
// Run `npm install @google-cloud/compute` first.
const Compute = require('@google-cloud/compute');
const compute = new Compute();
// Creates a new VM using the latest Ubuntu image.
(async () => {
try {
const zone = await compute.zone('us-central1-a');
const data = await zone.createVM(
'ubuntu-instance',
@fhinkel
fhinkel / createVM.js
Last active April 3, 2020 03:02
Create VM with startup script on GCP using Node.js Client
'use strict';
const Compute = require('@google-cloud/compute');
const http = require('http');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
// Create a new VM, using default ubuntu image. The startup script
{
"name": "profiler-issue",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@fhinkel
fhinkel / primes.cc
Last active December 7, 2017 22:29
#include <napi.h>
#include <math.h>
namespace primes {
// Implementation of isPrime() and prime() omitted. See
// https://github.com/fhinkel/javascript-vs-native-addon-prime-numbers/blob/master/primes.cc
Napi::Value Method(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
@fhinkel
fhinkel / index.js
Last active December 6, 2017 13:05
const js = require('./primes.js');
const addon = require('./build/Release/primes.node');
function run(i) {
console.time('Prime in js');
js.prime(i);
console.timeEnd('Prime in js');
console.time('Prime in addon');
addon.prime(i);
@fhinkel
fhinkel / prime.js
Last active December 3, 2017 19:49
function isPrime(p) {
const upper = Math.sqrt(p);
for(let i = 2; i <= upper; i++) {
if (p % i === 0 ) {
return false;
}
}
return true;
}
var fs = {
readFile: function(filename, cb) {
cb(null, {length: 12});
}
}
for (var i = 0; i < 10000; i++) {
var __filename = 'perf-test.js';
printLength(__filename)
}
function valuesFn (array) {
var i = 0
return function foo (abort, cb) {
if(i >= array.length)
cb(true)
else
cb(null, array[i++])
}
}