This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hash = (() => { | |
const makeCRCTable = () => { | |
let c | |
const crcTable = [] | |
for(let n = 0; n < 256; n++) { | |
c = n; | |
for(let k = 0; k < 8; k++) { | |
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)) | |
} | |
crcTable[n] = c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id":"8", | |
"hex_color":"FFCD1C", | |
"name":"Калининская", | |
"stations":[ | |
{ | |
"id":"8.189", | |
"name":"Новокосино", | |
"lat":55.745113, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zip(...arrays) { | |
const maxLength = Math.max(...arrays.map(array => array.length)) | |
return Array.from({ length: maxLength }).map((_, i) => { | |
return Array.from({ length: arrays.length }, (_, j) => arrays[j][i]) | |
}) | |
} | |
// Define the arrays that contain the coordinates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function omit(obj, keys) { | |
return Object.keys(obj) | |
.filter(key => !keys.includes(key)) | |
.reduce((acc, key) => { | |
acc[key] = obj[key] | |
return acc | |
}, {}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pick(obj, keys) { | |
return keys.reduce((acc, key) => { | |
if (obj.hasOwnProperty(key)) { | |
acc[key] = obj[key] | |
} | |
return acc | |
}, {}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe(...fn) { | |
return function piped(...args) { | |
return fn.reduce((result, f) => [f.call(this, ...result)], args)[0] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const h2sl = (hex, isString) => { | |
// Convert hex to RGB first | |
let r = 0, g = 0, b = 0 | |
if (hex.length == 4) { | |
r = "0x" + hex[1] + hex[1] | |
g = "0x" + hex[2] + hex[2] | |
b = "0x" + hex[3] + hex[3] | |
} else if (hex.length == 7) { | |
r = "0x" + hex[1] + hex[2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @see https://gist.github.com/alekstar79/11125248f8dc609f5c8dcba3e0f75b5e */ | |
import { createCachedFunction } from './cached.mjs' | |
/** @see https://gist.github.com/alekstar79/042a211b62203f1439f2012ce6aa9f55 */ | |
import { workerInit } from './worker.mjs' | |
/** | |
* @param {function} worker | |
* @return {function(*=): Promise<unknown>} | |
* @example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Function} fn | |
* @return {Function} | |
*/ | |
export function createCachedFunction(fn) | |
{ | |
const handler = { | |
cache: {}, | |
apply(target, that, args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Function} job | |
* @return {function(*=): Promise<unknown>} | |
*/ | |
export function workerInit(job) | |
{ | |
const url = window.URL.createObjectURL(new Blob( | |
[`"use strict";\nself.onmessage = ${job.toString()}`], | |
{ type: 'text/javascript' } | |
)) |
NewerOlder