Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
Hmmmmmm

u_mulder u-mulder

🤔
Hmmmmmm
View GitHub Profile
@u-mulder
u-mulder / markup.php
Last active Feb 7, 2021
Adding markup to php data
View markup.php
<?php
$newsArray = [
[
'title' => 'Новость номер 1',
'preview' => 'Краткое содержание номер 1',
'detail_url' => '/detail.php?id=1',
'author' => 'И. Иванов',
],
[
@u-mulder
u-mulder / djikstra.php
Created Aug 16, 2019
Djikstra algorithm in php
View djikstra.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 Jul 6, 2019
Transfer data from certain postgresql table fields to single hstore field
View fields_to_hstore.php
<?php
$fields = [
'field_1',
'field_2',
'field_3',
'date_field',
'field_6',
'field_7',
];
@u-mulder
u-mulder / class.php
Last active Sep 29, 2018
Interrupt execution of bitrix component based on OO approach (using class.php)
View 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 Aug 7, 2018
Count tables in a database
View tables_count.php
<?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 Apr 22, 2018
Brainfuck interpreter for Codewars kata
View brainfuck.js
// 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 Dec 23, 2017
Rotating array function
View array_rotate.php
<?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 Dec 16, 2017
Codewars fluent calculator implementation
View fluent_calc.php
<?php
/**
* @link https://www.codewars.com/kata/fluent-calculator-2
*/
class InvalidInputException extends Exception {}
class DigitCountOverflowException extends Exception {}
class DivisionByZeroException extends Exception {}
class FluentCalculator
{
View solutions.php
<?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 Sep 11, 2017
Bitrix tagged caching
View tagged_cache.php
<?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))