2011年10月13日 星期四

jquery 1.3 mouseleave event, trigger select option

jquery 1.3 mouseleave event, trigger select option

這是bug嗎? 若綁定mouseleave, 底下若有select tag時, 也會多trigger leave


< div class="move_wrp">
    < select>
       < option>
    < /select>
< /div>

解決方式

$j(".move_wrp").mouseleave(function(e){
    if ((typeof e.fromElement != 'undefined' && !e.fromElement.length) ||
        (typeof e.fromElement == 'undefined' && e.target.tagName != 'SELECT')) {
      $j(this).hide();
    }
  });

2010年12月14日 星期二

安裝apache, subverion

安裝Subverion筆記
   
    目標:
        visualsvn 移機
        再加上修改密碼功能
           
    環境:
        ubuntu10
        apache2.2
        php5
        Subversion
       
    1.使用samba mount到 VisualSvn
        mount.cifs //xx.xx.xx.xx/SvnRepository /usr/local/SvnRoot -o user=xxx,pass=xxx
       
    2.安裝apache2
        sudo apt-get install apache2 apache2-common apache2-utils apache2-doc
        預設裝在
            /etc/apache2/
            /etc/apache2/apache2.conf
        root
            /var/www
       
    3.安裝subversion
        sudo apt-get install subversion libapache2-svn
   
    4.設定環境, 使用apache2去管理Subversion
   
        4.1 文件有提到要使用liunx的group去管理權限 (重要, 才能commit)
            sudo addgroup subversion
            sudo usermod -G subversion -a www-data
           
            sudo chown -R root:subversion myproject
            sudo chown -R www-data:www-data /var/local/svnroot
            --> 授予 Apache(www-data) 使用者存取的權限
           
            /etc/group
           
        4.2 初始化一個repository
            sudo svnadmin create /usr/local/SvnRoot
   
        4.3 修改dav_svn.conf
            sudo vi /etc/apache2/mods-available/dav_svn.conf
            --> 此路徑底下的文件生效
                DAV svn
                #SVNParentPath /mnt/SvnRepository
                SVNParentPath /usr/local/SvnRoot

                   --> SVNPath指Subversion的檔案庫路徑,SVNParentPath指此路徑底下所有目錄
                   都會是Subversion檔案庫
                AuthType Basic
                AuthName "Agenda eSolution Java Dept Subversion repository"
                AuthUserFile /etc/subversion/passwd               
                AuthzSVNAccessFile /etc/subversion/authz
                Require valid-user
                #SVNAutoversioning on
           

        4.4 Subversion 設定文件路徑 /etc/subversion/
            新增Subversion使用者
                sudo htpasswd /etc/subversion/passwd todd (-c 會砍掉檔案重建)
           
            新增Subversion權限
                [aliases]
                # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=
                Research Institute/CN=Joe Average

                [groups]
                testgroup=todd

                [svn:/]
                *=

                [test:/]
                @agenda= rw
                todd2= rw
    5.SSL
        5.1 安裝
            sudo apt-get install ssl-cert
           
        5.2 Enable the SSL Apache module
            sudo a2enmod ssl
       
            /etc/apache2/ports.conf
            應該要有
               
                Listen 443
               

       
        5.3 生成一個 SSL證書
            mkdir /etc/apache2/ssl
            sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
           
        5.4 修改/etc/apache2/sites-available/default-ssl
           
            改成產生的路徑
            #SSLCertificateFile    /etc/apache/ssl/apache.pem
            #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key ?

        5.5 修改/etc/apache2/mods-available/dav_svn.conf
           
                ...
                SSLRequireSSL --> 加入
           

   
        5.6 這一步很重要
            sudo a2ensite default-ssl
            sudo /etc/init.d/apache2 restart
   
        5.7 根憑證 (Root CA) 作法:
            建立根憑證的 Private Key:
                openssl genrsa -des3 -out RootCA.key 2048
                    密碼請來問我
           
            產生根憑證的申請書:
                openssl req -new -key RootCA.key -out RootCA.req
                chmod og-rwx RootCA.key
               
            使用根憑證本身簽髮根憑證:
                openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey RootCA.key
                -in RootCA.req -out RootCA.crt

                rm -f RootCA.req
        5.8 伺服器憑證作法:
            建立伺服器憑證的 Private Key:
                openssl genrsa -out HostCA.key 2048
           
            產生伺服器憑證的申請書
                openssl req -new -key HostCA.key -out HostCA.req
                chmod og-rwx HostCA.key
               
                tip: 在填申請伺服器憑證申請書時 (Common Name) 要填上主機的全名,
                    不然用client去連subversion時會出現
                    server certificate was missing commonName attribute in subject name的錯誤
               
            使用根憑證簽發伺服器憑證
                openssl x509 -req -days 365 -sha1 -extensions v3_req -CA RootCA.crt
                -CAkey RootCA.key -CAserial RootCA.srl -CAcreateserial -in HostCA.req
                -out HostCA.crt

                rm -f HostCA.req
               
        5.9 修改 vi /etc/apache2/sites-available/default-ssl
            SSLCertificateFile    /etc/apache2/ssl/RootCA.crt
            SSLCertificateKeyFile /etc/apache2/ssl/RootCA.key
   
            tip: 這裡認證的檔案是使用 RootCA的,
                    我之前打了HostCA, 會出現
                    svn: OPTIONS of 'https://xxxx.xxxx.xxxx.xxxx/svn/xxxx':
                    SSL handshake failed: \ SSL error code 01 的錯誤
   
    6.新增修改帳密的 passwd.php
       
        5.1.安裝php5
            sudo apt-get install php5
            sudo apt-get install libapache2-mod-php5
       
        5.2.新增 /var/www/passwd.php
       
        5.3.修改 /etc/apache2/mods-available/dav_svn.conf, 目的是使用apache來做驗證
            在apache增加一個Alias, 設定該路徑需要認證, 指定認證的文件為 Subversion
       
            Alias /svntools "/var/www/"
           
                    Require valid-user
                    # how to authenticate a user
                    AuthType Basic
                    AuthName "Subversion Tools"
                    AuthUserFile /etc/subversion/passwd
           


        5.4.修改權限
            chmod 777 /etc/subversion/passwd
       
    最後 restart server時, 會要打上CA憑證的密碼 --> 這裡可以再改成起動時就設, 這部份未處理
    修改 httpd.conf 加入 ServerName xxxx.xxxx.xxxx.xxxx   
       
    7.改成對外
        將原本 VisualSVN Server導到 xx.xx.xx.xx:443
       
        所以修改 VisualSVN Server\conf\httpd.conf
        7.1 要打開 #LoadModule ssl_module bin/mod_ssl.so
       
            SSLProxyEngine on
            proxyPass xxx
            ProxyPassReverse xxx
       

