macOS – how to get familiar with VIM

If you have never ever worked with CLI (on macOS) I suggest to start with iTerm2: I just want you to know, this is my personal view, that iTerm2 is way better comparing to default Terminal – one that you can find inside /Applications/Utilities/

If you have never ever worked with VIM before, I strongly suggest to go through VIM tutorial. Start terminal application, and simply type vimtutor.

> vimtutor

You will find there lots of basics related to VIM: how to move around in the text, how to quit, how to edit and delete text, etc.

Just one comment from my side. Make sure to get familiar with lesson №1.2

Lesson 1.2: EXITING VIM

otherwise, you might get stuck forever ;)

After going through all the basics, I suggest jumping here: I am pretty sure, you will find this video very comprehensive. It covers lots of fancy features available in VIM.

Java preprocessor

If you have developed applications using C, you are probably aware of preprocessor. If you have ever worked with JNI code, you recall preprocessor’s directives for sure. You can find lots of them inside JNI based code generated through javah or javac -h.

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class recipeNo001_HelloWorld */

#ifndef _Included_recipeNo001_HelloWorld
#define _Included_recipeNo001_HelloWorld
#ifdef __cplusplus
extern "C" {
 * Class:     recipeNo001_HelloWorld
 * Method:    displayMessage
 * Signature: ()V
JNIEXPORT void JNICALL Java_recipeNo001_HelloWorld_displayMessage
  (JNIEnv *, jclass);

#ifdef __cplusplus

These directives let you change the code before it even gets compiled. This is quite powerful feature, it lets you adapt the code to environment you work with. It’s very useful while working with software, where various, incompatible, APIs must be supported – due to various factors.

You can also maintain different behavior in release and debug mode. You can simply control what gets into final version of the product.

It’s fairly easy to achieve similar (not exactly the same), behavior in Java. Java, by design, doesn’t provide preprocessor’s annotations. To get it working, you have to use some external preprocessing engine. Fortunately, there is one: <#FreeMarker>.

You can easily adapt it to get your Java source code preprocessed before it is being passed to Java compiler. Take a look below, inside jpp repo, to get the glimpse of what’s possible.

iPod shuffle – “-Voice Over, where have you been all my life?”

Have you tried to organize your songs into play lists? And that’s what you have in your little iPod shuffle?

“-All songs”
“-Play list one”
“-Play list two”
“-Play list three”

Man, this was driving me nuts. Fortunately, I found out that I could have “VoiceOver” turned on. After that happened, everything becomes way more simpler.

“-All songs”
“-/bʌɪ wʌns/” (do you know what that could be ;) )
“-Daft Punk”

Now, it is so much easier to jump between lists. To get it working, you have to check a little box, down in the settings. It is called – “Enable VoiceOver”

Logging – it can get really messy

There are different ways to create a log in Java

Recently, I have read quite interesing article regarding logs in Java – Logger to też jest biznes. I guess, it summarize experience of most of the people who work with Java code. I guess, most of us went throuhg different means of logging: System.out, Apache Log4j, Java platform based Logger, Apache Commons Logging, etc. We all have already been there. I bet, everyone has worked with different logger at least once during his/hers career. But it can get even worse.

Native code jumps in

There is even more into the game when you start embed native code calls inside Java code. And, there is a new player to the game, every time you call your Java from a native application (e.g. SOAP based calls from GSOAP based code). These are the places where real headache starts when it comes to Grand Logger Unification.

System.out is not always what you think it is

In general, all stdout streams (in different languages) are a little bit different things. System.out, stdout – in C, unit 6 – in Fortran, sys.stdout – in Python. All of these may behave slightly different and catching and piping data into one, unified logger might be a tricky thing to do. Remember that most of the legacy code, in C/Fortan, will typicaly print messages directly to stdout. You have to handle this situation somehow.

Getting rid of debug code – Apache FreeMarker to the rescue

If you code in C, you are probably familiar with preprocessor commands that can throw parts of the code away from your sources. It means that the code is really not there, in the final binary. This is something different comparing to logging with DEBUG level. In this case, there is no chance to accidentally call part of the code (e.g. by changing logger’s settings). This is just because of the fact, that code is not there. This might be useful in case you want to make sure nobody sees your “@#$%*&” messages – even accidentally.

You can easily simulate this kind of behavior with Apache FreeMarker.

Take a look below

import freemarker.template.*;
import java.util.*;

