Skip to content

Instantly share code, notes, and snippets.

@monochromer
monochromer / useful-links.md
Created February 18, 2025 08:01 — forked from mxmvshnvsk/useful-links.md
Как отдавать фронтенду только нужное, или Зачем вам BFF – полезные ссылки
@monochromer
monochromer / Dockerfile
Last active February 10, 2025 07:37
Dockerfile for `lua` and `vips`
FROM alpine:3.21.0
RUN apk add --no-cache --update \
make \
gcc \
musl-dev
RUN apk add --no-cache --update \
vips \
vips-dev \
@monochromer
monochromer / caddyfile
Created December 14, 2024 16:53
Caddy server autoserving `avif` and `webp` images. For example, instead of `image.png` serve `image.png.avif` if browser support it.
https://localhost:8443 {
tls internal
vars {
staticFolder "./public"
}
map {header.Accept} {avifSuffix} {
~image/avif avif
default ''
@monochromer
monochromer / nginx.conf
Created December 6, 2024 11:03 — forked from eXtrem0us/nginx.conf
Nginx Image Filter with Caching for Upstream
########################################################################################################
# This config enables us to:
# - Resize
# - Rotate
# ...the resident images on an upstream server, with Nginx Server in our hand, On the fly!
# - Just by using arbitrary Query Parameters
# ...and
# - Cache the transformed image by address.
#
# Well, I got the Idea from https://stumbles.id.au/nginx-dynamic-image-resizing-with-caching.html
@monochromer
monochromer / fix.md
Last active January 20, 2025 14:12
Сборка h2o

Reinstall gcc:

brew uninstall gcc
brew install gcc

or reinstal MacOS CommandLineTools:

@monochromer
monochromer / app.js
Created October 31, 2023 06:26
Node.js simple HTTP proxy
const http = require('node:http')
const https = require('node:https')
const events = require('node:events')
const stream = require('node:stream/promises')
const { env } = process
http
.createServer(async (clientRequest, clientResponse) => {
try {
@monochromer
monochromer / caddyfile
Last active October 26, 2023 11:08
Caddy Server and Nginx. Get output of reverse proxy if static file not found
http://localhost:8080 {
root * ./public
@notStatic {
not {
file {
try_files {path} {path}/
}
}
}
@monochromer
monochromer / lazy-hydration.md
Last active August 1, 2023 05:46
React Lazy Hydration

https://t.me/super_oleg_dev/102

Ленивая гидрация позволяет не выполнять реакту код компонента на клиенте сразу при гидрации всего приложения, и отлично комбинируется с IntersectionObserver - можно выполнять код только при попадании компонента в область видимости.

Также, можно вообще не выполнять код на клиенте пометив блок как статичный, и каким-либо образом убирать его из клиентского бандла.

Механизм достаточно простой, это по сути легализованный хак в React, детали есть в этом issue - facebook/react#10923 (comment)

Код для lazy обертки может базово выглядеть так:

@monochromer
monochromer / index.11tydata.js
Last active June 28, 2023 19:05
Eleventy double pagination
function createPagination(paginationOptions) {
return {
data: typeof paginationOptions.data === 'string'
? paginationOptions.data
: 'collections.all',
size: 1,
alias: paginationOptions.alias ?? 'paginationChunk',