Skip to content

Instantly share code, notes, and snippets.

View zmts's full-sized avatar
🇺🇦
russian warship go f*uck yourself

Sasha Zmts 🇺🇦 zmts

🇺🇦
russian warship go f*uck yourself
View GitHub Profile
@zmts
zmts / nest_js_dynamic_module.md
Last active January 14, 2025 15:50
Nest.js Dynamic module

Nest.js Dynamic module

Implementation example

.
├── index.ts
├── sender.module.ts
├── sender.service.ts
└── types.ts
@zmts
zmts / ohlc.md
Last active January 19, 2025 19:40
Aggregation of minute candles into 5-minute candles

SQL: Aggregation of minute candles into 5-minute candles

CREATE "ohlc_minutes" (
    "id" int4 NOT NULL DEFAULT nextval('ohlc_minutes_id_seq'::regclass),
    "ticker" varchar NOT NULL,
    "date" timestamptz NOT NULL,
    "open" numeric(20,8) NOT NULL,
    "high" numeric(20,8) NOT NULL,
 "low" numeric(20,8) NOT NULL,
@zmts
zmts / merge_objects.md
Created March 7, 2024 15:02
merge objects

Merge objects in JavaScript (lodash)

const mergeWith = require('lodash/mergeWith')
const isArray = require('lodash/isArray')

function mergeObjects(obj1, obj2) {
  return mergeWith(obj1, obj2, (objValue, srcValue) => {
    if (isArray(objValue) && isArray(srcValue)) {
 return objValue.concat(srcValue);

Convert .env file to object

const isNumber = (value) => {
  return !isNaN(Number(value))
}

const getValue = (value) => {
  if (value === '') return value
  if (['true', 'false'].includes(value)) return JSON.parse(value)
@zmts
zmts / dns.md
Created December 5, 2023 11:01

Too slow response .local domains Mac OS

The Multicast DNS feature of Bonjour technology allows devices on a local network to connect to each other by name without a separate DNS server. By default, any hostname ending in .local is treated as a Bonjour host rather than by querying the DNS server entries in Network preferences.

Though the .local domain is not defined as a valid top-level domain on the Internet, some private networks have DNS servers that assign hostnames in the .local domain. By default Mac OS X does not use the DNS server to resolve these names. This may result in unexpected failures to connect to .local hostnames defined by your server.

To fix this problem you need to add IPv6 entries for each of your vhosts in your /etc/hosts file:

127.0.0.1       localhost
127.0.0.1 myproject.local
@zmts
zmts / buildTreeFromFlatArray.md
Created August 15, 2023 09:37
Build tree from flat array

Build tree from flat array

function buildTree(nodes, parentId = null) {
  const tree = [];
  for (const node of nodes) {
    if (node.parentId === parentId) {
      const children = buildTree(nodes, node.id);
      if (children.length) {
        node.children = children;
@zmts
zmts / parent_child_get_item_level.md
Last active June 23, 2023 15:16
SQL: Get item level (aka generation) from parent child hierarchy

SQL: get item level (aka generation) from parent child hierarchy

CREATE TABLE "public"."parent_child" (
    "id" int4 NOT NULL DEFAULT nextval('people_id_seq'::regclass),
    "first_name" varchar(100),
    "parent_id" int4,
    "city" varchar(100),
    PRIMARY KEY ("id")
);
@zmts
zmts / select_by_id_from_feild_array.md
Last active June 23, 2023 15:16
SQL: select rows where some id in array

SQL: select rows where some id in array

CREATE TABLE "public"."items" (
    "id" int4 NOT NULL DEFAULT nextval('item_id_seq'::regclass),
    "name" text,
    "has_access" _int4 NOT NULL DEFAULT '{}'::integer[],
    PRIMARY KEY ("id")
);

SQL: sum per day

CREATE TABLE "stat" (
    "id" int4 NOT NULL DEFAULT nextval('stat_id_seq'::regclass),
    "type" varchar(100),
    "datetime" timestamptz,
    "amount" int8,
    "wallet_id" int8,
 PRIMARY KEY ("id")
@zmts
zmts / pg_jsonb_push.md
Last active October 25, 2021 17:16
Insert(push) object to nested array. JSONB PostgreSQL

Insert(push) object to nested array. JSONB PostgreSQL

// posts table

| id | content          |
|----|------------------|
| 40 | jsonb data       |