2009-04-05
Here is some simple bash script to bulk change encoding of all files in directory. It uses iconv for change of encoding.
#!/bin/bash
if [ $# -ne 3 ]; then
echo “usage: “$0″ dest_directory original_encoding destination_encoding”
exit
fi;
dir=$1
from=$2
to=$3
if [ ! -d $dir ]; then
mkdir $dir
fi
for f in $( ls . ); do
if [ -f $f ]; then
iconv -f $from -t $to $f > $dir$f
fi
done
To run it, create a file recode.sh and paste above code into it. Then in terminal run
chmod +x recode.sh
adn then just
./recode.sh encoded_dir/ ISO-8859-13 UTF-8
Command mentioned above recodes all files in current directory from ISO-8859-13 encoding to UTF-8 and copies new files to encoded_dir/ directory.
5 Comments |
Linux, MacOS |
Permalink
Posted by jarik
2009-03-05
To get some really good advices on your MySQL DB on server run these commands:
wget http://mysqltuner.com/mysqltuner.pl
chmod +x mysqltuner.pl
./mysqltuner.pl
Of course this would work only on unix server (not Windows;)) and you should have wget installed
Leave a Comment » |
Linux, MySQL |
Permalink
Posted by jarik
2009-02-22
If you use Plesk control panel to create CRON jobs and don’t want results to be sent to you by email, in Command field add ” > /dev/null”. For example:
php cron/my_script.php > /dev/null/
This will not send you result, bt will send email if there were some errors. If you don’t wan’t to get any errors just add ” > /dev/null 2>&1″. For example
php cron/my_script.php > /dev/null 2>&1
Leave a Comment » |
Linux |
Permalink
Posted by jarik
2009-02-21
If you got a hosting with CentOS 5, but without yum, just execute commands provided below and you’ll have a superb tool for installing new software with all dependecies.
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/elfutils-libs-0.125-3.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/gmp-4.1.4-10.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/readline-5.1-1.1.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/python-2.4.3-21.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/libxml2-2.6.26-2.1.2.1.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/libxml2-python-2.6.26-2.1.2.1.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/expat-1.95.8-8.2.1.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/python-elementtree-1.2.6-5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/sqlite-3.3.6-2.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/python-sqlite-1.1.7-1.2.1.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/elfutils-0.125-3.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/rpm-python-4.4.2-48.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/m2crypto-0.16-6.el5.2.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/python-urlgrabber-3.1.0-2.noarch.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/yum-metadata-parser-1.1.2-2.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos-5/5/os/i386/CentOS/yum-3.2.8-9.el5.centos.1.noarch.rpm
Leave a Comment » |
Linux |
Permalink
Posted by jarik
2009-01-10
If, in Finder, you’ll try to open shared folder (in my case, it is shared on windows machine) it just won’t open. To enter your credentials, open Finder, in menu select Go -> Connect to server. And in “Server Address” field enter “sbm://”(without quotes) and IP address or name of computer with shares. For example
smb://192.168.0.1
Then, press Browse or Connect and computer will ask you for a username and password. Just enter your credentials and Voila! You have just connected to password protected shared folder ;)
Leave a Comment » |
MacOS | Tagged: credentials, finder, MacOS, password, samba, shared folder |
Permalink
Posted by jarik
2008-10-13
I’ve searched for such functin in standard excel Date and Time functions but haven’t found anything. 1 minute of googling and very clear and short answer was foun in Understanding Nothing blog:
If a date is written in a cell A8 then the formula is
=DATE(YEAR(A8), MONTH(A8)+1, 0)
Shortly, this means that we are getting the date of 0th day of the next month or saying in peoples’ language, the last day of given month.
Leave a Comment » |
MS Excel | Tagged: date, formula, Microsoft Excel |
Permalink
Posted by jarik
2008-08-18
Inserting filter select fields in excel is very simple but I always forget it… :)
Let`s take some simple data for example:

Microfot Excel 2007
Now select header row:

Microfot Excel 2007
In “Home” pane press “Sort & Filter” and select Filter:

Microsoft Excel Filter tips
That’s all! Now you can filter rows by contents:

Microsoft Excel Filter tips

MicrosoftExcel filter tips
Leave a Comment » |
MS Excel | Tagged: Excel, filter, howto, MS Excel, tips & tricks |
Permalink
Posted by jarik
2008-07-19
Recently I have bought virtual server for several sites but backups are not free. So I decided to write few scripts that can be run with cronjob to save backups that can be later dowloaded vie ftp manually or even uploaded by another script to some other server.
This time I will show you how to make backups of MySQL databases. The most simple way to make backup of all databases is
mysqldump --all-databases > file.sql
It’s not very convinient if you have several databases ant want to make use of backups not only if you’ll need to restore all of them.
So I wrote simple script that makes backups of databases to different compressed (gziped) files and stores only last n backups.
mysqlbakcup.sh:
#! /bin/sh
#path to config file with database names
dbs="dbs.conf"
#Name of created directory
dir=`date +%Y-%m-%d_%H%M%S/`
#Directories with old backups to leave untouched by cleaner
dirsleave=3
if [ ! -d ${dir} ]
then
mkdir ${dir}
fi
for i in `cat ${dbs}`
do
mysqldump ${i} | gzip > ${dir}${i}.sql.gz
done
dirsleft=0
for i in `ls -r`
do
if [ -d ${i} ]
then
dirsleft=`expr ${dirsleft} + 1`
if [ "${dirsleft}" -gt "${dirsleave}" ]
then
rm -r -f ${i}
fi
fi
done
That’s it. Now fill dba.conf file.
dbs.conf:
database1
database2
In dbs.conf just write the list of names of databases to backup.
This script leaves last 3 backups and deletes older ones. So you can choose how often to run it. I’m doing it every night.
2 Comments |
Linux | Tagged: backup, bash, database, Linux, script, sql, unix |
Permalink
Posted by jarik