Tuesday, August 12, 2008

javascript and xml

http://www.cnblogs.com/javaca88/archive/2008/05/04/511876.html



Import XML Document

Import XML Document
http://www.quirksmode.org/dom/importxml.html

Working with XML and Javascript
http://www.peachpit.com/articles/article.aspx?p=29307&seqNum=4

On this page I import an XML document and then read out the data and put them in a table on the page.

I think importing XML documents will become more and more important in the future. You can manage the XML document as a kind of database, while the HTML document contains all information about the displaying of the data.

Anyway, try it first by clicking the link and loading some crucial information about the Roman emperors of the Julian-Claudian dynasty. You can also view the XML document separately.

First I import the document emperors.xml, then I enter the XML document through the W3C DOM and extract the data I need, while building a table to display the data.

The script

function importXML()

{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) createTable()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("emperors.xml");
}

function createTable()
{
var x = xmlDoc.getElementsByTagName('emperor');
var newEl = document.createElement('TABLE');
newEl.setAttribute('cellPadding',5);
var tmp = document.createElement('TBODY');
newEl.appendChild(tmp);
var row = document.createElement('TR');
for (j=0;j

Importing the XML

First of all I import the XML document and make it accessible through the object xmlDoc. When the document has finished loading, I want the script createTable() that construes the table to be executed immediately. Of course, the coding for all this is browser specific.

Clicking the link activates the function importXML.

function importXML()

{

Mozilla

Netscape imports an XML document through the method document.implementation.createDocument(). First check if document.implementation is supported, then check if document.implementation.createDocument() is supported. Explorer 5 on Mac also supports document.implementation, but not the createDocument method, so it shouldn't execute this script.

	if (document.implementation && document.implementation.createDocument)

{

Then create the document and give it an onLoad event handler: as soon as the document has been loaded the script createTable() is executed, creating the table:

		xmlDoc = document.implementation.createDocument("", "", null);

xmlDoc.onload = init;
}

Explorer

Explorer on Windows doesn't support document.implementation . Instead, you must create an Active X Object that will contain the XML document. So we see if the browser can create ActiveXObjects:

	else if (window.ActiveXObject)

{

If it does, we can proceed by creating the object

		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

Unfortunately there's no onLoad event for this object. To see if it's ready we should use the MS proprietary ReadyStateChange event. I don't quite understand all this myself, but it works. When the onReadyStateChange event handler fires, the readyState has a value between 1 and 4. 4 means that all data has been received (= onLoad). So if it's 4, start creating the table.

		xmlDoc.onreadystatechange = function () {

if (xmlDoc.readyState == 4) createTable()
};
}

Other browsers

If the browser supports neither way, give an alert and end everything:

	else

{
alert('Your browser can\'t handle this script');
return;
}

Load document

Finally, load the actual document. Surprisingly, the command for this is the same in both browsers:

	xmlDoc.load("emperors.xml");

}

Now we wait for the XML document to be loaded completely, then the function createTable() is started up.

Strangely, Mozilla sometimes only accepts a URL to the XML file that is relative to the page with the script, which in practice means that you can only access local XML files. Only the Linux version does accept absolute paths in all cases.

You might be able to solve the problem by putting the page containing the script on a real web server instead of a local host. However, this does not help in all cases.

Creating output

This function is entirely specific for the XML document I created. Each XML document is different, each way of displaying the content is different, so the function I wrote is only an example.

The XML document

The XML document consists of nodes named , which all contain the same children. As an example, this is the structure of the first node:

                                  

|
------------------------------------------
| | |

| | |
Augustus 27BC-14AD Peaceful

In the script below I assume that every emperor has this structure. If one hasn't, it could lead to huge problems, but this way I keep the script simple.

Creating the table

Function createTable() starts by creating an array of all the tags in the XML document. For each of these tags I want to create a TR containing several TD's with the data.

function createTable()

{
var x = xmlDoc.getElementsByTagName('emperor');

Then we create a new TABLE with CELLPADDING=5. Note the special spelling cellPadding, Explorer requires this and it doesn't hurt Netscape.

	var newEl = document.createElement('TABLE');

newEl.setAttribute('cellPadding',5);

Explorer requires that we also create a TBODY and append it to the table. Don't ask me why, I think TBODY is a completely useless tag, but without it the example doesn't work in Explorer.

	var tmp = document.createElement('TBODY');

newEl.appendChild(tmp);

First of all, a row with TH's for the headers. Create a TR

	var row = document.createElement('TR');

then go through the childNodes of the first emperor.

	for (j=0;j

A problem here: the XML document looks like this:

	


which means that Netscape considers the empty text node between emperor and name as the first child of emperor. Since these nodes are only a nuisance, we have to check if the nodeType of the childNode is 1 (= it's a tag). If it isn't, continue with the next child:

		if (x[0].childNodes[j].nodeType != 1) continue;

Create a container element (TH):

		var container = document.createElement('TH');

then read out the name of the childNode (ie. name, rule and death). I want these names to be printed inside the TH. So first I append the name to the TH, then I append the container to the TR

		var theData = document.createTextNode(x[0].childNodes[j].nodeName);

container.appendChild(theData);
row.appendChild(container);
}

Finally, append the row to the TBODY tag

	tmp.appendChild(row);

Then we go through all elements emperor and create a TR for each one

	for (i=0;i

Go through the childNodes of each emperor, check if it's a node (tag) and create a TD to hold the data

		for (j=0;j

Then extract the actual data. Remember that the text inside a tag is the nodeValue of the first childNode of that tag

			var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);

Append the text to the TD and the TD to the TR

			container.appendChild(theData);

row.appendChild(container);
}

and when you've finished going through the emperor, append the TR to the TBODY

		tmp.appendChild(row);

}

Finally, when you've gone through each emperor, append the TABLE to the special P with ID="writeroot" I created:

	document.getElementById('writeroot').appendChild(newEl);

}

and a table has been magically created.

Tuesday, August 5, 2008

example code!

http://www.example-code.com/

I poor developer likes example code! Yes, I like them.

check regular expression

Very good, very useful ar~

http://regexlib.com/RETester.aspx

Sunday, July 20, 2008

Google Map API

1. documentation

http://code.google.com/intl/zh-CN/apis/maps/documentation/index.html

2. Some tutorial

http://dev.leck.com/gsupport/

http://www.developer.com/lang/jscript/article.php/3615681

Thursday, July 17, 2008

Web Development Resources

Good Joomla tutorials(****)
http://www.phpeveryday.com/index.php
fff
Joomla documentation (****)
http://docs.joomla.org/Main_Page

CSS resource
http://www.cssjuice.com/

1. CSS Menu and navigation bar (*****)

http://css.maxdesign.com.au/index.htm

2. Write header background with three images (left, middle, right)

http://www.pixy.cz/blogg/clanky/rubberheaders/

3. Create rounded corners with Joomla

http://docs.joomla.org/Creating_rounded_corners

4. 25 rounded corners with CSS (****)

http://www.cssjuice.com/25-rounded-corners-techniques-with-css/

5. javascript

http://mootools.net/

Wednesday, July 16, 2008

微软(美国)产品开发组的团队角色

UI设计人员是对产品的使用界面进行设计和订正的人员。 Usability Engineer是检验UI设计的合理性的人员

在很多团队,真正的界面设计都是由PM做完了Spec,才找UI设计人员来征求意见。像我们团队,我的设计规范书写完后,我才找UI设计人员来,他们所做的也就不过是对我的设计作小改动,如那些英语词句用得不妥,哪里的按钮该改变大小,等等。我所知道的其它视窗操作系统的团队,也是差不多。这主要是因为我们能自己进行界面设计 - 视窗操作系统部门的PM是微软PM中最厉害的(至少我们这样看:-) ) 。可是,这是不太正确的方法,因为如果你有很强的PM, 你可用这种方法,要是你的PM的设计能力不强,这样的流程就要出问题。你的项目的成功不应该寄托在几个强有力的PM上,而是要用完善的流程来保证。好的流程应该是,在产品开发的早期,在做设计时,PM就应该和UI设计人员一起来考虑产品设计的合理性

这个问题在微软内部我们自己也有很大的争论。 UI设计人员就常常抱怨,在产品开发的早期,他们常常不被看重,被抛在一边。UI设计的领导人甚至在全公司的培训大会上讲,我们的这个文化有问题,领导对UI设计人员在产品开发早期能起的作用不够重视。可是这个争论已有几年了,结果仍无改变。我想这主要还是跟我们这个行业的产品开发的特性有关系。因为软件开发是很技术性的,常常在早期的技术讨论中,UI设计人员对技术讨论说不出个所以然来(因为他们大多是学艺术设计的),渐渐地各开发团队对UI设计人员的作用就看轻了。在使用界面因素占很大比例的产品团队,像Office 和MSN,这种情况要好一些。

Usability Engineer 所做的事和UI设计人员不同。他们是将UI设计的模型版,找客户来进行实用和使用性能的检验调查和测试,并根据调查结果对UI设计提出进行修改的意见。也就是说,他们的工作是检验UI设计的合理性,有点像测试人员对程序进行检验的功能 。 可以说, Usability Engineer 和UI设计人员的关系像测试人员与开发编程人员的关系。

User Education team 是编写使用说明书的编辑人员。

从大方面的来说,微软的产品组是公司的几大部门之一,其他还有市场/销售部门,服务部门,运作部门,还有研究院什么的。

在产品组里,是按产品分成一个个的商业部门(Business Unit),一个商业部门负责一个主要的产品。其中的项目团队主要是按以下的结构组成:(缩进表示汇报Report关系)

Product Unit Manager - 产品组总经理
---+ Group Program Manager
---+ Program Manager Lead
------+ Program Manager 1
------+ Program Manager 2
------+ Program Manager n
---+ Dev Manager
------+ Dev Lead
------+ Dev 1
------+ Dev 2
------+ Dev n
---+ Test Manager
------+ Test Lead
------+ Test 1
------+ Test 2
------+ Test n
---+ User Education Team Manager
------+ UE 1
------+ UE 2
---+ Architect (整体设计,规划,基本上只有特别大的产品组才有,画那种积木图。顺别提及,Bill Gates 是Chief Software Architect)

除此以外,还有全公司合用的:
+ Usability Engineer
+ Designer (美工)
+ Accessiblity Engineer
......

对于一个Feature,通常每个角色有一个,比如按上例中,可能是

[ Test 1 + Dev 2 + UE 1 + Usability Enigneer ] 组成一个Feature team.

Feature Team 之间没有隶属关系。

:p 对于参加过DEVP203课程的学员:
其实我们在课上讲过的模型,有很多变化的可能性.以上是最基本的微软配置,比如过的部门就很小,20个人就要出一个产品,并不是所有的角色都有.

合理的开发团队组合应该是什么?

允许我抛砖引玉,先谈一下微软的经验:

项目经理团队:(Program Management Team
• 设计项目经理 (Feature Design PM):负责具体的产品设计,写Design Spec。PM 队伍中,80%的PM是做这个。
• 发行项目经理 (Release PM):负责整个项目的流程和进度管理,制定进度表等,协调整个团队的工作。大的PM 队伍中有一人专门做这个。这是整个项目的领头人。大型的项目的成功与否,常常靠得力的发行经理的领导。
• 协助项目经理(Supporting PM):负责其它产品发行需要照顾到的事情,如客户交流、和市场开发人员交流、负责beta program (初版试行)、等等。大的PM 队伍中少不了这样的人。20%的PM是做这个。

开发团队:(Development Team)
• 开发团队领导(Development Manager): 负责管理各个开发小组,并对开发编程的工作做总体的规划。
• 开发组长(Development Lead): 负责管理开发工程师,也参加对开发编程的工作做总体的规划。
• 开发工程师(Develop Engineer, or Developer):负责具体的编程开发。
• 构架师(Architect): 大的产品团队有一两个资深工程师专门做整体系统的设计规划。

测试团队:(Quality Assurance or Test Team)
• 测试团队领导(QA Manager): 负责管理测试小组
• 测试组长 (Test Lead): 负责管理测试工程师, 制定测试计划等
• 测试工程师(Tester or Test Engineer):负责具体的测试工作
• 测试开发工程师(Developer in Test, or STED): 负责测试工具的开发

产品可用性团队:(Usability Team)
• 产品可用性工程师 (Usability Engineer): 做使用性能的调查和测试,采访客户或将客户邀请来做调查
• 界面设计师(UI Designer): 负责具体的界面设计
• 产品设计师 (Product Designer): 负责产品的总体设计, 特别是硬件产品。
以上这个团队并不是所有的产品队伍都有。比较小的队伍就没有这些专人,有的时候向别的队伍借用,或雇佣临时工。

客户教育或文档团队:(User Education, or UE Team)
• 文档组长 (UE Lead):负责管理文档小组
• 文档编辑 (UE Editor):负责具体的文档编辑和撰写

以上只是一个大约的组合模式。不同的团队有各自的侧重点和变化。在很大程度上这些也受到具体的产品的影响。我想我在微软的产品部门的其他同事们会再做补充。 希望这些信息能对国内的软件开发公司能有参考价值。我们希望通过这样的交流,我们能为中国软件开发事业的进一步发展尽我们的一点微薄之力。

Monday, July 7, 2008

PHP - Stop including class files and use __autoload() instead

PHP added several magic methods in PHP5. __autoload(), however, isn’t one of them. But that doesn’t make it any less useful. In fact it’s one of the gems in PHP that I find to be relatively under used. It’s common for PHP applications to break out classes into their own files. This becomes cumbersome when working on large projects as you wind up with numerous include/require calls for any given page. There’s got to be a better way...

Consistency is your friend
I’m sure you name your class files consistently so you can probably skip this section. Apparently, since you’re reading this, you do not have any rhyme or reason for your class file names. It doesn’t really matter what it is as long as it’s consistent and predictable. For example, EpiCode contains a models directory which contains all of the PHP class files. The file names follow the pattern ClassName.php. I know that class A is defined in models/A.php.

What can __autoload() do for you?
Did you know that PHP will call __autoload() if you try to call a function which is not yet defined? You simply have to define it and let it know where to find the class file. Let’s use my example of placing all class definitions inside a models directory with the filename being the same as the class name. Your __autoload() function may look something like this.


function __autoload($className)
{
require_once "./models/{$className}.php";
}

// Instantiate class A without including it and __autoload() will do so on your behalf
$ClassA = new A();


Make your code less ugly
If you can’t spare an extra function call here or there then __autoload() may not be for you. Though I would begin to question your reasoning. The upside is that your code could become significantly cleaner and more maintainable. The upside of easy to read code often trumps everything else.

Wednesday, July 2, 2008

在Linux上安装JDK,Tomcat,Eclipse,Myeclipse,Subclipse

一、软件下载
  JDK 1.5(Linux RPM in self-extracting file 或 Linux self-extracting file)
www.sun.com
Tomcat 5.5(Core:tar.gz)
    http://tomcat.apache.org/download-55.cgi#5.5.25
Eclipse 3.2.1(eclipse-SDK-3.2.1-linux-gtk.tar.gz)
http://archive.eclipse.org/eclipse/downloads/drops/R-3.2.1-200609210945/index.php

二、安装JDK
  1、将下载的JDK解压到JDK安装目录,例:
     cd /usr/java/
     tar xIvf jdk-1.2.2-RC4-linux-i386-glibc-2.1.2.tar.bz
2、安装JDK
给所有用户添加bin文件的可执行的权限
#chmod +x jdk-1_5_0_02-linux-i586.rpm.bin
执行以下命令,生成文件 jdk-1_5_0_02-linux-i586.rpm
#./jdk-1_5_0_02-linux-i586.rpm.bin
执行以下命令,给所有用户添加rpm文件的可执行的权限
#chmod +x jdk-1_5_0_02-linux-i586.rpm
执行以下命令,安装程序
#rpm -ivh jdk-1_5_0_02-linux-i586.rpm
出现安装协议等,按接受即可。
  2、设置好JAVA_HOME环境变量,它的值为JDK安装目录,如编辑/etc/profile,增加下面几行:
     JAVA_HOME=/usr/java/jdk1.5_*
     export JAVA_HOME
  3、将JDK的bin目录追加到PATH环境变量中,如编辑/etc/profile,增加下面几行:
     PATH=/usr/local/jdk1.5_*/bin:$PATH
     export PATH
4、设置环境变量的另一种方法(要使JDK在所有的用户中使用)
在/etc/profile.d下增加java.sh文件,内容如下:
#set java environment
JAVA_HOME=/usr/java/jdk1.5.0_13
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
然后给所有用户添加可执行的权限,指令如下:
chmod 755 /etc/profile.d/java.sh
5 、检查JDK是否安装成功
#java -version如果看到JVM版本信息和安装版本对应,代表安装成功!
三、安装Tomcat
  1、将下载的Tomcat解压到Tomcat安装目录,例:
     cd /usr/java
     tar xzvf /software/tomcat/jakarta-tomcat.tar.gz
  2、设置好TOMCAT_HOME环境变量,它的值为Tomcat安装目录,如编辑/etc/profile,增加下面几行:
     TOMCAT_HOME=/usr/local/jakarta-tomcat
     export TOMCAT_HOME
  3、Tomcat安装目录的bin子目录下的startup.sh用于启动服务,shutdown.sh为停止服务,服务的缺省端口为8080
  4、退出并重新登陆,启动服务,然后在浏览器上输入http://localhost:8080/来检查是否已经安装成功,例:
     cd $TOMCAT_HOME/bin
     ./startup.sh
     lynx http://localhost:8080/
5、设置环境变量的另一种方法(要使Tomcat在所有的用户中使用)
在/etc/profile.d下增加tomcat.sh文件,内容如下:
#set tomcat environment
TOMCAT_HOME=/usr/jakarta-tomcat
      export TOMCAT_HOME
然后给所有用户添加可执行的权限,指令如下:
chmod 755 /etc/profile.d/tomcat.sh
6、 测试环境变量
#echo $JAVA_HOME
...................

四、安装Eclipse
1、直接双击解压缩,就可以正常使用.

五、安装Myeclipse
1、shell下执行EnterpriseWorkbenchInstaller_*.*GA_E3.2.bin文件:
# ./EnterpriseWorkbenchInstaller_*.*GA_E3.2.bin
2 、出现Myeclipse安装画面,会先让你选择eclipse的安装目录,我这里就是/usr/java/eclipse,然后再选择安装目录, 输入/usr/java/myeclipse,然后next就可以了.

六、安装Subclipse

安装Subclipse之前,linux必须先安装javahl 库,否则 Subclipse不可用。

1、打开linux的添加或删除软件,选择搜索选项,输入javahl进行搜索。

2、选择搜索到的库,点击应用进行安装。

3、打开Eclipse,选择Help->update softwares->Find and Install...,弹出窗口.

4、在弹出窗口建立一个Subclipse站点,url 为 http://subclipse.tigris.org/update, 进行安装.

七、在linux之间传输文件

常用工具:sanba,ssh,wget,ftp等等. 现假设Eclipse下载到linux的/software目录下,需要把Eclipse传输到IP为192.168.0.3的机器上的home目录下, 步骤如下:

1、用SSH登陆

ssh -l root 192.168.0.3

2、打开本地linux终端,传输Eclipse文件

scp /software/Eclipse root@192.168.0.3:/home

3、从远程机器下载到本地

scp root@192.168.0.3:/home/Eclipse /software/Eclipse

4、SFTP传输命令

sftp root@192.168.0.3:/home/Eclipse /software/Eclipse

jdk5.0 tomcat5.0配置全攻略

最近刚转到java学习,没想到环境配置整整搞了四天,汗!相信有不少像我这样的java初学者对环境的配置有所疑问,在网上找到的东西根本不完整,今天希望用这篇文章能够帮助java初学者走好第一步!

1.首先JDK(Java Development Kit)不用说了吧,既然你要学习java相信你已经知道它是干什么的了,在sun公司的网站就可以免费获得!

下载好JDK后,我们一步步的将他安装到我们的本地系统,比如安装到:C:\Program Files\Java目录下,然后就是配置环境变量了,我这里只介绍Windows平台上的配置!步骤如下:

我的电脑---属性---高级---环境变量---[系统变量]---编辑->变量名[JAVA_HOME]---变量值[C:\Program Files\Java\jdk1.5.0_12]---确定;

编辑->变量名[CLASSPATH]---变量值[.;%JAVA_HOME%\lib\dt.jar,%JAVA_HOME%\lib\tools.jar]((前面的.号千万不要忘记,它代表当前目录))---确定;

找到系统变量中原有的[path]变量--编辑---在原有的值后加上---;%JAVA_HOME%\bin---确定;

好了JDK环境的配置已经大功告成了,接下来你就应该重新启动你的Computer了,因为系统变量在重启后才会生效。

现在该测试一下你的环境了!

用编辑工具在c:\下建立一个java程序:HelloWorld.java

public class HelloWorld

{ public static void main(String[ ] args)

{

System.out.println("HelloWorld!");

}

}

切记,程序名一定要与公有类的名字相同!保存文件后,--[开始]--运行---cmd---cd c:\(指向你保存文件的目录下)

java HelloWorld.java [回车]

javac HelloWorld [回车]

相信你已经看到输出为:HelloWorld!了,到此JDK环境我们已经配置起来了!

2.tomcat服务器的配置

tomcat也是一款免费软件,你可以到Apache网站上免费获取!

下载好tomcat后,安装,比如你安装的目录是D:\tomcat5.0 那么你还需要配置一下环境变量:电脑---属性---高级---环境变量---[系统变量]---编辑->变量名[CATALINA_BASE]--变量值[D:\tomcat5.0]确定;

电脑---属性---高级---环境变量---[系统变量]---编辑->变量名[CATALINA_HOME]---变量值[D:\tomcat5.0]---确定;

ok,tomcat的环境变量也好了(好象最新的tomcat版本不需要配置这个也可以)

打开浏览器----输入:http://localhost:8080/如果出现tomcat的欢迎页面,那么你的tomcat就已经安装成功了!

接下来,你还想做什么呢?我想你一定得知道它怎么去运行JSP\Servlet\JavaBean吧!

(1)jsp

在你的tomcat安装目录下,你可以找到D:\Tomcat 5.0\webapps\ROOT目录,那么这个目录就是系统默认的跟目录了,你先编写一个简单的JSP页面,放到这个目录下。jsp-one.jsp如下:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>




JSP注释


<% //利用For循环控制字体由大到小
for(int i=1;i<6;i++)><%=i%>>你好JSP<%=i%>>
<%} //利用for循环控制字体由小到大 for(int i=5;i>0;i--)
{
%><%=i%>>你好JSP<%=i%>>
<%} %>


保存后在浏览器中输入:http://localhost:8080/jsp-one.jsp你会看到什么呢?

如果你可以看到由大到小和由小到大的字体,那么你的jsp环境也就没问题了!

如果不是,请检查你的程序是不是在编码上有错误,比如你拷贝了上面的程序直接在[记事本]中保存,很有可能多出一些码!

XAMPP for Windows 简易教程

下载:
XAMPP Windows 1.5.4a
XAMPP Lite 1.5.4a (精简版)

有三种选择可供您下载 XAMPP 的 Windows 版:
安装包
简单且安全:XAMPP 的便捷安装程序。
ZIP 压缩包
给喜欢绿色软件的人:XAMPP 的普通 ZIP 压缩档案。
自解压 ZIP 包
便捷而高效:XAMPP 的超小自解压 7-ZIP 压缩档案。

安装:
方法 A:使用安装包进行安装
使用安装包来安装 XAMPP 是最简单的方法。

XAMPP win32 的安装向导

安装过程结束后,您会在 开始/程序/XAMPP 菜单下找到 XAMPP。您可以使用 XAMPP 控制面板来启动/停止所有服务或安装/卸载所有服务。

XAMPP 控制面板能启动/停止 Apache、MySQL、FilaZilla 和 Mercury,或直接将其安装为服务

方法 B:不使用安装包进行安装
如果不用安装包,则可下载 7-ZIP 压缩包或 ZIP 压缩包,并将其解压至您选择的文件夹中。


本图中,我们将 XAMPP 解压到“D:\program files”路径下的“D:\program files\xampp”文件夹中。之后,打开 XAMPP 所在的文件夹,并运行其中的“setup-xampp.bat”。


这样能使配置文件中的路径信息得到更新。


最后,通过那些批处理文件或图形界面的“xampp-control.exe”启用不同的服务即可。

注意:如果您使用的是 XAMPP 的安装包,您不需要运行“setup_xampp.bat”。

操作:
操作 1:启动/停止/测试 XAMPP
www.nat32.com 制作的 XAMPP 控制面板不包含在 Lite 版(精简版)中。

.\xampp\xampp-control.exe

其它的服务启动/停止脚本
启动 Apache 和 MySQL:.\xampp\xampp_start.exe
停止 Apache 和 MySQL:.\xampp\xampp_stop.exe
启动 Apache:.\xampp\apache_start.bat
停止 Apache:.\xampp\apache_stop.bat
启动 MySQL:.\xampp\mysql_start.bat
停止 MySQL:.\xampp\mysql_stop.bat
启动 Mercury 邮件服务器:.\xampp\mercury_start.bat
(Mercury 邮件服务器只能通过 XAMPP 控制面板的图形界面停止)
设置 FileZilla FTP 服务器:.\xampp\filezilla_setup.bat
启动 FileZilla FTP 服务器:.\xampp\filezilla_start.bat
停止 FileZilla FTP 服务器:.\xampp\filezilla_stop.bat

测试:Apache 服务启动后,在浏览器中输入地址
http://localhosthttp://127.0.0.1,并检测所有的 XAMPP 样例和工具。

操作 2:将特定的服务器配置为系统服务
您可以在 NT4、2000 和 XP 平台中将特定的服务器配置为系统服务。请使用以下脚本:

安装 Apache 服务器为系统服务:.\xampp\apache\apache_installservice.bat
卸载 Apache 服务器的系统服务:.\xampp\apache\apache_uninstallservice.bat
安装 MySQL 服务器为系统服务:.\xampp\mysql\mysql_installservice.bat
卸载 MySQL 服务器的系统服务:.\xampp\mysql\mysql_uninstallservice.bat
安装及卸载 FileZilla FTP 服务器为系统服务:.\xampp\filezilla_setup.bat
Mercury 邮件服务器:目前还不能配置为系统服务!

操作 3:安装插件
除了主程序包外,还有许多相关的插件可用于开发环境。目前,本站发布的官方 win32 插件如下:

1. 包含 Mod_Perl 和精选的重要 Perl 模块的 Perl 插件
2. Tomcat 插件(系统需求:系统中必须已经安装 SUN J2SE SDK)
3. Tomcat 插件的 Cocoon 模块(系统需求:系统中必须已经安装 Tomcat)
4. Python 插件

推荐的安装方法如下:
XAMPP 安装包需要安装包格式的插件,7-Zip 压缩包需要 7-Zip 压缩包格式的插件。ZIP 压缩包格式的插件请直接解压缩至 XAMPP 的主文件夹中。然后运行“setup_xampp.bat”批处理文件即可。安装包格式的插件能自动配置所有的东西,您不需要手动配置。

操作 4:升级 XAMPP
当 XAMPP 程序集里的单独组件被升级时,我们会将 XAMPP 同步升级。然而,其中一些组件的变化与我们最新发布的版本不兼容,所以我们就不会升级这类组件。我们通常能升级 XAMPP 中所有的服务器和程序。但我们不升级配置文件,因为您可能已经修改过他们了。提示:如果您用的是安装包版的 XAMPP,那么您在使用升级安装包的时候将非常轻松。其他用户请下载自解压 7-ZIP 压缩包。直接将其中的文件释放到 XAMPP 文件夹中,并覆盖原有的文件即可。

安全问题(必读!
XAMPP 安全控制台
正如前面提到,XAMPP 并不是为生产环境准备的,它只为开发者服务。为了方便开发者,XAMPP 被默认配置为所有功能全部开启。对于开发环境来说,这是非常好的,但对于生产环境,这可能是灾难性的。

下面是 XAMPP 默认配置的安全问题列表:
1. MySQL 管理员(root)未设置密码。
2. MySQL 服务器可以通过网络访问。
3. PhpMyAdmin 可以通过网络访问。
4. 样例可以通过网络访问。
5. Mercury 邮件服务器和 FileZilla FTP 服务器的用户是公开的。

所以大家应该在发布一些在线的东西前保证 XAMPP 的安全性。有时候,一个防火墙或一个外部路由器就足够安全了。首先,您可以试试基于网络的“XAMPP 安全控制台”。

修正绝大多数的安全薄弱环节,只需访问以下地址(只能在本地计算机上访问):

1.4.15 版之前的版本:
http://127.0.0.1/xampp/xamppsecurity.php

1.4.15 版及以后版本:
http://127.0.0.1/security

MySQL、PhpMyAdmin 的管理员密码和 XAMPP 的目录保护可以在这里设置。对于 Mercury 邮件服务器和 FileZilla FTP 服务器,请记得更改配置设置(比如用户名和密码)。如果您不需要这些服务,那就不要启动它们——这样也是安全的。

卸载
移除方法 A:安装包
使用安装包(NSI)安装的 XAMPP,请使用自带的卸载工具进行卸载!自带的卸载工具会将注册表中的相关内容和一些服务一并卸载。自带的卸载工具如下图所示。


移除方法 B:zip 和 7-zip 压缩包
卸载方法根据您使用的 XAMPP 安装版本有所不同:
1. ZIP 压缩包
2. 自解压 7-ZIP 压缩包
3. XAMPP lite(精简版)

卸载时只需删除整个 XAMPP 文件夹即可。不涉及注册表项,不涉及环境变量……简单而又干净!但在此之前不要忘记关闭所有 XAMPP 组件的服务器,退出所有的面板。也许您已经安装了一些 XAMPP 的组件作为系统服务,那么您必须先卸载这些服务!

常见问题
问题 1:什么是 XAMPP Lite(精简版)?
XAMPP Lite(精简版)类似 XAMPP 推荐的 PHP 与 MySQL 快速使用包。与完整版相比,它少了一些工具,比如 Mercury 邮件服务器或 FileZila FTP 服务器。注意:精简版没有相关的安装包、插件或升级包。

问题 2:我的网络文档应该放在哪里?
所有网络文档都放在 htdocs 主文件夹中(.\xampp\htdocs)。如果您将 test.html 文件放在这里,您可以通过
http://localhost/test.html 来访问它。php 或 cgi 文件也同样放在这里。其他的 WWW 子文件夹可以在 htdocs 目录下创建。例如将 test.html 放在 .\xampp\htdocs\new 路径下,您就可以在浏览器的地址栏中输入http://localhost/new/test.html 来访问这个文件。

更多的文件特性概述:
CGI) 可执行:全部;允许的结尾:.cgi => 主程序包
PHP) 可执行:全部;允许的结尾:.php .php4 .php3 .phtml => 主程序包
MOD Perl) 可执行:.\xampp\htdocs\modperl;允许的结尾:.pl => Perl 插件
ASP Perl) 可执行:.\xampp\htdocs\modperlasp;允许的结尾:.asp => Perl 插件
JSP Java) 可执行:.\xampp\tomcat\webapps\java(和其他);允许的结尾:.jsp => Tomcat 插件
Servlets Java) 可执行:.\xampp\tomcat\webapps\java(和其他);允许的结尾:.html(和其他)=> Tomcat 插件
MOD Python) 可执行:.\xampp\htdocs\python;允许的结尾:.py => Python 插件
Spyce Python) 可执行:.\xampp\htdocs\python;允许的结尾:.spy => Python 插件

