Skip to content

Instantly share code, notes, and snippets.

View kvalexandr's full-sized avatar

Alexandr Kudryavtsev kvalexandr

View GitHub Profile
$('.content iframe').wrap('<div class="video-wrap"></div>');
.video-wrap {
height: 0;
overflow: hidden;
padding-bottom: 56.25%;
position: relative;
}
.video-wrap iframe, .video-wrap object, .video-wrap embed {
function getChar(event) {
if (event.which == null) { // IE
if (event.keyCode < 32) return null; // спец. символ
return String.fromCharCode(event.keyCode)
}
if (event.which != 0 && event.charCode != 0) { // все кроме IE
if (event.which < 32) return null; // спец. символ
return String.fromCharCode(event.which); // остальные
}
function number_format(number, decimals, dec_point, thousands_sep) {
var i, j, kw, kd, km;
// input sanitation & defaults
if (isNaN(decimals = Math.abs(decimals))) {
decimals = 2;
}
if (dec_point == undefined) {
dec_point = ",";
UPDATE wp_options SET option_value = replace(option_value, 'http://domain.ru', 'http://newdomain.ru') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://domain.ru','http://newdomain.ru');
UPDATE wp_posts SET post_content = replace(post_content, 'http://domain.ru', 'http://newdomain.ru');
<?php
$query = array(
'access_token' => 'token',
'count' => 6
);
$url = 'https://api.instagram.com/v1/users/[user-id]/media/recent/?' . http_build_query($query);
try {
$curl_connection = curl_init($url);
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
<?php
$cacheId = 'uniqueCacheId';
$cacheTtl = '3600';
$cache = \Bitrix\Main\Application::getInstance()->getManagedCache();
if ($cache->read($cacheTtl, $cacheId)) {
$data = $cache->get($cacheId); // get our data
} else {
$data = '12345678';
В result_modifier.php шаблона вставляем:
<?
// сортировку берем из параметров компонента
$arSort = array(
$arParams["SORT_BY1"]=>$arParams["SORT_ORDER1"],
$arParams["SORT_BY2"]=>$arParams["SORT_ORDER2"],
);
// выбрать нужно id элемента, его имя и ссылку. Можно добавить любые другие поля, например PREVIEW_PICTURE или PREVIEW_TEXT
$arSelect = array(
#добавлем в конец url слеш
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*/[^/\.]+)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
@kvalexandr
kvalexandr / plural.php
Last active November 29, 2015 00:24
Plural numbers
<?php
function plural($number, $titles) {
$cases = array (2, 0, 1, 1, 1, 2);
return $titles[ ($number % 100 > 4 && $number % 100 < 20) ? 2 : $cases[min($number % 10, 5)] ];
}