安裝tomcat

    java
        sudo apt-get install openjdk-6-jdk
        cd /usr/lib/jvm/java-1.6.0-openjdk/
   
    tomcat
        tar xvzf apache-tomcat-6.0.14.tar.gz
        sudo mv apache-tomcat-6.0.14 /usr/local/tomcat
        vi /etc/init.d/tomcat
       
        export CATALINA_HOME=/usr/local/tomcat
        export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
        export PATH=$JAVA_HOME/bin:$PATH

        /usr/local/tomcat/lib/
            jtds-1.2.jar
            proxool-0.9.0RC3.jar
            proxool-0.9.1.jar
            proxool-cglib.jar

        /usr/local/tomcat/conf/content.xml
               
                factory="org.logicalcobwebs.proxool.ProxoolDataSource"
                name="jdbc/xxx"
                password="xxx"
                proxool.alias="xxx"
                proxool.driver-class="net.sourceforge.jtds.jdbc.Driver"
                proxool.driver-url="jdbc:jtds:sqlserver://xx.xx.xx.xx:1433;databaseName=xxx"
                proxool.prototype-count="4"
                type="javax.sql.DataSource"
                 user="xxx"/>

        目前先copy 到 /usr/local/tomcat/webapps/rbs
       
        sudo /etc/init.d/tomcat start
        sudo /etc/init.d/tomcat restart
       
        demo:
            http://xx.xx.xx.xx:8080/xxx/       

