Skip to content

Instantly share code, notes, and snippets.

View u-mulder's full-sized avatar
🤔
Hmmmmmm

Kirill Baranov u-mulder

🤔
Hmmmmmm
View GitHub Profile
@u-mulder
u-mulder / markup.php
Last active February 7, 2021 20:43
Adding markup to php data
<?php
$newsArray = [
[
'title' => 'Новость номер 1',
'preview' => 'Краткое содержание номер 1',
'detail_url' => '/detail.php?id=1',
'author' => 'И. Иванов',
],
[
@u-mulder
u-mulder / djikstra.php
Created August 16, 2019 20:27
Djikstra algorithm in php
<?php
/**
* Djikstra algorithm in php
*
* Input data from STDIN as:
*
* 4 8
* 1 2 6
* 1 3 2
@u-mulder
u-mulder / fields_to_hstore.php
Created July 6, 2019 20:10
Transfer data from certain postgresql table fields to single hstore field
<?php
$fields = [
'field_1',
'field_2',
'field_3',
'date_field',
'field_6',
'field_7',
];
@u-mulder
u-mulder / class.php
Last active February 16, 2024 06:59
Interrupt execution of bitrix component based on OO approach (using class.php)
<?php
use \Bitrix\Main\Error;
use \Bitrix\Main\ErrorCollection;
class MySuperComponent extends CBitrixComponent
{
const SEVERE_ERROR = 1;
const ALARM_ERROR = 2;
@u-mulder
u-mulder / tables_count.php
Created August 7, 2018 10:10
Count tables in a database
<?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>';
@u-mulder
u-mulder / brainfuck.js
Created April 22, 2018 10:19
Brainfuck interpreter for Codewars kata
// 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
@u-mulder
u-mulder / array_rotate.php
Last active December 23, 2017 19:03
Rotating array function
<?php
function rotateArray($a, $clockwise = true)
{
$r = [];
$i = 0;
$ti = count($a[0]);
$tj = count($a);
for (; $i < $ti; $i++) {
$row = [];
@u-mulder
u-mulder / fluent_calc.php
Last active August 18, 2023 12:01
Codewars fluent calculator implementation
<?php
/**
* @link https://www.codewars.com/kata/fluent-calculator-2
*/
class InvalidInputException extends Exception {}
class DigitCountOverflowException extends Exception {}
class DivisionByZeroException extends Exception {}
class FluentCalculator
{
@u-mulder
u-mulder / solutions.php
Created September 19, 2017 13:59
ADV test
<?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;
@u-mulder
u-mulder / tagged_cache.php
Last active September 11, 2017 09:42
Bitrix tagged caching
<?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))