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.

Groovy

Groovy Installation



$ curl -s get.gvmtool.net | bash

$ source "/Users/uki/.gvm/bin/gvm-init.sh"

$ gvm install groovy

$ groovy -version

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

$ which groovy

/Users/uki/.gvm/groovy/current/bin/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.grawl()
me.alive()
me.name = "Uki"
me.sayHi me.name

Creature bear = new Creature();
bear.alive()


OUTPUT:

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



If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins

Groovy as DSL

http://docs.groovy-lang.org/docs/latest/html/documentation/core-domain-specific-languages.html

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins

Hadoop on Pi cluster

http://www.widriksson.com/raspberry-pi-hadoop-cluster/

UNIX: create symbolic link ln -s

Symbolic link is a directory that points to another directory:

$ sudo ln -s TARGET_DIR SYMBOLIC_LINK_DIR



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

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins

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:

http://www.oracle.com/technetwork/java/javase/downloads/index.html




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

sudo ln -s location_of_JDK "version_name"



for example:

$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/ 1.8.0_51




Uki@ Versions $ ls -al
total 72
drwxr-xr-x 12 root wheel 408 Jul 29 12:03 .
drwxr-xr-x 11 root wheel 374 Jul 29 11:50 ..
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 59 Jul 29 12:03 1.8.0_51 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/
drwxr-xr-x 7 root wheel 238 Jul 29 11:50 A
lrwxr-xr-x 1 root wheel 1 Jul 29 11:50 Current -> A
lrwxr-xr-x 1 root wheel 52 Jul 29 11:50 CurrentJDK ->/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
Uki@ Versions $


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

Uki@ Versions $ sudo rm -r CurrentJDK
Uki@ Versions $ sudo ln -s 1.8.0_51 CurrentJDK

Check that change took place: 


Uki@ Versions $ ls -altotal 72
drwxr-xr-x 12 root wheel 408 Jul 29 12:07 .
drwxr-xr-x 11 root wheel 374 Jul 29 11:50 ..
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 59 Jul 29 12:03 1.8.0_51 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/
drwxr-xr-x 7 root wheel 238 Jul 29 11:50 A
lrwxr-xr-x 1 root wheel 1 Jul 29 11:50 Current -> A
lrwxr-xr-x 1 root wheel 8 Jul 29 12:07 CurrentJDK -> 1.8.0_51
Uki@ Versions $ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)










~~~~~~~~~~~~~~~~~~~~~~~










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)









http://stackoverflow.com/a/23396850/3566154










If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins

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.



Result:


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