Monday, September 29, 2008

Javascript 正则表达式的字符类使用说明

[^...] 不在方括号之中的任意字符
需要注意的是, 在方括号之内也可以使用特殊的字符类转序列,对于\ () []这5个字符如果要出现在方括号中则需要转义,如以下二个效果是一样的:


/[^.*?+]/
/[^\.\*\?\+]/

另补充一点是[\b]是回退键的直接量:

/[\b]/.test("[\b]") // true

Saturday, September 27, 2008

MySQL Replication server_errno=2020

080927 15:28:42 [Note] Slave: connected to master 'test@localhost:3306',replication resumed in log 'mysql-bin.000003' at position 34699088
080927 15:28:42 [ERROR] Error reading packet from server: Got packet bigger than 'max_allowed_packet' bytes ( server_errno=2020)
080927 15:28:42 [Note] Slave I/O thread: Failed reading log event, reconnecting to retry, log 'mysql-bin.000003' position 34699088
080927 15:28:42 [Note] Slave: connected to master 'test@localhost:3306',replication resumed in log 'mysql-bin.000003' at position 34699088


$> vi /etc/my.cnf
# max_allowed_packet = 1M # modify it to
max_allowed_packet = 10M

Thursday, September 18, 2008

Rsync install and configure

Firstly, download rsync and make install, then:
Rsync Server configure file example:


motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock

[MODULENAME]
path = /data/backfrom
comment = back data using rsync server
uid = nobody
gid = nobody
read only = no
list = yes
auth users = test
secrets file = /etc/rsyncd.scrt

$> rsync --daemon --port=873

$> vi /etc/rsyncd.scrt
test:testYu@Gmail.com
$> chmod 400 /etc/rsyncd.scrt

==================
Client:

$> vi /home/users/passwordfile
testYu@Gmail.com
$> chmod 400 /etc/rsyncd.scrt

$> rsync -vzrtopg --progress --delete test@192.168.0.1::MODULENAME /data/backto --password-file=/home/users/passwordfile

==================
OR connect rsync server using ssh:

#!/bin/sh
DEST="192.168.0.1"
USER="test"
BACKDIR="/data/backfrom/"
DESTDIR="/data/backto/"
OPTS="-vzrtopg --rsh=ssh --stats --progress"
VAR=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
if [ $VAR -eq 0 ]; then
rsync $OPTS $BACKDIR $USER@$DEST:$DESTDIR
else
echo "Cannot connect to $DEST."
fi

Monday, September 08, 2008

Ruby 正则转义单引号

a = "it's = 'test'"
puts a.gsub(/(')/, '\\\\\\1')

需要将单引号'转义为\',然后存入数据库,本来是用a.gsub(/(')/, "\\'")来处理,发现不正确,查了一下ruby正则,发现:
\' The part of the string after the match
\' 代表是正则匹配位置后面的部分字符串