Friday, July 10, 2015

Communication Between NodeJS Client and Matlab Server with Socket(TCP/IP)

Checkout Source Code


Run Matlab Server in one Terminal

$matlab -nodisplay

host='localhost';
port=5000;
s = server(host, port);
s.receive();
s.send('This is MatLab');
s.send('This is MatLab');

This is NodeJS
This is NodeJS
This is NodeJS

Run NodeJS client in another Terminal

$node

client = require('./client');
host='localhost';
port=5000;
c = new client(host, port);
c.receive();

This is MatLab
This is MatLab

c.send('This is NodeJS\n');
c.send('This is NodeJS\n');
c.send('This is NodeJS\n');

Friday, June 12, 2015

Call RabbitMQ in Matlab

--------------------------- ###Installation Environment ``` Ubuntu 12.04, 64-bit Matlab R2012a, 64-bit ``` --------------------------- ###Install Package Install open JDK and check the version ```bash sudo apt-get install openjdk-6-jdk sudo apt-get install openjdk-6-jre javac -version java -version ``` --------------------------- ###Code of Send.java and Recv.java Send.java ```java import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; public class Send { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); String message = "Hello World!"; channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); } } ``` Recv.java ```java import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; import com.rabbitmq.client.QueueingConsumer; public class Recv { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody(),"UTF-8"); System.out.println(" [x] Received '" + message + "'"); } } } ``` --------------------------- ###Compile and run Send.java and Recv.java ```bash wget rabbitmq-java-client-bin-3.5.3.zip unzip rabbitmq-java-client-bin-3.5.3.zip cp rabbitmq-java-client-bin-3.5.3/*.jar ./ javac -cp rabbitmq-client.jar Send.java Recv.java # This will produce Send.class and Recv.class ``` In one terminal ```bash java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send [x] Sent 'Hello World!' java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send [x] Sent 'Hello World!' ``` In another terminal ```bash java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Recv [*] Waiting for messages. To exit press CTRL+C [x] Received 'Hello World!' [x] Received 'Hello World!' ``` --------------------------- ### Run in Matlab ```matlab >> javaaddpath('/path/to/Send.class','/path/to/Recv.class', ... '/path/to/commons-io-1.2.jar', ... '/path/to/commons-cli-1.1.jar', '/path/to/rabbitmq-client.jar'); >> clientSend = Send; >> javaMethod('main', clientSend, '') [x] Sent 'Hello World!' >> javaMethod('main', clientSend, '') [x] Sent 'Hello World!' >> serverRecv = Recv; >> javaMethod('main', serverRecv, '') [x] Received 'Hello World!' [x] Received 'Hello World!' ``` --------------------------- ###Reference https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/java

Thursday, June 11, 2015

Three Ways to Call A Simple "Hello World" Java Program in MATLAB

--------------------------- ###Installation Environment Environment ``` Ubuntu 12.04, 64-bit Matlab R2012a, 64-bit ``` --------------------------- ###Install Package Install open JDK and check the version ```bash $ sudo apt-get install openjdk-6-jdk $ sudo apt-get install openjdk-6-jre $ javac -version $ java -version ``` A simple HelloWorld.java code ```java public class HelloWorld { public static void main( String args[] ) { System.out.println( "Hello World!" ); } } ``` --------------------------- ### The First Way Compile and run HelloWorld ```bash $ javac -cp %CLASSPATH:/path/to/matlab/jre HelloWorld.java $ jar -cvf library.jar HelloWorld.class ``` Example1.m ```matlab >> clear all; >> javaaddpath(/path/to/library.jar); >> HelloWorld ``` --------------------------- ### The Second Way Compile and run HelloWorld ```bash $ javac HelloWorld.java # This will produce a HelloWorld.class file $ java HelloWorld ``` Example2.m ```matlab >> java -version % consistent with the java version installed in system >> which classpath.txt % add the path HelloWorld.class to the end of classpath.txt >> javaaddpath(/path/to/matlab/HelloWorld.class); >> o = HelloWorld; >> javaMethod('main', o); ``` --------------------------- ### The Third Way Compile and run HelloWorld ```bash $ javac HelloWorld.java # This will produce a HelloWorld.class file $ java HelloWorld ``` Example3.m ```matlab >> java -version % consistent with the java version installed in system >> which classpath.txt % add the path HelloWorld.class to the end of classpath.txt /usr/local/MATLAB/R2012a/toolbox/local/classpath.txt >> o = HelloWorld; >> javaMethod('main', o, ''); ``` --------------------------- Reference: http://www.mathworks.com/matlabcentral/answers/99993-how-do-i-call-a-simple-hello-world-java-program-in-matlab https://sergiolima.wordpress.com/2009/10/15/using-java-objects-with-matlab/

Thursday, April 16, 2015

Build WebKit, JSC, MiniBrowser

```bash svn checkout https://svn.webkit.org/repository/webkit/releases/WebKitGTK/webkit-2.8.0 webkit ``` First, upgrade gcc and g++: ```bash sudo apt-get install python-software-properties sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install gcc-4.8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 sudo apt-get install g++-4.8 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 ``` Second, do the followings: ```bash Tools/gtk/install-dependencies Tools/Scripts/update-webkitgtk-libs Tools/Scripts/build-webkit --gtk --makeargs="-j24" # build whole webkit Tools/Scripts/build-jsc --gtk --makeargs="-j24" # build jsc cd webkit/WebKitBuild/Release make MiniBrowser -j5 # build MiniBrowsr ``` Third, launch MiniBrowser: ```bash Tools/Scripts/run-minibrowser --gtk ```

Wednesday, March 11, 2015

Highlight and Markdown Code

## Reference * [highlight](https://highlightjs.org/static/demo/) * [prism](http://prismjs.com/download.html) * [marked](https://github.com/chjj/marked) used for md syntax. ```markdown <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script src="https://github.com/PrismJS/prism/blob/gh-pages/prism.js"></script> <link href="https://github.com/PrismJS/prism/blob/gh-pages/themes/prism.css" rel='stylesheet'> <pre><code class="javascript"> function add(x, y){ return x+y; } var a = 11; var b = 22.5; var c = add(a,b); </code></pre> ``` ```html

function add(x, y){
    return x+y;
}
var a = 11;
var b = 22.5;
var c = add(a,b);
```