Skip to content

Instantly share code, notes, and snippets.

View mmomtchev's full-sized avatar

Momtchil Momtchev mmomtchev

View GitHub Profile
@mmomtchev
mmomtchev / ref1.png
Last active March 8, 2021 14:02
rlayers images
ref1.png
@mmomtchev
mmomtchev / http-server-reads-after-fin.js
Last active November 23, 2020 17:25
http-server-reads-after-fin
'use strict';
const net = require('net');
let server;
if (process.argv[2] !== undefined)
server = process.argv[2];
else {
console.error('specify server address/name');
return;
@mmomtchev
mmomtchev / gdal.LayerFeatures.get.js
Last active April 7, 2021 09:32
gdal.LayerFeatures.get vs gdal.LayersFeatures.getAsync
const gdal = require('../node-gdal-async');
const perf = require('perf_hooks').performance;
const PerformanceObserver = require('perf_hooks').PerformanceObserver;
const elu = perf.eventLoopUtilization();
console.time('open');
const dataset = gdal.open('admin.geojson');
console.timeEnd('open');
console.time('count');
@mmomtchev
mmomtchev / sched.js
Last active September 25, 2020 20:13
updating-large-dom-trees
/* light-weight, called by IntersectionObserver */
async function wind() {
/* scheduleLoad schedules loading of the data */
windData = await scheduleLoad(windReq);
/* scheduleDisplay is an equivalent function
* that schedules DOM updates */
await scheduleDisplay(windData);
}
/* create a promise that will be queued and return it
@mmomtchev
mmomtchev / best.mjs
Last active September 24, 2020 16:08
Beyond .then.then.catch - using and abusing Promises for fun and profit
'use strict';
import * as wiki from './wiki.mjs';
const result = {};
const linksHereCache = {};
(async function getPage(id, level) {
if (!linksHereCache[id])
linksHereCache[id] = wiki.linksHere(id).then(links => linksHereCache[id] = links);
let links;
const fs = require('fs');
const parseline = require('./parseline');
const rs = fs.createReadStream('allCountries.txt');
const nl = '\n'.charCodeAt(0);
const tab = '\t'.charCodeAt(0);
function parseline(line, start) {
function parseline2(line) {
const f0 = line.indexOf('\t');
const f1 = line.indexOf('\t', f0 + 1);
const data1 = line.slice(f0 + 1, f1);
if (data1 && data1.match(/^Paris$/g))
counter++;
}
const fs = require('fs');
const parseline = require('./parseline');
const rs = fs.createReadStream('allCountries.txt');
let t0 = 0, t1 = 0;
(async () => {
console.time(__filename);
let remainder = '';
for await (const buf of rs) {
const fs = require('fs');
const rs = fs.createReadStream('allCountries.txt');
const parseline = require('./parseline');
console.time(__filename);
let remainder = '';
rs.on('data', (buf) => {
const lines = (remainder + buf).split(/\r?\n/g);
remainder = lines.pop();
for (const line of lines) {
const fs = require('fs');
const es = require('event-stream');
const parseline = require('./parseline');
const rs = fs.createReadStream('allCountries.txt');
console.time(__filename);
rs.pipe(es.split()).pipe(es.through(parseline));
rs.on('close', () => console.timeEnd(__filename));