Utilize shell scripts,linux commands, open source tools,java, to Maximize the Power of Linux.
Focused on working with linux and shell, search engine technology including Chinese segmenter
Any questions please contact me at gmail: david.ullua

Labels

Showing posts with label common tools. Show all posts
Showing posts with label common tools. Show all posts

1/15/2007

vim与gvim 转换highlight的文本到html网页

今天发现用gvim居然可以把vim中着色显示的文本文件(c, php, sh, java, ...)转换成html,
且保留显示的格式和颜色,不必再为发布源代码到blog上显示格式混乱的问题了。

在gvim中点syntax => convert to html, 这样会产生一个后缀名加上html的文件,
然后保存即可(:w ).如果要对.html文件或者源文件作适当的编辑,
可以用Ctrl+ww 可以切换源文件与产生的html文件的窗口。

google 了一下"vim convert to html", 原来vim中也可以使用

:runtime! syntax/2html.vim 命令来保存按语法高亮显示的文本到html文件。

参考: http://vimdoc.sourceforge.net/vimfaq.html

24.14. How do I convert a source file (.c, .h, etc) with the Vim syntax
highlighting into a HTML file?

You can use the 2html.vim script to convert a source file into a HTML file

with the Vim syntax highlighting. Use the following command:
:runtime! syntax/2html.vim

For more information, read

:help convert-to-HTML

1/11/2007

to implement SVN password changing function by shell and php

We have install SVN as our version control system. It doesn't provide a remote password changing function on the web. I googled on the internet and didn't found a good solution. So I wrote a script in bash and a php front end page to do it.
(if you need a jsp or perl front end page, you can write one yourself)

Here's the shell script to change password for svn:

#!/bin/sh
#changepass.sh , function: change password for svn
#usage: changepass.sh username oldpass newpass newpassretype
if [ ! "$#" = 4 ]
then
echo "Usage:`basename $0` username oldpass newpass newpassretype"
exit 1
fi

passfile="/home/svn/passwd"

username=
oldpass=
newpass1=
newpass2=

username=$1
oldpass=$2
newpass1=$3
newpass2=$4

if [ ! $newpass1 = $newpass2 ]
then
#echo "password does not match!";
echo "password does not match!"
exit 2
fi

export NEWPASS=$newpass1
export USERNAME=$username

i=`sed /^"$username"[" ""\t"]*=[" ""\t"]*$oldpass\$/p $passfile -n|wc -l`
if [ $i = 1 ]
then
awk '{ if(index($0,ENVIRON["USERNAME"])==1) {print ENVIRON["USERNAME"] " = " ENVIRON["NEWPASS"] }else {print $0} }' $passfile > /home/svn/newpass

rm /home/svn/newpass 2>&1 1> /dev/null
cp /home/svn/newpass $passfile

echo 'password changed!'
elif [ `sed /"$username"/p $passfile -n |wc -l` > 0 ]
then
echo ' username and password does not match'
else
echo 'could not find username'
fi


here's the php front end changepass.php , it is for php 5, if you use php 4, maybe you need use $HTTP_POST_VARS instead $_POST ( just guess, i haven't test it):



if(strlen($_POST["pwd1"]) >0 ){
if($_POST["pwd1"]!=$_POST["pwd2"]){
print("Passwords do not match, try again.

\n");


}else{

$LoginName = $_POST["loginname"];
$OldPassword = $_POST["oldpwd"];
$NewPass1 = $_POST["pwd1"];
$NewPass2 = $_POST["pwd2"];
$retval='';
#echo $LoginName;
#echo $OldPassword;
// user apache or nobody(who runs httpd daemon) needs the permission of passwd file and temp file
$command = "/mnt/apache/changepass.sh ".$LoginName." ".$OldPassword." ".$NewPass1." ".$NewPass2 ;

#$command = "/bin/cat /mnt/apache/changepass.sh "." 2>&1";
$command = $command." 2>&1";

#system("/bin/echo abc",$retval);
system($command, $retval);

echo "
" ;echo $retval;echo '
';


if($retval!=0){
print("
Error while setting password:
\n");

}

}
}
else{
;#echo "parameters not set!";
}
?>





Login Name:
Old Password:
New Password:
Repeat Password:


the php page and shell scripts should works ok, but the php page shows nothing after click "submit" in fedora, however in slackware it is ok.

After debug step by step, found that shell script error message would not be ouput on the web page, so i add this line: $command = $command." 2>&1";

And finally found that SELinux would block some function on the web server. I disabled SELinux in the firewall settings, and it works.



12/18/2006

Gaim 1.5/2.0 with SSL support

Compile GAIM with SSL support on Linux (for MSN, gtalk/Google Talk)

when running gaim to connect to MSN/gtalk, it failed and said: SSL support is needed for MSN. Please install a supported SSL library. MSN (Microsoft Messenger) and Google Talk (GTalk or Gmail Talk) both require SSL authentication enabled when using GAIM instant messenger. See http://gaim.sf.net/faq-ssl.php for more information.

That mean you have not compiled GAIM with SSL support enabled or you don't have libraries (NSS and NSRP) in proper directories.
For gaim 1.5, you can just add "/usr/lib/firefox2.0/"(where your firefox is located) to the end of file /etc/ld.so.conf, and run ldconfig as root, then you can run gaim with SSL ; For gaim 2.0, you can install it from tarball and configure SSL support by the following steps:

1,Download SSL support libraries from Mozilla to /home/soft/gaim/:
#cd /home/soft/gaim/
#wget ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_9_RTM/Linux2.4_x86_glibc_PTH_OPT.OBJ/nss-3.9.tar.gz
#wget ftp://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v4.4.1/Linux2.4_x86_glibc_PTH_OPT.OBJ/nspr-4.4.1.tar.gz

2.Copy SSL library files to proper locations (system libraries directory):
#cd /home/soft/gaim/
#tar xzvf nss-3.9.tar.gz
#tar xzvf nspr-4.4.1.tar.gz

#cp -rf nss-3.9/lib/* /usr/local/lib/
#cp -rf nspr-4.4.1/lib/* /usr/local/lib/
(you can use /usr/lib/ instead if required)

3.Install gaim 2.0 with ssl support
#tar xzvf gaim-2.0.0beta5.tar.gz (assume you have download gaim-2.0 to /home/soft/gaim )
#cd gaim-2.0.0beta5
#./configure --with-nss-includes=/home/soft/gaim/nss-3.9/include --with-nspr-includes=/home/soft/gaim/nspr-4.4.1/include --with-nss-libs=/home/soft/gaim/nss-3.9/lib --with-nspr-libs=/home/soft/gaim/nspr-4.4.1/lib

Configure should finish without an error - look for this line:
SSL Library/Libraries......... : Mozilla NSS

If the lines contains Mozilla NSS, then you are set.

#make
#make install

Now run GAIM and you should be done, if the previous steps went without the errors. Create MSN or Google Talk account and it should connect correctly.

ps, if you use KDE, kopete is good substitute for gaim. It works fine with MSN/gtalk, while gaim has a more extensive support for plugins, like tencent QQ.

Reference: http://www.ambience.sk/gaim-compile-ssl-linux-msn-google-talk

About Me

I am a senior developer and a team leader with 3 years development experience in Suzhou, China, focus on mobile web search, linux, Java and machine learning in NLP (natural language processing). My goal is to improve people's life with computer technology.