XSLT中的DISTINCT和GROUP

主要思想,要考虑两个函数,key和generate-id

key, 对于string node返回一个string node (string function)。

generate-id, 对每一个节点(node),生成唯一的字符串标识(unique string identifier)。

参考:

http://www.w3.org/TR/xslt#key

Q: How do I count the number of elements with a given attributevalue?

上篇的翻译: XSLT问答:分组、计数和上下文

数据(内存)对齐

要点

  • 对齐参数一般是数据类型的大小,也可以通过编译指令指定。
  • 数据按照其类型的对齐参数在内存地址中对齐。
  • struct中的成员数据对齐之后,这个struct的sizeof()结果会变大。
  • struct本身的对齐参数等于其成员中对齐参数最大的一个。
  • struct的大小(sizeof)是其对齐参数的整数倍。
  • 32位系统中,指针类型的大小是4Bytes的,数组是成员的大小与成员的个数相乘。

实验

代码

#include “stdio.h”

// case1. memory alignment
typedef struct S00{
char A;
char a;
char b;
};

typedef struct S11{
unsigned A;
char a;
char b;
};

typedef struct S12{
char a;
int A;
char b;
};
// case2. pointer vs. array
typedef struct S21{
short* a;
};
typedef struct S22{
short a[7];
};
// case3. align as max size of member
// case3. struct as member
typedef struct S31{
S00 s[5];
};
typedef struct S32{
S12 s[5];
};

int main(int argc, char* argv[])
{
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(unsigned):\t%d\n”, sizeof(unsigned));
printf(”sizeof(int):\t%d\n”, sizeof(int));
printf(”sizeof(char):\t%d\n”, sizeof(char));
printf(”sizeof(short):\t%d\n”, sizeof(short));
printf(”sizeof(long):\t%d\n”, sizeof(long));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(S00):\t%d\n”, sizeof(S00));
printf(”sizeof(S11):\t%d\n”, sizeof(S11));
printf(”sizeof(S12):\t%d\n”, sizeof(S12));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(S21):\t%d\n”, sizeof(S21));
printf(”sizeof(S22):\t%d\n”, sizeof(S22));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(S31):\t%d\n”, sizeof(S31));
printf(”sizeof(S32):\t%d\n”, sizeof(S32));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
return 0;
}

结果

-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(unsigned): 4
sizeof(int): 4
sizeof(char): 1
sizeof(short): 2
sizeof(long): 4
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(S00): 3
sizeof(S11): 8
sizeof(S12): 12
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(S21): 4
sizeof(S22): 14
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(S31): 15
sizeof(S32): 60
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
Press any key to continue

参考

1. 内存对齐 作者 Fang
2. 补课补课,关于C语言中的结构体对齐问题

解决在firefox中word-wrap, word-break的问题

word-wrap:break-word; 和 word-wrap:break-word; 這兩個指令,目前在Firefox瀏覽器裡都還不會有作用。这样长单词在div等容器中就不能强制换行。

发现一个近似的解决办法。就是在需要断行的长单词后面,加上一个汉字或者其他亚洲文字。

比如下面代码在firefox中就不起作用:

