Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrey wtorsi

View GitHub Profile
@wtorsi
wtorsi / UniqueField.php
Last active Jun 23, 2020
Unique Field Validator for Dto. Unique Dto Constraint Validator for Symfony.
View UniqueField.php
<?php
declare(strict_types=1);
namespace Form\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
View gist:2d4735aff677bd0c3c9ff425935391db
<?php
function map(string $a): array
{
$len = \strlen($a);
$map = new SplFixedArray(127);
for ($i = 0; $i < $len; ++$i) {
$code = \ord($a[$i]);
$map[$code] = ($map[$code] ?? 0) + 1;
}
View unbanned.sql
select YEAR(u.birthdate) as year,
SUM(IF(u.gender = 'M', 1, 0)) as male,
SUM(IF(u.gender = 'F', 1, 0)) as female
from users u
left join users_banned ub on u.id = ub.user_id
where ub.user_id is null
group by year
order by year;
View group_limit.sql
select n.category_id, n.id, n.price
from products n
left join products j
on j.category_id = n.category_id and j.price >= n.price and n.id != j.price
group by n.id, n.category_id, n.price
having count(*) < 3
order by category_id, price desc
@wtorsi
wtorsi / calendar.html.twig
Last active Feb 11, 2020
[Twig] display calendar by months using Twig
View calendar.html.twig
<div class="row">
{%- for month in months -%}
<div class="col-6">
<table class="table table-condensed table-calendar bg-white">
<thead>
<tr>
<th colspan="7">
{{- month|format_date('medium', 'MMM') -}}
</th>
</tr>
@wtorsi
wtorsi / # php - 2018-03-14_14-10-31.txt
Created Mar 20, 2018
php on macOS 10.13.3 - Homebrew build logs
View # php - 2018-03-14_14-10-31.txt
Homebrew build logs for php on macOS 10.13.3
Build date: 2018-03-14 14:10:31
You can’t perform that action at this time.