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 / 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 / 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 / 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 / nginx.conf
Last active November 8, 2016 06:31
server
{
listen 80; # default_server
server_name {SERVER_NAME};
# SSL.
# Uncomment to enable
# listen 443 ssl;
# ssl_certificate /path/to/ssl.crt;
# ssl_certificate_key /path/to/ssl.key;
@sokil
sokil / compile_js.sh
Created January 15, 2016 10:15
compile_js.sh
#!/bin/bash
# config
jsFilesDir=./../public/js/
compiledJsFilename=compiled.js
# init js files array
js=(
a.js
b.js
@sokil
sokil / xphp.sh
Last active October 7, 2016 11:53
export PHP_XDEBUG_ENABLED=1
export PHP_IDE_CONFIG="serverName=%PhpStormServerName%"
export XDEBUG_CONFIG="idekey=PHPSTORM remote_host=%RemoteIp% remote_port=%RemotePort% remote_enable=1 remote_autostart=1"
php $@

Get list from mysql

mysql --defaults-extra-file=~/credentials.cnf -Nsqe "SELECT SQL_NO_CACHE * FROM ..." | pv -l | gzip > rows.gz

Get list from mysql, based on other list in file

zcat rows.gz | awk '{print $1}' | xargs -L 1000 | sed 's/ /\\",\\"/g' | xargs -I {} mysql --defaults-extra-file=~/credentials.cnf -Nsqe "SELECT SQL_NO_CACHE otherId FROM table WHERE id IN (\"{}\")" | pv -l | sort | uniq -c | sort -rn > otherIds
@sokil
sokil / CreateForm.php
Last active January 16, 2017 09:53
Create symfony form without prefix
<?php
$formFactory = $this->container->get('form.factory');
$form = $formFactory->createNamed(
null,
new RegistrationFormType('\Vendor\AcmeBundle\Entity\SomeEntity'),
$user,
[
'method' => $request->getMethod(),
]
@sokil
sokil / test.html
Created July 20, 2015 08:41
IE6-IE9 Limitation of css
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="a01.css" />
<link rel="stylesheet" type="text/css" href="a02.css" />
<link rel="stylesheet" type="text/css" href="a03.css" />
<link rel="stylesheet" type="text/css" href="a04.css" />
<link rel="stylesheet" type="text/css" href="a05.css" />
<link rel="stylesheet" type="text/css" href="a06.css" />
<link rel="stylesheet" type="text/css" href="a07.css" />
@sokil
sokil / MongoInsertBatch.php
Last active August 29, 2015 14:24
MongoInsertBatch
<?php
/**
* @link https://github.com/mongodb/mongo-php-driver/blob/v1.6/bson.c#L89
*/
// connection
$client = new MongoClient("mongodb://localhost");
$collection = $client->test->test;