public class Parser {

  public static void main(String[] args) throws Exception {

    if(args.length != 2) {
      System.out.println("You have to specify source file and it's location");
      System.out.println("This way, you can easily parse lots of files with find");
      System.out.println("find src -name \"*.java\" \\");
      System.out.println("-exec basename {} \\; \\");
      System.out.println("-exec dirname {} \\; \\");
      System.out.println("| tr '\\n' ' ' | xargs java -cp .:./freemarker.jar Parser");

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_27);
    cfg.setDirectoryForTemplateLoading(new File(args[1]));
    Template temp = cfg.getTemplate(args[0]);

    Writer out = new OutputStreamWriter(System.out);
    Map root = new HashMap();

    root.put("debug", new Boolean(true));
    temp.process(root, out);

    root.put("debug", new Boolean(false));
    temp.process(root, out);

and let’s say, we have src structure like this


and file looking like this

public class Test {
  // Debugger is set to: ${debug?c}

  public static void main(String [] arg) {
    /*<#if debug>*/ System.out.println("DEBUG message"); /*</#if>*/
    System.out.println("This code is always executed");

we can easily generate debug/release versions of the file following way

> find src -name "*.java" \
-exec basename {} \; \
-exec dirname {} \; \
| tr '\n' ' ' | xargs java -cp .:./freemarker.jar Parser

It’s worth noting, that source file itself ( is a valid Java code. It means, we don’t destroy things to get FreeMarker features.

You can also find quite interesting approach to the topic here: Making fun with Java and C preprocessor. This is quite different approach as we end up with broken Java code. Still, if you generate your code automatically, it might be the case you don’t care much whether code compiles or not before it goes through the preprocessor.

And remember, that sometimes, printf is not a bad idea

A few well-chosen test cases and a few print statements in the code may be enough.

Some programs are not handled well by debuggers: multi-process or multi-thread programs, operating systems, and distributed systems must often be debugged by lower-level approaches. In such situations, you’re on your own, without much help besides print statements and your own experience and ability to reason about code.

— The Practice of Programming – Brian W. Kernighan and Rob Pike

Back to the future

Modern Fortran Explained: Incorporating Fortran 2018 by Michael Metcalf and John Reid is already on the way! I am still waiting for it to arrive. It will be some sort of back to the future ;) The oldest “modern” language with new, fancy, features ;)

This time, all in red ;)

Back in time

Sometimes, you need to go back in time. Recently, I had to develop simple log roller – I wanted to be system independent. Who would have guessed you could find a straightforward solution here ;)

As for the roller itself, you can find it here


I was playing with RStudio recently. And there was this annoying “issue” with plots. I am calling it “issue” as I am not quite sure whether this is a bug or a feature.

The problem was that plots were drawn outside plot area. Axises were missing, title was too high, etc.

I was trying to change plot margins, to squeeze the plot inside plotting area, change the font size, and nothing really worked.

What solved the problem was this tiny line of code

That’s it. All you have to do is to call And then, plot again.

Be careful with du

Recently, I was little bit surprised by the output of du command. It turned out that size of a directory can vary, heavily, depending on the filesystem that is used for storing files. I was examining the size of application at different locations and what struck me were the differences in size reports.

# at pfs
> du -s -h directory
16G	directory

# at afs
> du -s -h directory
6.3G    directory

# at tmpfs
> du -s -h directory
6.4G    directory

# how much space does it really take
> tar cf - directory | dd of=/dev/null bs=1M
6.7 GB copied, 23.1807 s, 291 MB/s

You’re simply the best, better than all the rest
Better than anyone, anyone I ever met

You can find very comprehensive launchd tutorial here:

Java 9/10 and macOS – issues with java.version

It looks like you have to be extra careful while working with recent releases of JDK for macOS.

If you want to get JVM’s version (while running application) there is a simple way of doing it.

public class Simple {
  public static void main(String [] args) {

However, you have to be extra careful in macOS. For JVM 9 and JVM 10 you will get “9” and “10” respectively. This might be an issue, especially when you parse the version String to get major/minor numbers

String version = System.getProperty("java.version");

// this will give you -1 (for JVM 9/10), and that's no good
int dotPos = version.indexOf('.');

The funny thing is, that moving to 10.0.2 will suddenly give you different format (proper one).

In fact, there is a completely new way of getting JVM version since release 9 – Runtime.version(). And this one, will give all the information you need.

public class Simple {
  public static void main(String [] args) {
    Runtime.Version jvmversion = Runtime.version();
    System.out.println("major: " + jvmversion.major() 
      + " minor: " + jvmversion.minor() 
      + " security: " +;

which will give you

major: 9 minor: 0 security: 0

And what is your preferred way of getting Java’s version while running the code?

bash 4.4 on macOS

# Get the sources

mkdir -p ~/opt/src
cd ~/opt/src
curl -O
tar zxf bash-4.4.tar.gz

# prepare place for installation
mkdir -p ~/opt/usr

# build the stuff
cd ~/opt/src/bash-4.4
./configure --prefix=$HOME/opt/usr
make install

# test the thing
$HOME/opt/usr/bin/bash --version

use it



So, you are telling me that you can distinguish colors ;)

Colors can be source of real fight between people. There is even dedicated chapter related to colors in book “Jak przestałem kochać design” by Marcin Wicha. If you want people to kill you, try the list below whenever you want to apply small changes to web page UI ;)

> colors()
  [1] "white"                "aliceblue"            "antiquewhite"         "antiquewhite1"       
  [5] "antiquewhite2"        "antiquewhite3"        "antiquewhite4"        "aquamarine"          
  [9] "aquamarine1"          "aquamarine2"          "aquamarine3"          "aquamarine4"         
 [13] "azure"                "azure1"               "azure2"               "azure3"              
 [17] "azure4"               "beige"                "bisque"               "bisque1"             
 [21] "bisque2"              "bisque3"              "bisque4"              "black"               
 [25] "blanchedalmond"       "blue"                 "blue1"                "blue2"               
 [29] "blue3"                "blue4"                "blueviolet"           "brown"               
[625] "thistle"              "thistle1"             "thistle2"             "thistle3"            
[629] "thistle4"             "tomato"               "tomato1"              "tomato2"             
[633] "tomato3"              "tomato4"              "turquoise"            "turquoise1"          
[637] "turquoise2"           "turquoise3"           "turquoise4"           "violet"              
[641] "violetred"            "violetred1"           "violetred2"           "violetred3"          
[645] "violetred4"           "wheat"                "wheat1"               "wheat2"              
[649] "wheat3"               "wheat4"               "whitesmoke"           "yellow"              
[653] "yellow1"              "yellow2"              "yellow3"              "yellow4"             
[657] "yellowgreen" 

Unit Testing iPhone Apps – picture is worth a thousand words

If you are looking for well prepared, well delivered (unfortunately little bit outdated) video training on Unit Testing, make sure to watch this one

In case you still struggle with some old Objective-C based code, this one might be a good choice when you want to move old stuff towards TDD approach.

You can read my review here: Unit Testing iPhone Apps by Dan Pilone and Courtney Nash

vi + which

Sometimes, you want to look at the command (where is it located), and then, you decide to actually take a look inside the file (e.g. script). Instead of copying and pasting location, do following

which perl
vi `!!`

Escape Java/XML

mkdir escapefromreality
mkdir lib
echo 'package escapefromreality;

import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils.Builder;

public class EscapeJavaCode {

  public static void main(String[] args) throws Exception {
    try {
      String strJava = FileUtils.readFileToString(new File("escapefromreality/"));

      String strXML = FileUtils.readFileToString(new File("sample.xml"));
    } catch(Exception ex) {
      // remember to handle the exception
}' > escapefromreality/

echo '<xml>
  <sample attr="Hello"/>
</xml>' > sample.xml

curl -O
tar zxf commons-text-1.4-bin.tar.gz \
  --strip-components=1 \
  -C lib/ \

curl -O
tar zxf commons-io-2.6-bin.tar.gz \
  --strip-components=1 \
  -C lib/ \

curl -O
tar -zxf commons-lang3-3.7-bin.tar.gz \
  --strip-components=1 \
  -C lib/ \

javac -cp lib/commons-text-1.4.jar:lib/commons-io-2.6.jar \

for filename in lib/*.jar; do

java -cp .:${CP} escapefromreality/EscapeJavaCode

You shouldn’t learn Vim for learning’s sake

I can see people around (on various blogs) saying “- I’ve never used Vim before, and it’s so cool. I really have to learn how to use Vim!”.

Just Don’t.

If you are using IntelliJ, NetBeans, Visual Studio, Eclipse, keep it that way. Don’t put yourself into this illusive thinking that by starting using Vim you will become some sort of expert or something.

The only situation in which learning Vim may be regarded useful is when you plan to work on CLI – a lot. That’s it. There are no other reasons.

So, ask yourself honestly “- Will I spend 3/4th of my day while working on some remote UNIX machine, using CLI all the time?”. If your answer is “- No, I won’t”, stick to the IDE you already know and don’t waste time on Vim. Learn something else.

However! If you really, really want to learn it. Make sure to look here: Mastering Vim and Learning vi and Vim editors also, take a look at Tuvim ;)

Slightly different point of view: Why Vim?

Coding time flies when you’re having fun


Everything should be kept as simple as possible, but no simpler.

Teaching kids is a hard work. By teaching I mean not lecturing, but real, efficient and full of fun explaining how things work. I still remember one of my first computer languages – LOGO. This was Atari time and we have learned principles of programming by learning how turtle works. It was fun, but at the same time, it had lots of limitations.

First of all, if you want to write LOGO code you have to know how to write. You have to type on the keyboard, and you have to pay lots of attention to syntax. And, to be honest, LOGO code isn’t that sexy.

You can “penup”, you can “pendown” and move around. Of course you can do a lot with LOGO, but let’s face it, having fun with LOGO requires lots of work to be done.

The limits of my language means the limits of my world.

If you want to teach kids computer programming, you should start with something that allows expressing relatively complex ideas using simple language. In my opinion, at the time of writing, Scratch is exactly this kind of language.

Power of Scratch lays in the simplicity of code building mixed with quick reward. You can make objects move on the screen with just few clicks. Let’s play small quiz – just to show a sample.

Quiz time: What can you do, using following elements

Well, you can do pretty much. You can develop simple game and this way let the kids understand basics of programming.

Teaching coding is a hard task. If you want to avoid typical “Hello world” approach while delivering lectures to kids, you should become familiar with Scratch. It pays off.

TIS-100 – nice brain teaser for people
who like Assembler

If you like brain teasers, there is this cool game: TIS-100.

It’s a game, where you are supposed to solve Assembler based problems. You have a reduced set of instructions: moving data, basic arithmetics, few conditional jumps, and only one register – ACC. Well, in fact there are two registers, but other one is only accessible via ACC. In early stages you don’t have neither memory not the stack. Port operations are blocking, so you have to make sure things goes smoothly between modules.

What I have found most funny for me, was that kind of feeling related to missing elements coming from “normal/typical” architectures. I missed all these simple elements like stack, numerous registers, memory. Once you start playing, you need to change typical, assembler based, approach as you work with heavily reduced architecture. Another limitation is that each node (where you can run the code) has 15 lines limit and, sometimes, you have to pass data to other module to make intermediate calculations.

Anyway, this game is a real fun if you like low level coding. Learning architecture and getting used to instructions set will take you approximately 15-30 minutes. And here, Hacker’s Guide, you can find very well prepared cheat sheet for TIS-100.

The game is really worth the money – it’s just 12 PLN this week (during Steam Summer Sale).

Killing all your VNC sessions at once


SESSIONS_NO=`vncserver -list | grep "^:" | tr '\t' ' ' | cut -f1 -d' ' | wc -l`

if [[ $SESSIONS_NO -ne 0 ]]; then
  for no in $(vncserver -list | grep "^:" | tr '\t' ' ' | cut -f1 -d' '); do
    vncserver -kill $no
  echo "There are no running VNC sessions for user: $USER"

Pegasus Workflow Management System + VMware Fusion

If you want to start your experience with Pegasus Workflow Management System I strongly advice to use ready to go Virtual Machine available for download. You can get it here.


After downloading it, open VMware Fusion and choose: File -> Import… and choose PegasusTutorialVM-4.7.4.ova (you can find it wherever you have stored it – probably inside Downloads). After choosing the file, you will see something like this

Press Continue. VMware Fusion will complain!

Don’t worry, it will import machine properly, eventually. Simply press Retry. After a while, you will be notified that import was finished.

Fusion may complain about upgrading machine to reflect most recent changes in your release. Feel free to upgrade your machine. Press: Upgrade.

After a while, you will be shown a clock on nice blue background. Just drag it and scroll up. Now, you are ready to log in into machine. Chose user tutorial and type in pegasus as password.

On the left side of screen you will find Terminal application. Double click it. Now, it is the time to start your first task. Go ahead and create your first task.