Skip to content

Instantly share code, notes, and snippets.

View alekstar79's full-sized avatar
🎯
Focusing

Aleksey Tarasenko alekstar79

🎯
Focusing
View GitHub Profile
[
{
"id":"8",
"hex_color":"FFCD1C",
"name":"Калининская",
"stations":[
{
"id":"8.189",
"name":"Новокосино",
"lat":55.745113,
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
function omit(obj, keys) {
return Object.keys(obj)
.filter(key => !keys.includes(key))
.reduce((acc, key) => {
acc[key] = obj[key]
return acc
}, {})
}
function pick(obj, keys) {
return keys.reduce((acc, key) => {
if (obj.hasOwnProperty(key)) {
acc[key] = obj[key]
}
return acc
}, {})
}
function pipe(...fn) {
return function piped(...args) {
return fn.reduce((result, f) => [f.call(this, ...result)], args)[0]
}
}
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]
/** @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
/**
* @param {Function} fn
* @return {Function}
*/
export function createCachedFunction(fn)
{
const handler = {
cache: {},
apply(target, that, args)
/**
* @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' }
))
function getUserAgent({ brands = [] })
{
let agent
test: for (const { brand, version } of brands) switch (true) {
case ['Chromium','Google Chrome','CriOS'].includes(brand):
agent = `Chrome/${version}`
break
case ['Firefox'].includes(brand):