Add one second to date in javascript

const currentDate = new Date("2020-07-28T17:23:47.568Z");
const dateSub = new Date(currentDate.getTime() + 1000);
console.log(dateSub.toISOString());
28 июля 2020, 20:22

Run nodejs application in docker

docker run \
  -e "NODE_ENV=production" \
  -u "node" \
  -m "300M" --memory-swap "1G" \
  -w "/home/node/app" \
  --name "my-nodejs-app" \
  node [script]
19 июля 2020, 18:59

Что занимает порт?

sudo netstat -ltnp | grep -w ':80'
19 июля 2020, 18:46

Restart all docker containers

docker restart $(docker ps -a -q)
25 июня 2020, 16:23

SplFileObject read file

$file = new SplFileObject("file.txt");
while (!$file->eof()) {
    echo $file->fgets();
}
function lines($filename) {
    $file = new SplFileObject($filename);
    while (!$file->eof()) {
        yield $file->fgets();
    }
}

foreach (lines('German.txt') as $line) {
    echo $line;
}
15 июня 2020, 20:37

Javascript transliteration library

Iuliia
import iuliia from "iuliia";

// list all supported schemas
for (let schemaName of iuliia.Schemas.names()) {
    console.log(schemaName);
}

// transliterate using specified schema
let source = "Юлия Щеглова";
iuliia.translate(source, iuliia.ICAO_DOC_9303);
// "Iuliia Shcheglova"

// or pick schema by name
let schema = iuliia.Schemas.get("wikipedia");
iuliia.translate(source, schema);
// "Yuliya Shcheglova"
20 мая 2020, 15:17

Compare directories

diff -rq DIR1 DIR2
5 апреля 2020, 20:15

PhpStorm licence key april 2020

Add to /etc/hosts
0.0.0.0 account.jetbrains.com
0.0.0.0 www.jetbrains.com
0.0.0.0 www-weighted.jetbrains.com
812LFWMRSH-eyJsaWNlbnNlSWQiOiI4MTJMRldNUlNIIiwibGljZW5zZWVOYW1lIjoi5q2j54mIIOaOiOadgyIsImFzc2lnbmVlTmFtZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiIiLCJjaGVja0NvbmN1cnJlbnRVc2UiOmZhbHNlLCJwcm9kdWN0cyI6W3siY29kZSI6IklJIiwiZmFsbGJhY2tEYXRlIjoiMjAxOS0wNC0yMSIsInBha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ortep1Dh8xDUbqbBVNBL4jbiL3i3xsfNiyJgaZ5sX7i8tmStEpLbPwvHcByuf59qJhV/bZOl8KqJBETCDJcY6O2aqhTUy+9x93ThKs1GKrRPePrWPluud7ttlgtRveit/pcBrnQcXOl1rHq7ByB8CFAxNotRUYL9IF5n3wJOgkPojMy6jetQA5Ogc8Sm7RG6vg1yow==

4 января 2020, 00:24

Iptables port forwarding

iptables -t nat -I OUTPUT -p tcp -o lo --dport 80 -j REDIRECT --to-ports 8080
7 ноября 2019, 21:00

Linux get mac address

ifconfig -a | grep ether | awk '{print $2}'
15 октября 2019, 12:34

NodeJs natsort with Intl

const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
array.sort(collator.compare);
13 сентября 2019, 16:10

Install JIRA 8 on docker

version: '3.1'
services:
  jira:
    image: zhangguanzhang/atlassian-jira-software:8.0.0
    container_name: jira8
    restart: always
    environment:
      - "CATALINA_OPTS= -Xms1024m -Xmx4096m"
    links:
      - database
    volumes:
      - /home/jira8.0/data:/var/atlassian/jira
      - /home/jira8.0/logs:/opt/atlassian/jira/logs
      - /etc/localtime:/etc/localtime:ro
    ports:
      - '80:8080'

  database:
    restart: always
    container_name: jira8db
    image: percona:5.7
    environment:
      - MYSQL_DATABASE=jira
      - MYSQL_USER=jira
      - MYSQL_PASSWORD=jira
      - MYSQL_ROOT_PASSWORD=jira
    volumes:
      - /home/jira8.0/db:/var/lib/mysql
    ports:
      - "127.0.0.1:3306:3306"
    command:
      - '--collation-server=utf8_bin'
      - '--character-set-server=utf8'
      - '--max_allowed_packet=34M'
      - '--innodb_log_file_size=256M'
13 сентября 2019, 14:39

Rebuild all containers in docker-compose

 docker-compose up -d --force-recreate --build
11 сентября 2019, 11:43

Websocket broadcasting

Broadcasting All
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(data) {
    wss.clients.forEach(function each(client) {
      if (client.readyState === WebSocket.OPEN) {
        client.send(data);
      }
    });
  });
});
Broadcasting excluding itself.
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(data) {
    wss.clients.forEach(function each(client) {
      if (client !== ws && client.readyState === WebSocket.OPEN) {
        client.send(data);
      }
    });
  });
});
7 сентября 2019, 18:09

FadeIn without Jquery

el.classList.add('show');
el.classList.remove('hide');
.show {
  transition: opacity 400ms;
}
.hide {
  opacity: 0;
}
source
7 сентября 2019, 17:53

FFMPEG playlist

Create file playlist.txt
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
file '/path/to/video/video.mp4'
Run ffmpeg
ffmpeg -f concat -i playlist.txt -c copy output.mp4
7 сентября 2019, 17:50

Get docker host internal ip

docker inspect <container-id-or-name> | grep Gateway
7 сентября 2019, 10:08

Map, for, spread javascript benchmark for copy array

copy for: 2508.226ms
copy map: 1188.982ms
copy spread: 1898.890ms
const map = [
  [1, 2, 3, 4, 5],
  [6, 7, 8, 9, 10],
  [11, 12, 13, 14, 15]
];
const n  = 10e6;

console.time('copy for');
for (let i = 0; i < n; i++) {
  const m = [];
  for (let row = 0; row < map.length; row++) {
    m[row] = [];
    for (let reel = 0; reel < map[row].length; reel++) {
      m[row][reel] = map[row][reel];
    }
  }
}
console.timeEnd('copy for');

console.time('copy map');
for (let i = 0; i < n; i++) {
  const m = map.map(a => a.map(item => item));
}
console.timeEnd('copy map');

console.time('copy spread');
for (let i = 0; i < n; i++) {
  const m = map.map(a => [...a]);
}
console.timeEnd('copy spread');
13 августа 2019, 13:29

Javascript chrome full screen mode

document.documentElement.webkitRequestFullscreen();
25 июля 2019, 10:20

Javascript break(2)

loop:
for(let i=0; i<10; i++) {
  for(let j=0; j<10; j++){
    console.log(i,j);
    if(j === 5) break loop;
  }
}
22 июля 2019, 15:22