Skip to content

Instantly share code, notes, and snippets.

View kholschevnikov's full-sized avatar

Roman Kholschevnikov kholschevnikov

  • CityAds Media
  • Russia, Moscow
View GitHub Profile
@kholschevnikov
kholschevnikov / delete_all_merged_remote_branches.sh
Last active September 25, 2019 10:20
Delete all remote branches that have already been merged into origin/master.
git branch -r --merged origin/master | grep -vE 'master' | xargs git push origin --delete
@kholschevnikov
kholschevnikov / delete_all_local_merged_branches
Last active May 31, 2020 07:54
Delete all local merged branches
git branch --merged master | grep -vE 'master' | xargs git branch -d
@kholschevnikov
kholschevnikov / russian_plural.php
Last active September 11, 2015 07:04 — forked from fomigo/gist:2382775
Russian Plural Form in PHP
<?php
/*
echo plural_form(42, array('арбуз', 'арбуза', 'арбузов'));
*/
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
@kholschevnikov
kholschevnikov / get_tables_size.sql
Last active September 11, 2015 06:47
Размеры таблиц в Mysql
SELECT
concat(table_schema,'.',table_name) tableName,
concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024),2),'M') DATA,
concat(round(index_length/(1024*1024),2),'M') idx,
concat(round((data_length+index_length)/(1024*1024),2),'M') totalSize,
round(index_length/data_length,2) idxFrac
FROM information_schema.TABLES
ORDER BY data_length+index_length DESC
LIMIT 10
@kholschevnikov
kholschevnikov / recover_lost_stash.sh
Last active September 11, 2015 06:55
Recovering a lost stash
Like a commit, a dropped or cleared stash is stored in a Git database until you run git gc. The lost stash is treated like a commit and you can use git fsck to find it.
Let's create and drop a stash with a message.
% echo "I'm going to stash this" >> INSTALL
% git add INSTALL
% git stash save Changes INSTALL
% git stash list
stash@{0}: On master: Changed INSTALL
% git stash clear
@kholschevnikov
kholschevnikov / edit_comment_for_pushed_commit.sh
Last active September 11, 2015 06:54
Edit commit for pushed commit (and push to remote if needed)
git rebase --interactive c4d25d6^
# не меняем ничего кроме первого слова pick -> reword
reword c4d25d6 order status
pick 39ba64e redirect to order status after booking
# в следующем окне можно будет изменить комментарий
# если коммит был запушен
git push --force
#!/bin/sh
date=$1
DRY_RUN=1
if [ -z $1 ]; then
echo "Empty date"
exit;
fi
@kholschevnikov
kholschevnikov / drop_all_tables_except_one.sql
Last active September 11, 2015 06:40
MySQL: Drop all table except one
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables FROM information_schema.tables
WHERE TABLE_SCHEMA = 'table_schema' AND TABLE_NAME <> 'table_name';
SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt1 FROM @tables;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
@kholschevnikov
kholschevnikov / xdebug.ini
Last active April 13, 2018 07:58
xDebug for PHPStorm
[XDebug]
xdebug.remote_enable=true
xdebug.remote_connect_back=true
xdebug.remote_autostart=true
xdebug.profiler_enable=false
xdebug.max_nesting_level=700
xdebug.idekey=PHPSTORM
xdebug.remote_host=docker.for.mac.localhost
xdebug.remote_port=9002
@kholschevnikov
kholschevnikov / phpx
Last active September 11, 2015 06:37
Alias php bin for use xdebug in cli
XDEBUG_CONFIG="idekey=PHPSTORM" PHP_IDE_CONFIG="serverName={имя сервера}" php -d "xdebug.remote_host={IP рабочей машины}" -d "xdebug.remote_connect_back=0" -d "xdebug.remote_port=9000" -d "xdebug.remote_enable=1" $@