This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$newsArray = [ | |
[ | |
'title' => 'Новость номер 1', | |
'preview' => 'Краткое содержание номер 1', | |
'detail_url' => '/detail.php?id=1', | |
'author' => 'И. Иванов', | |
], | |
[ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Djikstra algorithm in php | |
* | |
* Input data from STDIN as: | |
* | |
* 4 8 | |
* 1 2 6 | |
* 1 3 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fields = [ | |
'field_1', | |
'field_2', | |
'field_3', | |
'date_field', | |
'field_6', | |
'field_7', | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \Bitrix\Main\Error; | |
use \Bitrix\Main\ErrorCollection; | |
class MySuperComponent extends CBitrixComponent | |
{ | |
const SEVERE_ERROR = 1; | |
const ALARM_ERROR = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
$dbh = new PDO('mysql:dbname=DBNAME;host=HOST', 'USER', 'PASSWORD'); | |
} catch (\Exception $e) { | |
echo $e->getMessage(); | |
die('Dead in ' . __FILE__ . ' on line ' . __LINE__ . PHP_EOL); | |
} | |
$r = $dbh->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "DBNAME"'); | |
echo '<pre>Count: ', print_r($r->fetch()), '</pre>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kata url: https://www.codewars.com/kata/my-smallest-code-interpreter-aka-brainf-star-star-k | |
function brainLuck(code, input) { | |
let output = ''; | |
let pointer = 0 | |
let input_pointer = 0; | |
let storage = {}; | |
let t = code.length; | |
let counter = 0; | |
let breakFor = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rotateArray($a, $clockwise = true) | |
{ | |
$r = []; | |
$i = 0; | |
$ti = count($a[0]); | |
$tj = count($a); | |
for (; $i < $ti; $i++) { | |
$row = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @link https://www.codewars.com/kata/fluent-calculator-2 | |
*/ | |
class InvalidInputException extends Exception {} | |
class DigitCountOverflowException extends Exception {} | |
class DivisionByZeroException extends Exception {} | |
class FluentCalculator | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* test1.php */ | |
$x = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];; | |
$x = array_reduce( | |
$x, | |
function ($t, $v) { | |
$prev = $t; | |
$t = []; | |
$t[$v] = $prev; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Source example comes from https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&LESSON_ID=2978 | |
$cacheTime = 10; | |
$cacheId = 'cache_id_comes_here'; | |
$cacheDir = '/some_tag_cache/subsubdir'; | |
/* D7 version */ | |
$cache = Bitrix\Main\Data\Cache::createInstance(); | |
if ($cache->initCache($cacheTime, $cacheId, $cacheDir)) |
NewerOlder