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
Showing posts with label work. Show all posts
Showing posts with label work. Show all posts
2008-11-11
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.
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.
2008-11-10
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
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
2008-11-06
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)
Pocasi.cz - Czech and European Weather Forecast (Czech language)
2008-08-21
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:
Source: Python doc
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
2008-08-19
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.
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.
2008-07-31
2008-07-28
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
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
2008-07-18
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
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
2008-07-07
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
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');
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');
2008-06-24
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
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
Subscribe to:
Posts (Atom)