Skip to content

Instantly share code, notes, and snippets.

View Ellrion's full-sized avatar

Maksim (Ellrion) Platonov Ellrion

View GitHub Profile
@Ellrion
Ellrion / postgres_queries_and_commands.sql
Created May 25, 2018 14:12 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@Ellrion
Ellrion / .bash_aliases
Created May 7, 2018 12:23 — forked from vratiu/.bash_aliases
Git shell coloring
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset
<?php
Illuminate\Database\Eloquent\Collection::macro('loadIt', function ($relation) {
return $this->load($relation)->reduce(function($relations, $model) use ($relation) {
return $relations->merge($model->{$relation});
}, new Illuminate\Database\Eloquent\Collection());
});
@Ellrion
Ellrion / helpers.php
Created March 13, 2018 09:25
array to xml string and xml string to array helpers
<?php
if (!function_exists('array2xml')) {
/**
* Конвертирует массив в xml
*
* @param $array
* @param null|string|SimpleXMLElement $root
* @param string $version
* @param string $encoding
@Ellrion
Ellrion / FlashMessageSender.php
Last active March 5, 2018 15:04
Flash messages min service for Laravel (only backend)
<?php
namespace App\Services\Foundation;
use Illuminate\Session\Store;
use Illuminate\Support\Collection;
/**
* Register it in AppServiceProvider (or other): $this->app->singleton('flash', FlashMessageSender::class);
*/
<?php
namespace App\Support\Http;
use Exception;
class ConfirmationException extends Exception
{
/**
* The recommended response to send to the client.
@Ellrion
Ellrion / LaravelUserProcessor.php
Last active February 5, 2019 16:53
Add info about auth user for log in Laravel
<?php
namespace App\Services\Foundation\Log;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
/**
@Ellrion
Ellrion / HigherOrderOptionalProxy.php
Created August 26, 2017 08:02 — forked from derekmd/Optional.php
Laravel global helper function `optional()`
<?php
namespace App\Support;
class HigherOrderOptionalProxy
{
/**
* The target being transformed.
* Use _ prefix to avoid namespace conflict on __get()
*
@Ellrion
Ellrion / helper.php
Created August 22, 2017 15:28
Сортировка ассоциативного массива в порядке указанном массивом ключей.
<?php
if (!function_exists('array_sort_by_keys_array')) {
/**
* Сортировка ассоциативного массива в порядке указанном массивом ключей.
*
* @param array $array Входной массив.
* @param array $sorter Массив ключей в нужном порядке.
*
* @return bool
<?php
namespace App\Services\Foundation;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Support\Jsonable;
use InvalidArgumentException;
use JsonSerializable;
class JsonFactory