2013年11月11日 星期一

Virtual Box 上 安裝 CentOS Guest Additions


Problem:

1. "building the virtualbox guest additions kernel modules [失敗]"
2. "Building the OpenGL support module FAILED "


1. Solution: (內容為參考 竹林小屋 Virtual Box 上 安裝 CentOS Guest Additions )
所需套件:
1.gcc
2.kernel-devel
3.kernel-headers

安裝流程:
yum install gcc    #安裝gcc,會同時安裝很多相依套件
yum install kernel-devel    #安裝kernel-devel
yum install kerner-headers    #安裝kernel-headers

安裝完成之後,還必須注意一點........
kernel、kernel-devel、kernel-headers三個套件版本要一樣!
否則人生失敗句可能還會再重現XD
rpm -qa | grep kernel    #檢查三個套件的版本是否一樣

筆者遇到kernel版本比其他兩個還要低,所以還要升級一下。
yum update kernel    #升級kernel版本

升級好之後,重新開機使用新的kernel。(不曉得有沒有不用重開的方法)

2. solution (http://it.oyksoft.com/post/6568/):

cd /media/VBOXADDITIONS_4.1.8_75467/
export MAKE='/usr/bin/gmake -i'
./VBoxLinuxAdditions.run


"make -i" , -i, --ignore-errors   Ignore errors from commands.忽略错误

3. 如果 kernel update 後, 程式
要從新 recompile 程式, 但會出現 /etc/init.d/vbox setup
yum install -y  kernel-devel





2013年10月8日 星期二

location hash explaination


Reference:
網頁設計筆記(二十一) 一頁式網頁 location.hash
mozilla Window.location
jQuery hashchange event

css float and clear property

1. Explaintion:
The float proper can set the div or other as the layout that out of the regular, which is such a hidden man in the content, and others is not see this float block,
and the other content will layout there self deployment which ignore the float block and behaviour, ex wrap the div, which such there is no float block exist.

The clear proper is set to the other content block, that will know there has a float block, and it will new a layout to deploy itself



Reference:
w3c 
修正 CSS 對於 float 區塊, 使用 clear:both 無效的解法
 Overflow清除Float效果的妙用


2013年10月7日 星期一

struts2 OGNL value Get Method

1. Problem:
there are some difference method to get struts2 value such as $, #,
but what is the difference between them??


2. Solution:
  • objectName: object in the ValueStack (default/root object in the OGNL context), such as an Action property
  • #objectName: object in the ActionContext but outside of the ValueStack, specifically...
  • %{ OGNL expression } is used to force OGNL evaluation of an attribute that would normally be interpreted as a String literal.

Reference:
whats-the-difference-between-and-signs-in-struts-tags

2013年9月9日 星期一

R plot png x11 error in centos

Problem:
Using the R to plot the figure and want to store with png file,
such as png(file="a.png")
but it will appear
Error in  png(file="a.png"): X11 is not available




Solution:
I used the R.2.15.2.
1. First you should install the important package for plotting
{
yum install -y cairo-devel.x86_64
yum install -y libpng-devel.x86_64 
}

2. configure and compile the R
{
 ./configure --with-x=no

  R is now configured for x86_64-unknown-linux-gnu

  Source directory:          .
  Installation directory:  
  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  C++ compiler:              g++  -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:            

  Interfaces supported:     
  External libraries:        readline
  Additional capabilities:   PNG, TIFF, NLS, cairo
  Options enabled:           shared BLAS, R profiling, Java


then 
make
}

3. Execute the R and check the png is TURE
{
> capabilities()
    jpeg      png     tiff    tcltk      X11     aqua http/ftp  sockets
   FALSE     TRUE     TRUE    FALSE    FALSE    FALSE     TRUE     TRUE
  libxml     fifo   cledit    iconv      NLS  profmem    cairo
    TRUE     TRUE     TRUE     TRUE     TRUE    FALSE     TRUE
}

4. Check and setting the bitmapType as cairo in R environment
{
>options(bitmapType="cairo")
}


Reference:
unable to start PNG / X11 in rstudio
How to get R to compile with PNG support
R install
R dowload

Centos x11





2013年8月8日 星期四

Java send mail using gmail and support utf-8 characters



Step 1. Download the jar
Download the jar of javax.mail.jar from oracle send mail , and I used the JavaMail 1.5.0 version of 


Step 2. Example Using connecttion to gmail
 please notice the red color character.
// ---------------
public void test_gmail2 () throws Exception {
      
            final String SMTP_HOST_NAME = "smtp.gmail.com";
            final String SMTP_HOST_PORT = "465";
            final String SMTP_AUTH_USER = "your_Gmail@gmail.com";
            final String SMTP_AUTH_PWD = "your_Gmail_Password";

            Properties props = new Properties();

            props.put("mail.transport.protocol", "smtps");
            props.put("mail.smtps.host", "smtp.gmail.com");
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.starttls.enable","true");
            props.put("mail.smtp.socketFactory.port", SMTP_HOST_PORT);
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.socketFactory.fallback", "false");
                  
            Session mailSession = Session.getInstance(props,  new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
                }
              });
            mailSession.setDebug(true);
            Transport transport = mailSession.getTransport("smtps");

            MimeMessage message = new MimeMessage(mailSession);
             message.setSubject("這是Testing SMTP-SSL");
            message.setContent("<h3>This</h3> is a test 信", "text/html;charset=utf-8");
          
         
            message.addRecipient(Message.RecipientType.TO, new InternetAddress("Sender_mail"));

          
            /**/
            transport.connect
              (SMTP_HOST_NAME, Integer.parseInt(SMTP_HOST_PORT), SMTP_AUTH_USER, SMTP_AUTH_PWD);

            transport.sendMessage(message,
                message.getRecipients(Message.RecipientType.TO));
            transport.close();
 }
    