2010年10月15日 星期五

prototype

$('xxx').readAttribute('xxx')
$('xxx').writeAttribute('xxx')

$(element).show();
$(element).hide();

$(element).up('div')
$(element).down('div')

$(element).select('div') //指定選tag
$(element).getElementsBySelector('div#xxx') //可以指定id, 或 input[]

$(element).getElementsBySelector('xxx').first() //若回傳是list, 可用 [0], 或 .first() 取element

$(element).each(function (el, index) {
    //
});


$(element).childElements()[0].addClassName('current');
$(element).childElements()[0].removeClassName('current');
   
           
$(element).setStyle({'display':'block'});           

document.observe("dom:loaded", function() {
    $$("xxx").each( function(element, index){
        element.observe("click",function(pEvent){
            //           
        } );
    } );
});

2010年10月1日 星期五

regex 檢查 example

來源: http://tw.myblog.yahoo.com/davidbulll/article?mid=79&prev=277&next=76




<form onsubmit="return check();">
<input type="text" name="t1">
<input type="submit">
</form>
<script language="javascript">
--------------------------------檢查數字(整數)

function check() {
 re = /^\d+$/;
 if (!re.test(document.forms[0].t1.value)) {
    alert("欄位不能空白且只允許輸入數字");
    document.forms[0].t1.focus();
    return false;
 }
 return true;
}

--------------------------------檢查數字可有小數

function check(thisname) {

 if (isNaN(document.getElementById(thisname).value)) {
    alert("欄位不能空白且只允許輸入數字");
    document.getElementById(thisname).focus();
    return false;
 }
 }

--------------------------------檢查是否有填資料
function gbchk(theForm)               
{            
  if (theForm.name.value == "")               
  {               
    alert("請輸入姓名!!");               
    theForm.name.focus();               
    return (false);               
  }   
  if (theForm.content.value == "")               
  {               
    alert("請輸入留言內容!!");               
    theForm.content.focus();               
    return (false);               
  }    
  return (true);               
}               
//-->
----------------------------------檢查是否為MAIL格式
    re1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
 if (re1.exec(theForm.email.value) == null)
 {
 alert("你的電子郵件格式不合!");
    theForm.email.focus();               
    return (false);               
 }
</script>
----------------------------------檢查日期格式

--------------------------------------------------------
 <input name="Submit2" type="submit"  value="送出"  onclick="return check()">

2010年4月4日 星期日

hadoop 範例練習

我的環境:
cygwin
hadoop-0.20.2


1.安裝cygwin, 與必要套件
...

2.

參考
http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop1/

其中, 提到以本機來模擬多台server的分散運算的部份
步驟3, 要讓hadoop-site.xml裡設定的各台server, 能以ssh免密碼方式登入
我在gen完key後, ssh localhost, 會出現
ssh connect to host localhost port 22 connection refused

原因是
要啓用 sshd service

參考
http://www.experts-exchange.com/Software/CYGWIN/Q_23631555.html
http://cha.homeip.net/blog/archives/2006/04/_winxp_cygwin_s.html

ssh-host-config , 我都選 yes
它會在 /etc/ 下產生一些ssh檔案
這時再試 ssh localhost應該要可以登入了

補充:
http://changyy.pixnet.net/blog/post/25245658

2010年1月24日 星期日

Hibernate Annotation 對映

One2OneUnidirectAssociationPk
One2OneUnidirectAssociationJoin
One2OneUnidirectAssociationFk

One2OneBidirectAssociationJoin

One2ManyUnidirectAssociationJoinMember
One2ManyUnidirectAssociationFk

One2ManyAndMany2OneBidirectAssociation
One2ManyAndMany2OneBidirectAssociationJoin

Many2OneUnidirectAssociationJoin
Many2OneUnidirectAssociationFk

Many2ManyUnidirectAssociationJoin
Many2ManyBidirectAssociationJoin



package com.todd;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateAnnotationHelper {
    private static SessionFactory sessionFactory;
    static {
        try {
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void close() {
        getSessionFactory().close();
    }
}