Skip to content

Instantly share code, notes, and snippets.

Andrey m8rge

Block or report user

Report or block m8rge

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@m8rge
m8rge / ExcelCsvWriter.php
Last active Dec 15, 2018
Blazing fast php excel writer. With Yii2 formatter dependency
View ExcelCsvWriter.php
<?php
/**
* require Yii2 for decimal formatter
*/
class ExcelCsvWriter
{
/**
* @var resource
*/
@m8rge
m8rge / CronException.php
Last active Oct 18, 2018
Yii2 console controller behavior. Prevents double run console command
View CronException.php
<?php
namespace console\components;
use Throwable;
use yii\base\Action;
class CronException extends \RuntimeException
{
/**
View streamBase64EncodeFilter.php
<?php
class Base64Encode extends \php_user_filter
{
private $bufferHandle;
private $tail = '';
public function filter($in, $out, &$consumed, $closing)
{
@m8rge
m8rge / tooltip-over-select2.js
Last active Sep 26, 2018
twitter bootstrap tooltip over select2
View tooltip-over-select2.js
/**
* Declate title attribute on target select element.
* Initialize tooltip:
*/
jQuery("div.select2-container").tooltip({
title: function() {
return $(this).next().attr("title");
},
});
@m8rge
m8rge / FindOrCreate.php
Last active Jun 26, 2018
FindOrCreate yii2 activerecord trait
View FindOrCreate.php
<?php
namespace common\traits;
trait FindOrCreate
{
/**
* @param mixed $key Primary key or array with condition for \yii\db\Query::where(condition)
* @return static
* @throws \Exception
View Writer.php
<?php
class Writer
{
public function saveFile()
{
file_put_contents('/var/www/file.pdf', '123');
}
}
@m8rge
m8rge / SerializeAttributeBehavior.php
Last active Jun 7, 2018
SerializeAttributeBehavior
View SerializeAttributeBehavior.php
<?php
use yii\base\Behavior;
use yii\db\ActiveRecord;
class SerializeAttributeBehavior extends Behavior
{
/**
* @var string[]
*/
@m8rge
m8rge / CantSave.php
Last active May 19, 2018
Yii2 exception for non-saved active records
View CantSave.php
<?php
namespace common\exception;
use e96\sentry\ErrorHandler;
use yii\base\Exception;
use yii\db\ActiveRecord;
class CantSave extends Exception
@m8rge
m8rge / telegram icon.txt
Last active Oct 9, 2017
Telegram vector svg font icon. MIT Licensed
View telegram icon.txt
To convert this svg to web font – just upload `telegram-single-path*.svg` to http://fontello.com service!
Use `telegram-source-240px.svg` as source file.
@m8rge
m8rge / date_diff.php
Created Jun 27, 2017
Как правильно посмотреть, что одна дата больше другой на N дней
View date_diff.php
<?php
$date1 = new \DateTime('2017-01-01');
$date2 = new \DateTime('2017-01-10');
$dateInterval = $date1->diff($date2); // this is not date1-date2, but date2-date1 :-(
var_dump($dateInterval->format('%r%a') > 3); // :-(
You can’t perform that action at this time.