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 / AsteriskMatch.php
Last active Jan 29, 2016
Test string against simple mask with asterisk *
View AsteriskMatch.php
<?php
class AsteriskMatch
{
/**
* @param string $mask string with asterisk
* @param string $string tested subject
* @return bool
* @throws \Exception
*/
@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
{
/**
@m8rge
m8rge / DbTestCase.php
Created Jul 2, 2015
Yii2 db fixtures from array
View DbTestCase.php
<?php
namespace tests\codeception\common\unit;
use Codeception\Specify;
use yii\di\Instance;
use yii\test\InitDbFixture;
/**
* usage:
View XMLReader.php
<?php
namespace console\components;
class XMLReader extends \XMLReader
{
/**
* @param string $nodeName
* @return $this
@m8rge
m8rge / HashBuilder.php
Last active Aug 29, 2015 — forked from mncaudill/similar.php
Image similarity algorithm
View HashBuilder.php
<?php
# Algorithm found here: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
class HashBuilder
{
private $buf;
function __construct()
{
$this->buf = imagecreatetruecolor(8, 8);
}
@m8rge
m8rge / WithoutTrait.php
Last active Jun 8, 2017
Without yii2 activerecord trait
View WithoutTrait.php
<?php
namespace common\ActiveRecordTrait;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
trait WithoutTrait
{
@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
@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
View OCSClient.php
<?php
class OCSClient extends CComponent
{
public $login;
public $token;
public $url = 'https://b2btestservice.ocs.ru/b2b.asmx?WSDL';
@m8rge
m8rge / SoftDeleteTrait.php
Created Jan 19, 2015
Yii2 Softdelete trait (trait better than behavior)
View SoftDeleteTrait.php
<?php
trait SoftDeleteTrait
{
public static function deletedProperties()
{
return ['deleted_at' => time()];
}
public static function deleteAll($condition = '', $params = [])
You can’t perform that action at this time.