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 / 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 / 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.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 / 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.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 / 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 / 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 / babashka.vim
Last active May 13, 2022 09:46
Vim Embed clojure language into sh for babashka (bb) command
" Clojure Embedding:
" ==============
if exists("b:current_syntax")
unlet b:current_syntax
endif
syn include @CLJScript syntax/clojure.vim
syn region CLJScriptCode matchgroup=CLJCommand start=+[=\\]\@<!'+ skip=+\\'+ end=+'+ contains=@CLJScript contained
syn region CLJScriptEmbedded matchgroup=CLJCommand start=+\<bb\>+ skip=+\\$+ end=+[=\\]\@<!'+me=e-1 contains=@shIdList,@shExprList2 nextgroup=CLJScriptCode
syn cluster shCommandSubList add=CLJScriptEmbedded
hi def link CLJCommand Type
<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;