Skip to content

Instantly share code, notes, and snippets.

@monochromer
monochromer / youtube-thumbnails-cdn.md
Last active October 19, 2022 19:28
Youtube Thumbnails CDN

Youtube Thumbnails CDN

URLS:

  • https://i.ytimg.com/vi/<video-id>/<size>.jpg
  • https://i.ytimg.com/vi_webp/<video-id>/<size>.webp

Sizes (video, channel):

  • default - 120x90, 88x88
  • mqdefault - 320x180, 240x240
  • hqdefault - 480x360, 800x800
@monochromer
monochromer / promise-patterns.js
Last active August 19, 2022 09:56
Паттерны использования promise (Promise Patterns)
/*
conf: Falsy Values 2015
author: Kornel Lesinski
theme: And .then() what? Promise programming patterns
link: https://www.youtube.com/watch?v=KrhQE8K2I7Q
*/
// 1 waterfall. Использование результатов предыдущих промисов
doFirst()
.then(firstResult => {
@monochromer
monochromer / hash-lib.js
Last active July 18, 2022 19:19
node.js hashing files
const crypto = require('crypto');
const fs = require('fs');
/**
* @typedef {object} HashFileOptions
* @prop {string} [algorithm = 'md5'] алгоритм хеширования
* @prop {crypto.HexBase64Latin1Encoding} [encoding = 'hex'] предствалние конечного хеша
*/
/**
@monochromer
monochromer / app.md
Last active April 12, 2022 06:17
NGINX Server Sent Events Proxy configuration

Headers from backend app:

Content-Type: text/event-stream;  
Connection: keep-alive;  
Cache-Control: no-cache;  
X-Accel-Buffering: no;
@monochromer
monochromer / git-date.sh
Last active April 6, 2022 12:13
git get last date commit of files
# https://stackoverflow.com/questions/32893773/how-to-git-log-with-date-time-and-file-names-in-one-line
git log --pretty=%x0a%ci --name-only \
| awk '
/^$/ { dateline=!dateline; next }
dateline { date=$0; next }
!seen[$0]++ { print date,$0 }
'
@monochromer
monochromer / form-data-to-json.js
Last active January 22, 2022 13:34
Serialize `FormData` to JSON
// https://jakearchibald.com/2021/encoding-data-for-post-requests/
function formToObject(formData) {
return Object.fromEntries(
[...new Set(formData.keys())]
.map((key) => [key, formData.getAll(key)]),
);
}
@monochromer
monochromer / css-network-performance.md
Last active October 20, 2021 20:05
CSS и производительность сети
  1. Сritical Path CSS style в head

  2. Разделяйте свои медиавыражения по типам

<link rel="stylesheet" href="all.css"         media="all"                />
<link rel="stylesheet" href="small.css"       media="(min-width: 20em)"  />
<link rel="stylesheet" href="medium.css"      media="(min-width: 64em)"  />