mercredi 7 décembre 2011

mardi 6 décembre 2011

Use script to start/stop/restart a java program

like start tomcat, write a script to start/stop/restart a java program:

script.sh
use: sh script.sh start

#!/bin/sh 
 
SERVER=/Users/cwang/desktop/test 
cd $SERVER 
 
case "$1" in 
 
  start) 
    nohup java -Xmx128m HelloWorld > $SERVER/server.log 2>&1 & 
    echo $! > $SERVER/server.pid 
    ;; 
 
  stop) 
    kill `cat $SERVER/server.pid` 
    rm -rf $SERVER/server.pid 
    ;; 
 
  restart) 
    $0 stop 
    sleep 1 
    $0 start 
    ;; 
 
  *) 
    echo "Usage: run.sh {start|stop|restart}" 
    ;; 
 
esac 
 
exit 0



Original: http://www.iteye.com/problems/14572

lundi 5 décembre 2011

mysql 如何判断一个表是否存在

判断一个表是否存在:
SHOW   TABLES   LIKE   'tablename';
执行这样的sql ,如果返回记录为0则不存在;


创建一个新的表
create table tablename(column1 varchar(10),column2 int)

mercredi 23 novembre 2011

【转】JSP 同一个form,不同的按钮提交到不同的jsp 页面进行处理


问题:在一个JSP页面中需要多个提交按钮,每个按钮点击后需要把同一个form提交到不同的页面进行处理
解决:用JS。
<html>
<head>
<title>一个表单、多个提交按钮、提交到多个不同页面</title>
</head>
<script>
function sm1(){
   document.getElementByIdx("form1").action="1.jsp";
   document.getElementByIdx("form1").submit();
}
function sm2(){
   document.getElementByIdx("form1").action="2.jsp";
   document.getElementByIdx("form1").submit();
}
</script>
<body>
<form action="" method="post" id="form1">
 <input name="mytext" type="text" id="mytext" />
 <input name="bt1" type="button" id="bt1" value="提交到1.jsp" onclick="sm1()" />
 <input name="bt2" type="button" id="bt2" value="提交到2.jsp" onclick="sm2()" />
</form>
</body>
</html>

原文地址:http://blog.sina.com.cn/s/blog_60328aa70100di5a.html

dimanche 16 octobre 2011

pdf 记录上次阅读信息


adobe reader :
编辑--------首选项--------文档----------“文档重新打开时恢复上次设置”选项前打勾
每次打开文档都是上次最后阅读的地方!

lundi 19 septembre 2011

两个电脑通过网线相互连接,共享网络


最正确,最完整做法:

将两台机器其中的一台机器作为主机(以后称为A)装上网卡两块,另一台用作客户机(称为B)。将A上其中一块网卡与B的网卡相连,A上另外一块网卡与ADSL modem相连,好了硬件的安装就完成了,下面开始进行软件的配置。
先设置主机A:
点击[开始]--[控制面板]--[网络连接](或者直接在桌面上右键点击网上邻居,在弹出菜单中选择属性即可),右击代表连接ADSL modem的网络连接(网卡1.),选择属性。在常规选项卡中找到tcp/ip协议并双击。将IP设为自动获取,DNS可以自动,也可以设置为当地网通的。相同的操作方法设置连接客户机B的网卡2.,IP应该取192.168.0.1,不要设置网关(有了网关,就变成网桥),主DNS取当地网通的,辅DNS取192.168.0.1。
再来设置客户机B:
客户机IP取192.168.0.2,网关192.168.0.1,DNS与A的网卡2.相同。
    基本配置完成后,现在还不具备B机访问INTERNET的功能,不过两台机器已经可以互相访问了(彼此应该在网上邻居里面找到)。下面在A的网络连接中选择ADSL的拨号连接,右键选择属性,在高级选项卡中可以看到Inertnet连接共享的选项,在“允许其它网络用户通过此计算机的internet连接来连接”前面挑勾,下方的家庭网络连接选择网卡2.的连接,再下面的两个选项大家就根据自己的需要设置吧。设定好后点击确定,等待一会系统此时会进行共享设置。当设置完成后您的两台电脑都应改可以访问internet了。

补充:继上次成功网卡直连,让B电脑上网,发布文库文档之后,先后用了两次B电脑,一次失败,一次成功。说明除了前文档所说之外,还有一些注意事项。
失败这次,因为A电脑在使用中,只确定和《网卡直连……》中确定一致。A电脑首先拨号的,断网,B电脑打开网页,A电脑不自动拨号。
成功这次,首先在A电脑中取消了ADSL连接高级选项中的共享,关闭再打开,然后重新选取共享,并在其下的设置中勾选全部协议。另外,在B电脑中浏览器-工具-ie选项-连接中,将ADSL设置为“从不拨号连接”。然后我是打开B电脑,打开网页,然后A电脑自动拨号,然后两部电脑都能正常上网!

