Skip to content

Instantly share code, notes, and snippets.

View arterm-sedov's full-sized avatar

arterm-sedov

View GitHub Profile
@arterm-sedov
arterm-sedov / transliterate-russian-to-lower-latin.php
Created December 12, 2024 12:04
PHP code to convert Russian letters to Latin lower case letters
<?php
function transliterate_to_lower($string)
{
$cyr = ['а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п', 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я'];
$lat = ['a','b','v','g','d','e','e','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sh','','y','','e','yu','ya'];
$strlat = str_replace($cyr, $lat, mb_strtolower($string));
return $strlat;
}
echo transliterate_to_lower("Привет, 1-й ёжик!");
@arterm-sedov
arterm-sedov / slugify-string.php
Last active December 12, 2024 12:07
PHP code to slugify strings into neat URLs
<?php
function slugify($string) {
$string = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $string);
$string = preg_replace('/[-\s]+/', '-', $string);
return trim($string, '-');
}
echo slugify("Hello Wörld! Καλημέρα. Привет, 1-й ёжик!. 富士山. 國語");
?>
@arterm-sedov
arterm-sedov / replace_italic_markdown.md
Last active December 5, 2024 14:21
replace italic ** with __ in markdown

A gist for VS Code to replace *italic* notation in markdown with _italic_ notation

Regex to match:

(?<!\*)\*(?!\*|\s)(.+?)(?<!\s|\*)\*(?!\*)

Regex to substitute:

_$1_

<!DOCTYPE html>
<html>
<head>
<title>Copy Header Anchor</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>
<div class="section">
<h1 id="section1">Section 1</h1>
@arterm-sedov
arterm-sedov / gist:1a63ce4ebc4deaf3cd3f3a3b194f2c81
Created August 18, 2023 09:39
phpkb automatic TOC generation
<?php
function TableOfContents($depth)
{
$html_string = Articles_Detail('All');
//get the headings down to the specified depth
$pattern = '/<h[2-'.$depth.']+ id=".+"[^>]*>.*?<\/h[2-'.$depth.']>/';
$whocares = preg_match_all($pattern,$html_string,$winners);
//reformat the results to be more usable
(.*[а-яА-ЯёЁ]+.*)+
@arterm-sedov
arterm-sedov / ok_remove_all_posts.js
Last active March 31, 2024 11:34
A script to remove all posts from your ok.ru wall
(function ()
{
'use strict';
if (!confirm('Удалить все заметки со стены?')) return;
var deletePostLink = document.body.querySelectorAll('a.delete-stub_cancel');
for (var i = 0; i < deletePostLink.length; i++)
{
deletePostLink[i].click();
}
alert( 'удалено записей:'+deletePostLink.length);