Friday, May 22, 2015

Linux tail command

To constantly monitor log files being appended, you can use:

tail -f /var/log/xyz*.log

if you want to see last 200 lines added:

tail -n 200 /var/log/xyz*.log

note the asterisk "*" symbol, that monitors ALL logs that meet the pattern, which is helpful with log names ending with DATE.

Tuesday, May 19, 2015


Groovy Installation

$ curl -s | bash

$ source "/Users/uki/.gvm/bin/"

$ gvm install groovy

$ groovy -version

Groovy Version: 2.4.3 JVM: 1.7.0_79 Vendor: Oracle Corporation OS: Mac OS X

$ which groovy


To add Groovy permanently to your Terminal  PATH

edit ~/.bash_profile
# Groovy updated May 19, 2015
export GROOVY_HOME=/Users/uki/.gvm/groovy/current
export PATH=${PATH}:${GROOVY_HOME}/bin

First Script

groovy_scripts $ cat hello.groovy 

println 'Hello from Groovy'
groovy_scripts $ groovy hello

Hello from Groovy

Groovy Console

Groovy Console is good for quick testing of Scripts, especially copy and paste from the Web.

$ groovyConsole

interface Alive{
   void alive()

class Creature implements Alive{
    def grawl() {
        println(" Grrrrrrrr!!! grawls the Creature")
    void alive()
        println(" Grrrrr!!! thinks the Creature")

class Human extends Creature {
    String name;
    def sayHi(name) {
        println(" Hi, my name is $name! says the Human")
    void alive()
        println(" I am alive! says the Human")

Creature me = new Human()
me.alive() = "Uki"

Creature bear = new Creature();


uki@ groovy_scripts $ groovy hello
 Grrrrrrrr!!! grawls the Creature
 I am alive! says the Human
 Hi, my name is Uki! says the Human

 Grrrrr!!! thinks the Creature

Groovy as DSL

Hadoop on Pi cluster

Thursday, May 14, 2015

UNIX: create symbolic link ln -s

Symbolic link is a directory that points to another directory:


Example 1:

$ cd /System/Library/Frameworks/JavaVM.framework/Versions

$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/ "1.8.0_20-ea"
$ ls -alt
lrwxr-xr-x  1 root  wheel   59 May 14 16:24 1.8.0_20-ea -> /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/

Example 2:

Debian linux Apache location: /var/www
Mac Apache default location: /Library/WebServer/Document

On Mac to mimic the Debian linux's Apache server in /var/www you can create a symbolic link that points to Mac's default server location:

$ sudo ln -s /Library/WebServer/Documents www

originally posted on 7/24/2009

Switching version of Java on Mac

To check the currently installed version of java on your Mac:

$ java -version
java version "1.6.0_65"

(Welcome back to 2006!)

You can download Java 1.7, 1.8 and 1.9 at Oracle and write down WHERE they install it:

Using SYMBOLIC LINKS I created locations of my various Java locations:

sudo ls -s location_of_JDK "version_name"

uki@ CNH_PROD $ cd /System/Library/Frameworks/JavaVM.framework/Versions/
uki@ Versions $ ls -al
total 88
drwxr-xr-x  3 root  wheel  476 May 17 11:07 .
drwxr-xr-x  3 root  wheel  408 Apr 22 13:02 ..
lrwxr-xr-x  1 root  wheel   10 Jan 31 19:01 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Jan 31 19:01 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Jan 31 19:01 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Jan 31 19:01 1.5.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Jan 31 19:01 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Jan 31 19:01 1.6.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   59 May 14 16:38 1.6.0_65 -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
lrwxr-xr-x  1 root  wheel   58 May 14 16:48 1.7.0_79 -> /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents
lrwxr-xr-x  1 root  wheel   59 May 14 16:24 1.8.0_20-ea -> /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/
drwxr-xr-x  7 root  wheel  272 Dec  3 09:47 A
lrwxr-xr-x  1 root  wheel    1 Jan 31 19:01 Current -> A
lrwxr-xr-x  1 root  wheel   59 May 17 11:07 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/
uki@ Versions $ 

now I can switch my Java to 1.8 by redirecting CurrentJDK:

$ sudo rm -r CurrentJDK

$ sudo ln -s 1.8.0_20-ea CurrentJDK

And back to 1.7:

uki@ Versions $ sudo rm -r CurrentJDK
uki@ Versions $ sudo ln -s 1.7.0_79 CurrentJDK
uki@ Versions $ java -version
java version "1.7.0_79"


It is also useful to create JAVA_HOME as a lot of apps use that.

Open your shell startup script, most of the time it is ~/.profile

edit ~/.profile


# JAVA updated: May 14, 2015
# other versions: /System/Library/Frameworks/JavaVM.framework/Versions/

# set up what CURRENT points to

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

# add Java home to path
export PATH=${PATH}:${JAVA_HOME}/bin


$ java -version
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b05, mixed mode)

If you mess up you will get messages like:
 $ java -version
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/bin/java" (-1)

That is because the folder you point at has to have /bin/java in it.

Please note that your system Java level is independent from you Android Eclipse Java setting (1.6)

Tuesday, May 5, 2015

Java: Generics, instanceof

In this exercise you will practice Java Generics, and instanceof operator

Note, you will have to implement Book, EBook and PaperBook classes on your own.

Java: concurrency with Runnable

In this simple tutorial we will see how to process some work in multiple threads using limited pool of x threads. Please note that there is an overhead in using threads.

You could use number of available CPUs as your pool size.


CPUs 8
thread with value 1 current sum 3
thread with value 2 current sum 3
thread with value 3 current sum 6
thread with value 4 current sum 10
thread with value 5 current sum 15
thread with value 6 current sum 21
thread with value 7 current sum 28
thread with value 8 current sum 36
final sum 120
thread with value 11 current sum 66
thread with value 13 current sum 91
thread with value 15 current sum 120
thread with value 9 current sum 45
thread with value 14 current sum 105
thread with value 12 current sum 78
thread with value 10 current sum 55

Tuesday, April 28, 2015

Android: Create Camera App in IntelliJ

Create new Android Module

Name the application
Name the main Activity class

Name the Module and its location
Choose API 17 or higher

  • In Preferences, find Java Compiler
  • Add your project (AndroidCamera)

Set Java Compiler to Java 1.6

Set Module Language Level also to Java 6

Run the MainActivity class

Select emulator

follow the code tutorial :

Tuesday, April 21, 2015

Java: introduction to Java Android programming

Since Android is one of the most prolific uses of Java UI today, we will do a short overview of that platform. We will use the same IntelliJ IDEA we use for or regular java programming.

Android SDK setup:

First of all we have to make sure our IDE has Android plugin:

Download at least one SDK level e.g. API 17:

Create a new Android MODULE:

Name the Module:

Accept default Module SDK, you should have API 17 or up:

Set output path:

Try to run the project:

Android (with ANT) project structure, please not it is different from Maven, or Gradle structure:

We will create an app as such:

With following structure:

Please follow the rest of the tutorial here: