Skip to content

Instantly share code, notes, and snippets.

View ivansky's full-sized avatar
😊
Wubba lubba dub dub!

Ivan Martianov ivansky

😊
Wubba lubba dub dub!
  • Armenia, Yerevan
View GitHub Profile
@ivansky
ivansky / credit_card.php
Created August 29, 2014 05:46
Check credit card type
<?php
/**
* Validates a credit card number using an array of approved card types.
*
* @param $number
* The credit card number to validate.
* @param $card_types
* An array of credit card types containing any of the keys from the array
* returned by commerce_payment_credit_card_types(). Only numbers determined
<?php
$source = [
'color' => ['red','blue','white','yellow','black'],
'who' => ['rabbit','bear','wolf'],
'else' => ['in space','in Russia','is hungry','is dead']
];
var_dump(recursion_calculate($source));
<?php
function parseClasses($classes){
return explode(' ', preg_replace('/[\t\s]+/',' ', trim($classes)));
}
function addBodyClass($class){
global $APPLICATION;
$classes = parseClasses($APPLICATION->GetPageProperty('body_class'));
$add = parseClasses($class);
<?php
define('ROOT', $_SERVER['DOCUMENT_ROOT']);
class AutoLoader {
private static $possible = array();
private static $events = array();
public static function load($class){
<?php
function test($str){
list($var) = explode('/', $str);
return $var;
}
function test2($str){
$var = array_shift(explode('/', $str));
return $var;
@ivansky
ivansky / .htaccess
Last active February 12, 2019 10:09
PHP 304 Last Modified Example
# Bitrix Example
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
#RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
@ivansky
ivansky / search_keyword_prepare.php
Created May 26, 2015 10:45
Search Keyword Prepare
<?php
/**
* Remove from string all invalid characters
* Leave only English, Russian, Turkish, Kazakh and Numbers
* @link http://www.unicode.org/charts/
* @param string $w
* @return string
*/
function prepareSearchKeyword($w){
@ivansky
ivansky / YADWord.php
Created May 26, 2015 11:25
Yandex Wordstat Collector
<?php
class YADWord {
private static $bind_region = array();
private static $bind_crc = array();
public $region_id = 213;
public $original;
type ScrollDirection = 'vertical' | 'horizontal' | 'both';
/**
* It prevents default behaviour above the scrollable areas
* until it's in available scrollable direction.
*
* Example of checkScrollableElement:
*
* var cleanBlocking = (
* blockOverScroll(