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 / dynamic-reps-repl.clj
Created April 7, 2022 14:56
Dynamic add Clojure dependency without REPL restart
(comment {
org.clojure/tools.deps.alpha {:git/url "https://github.com/clojure/tools.deps.alpha.git" :sha "d492e97259c013ba401c5238842cd3445839d020"}
})
(comment
(require '[clojure.tools.deps.alpha.repl :refer [add-lib]])
(add-lib 'ring/ring-jetty-adapter {:mvn/version "1.9.5"}))
@maksimr
maksimr / launch.json
Created April 14, 2023 08:59
VS Code configuration for C++ 👨🏻‍💻
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
@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

@maksimr
maksimr / index.js
Last active June 24, 2023 16:01
typeorm
async function main() {
const pg = require('pg');
const client = new pg.Client({
user: 'admin',
password: 'admin',
database: 'test',
host: '127.0.0.1',
port: 5432
});
@maksimr
maksimr / index.mjs
Last active September 22, 2023 19:14
typeorm postgres settings
import typeorm from 'typeorm';
async function main() {
const dataSource = new typeorm.DataSource({
type: 'postgres',
host: '127.0.0.1',
username: 'username',
password: 'password',
database: 'test',
extra: /**@type {import('pg').PoolConfig}*/({
@maksimr
maksimr / daemon.mjs
Last active October 13, 2023 20:55
node background-process
async function register(message) {
await import(message.path);
process.send({ type: 'registred' });
}
process.on('message', (message) => {
switch (message.type) {
case 'register':
return register(message);
case 'ping':
@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.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 November 20, 2023 18:11
node tracer
import { context, trace } from "@opentelemetry/api";
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { promisify } from "util";
async function main() {
const contextManager = new AsyncLocalStorageContextManager();
const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
@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() {