Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
d1i1m1o1n / header.pug
Created February 23, 2018 21:12 — forked from lineharo/header.pug
PUG - auto version .css or another files in HTML head
- function pDate() {
- return new Date().getTime();
- }
doctype html
html(lang="ru")
head
meta(charset="utf-8")
title TITLE
@d1i1m1o1n
d1i1m1o1n / TimeWeb - SSH RSA Key
Created November 9, 2016 06:53 — forked from zetrider/TimeWeb - SSH RSA Key
Авторизация SSH по RSA ключу - TimeWeb
user - имя пользователя
server.timeweb.ru - сервер
1. На машине ssh-keygen -t rsa
2. Копируем, можно по FTP или одной из команд
2.1. ssh-copy-id -i ~/.ssh/id_rsa user@server.timeweb.ru
2.2. scp ~/.ssh/id_rsa.pub user@server.timeweb.ru:~
3. На сервере
[ -d ~/.ssh ] || (mkdir ~/.ssh; chmod 711 ~/.ssh) # создание директории и изменение прав
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys # добавление открытого ключа
@d1i1m1o1n
d1i1m1o1n / index.php
Created July 5, 2016 09:14
Bitrix. New order d7
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
global $USER;
use Bitrix\Main,
Bitrix\Main\Loader,
Bitrix\Main\Config\Option,
Bitrix\Sale,
Bitrix\Sale\Order,
Bitrix\Sale\DiscountCouponsManager;
@d1i1m1o1n
d1i1m1o1n / d7.php
Created February 19, 2016 08:38
Bitrix(d7). DB query
<?php
use Bitrix\Main\Application;
$connection = Application::getConnection();
$sqlHelper = $connection->getSqlHelper();
$sql = "SELECT ID FROM b_user WHERE LOGIN = '".$sqlHelper->forSql($login, 50)."'";
//$connection->query($sql, $limit);
//$connection->query($sql, $offset, $limit);
@d1i1m1o1n
d1i1m1o1n / file.php
Created February 19, 2016 08:30
Bitrix. Clear cahce by tag
<?php
if(defined('BX_COMP_MANAGED_CACHE'))
$GLOBALS['CACHE_MANAGER']->ClearByTag('iblock_id_4'); //clear cache for iblock with ID = 4
@d1i1m1o1n
d1i1m1o1n / functions.php
Last active March 11, 2016 14:56
Plural froms сколнения
<?php
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
//usage
$ends = [
"банан",
"банана",
"бананов"
@d1i1m1o1n
d1i1m1o1n / functions.php
Created February 19, 2016 08:24
Is phone function
<?php
function isPhone($val){
if (!preg_match('/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/iu', $val))
return false;
return true;
}
//allow
@d1i1m1o1n
d1i1m1o1n / debug.php
Created February 19, 2016 08:18
Bitrix(d7). Debug
<?php
use Bitrix\Main\Diag\Debug;
use Bitrix\Main\Diag\Helper;
/*Write in file*/
//Debug::writeToFile($variable, $varName, $file);
Debug::writeToFile(['ID' => $ID, 'fields' => $arResult ], null, "log.log");
Debug::dumpToFile(['ID' => $ID, 'fields' => $arResult ], null, "log.log");
/*Time label*/
@d1i1m1o1n
d1i1m1o1n / file.php
Created February 19, 2016 08:13
PHP: Get coordinates by address.
<?php
$adress = urlencode("Москва, Тверская улица, дом 7");
$url = "http://geocode-maps.yandex.ru/1.x/?geocode={$adress}";
$content = file_get_contents($url);
preg_match("/<pos>(.*?)<\/pos>/", $content, $point);
$coords = str_replace(' ', ', ', trim(strip_tags($point[1])));
echo $coords;
// результат: 38.241803, 56.300984
@d1i1m1o1n
d1i1m1o1n / gist:b577776c2bad291cdfb8
Last active December 23, 2016 07:17 — forked from realmyst/gist:1262561
Вывести правильное окончание слова "товар" в зависимости от количества добавленных товаров в корзину (например, 1 товар, 3 товара, 5 товаров). Сколения
function getNumEnding(number, titles) {
var cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
getNumEnding(count, ["товар", "товара", "товаров"]);