2013年8月7日 星期三

Linux remove code previous number

we use the sed to replace the number is code
the first character can be space one number, the two number may a number

sed 's/^[ 0-9]*[0-9]//g' code.java





Reference
Sed RE pattern

Jquery can't change image refresh in Firefox and IE

1. Problem:
 Some times we try dynamic to change a picture in html,
and we assume this image is same,
in firefox and IE, this doesn't work,
and we happen is in captcha image.


2. Solution
This is because the firefox and ie seem the picture name is same, so they didn't send the request.  solution is add a random number in the request.
// HTML
<a href="" id="captcha_img_link"  title="Change img">chane</a>
<img id="captcha_img" align="middle" src="jcaptcha.jpg"  />


// Javascript
$(function (){
    // change image
    $('#captcha_img_link').click(function () {
        // Avoid the cache using appach random
        $("#captcha_img").attr('src',"./jcaptcha.jpg?random=" + Math.floor((Math.random()*20)+1));               
        return false;
    });
});




Reference:
How to force a web browser NOT to cache images

2013年7月31日 星期三

java eclipse JDK update JDK7_25 in linux

h3. Download SE for 64 bit for [oracle|http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html]

h3. Copy to directory and link
{code}
mv /home/Andy/IBMS/lib/jdk/jdk7_25/jdk1.7.0_25 /usr/java
unlink latest
unlink default
ln -s /usr/java/jdk1.7.0_25 latest
ln -s /usr/java/latest default
{code}


h3. Setup the run position
{code}
update-alternatives --install "/usr/bin/java" "javac" "/usr/java//jdk1.7.0_25/bin/javac" 1
update-alternatives --install "/usr/bin/javac" "javac" "/usr/java//jdk1.7.0_25/bin/javac" 1
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java//jdk1.7.0_25/bin/javaws" 1

[root@localhost java]# update-alternatives --config java

有 3 程式提供 'java'。

  選擇        指令
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /usr/java//jdk1.7.0_25/bin/java

請輸入以保留目前的選擇[+],或輸入選擇號碼:3
[root@localhost java]# update-alternatives --config javac
[root@localhost java]# update-alternatives --config javaws
{code}

h3. Setting Eclipse used JDK7

Choose Window->Preference, then click following content



h3. Setting project replace jdk6 to jdk7

your_Project (click mouse right button)-> properties \-> java build path \-> edit









