Skip to content

Instantly share code, notes, and snippets.

View gorshkov-leonid's full-sized avatar

Leonid Gorshkov gorshkov-leonid

View GitHub Profile
@gorshkov-leonid
gorshkov-leonid / useful-bash-scripts.md
Last active August 19, 2025 11:17
Useful Bash Scripts
  1. Get all unique file extensions

    find . -type f ! -path './.git/*' ! -path './node_modules/*' ! -path './.idea/*' ! -path './todo.txt' | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
  2. Decompile all .jar file

    for f in ./*.jar ; do docker run -it --rm -v `pwd`:/mnt --user $(id -u):$(id -g) kwart/jd-cli /mnt/$f -od /mnt/${f%.*}_src; done; 
    
@gorshkov-leonid
gorshkov-leonid / Recipe-bundling-fonts-with-headless-chrome.md
Created February 19, 2023 15:20 — forked from nmqanh/Recipe-bundling-fonts-with-headless-chrome.md
How to build a fontconfig bundle for adding arbitrary fonts to headless chrome independent of the OS. This is specifically useful for deploying headless chrome to AWS lambda where it is necessary to include fonts for rendering CJK (Chinese, Japanese, Korean) characters into the deployed bundle.

Building fontconfig

Start up a lambda-like docker container:

docker run -i -t -v /tmp:/var/task lambci/lambda:build /bin/bash

Install some dependencies inside the container:

yum install gperf freetype-devel libxml2-devel git libtool -y

easy_install pip

@gorshkov-leonid
gorshkov-leonid / prindt-font-using-puppeteer.md
Last active August 19, 2025 11:18
Print Font Using Puppeteer
       async function printFont(index: number): Promise<boolean> {
            const res = await cdp.send(
                "Runtime.evaluate",
                {expression: `Array.from(document?.querySelector('#my-iframe')?.contentWindow?.document?.body?.querySelector('#my-webcomponent')?.shadowRoot?.querySelectorAll('text') || []).filter((c) => c.textContent && (c.textContent.includes('Access') || c.textContent.includes('TV')))[${index}]`},
            ) as any
            if (res?.result?.objectId) {
                // eslint-disable-next-line prefer-destructuring
                const nodeId = ((await cdp.send("DOM.requestNode", {objectId: res.result.objectId})) as any).nodeId
                if (nodeId) {
@gorshkov-leonid
gorshkov-leonid / EACCES-permission-denied.md
Last active August 19, 2025 11:20
Error: listen EACCES: permission denied 0.0.0.0:3001
@gorshkov-leonid
gorshkov-leonid / template-literal-types-match.md
Created August 17, 2022 21:04
Match props in object (template-literal-types)
// todo use typescript 4.1 with https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html to filter keys in type by prefix automatically
//      example: https://stackoverflow.com/questions/53501721/typescript-exclude-property-key-when-starts-with-target-string
//      example: https://stackoverflow.com/questions/71811073/substrings-of-string-unions-using-template-literal-types  
type FilterStartingWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? Set : never
type FilteredKeys<Prefix extends string> = FilterStartingWith<keyof AccessResourcesNames, Prefix>
type FilteredResourceName<Prefix extends string> = Pick<AccessResourcesNames, FilteredKeys<Prefix>>
function pickResources<Prefix extends string>(...prefix: Prefix[]): FilteredResourceName<Prefix>{
     return accessResourcesNames as FilteredResourceName<Prefix>
};
@gorshkov-leonid
gorshkov-leonid / download-telegram-links-from-browser.md
Created April 11, 2022 21:40
download-telegram-links-from-browser.md
@gorshkov-leonid
gorshkov-leonid / avoid-npm-vunarabilities.md
Last active March 18, 2022 12:20
Avoid NPM vulnarabilities
    1. Rmove all ~, ^ from versions in package.json
    2. Create initial package.lock
  1. Create /Users/<user-name>/.npmrc or %USERPROFILE%\.npmrc or here echo $(npm config ls -l)
  2. Fill .npmrc with this content
     @netcracker:registry=https://corp-npm-server.com/path-to-internal-packages/
     registry=https://corp-npm-server.com/path-to-external-packages/
    
  3. Command
@gorshkov-leonid
gorshkov-leonid / docker-in-windows.md
Last active April 2, 2025 10:16
Docker In Windows (Final)

See final versions without trash here

Docker in Windows without Docker Desktop

❤️‍🔥 Install docker client in Windows

  • Download necessary version of docker binaries from https://docs.docker.com/engine/install/binaries/ and extract archive to c:/Program Files, for example, using script in powershell. Run powershell as Administrator and call:
    Expand-Archive .\docker-20.10.9.zip -DestianationPath $Env:ProgramFiles  
    Files docker.exe and dockerd.exe will be here c:/Program Files/docker/.
@gorshkov-leonid
gorshkov-leonid / typescript-tricks.md
Last active August 19, 2025 11:23
typescript-tricks.md

Tricks with types

Typesafe Object.keys

Expand
declare global {
    // https://github.com/microsoft/TypeScript/issues/3889
    type ObjectKeys<T> = T extends object
 ? (keyof T)[]