Wednesday, 21 December 2011

Web scraping

a computer software technique of extracting information from websites.

HtmlUnit is a headless web browser written in Java.
Selenium is a portable software testing framework for web applications.
JWebUnit is a Java-based testing framework for web applications.

JWebUnit and HtmlUnit both stub the browser, whereas Selenium runs inside the browser.

CAPTCHA

"Completely Automated Public Turing test to tell Computers and Humans Apart"
In other words, a computer administers a test to determine if the subject is or is not human.

Saturday, 3 September 2011

如何运行Wicket示范程序?

安装JDK1.6, NetBeans6.9.1, GlassFish3.1.1, Maven2.2.1 (set it as the External Maven Home in NetBeans)

Wicket in Action
================
下载http://wicketinaction.googlecode.com/files/wicket-in-action-0.9-source.zip

解压wicket-in-action-0.9-source.zip (注意:路径中不得有空格)

在NetBeans中,打开该项目, 并为其选择GlassFish3服务器

'Clean and Build' (Maven 将下载有关的库并存放在\.m2\repository下)

如果报告jta-1.0.1B.jar缺失,可从http://download.java.net/maven/2/javax/transaction/jta/1.0.1B/下载后,在项目库里选择'Manual install artifact',将其安装在本地库里后,重新Build

运行

Enjoying Web Development with Wicket
====================================
下载http://agileskills2.org/EWDW/source.zip

解压source.zip (注意:路径中不得有空格)

