Skip to content

Instantly share code, notes, and snippets.

View wtorsi's full-sized avatar

Andrew wtorsi

View GitHub Profile
@wtorsi
wtorsi / # php - 2018-03-14_14-10-31.txt
Created March 20, 2018 18:40
php on macOS 10.13.3 - Homebrew build logs
Homebrew build logs for php on macOS 10.13.3
Build date: 2018-03-14 14:10:31
@wtorsi
wtorsi / calendar.html.twig
Last active February 11, 2020 07:23
[Twig] display calendar by months using 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 / group_limit.sql
Created February 13, 2020 18:18
Limit in group
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
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;
<?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;
}
@wtorsi
wtorsi / UniqueField.php
Last active June 23, 2020 20:20
Unique Field Validator for Dto. Unique Dto Constraint Validator for Symfony.
<?php
declare(strict_types=1);
namespace Form\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
@wtorsi
wtorsi / graphic_card_switch_control.sh
Created March 15, 2021 11:58 — forked from ccqpein/graphic_card_switch_control.sh
macOS 10.14 use pmset to control graphic card switch.
# I find this https://discussions.apple.com/thread/8160651
# but it not match my 2018 version MacBook with macos 10.14
#
# On my local, gpuswitch value is
# 0 -> does not use dedicated graphics
# 1 -> use dedicated graphics
# 2 -> switch automaticly (I guess), because 2 is default value when "automatic graphics switching" selected
# in energy in preference.
# check settings depended on charger/battery