17 August, 2007

Interleaved table

Every time I hear question: "How to paint odd and even rows in html table in different colors".



Here is the example how to do it simple:

<html>
<head>

<style type="text/css">

.odd {background-color: #eee;}
.even {background-color: #fff;}

</style>

<script type="text/javascript">

function zebra(tableId)
{
var table=document.getElementById(tableId);
if (table)
{
var rows = table.getElementsByTagName("tr");

for (var i = 0; rows.length > i; i++)
{
rows[i].className = ((i % 2) == 0 ? "odd" : "even");
}
}
}

</script>
</head>

<body>

<table id="irregular">
<tr>
<td>break</td>
<td>broke</td>
<td>broken</td>
</tr>
<tr>
<td>buy</td>
<td>bought</td>
<td>bought</td>
</tr>
<tr>
<td>catch</td>
<td>caught</td>
<td>caught</td>
</tr>
<tr>
<td>forget</td>
<td>forgot</td>
<td>forgotten</td>
</tr>
</table>


<script type="text/javascript">
zebra("irregular");
</script>

</body>
</html>

15 August, 2007

Power Designer - the best UML and database modeling tool

The best software modeling tool which I've ever used is Power Designer from Sybase.
I've got acquainted with this program some years ago (it was a repackaged version "QDesigner" by Quest Software).



I've really enjoyed developing with this tool.
This tool is very useful and usable, flexible, easy to use and pretty good.

Power Designer CD contains some visual samples.



Object Oriented Model

It is possible to create UML diagrams (classes, sequence, deployment, etc.) and generate source codes (for many programming languages) from the model.



Physical Data Model

Development of a database turns to pleasure. Power Designer can generate SQL scripts with databases and tables definitions. Also it can create test data sets.



I've tested and evaluated some trial versions of Power Designer and I may say "it is the best".



You may download free evaluation copy of Power Designer or buy it.

14 August, 2007

HowTo check files integrity via shell script

In order to control integrity of files on my fileserver I've created special script.
It walks around filesystem (in the given directory) and calculates checksums for files or checks their.
If the file has been changed after last check the warning message will be displayed.



Script:


xqx_uintegra.sh

#!/bin/bash

#Checks files integrity via md5sum utility.
#
#For removal of all *.md5 files, execute: find -name "*.md5" -exec rm {} \;
#Usage:
# xqx_uintegra.sh "/path/to/directory"


DATE=`date +%Y.%m.%d_%H.%M.%S.%N`
LOG=~/`basename $0`-$DATE.log
touch $LOG

if test ! -w "$LOG"; then
LOG=/dev/stdout
fi

SHIFT=$[`tput cols`-10]
MOVE="\\033["$SHIFT"G"
DEFAULT="\\033[0;39m"
RED="\\033[1;31m"
GREEN="\\033[1;32m"
YELLOW="\\033[1;33m"
BLUE="\\033[1;34m"

logError_end() {
echo -e "$MOVE$RED$1$DEFAULT"
echo -e \\t$1 >>$LOG
}

logOk_end() {
echo -e "$MOVE$GREEN$1$DEFAULT"
echo -e \\t$1 >>$LOG
}

logWarning_end() {
echo -e "$MOVE$YELLOW$1$DEFAULT"
echo -e \\t$1 >>$LOG
}

checkSum() {
#$1=file
echo -en CheckSum:\\t$1
echo -en CheckSum:\\t$1 >>$LOG
file=`basename $1`
dir=`dirname $1`
(cd $dir && md5sum -c -- $file >/dev/null 2>&1 && logOk_end OK || logError_end ERROR)
}

calcSum() {
#$1=file
echo -en CalcSum:\\t$1
echo -en CalcSum:\\t$1 >>$LOG
file=`basename $1`
dir=`dirname $1`
(cd $dir && md5sum -b -- $file >$file.md5 2>/dev/null && logWarning_end CALCULATED || logError_end ERROR)
}


fin_process() {
while read; do
#echo $REPLY
if test -n "`echo $REPLY | grep '\.md5$'`"; then
checkSum $REPLY
else
if test ! -f "$REPLY.md5"; then
calcSum $REPLY
fi
fi
done
}


find $1 -type f | fin_process;
echo
echo -e "\\033[1;31m"
cat $LOG |grep ERROR
echo -e "\\033[0;39m"


This script works in Linux systems and under Cygwin environment.

Examples of usages:
In the Windows+Cygwin:
bash xqx_uintegra.sh E:/Temp/sun

In the Linux:
xqx_uintegra.sh /home/fileserver

13 August, 2007

HowTo understand Vi ( Vim ) editor

"Vim (Vi Improved) is very powerful editor..."
It is true, I know, I like it. Vi is the best editor for the Linux/Unix console.

Have you tried to understand Vi?

Most people don't understand Vi, because they don't like console and command line, it is needlessly for theirs.
Vi is good for servers, embedded and non-GUI systems;
for admins, linux developers and gurus,
but not for normal people, at first look.

You may execute vimtutor in your command line in order to understand Vi.
Vimtutor is great tutorial.

Also Vi supports highlighting for many types of files.


I've created consolidated list of Vi commands and hot keys:

Navigation
h move cursor left
j move cursor down
k move cursor up
l move cursor right
i, INSERT edit mode
R replace mode
ESC normal mode
CTRL-g show filename, current location in the file and status
SHIFT-g goto the end of file
number+SHIFT-g goto to the line number
% goto the matching pair for brackets [, ], {, }, (, )
:syntax on switch text highlight on
:help command help for the command

Search
/ search text
n search text again
? search in the backward direction
SHIFT-N search text again in opposite direction
:set ic search ignore cases

Edit
x delete character under cursor
de delete to the end of word
dw delete to the end of word+space
d$ delete to the end of line
d^ delete to the begin of line
dd delete a whole line

ce,w,$,^ do the same as delete command, but also switch to edit mode

u undo the last command
U restore line to it's original state
CTRL-R redo the last command

p put the last deletion after the cursor
o,O open new empty line below/above the cursor and switch to the edit mode
a append text after the cursor
A append text to the end of a line


Replace
r+character replace character under cursor
:s/old/new replace old text with new text (once)
:s/old/new/g replace all old text with new text in the line
:s/old/new/gc replace all old text with new text in the line, but ask to confirmation
:%s/old/new/g replace all old text with new text in the file
:#,#s/old/new/g replace all old text with new text between lines in the range #,#

Common
number+command repeat command number of times (e.g.: 2dd deletes two lines, 5j moves five lines down)


File
:q! exit without changes
:w save file
:wq save and exit
:w filename save file as filename
:#,# w filename save part of file between lines in the range #,#
:r filename insert the contents of the file
:!command execute external command

This article is created in Vi!

There are some programs which syntax is partially compatible with Vi: ed, sed (stream editor) and others.
E.g.:
command cat file.txt |sed -e '1,10s/a/A/g' replaces all 'a' with 'A' from 1 to 10 line.