Skip to content

Instantly share code, notes, and snippets.

Karel Wintersky KarelWintersky

  • St.Peterburg
Block or report user

Report or block KarelWintersky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@KarelWintersky
KarelWintersky / csv_to_array.php
Created Oct 11, 2015 — forked from jaywilliams/csv_to_array.php
Convert a comma separated file into an associated array.
View csv_to_array.php
/**
* Convert a comma separated file into an associated array.
* The first row must contain the array keys.
* Return something like this:
* Array
(
[0] => Array
(
[name] => Lorem
[number] => 11
View auntAsya.php
<?php
/**
* @name Aunt Asya has arrived =)
* @author M1zh0rY
* @category js clear script
* Infected Script:
* JS/Agent.* (all, ESET)
* JS/Kryptik.LP (ESET)
* Trojan:JS/BlacoleRef.BC (MCE)
* @license GNU
@KarelWintersky
KarelWintersky / Russian Plural Form in PHP
Last active Aug 15, 2016 — forked from fomigo/gist:2382775
Russian Plural Form in PHP
View Russian Plural Form in PHP
<?php
/*
echo plural_form(42, array('арбуз', 'арбуза', 'арбузов'));
*/
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]);
}
View vsprintf_keysarray.php
<?php
/**
* Like vsprintf, but accepts $args keys instead of order index.
* Both numeric and strings matching /[a-zA-Z0-9_-]+/ are allowed.
*
* Example: vskprintf('y = %y$d, x = %x$1.1f', array('x' => 1, 'y' => 2))
* Result: 'y = 2, x = 1.0'
*
* $args also can be object, then it's properties are retrieved
* using get_object_vars().
View kw.core.php
<?php
/**
* Эквивалент isset( array[ key ] ) ? array[ key ] : default ;
* at PHP 7 useless, z = a ?? b;
* @param $array
* @param $key
* @param $default
*/
function at($array, $key, $default)
{
View kw.core.dates.php
<?php
/**
* конвертирует дату из человекопонятного представления в метку времени, для создания метки времени берется полдень указанной даты
* @param $str_date
* @param string $format
* @return int
*/
function convertDateToTimestamp($str_date, $format = "d.m.Y")
{
View kw.core.converting.php
<?php
/**
* @param $size
* @return string
*/
function convertToHumanBytes($size)
{
$inflexion = array(" Bytes", " K", " M", " G", " T", " P", " E", " Z", " Y");
return $size ? round($size / pow(1024, ($i = floor(log($size, 1024)))), 0) . $inflexion[$i] : '0'.$inflexion[0];
View examples.php
<?php
/* EXAMPLES
$ip="127.0.12.7"; // IP для проверки
$test_ip=explode(".",$ip);
$range="127.0.0.0/22"; // Маска подсети
$chk=range_parser($range);
chk_ips($test_ip,$chk[0],$chk[1]); // FALSE
$range="127.0.0.0-127.1.0.255"; // Интервал IP-адресов
@KarelWintersky
KarelWintersky / !Как установить сфинкс.md
Created Apr 10, 2016 — forked from codedokode/!Как установить сфинкс.md
Как установить и настроить сфинкс.
View !Как установить сфинкс.md

Как установить и настроить сфинкс.

Скачиваем сфинкс (берем версию с MySQL и со стеммингом на 15 языков Win32 binaries w/MySQL+PgSQL+libstemmer+id64 support соответствующую битности твоей ОС), распаковываем например в d:\temp\s\

На этом установка sphinx завершена. В дебиане просто делаем sudo apt-get install sphinxsearch.

Создаем таблицы:

CREATE TABLE news 
    (id INT(10) AUTO_INCREMENT PRIMARY KEY, topic INT(10) NOT NULL, header VARCHAR(200) NOT NULL, 
@KarelWintersky
KarelWintersky / Fiddling with MySQL: information_scheme
Last active Aug 15, 2016
Fiddling with MySQL: information_scheme
View Fiddling with MySQL: information_scheme
$check_tables = array(
'table_1', 'table_2', 'table_3'
);
$check_tables_strs = array_map(function($n){
return "SELECT '{$n}' as table_name";
}, $check_tables);
$unions = implode($check_tables_strs, " UNION ALL \n");
You can’t perform that action at this time.