Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Delivery Area Explorer</title>
<link
rel="stylesheet"
href="https://unpkg.com/leaflet@1.9.2/dist/leaflet.css"
const pick =
(...options) =>
(data) => {
const result = {};
for (let option of options) {
if (option.constructor.name === "Array") {
option = option.reduce((acc, val) => ({ ...acc, [val]: val }), {});
}
function commandarize(methods) {
const args = process.argv.slice(2).map((arg) => {
const isJson = /^\[.+\]$|^\{.+\}$/.test(arg);
return isJson ? JSON.parse(arg) : arg;
});
const [methodName, ...params] = args;
if (methodName) {
const method =
@Ivannnnn
Ivannnnn / db.js
Last active October 8, 2022 10:50
Wrapper around better-sqlite3
const betterSqlite = require("better-sqlite3");
const proxify = (get, set) => new Proxy({}, { get, set });
const valuesFragment = (obj) => {
const keys = Object.keys(obj);
return `(${keys.join(",")}) VALUES (${keys.map((k) => "@" + k).join(",")})`;
};
module.exports = (dir, options) => {
const path = require("path");
function* walkSync(dir) {
const files = fs.readdirSync(dir, { withFileTypes: true });
for (const file of files) {
file.isDirectory()
? yield* walkSync(path.join(dir, file.name))
: yield path.join(dir, file.name);
}
}
const path = require("path");
const exec = (command, options = {}) =>
require("child_process").execSync(command, { encoding: "utf-8", ...options });
const crontabRead = () => exec("crontab -l").trim();
const crontabWrite = (str) => exec(`echo "${str}" | crontab`);
function parseCrontab() {
return crontabRead()
const group = (arr, func) =>
arr.reduce((acc, val) => {
(acc[func(val)] = acc[func(val)] || []).push(val);
return acc;
}, {});
@Ivannnnn
Ivannnnn / sortBy.js
Last active September 21, 2022 09:01
function sortBy(objArr, key, ascDesc = "asc") {
const sortingFunc =
ascDesc === "desc" ? (a, b) => b[key] - a[key] : (a, b) => a[key] - b[key];
return [...objArr].sort(sortingFunc);
}
/*
const data = [
{ order: 1 },
{ order: 3 },
@Ivannnnn
Ivannnnn / date.js
Last active September 24, 2022 13:36
function date(date = new Date(), props = {}) {
[date, props] =
date.constructor.name === "Object"
? [new Date(), date]
: [new Date(date), props];
for (let key in props) {
if (typeof props[key] === "string" && props[key].match(/^[+-]/))
props[key] = date[key.replace(/^set/, "get")]() + parseInt(props[key]);
date[key](props[key]);
@Ivannnnn
Ivannnnn / el.js
Created September 19, 2022 10:11
function el(...args) {
const argMap = { String: "type", Object: "props", Array: "children" };
args.forEach((arg) => (args[argMap[arg.constructor.name]] = arg));
if (!args.props && !args.children) return document.createTextNode(args.type);
const $el = document.createElement(args.type);
for (let key in args.props || {}) {
$el[key.toLowerCase()] === null
? $el.addEventListener(key.substr(2).toLowerCase(), args.props[key])