Skip to content

Instantly share code, notes, and snippets.

View Dionid's full-sized avatar
🌖
N2P is coming...

David Shekunts Dionid

🌖
N2P is coming...
View GitHub Profile
@Dionid
Dionid / table-schema.ts
Created February 3, 2024 14:28
Introspection + models
// instrospection.ts
type UserTable = {
id: string,
email: string,
password: string | null,
active: boolean
}
// models.ts
@Dionid
Dionid / docker-compose.yaml
Created January 31, 2024 21:55
Local kafka on docker-compose
services:
kafka:
container_name: kafka
hostname: kafka
image: confluentinc/confluent-local:7.4.3
ports:
- "8082:8082"
- "54106:54106"
- "9092:9092"
- "9997:9997"
import path from "path";
import { DockerCompose } from "libs/docker-compose";
import { isPortReachable } from "libs/is-port-reachable";
import * as dockerCompose from "docker-compose";
import knex from "knex";
import { TestConfig } from "./global-config";
module.exports = async () => {
@Dionid
Dionid / consensus.ts
Last active October 12, 2023 11:26
Consensus on Redis + TypeScript
import { Sleep } from "sleep";
import IORedis from "ioredis";
import pino from "pino";
import {
LEADERSHIP_EVENTS,
LeadershipMetrics,
} from "libs/metrics/leadership";
const leadershipKey = "leader";
@Dionid
Dionid / index.ts
Created September 6, 2023 17:46
Go defer in JS by try ... finally ...
describe('finally', () => {
it('1', () => {
const ttt = () => {
try {
return true
} finally {
// eslint-disable-next-line no-unsafe-finally
return false
}
}
// #1
class User {
public id: string
public password: string
public emails: Email[]
public deletedAt: Date | null
}
class Email {
export const INTERNAL_ERROR_TYPE = "internal_error";
export const INTERNAL_ERROR = {
type: INTERNAL_ERROR_TYPE,
message: "Internal error",
};
export const CRITICAL_ERROR = {
type: "critical_error",
message: "Critical error",
};
@Dionid
Dionid / esModuleInterop.js
Created August 16, 2022 21:56
esModuleInterop import wrapper
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
@Dionid
Dionid / index.ts
Created October 22, 2021 10:28
Union type tuple destruction not working on TS
const returnError = async <R>(callback: (...args: any) => Promise<R>): Promise<[R] | [undefined, Error]> => {
try {
return await callback()
} catch (e) {
return e
}
}
const [result, err] = returnError(
() => api.call(/* ... */)
@Dionid
Dionid / index.ts
Created July 8, 2020 19:48
MikroORM TypeScript minimal PostreSQL config with ssl (for heroku / hasura)
const config = {
entities: [],
driverOptions: {
connection: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},