Skip to content

Instantly share code, notes, and snippets.

View SDKiller's full-sized avatar

Serge Postrash SDKiller

View GitHub Profile
@SDKiller
SDKiller / gist:11ac03cc67a28318547c
Last active August 29, 2015 14:02
Жесть (а кому щас легко?)
-- getTotal --
SELECT
tfv.*,
COUNT(*) FROM `#__xfx_brokers` AS t
LEFT JOIN (
SELECT fv.`broker_id`,
MAX(IF(fv.`field_id` = 1, fv.`field_value`, NULL)) AS field_1,
MAX(IF(fv.`field_id` = 3, fv.`field_value`, NULL)) AS field_3,
MAX(IF(fv.`field_id` = 5, fv.`field_value`, NULL)) AS field_5
@SDKiller
SDKiller / AssetManagerDev.php
Created July 6, 2014 20:54
AssetManager override
<?php
namespace common\components;
use Yii;
use \yii\web\AssetManager;
class AssetManagerDev extends AssetManager
{
public function afterValidate()
{
$schema = static::getTableSchema();
foreach ($this->attributes as $attribute => $value) {
if (!$this->hasErrors($attribute)) {
$typecasted = $schema->getColumn($attribute)->phpTypecast($value);
if ($value !== $typecasted) {
$this->setAttribute($attribute, $typecasted);
SELECT
`broker_id`,
`account_number`,
`account_id`,
EXTRACT(YEAR_MONTH FROM `payment_date`) AS `yyyymm`,
SUM(`amount_total`) AS `sum_amount_total`,
SUM(`amount`) AS `sum_amount`
FROM `lk_withdrawals`
WHERE
(`user_id`=1) AND (`status`=1)
@SDKiller
SDKiller / gist:059f2729f51d18979bf3
Created September 12, 2014 17:11
FileHelper override
public static function removeDirectory($dir, $options = [])
{
if (!is_dir($dir)) {
echo 'Path is not a directory or not exists: ' . $dir . PHP_EOL;
return;
}
if (!is_link($dir) || isset($options['traverseSymlinks']) && $options['traverseSymlinks']) {
if (!($handle = opendir($dir))) {
echo 'Failed to open: ' . $dir . PHP_EOL;
public static function getValue($array, $key, $default = null)
{
if ($key instanceof \Closure) {
return $key($array, $default);
}
if (is_array($array) && array_key_exists($key, $array)) {
return $array[$key];
}
<?php
/**
* @author Serge Postrash aka SDKiller <jexy.ru@gmail.com>
*/
namespace frontend\widgets;
use Yii;
use yii\helpers\Html;
use yii\widgets\LinkPager;
@SDKiller
SDKiller / DropdownPager.php
Created October 23, 2014 17:42
Fixed current page display
<?php
/**
* @author Serge Postrash aka SDKiller <jexy.ru@gmail.com>
*/
namespace frontend\widgets;
use Yii;
use yii\helpers\Html;
use yii\widgets\LinkPager;
Performance Profiling
Total processing time: 2,225,665 ms; Peak memory: 24.0 MB.
Всего 490 записи.
# Time Duration Category Info
1 07:58:33.995 932.1 ms app\controllers\ListController requestCategories (siteId: 215, categoryId: -1, attempt 1)
2 07:58:34.928 667.0 ms app\controllers\ListController requestCategories (siteId: 215, categoryId: 20081, attempt 1)
3 07:58:35.595 424.0 ms app\controllers\ListController requestCategories (siteId: 215, categoryId: 550, attempt 1)
4 07:58:36.019 461.0 ms app\controllers\ListController requestCategories (siteId: 215, categoryId: 2984, attempt 1)
<?php
/*------------------------------------------------------------------------
# mod_newscalendar - News Calendar
# ------------------------------------------------------------------------
# author Jesús Vargas Garita
# Copyright (C) 2010 www.joomlahill.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.joomlahill.com
# Technical Support: Forum - http://www.joomlahill.com/forum
-------------------------------------------------------------------------*/