问题 3:我能移动 XAMPP 吗?
可以,但只限于 ZIP/7-ZIP 压缩包版的 XAMPP。移动操作之后,您必须运行“setup-xampp”使配置文件得到更新。请不要用这种方法尝试安装版的 XAMPP。如果您在使用安装版的 XAMPP,您可以将其复制(而不是移动)一份,并放到新的路径下,然后运行“setup-xampp”使配置文件得到更新。试试吧!

问题 4:我如何配置默认的开始页面?
如果您在浏览器中访问类似
http://localhost/xampp/ 的文件夹,Apache 服务器会自动返回一个默认的开始页面。Apache 会自动寻找已存在的类似 index.php 的索引页。httpd.conf 中的“DirectoryIndex”指令负责这个功能。在这里您可以定义默认开始页面的名字和协议。XAMPP 在默认状态下,“DirectoryIndex”指令的列表如下:

index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.html.var index.phtml

问题 5:我如何在 PHP5 和 PHP4 之间相互切换?
XAMPP(非精简版!)包含 PHP5 和 PHP4。请使用“php-switch.bat”($path-to-xampp\xampp\php-switch.bat)来切换版本。注意:在切换版本前请先停止 Apache 服务器。

问题 6:我在哪里能更改配置文件?
您可以通过文本编辑器来更改 XAMPP 的各种配置文件。这些文件存在于以下路径:
Apache 基本配置:.\xampp\apache\conf\httpd.conf
Apache SSL:.\xampp\apache\conf\ssl.conf
Apache Perl(仅限插件):.\xampp\apache\conf\perl.conf
Apache Tomcat(仅限插件):.\xampp\apache\conf\java.conf
Apache Python(仅限插件):.\xampp\apache\conf\python.conf
PHP:.\xampp\apache\conf\php.ini(Apache 正在运行的 PHP 版本)
MySQL:.\xampp\mysql\bin\my.cnf
phpMyAdmin:.\xampp\phpMyAdmin\config.inc.php
FileZilla FTP 服务器:.\xampp\FileZillaFTP\FileZilla Server.xml
Mercury 邮件服务器基本配置:.\xampp\MercuryMail\MERCURY.INI
Sendmail:.\xampp\sendmail\sendmail.ini