在NetBeans中,逐个打开项目, 并为其选择GlassFish3服务器,同时在其pom.xml文件中<build>块内,添加如下内容:


                <sourceDirectory>src/main/java</sourceDirectory>
                <resources>
                        <resource>
                                <filtering>false</filtering>
                                <directory>src/main/java</directory>
                                <includes>
                                        <include>**</include>
                                </includes>
                                <excludes>
                                        <exclude>**/*.java</exclude>
                                </excludes>
                        </resource>
                </resources>


'Clean and Build' (Maven 将下载有关的库并存放在\.m2\repository下)

运行

Monday, 15 August 2011

Friday, 8 July 2011

How to read and write Word/Excel 2007 files from C# programs?

(1) Add following references to your VS2008 project:
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;

full spec of above packages can be found at:
Microsoft.Office.Interop.Word Namespace
Microsoft.Office.Interop.Excel Namespace

Alternatively, you can use the 'object browser' from VS2008 or F1 key online help

(2) create following object in your C# programs and work on them:
object oMissing = System.Reflection.Missing.Value;
Excel.Application oXL = new Excel.Application();
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks._Open("my_workbook.xlsx", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing));
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Sheets["my_sheet"];
Excel.Range oRng = oSheet.UsedRange;

Word._Application oWord = new Word.Application();
Word._Document oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4;
oDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;
oDoc.PageSetup.LeftMargin = oWord.MillimetersToPoints(15F);
oDoc.PageSetup.RightMargin = oWord.MillimetersToPoints(15F);
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Word.Table oTable = oDoc.Tables.Add(wrdRng, 1, num_of_cols, ref oMissing, ref oMissing);

(3) clean the objects afterward:
object oDoNotSave = Word.WdSaveOptions.wdDoNotSaveChanges;
oDoc.Close(ref oDoNotSave, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
oWB.Close(oMissing, oMissing, oMissing);
oXL.Quit();

Thursday, 2 June 2011

如何开发JRuby+MySQL+Rails 3程序?

安装JDK 1.6
--------------------------
下载jdk-6u25-linux-x64.bin
chmod 700 jdk-6u25-linux-x64.bin
./jdk-6u25-linux-x64.bin

安装JRuby
--------------------------
下载jruby-bin-1.6.2.tar.gz
tar xvfz jruby-bin-1.6.2.tar.gz

安装GlassFish
-------------------------
下载glassfish-3.1.1-ml.zip
unzip glassfish-3.1.1-ml.zip

在.bash_profile中添加设置如下:
--------------------------
JAVA_HOME=$HOME/jdk1.6.0_25
JRUBY_HOME=$HOME/jruby-1.6.2
GLASSFISH_HOME=$HOME/glassfish3
PATH=$JAVA_HOME/bin:$JRUBY_HOME/bin:$GLASSFISH_HOME/bin:$PATH:$HOME/bin
export PATH JAVA_HOME JRUBY_HOME

重新登录

安装rails, jdbcmysql, glassfish gem, warbler
--------------------------
gem install rails activerecord-jdbcmysql-adapter glassfish warbler

创建MySQL用户
--------------------------
mysql -u root -p
mysql> create user duke@localhost identified by 'glassfish';
mysql> grant all on hello_development.* to duke@localhost;
mysql> grant all on hello_production.* to duke@localhost;
mysql> flush privileges;

创建hello程序
--------------------------
rails new hello -m http://jruby.org/rails3.rb -d mysql
cd hello
修改 config/database.yml中的MySQL用户名及口令


创建development数据库
-------------------------
rake db:create
rake db:migrate

创建production数据库
-------------------------
rake db:create RAILS_ENV='production'
rake db:migrate RAILS_ENV='production'

启动WEBrick (使用development数据库)
-------------------------
rails s
检查http://localhost:3000/是否正常

启动Glassfish gem(使用production数据库)
-------------------------
确认在/etc/hosts中,127.0.0.1映射到你的机器名(用hostname命令查看)
在 hello/Gemfile中添加gem 'glassfish'
(it is ok with development database)
glassfish hello
(there is a Routing Error: No route matches "/" with production database)
glassfish hello -e production

启动GlassFish(使用development数据库)
-------------------------
asadmin create-domain --portbase 2000 --domaindir . mydomain
asadmin start-domain --domaindir . mydomain

cd hello
warble
将hello.war放置到Glassfish上

Friday, 13 May 2011

如何测试FTPS?

启动RIP Linux

联网:dhcpup -u

配置:在/etc/lftp.conf里加上

set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate no

测试:
lftp -u '<username>,<password>' -d <server_ip>
ls
put file1
get file2
quit

Tuesday, 3 May 2011

如何用Slax提取Windows虚拟机里的文件?

(1) 用Slax光盘"Slax Copy To RAM"模式启动Windows虚拟机

(2)从光驱中移去Slax光盘

(3)为虚拟机安装VBoxAdditions


(4)为虚拟机添加共享文件夹q5

(5)连接共享文件夹
mkdir /mnt/q5
mount -t vboxsf q5 /mnt/q5

(6)拷贝所需文件至/mnt/q5
注:硬盘分区接点一般为/mnt/hda1,/mnt/hda2等等

Monday, 28 March 2011

Friday, 18 February 2011

如何克隆VirtualBox虚拟机?

(假定使用VirtualBox4.0.2)

1 在虚拟机硬盘所在目录下,运行如下命令将A盘复制到B盘:
...\.VirtualBox\HardDisks>vboxmanage clonehd A.vdi B.vdi

2 创建虚拟机B,并让其使用B盘。

Monday, 7 February 2011

Linux常用命令

测试网络的连通性:
[root@localhost ~]# ping -c 3 a.b.c.d

检查网络接口状态:
[root@localhost ~]# ifconfig -a

关闭网络接口eth0:
[root@localhost ~]# ifconfig eth0 down

打开网络接口eth0:
[root@localhost ~]# ifconfig eth0 up

为网络接口eth0设置网址:
[root@localhost ~]# ifconfig eth0 a.b.c.d netmask 255.255.255.0

查看内核路由表的配置:
[root@localhost ~]# route

添加默认网关:
[root@localhost ~]# route add default gw a.b.c.d

显示数据包所经过的路由:
[root@localhost ~]# traceroute a.b.c.d

显示网络端口状态:
[root@localhost ~]# netstat -penal

Monday, 31 January 2011

如何在VirtualBox中设置虚拟网络环境?

1 创建两个局域网(internal network)


局域网A

vboxmanage dhcpserver add --netname icc_net --ip 136.1.206.0 --netmask 255.255.255.0 --lowerip 136.1.206.1 --upperip 136.1.206.255 --enable


局域网B

vboxmanage dhcpserver add --netname ncc_net --ip 121.157.1.0 --netmask 255.255.255.0 --lowerip 121.157.1.1 --upperip 121.157.1.255 --enable

2 配置局域网B上机器(RHEL5)的网卡

在/etc/sysconfig/network-scripts/ifcfg-eth0中,添加如下配置:
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=121.157.1.147
NETWORK=121.157.1.0
USERCTL=no

在/etc/sysconfig/network中,添加如下配置:
GATEWAY=121.157.1.141

重新启动网卡:
service network restart

3 配置路由器(RHEL5)的网卡

在/etc/sysconfig/network-scripts/ifcfg-eth0中,添加如下配置:
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=121.157.1.141
NETWORK=121.157.1.0
USERCTL=no

在/etc/sysconfig/network-scripts/ifcfg-eth1中,添加如下配置:
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=136.1.206.121
NETWORK=136.1.206.0
USERCTL=no

重新启动网卡:
service network restart

在/etc/sysctl.conf中,设置:
net.ipv4.ip_forward =1

sysctl -p

4 配置局域网A上机器(Win7)的网卡
IP=136.1.206.129
NETMASK=255.255.255.0
GATEWAY=136.1.206.121

注意:路由器上的防火墙对A,B网间的通讯的影响。

Saturday, 8 January 2011

如何连接Ingres服务器?

Ingres与其他数据库不同,用于连接数据库的用户名必须是操作系统级的用户名。而且,操作系统级的用户名必须先生成。