Sunday, December 28, 2008

Internet Explorer for Linux

Sometimes I want to test my web pages under MSIE. Sometimes I have to view foreign pages under MSIE. Under Linux was not easy solution except reboot to Windows or start Wine or VMWare-like emulator. Now comes much faster and much easier solution.

Project IEs for Linux connects usability of Wine with available versions of original MSIE. All is covered by nice installer written in Python. You have almost no additional tasks to install it.

Fast and easy way to install ies4linux in Debian Kubuntu:

Install wine
# apt-get install wine wine-dev wine-gecko msttcorefonts

Install ies4linux
$ wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
$ tar zxvf ies4linux-latest.tar.gz
$ cd ies4linux-*
$ ./ies4linux

Installer will guide you through installation and finally makes icons on your desktop.

Resources:
IEs4Linux - Article in Czech language.
installation of wine at ies4linux Kubuntu page

Thursday, December 25, 2008

Setup MTU in Win XP

How to setup MTU (Maximal transfer unit) in Windows (XP)
Sometimes you need to change MTU on network interface in Windows desktop.

Start program
regedit.exe

Open path
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\]

Choose alias of your interface, e.g.:
[{A892802D-8D6A-4708-A1AA-EA93415D998F}]

Create new key: MTU
Type: REG_DWORD
Value: 195

Note: You can find proper alias by inspecting settings of each interface. Settings of each interface differ at least in Default gateway and IP address.

Note: Default value is 1500 (0x5dc). Values 195 or 190 are useful for erroneous WiFi.

Sunday, November 23, 2008

OpenVPN+WindowsXP+Debian Linux

How to connect Windows XP and Debian Linux using secure connection over OpenVPN.

Prepare your working tools
su
apt-get install openvpn
cd /usr/share/doc/openvpn/examples/easy-rsa/2.0/
gzip -d *.gz
mkdir -p /etc/openvpn/tools
ln -s tools/keys /etc/openvpn/keys
make install DESTDIR=/etc/openvpn/tools
cd /etc/openvpn/tools

Change key size (optionally):
Open file: /etc/openvpn/tools/vars
Change: export KEY_SIZE=1024
To value: 2048

or change key size by executing following commands (still optional):
cp vars vars.bak
cat vars.bak | \
sed -e 's/export KEY_SIZE=1024/export KEY_SIZE=2048' > vars


Generate keys:
source vars
./clean-all # Warning: this will delete all your previous keys!
# optionally: mv keys .. ; ln ../keys keys
./build-ca
./build-dh
./build-key-server server
./build-key client1
./build-key client2
./build-key client3

In future you can add new client certificate by following commands:
source ./vars
./build-key client4

# Optionally:
mkdir logs
mkdir var

Your client key is stored to files client1 - 3. Copy appropriate client file with certificates to your Windows desktop.

Customize configuration files:
On Linux: server.conf / client.conf
On Windows: server.ovpn / client.ovpn

Further settings:
Setup firewall rules
Open access through firewall to OpenVPN server:
iptables -I INPUT -s trusted-client.com -p UDP --dport 1194 -j ACCEPT
iptables -I FORWARD -s trusted-client.com -p UDP --dport 1194 -j ACCEPT

Allow forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

Allow access from VPN to anywhere around the world (optional):
iptables -I INPUT -i tun+ -j ACCEPT
iptables -I FORWARD -i tun+ -j ACCEPT

Allow NAT for VPN
iptables -F -t nat
iptables -t nat -A POSTROUTING -s 10.1.0.0/24 -o eth0 -j MASQUERADE

Setup OpenVPN server on Debian Linux:
Copy files: ca.crt, server.key, server.crt
To: /etc/openvpn