问题 7:这些文件夹里都是些什么东西?
路径 内容
\xampp\anonymous 匿名 FTP 的样例文件夹
\xampp\apache Apache 服务器
\xampp\cgi-bin 可执行的 CGI 脚本
\xampp\FileZillaFTP FileZilla FTP 服务器
\xampp\htdocs http 文档的主文件夹
\xampp\install 用于 XAMPP 的安装(请勿删除!)
\xampp\licenses 同上
\xampp\MercuryMail Mercury 邮件 SMTP POP3 IMAP 服务器
\xampp\mysql MySQL 服务器
\xampp\perl Perl
\xampp\php PHP(4 和 5)
\xampp\phpmyadmin phpMyAdmin
\xampp\security 额外的安全配置
\xampp\tmp 临时文件夹
\xampp\webalizer Webalizer 网络状态
\xampp\webdav WebDAV 样例

Windows下Tomcat的安装

1. 下载Tomcat for windows的安装程序,http://tomcat.apache.org/ , 我选择下载的Windows Executable和tar.gz 文件
2. 直接运行Windows Executable 包中解压出来的exe文件,可以选择full安装或者custom安装
3. 安装完成之后,会发现在任务栏多出一个类似Apache的图标,接下来还要进行一些配置才能使Tomcat 工作
4. 再次打开系统变量对话框,点击我的电脑->属性->高级->环境变量,在系统变量中查找Path变量,并在末尾添加Tomcat的安装路径,我这里是E:\phpserver\Tomcat 5.0。另外在添加两个变量:
TOMCAT_HOME=” E:\phpserver\Tomcat 5.0”
JAVA_HOME=”C:\Program Files\JAVA\jdk1.5”
5. 配置完环境变量以后要重新启动,配置才能生效
6. 重启之后,先启动Tomcat服务,可以直接点任务栏的图标,启动服务;也可以通过命令行E:\phpserver\tomcat 5.0\bin\startup来启动。
7. 打开ie,输入http://localhost:8080/index.jsp,如果页面显示出Tomcat的标志和一些说明文字,表示配置成功了

Friday, June 20, 2008

Top 10 SQL Server Blogs at Microsoft

By Bill Graziano on 26 September 2007 | 3 Comments | Tags: Developer Sites, DBA Sites


I read dozens of blogs every day related to SQL Server and development. I decided to try and list the Microsoft blogs where I find the most valuable content. Plus I included some non-blog SQL Server sites at Microsoft that I think you should know about.

Product Web Sites

The place to start is the Microsoft SQL Server product web page. It's a great link to many of the other SQL Server resources inside Microsoft. It also include information on features, the always popular SQL Server Edition Comparison and licensing details.

If you're a developer I'd suggest the MSDN's SQL Server Developer Center. If you're on the support side I'd look at TechNet's SQL Server TechCenter. You can also find SQL Server 2005 Books Online and SQL Server 2000 Books Online. You can even find SQL Server 2008 Books Online but it doesn't look very complete yet.

