Skip to content

Instantly share code, notes, and snippets.

View demofly's full-sized avatar

Stanislav O. demofly

View GitHub Profile
@demofly
demofly / squid-tail.sh
Created July 22, 2014 14:33
Convert Squid log timestamps on the fly
tail /var/log/squid/access.log -f -n999 | perl -p -e 's/^([0-9\.]*)/"[".localtime($1)."]"/e'
@demofly
demofly / 152.sh
Created July 14, 2014 03:19
152-ФЗ формат таблицы с описью OpenVZ виртуалок
seqid=0
for i in `vzlist -o ctid -H`
do
((sequid++))
vzctl exec $i "echo \"$sequid \`hostname -f\` \`lsb_release -a 2>/dev/null | grep Description | sed -r 's#.*:[ \t]+##g'\` \`cat /proc/cpuinfo | grep 'physical id' | uniq | wc -l\` CPU; \`free -h | grep Mem | awk '{print \$2}'\` RAM; \`df -hT | grep '/\$' | awk '{print \$3}'\` HDD \`ip -o -4 a s | grep brd | sed -r 's#.* ([0-9\.]{7,})/.*#\1#' | tr -s '\n' ' '\` \`netstat -tlpn | grep '^tcp\|^udp' | cut -d/ -f2 | sort -u | tr -s '\n' ' ' | sed 's#zabbix_agentd ##; s#exim4 ##; s#postgres#PostgreSQL#; s#config.ru ##; s#master#Postfix#; s#apache#Apache#; s#mysqld#MySQL#'\`\""
done
@demofly
demofly / Manual
Last active May 31, 2016 10:36
How to migrate an existing MySQL 5.5 DB from latin1 to UTF-8.
Convert old latin1 DB to a new UTF8 one:
DBS="db1 db2"
for dbname in $DBS
do
mysqldump "${dbname}" > "${dbname}"latin1.sql
cat "${dbname}"latin1.sql | sed "s#CHARSET=latin1#CHARSET=utf8#" | iconv -f iso8859-1 -t utf8 > "${dbname}"utf8.sql
done
====
Change in /etc/mysql/my.cnf:
@demofly
demofly / etc-logrotate.d-nginx
Created July 3, 2014 12:27
Debian Nginx logrotate
/var/log/nginx/*.log {
daily
dateext
dateformat .%Y-%m-%d
missingok
rotate 365
compress
delaycompress
notifempty
create 0640 www-data adm
@demofly
demofly / gist:00a83892cba486daf1cc
Created July 1, 2014 11:36
Место занимаемое базами Postgres
e=$(psql -lAt | head -n1 | cut -d\| -f1); psql -c "SELECT pg_database.datname, pg_database_size(pg_database.datname), pg_size_pretty(pg_database_size(pg_database.datname)) FROM pg_database ORDER BY pg_database_size DESC;" -d ${e}
@demofly
demofly / rvm-setup.sh
Last active August 29, 2015 14:03
rvm setup
apt-get install curl
curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
rvm --default 2.1.2
rvm list
rvm install 2.1.2
rvm list
gem install bundler
@demofly
demofly / go1.3-install-deb.sh
Last active August 29, 2015 14:03
How to install Go 1.3 in debian wheezy
apt-get install devscripts build-essential
apt-get build-dep golang-go
wget http://ftp.de.debian.org/debian/pool/main/g/golang/golang_1.3-1.dsc
wget http://ftp.de.debian.org/debian/pool/main/g/golang/golang_1.3.orig.tar.gz
wget http://ftp.de.debian.org/debian/pool/main/g/golang/golang_1.3-1.debian.tar.xz
dpkg-source -x golang_1.3-1.dsc
cd golang-1.3/
debuild -us -uc
@demofly
demofly / node-package-build-and-install.sh
Last active August 29, 2015 14:00
Deployment Debian script for latest nodejs and npm
#!/bin/bash
apt-get -y install build-essential checkinstall fakeroot curl
src=$(mktemp -d) && cd $src
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
./configure
fakeroot checkinstall -y --install=no --pkgversion $(echo $(pwd) | sed -n -re's/.+node-v(.+)$/\1/p') make -j$(($(nproc)+1)) install
dpkg -i node_*
wget https://www.npmjs.org/install.sh -O- | bash
@demofly
demofly / clean-whiteboard.sh
Created April 4, 2014 08:31
Позволяет убрать темноватый фон из фоток с надписями на белой маркерной доске
#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2
#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"
#!/bin/bash
convert in.jpg \( +clone -blur 0x20 \) -compose Divide_Src -composite -normalize -level 10%,90% -deskew 40% -unsharp 0x5+2+0 out.jpg
@demofly
demofly / convert-from-any-file-to-stdout-in-utf8
Last active August 29, 2015 13:58
A script allows to convert any file to utf-8 and send it content to stdout
#!/bin/bash
FFN="$1"
filename=`basename "$FFN"`
encoding=$(uchardet "$FFN")
enc=`echo $encoding | sed 's#^x-mac-#mac#'`
cat "$FFN" | perl -pe 's/\r\n/\n/g' | perl -pe 's/\n\r/\n/g' | perl -pe 's/\r/\n/g' > "$FFN.out"
iconv -f $enc -t UTF-8 "$FFN.out"