Learn more about Java

Java is powerful. It’s essential for any software developers. I should keep learning Java.

I will begin to review the data structure with java and practice myself tomorrow.

Convert String to xml with javascript

Use the following function to convert string to xml in javascript

function StringtoXML(text){
	if (window.ActiveXObject){
                  var doc=new ActiveXObject('Microsoft.XMLDOM');
                  doc.async='false';
                  doc.loadXML(text);
                } else {
                  var parser=new DOMParser();
                  var doc=parser.parseFromString(text,'text/xml');
	}
	return doc;
}
//voorbeeld toepassing:
var doc = StringtoXML(text);




We can also replace the string with regex

var s = "the batter hit the ball with the bat";

// Replace "the" with "a".
var re = /the/g;
var result = s.replace(re, "a");
document.write(result);
// Output: a batter hit a ball with a bat

Create a new html page by Javascript

When I’m doing the demo of our data visualizaion,  I need to create a new window to show the result.

If you want to create a new window by using javascript.Try following method.

 

var newWin = open(”,’Result of ColumnChartService’);// create a new window

newWin.document.write(“<html>Hello world</html>”);//write something into it
newWin.document.close();//close writing process

 

Notice! if you don’t write .close() in your javascript, it will cause some displaying problem.

configure: error: Cannot find OpenSSL’s on Mac

When I installed php-fpm on my mac today, this error occurred.

I tried a lot of solutions to solve this problem. It seems a common problem on mac.

Not sure the brew has fixed or not.

If you have this problem. Try the following methods:

First:

Sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ /usr/include

 

Then typing:

brew install php55

 

Second method:

 

brew install php55 –with-apache –with-fpm –with-homebrew-openssl=#{MacOS.sdk_path}/usr –with-thread-safety

 

 

Third method:

xcode-select –install brew install php55 –with-fpm brew link –overwrite php55

 

 

By the way ,this is the new way to start pfm

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell’s equivalent configuration file:

export PATH=”$(brew –prefix homebrew/php/php55)/bin:$PATH”

To have launchd start php55 at login:
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
Then to load php55 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

 

 

 

 

 

 

 

 


	

How to fix the 404 Not Found problem in wordpress

Usually this problem occurs when the permalinks type is postname.

Two methods to fix it.

First, check the .htaccess in the root file

The .htaccess should be something like this :

 

 

01

# BEGIN WordPress

02

<IfModule mod_rewrite.c>

03

RewriteEngine On

04

RewriteBase /

05

RewriteRule ^index\.php$ – [L]

06

RewriteCond %{REQUEST_FILENAME} !-f

07

RewriteCond %{REQUEST_FILENAME} !-d

08

RewriteRule . /index.php [L]

09

</IfModule>

 

Remember to  restart the server.

 

Second method is to check the config of apache.

You should enable mod_rewrite in apache server

Run this command:

sudo a2enmod rewrite

Code question: clone a graph

Question:Clone a graph. Input is a Node pointer. Return the Node pointer of the cloned graph.

A graph is defined below:
struct Node {
vector neighbors;
}

This question is copied from leetcode. The solution is good and I just want to mark the solution.

As you can see ,each node in the graph has many neighbours.

There is a special situation. When node A is captured, we begin to copy A’s neighbour node B. At the same time, A is also the neighbour of B. Therefore we will have a loop between node A and node B.

One way to fix it is using hashmap. We can record all the nodes that have already copied.

We can use the bread-first method to copy the entire graph.

First we can create a queue, then pop one node and push its neighbours into queue.

 

typedef unordered_map<Node *,Node *> Map;

Node *clone(Node *graph){

if(!graph) return null;

Map map;

queue<Node *> q;

q.push(graph);

 

Node *graphcopy=new Node();

map[graph]=graphcopy;

while(!q.empty()){

Node *node =queue.front();

q.pop();

int n=node.neighbors.size();

for (int i=0;i<n;i++){

Node *neighbor = node.neighbor[i];

if(map.find(neighbor)==map.end()){

Node *p=new Node();

map[node].neighbors.push_back(p);//add the neighbour node into copied node

map[neighbor]=p;//add a new node into hash table

q.push(neighbor);

}else{

map[node.neighbors.push_back(map[neighbor]);// add the neighbour node into copied node

}

}

 

}

 

}

 

 

 

Cross-browser implementation of jQuery.parseXML()

When using the jQuery.parseXML() in different browsers, the arguments of .find() are different.

eg:

<ser:dataURL>Here is a link</ser:dataURL>

If we try to use .find() to get the XML tag, it will cause problems between different browsers.

.find(“dataURL”) works in chrome and safari, but not in firefox and IE

.find(“ser\\:dataURL”) works in firefox and IE, but not in chrome and safari

Therefore, if we want to use jQuery.parseXML(), the format of .find should like : .find(“ser\\:dataURL,dataURL”)

This format works for both chrome and firefox