Skip to content

Instantly share code, notes, and snippets.

@Nelex
Nelex / answer.php
Created April 10, 2024 18:43
Answer
<?php
$levels[] = [1, 0, 2, 1,0,1,3,2,1,2,1]; //6
$levels[] = [3, 0, 2, 0, 4]; //7
$levels[] = [2, 0,0, 2]; //4
function estimate(array $levels): int
{
$count = 0;
@Nelex
Nelex / nginx-tuning.md
Created January 17, 2024 21:34 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@Nelex
Nelex / Sendy Nginx Config
Created February 7, 2023 20:36 — forked from amanjuman/Sendy Nginx Config
Sendy Nginx Config for PHP7.4 FPM
sudo su
//Setup Hostname
hostnamectl set-hostname subdomain.domain.tld
## Basic
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get autoremove -y && sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php -y && add-apt-repository ppa:nginx/stable -y
//Setup SWAP
sudo fallocate -l 1G /swapfile;
@Nelex
Nelex / mongodb_cheat_sheet.md
Created December 23, 2021 18:32 — forked from bradtraversy/mongodb_cheat_sheet.md
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@Nelex
Nelex / big-xml.php
Created September 26, 2021 20:10 — forked from chrisguitarguy/big-xml.php
How to use a combination of XMLReader and SimpleXMLElement to parse large XML files in PHP.
<?php
/**
* an example of how to read huge XML files relatively quickly and efficiently
* using a few core PHP libraries.
*
*/
// Assume your file is very large, 140MB or somethig like that
$fn = __DIR__ . '/some_file.xml';
@Nelex
Nelex / short-number-format.php
Created September 23, 2021 17:49 — forked from RadGH/short-number-format.php
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
@Nelex
Nelex / repo-reset.md
Created August 4, 2021 20:31 — forked from heiswayi/repo-reset.md
GitHub - Delete commits history with git commands

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

Так получилось что прикрутить один визивиг недостаточно, нужна по-любому загрузка картинок. Визуально лучшим редактором и более подходящим по возможностям мы выбрали CKEditor 5 в режиме balloon block. Чтобы было понятнее, режим balloon block это блочное редактирование прямо на странице с материалом.

Но есть проблема, конфиг прошлой версии CKEditor 4 не подходит. Вторая проблема, конфиг MyCustomUploadAdapter, который достаточно просто найти в сети, не работает. Перепробовал несколько версий, то идут версии чисто под реакт, то нерабочая, отправляющая вместо файла на сервер Promise.

В итоге, использовал тот же MyCustomUploadAdapter из сети с поправой из свежей версии CKFinder адаптера.

Сразу обозначу что код рабочий, но не чистый и добавлял его чтобы не забыть что как делал, но и возможно кому-то пригодиться. Кому нужно, код поправят под то как им нужно. Все это черновой код и продакшн код я не публикую специально. В итоге код выглядит так:

Использую yall как lazy-load js библиотеку, подключение здесь: https://github.com/malchata/yall.js/ На мой взгляд одна из самых удобных библиотек для ленивой загрузки картинок. И вот чтобы Картинки внутри поста так же грузились как ленивая загрузка использую следующий код:

$body = $post->body;//получаем контент поста $body = str_replace('src=','class="lazy" src="/images/imgload_small.png" data-src=',$body); //заменяем аттрибут src= на класс и подставную картинку, в моем случае это 1 пиксель прозрачного цвета.

Как итог, yall запущенный по событию DOMContentLoaded все такие картинки подключит под ленивую загрузку.

Внимание! В данном случае не учитывается что в посте могут быть другие теги с аттрибутом src, например iframe. Для своего случая учитывайте и этот момент.