Posts

Javascript String.prototype.trim(/* optional list of chars to trim*/) and String.prototype.reverse(); /*reverse a string*/

String.prototype.reverse = function(){ return this.split("").reverse().join(""); } String.prototype.trim = function (list) { var list = ' '+list; word=this; while(list.indexOf(word.substr(0,1)) > -1) word = word.substring(1); word = word.reverse(); while(list.indexOf(word.substr(0,1)) > -1) word = word.substring(1); word = word.reverse(); return word; }

Terminal ansi2html ( htop to html )

echo | htop | aha --black --line-fix > htop.htm "aha" is a program, that takes an input from terminal (by pipe) and puts a colorized HTML-File in stdout

MySQL export ( mysqldump ) -> ssh -> import ( mysql )

#mysqldump -uLocalUser -pLocalPassword database_name | ssh sshuser@sshhost "mysql -D remote_database_name -uRemoteUser -pRemotePassword" ( you will be asked to enter your ssh password )

Check Apache server Uptime or Mysql server uptime

MySQL -> # ps -eo "%U %c %t"| grep mysqld | grep -v grep|grep root Apache2 -> # ps -eo "%U %c %t"| grep apache2 | grep -v grep|grep root

Linux : Bash : CPU load in %

:;sleep=1;CPU=(`cat /proc/stat | head -n 1`);PREV_TOTAL=0;for VALUE in "${CPU[@]}"; do let "PREV_TOTAL=$PREV_TOTAL+$VALUE";done;PREV_IDLE=${CPU[4]};sleep $sleep; CPU=(`cat /proc/stat | head -n 1`);unset CPU[0];IDLE=${CPU[4]};TOTAL=0; for VALUE in "${CPU[@]}"; do let "TOTAL=$TOTAL+$VALUE"; done;echo $(echo "scale=2; ((($sleep*1000)*(($TOTAL-$PREV_TOTAL)-($IDLE-$PREV_IDLE))/($TOTAL-$PREV_TOTAL))/10)" | bc -l );

(MySQL) select the longest reccord in a table column

SELECT field_name FROM some_table WHERE length(field_name) = ( select max(length(field_name)) FROM some_table )

LINUX : BASH : Get multicore cpu average load in percents (%) for last minute

i=`cat /proc/cpuinfo | grep 'model name' | wc -l` ; j=`uptime | awk '{print $10 }' | tr ',' '\b'` ; Number=`echo - | awk -v K=$i -v K2=$j '{ print K*K2}'` ; echo "CPU :$Number % $i $j";