Skip to content

Instantly share code, notes, and snippets.

View AlekVolsk's full-sized avatar

AlekVolsk AlekVolsk

View GitHub Profile
@AlekVolsk
AlekVolsk / config.php
Last active August 20, 2022 21:13
Скрипт уведомления о новых письмах в телеграм
<?php
/** @var string $timeZone */
$timeZone = 'Europe/Moscow';
/** @var bool $displayErrors */
$displayErrors = false;
/** @var array $mailConfig */
$mailConfig = [
@AlekVolsk
AlekVolsk / ajax.js
Created March 15, 2021 18:45
Ajax query function in native js using jquery syntax
function ajax ({ // объект(!)
url, // url
type = 'GET', // *GET|POST
data = {}, // document.getElementById('formId') | FormData obj | serialized string | json | {}
dataType = 'json', // output format: *'json' | 'html' | 'formData' (FormData obj, return json from the backend!)
contentType = null, // Content-Type header string
before = () => {},
success = (response) => {},
error = (response, status) => {},
after = () => {}
@AlekVolsk
AlekVolsk / dominant_color.php
Last active November 7, 2021 21:12
Get Dominant & Сontrast color
<?php
/**
* getDominantColor
* Получение доминантного цвета. Функция требует наличия библиотеки GD.
*
* @param string $fname полный путь к файлу относительно сервера
* @param bool $skipBlackAndWhite пропускать чисто белый и чисто чёрный тона
* @return array
*/
@AlekVolsk
AlekVolsk / func.php
Created October 31, 2020 16:56
mb_ord() && mb_chr() for php < 7.2
<?php
if (!function_exists('mb_ord')) {
function mb_ord($string)
{
if (extension_loaded('mbstring') === true) {
mb_language('Neutral');
mb_internal_encoding('UTF-8');
mb_detect_order(array('UTF-8', 'ISO-8859-15', 'ISO-8859-1', 'ASCII'));
$result = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8'));
@AlekVolsk
AlekVolsk / icontrim.php
Last active January 10, 2021 18:29
Вырезать из строки иконочные символы
<?php
function icontrim($str)
{
$out = '';
$split = 1;
$arr = [];
$excludes = [
8211, // – shord dash
8212, // — long dash
@AlekVolsk
AlekVolsk / marquee.html
Created January 5, 2020 21:35
Бегущая строка на CSS
<div class="resultStats">
<div class="resultMarquee">Прокручиваемый контент</div>
<div class="resultMarquee">Прокручиваемый контент</div> /* повторять много раз, если не умещается */
</div>
<style>
.resultStats {
position: relative;
white-space: nowrap;
overflow: hidden;
@AlekVolsk
AlekVolsk / article_fields.php
Created January 5, 2020 21:32
Joomla: get custom fields in a articles module
<?php
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
foreach ($list as $item) {
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
$fields = [];
foreach($item->jcfields as $jcfield)
{
$fields[$jcfield->name] = $jcfield;
@AlekVolsk
AlekVolsk / get_cache_images.php
Created August 27, 2019 12:16
getCacheSquaredImages – square image cropping function
<?php
/**
* getCacheSquaredImages square image cropping function
*
* (array) $imagesList unassociated array of images with relative paths from the site root folder
* (string) $pathCache image cache folder path relative to the root folder of the site
* (int) $sliderSquareSize image full square size
* (int) $thumbSqaureSize image thumbnail square size
*
* retunt (array) unassociated array, where each element is an array with relative folders
@AlekVolsk
AlekVolsk / reading_time.php
Last active July 22, 2019 16:45
Getting time to read the article with the images in it
<?php
function getReadingTime($content)
{
$wordsPerMinuten = 200; // ru: слов в минуту
$secondsPerImage = 5; // ru: секунд на изображение
preg_match_all("~<img~i", $content, $resImgs);
$imgsTime = count($resImgs[0]) * $secondsPerImage;
$words = count(explode(' ', strip_tags(str_replace(["\n", '><'], ' ', $content))));
@AlekVolsk
AlekVolsk / polyfills.js
Created May 31, 2019 16:15
IE11 polyfill's: matches, closest, forEach
(function () {
// matches
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.matchesSelector ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector;
}