Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
Hmmmmmm

u_mulder u-mulder

🤔
Hmmmmmm
View GitHub Profile
@u-mulder
u-mulder / component_epilog.php
Last active Oct 5, 2015
Using data from result_modifier.php in component_epilog.php (bitrix)
View component_epilog.php
<?php
echo 'result is ' . $arResult['SOME_KEY']['key'];
@u-mulder
u-mulder / cssmin.go
Created Jan 20, 2016
Go POST request to cssminifier.com
View cssmin.go
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
)
@u-mulder
u-mulder / visitor_pattern.php
Last active Feb 5, 2016
PHP version of Visitor pattern
View visitor_pattern.php
<?php
/**
* Интерфейс для посещаемого
* Посещаемые объекты должны реализовывать
* - метод accept - принятие посетителя
* - метод getTotalCount - получение общей суммы чего-либо
*
*/
interface IDlvVisitee
@u-mulder
u-mulder / tg_sw.php
Created Jun 5, 2016
Send setWebhook to TelegramBot
View tg_sw.php
<?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 Aug 29, 2016
Bash script to rebase certain branch onto your current one
View git_rb.sh
#!/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 / pre-commit.sample
Last active Jan 10, 2017
Simple pre-commit hook to abort commiting if remote branch has new commits
View pre-commit.sample
#!/bin/bash
#
# Checking statuses of local and remote versions of current branch
#
# If commits from these branches differ, then someone forgot to run `git pull`
echo "Checking for changes before commit:"
echo "Fetching new info..."
git fetch
@u-mulder
u-mulder / bx.sql
Created Apr 26, 2017
Some raw queries to bitrix tables
View bx.sql
-- 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 Jul 1, 2017
Число дней в произвольном месяце произвольного года
View t_m_Y.php
<?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 Aug 24, 2017
Making change for a dollar
View solution.php
<?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 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))