Select estimated rows count from timescaledb

SELECT h.schema_name,
    h.table_name,
    h.id AS table_id,
    h.associated_table_prefix,
    row_estimate.row_estimate
   FROM _timescaledb_catalog.hypertable h
     CROSS JOIN LATERAL ( SELECT sum(cl.reltuples) AS row_estimate
           FROM _timescaledb_catalog.chunk c
             JOIN pg_class cl ON cl.relname = c.table_name
          WHERE c.hypertable_id = h.id
          GROUP BY h.schema_name, h.table_name) row_estimate
ORDER BY schema_name, table_name;
6 мая 2021, 13:31

Get estimated count rows

explain (format json) select * from tbl
28 апреля 2021, 17:38

Get weekday name with intl

new Intl.DateTimeFormat('ru-RU', { weekday: 'short' }).format(new Date()) //пн
19 апреля 2021, 23:32

Get start and end of current hour in javascript

const date = new Date();
const d1 = new Date(
  date.getFullYear(),
  date.getMonth(),
  date.getDay(),
  date.getHours(),
  0,
  0,
  0,
);
const d2 = new Date(
  date.getFullYear(),
  date.getMonth(),
  date.getDay(),
  date.getHours(),
  59,
  59,
  999,
);

console.log(d1); // 2021-03-05T09:00:00.000Z
console.log(d2); // 2021-03-05T09:59:59.999Z
19 марта 2021, 12:22

Install nodejs 14 on ubuntu 20

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
20 февраля 2021, 13:43

HomeBrew fatal error: 'pcre2.h' file not found

ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre
17 февраля 2021, 00:04

Create user without password

sudo adduser \
   --system \
   --shell /bin/bash \
   --gecos 'description' \
   --group \
   --disabled-password \
   --home /home/us \
   us
16 февраля 2021, 17:43

Error: Node Sass does not yet support your current environment: OS X Unsupported architecture (arm64)

npm rebuild node-sass
16 февраля 2021, 17:00

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';  
15 февраля 2021, 15:19

Install docker on Ubuntu

sudo apt-get remove -y docker docker-engine docker.io containerd runc

sudo apt-get update

sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

sudo apt-get update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io

14 февраля 2021, 12:59

Install ffmpeg with aac on homebrew

brew tap homebrew-ffmpeg/ffmpeg
brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac
13 февраля 2021, 12:48

Open file in new tab instead window in Sublime Text 3

Go to options
"open_files_in_new_window": false
10 февраля 2021, 16:50

Show hidden files on Mac Finder

Type in terminal
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
9 февраля 2021, 19:02

Increate memory limit for process

export NODE_OPTIONS=--max_old_space_size=4096
2 февраля 2021, 20:44

Php Transliterator

<?php
function slugify($string) {
    $translit = "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();";
    $string = transliterator_transliterate($translit, $string);
    $string = preg_replace('/[-\s]+/', '-', $string);
    return trim($string, '-');
}

echo slugify("Я люблю PHP!");
23 января 2021, 21:09

Generate date ranges in postgresql

SELECT d::date
FROM generate_series(
  timestamp without time zone '2021-01-01',
  timestamp without time zone '2021-02-01',
  '1 day'
) AS gs(d);

19 января 2021, 12:33

Knex join with subquery

knex(
  knex('A').where('A.id',1).as('t1')
).leftJoin(
  knex('B').where('B.id', 2).as('t2'), 
  't1.c', 
  't2.d'
)
15 января 2021, 10:33

Postgresql reset sequence

SELECT
	setval(pg_get_serial_sequence('tbl', 'id'), COALESCE(max(id) + 1, 1), FALSE)
FROM
	tbl;
19 декабря 2020, 20:04

Javascript end of week

function endOfWeek(date) {
    const lastday = date.getDate() - (date.getDay() - 1) + 6;
    return new Date(date.setDate(lastday));
}

const dt = new Date(); 
console.log(endOfWeek(dt).toString());
24 ноября 2020, 19:07

Manual installation LetsEncrypt

certbot run -a manual -i nginx -d example.com
5 ноября 2020, 22:19