Skip to content

Instantly share code, notes, and snippets.

@HDDen
HDDen / minified-print_r-and-var_export.php
Last active July 14, 2024 12:19
minified print_r and var_export
<?php
$arr = [
'form_id' => 'https://example.ru/',
'status' => 'validation_failed',
'message' => 'Одно или несколько полей содержат ошибочные данные. Пожалуйста, проверьте их и попробуйте ещё раз.',
'invalid_fields' => [
[
'field' => 'messaging',
'message' => 'Пожалуйста, заполните все обязательные поля',
'idref' => '',
@HDDen
HDDen / smtp.php
Last active June 28, 2024 12:00
SMTP sending in one class
// https://212d.ru/blog/otpravka-pochty-cherez-smtp-s-pomoshchyu-php
<?php
/**
* SendMailSmtpClass
*
* Класс для отправки писем через SMTP с авторизацией
* Может работать через SSL протокол
* Тестировалось на почтовых серверах yandex.ru, mail.ru и gmail.com, smtp.beget.com
*
@HDDen
HDDen / composer.txt
Created June 26, 2024 13:35
composer
cd /site.com/public_html/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar require drupal/smtp
@HDDen
HDDen / Promise_cycle_example.js
Last active July 9, 2024 18:59
Promise cycle example
var temporaryPromises = block.getAttribute('data-imgs').split(',').map(function(src){
return new Promise(function (resolve, reject) {
return resolve(true);
// return resolve(false); // надо явно передавать результат + Promise.all прервется если будет хотя бы один reject
});
});
Promise.all(temporaryPromises).then(function (arr) { // в arr будет массив результатов - в данном случае, true/false
console.log(arr);
});
@HDDen
HDDen / form_json_submitting.js
Last active April 22, 2024 14:30
Custom form submit
js:
/**
* Form submit
*/
document.querySelectorAll('form').forEach(function(el){
el.addEventListener('submit', function(e){
var path = window.location.pathname+'php/sender.php';
var debug = false;
@HDDen
HDDen / scrollbar_styling.css
Last active June 16, 2024 13:02
Styling scrollbars
.styled-scrollbars {
--scrollbar-foreground: #a6a6a6;
--scrollbar-background: rgba(255, 255, 255, 0);
--scrollbar-fake-background: #f0f0f3;
--scrollbar-size: 5px;
--scroll-thumb-start: 40px;
--scroll-thumb-end: 40px;
--scrollbar-radius: 20px;
padding-right: 1px; /* экстра-отступ */
margin-right: -1px;
@HDDen
HDDen / fix_unserialized.php
Created February 7, 2024 08:51
Fix broken serialized data (drupal metatags, for example)
<?php
// based on https://stackoverflow.com/a/21389439/18216946
$unserialized = "a:2:{s:2:"aaaaaaaaaaaaa";}"; // some potentially broken data
$fixed_data = preg_replace_callback ( '!s:(\d+):"(.*?)";!', function($match) {
return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
},$unserialized );
$final = unserialize($fixed_data);
@HDDen
HDDen / cf_cache_rules_implementation_guide_spcc.md
Created January 23, 2024 12:46 — forked from isaumya/cf_cache_rules_implementation_guide_spcc.md
Super Page Cache for Cloudflare — Guide for using Remove Cache Buster Query Parameter feature (when using Cache Everything page rule)

Implementation Guide for using "Remove Cache Buster Query Parameter" feature

The Super Page Cache for Cloudflare plugin has recently added the feature for using the Cache Everything pagerule withing the ?swcfpc=1 cache buster query paramater. This opens up so many new doors where users previously had to use the Cloudflare Workers to remove the cache buster.

With this new option now users are able to take advantage of Cloudflare Cache Everything page rule and take it to the next level by using the new Rulesets released by Cloudflare. Basically this is achived by taking advantage of the all new Cache Rules feature implemented by Cloudflare.


Setp 1 — Setting up the Cache Rules inside your Cloudflare Dashboard

The first thing that you need to do is, log-in to your Cloudflare Dahsbord and go to the domain/zone doe which you are setting up the [Super Page Cache for Cloudflare](https://wordpress.org/plug

@HDDen
HDDen / js_post_wordpress_ajax_data.js
Last active February 20, 2024 19:50
js post wordpress ajax data
/**
* Cюда поместим отправляемые параметры
*/
var query = {
'action': 'loadMore',
'hdden_data': {
'posttype': 'news',
}
};
@HDDen
HDDen / js_post_json.js
Created January 6, 2024 19:47
js json send
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;
if (this.status == 200) {
var data = JSON.parse(this.responseText);
// we get the returned data
}