Skip to content

Instantly share code, notes, and snippets.

View KarelWintersky's full-sized avatar

Karel Wintersky KarelWintersky

View GitHub Profile
@KarelWintersky
KarelWintersky / csv_to_array.php
Created October 11, 2015 21:08 — forked from jaywilliams/csv_to_array.php
Convert a comma separated file into an associated array.
/**
* 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
@KarelWintersky
KarelWintersky / auntAsya.php
Created October 11, 2015 21:13 — forked from M1zh0rY/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 / vsprintf_keysarray.php
Created October 11, 2015 22:25
vsprintf using hasharray
<?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().
@KarelWintersky
KarelWintersky / kw.core.php
Created October 11, 2015 22:28
KW: Core functions
<?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)
{
@KarelWintersky
KarelWintersky / kw.core.dates.php
Created October 11, 2015 22:30
KW: Date functions
<?php
/**
* конвертирует дату из человекопонятного представления в метку времени, для создания метки времени берется полдень указанной даты
* @param $str_date
* @param string $format
* @return int
*/
function convertDateToTimestamp($str_date, $format = "d.m.Y")
{
@KarelWintersky
KarelWintersky / kw.core.converting.php
Created October 11, 2015 22:32
KW: Value converting
<?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];
@KarelWintersky
KarelWintersky / examples.php
Created October 11, 2015 22:33
KW: IP functions
<?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 April 10, 2016 03:13 — forked from codedokode/!Как установить сфинкс.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 / Flatten array
Last active August 15, 2016 05:19
Flatten array
/**
$data = array(
'user' => array(
'email' => 'user@example.com',
'name' => 'Super User',
'address' => array(
'billing' => 'Street 1',
'delivery' => 'Street 2'
)
),
@KarelWintersky
KarelWintersky / Fiddling with MySQL: information_scheme
Last active August 15, 2016 05:19
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");