Skip to content

Instantly share code, notes, and snippets.

View wmakeev's full-sized avatar
💭
💻

Makeev Vitaliy wmakeev

💭
💻
View GitHub Profile
@wmakeev
wmakeev / resize.ts
Last active May 29, 2023 06:57
[Image resize] #imagemagick #resize #spawn #convert
import { spawn } from "node:child_process";
import type { Readable } from "node:stream";
export interface ImageResizeOptions {
quality?: number;
square?: boolean;
}
const CONVERT_ERR_MATCH_REGEX = /convert:\s(.+)\s`/gm;
@wmakeev
wmakeev / enrichTransform.js
Last active May 10, 2023 13:57
[highland enrich transform] #highland #transform
/**
* Enrich source stream items with some data
*
* @param pick Function that transform source item to pass result to enrichment transform
* @param enrichmentData Enrichment transformation, which returns the data stream with which the original stream will be enriched
* @param compose Function that enrich source item with enrichment data
* @type {EnrichTransform}
*/
export const enrichTransform = (pick, enrichmentData, compose) => (source$) => {
return source$
@wmakeev
wmakeev / s3Upload.js
Last active May 5, 2023 06:17
[Upload to Yandex.Cloud S3 bucket] #yandex #cloud #s3 #upload
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import mime from "mime-types";
import querystring from "node:querystring";
import { env } from "../env.js";
/*
{
"BUCKET_ENDPOINT": "https://storage.yandexcloud.net",
"BUCKET_REGION": "ru-central1",
"BUCKET_NAME": "my-bucket",
@wmakeev
wmakeev / load.ts
Last active March 28, 2023 11:58
[$mol bach loader adaptation (concept)] #mol #batch
namespace $ {
/** Элемент очереди на массовую загрузку */
type Queue_item = {
id: string
resolve: ( value: unknown ) => void
reject: ( reason?: any ) => void
signal: AbortSignal
}
@wmakeev
wmakeev / harp-sample-1.ts
Last active March 1, 2023 03:41
$mol samples #mol #sample
// prettier-ignore
export class $my_model extends $mol_object {
static type() {
return ''
}
@$mol_mem_key
static item( id: string ) {
@wmakeev
wmakeev / example.js
Last active October 16, 2023 06:34
[ESM __dirname] #esm #dirname #filename #node
import * as url from "node:url";
/**
* Returns `__dirname` like value for ESM
*
* ```js
* const dirname = getDirname(import.meta.url)
* ```
* @link https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
* @param {string} fileUrl
@wmakeev
wmakeev / settings.json
Created January 30, 2023 18:33
[$mol vscode code format settings] #mol #format #settings
{
"typescript.tsdk": "node_modules/typescript/lib",
"files.watcherExclude": {
"**/node_modules": true,
"**/-*": false
},
"search.exclude": {
"**/node_modules": true,
"**/-*": true
},
@wmakeev
wmakeev / redirect.js
Last active January 26, 2023 09:40
[Redirect bookmarklet] #bookmarklet #redirect #url #queystring
(() => {
// 1. Скопировать этот код на страницу https://caiorss.github.io/bookmarklet-maker/
// 2. Заполнить название закладки
// 3. Сюда добвить ID вашей функции в Yandex.Cloud
const FUNCTION_ID = "qwertyyuio1234567890";
// 4. Тут указать название закладки с фильтром в разделе "Заказы покупателей"
const FILTER_NAME = "Все";
@wmakeev
wmakeev / object.entries.js
Last active October 22, 2023 11:57
[TypeScript type fixes] #typescript #fix
/** @type {TypedEntries} */
export function typedEntries(obj) {
// @ts-expect-error ignore
return Object.entries(obj);
}
/** @type {TypedFromEntries} */
export function typedFromEntries(entries) {
return Object.fromEntries(entries);
}
@wmakeev
wmakeev / mergePdf.js
Last active January 24, 2023 06:24
[Merge PDF] #pdf #merge
// gist: https://gist.github.com/wmakeev/ede27b97b3d227258684c5e80bf7fca3
import { PDFDocument } from "pdf-lib";
/**
* Merges pdf files in one (with pdf-lib)
*
* @see https://stackoverflow.com/a/68482188
*
* @param {ArrayBuffer[]} pdfsToMerge