mercredi 3 août 2011

install pgp on Mac OS X

1: Begin by downloading and verifying the GnuPG archives from
<http://www.gnupg.org/>.  Here's what to type:

curl -O ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-1.4.11.tar.gz
curl -O ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-1.4.11.tar.gz.sig

2: To verify:

gpg --verify gnupg-1.4.11.tar.gz.sig

or, if you don't have an older copy of GnuPG or another OpenPGP program
(NEVER verify the version of GnuPG you download with itself), use the SHA-1
checksums found on the GnuPG Web site and compare with the checksum from:

openssl sha1 gnupg-1.4.11.tar.gz

3: Next, untar GnuPG:

tar -xzf gnupg-1.4.11.tar.gz

And move into the GnuPG directory:

cd gnupg-1.4.11

4: Now you need to set up GnuPG to build on your system.  You do this by
running configure:

./configure

5: Once you have everything configured, it's time to compile GnuPG by running:

make

6: If all tests pass, the only thing left to do is type:

sudo make install

Reference: http://macgpg.sourceforge.net/docs/howto-build-gpg-osx.txt.asc

[FW] Installing GLPK on a Mac


So you want copy-paste instructions to install GLPK on your Macbook? Here are the steps:


  1. Download the latest version of GLPK fromhttp://www.gnu.org/software/glpk/#downloading
  2. Optional: Follow the instructions to verify the download (you might need to get GNU Privacy Guard or gpg for this. You can get it at http://gnupg.org);
    The GLPK distribution tarball can be found on http://ftp.gnu.org/gnu/glpk/ [via http] and ftp://ftp.gnu.org/gnu/glpk/ [via FTP]. It can also be found on one of our FTP mirrors; please use a mirror if possible.
    To make sure that the GLPK distribution tarball you have downloaded is intact you need to download the corresponding .sig file and run a command like this:
    gpg --verify glpk-4.32.tar.gz.sig

    If that command fails because you do not have the required public key, run the following command to import it:
    gpg --keyserver keys.gnupg.net --recv-keys 5981E818

    and then re-run the previous command.
    (if gpg is not installed, refer to: http://hichenwang.blogspot.com/2011/08/install-pgp-on-mac-os-x.html)
  3. Say it’s downloaded to your “Downloads” directory, go there and execute the following commands (using the terminal)
    1.cd ~/Downloads
    2.tar -xzf glpk-4.43.tar.gz
    3../configure --prefix=/usr/local # see note [1]
    4.make
    5.sudo make install
  4. At this point, you should have GLPK installed. Verify it:
    1.which glpsol
    2./usr/local/bin/glpsol
  5. … and try help:
    1.glpsol --help
Now that you are all set-up, read up this excellent introduction using GLPK:http://www.ibm.com/developerworks/linux/library/l-glpk1
Notes:
[1]: HiveLogic article on why using /usr/local is better
[2] If you want MySQL support (or something “extra”) check out the INSTALL file in the package

mardi 26 juillet 2011

Restart Apache in Mac OS X

To restart the Apache webserver service you can run the following command in a Mac OS X Terminal window:

sudo /usr/sbin/apachectl restart

if you have the following error:

/usr/sbin/apachectl: line 73: ulimit: open files: cannot modify limit: Invalid argument


follow the instructions:


Luckily the world is a big place and someone had already fixed the problem.
Just open up /usr/sbin/apachectl and change (around line 64):

ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

to

ULIMIT_MAX_FILES=""


ref: http://www.justinball.com/2010/11/23/apachectl-stopped-working-after-mac-osx-10-6-5/

jeudi 21 juillet 2011

install wget in mac os x

wget is great command line *nix program for grabbing things from the web, but it doesn’t ship with macs. It’s also not a part of the developer tools package. Here’s the steps I used to build and install wget on my mac.

Grab the wget source code from http://ftp.gnu.org/pub/gnu/wget/wget-1.9.1.tar.gz (or get the latest here) . Open a terminal window and follow along:

tar xzf wget-1.9.1.tar.gz
cd wget-1.9.1
./configure
make
sudo make install
The wget binary should now be in your /usr/local/bin folder. Let’s also put /usr/local/bin in the shell path so we can type wget from the command line rather than the tedious /usr/local/bin/wget when we want to run the program. This is accomplished by editing ~/.bash_profile to add the following line:

PATH=$PATH:/usr/local/bin; export PATH

To get the shell to re-read this file again, type source ~/.bash_profile. Now whenever you start the terminal, /usr/local/bin will be in the path.

The other part of installing wget that needs a tweak is wget’s manual page isn’t found when running man wget from the terminal. To resolve this we need to edit the man configuration file.
 
sudo nano /usr/share/misc/man.conf

Scroll down a bit and below all the other lines beginning with MANPATH, add:
MANPATH /usr/local/man

64 bits or 32 bits?

1: how to determine the JVM that you are running is 64-bit or 32-bit?

    open the terminal and enter the following command:

    - java -d64 -version
 
    if it is a 64-bit system, you will get the following result:

        chen-macbook:~ cwang$ java -d64 -version
    Java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-9M3326)
    Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)


    otherwise, you will get the following result:

        chen@chen-VirtualBox:~$ java -d64 -version
    Running a 64-bit JVM is not supported on this platform.


