Tuesday, March 15, 2016

JQuery

1. ID selector and class selector in jQuery:

$("#LoginTextBox") -- Returns element wrapped as jQuery object with id="LoginTextBox" $(".active") -- Returns all elements with CSS class active.
2. How do you find all selected options of HTML select tag?
You can use following jQuery selector to retrieve all selected options of <select> tag with multiple=true :
$('[name=NameOfSelectedTag] :selected')

$('[name=NameOfSelectedTag] :selected').each(function(selected){
        alert($(selected).text());
});

3.
What is difference between detach() and remove() method in jQuery? (answer)
Though both detach() and remove() method is used to remove a DOM element,Main difference between them is that detach() keep track of the last element detached, so that it can be reattached, while remove() method does keep reference of last removed method. This is one of the many jQuery interview question from DOM manipulation. You can also take a look on appendTo() for adding element into DOM.
4.
How do you add and remove CSS classes to an element using jQuery? (answer)
By using addClass() and removeClass() jQuery methods. 

5.
What is difference between jQuery.get() and jQuery.ajax() method?
ajax() method is more powerful and configurable, allows you to specify how long to wait and how to handle error, get() is a specialization to over ajax just to retrieve some data.

Thursday, March 10, 2016

Java BigDecimal(String) and BigDecimal(double) 区别

将 double 转换为 BigDecimal,后者是 double 的二进制浮点值准确的十进制表示形式。返回的 BigDecimal 的标度是使 (10scale × val)为整数的最小值。
注:
  1. 此构造方法的结果有一定的不可预知性。有人可能认为在 Java 中写入 new BigDecimal(0.1) 所创建的 BigDecimal 正好等于 0.1(非标度值 1,其标度为 1),但是它实际上等于 0.1000000000000000055511151231257827021181583404541015625。这是因为 0.1 无法准确地表示为 double(或者说对于该情况,不能表示为任何有限长度的二进制小数)。这样,传入到构造方法的值不会正好等于 0.1(虽然表面上等于该值)。
  2. 另一方面,String 构造方法是完全可预知的:写入 new BigDecimal("0.1") 将创建一个 BigDecimal,它正好 等于预期的 0.1。因此,比较而言,通常建议优先使用 String 构造方法。
  3. 当 double 必须用作 BigDecimal 的源时,请注意,此构造方法提供了一个准确转换;它不提供与以下操作相同的结果:先使用 Double.toString(double) 方法,然后使用 BigDecimal(String) 构造方法,将 double 转换为 String。要获取该结果,请使用 static valueOf(double) 方法。

Friday, February 26, 2016

Java interview questions


The difference between the method sleep and wait

both throws InterruptedException (how to handle InteruptedException?)

Java return and finally - what will be printed out?

public void testFinally(){
   System.out.println(setOne2().toString());
}

protected StringBuilder setOne(){
   StringBuilder builder=new StringBuilder();
   try{
       builder.append("Cool");
       return builder.append("Return");
   }finally{
       builder.append("+1");
   }
}

protected StringBuilder setOne2(){
   StringBuilder builder=new StringBuilder();
   try{
       builder.append("Cool");
       return builder.append("Return");
   }finally{
       builder=null;
   }
}

Wednesday, February 17, 2016

About Marriage and divorce in Ontario

Q We are already married and do not have a marriage
contract. Now we think it might be a good idea to have
one. Is it too late?
A No, it’s not too late. You can sign a marriage contract after you
are married. Remember that it must be in writing and signed by
you and your spouse in front of a witness who must also sign the
contract. If you write your contract yourselves, each of you should
have your own lawyer look it over before you sign it.

Q I am getting married in a few months. I don’t own a lot but I
do have the china set my mother got when she was married.
It is worth about $2,000. When I marry, does the china set
become my husband’s too?
A No. The china is your property. If your marriage ends, you can
keep the china. But if the china has increased in value when your
marriage ends, you and your spouse will share the increase in
value.
If you have a marriage contract, it could say that the china is your
property and that any increase in the value of the china during
your marriage will not be shared with your spouse if your
marriage ends.

If you and your spouse cannot agree on how to settle the
issues between you, you can go to court and ask a judge to decide for
you.

Separation agreements and court orders resolve family matters
when you separate but they do not legally end your marriage. The only
way to do this is to get a divorce. Only a court can give you a divorce.

It’s my wife’s fault our marriage is over. She started seeing
someone else and has decided that she wants out of the
marriage. Why should I have to share the value of my
property with her now just so this new guy gets it?
A Your spouse’s new relationship has no effect on the division of
property at the end of your marriage. The law on dividing family
property has nothing to do with why your marriage has ended.
The law sees a marriage as an equal partnership. When it is
over, the financial benefits of the partnership have to be divided
evenly and fairly. The calculations are made without looking at
who is at fault or who is to blame.

