Yun's profile无尽的探索PhotosBlogLists Tools Help

Blog


    July 21

    UserType for persisting a Typesafe Enumeration with a VARCHAR column [转]

    Use this Typesafe Enumeration class in your domain model as a simple property type (e.g. of the Comment class in a forum):

    public class Rating implements Serializable {
    
        private String name;
    
        public static final Rating EXCELLENT = new Rating("Excellent");
        public static final Rating OK = new Rating("OK");
        public static final Rating LOW = new Rating("Low");
        private static final Map INSTANCES = new HashMap();
    
        static {
            INSTANCES.put(EXCELLENT.toString(), EXCELLENT);
            INSTANCES.put(OK.toString(), OK);
            INSTANCES.put(LOW.toString(), LOW);
        }
    
        private Rating(String name) {
            this.name=name;
        }
    
        public String toString() {
            return name;
        }
    
        private Object readResolve() {
            return getInstance(name);
        }
    
        public static Rating getInstance(String name) {
            return (Rating)INSTANCES.get(name);
        }
    }
    

    Next, write the Hibernate custom mapping type:

    public class RatingUserType implements UserType {
    
        private static final int[] SQL_TYPES = {Types.VARCHAR};
    
        public int[] sqlTypes() { return SQL_TYPES; }
        public Class returnedClass() { return Rating.class; }
        public boolean equals(Object x, Object y) { return x == y; }
        public Object deepCopy(Object value) { return value; }
        public boolean isMutable() { return false; }
    
        public Object nullSafeGet(ResultSet resultSet,
                                  String[] names,
                                  Object owner)
                throws HibernateException, SQLException {
    
          String name = resultSet.getString(names[0]);
          return resultSet.wasNull() ? null : Rating.getInstance(name);
        }
    
        public void nullSafeSet(PreparedStatement statement,
                                Object value,
                                int index)
                throws HibernateException, SQLException {
    
            if (value == null) {
                statement.setNull(index, Types.VARCHAR);
            } else {
                statement.setString(index, value.toString());
            }
        }
    }
    

    Finally, in your mapping files, bind it all together:

    <hibernate-mapping package="org.hibernate.auction.model">
    
    <class name="Comment"
           table="COMMENTS"
           lazy="true">
    
        <!-- Common id property. -->
        <id name="id"
            type="long"
            column="COMMENT_ID"
            unsaved-value="null">
            <generator class="native"/>
        </id>
    
        <!-- Simple property. -->
        <property
            name="rating"
            column="RATING"
            type="org.hibernate.auction.persistence.RatingUserType"
            not-null="true"
            update="false"/>
    ...
    </class>
    </hibernate-mapping>
    

    You may also use your Rating enumerated type in Hibernate queries:

    Query q = session.createQuery("from Comment c where c.rating = :rating");
    q.setParameter("rating",
                   Rating.LOW,
                   Hibernate.custom(RatingUserType.class));
    

    This is all there is to know about it. You may enhance this strategy with a generic UserType implementation, that knows how to persist different Typesafe Enumerations, this is described here.

    The examples and domain model you have just seen can be found in Hibernate in Action.

    Christian

    Reference:  1. http://www.hibernate.org/172.html

    枚举类型的映射和表示 [转]

    在项目中常遇到用数字表示一种意思的字段,例如:type ,1 表示正常状态,0表示冻结状态;这是一类典型的问题,即枚举类型的映射和表示。在Hibernate2.1版本中提供了enum的接口类型来处理这类问题,参考这个讨论:

    http://forum.javaeye.com/viewtopic.php?t=8114&postdays=0&postorder=asc&highlight=enum&start=0

    但是在Hibernate3中取消了enum类型的支持,Hibernate官方推荐使用UserType接口。不过使用UserType接口实际上会比较复杂,下面我将使用一个简单的案例来讲解使用UserType接口来解决这类问题的办法:

     

    package com.javaeye.simple.domain;

    import java.io.Serializable;

    public class UserTitle implements Serializable {

        private int title;

        public static final UserTitle EMPLOYEE = new UserTitle(0);

        public static final UserTitle MANAGER = new UserTitle(1);

        public static final UserTitle DIRECTOR = new UserTitle(2);

        public static final UserTitle CEO = new UserTitle(3);

        private UserTitle(int title) {
            this.title = title;
        }

        public int toInt() {
            return title;
        }

        public static UserTitle fromInt(int title) {
            switch (title) {
            case 0:
                return EMPLOYEE;
            case 1:
                return MANAGER;
            case 2:
                return DIRECTOR;
            case 3:
                return CEO;
            default:
                throw new RuntimeException("Unknown Status");
            }
        }

        public String toString() {
            switch (title) {
            case 0:
                return "雇员";
            case 1:
                return "经理";
            case 2:
                return "总监";
            case 3:
                return "CEO";
            default:
                throw new RuntimeException("Unknown Status");
            }
        }

    }

    注意,我们需要一个UserTitleType的类,实现UserType接口,定义一个User对象的UserTitle属性是如何向数据库持久化的:

    package com.javaeye.simple.domain;

    import java.io.Serializable;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Types;
    import java.sql.SQLException;

    import org.hibernate.HibernateException;
    import org.hibernate.usertype.UserType;

    public class UserTitleType implements UserType {

        public int[] sqlTypes() {
            int[] types = {Types.INTEGER};       
            return types;
        }

        public Class returnedClass() {
            return UserTitle.class;
        }

        public boolean equals(Object x, Object y) throws HibernateException {
            return x == y;
        }

        public int hashCode(Object x) throws HibernateException {
            return x.hashCode();
        }

        public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
            int title = rs.getInt(names[0]);
            return rs.wasNull() ? null : UserTitle.fromInt(title);
        }

        public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
            if (value == null) {
                st.setNull(index, Types.INTEGER);
            } else {
                st.setInt(index, ((UserTitle) value).toInt());
            }
        }

        public Object deepCopy(Object value) throws HibernateException {
            return value;
        }

        public boolean isMutable() {
            return false;
        }

        public Serializable disassemble(Object value) throws HibernateException {
            return (Serializable) deepCopy(value);
        }

        public Object assemble(Serializable cached, Object owner) throws HibernateException {
            return deepCopy(cached);
        }

        public Object replace(Object original, Object target, Object owner) throws HibernateException {
            return deepCopy(original);
        }

    }

    注意nullSafeGet和nullSafeSet方法的代码,是如何实现UserTitle的字符串值和数据库中保存数字进行转换的。
    最后是映射文件:

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping package="com.javaeye.simple.domain">

        <class name="User">
            <id name="id" unsaved-value="null">
                <generator class="native"/>
            </id>
            <property name="username"/>
            <property name="password"/>
            <property name="gender"/>
            <property name="age"/>
            <property name="department"/>
            <property name="mail"/>
            <property name="birthday"/>
            <property name="title" type="com.javaeye.simple.domain.UserTitleType">
            </property>
        </class>
    </hibernate-mapping>

    指明title属性是用户自定义的某类型。

    在Java程序中指定user的title属性:
    user.setTitle(UserTitle.MANAGER);
    session.save(user);
    在页面输出:
    <% user.getTitle() %>
    就可以打印出中文字符串表示。


    参考:
    1. http://www.javaeye.com/topic/15849
    2. http://www.hibernate.org/172.html

    July 18

    深树

    1. deeptree.jsp中定义css为deeptree.css,并定义<div id="deeptree" class="deeptree" CfgXMLSrc="deeptreeconfig.xml">
    2. deeptree.css中定义了class=deeptree的behavior为:url(deeptree.htc)
    3. deeptree.htc中包含对deeptree的树操作和XML操作和其它页面行为操作的定义。其初始化数据来自deeptreeconfig.xml.使用了deeptree.xsl来处理树相关的操作。
    4. 树的信息来自于TreeRoot.xml和Tree688.xml等这样的数据源。

    参考:1. Deeptree下载

    Apache Lenya2.0中的configure tools

    主要类图:

    1

    主要流程:
    ConfigureCommandLine从Configuration中读取选择的default和local的属性,如果在控制台输入新的值,则替换为新值。最后写下这些local参数。  

    July 17

    Keycode对照表

    字母和数字键的键码值(keyCode)
    按键 键码 按键 键码 按键 键码 按键 键码
    A 65 J 74 S 83 1 49
    B 66 K 75 T 84 2 50
    C 67 L 76 U 85 3 51
    D 68 M 77 V 86 4 52
    E 69 N 78 W 87 5 53
    F 70 O 79 X 88 6 54
    G 71 P 80 Y 89 7 55
    H 72 Q 81 Z 90 8 56
    I 73 R 82 0 48 9 57

     

    数字键盘上的键的键码值(keyCode) 功能键键码值(keyCode)
    按键 键码 按键 键码 按键 键码 按键 键码
    0 96 8 104 F1 112 F7 118
    1 97 9 105 F2 113 F8 119
    2 98 * 106 F3 114 F9 120
    3 99 + 107 F4 115 F10 121
    4 100 Enter 108 F5 116 F11 122
    5 101 - 109 F6 117 F12 123
    6 102 . 110        
    7 103 / 111        

     

    控制键键码值(keyCode)
    按键 键码 按键 键码 按键 键码 按键 键码
    BackSpace 8 Esc 27 Right Arrow 39 -_ 189
    Tab 9 Spacebar 32 Dw Arrow 40 .> 190
    Clear 12 Page Up 33 Insert 45 /? 191
    Enter 13 Page Down 34 Delete 46 `~ 192
    Shift 16 End 35 Num Lock 144 [{ 219
    Control 17 Home 36 ;: 186 \| 220
    Alt 18 Left Arrow 37 =+ 187 ]} 221
    Cape Lock 20 Up Arrow 38 ,< 188 '" 222

    多媒体键码值(keyCode)
    按键 键码 按键 键码 按键 键码 按键 键码
    音量加 175            
    音量减 174            
    停止 179            
    静音 173            
    浏览器 172            
    邮件 180            
    搜索 170            
    收藏 171            

     

    应用:1.限制输入数字

    <input style="ime-mode : disabled"  onKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">

    参考:1. Keycode对照表

    July 09

    SSL Configuration HOW-TO

    Configuration

    Note that JSSE is bundled with Sun's JDK 1.4 and later, so if you're using JDK 1.4 and later, you can skip this step.

    Tomcat currently operates with JKS, PKCS11 or PKCS12 format keystores. The JKS format is Java's standard "Java KeyStore" format, and is the format created by the keytool command-line utility. This tool is included in the JDK.

    To create a new keystore from scratch, containing a single self-signed Certificate, execute the following from a terminal command line:

    %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA
    This command will create a new file, in the home directory of the user under which you run it, named ".keystore".
    To specify a different location or filename, add the -keystore parameter, followed by the complete pathname to your 
    keystore file, to the keytool command shown above.
    %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA -keystore \path\to\my\keystore
    You MUST use the same password here as was used for the keystore password itself.

    Note: your private key password and keystore password should be the same. If they differ, you will get an error along the lines of java.io.IOException: Cannot recover key, as documented in Bugzilla 38217, which contains further references for this issue.

    The final step is to configure your secure socket in the $CATALINA_HOME/conf/server.xml file, where $CATALINA_HOME represents the directory into which you installed Tomcat 5. An example <Connector> element for an SSL connector is included in the default server.xml file installed with Tomcat. It will look something like this:

    <-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
    <!--
    <Connector 
               port="8443" minProcessors="5" maxProcessors="75"
               enableLookups="true" disableUploadTimeout="true"
               acceptCount="100" debug="0" scheme="https" secure="true";
               clientAuth="false" sslProtocol="TLS"/>
    -->

    You will need to remove the comment tags around it.Then, you can customize the specified attributes as necessary.If you change the port number here, you should also change the value specified for the redirectPort attribute on the non-SSL connector.

    Attribute Description
    keystoreFile Add this attribute if the keystore file you created is not in the default place that Tomcat expects (a file named .keystore in the user home directory under which Tomcat is running). You can specify an absolute pathname, or a relative pathname that is resolved against the $CATALINA_BASE environment variable.
    keystorePass Add this element if you used a different keystore (and Certificate) password than the one Tomcat expects (changeit).
    ... ...

    After completing these configuration changes, you must restart Tomcat as you normally do, and you should be in business. You should be able to access any web application supported by Tomcat via SSL.

    Reference:

    1. The Apache Tomcat 5.5 Servlet/JSP Container SSL Configuration HOW-TO
    July 04

    eclipse内置resin的方法

    此配置适用于Resin2.x和Resin3.x版本。运行时需要在每个project目录下放置一个resin.conf文件,由于Resin2.x和Resin3.x版本的配置文件不同,所以需要两个文件,resin.conf文件用于启动resin2.x,resin30.conf用于启动resin3.x。

    以下说明以配置Resin2.1.16版本为例,具体步骤如下:
    1、打开“window->Preferences->Java->Build Path->Classpath Variables”,添加classpath variables,将基配置到Resin的安装目录。比如在我的机器上配置为:Resin_2.1.16 -D:/Program/JavaSoft/resin-2.1.16。最好同时配置一个JDK_TOOLS,指定到java_home下的lib/tools.jar文件上,否则可能会在控制台输出时中文显示成乱码。
    2、运行菜单“Run->Run...”,在弹出的窗口中添加一个Java Application的运行项目。
    3、项目名称随便添写,只要能区分出不同的应用就可以了。如:resin_2.1.16。在Project一项置为空,如果已经有内容了则将其删除,这要才能保证在每个项目中都可以运行。
    4、设置项目的启动类(Main Class),Resin2.x为com.caucho.server.http.HttpServer,Resin3.x为com.caucho.server.http.ResinServer。
    5、配置Arguments,在Program arguments中填写-conf "${project_loc}\resin.conf",(如果配置Resin3.x则填写-conf "${project_loc}\resin30.conf")。
    6、在VM arguments中为空(如果是Resin3.x则填写-Djava.util.logging.manager=com.caucho.log.LogManagerImpl)
    7、指定Working directory为resin的安装目录。
    8、配置JRE,保持默认配置即可,如果是resin3.x版本可能需要jre5.0。
    9、配置classpath,选择Bootstrap Entries,点击Advanced,选择Add ClasspathVariables,选择Resin_2.1.16,点击Extend,将lib目录下的所有jar文件选中,添加到启动项目中,然后将JDK_TOOLS也加到启动项目中。
    10、保存配置。在项目的根目录下放置resin.conf,在eclipse的Run菜单中将Resin_2.1.16加入到收藏中,选择项目或是项目中的某个文件,然后运行Resin_2.1.16即可。

    May 29

    修改Oracle9i中XDB的http和ftp服务端口

    安装Oracle 9i,其安装缺省包含了XDB。在启动数据库后,Oracle XDB的http服务将会自动占用了8080端口,使用下面方法修改XDB的http和ftp服务端口:

    1.使用dbms_xdb包修改端口设置

    使用sys登录sqlplus

    sqlplus sys/syspassword as sysdba

    执行如下的脚本:

    ============================ 
    -- Change the HTTP/WEBDAV port from 8080 to 8081 
    call dbms_xdb.cfg_update(updateXML( 
    dbms_xdb.cfg_get() 
    , '/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()' 
    , 8081)) 
    / 
    -- Change the FTP port from 2100 to 2111 
    call dbms_xdb.cfg_update(updateXML( 
    dbms_xdb.cfg_get() 
    , '/xdbconfig/sysconfig/protocolconfig/ftpconfig/ftp-port/text()' 
    , 2111)) 
    / 
    COMMIT; 
    EXEC dbms_xdb.cfg_refresh;
     
    参考
    1. 轻松解决Oracle XDB的8080端口冲突问题
    November 20

    Hierarchical Queries

    CONNECT BY Example

    The following hierarchical query uses the CONNECT BY clause to define the relationship between employees and managers:

    SELECT employee_id, last_name, manager_id
       FROM employees
       CONNECT BY PRIOR employee_id = manager_id;
    

     

    START WITH Examples

    The next example adds a START WITH clause to specify a root row for the hierarchy and an ORDER BY clause using the SIBLINGS keyword to preserve ordering within the hierarchy:

    SELECT last_name, employee_id, manager_id, LEVEL
          FROM employees
          START WITH employee_id = 100
          CONNECT BY PRIOR employee_id = manager_id
          ORDER SIBLINGS BY last_name;
    August 23

    Melodies

    RETURN TO SOLITUDE

                      Robert Bly

    It is a moonlit, windy night.
    The moon has pushed out the Milky Way.
    Clouds are hardly alive, and the grass leaping.
    It is the hour of return.

    We want to go back, to return to the sea,
    The sea of solitary corridors,
    And halls of wild nights,
    Explosions of grief,
    Diving into the sea of death,
    Like the stars of the wheeling Bear. 

    What shall we find when we return?
    Friends changed, houses moved,
    Trees perhaps, with new leaves.

    from Silence in the Snowy Fields (1962)

     

    One Fine Spring Day MV [Main Theme]

    http://www.youtube.com/watch?v=qgrAOEnrS7g

    August 22

    The Isle - Percy Bysshe Shelley

    There was a little lawny islet
    By anemone and violet,
    Like mosaic, paven:
    And its roof was flowers and leaves
    Which the summer's breath enweaves,
    Where nor sun nor showers nor breeze
    Pierce the pines and tallest trees,
    Each a gem engraven; --
    Girt by many an azure wave
    With which the clouds and mountains pave
    A lake's blue chasm.

     

    小岛

    有一座小岛,细草如茵,
    仿佛是精美的镶嵌珍品,
    点缀着秋牡丹和紫罗兰,
    上空有鲜花、绿叶的屋顶,
    是夏季的气息把它编织成;
    无论是阳光、阵雨、微风,
    都穿不透那里的乔木青松——
    每一棵都是玉石的雕件;
    四周是湛蓝的波涛万顷,
    和白云、青山一同围砌成:
    一片蓝汪汪湖泊的深渊。 
                        1822 年
                        (江枫 译)

    Alice in Wonderland

     Chapter I - Down the Rabbit-Hole

    02white_rabbitAlice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'

    So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.

    There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.

    In another moment down went Alice after it, never once considering how in the world she was to get out again.

    The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.

    Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it.

    'Well!' thought Alice to herself, 'after such a fall as this, I shall think nothing of tumbling down stairs! How brave they'll all think me at home! Why, I wouldn't say anything about it, even if I fell off the top of the house!' (Which was very likely true.)

    Down, down, down. Would the fall never come to an end! 'I wonder how many miles I've fallen by this time?' she said aloud. 'I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down, I think--' (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) '--yes, that's about the right distance -- but then I wonder what Latitude or Longitude I've got to?' (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say.)

    Presently she began again. 'I wonder if I shall fall right through the earth! How funny it'll seem to come out among the people that walk with their heads downward! The Antipathies, I think--' (she was rather glad there was no one listening, this time, as it didn't sound at all the right word) '--but I shall have to ask them what the name of the country is, you know. Please, Ma'am, is this New Zealand or Australia?' (and she tried to curtsey as she spoke -- fancy curtseying as you're falling through the air! Do you think you could manage it?) 'And what an ignorant little girl she'll think me for asking! No, it'll never do to ask: perhaps I shall see it written up somewhere.'

    Down, down, down. There was nothing else to do, so Alice soon began talking again. 'Dinah'll miss me very much to-night, I should think!' (Dinah was the cat.) 'I hope they'll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I'm afraid, but you might catch a bat, and that's very like a mouse, you know. But do cats eat bats, I wonder?' And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do bats eat cats?' for, you see, as she couldn't answer either question, it didn't much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, 'Now, Dinah, tell me the truth: did you ever eat a bat?' when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over.

    Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, 'Oh my ears and whiskers, how late it's getting!' She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof.

    There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again.

    Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted!

    03tiny_door

    Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head though the doorway; 'and even if my head would go through,' thought poor Alice, 'it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only know how to begin.' For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible.

    There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, ('which certainly was not here before,' said Alice,) and round the neck of the bottle was a paper label, with the words 'DRINK ME' beautifully printed on it in large letters.

    04drink_me

    It was all very well to say 'Drink me,' but the wise little Alice was not going to do that in a hurry. 'No, I'll look first,' she said, 'and see whether it's marked "poison" or not'; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they would not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger very deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked 'poison,' it is almost certain to disagree with you, sooner or later.

    However, this bottle was not marked 'poison,' so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off.

    'What a curious feeling!' said Alice; 'I must be shutting up like a telescope.'

    And so it was indeed: she was now only ten inches high, and her face brightened up at the thought that she was now the right size for going through the little door into that lovely garden. First, however, she waited for a few minutes to see if she was going to shrink any further: she felt a little nervous about this; 'for it might end, you know,' said Alice to herself, 'in my going out altogether, like a candle. I wonder what I should be like then?' And she tried to fancy what the flame of a candle is like after the candle is blown out, for she could not remember ever having seen such a thing.

    After a while, finding that nothing more happened, she decided on going into the garden at once; but, alas for poor Alice! when she got to the door, she found she had forgotten the little golden key, and when she went back to the table for it, she found she could not possibly reach it: she could see it quite plainly through the glass, and she tried her best to climb up one of the legs of the table, but it was too slippery; and when she had tired herself out with trying, the poor little thing sat down and cried.

    'Come, there's no use in crying like that!' said Alice to herself, rather sharply; 'I advise you to leave off this minute!' She generally gave herself very good advice, (though she very seldom followed it), and sometimes she scolded herself so severely as to bring tears into her eyes; and once she remembered trying to box her own ears for having cheated herself in a game of croquet she was playing against herself, for this curious child was very fond of pretending to be two people. 'But it's no use now,' thought poor Alice, 'to pretend to be two people! Why, there's hardly enough of me left to make one respectable person!'

    Soon her eye fell on a little glass box that was lying under the table: she opened it, and found in it a very small cake, on which the words 'EAT ME' were beautifully marked in currants. 'Well, I'll eat it,' said Alice, 'and if it makes me grow larger, I can reach the key; and if it makes me grow smaller, I can creep under the door; so either way I'll get into the garden, and I don't care which happens!'

    She ate a little bit, and said anxiously to herself, 'Which way? Which way?', holding her hand on the top of her head to feel which way it was growing, and she was quite surprised to find that she remained the same size: to be sure, this generally happens when one eats cake, but Alice had got so much into the way of expecting nothing but out-of-the-way things to happen, that it seemed quite dull and stupid for life to go on in the common way.

    So she set to work, and very soon finished off the cake.

    August 17

    寒山道 - 唐·寒山

    人问寒山道,寒山路不通。
    夏天冰未释,日出雾朦胧。
    似我何由届,与君心不同。
    君心若似我,还得到其中。

    August 15

    Prototype JavaScript Framework Review (Cont'd)

    String.prototype 的扩展:

    strip: function() {
      return this.replace(/^\s+/, '').replace(/\s+$/, '');
    },

    Introduction to Ajax
    new Ajax.Request('/some_url', { method:'get' });

    August 13

    王菲选辑

    最近,无意识地断断续续哼哼听听地温故了些王菲的歌,集中选辑如下:

    给自己的情书

    曲:C.Y.Kong  词:林夕 编:C. Y. Kong

    请不要灰心 你也会有人妒忌
    你仰望到太高 贬低的只有自己
    别荡失太早 旅游有太多胜地
    你记住你发肤 会与你庆祝钻禧
    lalala 慰藉自己 开心的东西要专心记起
    lalala 爱护自己 是地上拾到的真理
    写这高贵情书
    欲自言自语 助我的天书
    自己都不爱怎么相爱 怎么可给爱人好处
    这千斤重情书
    在夜阑尽处 如门前大树
    没有他倚靠 归家也不必结语

    请不要哀伤 我会当你是偶像
    你要别人怜爱 请安装一个玉箱
    做甚么也好 别为着得到赞赏
    你要强壮到底 再去替对方设想
    lalala 慰藉自己 开心的东西要专心记起
    lalala 爱护自己 是地上拾到的真理
    写这高贵情书
    欲自言自语 助我的天书
    自己都不爱怎么相爱 怎么可给爱人好处
    这千斤重情书
    在夜阑尽处 如门前大树
    没有他倚靠 归家也不必结语

    lalalala....... lalalala.......

    抛得开手里玩具 先懂得好好进睡
    心窝都关过后 从泥泞重到这不甘心相信的金句
    写这高贵情书
    欲自言自语 助我的天书
    自己都不爱怎么相爱 怎么可给爱人好处
    这千斤重情书 在夜阑尽处如门前大树
    他不可倚靠 归家也不必结语

    我要给我写这高贵情书
    欲自言自语 助我的天书
    自己都不爱怎么相爱 怎么可给爱人好处
    凭着我这千斤重情书
    在夜阑尽处 如门前大树
    没有他倚靠 归家也不必结语

     

    笑忘书

    曲:C.Y.Kong  词:林夕 编:C. Y. Kong

    没没有蜡烛 就不用勉强庆祝
    没没想到答案 就不用寻找题目
    没没有退路 那我也不要思慕
    没没人去仰慕 那我就继续忙碌

    lalala 思前想后 差一点忘记了怎么投诉
    lalala 从此以后 不要犯同一个错误
    将这样的感触写一封情书送给我自己
    感动得要哭 很久没哭
    不失为天大的幸福
    将这一份礼物这一封情书给自己祝福
    可以不在乎 才能对别人在乎

    有一点帮助 就可以对谁倾诉
    有一个人保护 就不用自我保护
    有一点满足 就准备如何结束
    有一点点领悟 就可以往后回顾

    lalala 思前想后 差一点忘记了怎么投诉
    lalala 从此以后 不要犯同一个错误
    将这样的感触写一封情书送给我自己
    感动得要哭很久没哭
    不失为天大的幸福
    将这一份礼物这一封情书给自己祝福
    可以不在乎 才能对别人在乎

    lalalala....... lalalala.......

    从开始哭着忌妒 变成了笑着羡慕
    时间是怎么样把握了我皮肤
    只有我自己最清楚
    将这样的感触写一封情书送给我自己
    感动得要哭很久没哭
    不失为天大的幸福将这一份礼物
    这一封情书给自己祝福
    可以不在乎 才能对别人在乎

    让我亲手将这样的感触写一封情书送给我自己
    感动得要哭很久没哭
    不失为天大的幸福
    就好好将这一份礼物这一封情书给自己祝福
    可以不在乎 才能对别人在乎

     

    百年孤寂

    曲:C. Y. Kong/Adrian Chan 词:林夕 编:C. Y. Kong

    心 属於你的
    我借来寄托 却变成我的心魔
    你 属於谁的
    我刚好经过 却带来潮起潮落
    都是因为一路上 一路上
    大雨曾经滂沱 证明你有来过
    可是当我闭上眼 再睁开眼
    只看见沙漠 哪里有甚麽骆驼
    背影是真的 人是假的 没甚麽执着
    一百年前你不是你我不是我
    悲哀是真的 泪是假的 本来没因果
    一百年後没有你也没有我
    (MUSIC )
    风 属於天的
    我借来吹吹 却吹起人间烟火
    天 属於谁的
    我借来欣赏 却看到你的轮廓
    都是因为一路上 一路上
    大雨曾经滂沱 证明你有来过
    可是当我闭上眼 再睁开眼
    只看见沙漠 哪里有甚麽骆驼
    背影是真的 人是假的 没甚麽执着
    一百年前你不是你我不是我
    悲哀是真的 泪是假的 本来没因果
    一百年後没有你也没有我
    ( MUSIC )
    背影是真的 人是假的 没甚麽执着
    一百年前你不是你我不是我
    悲哀是真的 泪是假的 本来没因果
    一百年後没有你也没有我
    背影是真的 人是假的 没甚麽执着
    一百年前你不是你我不是我
    悲哀是真的 泪是假的 本来没因果
    一百年後没有你也没有我

     

    新房客

    曲:王菲  词:林夕 编:张亚东

    等待晚上 迎接白天
    白天打扫 晚上祈祷
    离开烦嚣 寻找烦恼
    天涯海角 心血来潮
    有人在吗 有谁来找
    我说你好 你说打扰
    不晚不早 千里迢迢
    来得正好
    哪里找啊 哪里找啊
    一切很好 不缺烦恼

    我见过一场海啸
    没看过你的微笑
    我捕捉过一只飞鸟
    没摸过你的羽毛
    要不是 那个清早
    我说你好 你说打扰
    要不是 我的花草
    开得正好
    哪里找啊 哪里找啊
    一切很好 不缺烦恼

     

    守望麦田

    曲:C.Y. Kong/Adrian Chan 词:林夕 编:C.Y. Kong

    风吹过麦田
    田总要收割 也许留在我腑脏
    心给你碰撞
    如沙里采矿 也许能令我发光

    共你就似星和云 升和沉
    彼此怎麽挂碍
    美丽多於遗害
    共你就似风和尘 同不同行
    与天地常在
    那怕没法再相爱

    空空两手来 挥手归去
    阅过山与水
    水里有谁 未必需要一起进退
    刻骨铭心来 放心归去未算无一物
    深爱过谁 一天可抵上一岁

    水蒸发成云
    抛弃的雨 也许来自你的汗
    手经过脸庞
    旁人给你的吻 也许留在我掌心

    共你就似星和云 升和沉
    彼此怎麽挂碍
    美丽多於遗害
    共你就似风和尘 同不同行
    与天地常在
    那怕没法再相爱

    空空两手来 挥手归去
    阅过山与水
    水里有谁 未必需要一起进退
    刻骨铭心来 放心归去未算无一物
    深爱过谁 一天可抵上一岁

    ... ...

     

    旋木

    词:杨明学 曲:袁惟仁 编:黄中岳

    拥有华丽的外表和绚烂的灯光
    我是匹旋转木马 身在这天堂
    只为了满足孩子的梦想
    爬到我背上就带你去翱翔

    我忘了只能原地奔跑的那忧伤
    我也忘了自己是永远被锁上
    不管我能够陪你有多长
    至少能让你幻想与我飞翔

    奔驰的木马 让你忘了伤
    在这一个供应欢笑的天堂
    看着他们的羡慕眼光
    不需放我在心上
    旋转的木马 没有翅膀
    但却能够带着你到处飞翔
    音乐停下来你将离场
    我也只能这样

    August 12

    学术三境界

    古今之成大事业、大学问者,必经过三种之境界。“昨夜西风凋碧树,独上高楼,望尽天涯路①”,此第一境也。“衣带渐宽终不悔,为伊消得人憔悴②”,此第二境也。“众里寻他千百度,回头蓦见,那人正在灯火阑珊处③”,此第三境也。此等语皆非大词人不能道。然遽以此意解释诸词,恐晏、欧诸公所不许也。  


    注释:
    ①晏殊【蝶恋花】见二四注。
    ②柳永【凤栖梧】:"伫倚危楼风细细。望极春愁,黯黯生天际。草色烟光残照里。无言谁会凭栏意。 拟把疏狂图一醉,对酒当歌,强乐无味。衣带渐宽终不悔,为伊消得人憔悴。"
    ③辛弃疾【青玉案】(元夕):"东风夜放花千树。更吹落、星如雨。宝马雕车香满路,凤箫声动,玉壶光转,一夜鱼龙舞。 蛾儿雪柳黄金缕。笑语盈盈暗香去。众里寻它千百度。蓦然回首,那人却在,灯火阑珊处。"


    参考:

    August 09

    秋兴赋 - 晋·潘安仁

       晋十有四年,余春秋三十有二,始见二毛。以太尉掾兼虎贲中郎将,寓直于散骑之省。高阁连云,阳景罕曜,珥蝉冕而袭纨绮之士,此焉游处。仆野人也,偃息不过茅屋茂林之下,谈话不过农夫田父之客。摄官承乏,猥厕朝列,夙兴晏寝,匪遑疷宁,譬犹池鱼笼鸟,有江湖山薮之思。于是染翰操纸,慨然而赋。于时秋也,故以"秋兴"命篇。辞曰:

      四时忽其代序兮,万物纷以回薄。览花莳之时育兮,察盛衰之所托。感冬索而春敷兮,嗟夏茂而秋落。虽末士之荣悴兮,伊人情之美恶。善乎宋玉之言曰:"悲哉,秋之为气也!萧瑟兮草木摇落而变衰,憀栗兮若在远行,登山临水送将"。夫送归怀慕徒之恋兮,远行有羁旅之愤。临川感流以叹逝兮,登山怀远而悼近。彼四戚之疚心兮,遭一涂而难忍。嗟秋日之可哀兮,谅无愁而不尽。

      野有归燕,隰有翔隼。游氛朝兴,槁叶夕殒。于是乃屏轻箑,释纤絺,藉莞蒻,御袷衣。庭树槭以洒落兮,劲风戾而吹帷。蝉嘒嘒而寒吟兮,雁飘飘而南飞。天晃朗以弥高兮,日悠阳而浸微。何微阳之短晷,觉凉夜之方永。月朣朦以含光兮,露凄清以凝冷。熠耀粲于阶闼兮,蟋蟀鸣乎轩屏。听离鸿之晨吟兮,望流火之余景。宵耿介而不寐兮,独辗转于华省。

      悟时岁之遒尽兮,慨俛首而自省。斑鬓髟以承弁兮,素发飒以垂领。仰群俊之逸轨兮,攀云汉以游骋。登春台之熙熙兮,珥金貂之炯炯。苟趣舍之殊涂兮,庸讵识其躁静。闻至人之休风兮,齐天地于一指。彼知安而忘危兮,故出生而入死。行投趾于容迹兮,殆不践而获底。阙侧足以及泉兮,虽猴猿而不履。龟祀骨于宗祧兮,思反身于绿水。且敛衽以归来兮,忽投绂以高厉。耕东皋之沃壤兮,输黍稷之余税。泉涌湍于石间兮,菊扬芳于崖澨。澡秋水之涓涓兮,玩游鯈之潎潎。逍遥乎山川之阿,放旷乎人间之世。悠哉游哉,聊以卒岁。

    July 25

    Donald Ervin Knuth

    don Two or three years ago, I catched occasionally Prof. Donald E. Knuth's 3-volume work "The Art of Computer Programming", which was tranlsated by Shu-Yunlin. I was attracted by this great work and great people immediately.

    Donald E. Knuth was born in Milwaukee, Wisconsin on January 10, 1938 and is world-famous for he is Professor Emeritus of The Art of Computer Programming.

    From his website and many other biographys you can find Knuth maded so many great academic or other achievements.

    In 1971, Knuth was the recipient of the first ACM Grace Murray Hopper Award. He has received various other awards including the Turing Award, the National Medal of Science, the John von Neumann Medal and the Kyoto Prize.

    After producing the third volume of his series in 1976, he expressed such frustration with the nascent state of the then newly developed electronic publishing tools (esp. those which provided input to phototypesetters) that he took time out to work on typesetting and created the TeX and METAFONT tools.

    In addition to his writings on computer science, Knuth is also the author of 3:16 Bible Texts Illuminated.

    In his biography, you can also learn Knuth is known for a famous programmer as well as for his geek professional humor.

    He pays a finder's fee of $2.56 for any typos/mistakes discovered in his books, because "256 pennies is one hexadecimal dollar".

    Version numbers of his TeX software approach the transcendental number π, that is versions increment in the style 3, 3.1, 3.14 and so on. Version numbers of Metafont approach the number e similarly.

    He once warned users of his software, "Beware of bugs in the above code; I have only proved it correct, not tried it."

    Knuth's impact is far-reaching. I also found Knuth has a Chinese name 高德納, given to him in 1977 by Frances Yao just before his first visit to China. While acknowledging his contributions to the field, Knuth comments only that "some people seem to be interested in what I have to say."  Recently weeks, I bought the first volume of "The Art of Computer Progamming".  I hope I can also seek the funny comes from this respected and immortal master.

     

    References: