Skip to content

Instantly share code, notes, and snippets.

View sokil's full-sized avatar
🇺🇦
sapere aude

sokil

🇺🇦
sapere aude
View GitHub Profile
@sokil
sokil / Menu.php
Last active July 15, 2016 21:28
Symfony Menu
<?php
namespace Vendor\Package\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Yaml\Yaml;
class Builder
@sokil
sokil / bash_join.sh
Last active September 1, 2016 11:38
#!/bin/bash
# delimited by tab
join -t $'\t' <(cat file1 | sort) <(cat file2 | sort)
# join fields
join -t $'\t' -a1 -e 'NULL' -o auto <(cat file1.csv | sort) <(cat file2.csv | sort | uniq -w 32)
@sokil
sokil / triggers.sql
Created June 27, 2016 21:32
pt-online-schema-change
CREATE TRIGGER `pt_osc_test_users_del` AFTER DELETE ON `test`.`users` FOR EACH ROW DELETE IGNORE FROM `test`.`_users_new` WHERE `test`.`_users_new`.`id` <=> OLD.`id`
CREATE TRIGGER `pt_osc_test_users_upd` AFTER UPDATE ON `test`.`users` FOR EACH ROW REPLACE INTO `test`.`_users_new` (`id`, `name`, `password`) VALUES (NEW.`id`, NEW.`name`, NEW.`password`)
CREATE TRIGGER `pt_osc_test_users_ins` AFTER INSERT ON `test`.`users` FOR EACH ROW REPLACE INTO `test`.`_users_new` (`id`, `name`, `password`) VALUES (NEW.`id`, NEW.`name`, NEW.`password`)
@sokil
sokil / JsonRequestListener.php
Last active October 2, 2016 17:59
Convert JSON request in Symfony app
<?php
namespace Sokil\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class JsonRequestListener implements EventSubscriberInterface
{
@sokil
sokil / copy_file.sh
Last active January 17, 2017 11:51
rename or copy files from one dir to another
find . -name "someFile.po" \
| grep someSourceDir \
| xargs -I{} sh -c 'old={}; new=$(echo $old | sed "s/someFile.po/someNewFile.po/g"); cp $old $new'
@sokil
sokil / AmountFormattrer.php
Last active September 24, 2016 18:24
Amount formatter
<?php
class Amount
{
public function getFormattedAmount($locale, $currency)
{
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
return $formatter->formatCurrency($this->amount, $currency);
}
}
@sokil
sokil / hackme.cpp
Last active September 28, 2016 18:58
// For Windows 32
// i686-w64-mingw32-g++-win32 -static-libstdc++ -static-libgcc -o hackme_win32.exe hackme.cpp
// wine hackme_win32.exe
// For Windows 64
// x86_64-w64-mingw32-g++ -static-libstdc++ -static-libgcc -o hackme_win64.exe hackme.cpp
// wine hackme_win64.exe
#include <iostream>
int main() {
#!/bin/bash
test="a78b"; regex="([0-9]+)"; if [[ $test =~ $regex ]]; then echo ${BASH_REMATCH[1]}; else echo "not equals"; fi
#!/bin/bash
cat domains.csv | xargs -I{} bash -c 's=$(GET -ds "https://{}"); if [[ $s != "200 OK" ]]; then echo {}; fi'
#!/bin/sh
# convert line
echo "fff" | php -r '$id = stream_get_contents(STDIN); $id[0] = dechex(15 - hexdec($id[0])); echo $id . PHP_EOL;'
# convert file
head log.csv | xargs -L 1 | xargs -I{} php -r '$id = "{}"; $id[0] = dechex(15 - hexdec($id[0])); echo $id . PHP_EOL;'