Skip to content

Instantly share code, notes, and snippets.

@aboritskiy
aboritskiy / clean-up-merged-remote-branches.sh
Created February 20, 2023 14:12
Remove merged remote branches
#!/bin/bash
set -eu
git fetch -ap
git branch -r --merged origin/master | grep -v master | grep -v dev | grep -v HEAD | sed 's/^ origin\///' | xargs git push --delete origin
@aboritskiy
aboritskiy / kill-all.sh
Created December 11, 2020 12:23
Delete everything in elasticsearch host
curl -X DELETE 'http://localhost:9200/_all'
@aboritskiy
aboritskiy / remove-gpg-user.sh
Last active July 13, 2020 12:49 — forked from glogiotatidis/remove-gpg-user.sh
Git-crypt remove user.
#!/bin/bash
#
# Script to remove GPG key from git-crypt
#
# It will re-initialize git-crypt for the repository and re-add all keys except
# the one requested for removal.
#
# Note: You still need to change all your secrets to fully protect yourself.
# Removing a user will prevent them from reading future changes but they will
# still have a copy of the data up to the point of their removal.
@aboritskiy
aboritskiy / archive-slack-channels.sh
Created April 1, 2020 08:50
archives dead slack channels
TOKEN=""
curl "https://slack.com/api/channels.list?token=$TOKEN&exclude_archived=true&pretty=1" > /tmp/channels.list
IDS=$(cat /tmp/channels.list | jq '.channels[] | select(.num_members == 0) | .id' | sed -e 's/"//g')
for ID in $IDS; do
CHANNEL_DATA=$(cat /tmp/channels.list | jq ".channels[] | select(.id == \"$ID\") | \"\(.id) \(.name) \(.num_members)\"")
echo "$CHANNEL_DATA"
read -p " proceed? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo " archiving..."
@aboritskiy
aboritskiy / aws-snapshots-cleanup.sh
Created March 27, 2020 21:36
Interactively removes AWS snapshots that were created by CreateImage but AMI was removed.
#!/bin/bash
set -eu
AWS_ACCOUNT_ID=657433956652
echo "Snapshots exist for following images: "
aws ec2 describe-snapshots --filters Name=description,Values="Created by CreateImage*" --owner-id=$AWS_ACCOUNT_ID --output=text | grep "^SNAPSHOTS" | sed 's/.*\(ami-[0-9a-z]\+\).*/\1/' | sort | uniq | sort > /tmp/snapshot-cleanup-existing-snapshots
@aboritskiy
aboritskiy / remove-submodules.sh
Created March 27, 2020 19:36
Interactively removes all project submodules, saving each remove in a separate commit and stopping before each.
#!/bin/bash
SUBMODULES_LIST=$(git submodule status | awk '{print $2}');
echo "Status before:"
echo
git submodule status
echo
for SUBMODULE_PATH in $SUBMODULES_LIST
@aboritskiy
aboritskiy / get-db-size
Created October 17, 2018 10:43
Database Tips and Tricks
SELECT table_schema as `Database`, table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "PUT-YOUR-DB-NAME-HERE"
ORDER BY (data_length + index_length) DESC;
@aboritskiy
aboritskiy / provision.sh
Created October 15, 2018 07:03
AWS Autoscaling little demo
#!/bin/bash
yum update -y
yum install -y httpd
echo "<VirtualHost *:80>
ServerName default
ServerAdmin anton.boritskiy@gmail.com
DocumentRoot /var/www/html/
<Directory '/var/www/html/'>
Options FollowSymLinks Includes ExecCGI
AllowOverride All
@aboritskiy
aboritskiy / .htaccess
Created October 12, 2018 20:50
Apache2.4 block Magento1 guts
RewriteRule ^/\. - [L,R=403]
RewriteRule ^/app/ - [L,R=403]
RewriteRule ^/dev/ - [L,R=403]
RewriteRule ^/downloader/ - [L,R=403]
RewriteRule ^/includes/ - [L,R=403]
RewriteRule ^/lib/ - [L,R=403]
RewriteRule ^/shell/ - [L,R=403]
RewriteRule ^/pkginfo/ - [L,R=403]
RewriteRule ^/var/ - [L,R=403]
RewriteRule ^/rss/ - [L,R=403]
@aboritskiy
aboritskiy / README.me
Created June 12, 2018 21:50
MySQL Upgrade Amazon Linux
mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0"
mysqladmin -u root -p shutdown
sudo yum remove mysql55\*
sudo yum install mysql56-server
sudo service mysqld start
sudo mysql_upgrade -u root -p