2: how to determine your system is 64-bit or 32-bit?

    MAC OS:
        open the terminal and enter the command uname -p,
        if you get i386, that means your system is 32-bit, x86-64 otherwise.
    
 
Finished

  



 

mardi 5 juillet 2011

Emacs 学习笔记

C: ctrl;
M: alt (or apple key);
------------------


------------------
移动光标:

C-l: 光标居中;
C-v (PgDn): 下一页 ;

M-v (PgUp): 上一页;

C-p: 上一行;
C-n: 下一行;
C-b: 左移一个字符;
C-f: 右移一个字符;
M-f: 右移一个单词;
M-b: 左移一个单词;

C-a: 一行的最前端;
C-e: 一行的最后端;
M-a: 一句话的最前端;
M-e: 一句话的最后端;

M-<: 文章的头;
M->: 文章的尾;

C-u N C-f: 重复执行一个命令N次;
也可以用于输入:C-u 8 *: 输入8个*;
-------------------
文字编辑:

<Delback>: 删除光标之前的一个字符;(effacer)
C-d: 删除光标之后的一个字符;(effacer)

M-<Delback>: 删除光标之前的一个单词;(supprimer)
M-d: 删除光标之后的一个单词;(supprimer)
C-k: 删除到本行结束;(supprimer)
M-k: 删除到本句结束;(supprimer)
C-@, C-w: 删除一段文字分别标记始末;(supprimer)

effacer 和 supprimer 的区别:
supprimer 可以复原,儿effacer 不可以;
C-y: 复原命令,把最后删除的文本重新插入;(如果连续做了很多次C-k,则所有被删除的文字都要被重新插入)
通过这个方法,可以copy,用C-@,C-w标记选中的部分,然后supprimer;然后C-y 还原;再在需要的地方C-y 粘贴就行了;
C-y 只能粘贴最近一次删除的,而M-y 可以拿回所有删除的文字;
M-y: 一次——最近一次删除的;两次——之前两次删除的;以此类推;

C-x u: 撤销,undo;不过这条命令只undo 一条命令;需要undo 多个modification,使用多次命令;
同样,可以使用C-_,相同的功能但是更容易操作;(注意,使用_需要按住shift);

向前查找:C-s;(查找之后的内容)C-s,查找下一个,期间可以修改关键字,按回车,结束本次查找;
向后查找:C-r;(查找之前的内容)

-------------------
文件操作:

C-x C-f:打开一个文件;
C-x C-s:保存;
C-x C-c: 关闭当前窗口;

Tempons:
Emacs 把每个文件都保存在一个叫做“tempon” 的对象里;
C-x C-b:list of tempons;
然后想编辑哪个文件,就用命令:C-x b tempon_name 就行了;
至于每个tempon 名,在list of tempons 中看就行了;
(当然,也可以使用命令C-x C-f 打开一个文件进行编辑)
-------------------
C-g: 停止当前执行的命令;
退出一个recursive 的命令,连续按三下<ESC>;可以退出C-g 不能退出的情况;

C-x s: 保存所有可能保存的tempons,每个以此询问;

M-x repl s<Tab> X <return> Y <return>: 把光标后面的X 全部换成Y;
M-x recover file<enter>: 恢复自动保存的文件;(后面有confirmation)
-------------------
窗口:

C-x 1: 当有多个窗口的时候,只保留光标所在的窗口;
C-x 2: 分成两个窗口,同一个文件;
C-x o:切换光标到另一个窗口;

-------------------
管理操作:

M-x text mode<enter>: 进入文本编辑模式;

-------------------
帮助:

C-h C Command: 查询有关Command 的信息(C: 帮助类型);
如果不知道C 应该写什么,输入?,有一个list 将说明每个字符的不同含义;
i.e.: C-h c C-p
显示:C-p runs the command previous -line;

C-x 1: 返回一个窗口的状态;
C-u 8 *: 插入 ********;
<Delback>:    删除光标之前的字符;
C-d:   删除光标之后的字符;
M-<Delback>:  删除光标之前的单词;
M-d:删除光标之后的单词;
C-k:删除光标到本行末;
M-k:删除光标到本句末;
C-@ 或者C-SPC标记一端,C-w标记另一端,两端之间的文字会被删掉;