Skip to content

Instantly share code, notes, and snippets.

View Dionid's full-sized avatar
👌

David Shekunts Dionid

👌
View GitHub Profile
@Dionid
Dionid / consensus.ts
Last active October 12, 2023 11:26
Consensus on Redis + TypeScript
View consensus.ts
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 ...
View index.ts
describe('finally', () => {
it('1', () => {
const ttt = () => {
try {
return true
} finally {
// eslint-disable-next-line no-unsafe-finally
return false
}
}
View gist:616eb8915d1c2b9bb74a56342cf3dbac
// #1
class User {
public id: string
public password: string
public emails: Email[]
public deletedAt: Date | null
}
class Email {
View typed-errors.ts
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
View esModuleInterop.js
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
View index.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)
View index.ts
const config = {
entities: [],
driverOptions: {
connection: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},
@Dionid
Dionid / gist:d63e642c3d61c5bd2fadd76a63329e10
Created July 6, 2020 16:06
Poorly done Binary tree isBalanced check (this is bad, i know, it is for future me to improve) + tests
View gist:d63e642c3d61c5bd2fadd76a63329e10
interface TNode {
value: number
left?: TNode
right?: TNode
}
export interface Tree {
root: TNode
}
View gist:2e8acd77306ba4fade41321f70e176a8
Пример кода для блока, где 3 человечка, а разделитель только справа от второго
```javascript
var blocks = [
{
"text": "...",
"persons": [
{
"separatorFromRight": false
},
View gist:d0235f45fe09feabd67376cb856adb81
[Nov 29 15:58:52.874] Exception 28 @ 0x4027639e, vaddr 0x00000000
[Nov 29 15:58:52.877] A0: 0x40276228 A1: 0x3ffffa40 A2: 0x3fff033c A3: 0x00000000
[Nov 29 15:58:52.883] A4: 0x00000001 A5: 0x00000000 A6: 0x00000000 A7: 0x00000001
[Nov 29 15:58:52.888] A8: 0x3fff0338 A9: 0x00000007 A10: 0x3fff0398 A11: 0x00000007
[Nov 29 15:58:52.894] A12: 0x3ffee3a4 A13: 0x00000076 A14: 0x000000d0 A15: 0x40200010
[Nov 29 15:58:52.899]
[Nov 29 15:58:52.899] (exc SP: 0x3ffff8a0)
[Nov 29 15:58:52.902]
[Nov 29 15:58:52.902] --- BEGIN CORE DUMP ---
[Nov 29 15:58:52.905] {"arch": "ESP8266",