Skip to content

Instantly share code, notes, and snippets.

Ihor Vyspiansky vyspiansky

Block or report user

Report or block vyspiansky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
vyspiansky / strip-tags.js
Created Jan 4, 2020
JavaScript: remove HTML tags
View strip-tags.js
function strip(html) {
const tempWrapper = document.createElement("DIV");
tempWrapper.innerHTML = html;
return tempWrapper.textContent || tempWrapper.innerText;
const html = '<p><strong>Lorem Ipsum<strong> is simply dummy text of the printing and typesetting industry.</p>';
const plainText = strip(html);
vyspiansky / remove-duplicate-spaces.php
Created Jan 4, 2020
PHP: remove duplicate spaces in a string
View remove-duplicate-spaces.php
// Let's replace adjacent spaces with one space
$text = " один два три ";
$text = preg_replace('| +|', ' ', $text);
// Output:
vyspiansky / human-readable-random-string.php
Last active Jan 5, 2020
PHP: human readable random string
View human-readable-random-string.php
* Human Readable Random String
* @param int length Length of random string (must be a multiple of 2).
* @return string Returns the random string.
function readable_random_string($length = 8) {
$consonants = [
"b", "c", "d", "f", "g",
vyspiansky / unzip-file.php
Last active Jan 4, 2020
PHP: unzip ZIP file
View unzip-file.php
// Path to zip file
$file = '...';
// Destination directory for unzipped files
$dest = '...';
// Create object
$zip = new ZipArchive();
vyspiansky / split-word-in-capital-ukrainian-letters.php
Last active Jan 4, 2020
PHP: split a word in capital Ukrainian letters
View split-word-in-capital-ukrainian-letters.php
// PHP: split a word in capital Ukrainian letters
$pattern = '/[А-ЯҐЄІЇ][^А-ЯҐЄІЇ]*/u';
$subject = 'АкулаҐаваЄнотІгуанаЇжак';
preg_match_all($pattern, $subject, $matches);
// Output: [['Акула', 'Ґава', 'Єнот', 'Ігуана', 'Їжак']]
vyspiansky / truncate-text-at-word-break.php
Last active Jan 4, 2020
PHP: truncate the text without breaking the words into pieces
View truncate-text-at-word-break.php
$charset = 'UTF-8';
$text = 'Повість — літературний прозовий твір середньої форми, довший за оповідання, але коротший за роман, під відповідною назвою поширений у слов\'янських мовах та країнах.';
// truncate a long line to the required length
$truncated_text = mb_substr($text, 0, mb_strpos($text, ' ', 35, $charset), $charset);
echo $truncated_text;
// Output: Повість — літературний прозовий твір
vyspiansky / truncate-string-with-ellipsis.css
Created Jan 4, 2020
CSS: truncate string with ellipsis
View truncate-string-with-ellipsis.css
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
vyspiansky / show-empty-table-cells.css
Created Jan 4, 2020
CSS: show the empty cells in the table
View show-empty-table-cells.css
td {
empty-cells: show;
vyspiansky / replace-br-with-p.sql
Created Jan 4, 2020
MySQL: replace <br> with <p>
View replace-br-with-p.sql
# let's say we have an `article` table with `text` field
UPDATE `article` SET `text` = CONCAT('<p>', REPLACE(`text`, '<br>', '</p><p>'), '</p>');
vyspiansky / hidden-element-width-height.js
Created Jan 4, 2020
jQuery: get the width/height of a hidden element ("display: none")
View hidden-element-width-height.js
const elem = $("#someSelector");
// set specific styles to calculate the width/height
display: "block"
position: "absolute",
visibility: "hidden"
const elemWidth = elem.outerWidth();
You can’t perform that action at this time.