Skip to content

Instantly share code, notes, and snippets.

View dilame's full-sized avatar

Dmitry dilame

  • Россия, Москва
View GitHub Profile
@dilame
dilame / pagination.ts
Created March 18, 2025 13:17
TS pagination cursor class
import { createCipheriv, createDecipheriv, randomBytes } from 'crypto'
import process from 'node:process'
import { CustomError } from 'ts-custom-error'
import { z } from 'zod'
export const environment = z
.object({
PAGINATION_SECRET_KEY: z.string().min(1)
})
.parse(process.env)
@dilame
dilame / async-iterable-to-observable.ts
Last active March 29, 2025 05:36
RxJS <-> GraphQL subscriptions interop with proper resource cleaning
import { Observable, Subscriber } from 'rxjs'
/**
* Converts an `AsyncIterableIterator` into an RxJS `Observable`.
*
* The function iterates over the async iterator and emits its values
* through `observer.next()`. When the subscription is terminated
* (via `unsubscribe()`), the iterator's `return()` method is called
* (if available) to release resources.
* It is important, because native RxJS `from` operator don't do this
@dilame
dilame / tsconfig.json
Last active February 17, 2025 20:53
The most strict TypeScript tsconfig mode
{
"compilerOptions": {
// Strict Checks
"alwaysStrict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"useUnknownInCatchVariables": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
@dilame
dilame / accounting.sql
Last active March 10, 2025 11:23
Postgresql basic accounting
CREATE SCHEMA IF NOT EXISTS wallet;
CREATE TABLE wallet.segment
(
id smallint NOT NULL,
code text NOT NULL,
PRIMARY KEY (id) INCLUDE (code),
UNIQUE (code) INCLUDE (id)
);
@dilame
dilame / cloud-init-docker.yml
Created October 27, 2019 08:46
cloud-init to install docker using official shell script. Yep, that small
#include https://get.docker.com
@dilame
dilame / cloud-init.yaml
Created October 25, 2019 20:36 — forked from syntaqx/cloud-init.yaml
cloud init to install docker on ubuntu
#cloud-config
package_update: true
package_upgrade: true
package_reboot_if_required: true
manage-resolv-conf: true
resolv_conf:
nameservers:
- '8.8.8.8'