MyThinkPond

On Java, Python, Groovy, Grails, Spring, Node.js, Linux, Arduino, ARM, Embedded Devices & Web

Pictures from the Royal Palace Museum in Piazza San Marco, Venice, Italy

Posted by Venkatt Guhesan on August 26, 2014

Here are some pictures I took from the Royal Palace Museum in Piazza San Marco, Venice, Italy [map]
Shows you some of the wonderful Christian relics and how the royal family in Venice, Italy was involved in exploration of the new world, seafaring and art.

 

Posted in General, Travels | Tagged: , , , | Leave a Comment »

Photos from Venice, Italy

Posted by Venkatt Guhesan on August 21, 2014

Here are a few photos I took while in Venice, Italy.

 

Posted in General, Travels | Tagged: , , | Leave a Comment »

Beautiful Island of Santorini, Greece

Posted by Venkatt Guhesan on August 20, 2014

Here are a few photographs I took on a clear sunny day in the island of Santorini, Greece.

Beautiful city carved out of a violent burst of volcano – shows the greatness of humanity and what we can overcome with endurance and strength!

 

Posted in Travels | Tagged: , , , | 1 Comment »

Hello World with SparkCore

Posted by Venkatt Guhesan on June 17, 2014

Finally got my SparkCore, an Arduino built with on-board WiFi (no need for a Arduino WiFi shield). This version is a different take on the “Internet of Things” and “Build internet-connected hardware”

Here’s a picture of the Spark connected to the WiFi running my first HelloWorld app downloaded directly from the Spark IDE to the core.

Spark Core

Looking forward to building some designs around it! To learn more about Arduino and SparkCore visit their corresponding sites.

Happy Blogging!

 

Posted in Embedded Systems, SparkCore - Arduino | Tagged: , , , | Leave a Comment »

Switching back to wordpress site

Posted by Venkatt Guhesan on June 17, 2014

For the past year, I’ve tried to use my own hosted WordPress blog but I’ve noticed that my hits seems to be much higher on WordPress hosted site than my personal site. So I’ve decided to make my switch back to the WordPress hosted blog.

So starting today, both MyThinkPond.com and MyThinkPond.wordpress.com link back to the same blog site.

 

Posted in Uncategorized | Leave a Comment »

Grails 2.3.5 – grails stop-app – does not stop the app running via run-app

Posted by Venkatt Guhesan on February 2, 2014

If you’re using Grails 2.3.X and you’re developing, most likely you’re running your app like this:

grails run-app
#in one command-prompt/shell-terminal and
grails stop-app
#in another command-prompt/shell-terminal

With the latest version of Grails (version 2.3.5), the stop-app say:

grails stop-app
| Server Stopped
# But nothing happens and the server-process continues to run#

Here’s an undocumented fix that can come in handy:

# On terminal/command-prompt #1
# Run the way you do today
grails run-app
# On terminal/command-prompt #2, change-directory (cd) to the root folder where you have your Grails project
# Create a file with a file-name ".kill-run-app"
# For Linux (*Nix) environments
touch .kill-run-app
# For Windows where you do not have 'touch' command do the following instead
echo hello > .kill-run-app
# Wait for a few seconds and Grails will kill the app that's running

Now you can resume with starting a new instance of “grails run-app”.

Cheers & Happy Coding!

Posted in Grails, Groovy, Java | Tagged: , , , , | Leave a Comment »

Grails – Adding JavaScript to bottom of page

Posted by Venkatt Guhesan on February 2, 2014

In Grails using the templating (Sitemesh) if you were to include per-page JavaScript resources then it shows up much earlier in the layout content as part of the <g:layoutBody>

Here is an example illustrating the problem:

SamplePage.gsp

<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="layoutPage"/>
<head>MyThinkPond.com Custom Page</head>
...
</head>
<body>
Some this page content
<script type="text/javascript" src="${request.contextPath}js/samplePage.js"></script>
</body>
</html>

and the layout page (layoutPage.gsp)

<!DOCTYPE html>
<html>
<head>
<title><g:layoutTitle default="MyThinkPond.com"/></title>
...
</head>
<body>
<div>
Some template (header) content
<g:layoutBody/>
</div>
<!-- Common JS Files -->
<script type="text/javascript" src="${request.contextPath}js/common.js"></script>
<!-- Begin: Custom Page JavaScript Should Go Here -->
<!-- End: Custom Page JavaScript Should Go Here -->
</body>
</html>

results in the following page in browser

<!DOCTYPE html>
<html>
<head>
<titleMyThinkPond.com Custom Page</title>
...
</head>
<body>

<div>
Some template (header) content
Some this page content
<script type="text/javascript" src="${request.contextPath}js/samplePage.js"></script>
</div>

<!-- Common JS Files -->
<script type="text/javascript" src="${request.contextPath}js/common.js"></script>
<!-- Begin: Custom Page JavaScript Should Go Here -->
<!-- End: Custom Page JavaScript Should Go Here -->
</body>
</html>

