Skip to content

Instantly share code, notes, and snippets.

View asboldyrev's full-sized avatar

Andrew Boldyrev asboldyrev

  • Zmeinogorsk, Russia
  • 12:43 (UTC +07:00)
View GitHub Profile
if (!function_exists('string_match')) {
function string_match(string $haystack, string $needle, bool $inPosition = false) {
$length = mb_strlen($haystack);
for ($index = 0; $index < $length; $index++) {
if (mb_substr($haystack, $index, 1) != mb_substr($needle, $index, 1)) {
return $inPosition ? $index : ($index * 100 / $length);
}
}
@asboldyrev
asboldyrev / short_url.php
Last active July 19, 2022 05:43
Генератор «уникальных» строк, для использования в ссылках
<?php
function google_short_url(int $len = 7, string $prefix = '') {
$short = $prefix;
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$charslen = strlen($chars);
for ($index=0; $index<$len; $index++) {
$rnd = rand(0, $charslen);
$short .= substr($chars, $rnd, 1);
@asboldyrev
asboldyrev / HDR.scm
Last active December 28, 2022 16:41
script for GIMP creating pseudo HDR from the color model Lab
; Install to ~/.gimp/2.10/scripts
(define (script-fu-hdr-from-lab inImage inLayer)
(let*
(
; Define variables
(copy 0)
(copy2 0)
(lightness 0)
(lightness2 0)
@asboldyrev
asboldyrev / byte_converter.php
Last active August 5, 2020 14:41
byte converter
<?php
function byte_convert($bytes, $format = null) {
$base = 1024;
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
if($format) {
$format = mb_strtoupper($format, 'UTF-8');
$exp = array_search($format, $units);
return round($bytes / pow($base, $exp)) . ' ' . $format;
@asboldyrev
asboldyrev / wallpaper.sh
Last active January 18, 2018 13:15
wallpaper
#!/bin/bash
DIR="/home/boldyreva/Изображения/wallpapers/yandex"
DATE=$(date +%Y-%m-%d)
TIMESTAMP=$(date +%Y-%m-%d%t%H:%M:%S)
URL="https://yandex.ru/images/today?size=1920x1200"
FILENAME=${DIR}/Yandex-Images-${DATE}.jpg
if ! [ -f ${DIR}/Yandex-Images-${DATE}.jpg ]; then
wget -P ${DIR}/ ${URL}