Skip to content

Instantly share code, notes, and snippets.

@feldwebel
feldwebel / gist:9d05e90456505ed6b4d6681906856dcb
Last active October 5, 2022 20:18
Symfony serializer instantiation
Such symfony serializer instantiation allows automatic camel to snake case field conversion
and direct deserialization to private fields.
composer require
symfony/serializer
symfony/property-access
phpdocumentor/reflection-docblock
public function __construct()
{
docker pull mysql
docker run --name testMysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
docker exec -it testMysql mysql -uroot -p
// docker exec -it testMysql bash
// mysql -u root -p
CREATE DATABASE db_test;
@feldwebel
feldwebel / xdebug.ini
Created April 21, 2021 20:35
xdebug v3 config example
xdebug.mode=debug
xdebug.start_with_request=true
xdebug.discover_client_host=true
xdebug.remote_idekey = PHPSTORM
@feldwebel
feldwebel / xdebug.ini
Created June 22, 2020 14:05
xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_enable=on
xdebug.remote_autostart=on
xdebug.remote_host=172.26.0.1
xdebug.idekey=PHPSTORMPP
xdebug.extended_info=on
RESTAURANT EXERCISE (please use JAVA 7 syntax)
Your restaurant has a set of tables of different sizes: each table can accommodate 2, 3, 4, 5 or 6 persons. Clients arrive alone or in groups, up to 6 persons. Clients within a given group must be seated together at one table, hence you can direct a group only to a table, which can accommodate them all. If there is no table with the required number of empty chairs, the group has to wait in the queue.
Once seated, the group cannot change the table, i.e. you cannot move a group from one table to another to make room for new clients.
Client groups must be served in the order of arrival with one exception: if there is enough room at a table for a smaller group arriving later, you can seat them before the larger group(s) in the queue. For example, if there is a six-person group waiting for a six-seat table and there is a two-person group queuing or arriving you can send them directly to a table with two empty chairs.
Groups may share tables, however if at the same
@feldwebel
feldwebel / SimpleTest.java
Last active November 17, 2019 14:53
Java parametrized junit test for stdin/stdout
/*
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
*/
import junitparams.JUnitParamsRunner;
@feldwebel
feldwebel / cli
Last active March 31, 2018 18:24
cli snippets
ищем строку где-то в файлах
grep -rni ~/ -e 'string to find'
если ktorrent не видит раздач на рутрекере
iptables -t nat -A OUTPUT -p tcp -m tcp --dport 80 -d 195.82.146.120/30 -j DNAT --to-destination 163.172.167.207:3128
@feldwebel
feldwebel / snippets.sql
Last active October 31, 2018 17:05
sql snippets
SELECT * FROM generate_series('2014-01-01'::timestamp, now(), '1 day');
select id, a.key as account, (a.value::json->0)::text::date as "from", (a.value::json->1)::text::date till from tbl_customer
cross join lateral jsonb_each_text(settings->'frozen_repayment_accounts') a
where settings->'frozen_repayment_accounts' is not null
and (now() between (a.value::json->0)::text::date and (a.value::json->1)::text::date)
@feldwebel
feldwebel / percentage.sql
Last active October 16, 2017 12:19
Percentage
select c.tin, sum(case when lt.type = any(array['interest', 'loan']) then lt.amount else -lt.amount end) portfolio,
round(
100.0
* sum(case when lt.type = any(array['interest', 'loan']) then lt.amount else -lt.amount end)
/ (select sum(case when type = any(array['interest', 'loan']) then amount else -amount end) from tbl_loan_transaction)
, 2) "%"
from tbl_loan_transaction lt
join tbl_customer c on c.id = lt.customer_id
group by c.tin
having sum(case when lt.type = any(array['interest', 'loan']) then lt.amount else -lt.amount end) > 0
@feldwebel
feldwebel / test.sql
Created October 8, 2017 12:36
another try
create or replace function my_sign(text, numeric) returns numeric as $$
select case when $1 = any(array['interest', 'loan']) then $2 else -$2 end;
-- select case when position('_repayment' in $1) = 0 then $2 else -$2 end;
$$ language sql;
select * from (
select distinct on (lt.customer_id) c.tin,
sum(my_sign(lt.type, lt.amount)) over wnd portfolio,
round(
100.0