Skip to content

Instantly share code, notes, and snippets.

@condor-bird
condor-bird / regular-expression.php
Last active April 26, 2018 16:25
Regular expression
<?php
//поиск строки, где нет title=
<a (?![^>]*title=".+?").*?\/>
// preg_replace("#(</?\w+)(?:\s(?:[^<>/]|/[^<>])*)?(/?>)#ui", '$1$2', $html);
// \w+(?<!href|title|alt|height|width|src)=".+?"
// <([a-z][a-z0-9]*)(?:[^>]*(\shref=['\"][^'\"]*['\"]))?[^>]*?(\/?)> <$1$2$3>
@condor-bird
condor-bird / htmlspecialchars-only-code-tags.php
Created April 22, 2018 11:23
htmlspecialchars only on code tags
<?php
// htmlspecialchars only on <code></code> tags.
// test data
$textToScan = "Hi <code>test12</code><br>
Line 2 <code><br>
Test <b>Bold</b><br></code><br>
";
// the regex pattern (case insensitive & multiline
@condor-bird
condor-bird / php-notes.php
Last active May 12, 2018 16:46
PHP notes
<?php
preg_replace("/http:\/\/.*?\//", "", $string);
preg_replace("@^https?://[^/]+/@", "", $string);
//delete all attribute html
preg_replace("#(</?\w+)(?:\s(?:[^<>/]|/[^<>])*)?(/?>)#ui", '$1$2', $html);
@condor-bird
condor-bird / slick-example.html
Created June 19, 2018 16:56
Example slick jquery plugins
<div class="slider">
<div class="slide">your content</div>
<div class="slide">your content</div>
<div class="slide">your content</div>
<div>
<h1>ignore me</h1>
</div>
</div>
CREATE TABLE `offer`(
`_ID` INT NOT NULL,
`_IDoffers` INT NOT NULL,
`available` VARCHAR(255) NOT NULL,
`barcode` VARCHAR(255) NULL,
`categoryId` INT NULL,
`currencyId` INT NULL,
`delivery` INT NULL,
`description` TEXT NULL,
`id` INT NOT NULL,
@condor-bird
condor-bird / test-translit.php
Created January 21, 2019 10:12
test translit
<?php
function rus2translit($string) {
$converter = array(
'а' => 'a', 'б' => 'b', 'в' => 'v',
'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'e', 'ж' => 'zh', 'з' => 'z',
'и' => 'i', 'й' => 'y', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n',
'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u',
@condor-bird
condor-bird / preg_split.php
Created February 23, 2019 10:55
Split Link
<?php
$regex = '#(https?://[a-z0-9.?=+_-]*)#i';
$res = preg_split($regex, $string, -1, PREG_SPLIT_NO_EMPTY);
@condor-bird
condor-bird / has-children-javascript.js
Created April 4, 2020 08:39
How to check if element has any children in Javascript?
if (element.firstChild) {
// It has at least one
}
if (element.hasChildNodes()) {
// It has at least one
}
if (element.childNodes.length > 0) { // Or just `if (element.childNodes.length)`
// It has at least one
@condor-bird
condor-bird / react-view-resize.js
Created April 4, 2020 08:42
Rerender view on browser resize with React
import React, { useLayoutEffect, useState } from 'react';
function useWindowSize() {
const [size, setSize] = useState([0, 0]);
useLayoutEffect(() => {
function updateSize() {
setSize([window.innerWidth, window.innerHeight]);
}
window.addEventListener('resize', updateSize);
updateSize();
@condor-bird
condor-bird / dom-change-listener.js
Created April 4, 2020 08:43
Is there a JavaScript DOM change listener?
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
// fired when a mutation occurs
console.log(mutations, observer);
// ...
});
// define what element should be observed by the observer
// and what types of mutations trigger the callback