|
Ok!
|
|
|
Ok!
|
---|---|---|---|---|
234 | pip install Flask set FLASK_APP=main.py flask --app main.py run | flask, запустить | 20090 | Запустить приложение python flask |
223 | public function convertImage(&$content) { if (defined('ADMIN_SECTION') || defined('WIZARD_SITE_ID')) { return; } preg_match_all('/"(/upload/[^"]*.(jpg|jpeg|png))"/i', $content, $matches1); self::convertImageToWebp($content, $matches1); preg_match_all("/'(/upload/[^']*.(jpg|jpeg|png))'/i", $content, $matches2); self::convertImageToWebp($content, $matches2); } private static function convertImageToWebp(&$content, $matches) { if (!empty($matches[1])) { foreach ($matches[1] as $i => $imageUrl) { $root = $_SERVER['DOCUMENT_ROOT']; $type = $matches[2][$i]; $newName = str_replace($type, 'webp', $imageUrl); if (file_exists($root . $newName)) { $content = str_replace($imageUrl, $newName, $content); continue; } if (!file_exists($root . $imageUrl)) { continue; } $type = strtolower($type); switch ($type) { case 'jpeg': case 'jpg': $img = imagecreatefromjpeg($root . $imageUrl); break; case 'png': $img = imagecreatefrompng($root . $imageUrl); imagepalettetotruecolor($img); imagealphablending($img, true); imagesavealpha($img, true); break; } if (isset($img)) { $result = imagewebp($img, $root . $newName, 75); if (!$result) { continue; } $content = str_replace($imageUrl, $newName, $content); imagedestroy($img); unset($img); } } } } | bitrix, webp, convert | 20030 | convert image to webp bitrix |
212 | $(document).ready(function(){ let tilDate = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 5); let tilDay = new Date(tilDate).getDate(); let monthNames = [ "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря" ]; if($('[field="tn_text_1655377664248"]').length){ new_text = tilDay + " " + monthNames[tilDate.getMonth()]; $('[field="tn_text_1655377664248"] span').text(new_text); } }); | 5 дней, JS | 20010 | Добавит 5 дней |
227 | const numbers = [1, 2, 3]; const doubled = numbers.map(x => x * 2); // [2, 4, 6] | map, js | 19800 | Метод map в javascript |
194 | <url>(.*)([^/]+)</loc>(.*)</url> | regexp | 19010 | Заменить строки, где loc оканчивается без слэша в файле sitemap.xml |
203 | /^([a-z0-9_.-]+)@([a-z0-9_.-]+).([a-z.]{2,6})$/ | regexp, email. JS | 14800 | Регулярное выражение для проверки email |
171 | http://example.com/?_ym_debug=1 | метрика, counter test, проверка | 12300 | Проверка счетчиков и событий метрики в консоли |
174 | function find_closed() { //clearTimeout(typingTimer); //typingTimer = setTimeout(doneTyping, doneTypingInterval); var found; var tr = jQuery('.pricing tr'); var pos = jQuery('body, html').scrollTop(); var s = jQuery('#searchfield').val(); //var add = jQuery('.prices').first().position().top; var old, i, cont; if(s.length > 2) { old = jQuery('.found_color').parents('td'); jQuery.each(old, function(){ cont = jQuery(this).text(); old.text(cont); }); jQuery('tr').removeClass('found'); for (i = 0; i < tr.length; i++) { if (tr.eq(i).text().toLowerCase().indexOf(s.toLowerCase()) > -1) { tr.eq(i).addClass('opened found'); var text = tr.eq(i).children('td:first-child').text().replace(s, '<span class=found_color>' + s + '</span>'); //console.log(text); tr.eq(i).children('td:first-child').html(text); found = 1; }else{ //tr.eq(i).remove(); tr.eq(i).removeClass('opened'); tr.eq(i).removeClass('found'); } } if(jQuery('.found').length){ var E = setTimeout(function(){ pos += jQuery('.found').first().parents('table').position().top; jQuery('body, html').animate({scrollTop: pos}, 300, 'swing'); console.log(pos); },300); } if (found < 1) { jQuery('.not-found').text('Не найдено на этой странице. Поищите через общий поиск') } } } | найти в скрытом аккордионе | 12300 | find_closed с подстветкой |
201 | function send(onError, onSuccess, url, method = 'GET', data = null, headers = [], timeout = 60000) { let xhr; if (window.XMLHttpRequest) { // Chrome, Mozilla, Opera, Safari xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // Internet Explorer xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open(method, url, true); headers.forEach((header) => { xhr.setRequestHeader(header.key, header.value); }) xhr.timeout = timeout; xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if(xhr.status >= 400) { onError(xhr.statusText) } else { onSuccess(xhr.responseText) } } } xhr.send(data); } | xhr, request, XMLHttpRequest, JS | 12090 | XMLHttpRequest обернутый в функцию |
205 | function flog($fname, $ftext, $write_a_w_state = null){ if(!$write_a_w_state) $write_a_w_state = "a+"; $fp = fopen("/home/d/dlmlru/posuda/public_html/log/" . $fname, $write_a_w_state); fwrite($fp, date("Y-m-d H:i:s ") . $ftext . " "); fclose($fp); } | flog | 12090 | функция логирования php |
222 | echo <<<EOH ---------- ----------- -- ---------- результат значение оп тест ---------- ----------- -- ---------- EOH; | eoh, php print formated | 12090 | Форматированная строка в PHP |
195 | include_once($root . 'getID3/getid3/getid3.php'); $getID3 = new getID3; $file = $getID3->analyze($root . $file_src); #echo("Duration: ".$file['playtime_string']. #" / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall". #" / Filesize: ".$file['filesize']." bytes<br />"); | gd3, анализ видео | 12010 | Анализ длительности, ширины, высоты видео |
199 | function maskPhone(selector, masked = '+7 (___) ___-__-__') { const elems = document.querySelectorAll(selector); function mask(event) { const keyCode = event.keyCode; const template = masked, def = template.replace(/D/g, ""), val = this.value.replace(/D/g, ""); let i = 0, newValue = template.replace(/[_d]/g, function (a) { return i < val.length ? val.charAt(i++) || def.charAt(i) : a; }); i = newValue.indexOf("_"); if (i !== -1) { newValue = newValue.slice(0, i); } let reg = template.substr(0, this.value.length).replace(/_+/g, function (a) { return "\d{1," + a.length + "}"; }).replace(/[+()]/g, "\$&"); reg = new RegExp("^" + reg + "$"); if (!reg.test(this.value) || this.value.length < 5 || keyCode > 47 && keyCode < 58) { this.value = newValue; } if (event.type === "blur" && this.value.length < 5) { this.value = ""; } } for (const elem of elems) { elem.addEventListener("input", mask); elem.addEventListener("focus", mask); elem.addEventListener("blur", mask); } } maskPhone('input[type=tel]'); | маска телефона | 12009 | Скрипт JS маски телефона |
71 | function resi($src,$w,$h) { $im_array = explode('/', $src); $folder = "/" . $im_array[1] . "/" . $im_array[2] . "/"; $file = end($im_array); $root_path = "/home/d/dlmlru/shop_beta/public_html"; if(!is_file( $root_path . "/images/products/" . 'N_'. $file)) { $inFile = $root_path . $src; $outFile = $folder . 'N_' . $file; $image = new Imagick($inFile); $image->thumbnailImage($w, $h); $image->writeImage($root_path . $outFile); return $folder . 'N_' . $file; }else{ return $folder . 'N_' . $file; } } # example <img src="<?echo resi('/images/products/DSC08794_КМГ613_1600.jpg', 200, 133);?>" width="200"/> | resize, php | 12000 | Ресайз картинок php |
214 | [display-posts category="apartamenty" image_size="medium" include_excerpt="true" orderby="date" order="ASC" include_excerpt_dash="false"] | список записей, WP | 11090 | Плагин WP – Display Posts для вывода списка записей по критериям |
170 | /bitrix/admin/perfmon_table.php?PAGEN_1=1&SIZEN_1=20&lang=ru&table_name=b_event&by=DATE_INSERT&order=desc | битрикс, отправленные письма | 11020 | Список отправленных писем в Битрикс |
242 | use BitrixMainPageAsset; use BitrixMainPageAssetLocation; Asset::getInstance()->addString("<script>***</script>", true, AssetLocation::AFTER_JS); // AssetLocation::BEFORE_CSS; // AssetLocation::AFTER_CSS; // AssetLocation::AFTER_JS_KERNEL // AssetLocation::AFTER_JS | head, js, css, d7 | 10980 | Вставка ссылок в head Битрикс |
158 | RewriteRule ^receipt/(.+)/$ receipt/full.php?tag=$1 [L] | редирект, строка на папку | 10970 | Перевод в htaccess с get параметра на папку и садресом |
67 | <? $APPLICATION->AddHeadString('ваш_код',true); ?> | шапка, битрикс, head | 10900 | Добавить любую строку в шапку Битрикс |
152 | $('[name=docviewer]').show(200, function(){$(document).on('click', function(e){ $("#docviewer").hide() })}); | iframe close, закрыть iframe | 10900 | После показа iframe закрыть его по щелчку снаружи |