You can see that the JavaScript is included as part of the body and not at the bottom.

Here’s how you resolve this issue:

In your custom page, define a content block like this:

SamplePage.gsp

<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="layoutPage"/>
<head>MyThinkPond.com Custom Page</head>
...
</head>
<body>
Some this page content
<content tag="javascript">
<script type="text/javascript" src="${request.contextPath}js/samplePage.js"></script>
</content>
</body>
</html>

In your template layout page add the content block to the bottom as needed like this:
layoutPage.gsp

<!DOCTYPE html>
<html>
<head>
<title><g:layoutTitle default="MyThinkPond.com"/></title>
...
</head>
<body>
<div>
Some template (header) content
<g:layoutBody/>
</div>
<!-- Common JS Files -->
<script type="text/javascript" src="${request.contextPath}js/common.js"></script>
<!-- Begin: Custom Page JavaScript Should Go Here -->
<g:pageProperty name="page.javascript"/>
<!-- End: Custom Page JavaScript Should Go Here -->
</body>
</html>

This will extract the JavaScript portion from samplePage and insert at the bottom of the layoutPage.

Here is the result of this magic in a page in the browser:

<!DOCTYPE html>
<html>
<head>
<titleMyThinkPond.com Custom Page</title>
...
</head>
<body>

<div>
Some template (header) content
Some this page content
</div>

<!-- Common JS Files -->
<script type="text/javascript" src="${request.contextPath}js/common.js"></script>
<!-- Begin: Custom Page JavaScript Should Go Here -->
<script type="text/javascript" src="${request.contextPath}js/samplePage.js"></script>
<!-- End: Custom Page JavaScript Should Go Here -->
</body>
</html>

You can see that the page specific JavaScript content got added towards the bottom as you intended it to be.

If this article has helped you, please add this article to your favorite social links so that others may also find this article.

Cheers & Happy Coding!

Posted in Grails, Groovy, Java | Tagged: , , , | 1 Comment »

Grails 2.X .gitignore file

Posted by Venkatt Guhesan on November 16, 2013

Grails

With a new Grails 2.X project you run into challenges on which folders to check-in into a GIT repository. You want to remove any non-essential files that Grails can rebuild at run-time. And if you are using either GITHub or BitBucket for your GIT repo’s the default .gitignore file created or provided by GITHub is setup for configured for a Grails 1.X project and not a Grails 2.X project.

 

 

 

So here are a few simple steps to help you create the correct .gitignore file for a Grails 2.X project:

Step-1: Create the following .gitignore file under the root Grails project folder:

*.iws
*Db.properties
*Db.script
.settings
.classpath
.project
.idea
eclipse
stacktrace.log
target
target-eclipse
/plugins
/web-app/plugins
/web-app/WEB-INF/classes
web-app/WEB-INF/tld/c.tld
web-app/WEB-INF/tld/fmt.tld

Step-2: Git does not allow you to check in empty (but essential folders). To avoid this you can run the following command:

find . -type d -empty -exec touch {}/.gitignore ;

The above command creates a empty “.gitignore” file below all folders. And since you now have non-empty folders, you can now check them in into Git so that if you check-out/clone the project in the future, you will have those essential but empty folders.

If you find this article useful, Tweet me on your Twitter account or +1 me on Google-Plus so that others can also benefit from this information.

Cheers

Posted in Grails, Groovy, Java, SourceControl - GIT | Tagged: , , , , | Leave a Comment »

Cubieboard2 with ARM AllWinner Processor – A20 finally arrived

Posted by Venkatt Guhesan on November 3, 2013

Cubieboard2 with ARM AllWinner Processor – A20 finally arrived. Pretty excited about building my ARM Linux embedded system.

CubieTruck

Learn more about Cubieboard here

Posted in CubieBoard2 & CubieTruck, Embedded Systems, Linux, Technology | Tagged: , , | Leave a Comment »

Working with zeromq (0mq), Java, JZMQ on a CentOS platform

Posted by Venkatt Guhesan on June 24, 2013

Recently I decided to port some of my development using ZeroMQ onto my CentOS development machine and I ran into some challenges. I’m documenting those challenges so that if someone else runs into the same pitfalls I did, they can avoid it.

In this example today, we will work with the first “HelloWorld” examples in the ZeroMQ guide found here. I added a few modifications to the sample such as a package name and a try-catch around the Thread and an exception.tostring() to display any stack-trace.

Source code for src/zmq/hwserver.java


package zmq;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.zeromq.ZMQ;

//
// Hello World server in Java
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//

public class hwserver {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ZMQ.Context context = ZMQ.context(1);
		// Socket to talk to clients
		ZMQ.Socket socket = context.socket(ZMQ.REP);
		socket.bind ("tcp://*:5555");
		try {
			while (!Thread.currentThread ().isInterrupted ()) {
				byte[] reply = socket.recv(0);
				System.out.println("Received Hello");
				String request = "World" ;
				socket.send(request.getBytes (), 0);
				Thread.sleep(1000); // Do some 'work'
			}
		} catch(Exception e) {
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			e.printStackTrace(pw);
			System.out.println(sw.toString());
		}
		socket.close();
		context.term();

	}

}

