Skip to content

Instantly share code, notes, and snippets.

View maksimr's full-sized avatar
🎯
Focusing

Maksim Ryzhikov maksimr

🎯
Focusing
View GitHub Profile
@maksimr
maksimr / setup.sh
Last active October 22, 2025 18:27
setup env
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.nvm/nvm.sh
nvm install node
nvm alias default $(nvm ls --no-alias --no-colors | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | sort -r | head -n 1)
npx -y github:maksimr/udot use https://github.com/maksimr/dotfiles
npx -y github:maksimr/udot install --module-path=~/.local/bin/udot
// @ts-check
main();
/**
* @returns {Promise<void>}
*/
async function main() {
/**@type {{version?: string; output?: string; help?: boolean}}*/
const options = {};
@maksimr
maksimr / index.ts
Last active December 29, 2023 18:32
tracer
import { Tracer } from './tracer';
import express, { Request, Response } from 'express';
import { ErrorHandler, Handler, wrap } from 'async-middleware';
import { spanProcessor } from './span-processor';
import { SpanOptions } from '@opentelemetry/api';
async function main() {
const tracer = new Tracer({ name: 'example-tracer-node' });
const app = express();
@maksimr
maksimr / index.ts
Last active December 11, 2023 20:14
jsonb index
import pg from 'pg';
async function main() {
const client = new pg.Client({
host: '127.0.0.1',
port: 5432,
user: 'username',
password: 'password',
database: 'test'
});
@maksimr
maksimr / index.ts
Last active November 19, 2023 20:33
streamin data from postgresql database to s3
import { CreateBucketCommand, DeleteBucketCommand, DeleteObjectCommand, ListBucketsCommand, ListObjectsCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import pg from 'pg';
import QueryStream from 'pg-query-stream'
import { JsonStreamStringify } from 'json-stream-stringify';
/**
* This is an example of streaming data from a postgresql database to S3
* with low memory usage
*/
async function main() {
@maksimr
maksimr / index.mjs
Last active November 20, 2023 18:12
node tracer example
import express from "express";
import bodyParser from "body-parser";
import { trace, context } from "@opentelemetry/api";
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
trace.setGlobalTracerProvider(provider);
@maksimr
maksimr / index.ts
Last active October 14, 2023 15:19
node profiler
import inspector from 'inspector';
import { writeFile } from 'fs/promises';
import cron from 'node-cron';
class Profiler {
private session: inspector.Session;
constructor() {
this.session = new inspector.Session();
}
@maksimr
maksimr / index.md
Last active June 8, 2023 08:07
📝 Getting started with C++ extension for Node.js

https://nodejs.org/api/n-api.html#node-api

mk -p /tmp/echo/src
pushd /tmp/echo
npm init -y
npm install -S node-addon-api node-api-headers
touch src/index.cpp src/echo.h src/echo.cpp

node-addon-api and node-api-headers contain the C++ headers required to build the extension

<link rel="shortcut icon" width=32px>
<canvas style="display: none" id="loader" width="16" height="16"></canvas>
<script>
class Loader {
constructor(link, canvas) {
this.link = link;
this.canvas = canvas;
this.context = canvas.getContext('2d');
this.context.lineWidth = 2;
@maksimr
maksimr / what-forces-layout.md
Created May 23, 2017 14:08 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()