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
@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
<?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 / pullUpLastTag.php
Created November 15, 2013 05:15
Подтягивает последний тег до последнего коммита и пушит его в мастер.
#!/usr/bin/env php
<?php namespace App;
/**
* @param string $command
* @return string[]
*/
function exec($command)
{
echo "> $command\n";
@m8rge
m8rge / gist:7923382
Last active December 31, 2015 02:49
chef, будь он неладен
# Создание шаблона с sql созданием бд и пользователя
template "/var/tmp/getmail_create_tables.mysql" do
source "mysql/getmail.sql.erb"
mode "0600"
# только если пользователя бд нет
not_if "mysql -e \"\" -h localhost -P 3306 getmail"
# запускаем на выполнение
notifies :run, "execute[mysql_create_getmail_tables]", :immediately
end
@m8rge
m8rge / tooltip-over-select2.js
Last active September 8, 2020 10:20
twitter bootstrap tooltip over select2
/**
* Declate title attribute on target select element.
* Initialize tooltip:
*/
jQuery("div.select2-container").tooltip({
title: function() {
return $(this).next().attr("title");
},
});
@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');
}
});
}());
@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 = [])
<?php
class OCSClient extends CComponent
{
public $login;
public $token;
public $url = 'https://b2btestservice.ocs.ru/b2b.asmx?WSDL';
@m8rge
m8rge / CantSave.php
Last active May 19, 2018 18:13
Yii2 exception for non-saved active records
<?php
namespace common\exception;
use e96\sentry\ErrorHandler;
use yii\base\Exception;
use yii\db\ActiveRecord;
class CantSave extends Exception
@m8rge
m8rge / FindOrCreate.php
Last active June 26, 2018 04:37
FindOrCreate yii2 activerecord trait
<?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