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 / component_epilog.php
Last active October 5, 2015 14:30
Using data from result_modifier.php in component_epilog.php (bitrix)
<?php
echo 'result is ' . $arResult['SOME_KEY']['key'];
@u-mulder
u-mulder / cssmin.go
Created January 20, 2016 19:39
Go POST request to cssminifier.com
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
)
@u-mulder
u-mulder / visitor_pattern.php
Last active February 5, 2016 08:00
PHP version of Visitor pattern
<?php
/**
* Интерфейс для посещаемого
* Посещаемые объекты должны реализовывать
* - метод accept - принятие посетителя
* - метод getTotalCount - получение общей суммы чего-либо
*
*/
interface IDlvVisitee
@u-mulder
u-mulder / tg_sw.php
Created June 5, 2016 18:51
Send setWebhook to TelegramBot
<?php
define('BOT_TOKEN', 'YOUR_BOT_TOKEN_HERE');
$wh_url = 'YOUR_WEB_HOOK_URL'; // must support https!
$url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/setWebhook?' . http_build_query(['url' => $wh_url]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
var_dump($r);
@u-mulder
u-mulder / git_rb.sh
Last active August 29, 2016 09:52
Bash script to rebase certain branch onto your current one
#!/bin/bash
# Your project path
cd /path/to/project
# Base branch which will be rebased, suppose it's "master"
baseBranch="base_branch"
# Current branch
curBranch=`git status |head -n 1| grep "branch" | cut -d ' ' -f 4`
@u-mulder
u-mulder / bx.sql
Created April 26, 2017 13:50
Some raw queries to bitrix tables
-- Some queries to bitrix tables
-- `b_option` stores your options
select count(*) from b_option;
-- select options for a certain module
select * from b_option where MODULE_ID = 'module.name';
-- select option for a certain module with a certain name
select * from b_option where MODULE_ID = 'module.name' and NAME ='NAME_GOES_HERE'
-- delete all options for a certain module
delete from b_option where MODULE_ID = 'module.name';
@u-mulder
u-mulder / t_m_Y.php
Last active July 1, 2017 16:40
Число дней в произвольном месяце произвольного года
<?php
$year = 2016;
foreach (range(1,12) as $month) {
var_dump(getDaysCount($month, $year));
}
function getDaysCount($month, $year)
{
return date('t', strtotime('01.' . $month . '.' . $year));
}
@u-mulder
u-mulder / solution.php
Created August 24, 2017 11:48
Making change for a dollar
<?php
// Linked posts
// https://math.stackexchange.com/questions/176363/keep-getting-generating-function-wrong-making-change-for-a-dollar/176397#176397
// https://math.stackexchange.com/questions/15521/making-change-for-a-dollar-and-other-number-partitioning-problems
// Simple solution:
// Sum you need to count
$money = 4;
// Coin variants, no matter what order
$coins = [1,2];
@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))
@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;