Monthly Archives: October 2011

修改wordpress编辑器

一般习惯在Wordpress的HTML模式下来编辑,不过在添加b-quote的时候,编辑器喜欢在上下各添加两个回车符,我还要手工来删除这回车符,如果想禁用这一项功能,必须修改wordpress的js文件,这个文件是wp-incldes\js\quicktag.js,把js文件中的“”\n\n<blockquote>”,”</blockquote>\n\n””替换为“”<blockquote>”,”</blockquote>””

搞定AWK的if语句

用AWK写过一个优化处理Centos开机启动的的shell,凡是不在指定范围内的服务用awk停止。

1.首先用awk停止所有服务

chkconfig --list| awk '{system("chkconfig "$1" off")}'

2.利用awk的if判断服务是否在可启动的列表中,是的话就启动

chkconfig --list| awk '{if($1=="crond") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="network") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="sshd") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="nginx") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="php-fpm") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="mysqld") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="pptpd") system("chkconfig "$1" on")}'
chkconfig --list| awk '{if($1=="syslogd") system("chkconfig "$1" on")}'

但是这样写下来有些麻烦,原来没有 查到awk的if逻辑与是怎么表示的,试了几次shell报错也就没有优化,今天找到了资料,在awk中“||”表示逻辑与,“&&”表示逻辑于,上面的几行就能用一行shell表示了:

chkconfig --list| awk '{if($1=="crond" ||  $1=="network"  ||  $1=="sshd"  ||  $1=="nginx"  ||  $1=="php-fpm"  ||  $1=="mysqld"  ||  $1=="pptpd" ||  $1=="syslogd") system("chkconfig "$1" on")}'

Awk If Statement Examples ( if, if else, if else if, 😕 )

终于恢复了在OS Lion中使用三指在Finder和浏览器中前进后退

在10.5中已经习惯了使用三指在触摸屏左右滑动来实现Finder或者各种浏览器里面前进后退,升级了Lion后发现已经不能用了,在浏览器的页面中前进后退变成了双指左右滑动(在Finder中无法实现双指左右前进后退),三指左右滑动变成了切换桌面(Lion非常好的功能,超级喜欢)。虽然很喜欢Lion的切换桌面,但是还是怀念Finder中的切换方式,不过找到了个设置方式,只要把切换桌面变成四指左右即可,10.5的方便操作方式终于回来了。

安装OSQA问答系统


OSQA是一个python技术的开源QA系统,基于Django框架。因为Django要用python2.6,但是centos的yum体系是python2.4的,所以准备在一个Debian的VPS测试安装OSQA。

Hi-VPS的Debian 6.0的模板的source list有问题,需要更新一下:

cat >/etc/apt/sources.list <

VPS Debian模板默认安装了apache2和python(2.6),所以只要安装mysql-server即可:

#apt-get upgrade
#apt-get update
#apt-get install mysql-server mysql-client

创建OSQA的目录

#mkdir -p /home/osqa/osqa-server
#wget http://www.osqa.net/releases/fantasy-island-0.9.0-beta3.tar.gz
#tar zxvf fantasy-island-0.9.0-beta3.tar.gz
#cp -rf ./fantasy-island-0.9.0-beta3/* /home/osqa/osqa-server

在/home/osqa/osqa-server目录创建文件:

#cat >/home/osqa/osqa-server/osqa.wsgi <

删除默认的apach2站点文件:

#rm -rf /etc/apache2/sites-available/default\
/etc/apache2/sites-available/default-ssl\
/etc/apache2/sites-enabled/000-default

创建OSQA的apache配置文件:

#cat >/etc/apache2/sites-available/osqa <
	ServerAdmin forum@example.com
	DocumentRoot /home/osqa/osqa-server
	ServerName example.com

	#run mod_wsgi process for django in daemon mode
	#this allows avoiding confused timezone settings when
	#another application runs in the same virtual host
	WSGIDaemonProcess OSQA
	WSGIProcessGroup OSQA

	#force all content to be served as static files
	#otherwise django will be crunching images through itself wasting time
	Alias /m/ "/home/osqa/osqa-server/forum/skins/"
        
                Order allow,deny
                Allow from all
        
	Alias /upfiles/ "/home/osqa/osqa-server/forum/upfiles/"
	
		Order deny,allow
		Allow from all
	

	#this is your wsgi script described in the prev section
	WSGIScriptAlias / /home/osqa/osqa-server/osqa.wsgi

	CustomLog ${APACHE_LOG_DIR}/osqa.access.log common
	ErrorLog ${APACHE_LOG_DIR}/osqa.error.log

EOF


创建站点配置文件链接:

#ln -s /etc/apache2/sites-available/osqa /etc/apache2/sites-enabled/osqa

在mysql中创建数据库:

#mysql -u root -p
#CREATE DATABASE osqa DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

安装python-setuptools和其他必备工具

#apt-get install python-setuptools python-mysqldb
#easy_install South django django-debug-toolbar markdown html5lib python-openid

开始安装:

#cd /home/osqa/osqa-server
#cp settings_local.py.dist settings_local.py

settings_local.py中有些部分需要修改:

DATABASE_NAME = 'osqa'
DATABASE_USER = 'osqa'
DATABASE_PASSWORD = 'your_osqa_password'
DATABASE_ENGINE = 'mysql'
APP_URL = 'http://YOUR_URL/'

开始安装:

#python manage.py syncdb --all
#python manage.py migrate forum --fake
#chown -R www-data:www-data /home/osqa/osqa-server
#chmod -R g+w /home/osqa/osqa-server/forum/upfiles
#chmod -R g+w /home/osqa/osqa-server/log
#/etc/init.d/apache2 restart

安装完毕