Skip to content

Instantly share code, notes, and snippets.

View m8rge's full-sized avatar
👨‍💻
Code is for developers first

Andrey m8rge

👨‍💻
Code is for developers first
View GitHub Profile
<?php
// we have some model attributes in array
$modelAttributes = array(
'first',
'second'
);
// also, we have new attributes in same array. This can occure if your html form contains elements with names:
// Model[Attribute][] = first
// Model[Attribute][] = second
@m8rge
m8rge / EMemCache.php
Last active December 11, 2015 05:48
Yii component EMemCache prevents dogpile effect. WARNING! EMemCache internal cache value format incompatible with CMemCache!
<?php
/**
* Presents lockingForUpdate ability to prevent dogpile effect
*/
class EMemCache extends CMemCache
{
/**
* @param $key string
* @param $timeoutSeconds int
@m8rge
m8rge / DbTestCase.php
Created July 2, 2015 03:25
Yii2 db fixtures from array
<?php
namespace tests\codeception\common\unit;
use Codeception\Specify;
use yii\di\Instance;
use yii\test\InitDbFixture;
/**
* usage:
<?php
namespace console\components;
class XMLReader extends \XMLReader
{
/**
* @param string $nodeName
* @return $this
@m8rge
m8rge / HashBuilder.php
Last active August 29, 2015 14:21 — forked from mncaudill/similar.php
Image similarity algorithm
<?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);
}
<?php
class OCSClient extends CComponent
{
public $login;
public $token;
public $url = 'https://b2btestservice.ocs.ru/b2b.asmx?WSDL';
@m8rge
m8rge / SoftDeleteTrait.php
Created January 19, 2015 12:52
Yii2 Softdelete trait (trait better than behavior)
<?php
trait SoftDeleteTrait
{
public static function deletedProperties()
{
return ['deleted_at' => time()];
}
public static function deleteAll($condition = '', $params = [])
@m8rge
m8rge / git-anchors-check.js
Created November 24, 2014 07:00
Validate on page anchors consistence on github
(function() {
$('article').find('a:not(.anchor)[href^=#]').each(function (i, e) {
var id = $(e).attr('href').replace(/^#/, '');
if ($('a[id="' + decodeURI(id) + '"]').length == 0) {
console.log(e);
} else {
console.log('validated');
}
});
}());