Skip to content

Instantly share code, notes, and snippets.

@x-yuri
x-yuri / Setting breakpoints using Chrome DevTools Protocol.md
Last active July 22, 2024 12:17
Setting breakpoints using Chrome DevTools Protocol

Setting breakpoints using Chrome DevTools Protocol

a.js:

const waitPort = require('wait-port');
const CDP = require('chrome-remote-interface');
const { spawn } = require('node:child_process');
const path = require('path');
const fs = require('fs');
@x-yuri
x-yuri / Debugging a nextjs project with vscode and --turbo.md
Last active July 19, 2024 03:12
Debugging a nextjs project with vscode and --turbo

Debugging a nextjs project with vscode and --turbo

Create a nextjs project:

next+14.2.5.patch (the name should match the nextjs version):

diff --git a/node_modules/next/dist/cli/.next-dev.js.swp b/node_modules/next/dist/cli/.next-dev.js.swp
new file mode 100644
index 0000000..59ed063
@x-yuri
x-yuri / Debugging vscode-js-debug.md
Last active July 19, 2024 03:13
Debugging vscode-js-debug

Debugging vscode-js-debug

Create a nextjs project:

next+14.2.5.patch (the name should match the nextjs version):

diff --git a/node_modules/next/dist/cli/.next-dev.js.swp b/node_modules/next/dist/cli/.next-dev.js.swp
new file mode 100644
index 0000000..59ed063
@x-yuri
x-yuri / Parsing nodejs command line.md
Last active July 16, 2024 10:34
Parsing nodejs command line

Parsing nodejs command line

a.mjs:

export default function getInspectInfo(nodeOptions, execArgv) {
    const args = (
        nodeOptions?.match(/(?<=^| )--inspect(-brk)?(=\S+)?(?= |$)/g) || []
    ).concat(execArgv.filter(
        a => a.startsWith('--inspect')
@x-yuri
x-yuri / Splitting a command line into arguments.md
Last active July 16, 2024 05:34
Splitting a command line into arguments

Splitting a command line into arguments

a.mjs:

// ", ', \ and (space) can be escaped with \
// \ before other symbols is removed
// inside double quotes " and \ can be escaped with \
// \ before other symbols remains
export default function splitCommandLine(l) {
@x-yuri
x-yuri / PID 1 processes doesn't have default signal handlers.md
Last active July 13, 2024 06:31
PID 1 processes doesn't have default signal handlers

PID 1 processes doesn't have default signal handlers

Dockerfile:

FROM alpine:3.20
COPY a.c .
RUN apk add build-base \
    && gcc a.c
@x-yuri
x-yuri / sh template engines.md
Created July 4, 2024 02:08
sh template engines

sh template engines

a.tpl:

a: <% $a %>
% if [ "$b" ]; then
b: <% $b %>
@x-yuri
x-yuri / bash: interrupting commands with async subprocesses when job control is disabled.md
Last active July 14, 2024 04:47
bash: interrupting commands with async subprocesses when job control is disabled
@x-yuri
x-yuri / bash: interrupting commands with async subprocesses when job control is disabled.md
Last active July 2, 2024 01:26
bash: interrupting commands with async subprocesses when job control is disabled

bash: interrupting commands with async subprocesses when job control is disabled

See [the new gist][d].

bash allows to override SIGINT in async subprocesses when job control is disabled since 4.3:

$ bash -c 'sleep 10 & wait'
$ ps -eHo pid,ppid,pgid,stat,ignored,args
    PID    PPID    PGID STAT          IGNORED COMMAND
@x-yuri
x-yuri / bash: interrupting async subprocesses.md
Last active July 2, 2024 03:08
bash: interrupting async subprocesses

bash: interrupting async subprocesses

a.sh:

trap - INT
while true; do
    echo -n .
    sleep 2
done