Setup OpenVPN client on Windows XP:
Copy files: cli/*, ca.crt, server.crt, client3.key, client3.crt
To: C:\Progra~1\OpenVPN\config

Start OpenVPN server on Debian Linux:
/etc/init.d/openvpn restart
or
openvpn --config /etc/openvpn/server.conf

Start OpenVPN client on Windows XP:
right click OpenVPN tray icon, choose "connect"
or run from command line:
openvpn --config C:\Progra~1\OpenVPN\config\client3.ovpn
 ... can be stopped by the F4 key.

Start  or shutdownOpenVPN on Windows7 as a service:
net start OpenVPNService
net stop OpenVPNService

SSH without password

You can access your remote Linux server over SSH without password. This is faster and some cases prefered way.

The goal is in generating of pair of public-private keys which will authorize your access. You will leave your private key on your local computer (kept in secret) and copy public key to any remote server you want to access. After registering the public key you will be able to access remote server without entering passowrd.


Generate public-private key pair on your local Linux desktop:
$ ssh-keygen -b 2048 -t dsa

Distribute your public key to remote server:
$ scp ~/.ssh/id_dsa.pub \
user@server.com:.ssh/id_dsa.pub.tmp


or alternatively you can use:
ssh-copy-id -i ~/.ssh/id_dsa.pub user@server.com

Register your public key on your remote server:
$ ssh user@server.com
$ cat ~/.ssh/id_dsa.pub.tmp >> ~/.ssh/authorized_keys2


Access your remote server without password:
$ ssh user@server.com

step by step guide in Czech

Wednesday, November 19, 2008

Time synchronization in Linux

Date and time settings in Debian Linux

Set date and time approximately (optional step):

$ sudo su
# apt-get install ntpdate
# ntpdate ntp.cesnet.cz


Install NTP for higher precission with automatic time synchronization:

# apt-get install ntp ntp-server ntp-simple ntp-doc


Configure NTP for automatic time synchronization:
Open file /etc/ntp.conf

Add lines:

server clock1.zcu.cz
server clock2.zcu.cz
server ntp.cesnet.cz

Comment out everything except following directives:

driftfile, statsdir, statistics, filegen (more lines in sequence)


Start NTP server:

# /etc/init.d/ntp-server restart


Display current time settings:

# ntpq -p
- shows table of servers accessibility and accuracy
- main server is marked by star (*), else automatic synchronization does not work


Store date and time to hardware clock:

# /usr/sbin/ntpdate -s
# /sbin/hwclock --adjust
# /sbin/hwclock --systohc

Tuesday, November 18, 2008

Command com in Linux Shell

If you liked it and if you miss it...

while `/bin/true` ; do
read -p 'C:\> ' cmd
if [ "$cmd" != "" ]
then
echo Bad command or file name
# echo $cmd
echo
fi
done

Monday, November 17, 2008

Shell regular expressions

Sedatives with sed

sed -i -e 's/template/supplement/g'

parameters:
-e allows to chain more rules for replace
/g replaces all occurences (global)
-i edit current file in place (use -ibackup for backup)

Fresh grepfruit

grep -P 'template' file

prints lines from file which match regex template.
-P uses Perl-compatible regular expressions (if not available, try -E instead)
-E uses extended regular expressions


Awkward tasks

who | awk -F ' ' '{print $1}'

prints first item of each line.
-F specifies item delimiter, default is white character.

Tuesday, November 11, 2008

Faster scp with tar

scp using tar:

Following sequence retrieves data from remote server immediately without need to store compressed tar to file.

ssh root@server tar -c /www/domain.com | tar -x

Following sequence sends local data via ssh to the remote server.

tar -c /www/domain.com | \
ssh root@server cd /www/domain.com '&&' tar -x


Bash - functions, timestamp, date diff

Bash function - command line calculator
calcfn () { echo "$*" | bc -l; }

Bash timestamp of specific date
date +%s -d 20070103

Date difference in Bash
dateOfPast='20080103'
today=`date +%Y%m%d`
timeStampToday=`date +%s -d $today`
timeStampOfPast=`date +%s -d $dateOfPast`
secondsInDay=86400
dayDiff=`echo \($timeStampToday - $timeStampOfPast\) / $secondsInDay | bc`
echo $dayDiff

Convert Unix timestamp to local date time
echo $timeStamp | perl -n -e 'chop; print localtime( ($_)[0] ) . "\n";'

Convert Unix timestamp to GMT
echo 1234567890 | perl -n -e 'chop; print gmtime( ($_)[0] ) . "\n";'
Unix Timestamp
1234567890 ... Friday The 13th.

Monday, November 10, 2008

Vim - File Differences with vimdiff

Brief usage of vimdiff. For detailed description see man, info and online docs.

Start vim in diff mode
vimdiff file1.php file1.php~

Alternatives:
gvimdiff
vimdiff -O ==horizontal windows
vim -d

Switch between windows
Ctrl+w Ctrl+w

Put new lines to other window
dp

Obtain new lines (from another window)
do

Skip between diff groups
previous group
[c

next group
]c

(Un)folding
open folded difference
zo

close folded diff
zc

Source: vimdoc

Thursday, November 06, 2008

Czech Weather Forecast - Pocasi.cz

Our team was hard working last weeks. And here is the result:
Pocasi.cz - Czech and European Weather Forecast (Czech language)

Sunday, October 12, 2008

Automated build with Autotools

Automake, Autoconf, Libtool - simply Autotools...

Quick way to start autotools

Programmer's command sequence:

autoscan
autoreconf --install --force
./configure
make clean


install
builds the configuration scripts by calling the sequence of particular autotools commands. The advantage is that we do not have to remember the whole sequence
and we do it in one simple command.

force forces the autoreconf to rebuild the configuration even if it already exists.

make clean cleans up build environment

The autoreconf command supplies following sequence
libtoolize --force
aclocal
automake --foreign --add-missing
autoconf


User's command sequence:

./configure --prefix=/usr/local
make
make check # not neccessary, just a test
DESTDIR=/tmp/package make install

Resources:
AutoBook book for Auto* Libtool, Gettext, ... (latest)
AutoTools for beginners - quick intro
Wikipedia: GNU build system - short description

Monday, October 06, 2008

Greek dance, Prague tower, bowling

Weekend in Czech cottange with Greek dance, Prague tower and bowling without bowles...

Last weekend I was invited to friend's cottage. He prepared barbequeing and bought Pilsen beer.

It was great but I left during saturday to prepare for Greek dance with my friend. It was simply excellent. Good music and good dance with fine people. And additionally I have found dancing partner for latin dance courses.

On sunday evening I have met with my school mate and his girl friend. They invited me to visit their new residence. It was nice place. We were talking to late night about summer, traveling, work and our hobbies. We almost forgot about the bowling so we had to change our plan and move the bowling to wednesday.

On wednesday will be interresting concert so we will probably change our plans again.

Evrope to osladime

Evropě to osladíme. Dokonce jsme si nechali nahrát novou verzi hymny, která obsahuje nepatrné zakašlání. Prostě je vidět, že na Evropu kašleme. (Obrázek kampaně převzat z www.lidovky.cz)

Saturday, September 27, 2008

Processing mail with procmail

Sometimes I change my procmail rules and I want to force procmail to process my inbox again with these new rules. The inbox is usually in mbox format, therefore I have to split it to particular emails.

In this case I use formail which splits inbox to particular messages and calls specified program to serve each message independently.

Process allready received mail with procmail rules again:
formail -s procmail < $MAIL

Wednesday, September 10, 2008

AJAX Exception: Permission denied

While experimenting with AJAX via iFrame, I received following exception:

Error: Permission denied to get property Window.document

It was caught while accessing iFrame's body from the main page by the following way:
document.getElementById(frameId).contentWindow.document.body;

The problem was that I loaded some foreign site into my iFrame and then I triend to access it's body object.

Firefox prevents Javascript from accessing objects (like window's document) of sites different from the original document site. The solution is to place both the main page and content of the iFrame to the same server site.

Monday, August 25, 2008

Melodies On The Street

Last weekend I visited my home town Pilsen. I was terribly tired but I felt lucky to spend some time with my friends. I arranged meeting with my school mates. There were too many events and so little time, therefore I have met just some of them. Even though I spent a nice time.

One of my friends decided to be programmer and to reach really big salary. If he is allready decided then I don't want to argue to him about that idea. I will help him on his way.

Thursday, August 21, 2008

Python Unicode exception

While using Python I encounter one common exception:

Traceback (most recent call last):

File "./unicode-test.py", line 564, in ?
main()
File "./unicode-test.py", line 553, in main
print "Value: %s" % unicodeString
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 87: ordinal not in range(128)

The reason is that we want to print Unicode object but it cannot be converted to appropriate characters automaticaly. Solution is easy, we have to convert the object before printing it:

print ("Value: %s" % unicodeString).encode('utf-8')

optionaly:
# visible char
print ("Value: %s" % unicodeString).encode('ascii', 'replace')
# zero char
print ("Value: %s" % unicodeString).encode('ascii', 'ignore')
# exception (default)
print ("Value: %s" % unicodeString).encode('ascii', 'strict')

Additional reading: source

Note: We have to convert the whole object after joining ascii with unicode. Otherwise Python would join the ascii part and utf8 part and convert the result to Unicode and the error appears again.

You can use unicodedata to normalize string:
import unicodedata
unicodedata.normalize('NFKD', 'p\xc5\x99\xc3\xadli\xc5\xa1 \xc5\xbelu\xc5\xa5ou\xc4\x8dk\xc3\xbd k\xc5\xaf\xc5\x88'.decode('utf-8')).encode('utf-8')

Source: Python doc

Tuesday, August 19, 2008

Non-traditional English lesson

Well, today I spent nice English lesson. Some students go with their teacher to the nature or sit in a caffee or pub. Today was nice weather so we got into nice restaurant and started talking.

For me was absolutely unusual leaving the work before the 4pm so I was looking around enjoying the city rush and sun. We returned aproximately at noon and decided to repeat the meeting again in another restaurant. Additionaly we combined our lesson with lunch so I saved almost one whole hour just by attending my favourite English lesson.

Friday, August 15, 2008

Bits and pieces

Great Greek dances...

I am looking forward for this weekend. I will attend lesson of Greek dances with my friend. We tried this kind of dance just once before and we liked it.

Yesterday I had talk with one of the Czech Square dance choreographers (yes, caller) about our further teaching lessons of another dance level - C3A. Just a few people in Czech republic know this level, we even do not have whole square group and we meet irregularly. His idea was to teach other dancers this level to enforce our dancers base.

Attended Greek dances
...It was fine. In the village nearby Prague, along the Vltava bank. The weekend was raining so it was good time for dance.

Mixed notes

Python lacks good XML support in standard distribution. I found a list of Python XML libraries comparison:
http://www.somebits.com/weblog/tech/python/xpath.html

It is possible to convert DOM to dictionary records with following functions:
http://code.activestate.com/recipes/116539/

or use module xml2dict:
http://code.google.com/p/xml2dict/

Sometimes I do ssh to some development machine which I am not quite familiar with. I usualy want to detect Linux distribution and version. The following description is very helpful:
http://www.novell.com/coolsolutions/feature/11251.html

Czech trafic navigator:
http://www.dopravniinfo.cz/default.aspx

Python date and time manipulation:
http://seehuhn.de/pages/pdate

Thursday, August 14, 2008

Dancing in Samba rhythm

Sometimes I want to use Samba as fast as possible. Unfortunately there may occur unexpected problems during user authentication. Following sequence of commands solves many of them:

smbpasswd user_name
pdbedit -a user_name

In other words, adding user and setting up password may not have been enough, we need to add him/her to user database.

Mount:
sudo mount -t cifs //netbiosname/sharename /media/sharename

Options:
-o \
username=winusername, \
password=winpassword, \
iocharset=utf8, \
file_mode=0777, \
dir_mode=0777 \

Or:
guest, \
rw

Monday, August 11, 2008

Debian X Fonts

How to install nice X fonts in Debian quick and easily?

In the root console exec command:
apt-get install msttcorefonts

If the following error occur:
E: Couldn't find package msttcorefonts

you should add "contrib" section to your /etc/apt/sources.list:
deb http://ftp.us.debian.org/debian etch main contrib non-free

and then execute - as usually:
apt-get update

and do again:
apt-get install msttcorefonts

Then select these fonts as default.

If you use KDE open Control Center then select:
Appearance & Themes then Fonts. In the right dialog select default fonts for each font type.

Appropriate font names are: Times, Arial, Courier, Courier New, Courier 10 Pitch, Lucida Typewriter

Done. Note that font settings take effect after restart of each application. You also have to select fonts for specific applications such as Firefox, Thunderbird, Kwrite, etc.

Wednesday, August 06, 2008

Sailing on Vltava river

Yesterday was nice weather and sun was shining like other days. But instead of other days I did not have to stay in my office all the time. I just finished one important project and I was allowed to leave for a while so I enjoyed the day even more.

I went with my friend on the Vltava bank where we rent pedal-powered ship. Then we sailed around the Strelecky island. We enjoyed very nice view of Prague Castle and Vysehrad church which we saw from our ship.

Thursday, July 31, 2008

Počítačový evergreen

Proti bolesti zad...

http://zdravi.idnes.cz/deset-prekvapivych-triku-proti-bolestem-zad-f33-/zdravi.asp?c=A080317_141512_zdravi_bad

http://slovnik.seznam.cz/?q=pra%C5%BE%C3%A1k&lang=cz_en

100 Prague towers

Interesting project shows Prague from perspective of famous Prague towers. You can turn around in 360 degrees or move to another tower just by clicking on the picture.

English version: http://stovezata.praha.eu/homepage.html
Czech version: http://stovezata.praha.eu/index.html

Tuesday, July 29, 2008

Square dancing weekend

Last weekend was wonderful dancing event for people who enjoy Square dance. My friends David&Lenka precisely prepared dancing event which was the final part of their weding celebration.

It started in the Prague where we took boat trip throught center of the city and we saw some nice places including Charles' bridge and Vysehrad. Then we went by bus to the place where the dancing started.

It was situated in hotel near by Prague. Level of the even was high in all ways - it was very well organised, place was nice, hotel stuff took care of us all the time, dancing quality was very good and also square dance level - we danced C3A all the weekend. Even the weather was great so it was very nice relaxing weekend.

At the end of the weekend I went with my friend to the theatre to visit play. It was part of the summer student theatre fest. The evening contained one chorus sing, one drama and one pantomima. All the plays were wonderful.

Monday, July 28, 2008

Playing Oracle and MySQL game

Sometimes we want to escape characters in Oracle SQL Plus console

Set the escape character
set escape \

Send command (in the same session)
INSERT INTO customer (url) VALUES('http://www.example.com/redir.php?id=1234\&log=true');

Select rows recursevely

SELECT LPAD(' ', 2 * (LEVEL - 1)) || TO_CHAR(child) s
FROM test_table
START WITH parent IS NULL
CONNECT BY PRIOR child = parent;

This has just one restriction: no joins allowed.
source: http://www.adp-gmbh.ch/ora/sql/connect_by.html

Insert-update with MySQL

INSERT INTO table_name (col_names)
VALUES (values)
ON DUPLICATE KEY UPDATE col=val, col2=val2;
source: http://devblog.billism.com/?p=12

Tuesday, July 22, 2008

Riding back horses again

We were riding back horses again. Last weekend was very good weather for relaxing so we took another lesson of horse-driving. We ran for some times but very slowly and carefully, much slower than I wanted. But better to be careful than injured.

We went to the nature and if was time I enjoyed the surrounding view of woods, fields and wild in the sunshine.

Just at the end the horse stepped on my foot. It was not good but, fortunately, I did not need the doctor's help.
Even though, I am decided to take another lesson next time but I will take another horse.

Friday, July 18, 2008

Starting with MySQL

All the beginning are terrible and slow... again and again looking into the manual for the same commands.

Install
apt-get install mysql-client mysql-server mysql-common php5-mysql

Set root password
mysqladmin password 'new_root_password'

Login to DB
mysql -u root -p

Create database
CREATE DATABASE db_name;

Create regular user and grant appropriate rights
SELECT PASSWORD('secret_password');
CREATE USER user_name IDENTIFIED BY 'secret_password';
GRANT ALL ON db_name.* TO 'user_name'@'host_name' IDENTIFIED BY 'secret_password';
^D

Login under the regular user
mysql -u user_name -p db_name

Create table
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
created_date DATETIME,
name VARCHAR(200),
phone VARCHAR(200)
);

Create index
CREATE INDEX index_users_name ON users (name);
details

Riding back horses

Me and my brother tried riding back horses last week. I was brave enough to settle the horse and ride back immediately to the nature, while my brother decided to take theoretical lesson first. This week we both go to ride horses freely in the nature so we will see...

Visit to the State Opera Prague

At the beginning of July I took the chance and visited the ballet performance in the State Opera Prague. I also invited my close friends. Swan Lake is the famous opera from Tchaikovsky and we all enjoyed it very much. After that we took a cup of hot chocolate and went for sight seeing in the evening city.

Firefox: Open new window in new tab

How to force open new window to new tab in Firefox 2.0?

Open location
about:config

Set Filter
browser.link.open

Variables:
browser.link.open_external
Rule for opening links from external programs (e.g. Thunderbird, Psi, ...)
browser.link.open_newwindow
Rule for opening links targeted to new window by the 'target' attribute
browser.link.open_newwindow.restriction
Rule for opening restrictions by Javascript

Values:
The value sets opening links in:
1 current tab
2 new window
3 new tab in current window

Thursday, July 10, 2008

Xlib: connection refused by server

Trying run under root:
su
swscanner
I received following error message:
Xlib: connection to ":0.0" refused by server

Easy solution, run under regular user:
xhost +localhost
OR:
xhost local:root

Then run under root:
export XAUTHORITY=/home/regular_user_name/.Xauthority

Where
regular_user_name is name of the user doing command su.


Monday, July 07, 2008

Acer TravelMate 5720 - video drivers

How To install video drivers to Acer TravelMate 5720 (thanks to Miro):
Proprietary binary drivers for Debian:
apt-get install fglrx-driver fglrx-driver-dev fglrx-control fglrx-kernel-src
cd /usr/src/
tar -xjvf fglrx.tar.bz2
cd modules/
./make.sh
mkdir -p /lib/modules/`uname -r`/misc
cp fglrx.ko /lib/modules/`uname -r`/misc/
depmod -ae

Oracle DB server notes

Oracle Error:
Warning: ocifetch(): OCIFetch: ORA-24374: define not done before fetch or execute and fetch in /home/martin/dev/www/inc/ora_funct.php on line 15

Reason and solution:

sometimes wrong syntax but mostly missing access rights to accessed table. You can solve this problem by granting sufficient rights to the user which is accessing the table.

Oracle sql date comparison:
SELECT column
FROM table
WHERE start_date <= TO_DATE('20080401', 'yyyy-mm-dd');

Tuesday, June 24, 2008

Spelling with ispell and related tasks

Change default ispell dictionary:
dpkg-reconfigure ispell
or:
select-default-ispell

Using ispell by non-interactive way:
echo string | ispell -a | grep -v 'Ispell version' | grep -v '^

Optionaly we can define another dictionary:
ispell -d dictionary_name

We can choose the dictionary from istalled files:
ls /usr/lib/ispell/*.hash | sed 's/.*\///' | sed 's/.hash//'

One kind of errrors while using xargs:
xargs: unmatched double quote
OR:
xargs: unmatched single quote
Solution:
find . -type f -print | xargs grep pattern

I experienced error message while using iconv:
iconv illegal input sequence at position 0
Solution:
ispell --null

Converting UTF8 to 7bit ASCII:
iconv -f UTF-8 -t ASCII//TRANSLIT < input.txt > output.txt