Similarly, source code for the client, src/zmq/hwclient.java

package zmq;

import org.zeromq.ZMQ;

public class hwclient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ZMQ.Context context = ZMQ.context(1);

		// Socket to talk to server
		System.out.println("Connecting to hello world server");

		ZMQ.Socket socket = context.socket(ZMQ.REQ);
		socket.connect ("tcp://localhost:5555");

		for(int requestNbr = 0; requestNbr != 10; requestNbr++) {
			String request = "Hello" ;
			System.out.println("Sending Hello " + requestNbr );
			socket.send(request.getBytes (), 0);

			byte[] reply = socket.recv(0);
			System.out.println("Received " + new String (reply) + " " + requestNbr);
		}

		socket.close();
		context.term();

	}

}

Now that you have the sample code, how do you compile using the ZeroMQ?

Assumption: You have installed Java (1.7 or above)

Step-1: Installing ZeroMQ onto CentOS [Following steps are performed under root account]

  1. Install “Development Tools” if it’s not already installed on your CentOS as root:        yum groupinstall “Development Tools”
  2. Download the “POSIX tarball”  ZeroMQ source code onto your CentOS development machine from here. At the time of writing this article, ZeroMQ version 3.2.3 was the stable release. You might want to download the latest stable release.
  3. Unpack the .tar.gz source archive.
  4. Run ./configure, followed by “make” then “make install“.
  5. Run ldconfig after installation.

Step-2: Installing a Language Binding for Java. In this case, we will use JZMQ from https://github.com/zeromq/jzmq

  1. Download the latest stable release from GITHub link above. (git clone git://github.com/zeromq/jzmq.git)
  2. Change directory, cd jzmq
  3. Compile and Install:
    ./autogen.sh
    ./configure
    make
    make install
    
  4. Where did it install?
    # JAR is located here: /usr/local/share/java/zmq.jar
    # .so link files are located here: /usr/local/lib
    
  5. Important Step: Add /usr/local/lib to a line in /etc/ld.so.conf (here is my copy after editing)
    include ld.so.conf.d/*.conf
    /usr/local/lib
    
  6. Reload “ldconfig“. This clears the cache.

 

Step-3: Compile and run the Java examples above.

cd ~/dev/zeromq/example/
# Compile hwserver.java
javac -classpath  /usr/local/share/java/zmq.jar ./zmq/hwserver.java
# Compile hwclient.java
javac -classpath  /usr/local/share/java/zmq.jar ./zmq/hwclient.java
# Run hwserver in a separate prompt
java -classpath .: /usr/local/share/java/zmq.jar -Djava.library.path=/usr/local/lib zmq.hwserver
# Run hwclient in a seperate prompt
java -classpath .:/usr/local/share/java/zmq.jar -Djava.library.path=/usr/local/lib zmq.hwclient

Output on the hwserver console:

Received Hello
Received Hello
Received Hello
Received Hello
Received Hello
Received Hello
Received Hello
Received Hello
Received Hello
Received Hello

output on the hwclient console:

Connecting to hello world server
Sending Hello 0
Received World 0
Sending Hello 1
Received World 1
Sending Hello 2
Received World 2
Sending Hello 3
Received World 3
Sending Hello 4
Received World 4
Sending Hello 5
Received World 5
Sending Hello 6
Received World 6
Sending Hello 7
Received World 7
Sending Hello 8
Received World 8
Sending Hello 9
Received World 9

Few interesting points to note are as follows:

  • What happens if you started the client first and then the server? Well, the client waits until the server becomes available (or in other words, until some process connects to socket port 5555) and then sends the message. When you say socket.send(…), ZeroMQ actually enqueues a message to be sent later by a dedicated communication thread and this thread waits until a bind on port 5555 happens by “server”.
  • Also observe that the “server” is doing the connecting, and the “client” is doing the binding.

What is ZeroMQ (ØMQ)?

(Excerpt from the ZeroMQ website!)

ØMQ (also seen as ZeroMQ, 0MQ, zmq) looks like an embeddable networking library but acts like a concurrency framework. It gives you sockets that carry atomic messages across various transports like in-process, inter-process, TCP, and multicast. You can connect sockets N-to-N with patterns like fanout, pub-sub, task distribution, and request-reply. It’s fast enough to be the fabric for clustered products. Its asynchronous I/O model gives you scalable multicore applications, built as asynchronous message-processing tasks. It has a score of language APIs and runs on most operating systems. ØMQ is from iMatix and is LGPLv3 open source.

If you find this article useful, please subscribe to my blog and/or share my link with others.

Posted in Java, ZeroMQ | Tagged: , , , , , | 1 Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 120 other followers