You can find additional information on the SQL Server 2000 Support Site and the SQL Server 2005 Support Site. Both sites include an RSS feed of recent Knowledge Base articles that is definitely worth a subscription. Both sites have "How To" articles, KB articles, downloads and a variety of other resources.

The last Microsoft site is one of the most important. Connect is where Microsoft gives you a view and a vote into its bug database. You can file bugs, suggest features and vote on their importance. As I sat in the MVP sessions at PASS Microsoft again and again referred to feedback from Connect. If you want your voice heard in the product this is the place. (Thanks for reminding me Geoff!)

SQL Server Blogs

The list of blogs is longer and more varied. There are additional blogs out there but many don't seem to be updated much at all. These are the blogs I read that are updated regularly. The list is in the order they appear in my reader (sort of random).

  • PSS SQL Server Engineers. One of the great experiences of PASS each year is watching Microsoft's top support engineers present. Since they mostly deal with actual, running SQL Servers I find their experiences closely mimic the community. Their blog posts tend to be very practical and highly technical. If you come to PASS I'd encourage you to visit the PSS Service Center and get to know these people.
  • The SQL Server Customer Advisory Team (SQLCAT) sits inside the product team and works with Microsoft's largest SQL Server customers and their most interesting installations. They recently launch a new web site where they provide great technical content. You can also find information on their old blog.
  • The ADO.NET Team Blog covers all things client related. Lately they've been posting on the Entity Framework and LINQ including a post titled Entity Framework for DBAs which finally gives the perspective I've been waiting for. You can view their older posts at the Data Access blog.
  • The SQL Server Release Services also has a blog. They post on releases, service packs, versions and end of support life issues. They didn't post much in the beginning but they've been much more active since June. Of special interest is their post listing when support will end for the various versions of SQL Server.
  • The SQL Programmability & API Development Team posted pretty regularly up until June of this year. Hopefully they'll get started again as SQL Server 2008 gets closer to release. They cover a variety of topics including the CLR, procedure cache and XML.
  • SQL Server Engine Tips is published by the relational engine team. Posting is a little sporadic but the information is great.
  • I don't know exactly who runs the SQL Server Performance blog. They cover a variety of relational engine performance issues. Their posts are usually very technical.
  • The Query Processing Team was posting until June of 2007. They had some great posts too! It seems a number of these blogs went dark about the time the first SQL Server 2008 CTP was released. Hmmmm. Hopefully they'll start back up again soon.
  • The SQL Server Storage Engine team also has a blog. It mostly seemed to be Paul Randall posting. Here's hoping they keep the blog up now that Paul has left Microsoft.
  • And what list of blogs would be complete without the ever eclectic Euan Garden. Here you'll find everything from Data Dude to SQL Server Myth Busters -- one of my favorite set of posts. You certainly get a lot of Euan's character in his blog posts!

The worst part about writing a list is the sites and blogs I left out. What other Microsoft blogs do you read on SQL Server? I'll post an update once I have enough new material.

Friday, May 30, 2008

Dragging and dropping to order items in Javascript

[1]http://www.isocra.com/2007/07/dragging-and-dropping-table-rows-in-javascript/

[2]http://www.stillnetstudios.com/2006/12/31/drag-and-drop-sort-order-with-scriptaculous/

[3]http://tool-man.org/examples/index.html

Thursday, May 22, 2008

Free Online Image Converter

http://www.coolutils.com/Online-Image-Converter.php

Here you can convert most commonly used graphic image formats - BMP, JPG, PNG, GIF or ICO. Our Online Image Converter is quick and reliable, and what is most important quite easy-to-use.

Saturday, May 17, 2008

幕末古写真ジェネレーター - 照片轉為江戶明治時的老照片!

「幕末古写真ジェネレーター -写真を江戸〜明治期の古写真ぽくします」是一個相當有趣的線上圖片產生器,可以線上幫你將照片轉為江戶明治時期的照片風格,也就是看起來泛黃、帶點破舊感覺的照片。使用上相當簡單,可以透過電腦上傳照片、或是直接以URL方式輸入網路上的照片,接著在點選「古写真風にする」按鈕就能產生老照片囉!

轉換前的總統府原圖:

轉換後的總統府照片:

是不是很有歷史的感覺呢?除了照片變黃外,還加上了一些類似暈染、刮痕等等的效果,想讓照片回到上個世紀嗎?快丟到「幕末古写真ジェネレーター」時光機吧!

愛因斯坦動態製圖










【網站網址】http://www.hetemeel.com/einsteinform.php
【網站介紹】在這個網站裡,你可以任意輸入想出現於圖片內的文字與位置,點選 Preview image 後將會顯示於下方。不過似乎不支援中文字的輸入,所以僅能以英文或是數字、符號來作為內容。

山姆叔叔 “I WANT YOU” 製圖

【網站網址】http://www.hetemeel.com/unclesamform.php
【網站介紹】改變圖片中的文字,完成後點選 Preview image 即可預覽圖片。推薦使用大寫的英文字母。

字典圖片製作

【網站網址】http://www.hetemeel.com/dictionaryform.php
【網站介紹】可以製作一小頁專屬於自己的字典,除此之外,你也可以補充說明,或是鍵入任何你想顯示於字典內的文字,點選 Preview 即可預覽。而字典內的圖案可以由你自行決定,但僅限於 JPG, PNG 檔案,如果不想出現任何圖片,僅需留下空白即可。

普普風圖片產生器

Warholizer 普普風圖片產生器














Warholizer: Turn youself and your friends into pop icons! 是一個很有趣的網站,它能線上將圖片轉成Pop風格的圖示,可以直接上傳圖片、或是加入會員,也可以從 Flickr 上傳圖片、或是直接使用 URL 擷取圖片。

【網站網址】http://www.bighugelabs.com/flickr/warholizer.php

ConvertICO

ConvertICO is a Free Online Converter - fast (you don't need to install the software and you don't need to register) and easy to use (you need only 3 clicks to convert the PNG or ICO file) - which allows you to convert PNG to ICO (Windows Vista compatible) and ICO to PNG format files.

http://www.convertico.com/

Wednesday, May 14, 2008

matlab 从queue 类构建stack类的全过程

8.9.4 继承性及其应用
8.9.4.3 利用继承性创建子类的示例

【例 8.9.4 .3-1 】把例 8.9.2-1 构成的队列作为父类,利用继承性,创建 stack 堆栈子类。
(1)建立类目录 @stack ,并使它成为当前目录 (以下指令仅对 5.3 版适用)
mkdir('e:\mat53\work','@stack') % 在 e:\mat53\work 上建子目录 @stack
cd e:\mat53\work\@stack % 是子目录 @stack 成为当前目录

(2)编写堆栈类的构造函数 @stack\stack.m
[@stack\stack.m]
function ST=stack(v)
% 调用格式
% ST=stack 创建一个 " 空 " 堆栈对象 .
% ST=stack(v) 创建包含变量 v 的堆栈对象。
if nargin>1;error( 'Too many arguments.' ); end ;
if nargin==0 % 没有输入宗量情况
Q=queue;
s.value=[]; % value 域被赋“空阵”
s.name= '' ; % name 域不给任何字符
elseif isa(v, 'stack' ); % 输入宗量是同类对象情况
s=v; % 直接把输入量赋给 q
Q=queue(evalin( 'caller' ,inputname(1))); % 生成队列对象
else % 非同类输入宗量情况
s.value=v; % 在 value 域中放置输入对象 v 的内容
s.name=inputname(1); % 在 name 域中放置输入对象名 v 字符
if isempty(s.name) % 假如输入量无名
s.name=[ '(' class(v) ')' ]; % 就采用 v 本身的类名
end

Q=queue(evalin( 'caller' ,inputname(1))); % 生成队列对象
end
ST=class(s, 'stack' ,Q); % 产生继承父类对象 Q 性质的 ST 堆栈子类

【 * 例 8.9.4 .3-2 】本例目的之一是:检查上例构造函数设计的正确性。目的之二是:观察堆栈关于队列的显示,类别判断和为 “空”判断性质的继承。

(1)堆栈对象的创建,及由于继承性,而获得正确显示。
AA=' 继承性 ';
ST=stack(AA)
ST=
AA: 继承性

(2)类别检查
class(ST)
ans =
stack

(3)由于在此设计采用了继承性,所以“是堆栈,就一定是队列”。
isa(ST,'stack')
isa(ST,'queue')
ans =
1
ans =
1

(4)检查对 isempty.m 是被继承
isempty(ST)
ans =
0


【 * 例 8.9.4 .3-3 】本例通过堆栈类对象的“压入”和“弹出”操作,进一步观察继承性。

(1)把元素压入堆栈
BB=1:6;CC=sym('x^2+4*x');
comein(ST,BB,CC)
ST=
[ 1*3 stack ]

(2)显示堆栈中第三元素的内容
display(ST,3)
The content of ST(3)
is a 'sym' object
CC=
x^2+4*x

(3)从堆栈弹出元素
[Name1,Value1,ST_1]=goout(ST)
Name1 =
AA
Value1 =
继承性
ST_1=
[ 1*2 stack ]

matlab FIFO 队列 queue 类的全过程

8.9 面向对象编程
8.9.2 面向对象编程应用示例

【例 8.9.2 -1 】本例演示:创建“先进先出” FIFO 队列 queue 类的全过程。在本例中,读者应充分注意:构架域( Fields of a structure array )和定义在其上的方法函数( Method function )之间的关系。

(1)建立类目录 @queue
(2)选择构架数组为 queue 类的数据结构
(3)创建构造函数 queue.m
[@queue\queue.m]
function q=queue(v)
%@QUEUE\QUEUE queue class constructor function
% 调用格式
% q=queue 创建一个 " 空 " 队列对象 .
% q=queue(v) 创建包含变量 v 的队列对象。
superiorto( 'double' , 'sparse' , 'struct' , 'cell' , 'char' , 'inline' , 'sym' );
% 使 queue 对象具有最高优先级 <6>
if nargin>1;error( 'Too many arguments.' ); end ;
if nargin==0 % 没有输入宗量情况
q.value=[]; % value 域被赋“空阵”
q.name= '' ; % name 域不给任何字符
q=class(q, 'queue' ); % 给变量 q 挂上 queue 标签
elseif isa(v, 'queue' ); % 输入宗量是同类对象情况
q=v; % 直接把输入量赋给 q
else % 非同类输入宗量情况
q.value=v; % 在 value 域中放置输入对象 v 的内容
q.name=inputname(1); % 在 name 域中放置输入对象名 v 字符
if isempty(q.name) % 假如输入量无名
q.name=[ '(' class(v) ')' ]; % 就采用 v 本身的类名
end

q=class(q, 'queue' ); % 给变量 q 挂上 queue 标签 <20>
end

(4)为 queue 对象编写显示函数 display.m
[@queue\display.m]
function display(q,ki,kj)
%QUEUE\DISPLAY command window display of a queue object.
% 调用格式
% display(q) 笼统显示整个队列
% display(q,ki) 单下标法显示具体队列元素的内容
% display(q,ki,kj) 双下标法显示具体队列元素的内容
if nargin==0;error( ' 缺少输入宗量,即被显示对象 ! ' ); end
switch nargin
case 1 % 显示整个队列
[m,n]=size(q);
vname=inputname(1); % 被显示对象 q 的名称
if isempty(vname) % 显示对象若无名称
fprintf( 'ans=\n' ); % 按 MATLAB 惯例,屏幕显示 ans 缺省名
elseif fprintf( '%s=\n' ,vname); % 对象有名称时,则屏幕以字符串形式显示名称
end ;

if isempty(q) % 假如被显示对象为“空”
fprintf( ' [ empty ' ) %<17>
fprintf( '%s' ,class(q)) %<18>
fprintf( ' ]\n\n' ); %<19>
elseif m*n==1; % 被显示对象今包含一个“元素”时
fprintf( ' %s: ' ,q.name); % 屏幕先以字符串形式显示所存放对象的名称
disp(q.value); % 紧接着,不换行,显示所存放对象的内容
fprintf( '\n' );
else % 被显示对象今包含多个“元素”时
fprintf( ' [ %d*%d ' ,m,n) % 以下 3 条指令只显示队列“元素”排列 <25>
fprintf( '%s' ,class(q)) %<26>
fprintf( ' ]\n\n' ); %<27>
end

