Skip to content

Instantly share code, notes, and snippets.

Avatar

F. Hinkelmann fhinkel

View GitHub Profile
View video-intelligence.api.json
{
"metadata": {
"toolPackage": "@microsoft/api-extractor",
"toolVersion": "7.8.2-pr1796.0",
"schemaVersion": 1003,
"oldestForwardsCompatibleVersion": 1001
},
"kind": "Package",
"canonicalReference": "@google-cloud/video-intelligence!",
"docComment": "",
View maxGap.js
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
Create minimal Compute Engine instance with Node.js
View createComputeEngine.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 Apr 3, 2020
Create VM with startup script on GCP using Node.js Client
View createVM.js
'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
View package.json
{
"name": "profiler-issue",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
View primes.cc
#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();
View index.js
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);
View prime.js
function isPrime(p) {
const upper = Math.sqrt(p);
for(let i = 2; i <= upper; i++) {
if (p % i === 0 ) {
return false;
}
}
return true;
}
View perf-test-d8.js
var fs = {
readFile: function(filename, cb) {
cb(null, {length: 12});
}
}
for (var i = 0; i < 10000; i++) {
var __filename = 'perf-test.js';
printLength(__filename)
}
View context-allocated-vars.js
function valuesFn (array) {
var i = 0
return function foo (abort, cb) {
if(i >= array.length)
cb(true)
else
cb(null, array[i++])
}
}