Skip to content

Instantly share code, notes, and snippets.

View Voronenko's full-sized avatar
turning coffee into code since late 90s

Vyacheslav Voronenko

turning coffee into code since late 90s
View GitHub Profile
@Voronenko
Voronenko / Apache load realtime
Created May 4, 2015 13:31
Apache load realtime
while true; do
TERM=xterm-color && clear && apache2ctl status && sleep 2
done
@Voronenko
Voronenko / Remove known host at line X
Created May 11, 2015 22:50
Remove known host at line X ...
sed -ie '191d' /Users/slavko/.ssh/known_hosts
@Voronenko
Voronenko / dump stored procedures
Created May 13, 2015 11:06
Dump all stored procedures from MySQL database
MYSQL_CONN="-uroot -p..................."
DBNAME="test_LCX"
SQLSTMT="SELECT COUNT(1) FROM mysql.proc"
PROCCOUNT=`mysql ${MYSQL_CONN} -ANe"${SQLSTMT}" | awk '{print $1}'`
if [ ${PROCCOUNT} -eq 0 ] ; then exit ; fi
SPLIST=""
for DBSP in `mysql ${MYSQL_CONN} -ANe"SELECT CONCAT(type,'@',db,'.',name) FROM mysql.proc" | grep ${DBNAME}`
do
SPLIST="${SPLIST} ${DBSP}"
done
@Voronenko
Voronenko / parse json
Created May 14, 2015 14:25
Parse JSON using mysql
/*
{"age":"Over 30","gender":"female"}
{"age":"Under 30","gender":"female"}
{"age":"Over 30","gender":"male"}
{"age":"Under 30","gender":"male"}
*/
select common_schema.extract_json_value(f.event_data,'/age') as age,
@Voronenko
Voronenko / mongo backup scripts
Last active December 10, 2021 16:53
This script can be used to perform regular backups of specified mongodb, amend 5 variables at the beginning with your target one
#!/bin/bash
#
REMOTE_USER="[email protected]"
LOCAL_BACKUP_DIR="./backups"
REMOTE_BACKUP_DIR="/home/slavko/mongo_backups"
[ ! -d $LOCAL_BACKUP_DIR ] && mkdir -p $LOCAL_BACKUP_DIR || :
ssh $REMOTE_USER 'bash -s' < regular_mongo_backup.sh
@Voronenko
Voronenko / china_hosts_deny
Created June 26, 2015 07:13
Deny hosts for ssh guessing bots from China
ALL: 121.0.16.0/20, 121.100.128.0/17, 121.16.0.0/12, 121.192.0.0/14, 121.201.0.0/16, 121.204.0.0/14, 121.224.0.0/12, 121.248.0.0/14, 121.32.0.0/13, 121.40.0.0/14, 121.4.0.0/15, 121.46.0.0/15, 121.48.0.0/15, 121.51.0.0/16, 121.55.0.0/18, 121.56.0.0/15, 121.58.0.0/17, 121.59.0.0/16, 121.60.0.0/14, 121.68.0.0/14, 121.76.0.0/15, 121.8.0.0/13, 121.89.0.0/16, 122.0.128.0/17, 122.0.64.0/18, 122.198.0.0/16, 122.200.64.0/18, 122.4.0.0/14, 122.48.0.0/16, 122.49.0.0/18, 122.51.0.0/16, 122.8.0.0/13, 123.199.128.0/17, 123.49.128.0/17, 123.99.128.0/17, 124.108.40.0/21, 124.108.8.0/21, 124.112.0.0/13, 124.128.0.0/13, 124.147.128.0/17, 124.156.0.0/16, 124.160.0.0/13, 124.16.0.0/15, 124.172.0.0/15, 124.192.0.0/15, 124.196.0.0/16, 124.200.0.0/13, 124.20.0.0/15, 124.220.0.0/14, 124.224.0.0/12, 124.240.0.0/17, 124.242.0.0/16, 124.243.192.0/18, 124.248.0.0/17, 124.249.0.0/16, 124.250.0.0/15
ALL: 124.254.0.0/18, 124.29.0.0/17, 124.40.128.0/18, 124.42.0.0/17, 124.47.0.0/18, 124.64.0.0/15, 124.66.0.0/17, 124.6.64.0/18, 124.67.0.0/16
@Voronenko
Voronenko / pr.md
Last active August 29, 2015 14:24 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@Voronenko
Voronenko / cleanup_s3_bucket.sh
Created July 28, 2015 14:09
Removes backups older than N days from S3 bucket using s3cmd tool
#!/bin/bash
# Usage: ./cleanup_s3_bucket "bucketname" "90 days"
s3cmd ls s3://$1 | while read -r line;
do
createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -d"$createDate" +%s`
olderThan=`date -d"-$2" +%s`
if [[ $createDate -lt $olderThan ]]
@Voronenko
Voronenko / reload_css_bookmarklet
Created August 11, 2015 19:28
reload css bookmarklet
<a href="javascript:(function(){var h,a,f;a=document.getElementsByTagName('link');for(h=0;h<a.length;h++){f=a[h];if(f.rel.toLowerCase().match(/stylesheet/)&&f.href){var g=f.href.replace(/(&|%5C?)forceReload=\d+/,'');f.href=g+(g.match(/\?/)?'&':'?')+'forceReload='+(new Date().valueOf())}}})()">Reload css</a>
@Voronenko
Voronenko / aws_elb_get_instance_public_ips
Created August 26, 2015 19:53
Get public IPs of the instances currently linked to aws load balancer named LB1
aws elb describe-instance-health --load-balancer-name bla --region us-east-1 | awk '{ print $2 }' | grep "i-" | cut -d '=' -f 2 | sed -e 's/,$//' | xargs aws ec2 describe-instances --instance-id | grep PublicIpAddress | awk '{print $2}' | cut -d '=' -f 2 | sed -e 's/,$//'