case 2 % 单下标法显示具体队列元素的内容
disp([ 'The content of ' ,inputname(1), '(' ,int2str(ki), ')' ])
disp([ 'is a ''' ,class(q(ki).value), ''' object' ])
fprintf( ' %s=\n' ,q(ki).name);
disp(q(ki).value);
fprintf( '\n' );
case 3 % 双下标法显示具体队列元素的内容
disp([ 'The content of ' ,inputname(1), '(' ,int2str(ki), ',' ,int2str(kj), ')' ])
disp([ 'is a ''' ,class(q(ki,kj).value), ''' object' ])
fprintf( ' %s=\n' ,q(ki,kj).name);
disp(q(ki,kj).value);
fprintf( '\n' );
end

(5)编写重载函数 isempty.m
[@queue\isempty.m]
function f=isempty(q)
%@QUEUE\ISEMPTY True for an empty queue object.
f=0;
[m,n]=size(q);
if m*n==1;
if isempty(q.value) & isempty(q.name) %<6>
f=1;
end ;
end ;

(6)编写“入队”、“离队”函数
[ @queue\comein.m]
function q=comein(p,varargin)
% @QUEUE\COMEIN a variable comes to the end of a queue.
% 调用格式
% comein(p,a,b,...) 使输入宗量 a,b 等排在 p 之后形成新队列,
% 其名沿用 p 位置上的输入队列名 .
% q=comein(p,a,b,...) 使输入宗量 a,b 等排在 p 之后形成新队列 q .
if nargin<2 error( 'comein needs at least two arguments.' ); end ;
if ~isa(p, 'queue' ) error([inputname(1), ' is not a queue' ]); end ;
q0=p;
qzzy=class(p); % 获取第一输入宗量的类别字符串 <10>
for i=1:length(varargin)
temp=varargin{i};
s=eval([qzzy, '(temp)' ]); % 使后来元素成为与第一输入宗量相同的类别 <13>
s.name=inputname(i+1);
if isempty(s.name) % 假如某输入宗量本身无名称
s.name=[ '(' class(temp) ')' ]; % 则把它的类别名作为名称使用
end

if isempty(q0) % 假如前队列是“空”队列
q0=s; % 则直接进入队列
else % 假如前队列非“空”
q0=[q0 s]; % 则新变量排在队尾
end
end

if nargout==0; % 假如没有输出宗量
assignin( 'caller' ,inputname(1),q0); % 新队列沿用第一个输入队列名
evalin( 'caller' ,inputname(1));
else % 假如有输入输出宗量
q=q0; % 新队列名为 q
end

[@queue\goout.m]
function [n,v,q]=goout(p)
% @QUEUE\GOOUT removes the first(the front) element from a queue.
% 调用格式
% goout(p) 从队列 p 中的第一个元素离队 .
% v=goout(p) v 是从 p 队列中移出的那第一个元素的“值”
% [n,v]=goout(p) n,v 分别 是从 p 队列中移出的那第一个元素的“名称”和“值”
% [n,v,q]=goout(p) n,v 分别 是从 p 队列中移出的那第一个元素的“名称”和“值”
% q 是被移去第一个元素后的新队列
if nargin==0 ;error( 'No queue specifide.' ); end ;
if nargout>3;error( 'Too many output arguments.' ); end ;
if nargin>1 error( 'Too many input arguments.' ); end ;
if ~isa(p, 'queue' );error([inputname(1), ' is not a queue.' ]); end ;
if isempty(p)
q1=p;
else
[m,n]=size(p);
v1=p(1).value;n1=p(1).name;
if m*n==1
q1=queue;
else
q1=p(2:end);
end
end

if nargout<3;
assignin( 'caller' ,inputname(1),q1);
end ;

if nargout==0,
evalin( 'caller' ,inputname(1));
end
if nargout>=1;v=v1; end ;
if nargout>=2;n=n1; end ;
if nargout==3;q=q1; end ;

【 * 例 8.9.2 -2 】本例的目的:一,检验例 8.9.2-1 所编写的程序的正确性;二,演示所设计的新类是如何被运作的。

(1)创建一个队列对象,并显示。
qe='Hello! 你好 ! '; % 字符串
Q=queue(qe) % 生成队列对象 Q ,并显示
Q=
qe: Hello! 你好 !

(2)类别检查和是否对象判断
class(Q) % 类别检查
isobject(Q) % 是否对象判断
isa(Q,'queue') % 是否队列判断
ans =
queue
ans =
1
ans =
1

(3)是否“空”队列判断
isempty(Q)
ans =
0

【 * 例 8.9.2 -3 】本例目的:一,演示“入队”、“离队”函数的调用方法;二,演示 @queue\display 显示队列具体元素细节的功能。

(1)利用“入队”函数,使队列变长。
a=[1,2,3;4,5,6];b{1}='This';b{2}=' is ';b{3}='a cell array';
comein(Q,a,b) % 增长队列,并显示整个队列的“宏观”情况
Q=
[ 1*3 queue ]

(2)显示队列 Q 中具体元素的内容
display(Q,2) % 给出 Q 队列第 2 个元素的类别、内容:变量名和值
The content of Q(2)
is a 'double' object
a=
1 2 3
4 5 6

(3)把 Q 队列第 1 个元素和其余部分分离,并生成新队列 QQ
[nn,vv,QQ]=goout(Q)
nn =
qe
vv =
Hello! 你好 !
QQ=
[ 1*2 queue ]

(4)采用双下标法,显示 QQ(1,2) 的内容
display(QQ,1,2)
The content of QQ(1,2)
is a 'cell' object
b=
'This' ' is ' 'a cell array'

【例 8.9.2 -4 】利用指令 methods 可以获知对任何类定义的(在类目录上的)所有方法函数。
methods queue
Methods for class queue:

comein display goout isempty queue

Sunday, May 11, 2008

IE Automation & Tabs

A comment to one of my other posts asked about how to launch IE and open several additional tabs.

IE7 does not support specifying multiple URLs on the command line, but another way to do this is to use IE Automation to launch IE as an out-of-proc COM server and then call methods such as IWebBrowser2::Navigate2. While you can do this using C++ or any language that supports COM, the easiest is to use Windows Scripting Host.

First, create a 'lanuchie.js' file using your favorite text editor, add the following, and save:

var navOpenInBackgroundTab = 0x1000;
var oIE = new ActiveXObject("InternetExplorer.Application");
oIE.Navigate2("http://blogs.msdn.com");
oIE.Navigate2("http://blogs.msdn.com/tonyschr", navOpenInBackgroundTab);
oIE.Navigate2("http://blogs.msdn.com/oldnewthing", navOpenInBackgroundTab);
oIE.Navigate2("http://blogs.msdn.com/ericlippert", navOpenInBackgroundTab);
oIE.Visible = true;
Now from the command line you can do:

wscript.exe launchie.js
to open IE, navigate the first tab, and then open three background tabs.

One caveat: due to some IE features such as Protected Mode you will sometimes observe that the links are opened in an existing IE window.

Published Friday, January 19, 2007 10:51 AM by tonyschr

Monday, May 5, 2008

定理(Theorem)、命題(Proposition)、輔助定理(Lemma)、引申定理(Corollary)、假設(Assumption)

名詞定義:
定理(Theorem)、命題(Proposition)、輔助定理(Lemma)、引申定理(Corollary)、假設(Assumption)

名詞解釋

Theorem:就是定理,比較重要的,簡寫是 Thm。

Lemma:小小的定理,通常是為了證明後面的定理,如果證明的篇幅很長時,可能會把證明拆成幾個部分來敘述,雖然篇幅可能變多,但脈絡卻很清楚。

Corollary:推論。由定理立即可推知的結果。

Property:性質,結果雖然值得一記,卻沒定理來的深刻。

Proposition:有人翻譯為「命題」, 有些作者喜歡用,大概也可以算是比較簡單的定理的一種稱呼。

Claim:證明時先敘述一個結果,再作證明。看的人比較輕鬆。

Note:通常只是一個註解。

Remark:涉及一些結論,比較起來 "Note" 比較像說明, "remark" 則常是非正式的定理。

至於「定義」可以想成是一個若且唯若的定理,

Wednesday, April 23, 2008

CSS Code for the blog

CODE {
color: black;
display: block; /* fixes a strange ie margin bug */
font-family: Courier New;
font-size: 8pt;
overflow:auto;
background: #f0f0f0 url(http://yongzhen.zhuang.googlepages.com/Code_BG.gif) left top repeat-y;
border: 1px solid #ccc;
padding: 10px 10px 10px 21px;
max-height:200px;
line-height: 1.2em;
}

We can use element <code></code>. The appearance is like this

<code>
write my code here...........
</code>

C++ STL - Iterator的erase



std::vector<int> v;
v.push_back(0);
std::vector<int>::iterator vi = v.begin();
while(vi != v.end())
{
if(*vi == 0)
{
v.erase(vi++);
continue;
}
++vi;
}


以上這段code在VC2003上run是正常的, 用gcc 3.2.2的話會造成segmentation fault。

很明顯的, vi++這個iterator的運算在兩個平台上有不同的implementation, gcc是先erase才做++的動作, 因為erase後iterator會指向無法預測的地方, 所以才會產生seg-fault。而VC2003則是先++才把原iterator傳進去, 所以沒有問題。

正確的寫法應該是 vi = v.erase(vi);

Sunday, April 20, 2008

微软成立SQL Server中国研发中心 关注BI等领域

CNET科技资讯网6月12日北京报道 今天,微软中国研发集团宣布建立SQL Server中国研发中心。这是继移动技术中心之后,该研发集团成立的第二家着眼当前技术热点的研发机构。

微软表示,该中心成立后会特别关注中国和东亚地区的市场需求。目前,该中心在上海和北京拥有大约30名员工,正式研发人员的规模将在2-3年内达到上百人。

微软全球资深副总裁、微软中国研发集团主席张亚勤博士指出:“随着“以数据为核心的计算”(Data Centric Computing)渐成主流,对数据的分析和处理将成为全球计算科技研发和体验的一大核心。希望SQL Server中国研发中心能够在此领域作出重大贡献。”

SQL Server 中国研发中心任命孙博凯(Prakash Sundaresan)为总监,孙博凯此前在上海工作过18个月。孙表示:“SQL Server中国研发中心关注的领域主要包括: 数据可编程性、商业智能以及开发工具的升级、管理和支持。”

微软称,SQL Server不但可以满足不同规模的企业对海量数据处理、高性能计算、高可靠性解决方案的迫切需求,且能够令企业拥有更高的生产力、卓越的操控力和最佳的商业洞察力。全球数据库市场统计表明,近两年SQL Server的年销售额超过25亿美元,并保持了15%以上的年增长率。在中国,其市场增长率也获得快速提升。

微软成立SQL Server中国研发中心 关注BI等领域

图:张亚勤向孙博凯赠送礼物

Tuesday, March 4, 2008

热爱生命

也许,日子过于平凡。而个体的一切举动,都必然将生活渲染,或者靓丽,或者阴暗。谁又能逃避庸俗呢?凡夫俗子每日奔波,圣人贤哲早已成为历史,先锋时代的诗人,纵然极力躲避俗世光环的侵扰,却终将难以独立。日光之下,并无新事。

我们在举杯的瞬间,时光成为了记忆。他在我们举杯的欢笑或沉睡中,灵魂永恒寂寞了。10月4日,也还是一个假期中途,各地旅客不断,每处都有新的欢笑和风景。余地,一个年轻的生命,一颗稍显苍老的魂灵,陡然间回归故乡。告别尘世,这是他的选择,只是,这样的选择未免失去理性。他在文字中的建筑,被瞬间的举动引入迷途。一个凌晨的都市,霓虹想必发散出微弱的光芒。

“内心:幽暗的花园”。

这几乎成了他的独白。

为什么让幽暗占据心灵?地狱中的亡灵,每一日在哀哭里疼痛,而这,不应该属于一个诗人。诗人的疼痛,来源于内心正义与爱的呐喊,即使生命因此殉道,也是理想的一种方式。这应该成为你的坐标,驱逐内心幽暗!然而,在极端现实面前,余地瞬间结束了自己的生命,他遗忘甚至放弃了作为丈夫和父亲应尽的责任。

诗人的诗兴思维,也许并不适合成家立业。他们的天地生命如果不与现实和平相处,结果将会非常危险。也许,余地作为一个父亲,留给刚出生的双胞胎儿子的,仅仅是两首诗歌,这便是亲情的所有代价。打开网页,瞬间看到平平安安欢笑的脸。伊人,肩上挑起更重的负担。

联想到89年的海子,以同样惨烈的方式结束生命。一代诗人的传奇,就此郑重谢幕。海子死后,她年迈的母亲发疯似的逢人便磕头,向苍天祈求她的儿子。在一个普通的母亲心中,出版再多的书,有再多的金钱,都比不上有一个健康活着的孩子更为重要。

在他们的文字中,此辈当得天地英才;然而对于生命肤浅的理解,却又令其顿失色彩。

幼年时读《老人与海》,深深被老人的顽强所折服;但是稍大明白作者海明威死于自杀,作品本身也失去了某种撼人心魄的魅力,虽然其文学价值不可低估,然而作者本人的肤浅让后辈质疑其作品的内在生命力。

热爱生命”是一句被重复了千万句的箴言。杰克·伦敦以整部小说诠释生命的真谛;余华的《活着》告诉我们:人应当不是为了活着之外的任何事物而活着,乃是为了活着本身而活着。只有活着才有希望,活着才是真实的,除此之外,一切都非常善变。

自杀之辈,可以找很多借口或理由。余地的压力,在一个民工身上存在,在一个企业领导人身上存在,在国家总统身上同样存在。21世纪的中国,社会处于转型期,大众面临的身心压力自然非比从前。舒缓我们的压力,调整心态,热爱生命,又是显得何其紧迫!

人因为余地的自杀而质疑诗人都是弱者。事实并非如此。爱因斯坦思考过生死的问题:“在死亡面前,人人都是平等的”。死神的召唤,或许具备某种不可抗拒的魔力。不仅仅是余地,自杀现象在这个时代更趋热烈,在不同阶层,不同年龄段,自杀阴影始终挥之不去。张国荣死了,翁美玲死了,三毛也死了……还有许多未知的生命一起奔赴永恒。余地只是其中之一。

这是人类精神性的空虚直接导致。不存在彼岸的观望,不存在安静的时刻,不具备永恒意识,生命其实非常脆弱。帕斯卡尔说:“人不过是一枝会思想的芦苇”。伟大,在于思想,创造出人类文明;渺小,在于生命本质的脆弱,让我们无力承担压力以及无法超越死亡。

周国平先生的文字给人新的鼓舞。哲人的思考是深邃的。他说:“孤独之为人生的重要体验,不仅是因为惟有在孤独中,人才能与自己的灵魂相遇,而且是因为惟有在孤独中,人的灵魂才能与上帝、与神秘、与宇宙的无限之谜相遇。”

真实的天地生命,尽在于此。那是一种懂得停下来享受安静的智慧。众生在匆匆中,也可以如这般安静。在生命中某一些浮躁阶段,不妨仰望高于我们的星空,一切都将豁然开朗。

走了的余地,走好;

正在行走或奔跑的人们,一路平安!

Tuesday, February 12, 2008

Differences of treasury bills (T-Bills), notes and bonds

Treasury bills (T-Bills), notes and bonds are marketable securities the U.S. government sells in order to pay off maturing debt and to raise the cash needed to run the federal government. When you buy one of these securities, you are lending your money to the government of the United States.

T-bills are short-term obligations issued with a term of one year or less, and because they are sold at a discount from face value, they do not pay interest before maturity. The interest is the difference between the purchase price and the price paid either at maturity (face value) or the price of the bill if sold prior to maturity.

Treasury notes and bonds, on the other hand, are securities that have a stated interest rate that is paid semi-annually until maturity. What makes notes and bonds different are the terms to maturity. Notes are issued in two-, three-, five- and 10-year terms. Conversely, bonds are long-term investments with terms of more than 10 years.

Option pricing theory vs. queuing theory

◈ Both theories are for modeling and analysis
􀂄 The “science” of pricing and queuing
􀂄 Analytical closed-form solutions for the general case is very difficult
or impossible to obtain
◈ Both belong to a branch in applied mathematics
􀂄 Involves sophisticated theoretical mathematics and statistics
􀂄 Lead to new mathematical tools, theories and analysis
◈ Both based on “unrealistic” assumptions for mathematical
tractability
􀂄 Exponential distribution for queuing theory
􀂄 Log-normal stock price distribution for option pricing
◈ They are often used for design and optimization
􀂄 Strong predictive power
􀂄 Useful theoretical tools
◈ Therefore, be cautious on the results due to underlying
assumptions, and be appreciative to the models derived and the
expressive beauty of mathematics

Text Books

◈ Higham, An Introduction to Financial Option Valuation, Cambridge
A very good introductory book for financial engineers

Wilmott, Paul Wilmott Introduces Quantitative Finance, Wiley
Mathematical, good introduction to qfin field

◈ Keith Cuthbertson and Dirk Nitzsche, Financial Engineering: Derivatives and
Risk Management, Wiley

Hull, Options, futures, and other derivatives, Pearson
A complete guide on options and futures

◈ McDonald, Derivatives Markets, Addison-Wesley
A good book on derivatives

◈ Corrado and Jordan, Fundamentals of Investments: Valuation and Management,
McGraw-Hill
Easy to start with, but for general financial students
Some slides are from there

◈ Bodie, Kane, and Marcus, Investments, McGraw-Hill
Some slides are from there

◈ Levy and Post, Investment, Prentice-Hall

◈ Alexander, Sharpe and Bailey, Fundamentals of Investments, Prentice-Hall

◈ Duffy, Financial Instrument Pricing Using C++, John Wiley & Sons, Ltd.

◈ Duffy, Introduction to C++ for Financial Engineers: An Object-Oriented Approach,
Wiley

◈ London, Modeling Derivatives in C++, John Wiley & Sons, Ltd.

What is a good model?

A good model has strong predictive power

- It considers all the important parameters without over-simplifying the reality
- A good model does not need to factor in all the system parameters, as
many of them are not important!
- It provides you with trends and general performance characteristics
- It sheds light on how different parameters affect/interact with each other to
come up with an equilibrium price
- It provides you guidance on possibly “under-priced” or “over-priced”
instruments

Using models, we can “quantify,” and hence “optimize,” many investment
decisions and understand how a portfolio performs over time by varying
parameters.

Assumptions commonly made in pricing models

Increased realism leads to increased complexity
◈ The more money, the better
- Need to keep rebalancing one’s portfolio in order to gain money.
- Can money really buy job satisfaction or happiness? There is opportunity
cost associated with gaining money (your time, energy, family, friends, etc.).
Is it really good for your soul to be occupied with money only every moment
of your life? Would you be more interested in work other than investment?
Efficient market with perfect information (no un-symmetric or insider
information)
- Market at equilibrium and hence no arbitrage opportunity
There is a commonly-agreed and known risk-free interest rate
Price is continuous
Trading is instantaneous and continuous (no stale prices)
No transaction costs or taxes (Tax and death are two certainties in your
life)
Settled transactions are reflected in the proceeds immediately
- No restrictive rules (such as short proceeds can be totally available for use
immediately)
Log-normal stock price movement
- Leads to analytic simplicity
◈ Etc.

<金色的琴弦>出现过的所有曲子

第一话:
柚木梓马:
格里格的培尔·金组曲之晨景

火原和树:
Wagner瓦格纳的 Under the Double Eagle双鹰旗下进行曲
小号版

月森莲:
维尼亚夫斯基 D大调第一波兰舞曲
后来片尾的那个是萨拉萨蒂改编的歌剧《卡门》中的斗牛士之歌

志水桂一:
博凯里尼《降B大调大提琴协奏曲》

冬海笙子:
雷格《G大调浪漫曲》

第二话:
月森莲 日野香穗子:
Schubert舒伯特的 Ave Maria圣母颂(第2话中两个各演奏一遍,第7话中两人合奏的也是这个曲子)

日野香穗子:
Gossec戈赛克的Gavotte加伏特舞曲[小提琴版]

火原和树:
门德尔松的《乘着歌声的翅膀》

第三话:
日野香穗子&火原和树:
Gossec戈赛克的Gavotte加伏特舞曲[小提琴加小号版]

土浦梁太郎:
Chopin肖邦Op.66 的升c小调幻想即兴曲

第四话:
土浦梁太郎:
肖邦降D大调op.64 No.1小狗圆舞曲
肖邦练习曲作品的10号之3“离别曲”(比赛时日野和土浦合奏的也是此曲)

王崎信武:
德沃夏克E小调第九交响乐<自新大陆>中的第二章
小提琴版
交响乐版

第五话:
日野香穗子与土浦梁太郎合奏的为肖邦练习曲作品的10号之3“离别曲”

第七话:
月森莲&日野香穗子:
Schubert舒伯特的 Ave Maria圣母颂(话说他俩要成了这曲子就是定情物的说)

第八话:
月森莲:
Tomaso Antonio Vitali维塔利《G小调恰空》(Chaconne in G Minor)

日野香穗子:
帕海贝尔Johann Pachelbel《D大调卡农》(Canon and Gigue in D)[小提琴版]

第九话:
几位不知名大叔的三重奏:舒伯特 - 钢琴三重奏No.1 降B大调, Op. 99, D. 898
Franz Schubert - Piano Trio No.1 in B-Flat Major, Op.99, D.898
动画里的是第二乐章02. Schubert Piano Trio No. 1 Op. 99: Andante con moto(多谢fujitofu大大提供曲名,终于拖好无损,压好放上了……)

第十话:
土浦梁太郎:
Chopin肖邦Op.66 的升c小调幻想即兴曲

日野香穗子:
帕海贝尔Johann Pachelbel《D大调卡农》(Canon and Gigue in D)[小提琴版]

火原和树:
门德尔松的《乘着歌声的翅膀》

冬海笙子:
Saint-Saens Op. 37, Romance in D-flat major for flute and orchestra(多谢fujitofu大大提供)

志水桂一:
圣桑《动物狂欢节》天鹅

柚木梓马:
马斯奈的《泰伊思冥想曲》

第十一话:
柚木梓马:
Adagio 舒缓曲 托马索·阿尔比诺尼Tomaso Albinoni

PS:阿尔比诺尼最著名的作品是《g小调柔板》(即此舒缓曲),以至于被称为“阿尔比诺尼柔板”(Albinoni Adagio)。但据学者考证,这一片段并非他所作。二次大战期间,米兰的音乐学者雷莫·贾佐托(Remo Giazotto)刚刚完成了阿尔比诺尼的传记和作品目录,1945年,他在德国的德累斯顿图书馆发现了一个手稿片断,怀疑是阿尔比诺尼的作品,贾佐托觉得非常好听,就用这个旋律写了一段曲子,后来被传为“阿尔比诺尼柔板”。它是贾佐托的作品,应该称作“贾佐托柔板”,但至今人们仍习惯地称之为“阿尔比诺尼柔板”。

第十二话:
找日野要求提供意见的女生演奏的曲子:莫扎特:G大调第三小提琴协奏曲
Concerto for violin and orchestra No. 3 K 216 in G major -Mozart

王崎信武:
德彪西:美丽的夕阳 Beau soir, for vl. and pno-Debussy

第十三话:
日野香穗子:
柴可夫斯基 旋律 TCHAIKOVSKY - Melody Op. 42 No. 3

第十四话:
柚木梓马:
Adagio 舒缓曲 托马索·阿尔比诺尼Tomaso Albinoni(没有变化啊……)

第十五话:
火原和树:
Massenet, Jules马斯奈 挽歌Elegy, Op.10, No.5(火原同学即使追入爱河也不必悲伤至此吧……)

第十六话:
日野香穗子、月森莲、王崎信武、志水桂一:
Mozart, G大调弦乐小夜曲 K.525 第一乐章 Eine Kleine Nachtmusik,1.Allegro(这曲子超喜欢,从小听到大的)

第十七话:
火原和树:
Schudert 舒伯特小夜曲Serenade(交响版)

志水桂一:
佛瑞 西西里舞曲 Gabriei Faure Siciliano

冬海笙子:
舒曼 Schumann _3首浪漫曲 3 Romances Op 94(发现冬海MM只会选浪漫曲)

月森莲:
Maurice Ravel Poeme, Op. 25拉威尔-茨冈狂想曲

土浦梁太郎:
c小调第12号练习曲 革命 肖邦 Etude Revolutionary In C Minor OP 10 12 Chopin

日野香穗子:
柴可夫斯基 旋律 TCHAIKOVSKY - Melody Op. 42 No.
乘着歌声的翅膀 (门德尔松)
http://music.163888.net/openmusic.aspx?id=5199714
长笛版 http://music.163888.net/openmusic.aspx?id=5316918

2.卡农
(帕海贝尔(Johann Pachelbel)《Canon and Gigue in D》(D大调卡农)被影片《反夫俗子》(ordinary people)《我的野蛮女友》当作背景音乐使用过第八话日野香穗子决定了的曲子……)
http://music.163888.net/openmusic.aspx?id=5220086

3.加伏特舞曲
(Gossec戈赛克的 Gavotte加伏特舞曲)
http://music.163888.net/openmusic.aspx?id=5252847
小提琴版 http://music.163888.net/openmusic.aspx?id=5166119
小提琴+小号 http://music.163888.net/openmusic.aspx?id=5199664

4.离别曲
(土浦梁太郎在第四话的录象中弹奏的曲子 土浦梁太郎 日野香穗子在第五话比赛中也是演奏此曲)
http://music.163888.net/openmusic.aspx?id=5166331

5.斗牛士之歌
http://music.163888.net/openmusic.aspx?id=5048942

6.小狗圆舞曲
(肖邦 降D大调,op.64,no.1 小狗圆舞曲 第四话土浦梁太郎录象中演奏)
http://music.163888.net/openmusic.aspx?id=5176912

7.圣母颂 (舒伯特《Ave Maria》《圣母颂》 月森莲在第二话中演奏的作品。)
http://music.163888.net/openmusic.aspx?id=5164289
小提琴独奏 http://music.163888.net/openmusic.aspx?id=5199392

8.自新大陆
(Dvorak德沃夏克Op.09 的 From the New World 自新大陆 第二乐章 王崎信武在公园演奏的)
http://music.163888.net/openmusic.aspx?id=5166392
小提琴 http://music.163888.net/openmusic.aspx?id=5199874

9. 晨景
(Grieg(格里格)的 Morning from "Peer Gynt"(培尔·金组曲之"晨景") 柚木梓马比赛曲目)
http://music.163888.net/openmusic.aspx?id=5166050

10.双鹰旗下进行曲
(Wagner(瓦格纳)的 Under the Double Eagle《双鹰旗下进行曲》 火原和树)
http://music.163888.net/openmusic.aspx?id=5164555
小号 http://music.163888.net/openmusic.aspx?id=5166084

11.D大调第一波兰舞曲
(维尼亚夫斯基 D大调第一波兰舞曲 月森莲的第一次比赛曲)
http://music.163888.net/openmusic.aspx?id=5165639

12.降B大调大提琴协奏曲
(志水桂一在第一话里演奏的 Bocherini(博凯里尼)的 Concerto B flat Major《降B大调大提琴协奏曲》)
http://music.163888.net/openmusic.aspx?id=5164415

13.圣桑 天鹅
(法国作曲家圣桑《动物狂想曲》中,第十三首大提琴作品《天鹅》为其最为知名的代表作。 志水桂一第十话比赛曲目)
http://music.163888.net/openmusic.aspx?id=5366781

14.爱的礼赞
(《爱的礼赞》亦译作《爱的问候》及《情人的问候》,是小提琴独奏曲。本曲是英国作曲家爱德华-埃尔加(Edward Elgar,1857-1934)的代表作之一,而且是小提琴独奏曲中的名篇。 金色琴弦OP完整版中出现的伴奏)
http://music.163888.net/openmusic.aspx?id=5238817

15.G小调恰空
(Tomaso Antonio Vitali托马索·安东尼奥·维塔利《G小调恰空》(Chaconne in G Minor) 第8话月森莲在家拉的曲子……)
http://music.163888.net/openmusic.aspx?id=5220034

16.升c小调幻想即兴曲
(升c小调幻想即兴曲 肖邦Fantasie Impromptu In C Sharp Minor OP 66 Chopin 土浦梁太郎第三话末演奏曲子)
http://music.163888.net/openmusic.aspx?id=5169225

17.马斯奈 泰伊思冥想曲
(马斯涅的《沉思》小提琴独奏曲, 原曲为马斯涅的歌剧《泰伊思》第二幕第一场与第二场中间所奏的间奏曲,故又称为”泰伊思冥想曲”,常被单独演奏,成为小提琴独奏曲中经久不衰的名篇,也是马斯涅的代表作品。 柚木梓马第十话比赛曲目)
http://music.163888.net/openmusic.aspx?id=5366816

18.G大调浪漫曲
(雷格《G大调浪漫曲》 冬海笙子的第一次比赛曲目)
http://music.163888.net/openmusic.aspx?id=5221702

19.g小调柔板
(Adagio 舒缓曲 托马索·阿尔比诺尼(Tomaso Albinoni, 1671-1750) 第11话柚木梓马在天台上演奏的……)
http://music.163888.net/openmusic.aspx?id=5436844

20.圣桑 浪漫曲
(Op. 37, Romance in D-flat major for flute and orchestra 冬海笙子第2次比赛曲目)
http://music.163888.net/openmusic.aspx?id=5403787

21.美丽的夕阳
(Beau soir, for vl. and pno -Debussy 德彪西 美丽的夕阳 金色琴弦12话王崎信武)
http://music.163888.net/openmusic.aspx?id=5505116

22.旋律
(TCHAIKOVSKY - Melody Op. 42 No. 3 柴可夫斯基 旋律 日野第13话)
http://music.163888.net/openmusic.aspx?id=5580956

23.G大调弦乐小夜曲
(莫扎特《G大调弦乐小夜曲 K.525》 第一乐章 Eine Kleine Nachtmusik,1.Allegro 16话四重奏)
http://music.163888.net/openmusic.aspx?id=5879241

24.小夜曲
(Schudert 舒伯特小夜曲Serenade 火原和树第3次比赛曲目)
http://music.163888.net/5953391

25.西西里舞曲
(西西里舞曲 佛瑞Gabriei Faure Siciliano 志水桂一第三次比赛曲目)
http://music.163888.net/5953462

26.茨冈狂想曲
(Maurice Ravel Poeme, Op. 25拉威尔-茨冈狂想曲 月森莲第三次比赛曲目)
http://music.163888.net/5953616

27.3首浪漫曲
(舒曼 Schumann _3首浪漫曲 3 Romances Op 94 冬海笙子第三次比赛曲目)
http://music.163888.net/5953512

28.革命
(c小调第12号练习曲 革命 肖邦 Etude Revolutionary In C Minor OP 10 12 Chopin 土浦梁太郎第三次比赛曲目)
http://music.163888.net/5953551

29.Elegy
(Massenet, Jules Elegy, Op.10, No.5 火原和树15话)
参考资料:http://zhidao.baidu.com/question/20500924.html?fr=qrl3

Monday, February 11, 2008

Microsoft: SQL Server licensing to win Oracle customers

The forthcoming launch of SQL Server 2008 will see Microsoft focus its considerable resources on the issue of licensing, to win customers from rivals Oracle and IBM.

"Our challenge, now (that) we have picked off a lot of the low-hanging fruit, is to attack the traditional Oracle strongholds," said Matt Dunstan, Microsoft's U.K. marketing director for databases.

Dunstan, who is in charge of the battle with Oracle and IBM, said Microsoft will exploit weaknesses it sees in Oracle's licensing and customer treatment. It is a bold strategy from a company that has itself frequently been pilloried for its licensing policies, but Dunstan clearly thinks Oracle's licensing is a weak spot.

A "common gripe" for Oracle customers, Dunstan said, is around the issue of maintenance and licensing. "Oracle has ticked them off," he added. "I am not privy to Oracle's commercial relationships, but one of the big misconceptions is that a lot of customers believe they have an Oracle site license...there is no such thing as an Oracle site license, I believe."

In fact, Oracle has two licenses for its databases: User Plus, which factors a minimum number of users, and Processors, which is based on the number of processors on the Oracle server.

Oracle earlier this year switched to counting processor sockets rather than processor cores for some products, following the lead of Microsoft, which had seen its database market share grow at 30 percent-plus revenue each quarter for several years.

Oracle was approached for comment to clarify its latest position on licensing, but it did not respond in time for this article.

Dunstan maintains that some Oracle customers discover the lack of a site license only when it's time to pay for the ongoing license, and they find that they have to pay more than they thought. He stressed that his information was from conversations with customers, resellers, and other interested parties.

Oracle has been prepared to offer something very like site licensing, at least for the National Health Service. However, it is not clear how much of an exception this is to normal policy. In January 2004, Oracle agreed to a contract with the NHS that worked out at around 100 million pounds ($207 million), and that licenses all NHS employees to use selected Oracle software.

"Our perspective is that SQL has become very widely adopted, even among the traditional Oracle and IBM customers," Dunstan said. "You often see SQL as well as Oracle, or as well as IBM. With customer references like Virgin, the London Stock Exchange, and Nasdaq, the question 'Is SQL good enough?' has gone."

Dunstan added that because Microsoft works off a clear price list, everything is clearly priced. "Customers can make decisions based on reasonable assumptions," he said.

Colin Barker of ZDNet UK reported from London.

--------------------------

Market shares 2006
IBM DB2 34.3
Oracle 33.9
MS SQL Server 20.1

Tuesday, January 8, 2008

static_cast、dynamic_cast、reinterpret_cast、和const_cast

static_cast、dynamic_cast、reinterpret_cast、和const_cast

关于强制类型转换的问题,很多书都讨论过,写的最详细的是C++ 之父的《C++ 的设计和演化》。最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_cast, dynamic_cast。标准C++中有四个类型转换符:static_castdynamic_castreinterpret_cast、和const_cast。下面对它们一一进行介绍。

static_cast

用法:static_cast < type-id > ( expression )

该运算符把expression转换为type-id类型,但没有运行时类型检查来保证转换的安全性。它主要有如下几种用法:
  • 用于类层次结构中基类和子类之间指针或引用的转换。进行上行转换(把子类的指针或引用转换成基类表示)是安全的;进行下行转换(把基类指针或引用转换成子类表示)时,由于没有动态类型检查,所以是不安全的。
  • 用于基本数据类型之间的转换,如把int转换成char,把int转换成enum。这种转换的安全性也要开发人员来保证。
  • 把空指针转换成目标类型的空指针。
  • 把任何类型的表达式转换成void类型。
注意:static_cast不能转换掉expression的const、volitale、或者__unaligned属性。

dynamic_cast

用法:dynamic_cast < type-id > ( expression )

该 运算符把expression转换成type-id类型的对象。Type-id必须是类的指针、类的引用或者void *;如果type-id是类指针类型,那么expression也必须是一个指针,如果type-id是一个引用,那么expression也必须是一个 引用。

dynamic_cast主要用于类层次间的上行转换和下行转换,还可以用于类之间的交叉转换。

在类层次间进行上行转换时,dynamic_cast和static_cast的效果是一样的;在进行下行转换时,dynamic_cast具有类型检查的功能,比static_cast更安全。
class B{

public:

int m_iNum;

virtual void foo();

};

class D:public B{

public:

char *m_szName[100];

};



void func(B *pb){

D *pd1 = static_cast<D *>(pb);

D *pd2 = dynamic_cast<D *>(pb);

}

在 上面的代码段中,如果pb指向一个D类型的对象,pd1和pd2是一样的,并且对这两个指针执行D类型的任何操作都是安全的;但是,如果pb指向的是一个 B类型的对象,那么pd1将是一个指向该对象的指针,对它进行D类型的操作将是不安全的(如访问m_szName),而pd2将是一个空指针。另外要注 意:B要有虚函数,否则会编译出错;static_cast则没有这个限制。这是由于运行时类型检查需要运行时类型信息,而这个信息存储在类的虚函数表 (关于虚函数表的概念,详细可见<Inside c++ object model>)中,只有定义了虚函数的类才有虚函数表,没有定义虚函数的类是没有虚函数表的。

另外,dynamic_cast还支持交叉转换(cross cast)。如下代码所示。
class A{

public:

int m_iNum;

virtual void f(){}

};



class B:public A{

};



class D:public A{

};



void foo(){

B *pb = new B;

pb->m_iNum = 100;

D *pd1 = static_cast<D *>(pb); //copile error

D *pd2 = dynamic_cast<D *>(pb); //pd2 is NULL

delete pb;

}

在函数foo中,使用static_cast进行转换是不被允许的,将在编译时出错;而使用 dynamic_cast的转换则是允许的,结果是空指针。

reinpreter_cast

用法:reinpreter_cast<type-id> (expression)

type-id必须是一个指针、引用、算术类型、函数指针或者成员指针。它可以把一个指针转换成一个整数,也可以把一个整数转换成一个指针(先把一个指针转换成一个整数,在把该整数转换成原类型的指针,还可以得到原先的指针值)。

该运算符的用法比较多。

const_cast

用法:const_cast<type_id> (expression)

该运算符用来修改类型的const或volatile属性。除了const 或volatile修饰之外, type_id和expression的类型是一样的。

常量指针被转化成非常量指针,并且仍然指向原来的对象;常量引用被转换成非常量引用,并且仍然指向原来的对象;常量对象被转换成非常量对象。

Voiatile和const类试。举如下一例:
class B{

public:

int m_iNum;

}

void foo(){

const B b1;

b1.m_iNum = 100; //comile error

B b2 = const_cast<B>(b1);

b2. m_iNum = 200; //fine
}

上面的代码编译时会报错,因为b1是一个常量对象,不能对它进行改变;使用const_cast把它转换成一个常量对象,就可以对它的数据成员任意改变。注意:b1和b2是两个不同的对象。

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1546067


空对象的大小

我们来看下面的这个类

class Empty

{

};

Empty这个类什么也不包含,其中没有任何数据和方法,那么,我们计算它所占据的空间大小sizeof(Empty)应该是多少呢?多数人认为应该是“0”,这似乎是毋庸置疑的,因为它什么也没有,不占据空间吗!但这到底对不对呢?我们来具体测试一下。

我们建立这样一个文件Test.cpp,包含如下代码:

0001 #include

0002 #include

0003 using namespace std;

0004 //----------------------------------------------------------------

0005 class Empty

0006 {

0007 };

0008 //----------------------------------------------------------------

0009 int main(int argc, char* argv[])

0010 {

0011 cout << "Sizeof(Empty)" << '\t' << sizeof(Empty) << endl;

0012 getch();

0013 return 0;

0014 }

0015 //----------------------------------------------------------------

执行它,gcc得到的输出是“Sizeof(Empty) 1”,C++ Builder的结果是“Sizeof(Empty) 8”,全都不是“0”。这是为什么呢?原因很简单。空对象并不表示没有对象。例如:

Empty a, b;

if (a == b)

{

//do something

}

如果a和b的大小是“0”,那么a和b如何判断是否相同呢?它们都不包含任何内容,能否认为这两个对象就是同一个对象呢?显然是不能。那么又怎么能区分它们两个呢?这就需要它们包含点儿什么。那么事实上Empty对象的内存布局就应该为



char 占位


Empty Object内存布局

1.2. 简单数据对象
考察了空对象之后,我们再来看看包含了数据的对象的大小,如下一个类:

class Simple

{

char a;

int i;

};

它的大小由应该是多少呢?int类型占用4个字节空间,char类型占用一个字节空间,二者相加应该是“5”,慢着点,先不要急着下结论,我们再来验证一次,这一次得到的结果是“8”。为什么会是这样呢?额外的3个字节空间从哪里来的呢?这要从CPU的总线谈起,现在的计算机CPU普遍都是32位的,最有效率的数据传送方式莫过于一次4个字节,为了配合CPU的这个要求,编译器采用了补齐原则,给char类型补上了3个字节,于是乎Simple对象的大小变成了“8”。它的内存布局成为了

char a (1 Byte)

补齐占位(3 Byte)

int i (4 Byte)


Simple对象内存布局

工作笔试(五)x&(x-1)

求下面函数的返回值(微软)
-------------------------------------
int func(x)
{
int countx = 0;
while(x)
{
countx++;
x = x&(x-1);
}
return countx;
}

假定x = 9999
10011100001111
答案: 8

思路: 将x转化为2进制,看含有的1的个数。
注: 每执行一次x = x&(x-1),会将x用二进制表示时最右边的一个1变为0,因为x-1将会将该位(x用二进制表示时最右边的一个1)变为0。

判断一个数(x)是否是2的n次方
-------------------------------------
#include

int func(x)
{
if( (x&(x-1)) == 0 )
return 1;
else
return 0;
}

int main()
{
int x = 8;
printf("%d\n", func(x));
}


注:
(1) 如果一个数是2的n次方,那么这个数用二进制表示时其最高位为1,其余位为0。

(2) == 优先级高于 &

temporary object 临时对象

Exceptional C++ Item 6

Const用法小结

1. const常量,如const int max = 100;
优点:const常量有数据类型,而宏常量没有数据类型。编译器可以对前者进行类型安全检查,而对后者只进行字符替换,没有类型安全检查,并且在字符替换时可能会产生意料不到的错误(边际效应)

2. const 修饰类的数据成员。如:
class A

{

const int size;



}

const数据成员只在某个对象生存期内是常量,而对于整个类而言却是可变的。因为类可以创建多个对象,不同的对象其const数据成员的值可以不同。所以不能在类声明中初始化const数据成员,因为类的对象未被创建时,编译器不知道const 数据成员的值是什么。如

初始化使用initilization list

class A

{

const int size = 100; //错误

int array[size]; //错误,未知的size

}

const数据成员的初始化只能在类的构造函数的初始化表中进行。要想建立在整个类中都恒定的常量,应该用类中的枚举常量来实现。

(or static const int size;)

class A

{…

enum {size1=100, size2 = 200 };

int array1[size1];

int array2[size2];

}

枚举常量不会占用对象的存储空间,他们在编译时被全部求值。但是枚举常量的隐含数据类型是整数,其最大值有限,且不能表示浮点数


3. const修饰指针的情况,见下式:

int b = 500;
const int* a = & [1]
int const *a = & [2]
int* const a = & [3]
const int* const a = & [4]

如果你能区分出上述四种情况,那么,恭喜你,你已经迈出了可喜的一步。不知道,也没关系,我们可以参考《Effective c++》Item21上的做法,如果const位于星号的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量;如果const位于星号的右侧,const就是修饰指针本身,即指针本身是常量。因此,[1]和[2]的情况相同,都是指针所指向的内容为常量(const放在变量声明符的位置无关),这种情况下不允许对内容进行更改操作,如不能*a = 3 ;[3]为指针本身是常量,而指针所指向的内容不是常量,这种情况下不能对指针本身进行更改操作,如a++是错误的;[4]为指针本身和指向的内容均为常量。


4. const的初始化

先看一下const变量初始化的情况
1) 非指针const常量初始化的情况:A b;
const A a = b;

2) 指针const常量初始化的情况:

A* d = new A();
const A* c = d;
或者:const A* c = new A();
3)引用const常量初始化的情况:
A f;
const A& e = f; // 这样作e只能访问声明为const的函数,而不能访问一般的成员函数;

[思考1]: 以下的这种赋值方法正确吗?
const A* c=new A();
A* e = c;

wrong

[思考2]: 以下的这种赋值方法正确吗?
A* const c = new A();
A* b = c;

correct

5. 另外const 的一些强大的功能在于它在函数声明中的应用。在一个函数声明中,const 可以修饰函数的返回值,或某个参数;对于成员函数,还可以修饰是整个函数。有如下几种情况,以下会逐渐的说明用法:
A& operator=(const A& a);
void fun0(const A* a );
void fun1( ) const; // fun1( ) 为类成员函数
const A fun2( );

1) 修饰参数的const,如 void fun0(const A* a ); void fun1(const A& a);
调用函数的时候,用相应的变量初始化const常量,则在函数体中,按照const所修饰的部分进行常量化,如形参为const A* a,则不能对传递进来的指针的内容进行改变,保护了原指针所指向的内容;如形参为const A& a,则不能对传递进来的引用对象进行改变,保护了原对象的属性。
[注意]:参数const通常用于参数为指针或引用的情况,且只能修饰输入参数;若输入参数采用“值传递”方式,由于函数将自动产生临时变量用于复制该参数,该参数本就不需要保护,所以不用const修饰。

[总结]对于非内部数据类型的输入参数,因该将“值传递”的方式改为“const引用传递”,目的是为了提高效率。例如,将void Func(A a)改为void Func(const A &a)

对于内部数据类型的输入参数,不要将“值传递”的方式改为“const引用传递”。否则既达不到提高效率的目的,又降低了函数的可理解性。例如void Func(int x)不应该改为void Func(const int &x)

2) 修饰返回值的const,如const A fun2( ); const A* fun3( );
这样声明了返回值后,const按照"修饰原则"进行修饰,起到相应的保护作用。const Rational operator*(const Rational& lhs, const Rational& rhs)
{
return Rational(lhs.numerator() * rhs.numerator(),
lhs.denominator() * rhs.denominator());
}

返回值用const修饰可以防止允许这样的操作发生:
Rational a,b;
Radional c;
(a*B) = c;

一般用const修饰返回值为对象本身(非引用和指针)的情况多用于二目操作符重载函数并产生新对象的时候。
[总结]

1. 一般情况下,函数的返回值为某个对象时,如果将其声明为const时,多用于操作符的重载。通常,不建议用const修饰函数的返回值类型为某个对象或对某个对象引用的情况。原因如下:如果返回值为某个对象为const(const A test = A 实例)或某个对象的引用为const(const A& test = A实例) ,则返回值具有const属性,则返回实例只能访问类A中的公有(保护)数据成员和const成员函数,并且不允许对其进行赋值操作,这在一般情况下很少用到。

2. 如果给采用“指针传递”方式的函数返回值加const修饰,那么函数返回值(即指针)的内容不能被修改,该返回值只能被赋给加const 修饰的同类型指针。如:

const char * GetString(void);

如下语句将出现编译错误:

char *str=GetString();

正确的用法是:

const char *str=GetString();

3. 函数返回值采用“引用传递”的场合不多,这种方式一般只出现在类的赙值函数中,目的是为了实现链式表达。如:

class A

{…

A &operate = (const A &other); //负值函数

}
A a,b,c; //a,b,c为A的对象



a=b=c; //正常

(a=B)=c; //不正常,但是合法

若负值函数的返回值加const修饰,那么该返回值的内容不允许修改,上例中a=b=c依然正确。(a=B)=c就不正确了。
[思考3]: 这样定义赋值操作符重载函数可以吗?
const A& operator=(const A& a);

6. 类成员函数中const的使用
一般放在函数体后,形如:void fun() const;
任何不会修改数据成员的函数都因该声明为const类型。如果在编写const成员函数时,不慎修改了数据成员,或者调用了其他非const成员函数,编译器将报错,这大大提高了程序的健壮性。如:

class Stack

{

public:

void Push(int elem);

int Pop(void);

int GetCount(void) const; //const 成员函数

private:

int m_num;

int m_data[100];

};

int Stack::GetCount(void) const

{

++m_num; //编译错误,企图修改数据成员m_num

Pop(); //编译错误,企图调用非const函数

Return m_num;

}

7. 使用const的一些建议

1 要大胆的使用const,这将给你带来无尽的益处,但前提是你必须搞清楚原委;
2 要避免最一般的赋值操作错误,如将const变量赋值,具体可见思考题;
3 在参数中使用const应该使用引用或指针,而不是一般的对象实例,原因同上;
4 const在成员函数中的三种用法(参数、返回值、函数)要很好的使用;
5 不要轻易的将函数的返回值类型定为const;
6除了重载操作符外一般不要将返回值类型定为对某个对象的const引用;

[思考题答案]
1 这种方法不正确,因为声明指针的目的是为了对其指向的内容进行改变,而声明的指针e指向的是一个常量,所以不正确;
2 这种方法正确,因为声明指针所指向的内容可变;
3 这种做法不正确;
在const A::operator=(const A& a)中,参数列表中的const的用法正确,而当这样连续赋值的时侯,问题就出现了:
A a,b,c:
(a=B)=c;
因为a.operator=(B)的返回值是对a的const引用,不能再将c赋值给const常量。
Const用法小结 [ C\C++ const]