Skip to content

Instantly share code, notes, and snippets.

View songpon's full-sized avatar

Songpon Phusing songpon

View GitHub Profile
@songpon
songpon / check_postgres_table_size.sql
Last active December 8, 2017 00:41
check postgresql table size , top 20 tables
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 20;
# java 7 only [https://drive.google.com/file/d/1yNCrwEajgpFnRiIUaB8GW04RCtRDI9Lp/view?usp=sharing]
# ireport [https://drive.google.com/a/itblabla.com/file/d/1XM5_34PxcnpIxuxkOB5Yy3llAOsjE0HE/view?usp=sharing]
./ireport --jdkhome /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
#!/bin/bash
cd /var/log/postgresql; tail -n 500000 postgresql-9.1-main.log > res2 ;grep -A 5 -ir deadlock res2
#!/bin/bash
psql mypgdb -c "SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS SIZE
FROM pg_catalog.pg_database d
where d.datname='mypgdb'
ORDER BY
import hashlib
def check_sum(data):
# if type dict need to cast to string
if type(data)==type({}):
data = str(data)
# lib require to encode to unicode before hash
hash_object = hashlib.md5(data.encode())
return hash_object.hexdigest()
#!/bin/bash
image_name=$(od -A n -t d -N 1 /dev/urandom)
#Replace unused string in caption ( extension dot)
caption=$(echo $1 | sed -r 's/_/ /g;s/\./ /g; s/mp3//gI; s/m4a//gI')
convert -background black -size 800x480 -fill "#ff0080" -pointsize 72 -gravity center caption:"$caption" $image_name.png
ffmpeg -loop 1 -r ntsc -i $image_name.png -i "$1" -c:a copy -c:v libx264 -preset fast -threads 0 -shortest "$1".mkv
#!/bin/bash
# install vim .bash
git clone https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
# install pyenv
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
# set to .bashrc
#!/bin/bash
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
!/bin/bash
for f in *; do mv "$f" "`echo $f | sed s/search_str/replace_str/`"; done
# example
#for f in *; do mv "$f" "`echo $f | sed s/_NongZEZA@CtHts//`"; done
#!/bin/bash
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'