Reference:
[How do I install Oracle Java JDK 7?|http://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7]
[Eclipse update|http://stackoverflow.com/questions/12588537/how-to-change-jdk-version-for-an-eclipse-project]


Reference:
[How do I install Oracle Java JDK 7?|http://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7]

2013年7月29日 星期一

PSQL string concate

1. Solution:
A. Using || symbol
select account||lastname from user where account = 'andy';







B. write the function
create or replace function concate(text,text) RETURNS text AS $$ SELECT $1 || '' ||$2; $$ LANGUAGE 'sql';
select concate(account,lastname) from user where account = 'andy';




Reference:
a-better-concat-for-postgresql
How to concatenate strings of a string field in a PostgreSQL
wiki Postsql

2013年7月28日 星期日

Struts2 Version 2.3.15 HelloWorld Setting

1. Problem:
There are some different after struts2 2.1.3, e.g. the library and the strtus.xml, web.xml setting file


2. Solution:
A. Downlaod form struts-2.3.15.1-lib.zip

B. Use the following Basic library, and copy to WebContent/WEB-INF/lib:
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.15.1.jar
xwork-core-2.3.15.1.jar

C. Writing the web.xml, there we use the StrutsPrepareAndExecuteFilter

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
   
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

D. Writing the struts.xml in Project_dir/Java Resource/src and write your action class
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.devMode" value="true" />
    <package name="default" extends="struts-default"> 
        <action name="hello" class="ibms.struts2.HelloWorldAction" method="execute">
            <result name="success">/HelloWorld.jsp</result>
        </action>
       
    </package>
</struts>


3. Reference
Difference between Struts 2 FilterDispatcher and StrutsPrepareAndExecuteFilter ?
struts2-hello-world-jsp-example-error



2013年6月12日 星期三

Linux ftp folder donwload


Solution:
wget -r ftp://user:pass@server.com/
 
 
 
Reference:  How do you recursively ftp a folder in linux



2013年6月6日 星期四

homozygous and heterozygos

An "allele" does not have zygosity...so it cannot be either hetero- or homozygous. An allele is defined as one of potentially many possibilities at a given location in a genome (a "locus").

A "locus" can be heterozygous or homozygous (among other things), meaning it either has two different alleles, or exactly the same two alleles.

Common SNP terminology is somewhat confusing...based on the acronym one would expect it to refer to a given allele at a specific position, and sometimes it does. However, "SNP" is more often used to refer to a specific base (the "locus") that has multiple possible alleles (for example, a A or a G).

So a heterozygous indel would be one copy of the specific lesion (an insertion or a deletion), the other strand lacking that particular insertion or deletion.

Hopefully that helps, if I didn't understand your question, let me know.


Reference:
http://seqanswers.com/forums/showthread.php?t=1175

Look other: Frequency of homozygous indels vs heterozygous indels

2013年5月28日 星期二

centos open directory in same window

Solution:

choose Edit->Preferences->Behaviour->Always open in browser window.

編輯-> 偏好設定->運作方式->總是以瀏覽視窗開啟

2013年5月10日 星期五

XSLT - eXtensible Stylesheet Language Transformations

1. Description:
Here we demonstrate a simple data.xml, and a showing transformation file of the xslt, then you can using browser to open the data.xml, browser will transform XML into HTML, before it is displayed by a browser.


2.  Code of data.xml
---------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<?xml-stylesheet type="text/xsl" href="data_xslt_test.xsl"?>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
         <artist>Bob Dylan</artist>
         <country>USA</country>
         <company>Columbia</company>
          <price>10.90</price>
          <year>1985</year>
     </cd>
      <cd>
                 <title>Hide your heart</title>
                  <artist>Bonnie Tyler</artist>
                   <country>UK</country>
                    <company>CBS Records</company>
                    <price>9.90</price>
                    <year>1988</year>
      </cd>
</catalog>
---------------------------------------------------
 Be carefully, this data.xml will refereence the style sheet of href="data_xslt_test.xsl"

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

file of  xslt of data_xslt_test.xsl
 <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>


3.  Open the data.xml with firefox
firefox data.xml


Reference:












2013年5月8日 星期三

IE Conditional Comments


Following is from the http://haslayout.net/condcom, more detail can reference it

Overview

IE Conditional Comments (or condcom for short) are special comments that enable authors to use the instructions that only Internet Explorer 5.0 and above on Windows platform will see.

Various types of conditional comments

Regular comment:
<!--This is a comment-->
IE conditional comment:
<!--[if IE]> <![endif]-->
Reversed anti-IE comment:
<!--[if !IE]>--> non-IE HTML Code <!--<![endif]-->
Reversed IE conditional comment (rarely needed):
<!--[if ! lt IE 7]>
    <![IGNORE[--> <![IGNORE[]]>
        Code for browsers that match the if condition
<!--<![endif]-->
In a nutshell, any browser except Internet Explorer on a Windows platform will treat conditional comment as a regular HTML comment. You cannot use condcoms in the CSS code itself. IE conditional comments are useful for hiding or revealing the code to IE, which in turn allows authors to use CSS "hacks" in a more appropriate fashion.



IE9 compatible mode

Problem:
 When you written in web page, if you have some CSS3 code, but the 
 IE9 browser open page using the quirk mode, and you will miss the your style,
 how do you setting the IE9 browser to standard mode??

Solution:
(a)  Before html, you can type the doctype
     <!DOCTYPE html>

(b)  in <head> </head> tag, adding the

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">



Reference:
DOCTYPE & Quirks Mode
Internet Explorer 9 (IE9) 的相容性檢視

2013年4月29日 星期一

Eclipse package meaning


Problem: what do different packages of eclipse like

Indigo
Helios SR1
Helios
Galileo
Ganymede
Europa


Solution: These are code names for major releases of the Eclipse IDE/platform. For example, I think Galileo was Eclipse 3.5. They started relying heavily on the code names about 4-5 years ago, not sure why - it can be confusing post-release.

Helios is the latest stable release. "SR1" means there's been a service release applied (bug fixes).


source: http://in.answers.yahoo.com/question/index?qid=20110121055244AAEgJAj

2013年2月24日 星期日

R plot png file on centos

Problem:
 When you run R on in primary centOS server, you didn't use the png. It will appear some error "Error in X11...unable to start device PNG".  "
"unable to open connection to X11 display "


Solution:
Install the package
{code}
>yum install libpng-devel.x86_64
{code}

{code}
R
# To avoid the x11 warning
Sys.setenv("DISPLAY"=":0.0")
{code}




Reference:
Install libpng package
Check the png Capabilities of R
R with x11 setting





2013年2月21日 星期四

R package install method

Currently, I only try the local method

For example install HSAUR: A Handbook of Statistical Analyses Using R package

1. Download the package from the cran HSAUR_1.3-0.tar.gz
2. R
>install.packages(file_name_and_path, repos = NULL, type="source")


Reference: How to install R package 
the possible method from network 

2013年2月18日 星期一

2013年1月9日 星期三

linux grep color setting


1. Solution
alias grep_gray="GREP_COLOR='1;30' grep --color=always"
alias grep_red="GREP_COLOR='1;31' grep --color=always"
alias grep_green="GREP_COLOR='1;32' grep --color=always"
alias grep_yellow="GREP_COLOR='1;33' grep --color=always"
alias grep_blue="GREP_COLOR='1;34' grep --color=always"
alias grep_magenta="GREP_COLOR='1;35' grep --color=always"
alias grep_cyan="GREP_COLOR='1;36' grep --color=always"

2. Example
echo hello there | grep_magenta ll | grep_yellow ere
hello there



Reference:
detail
linux color tutorial

2013年1月8日 星期二

Centos linux etc system config

1. Introduction
This is the nerve center of your system, it contains all system related configuration files in here or in its sub-directories. A "configuration file" is defined as a local file used to control the operation of a program; it must be static and cannot be an executable binary. For this reason, it's a good idea to backup this directory regularly. It will definitely save you a lot of re-configuration later if you re-install or lose your current installation. Normally, no binaries should be or are located here. [detail]



2. Category
[Network]
Firewall:  /etc/sysconfig/iptables , service iptable restart
DNS server: /etc/resolv.conf


[File System]
Files system: /etc/fstab, mount -a
Auto mount: /etc/auto.mnt, /etc/auto.master, service autofs restart