Usually a spouse's behaviour does not affect how property is divided.

Tuesday, January 19, 2016

Solace JMS issue

Solace JMS provider implementation has an obvious bug, in SolMessageProducer.java, method
protected void sendMessage(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)

the parameter priority is never used, it sets the priority to 0 directly:
solMsg.setJMSPriority(0);

It causes that the JMSPriority cannot be set to other value. It exists until the current version: sol-jms-7.1.2.226

QBrowser is an excellent Java Swing GUI client. It can browse the queue/topic with minor modification.
https://java.net/nonav/projects/mq/sources/mq5/content/mq/src/share/java/examples/applications/qbrowser/QBrowser.java?rev=38

Hermes should be more powerful, but it's too complex and you can only treat it as a black box. I cannot configure it to connect Solace based on the below document. Already set SECURITY_PRINCIPAL to username@vpn Got the error
jndi lookup failed - 401 incomplete authentication configuration

http://dev.solacesystems.com/integration-guides/hermes-jms/

The JMS API provides no mechanism for browsing a topic. Messages usually disappear from a topic as soon as they appear: if there are no message consumers to consume them, the JMS provider removes them. Although durable subscriptions allow messages to remain on a topic while the message consumer is not active, no facility exists for examining them.

Wednesday, January 13, 2016

Git note

Git (DVCS)
Eclipse help on EGit is a good document to start Git
1. There is no master repository. No need to be online to perform actions.
2. Every changesets contain pointers to the previous changeset (with a unique hash value). Makes merge much easier.
3. Origin is the name of the default remote, but you can have many remotes per repository.
4. It's generally considered good practice to rebase changes prior to pushing to a remote tree to avoid these kind of fan-outs, but it's not necessary to do so.

Git Complete: The definitive, step-by-step guide to Git

1. Install Git
2.
Sign up and create a repository github-demo on (init with readme)
https://github.com
3.
Origin is the name of the default remote, but you can have many remotes per repository.
git config --list --show-origin
git version
git config --global user.name "xxx xxx"
git config --global user.email "xxxxxx@gmail.com"

You can verify this by the following two commands:
git config user.email
git config user.name

git config --global --list
git clone https://github.com/auspix/github-demo.git
git status
git add start.txt  --put the file from working directory to staging area
git commit -m "Adding start txt file" --move the file from staging to local repository
git push origin master --origin refers to the github copy of our repository, master refers to our default and only branch in the repository

4. Start with a fresh project
git init fresh-project
cd fresh-project/.git
cd ..
git status
5.
Download bootstap project from http://www.initializr.com/
cd C:\git\other_repo\initializr-verekia-4.0
git init
git status
git add .
git status
git commit -m "My first commit, inline"
git pull origin master --get changes from remote repo to local to make sure we are up-to-date, should always to a pull before a push
git push origin master
git help
git help pull
git help push
6.
go to the home folder, notepad++ .gitconfig
git config --global core.editor "'C:/Apps/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
git commit -am "Adding more messages" --to integrate add and commit into one single command
git ls-files    --show all tracked filese
git add .      --add all files under current folder recursivly
git reset HEAD level1-file.txt   --move back the file from staging to working area (opposite to git add level1-file.txt)
git checkout -- level1-file.txt  --discard changes in working directory and return to last commit
7.
git mv start.txt start2.txt  --rename the file name
git add -A      --add all files include the renaming and deletion, if you rename from OS, then use this command
git rm             --to delete the git indexed file
git log        --to show the commit history
git log -- level3-fileNEW.txt  --show the specified file log
8.
git diff                 --show the difference between working area and staging area
git diff HEAD       --show the difference between working area and local repo
git diff --staged HEAD  --show the difference between staging area and the local repo
git diff -- TheFile           --only compare the specified file
git diff master origin/masetr  --compare local repo with remote repo (origin/maseter)
9.
git branch mynewbranch    --create new branch
git checkout mynewbranch --switch to the new branch

10.
notepad++ .gitignore
fast forward merge is only possible if there's no commit on the target branch just like there's never new branch
git merge copyright-branch --no-ff      --disable fast forward merge
git checkout master
git merge simple-changes -m "Merging from branch simple-changes"

11.
git stash         --record the current state of the working directory and the index, but go back to a clean working directory.
git stash apply   --Like pop, but do not remove the state from the stash list.
git stash list    --show the stash
git stash drop    --drop the stash

12.
git tag myTag     --just a marker/label on current command (for milestone ...)
git tag --list
git tag --delete myTag

git push -u origin myNewBranch  # Pushes your newly created local branch "myNewBranch"
                                 # to the remote "origin".
To list all the remotes, run git remote


git pull = git fetch+ git merge。pull的话,拉取远程分支并与本地分支合并,fetch只是拉远程分支,怎么合并,可以自己再做选择。