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('your_table_id_seq', COALESCE((SELECT MAX(id)+1 FROM your_table), 1), false)

or 

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

Show enum types in postgress

select enum_range(null::my_type)
16 сентября 2020, 18:20

Show list of all services on Ubuntu/Debian

service --status-all
31 августа 2020, 10:17

Javascript sleep promise

const sleep = (ms) => new Promise( (r) => setTimeout(r, ms));
29 августа 2020, 22:22

Update multiple rows with one query in postgresql

CREATE TABLE table1 ( 
	"id" Integer NOT NULL,
	"a" Text NOT NULL,
	"b" Text NOT NULL );
insert into table1 values  
(1, 'a', 'b'),
(2, 'a', 'b')
update table1 as t set 
  a = data.a,
  b = data.b
from (values
  (1, 'a1', 'b1'),
  (2, 'a2', 'b2')
) as data(id, a, b)
where t.id = data.id
29 августа 2020, 21:41

How to edit local commit message

git commit --amend 
27 августа 2020, 13:10

Javascript replace all

function replaceAll(string, search, replace) {
  return string.split(search).join(replace);
}
11 августа 2020, 11:09

Difference between ROW_NUBER(), RANK(), DENSE_RANK() in postgresql

WITH T(StyleID, ID)
     AS (SELECT 1,1 UNION ALL
         SELECT 1,1 UNION ALL
         SELECT 1,1 UNION ALL
         SELECT 1,2)
SELECT *,
       RANK() OVER(PARTITION BY StyleID ORDER BY ID)       AS 'RANK',
       ROW_NUMBER() OVER(PARTITION BY StyleID ORDER BY ID) AS 'ROW_NUMBER',
       DENSE_RANK() OVER(PARTITION BY StyleID ORDER BY ID) AS 'DENSE_RANK'
FROM   T  
Returns

StyleID     ID       RANK      ROW_NUMBER      DENSE_RANK
----------- -------- --------- --------------- ----------
1           1        1         1               1
1           1        1         2               1
1           1        1         3               1
1           2        4         4               2
6 августа 2020, 20:48