<div style=”word-wrap:break-word; word-break:break-all;border: 1px solid black; width:50%;”>
(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol
</div>

(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol

如果在末尾加上一个汉字的标点符号“。”,就没问题了。甚至word-wrap和word-break属性都不需要。

<div style=”border: 1px solid black; width:50%;”>
(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol。
</div>

(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol。

这个中文的句号,在不支持中文的电脑里恐怕不能正常显示。

另外一个属性,overflow: hidden; 会把超出范围的内容隐藏起来,达到保持界面的作用。好处是它是ie mozilla通用的。

Writely.com blogging error

Sorry! Your blog site returned this error:
The request was aborted: The connection was closed unexpectedly.

Mostly time:

405 Method Not Allowed

Writely forum traces on these[1][2], but not solved untile now.

They are part of Google now but not compatible to Blogger.

That’s bad.

富兰克林的13项美德

Blog on 27th Floor拷贝过来。
在此篇的评论中,找到这个pdf ,是一个“每周努力实习一项”用的表格。
然后到www.pocketmod.com下载PDF to PocketMod converter ,打印出来。按照pocketmod的指示,做成一个可以随身携带的小笔记本。

本杰明·富兰克林,美国科学家,政治家,外交家,美国独立宣言和宪法签署人,作家,出版家,成功的印刷厂主。据说这13条美德是他在20岁时自己制定的,每周努力实习一项,到13周后重来一遍。(本来想翻译,仔细看过却觉得不如放在这里学英文)

1. Temperance: Eat not to dullness and drink not to elevation.
节制:不要吃得像个傻子,也不要喝得飘飘然。

2. Silence: Speak not but what may benefit others or yourself. Avoid trifling conversation.
沉默:只说那些能让他人或自己受益的话。避免闲聊。

3. Order: Let all your things have their places. Let each part of your business have its time.
秩序:让东西各归其位。给自己的事务安排好时间。

4. Resolution: Resolve to perform what you ought. Perform without fail what you resolve.
决心:下定决心做你应该做的。把要解决的问题成功解决掉。

5. Frugality: Make no expense but to do good to others or yourself: i.e. Waste nothing.
节俭:只花对他人或自己有益处的钱,就是说不要浪费任何东西。

6. Industry: Lose no time. Be always employed in something useful. Cut off all unnecessary actions.
勤奋:不要浪费时间。总应该有些有用的事来做。取消一切不必要的活动。

7. Sincerity: Use no hurtful deceit. Think innocently and justly; and, if you speak, speak accordingly.
诚实:不要恶意骗人。以善意和公正为思考的出发点;而且说话也应如此。

8. Justice: Wrong none, by doing injuries or omitting the benefits that are your duty.
正当:不应当去伤害人或因失职而使利益受损。

9. Moderation: Avoid extremes. Forbear resenting injuries so much as you think they deserve.
适度:避免极端。克制怨恨会带来多大的伤害仅在自己一念之间。

10. Cleanliness: Tolerate no uncleanness in body, clothes or habitation.
整洁:不可容忍身体、衣服和住所的污秽。

11. Chastity: Rarely use venery but for health or offspring; Never to dullness, weakness, or the injury of your own or another’s peace or reputation.
贞洁:仅为健康和生育的目的行房;不要在此事上犯傻,也不要软弱,更不要有损于自己或他人的平静与名声。

12. Tranquility: Be not disturbed at trifles, or at accidents common or unavoidable.
冷静:不要让琐事,普通或不可避免的事故来扰乱自己。

13. Humility: Imitate Jesus and Socrates.
谦逊:向耶酥和苏格拉底学习。

C51中的函数指针

Reference to Function Pointers in C51.pdf provided by Keil.

8051一个特别之处在于他不用stack而是用fixed memory locations给函数传参。因为8051的stack很小,只有128 bytes。
这样就造成了函数指针(function pointer)使用上的很多问题和限制。

上面说的fixed memory在链接时由编译器指定。
编译器根据程序代码生成一个Call Tree,就是函数调用的关系,谁调用了谁。
这样两个不同时调用的函数就可以共享同一块memory作为传参之用。

编译器不能聪明到知道函数指针代表的是哪一个函数。
初始化和把这个指针作为参数传递的时候,都有可能误认为是一次调用。
于是就会出现Call Tree的构造错误。
此时编译和链接都不会出错,直到运行时,就有可能两个同时运行的(比如funcA执行中调用funcB)函数的传参用地址重叠,发生错误。

可以用链接指令OVERLAY强制指定Call Tree的结构,来避免这个问题。

另外一个问题就是函数的非直接调用(indirectly called function)时,8051要把所有的参数都读到寄存器中。
但是寄存器的大小和个数有限,于是像函数指针这种非直接调用的函数,就最多只能使用三个参数,参数的大小也有限制。

可以考虑把参数放到一个结构(Struct)里面,然后传递这个结构的指针作为参数。

上面两个问题都可以通过reentrant机制来解决。
reentrant是8051提供的一种机制,在IDATA, PDATA, XDATA上面模拟一个Stack。
需要将函数和函数指针都声明成reentrant的。

reentrant会降低程序运行的效率。

C51中的函数指针问题,使得C++这样依靠函数指针实现虚函数等面向对象方法的编程语言无法使用。

Questions from Xiaoying


1.你现在的工作职位,主要职责?对自己未来工作发展的期待?

固件工程师(firmware engineer)。负责手机芯片协议程序开发。

我希望能在相对固定的技术领域稳定工作,时间越长越好。期待公司和行业的发展良好,期待我能在公司和行业的发展中逐渐起到重要作用,期待“。

2.在你看来,“新鲜能力”是什么? 对你现在的工作讲意味着?

新鲜能力(哪个土人想出来的怪词?) = 好奇心 + 踏实的基础知识或能力

意味着有动力有能力不懈不诲地坚持这样枯燥平淡的工作。能够为自己的努力自豪。

3.在你看来,“新鲜能力”是否能够经过努力塑造出来?如果可以,你自己会怎么塑造新鲜能力?或者你自己是如何让自己保持新鲜的?

否。好奇心没法培养,努力也没用。好奇心是“新鲜”的原动力。

要保持“新鲜”,就要努力巩固已有的知识、能力、习惯、性格、原则。因为

一则“温故而知新”。脚踏实地才可以跳一跳。

二则最重要的是,尝试新鲜不能迷失自己。要有自己的原则、方法和知识体系。不至于肤浅,盲目。就像我们中国人应该首先继承好自己的文化和历史,然后才能去借鉴别人新鲜的东西,否则危险。

说白了就是有根基的人才能创新(新鲜)。否则人云亦云,随波逐流,异想天开,终究会很疲惫,不知所措。越“努力”走得越远。

4.作为一个职员,你认为公司应该为发挥员工的“新鲜能力”提供怎样的环境或者做好哪些事情?

公司能经营好本行业务,整个公司和职员都不是每天为了生计疲于奔命。

5.你自己或者朋友的关于“新鲜能力”的故事?

没有。 

 

Compile VC6 project with makefile

PATH:

Compiler directory, cl.exe, link.exe, nmake.exe, lib.exe …
C:\Program Files\Microsoft Visual Studio\VC98\Bin;
rc.exe for resource compile
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;

makefile file generation:

Function on MS Visual Studio (VC++) 6.0, menu Project -> Export Makefile… , .mak file exported.

Include files:

Code in the .mak file:
CPP=cl.exe CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I “..\..\ps_inc” /I “..\..\al\drv_inc” \D “WIN32″ /D “_DEBUG” /D “_MBCS” /D “_LIB” /D “_WINDOWS” /Fp”$(INTDIR)\testProject.pch” /YX /Fo”$(INTDIR)\\” /Fd”$(INTDIR)\\” /FD /GZ /c .cpp{$(INTDIR)}.obj:: $(CPP) @<< $(CPP_PROJ) $< <<
So modify variable CPP_PROJ to change the compile setting.
For example:
CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I “..\..\ps_inc” /I “..\..\al\drv_inc” \ /I “D:\_soft\@microsoft\VS6\install\Program Files\Microsoft Visual Studio\VC98\Include” \ /D “WIN32″ /D “_DEBUG” /D “_MBCS” /D “_LIB” /D “_WINDOWS” /Fp”$(INTDIR)\EMMI.pch” /YX /Fo”$(INTDIR)\\” /Fd”$(INTDIR)\\” /FD /GZ /c

Other:

Notice that link.exe exists in both cygwin/bin directory and system path.

Solution for Matlab 7.0 R14 on XP Pro Start up Corruption

概要:
matlab会因为某些设置不能启动,corrupt。
删除配置文件可以解决。
主要的配置文件在user profile中的MATLAB.prf文件中。
也有一部分在-nodesktop参数启动时创建在windows安装目录的matlab.ini中。
后者比较难被发现(我用filemon.exe找到)。

I fixed the problem exactly as discribed above.
Setting of “Echo on” does cause the problem.
The setting stored in “C:\windows\matlab.ini” but not matlab.prf in
user profile. (I run Matlab 7.01 R14 on Windows XP SP2 En)
Modifiy “Echo on” setting in the matlab.ini to 0, then done.

It seems matlab.ini was generated when running “matlab.exe -nodesktop”
mode.
So reinstall the software helps nothing.

I think this is a bug of this version matlab.

[现象和环境. Problem and Environment]

Matlab 7.0.0 R14 automatically shuts down immediately after starting.
This computer has Windows XP Pro SP1, Intel P4.

Below is a copy of the log file:

————————————————————————
Segmentation violation detected at Sat Oct 29 19:39:48 2005
————————————————————————

Configuration:
MATLAB Version: 7.0.0.19920 (R14)
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600)
Processor ID: x86 Family 15 Model 2 Stepping 7, GenuineIntel
Virtual Machine: Java 1.4.2 with Sun Microsystems Inc. Java
HotSpot(TM) Client VM
(mixed mode)
Default Charset: ibm-5348_P100-1997

Register State:
EAX = 78b9a3c0 EBX = 50000000
ECX = 00000000 EDX = 00000000
ESI = 79066dce EDI = 00000001
EBP = 00cdeb60 ESP = 00cdeb60
EIP = 789b9225 FLG = 00010246

Stack Trace:
[0] m_interpreter.dll:public: bool __thiscall
dbstopIfTable::getIdentifier(char const *)(0×78b9a3c0 “any”,
0×00cdeb80 “HñÍ”, 0×789cf2a0, 0×78b9a3c0 “any”) + 5 bytes
[1] m_interpreter.dll:_inGetStopIfWarning(0×78b9a3c0 “any”,
0×789b109b, 0×50000000, 0×00cdf148 “hñÍ”) + 18 bytes
[2] m_interpreter.dll:_inRefreshGlobalJitEnablement(0×77f78b01,
0×79066e34 “Matlab Settings”, 0×79066fc8 “Echo On”, 0) + 32 bytes
[3] uiw.dll:void __cdecl uiwProfileCmds(int,struct HWND__ *)(2,
0×00160516 “JóJóJóJóJóJó”, 17, 0×00160516 “JóJóJóJóJóJó”) + 321 bytes
[4] uiw.dll:void __cdecl opnCmdWnd(struct HINSTANCE__ *,int,char
*,bool)(4194304, 1, 0×79067014 “MATLAB Command Window”, 1) + 173
bytes
[5] uiw.dll:_uiwSetupWindows(4194304, 1, 1, 0) + 187 bytes
[6] mcr.dll:private: void __thiscall
mcrGlobalOptionsInternal::mcr_complete_initialization(void)(0×01545f88
” T@”, 0, 0×01545f88 ” T@”, 0×77f488f5) + 64 bytes
[7] mcr.dll:public: void __thiscall
mcrGlobalOptionsInternal::mcr_initialize(class MfileReader
*,bool)(0×01545f88 ” T@”, 0, 0×77e6df37, 0×015420c0) + 70 bytes
[8] mcr.dll:public: __thiscall mcrInstance::mcrInstance(class
mcrOptions &,class MfileReader *)(0×00cdff04, 0×01545f88 ” T@”,
0×0004238a “-logfile log”, 0×4d5c3a43) + 265 bytes
[9] MATLAB.exe:0×00401c86(4194304, 0, 0×0004238a “-logfile log”,
0×015420c0)
[10] MATLAB.exe:0×00403e45(0×80000002, 0×00d5dec8, 0×7ffdf000,
0xef0b8cf4)
[11] kernel32.dll:0×77e762b6(0×00403cc0 “jth(U@”, 0, 0, 1245343)
MATLAB program terminated.

The log file should contain some instructions at the bottom: if you can
consistently reproduce this segmentation violation please send it to our
technical support staff. If you can’t consistently reproduce it, send it to
the segv address at mathworks.com.

Based on a quick glance at the log file,
[解决办法. Solution]
try going into your preferences
directory (it should probably be in your Windows profile, under Application
Data\MathWorks\MATLAB\R14) and rename the MATLAB.prf file to oldMATLAB.prf.

If that resolves the issue, please send the older file to support so they
can determine what was wrong with that file.

*snip log file*


Steve Lord
s…@mathworks.com

Mark Couwenberg nospam
Nov 2, 9:26 pm show options
Newsgroups: comp.soft-sys.matlab
From: “Mark Couwenberg” - Find messages by this author
Date: Wed, 2 Nov 2005 08:26:04 -0500
Local: Wed, Nov 2 2005 9:26 pm
Subject: Re: Segmentation violation Matlab 7.0 R14 on XP Pro
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

I tried to find the matlab.prf file, but it was not there. Therewas 1
directory from my older version of Matlab (R13). I copied this one
and renamed as R14, but the results of the logfile are the same all
the time.
What’s more: the logfile how I copied in the 1st message is exactly
the one I get, so there are no instructions at all. The last line is
something with kernel32. I have no idea how to interpret this and use
it for faultfinding.

- Hide quoted text -
- Show quoted text -
Steven Lord wrote:

Steven Lord
Nov 2, 9:37 pm show options
Newsgroups: comp.soft-sys.matlab
From: “Steven Lord” - Find messages by this author
Date: Wed, 2 Nov 2005 08:37:55 -0500
Local: Wed, Nov 2 2005 9:37 pm
Subject: Re: Segmentation violation Matlab 7.0 R14 on XP Pro
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

“Mark Couwenberg” wrote in message

news:ef19cd9.1@webx.raydaftYaTP…

In that case, since it sounds like you can consistently reproduce this
segmentation violation, send it in to the technical support staff. They’ll
see if there’s anything similar in their database, and contact the
developers if necessary to figure out what’s wrong.


Steve Lord
s…@mathworks.com

zh.char…@gmail.com
Dec 2, 5:52 pm show options
Newsgroups: comp.soft-sys.matlab
From: zh.char…@gmail.com - Find messages by this author
Date: 2 Dec 2005 01:52:44 -0800
Local: Fri, Dec 2 2005 5:52 pm
Subject: Re: Segmentation violation Matlab 7.0 R14 on XP Pro
Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse

I fixed the problem exactly as discribed above.
Setting of “Echo on” does cause the problem.

[解决办法补充. supplement on Solution]

The setting stored in “C:\windows\matlab.ini” but not matlab.prf in
user profile. (I run Matlab 7.01 R14 on Windows XP SP2 En)

Modifiy “Echo on” setting in the matlab.ini to 0, then done.

It seems matlab.ini was generated when running “matlab.exe -nodesktop”
mode.
So reinstall the software helps nothing.

I think this is a bug of this version matlab.

Regards,

Charlie Zhu
zh.char…@gmail.com

End of messages

list partterns in Matlab and Python

list partterns in Matlab and Python

A comparation between usage in Matlab against Python of the List variable as the most common and frequently utility in the languages.

Indexing

Key point of Indexing: Index, List to be filtered
Matlab

>> lst = rand(2,3) %@ the List to be filtered
lst =
0.4103 0.0579 0.8132
0.8936 0.3529 0.0099

>> i = lst > 0.5 %@ the Index, a list with integer elements
i =
0 0 1
1 0 0

>> lst(i) %@ the Result, get a new list from lst with elements indexed by i
ans =
0.8936
0.8132

>> lst(lst>0.5)=1
lst =
1.0000 0.0579 1.0000
1.0000 1.0000 0.0099

Append

Python

lst.append(obj)

Matlab
No declaration or additional appending operation.

>> clear
>> lst(2) = 1
lst =
0 1

>> lst(5) = 1
lst =
0 1 0 0 1

>> lst(length(lst)+1) = 9 %@ Appending operation
lst =
0 1 0 0 1 9

Sorting

>> lst=rand(3,4)
lst =
0.9501 0.4860 0.4565 0.4447
0.2311 0.8913 0.0185 0.6154
0.6068 0.7621 0.8214 0.7919
>> sort(lst) %@ Matrix sorting means “Sorts each column”.
ans =
0.2311 0.4860 0.0185 0.4447
0.6068 0.7621 0.4565 0.6154
0.9501 0.8913 0.8214 0.7919
>> sortrows(lst,1) %@ Each row treated as a element in List.
ans =
0.2311 0.8913 0.0185 0.6154
0.6068 0.7621 0.8214 0.7919
0.9501 0.4860 0.4565 0.4447
« Previous PageNext Page »

Random posts

  • About
  • 真是个操蛋的墙
  • 漫画转载:网络吉祥物
  • Setup Web.py and flup on Windows+Apache(WAMP)
  • 天气预报RSS