_JAVA_OPTIONS will not always work for your Java code

It’s good to know, that _JAVA_OPTIONS will not always work in your Java code. Especially, when you elevate privileges using sudo.

Let’s say we have this simple code

public class Simple {
  public static void main(String [] arg) {
    System.out.println("Hello from Simple!");
  }
}

and we run it following way

> export _JAVA_OPTIONS="-Xms1G"
> java Simple
Picked up _JAVA_OPTIONS: -Xms1G
Hello from Simple!
> sudo java Simple
Password: 🔑
Hello from Simple!

As you can see, in case of second execution _JAVA_OPTIONS were not picked up. The reason for not picking it up follows

/* ./hotspot/share/runtime/arguments.cpp */ 

// Don't check this environment variable if user has special privileges
// (e.g. unix su command).
if (buffer == NULL || os::have_special_privileges()) {
  return JNI_OK;
}

The submit token is NOT YOUR LOGIN PASSWORD.

If you are trying to submit your solution using sbt, like this.

> sbt submit user@some.address.com SoMeToKeN
...
...
[error] Invalid input to `submit`. The required syntax for `submit` is:
[error] submit <email-address> <submit-token>
[error]
[error] The submit token is NOT YOUR LOGIN PASSWORD.
[error] It can be obtained from the assignment page:
[error] https://www.coursera.org/learn/scala-spark-big-data/programming/CfQX2
[error] or (for premium learners):
[error] https://www.coursera.org/learn/scala-spark-big-data/programming/QcWcs
[error]
[error]
...
...

you might find this one a solution for you. Start sbt, and run submit from there.

> sbt
> submit user@some.address.com SoMeToKeN
[info] Attempting to submit "wikipedia" assignment in "scala-spark-big-data" course
[info] Using:
[info] - email: user@some.address.com
[info] - submit token: SoMeToKeN
[info] Connecting to Coursera...
[info] Successfully connected to Coursera. (Status 201)
[info]
[info] Assignment submitted successfully!
[info]
[info] You can see how you scored by going to:
[info] https://www.coursera.org/learn/scala-spark-big-data/programming/CfQX2/
[info] or (for premium learners):
[info] https://www.coursera.org/learn/scala-spark-big-data/programming/QcWcs
[info]
[info] and clicking on "My Submission".

sign_and_send_pubkey: no mutual signature supported – macOS 10.14

Just add this one inside ~/.ssh/config.

Host *
  PubkeyAcceptedKeyTypes=+ssh-dss

And Now for Something Completely Different – Zbudzone furie

The dusk was repeating them in a persistent whisper all around us,
in a whisper that seemed to swell menacingly
like the first whisper of a rising wind.
‘The horror! The horror!’


And Now for Something Completely Different – Upadłe anioły

Jedyne co mogę powiedzieć na temat tej książki, to: a = g⋅sinα


Kindle Paperwhite and hard space issue

Recently I have encountered quite frustrating issue with Kindle Paperwhite (3rd) and hard spaces inside Mobi document. At the same time (while buying the book) I have download three, different, formats: epub, Mobi and RTF. All of these have hard spaces all over the place in document. However, there is a slight difference in the way these hard spaces are treated in Books and Kindle (both physical device and application).

In Kindle, there is an issue with selecting single words. If there are hard spaces surrounding the word, everything, together with adjacent words is selected. This prevents dictionary from kicking in. In this sample, I am trying to select word: “спины”.

As you can see, no matter what you do, there is no chance to select the word you are looking for. This is quite frustrating as you can’t lookup words in the dictionary which makes reading Kindle quite pointless (especially when you are reading in foreign language).

Now, the funny thing is that Books – you have it installed on iPad – can handle hard spaces way better. They treat hard space as a regular one, thus, allowing to select single word. In the very same book, opened using Books, I can easily select the word: “спины”.

Which makes it way better experience while reading books for which you have to have access to dictionary. Now, as I don’t give up quite easily and I wanted to use Kindle Paperwhite for that particular book, I tried to approach topic from different angle. It turned out the solution was very simple. All I had to do was taking RTF file (one that I have downloaded together with epub and Mobi), replace all hard spaces with regular ones, and send it to my Kindle’s e-mail. That’s it. Once file was downloaded (it’s not Mobi but who cares) everything worked as expected.

Now, I can lookup words inside Kindle’s dictionary without any issues.

Anyway, I think it would be cool to have this kind of support out of the box inside Kindle, so it’s possible to select the word that is surrounded by hard spaces. The same way, Books allows to select it. If you have the very same issue, try to replace spaces inside your doc and have fun :)


Samsung and scanning to PDF in macOS Mojave

… is broken. There is no way to use default Image Capture application with Samsung SCX-4500W printer. However, there is hope :)

You can download Samsung Easy Document Creator from here: link. Please note that Samsung line of printers was acquired by HP – this is why you have to download application from HP’s pages.

When you open this page, make sure to choose macOS 10.3 – there is no application for macOS Mojave.

Once application is installed, you can use it for scanning pages directly to PDF files – it will not crash the same way Image Capture does. Also, you will be able to open files inside Preview :)


How to get JAR location from JNI


And Now for Something Completely Different – Wojtek Justyna TreeOh!

Radio RAM nie zawodzi ;)

Tym razem, dzięki nim, dowiedziałem się o zespole Wojtek Justyna TreeOh!. Grają niesamowicie sympatyczny, spokojny, nieprzekombinowany Jazz, którego bardzo miło się słucha – szczególnie wtedy, gdy za oknem robi się ciemno. Nienatarczywy towarzysz wieczornej lektury książek, ale jako tło dla domówki też sie nada.

A tutaj link do ich strony na bandcamp: https://wojtekjustynatreeoh.bandcamp.com

Zdecydowanie warto


And Now for Something Completely Different – Altered Carbon

Zdecydowanie lepsza od interpretacji Netflixa


And Now for Something Completely Different – Company of One

Company of One is … everything


eternity – defined using macOS keyboard settings

To learn what eternity means, change your keyboard setting from this

to this


Running JAR file from R using rJava (without spawning new process)

Let’s say we have this, very simple, structure of the project

.
|-- Manifest.txt
`-- src
    `-- somepackage
        `-- StringTest.java

where StringTest.java is a very simple Java class

package somepackage;

public class StringTest {
  public String changeString(String str) {
    return "I have changed the string: " + str;
  }

  public static void main(String [] arg) {
    System.out.println(new StringTest().changeString("Hello"));
  }
}

while Manifest.txt contains

Manifest-Version: 1.0
Main-Class: somepackage.StringTest

We can easily create JAR (“executable”) from these files using jar application

# create JAR
> jar cfm test.jar Manifest.txt -C target somepackage/StringTest.class

# execute JAR
> java -jar test.jar
I have changed the string: Hello

Now, let’s try to run this code inside R. It’s quite straightforward.

# make sure R will be able to pick it up
> export CLASSPATH=./test.jar
> R

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

...
...
...

> library(rJava)
> .jinit()
> obj <- .jnew("somepackage.StringTest")
> s <- .jcall(obj, returnSig="V", method="main", c("Hello", "Hello") )
I have changed the string: Hello
>

R, Java 11 and making sure you can load rJava

As usual, there are some issues with new Java releases (11 and 12) and R. If you want to run rJava package inside R you have to do few things.

First, make sure you are using Java 11 as default inside terminal session. Inside ~/.profile add this line

export JAVA_HOME=$(/usr/libexec/java_home -v 11)

Once it’s done, you have to make sure to install XCode – you can find it here: XCode. We will need that. XCode contains SDK that is used while R reconfigures itself – it will try to compile small, JNI based, code.

After XCode is installed, make sure to modify this file: /Library/Frameworks/R.framework/Versions/3.4/Resources/etc/Makeconf.

Try to locate the line that reads

CPPFLAGS = -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

and replace it with line

CPPFLAGS = -isysroot  /Applications/XCode/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/
 -I/usr/local/include

Note! Make sure this is just one line inside Makeconf!

Now, you are ready to configure R. Simply call this one

> sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME}/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar

That’s it. You can now install and use rJava package.

Let’s say you have this simple code

.
`-- src
    `-- somepackage
        `-- StringTest.java

and the content of file is

package somepackage;

public class StringTest {
  public String changeString(String str) {
    return "I have changed the string: " + str;
  }

  public static void main(String [] arg) {
    System.out.println(new StringTest().changeString("Hello"));
  }
}

You can compile it following way.

> javac -d target src/somepackage/StringTest.java
> java -cp target somepackage.StringTest
I have changed the string: Hello
> export CLASSPATH=`pwd`/target

and then, use it inside R.

> R

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
...
...
...

> library(rJava)
> .jinit()
> obj <- .jnew("somepackage.StringTest")
> s <- .jcall(obj, returnSig="Ljava/lang/String;", method="changeString", "Hello")
> print(s)
[1] "I have changed the string: Hello"
> s <- .jcall(obj, returnSig="V", method="main", c("Hello", "Hello") )
I have changed the string: Hello

macOS boots to black screen of emptiness

1. disable Night Shift

It looks like Mojave 10.14.5 has some issues with booting when display colours are adapted to night mode using Night Shift.

After starting up my macOS based machine in the evening (when Night Shift kicks in with all the fancy colour settings) I have noticed that machine boots into black screen. To get screen back, I had to unplug HDMI and put it back.

As I already had some issues with f.lux in the past, I decided to disable Night Shift and give it a try. Guess what, with Night Shift disabled it boots as expected.

If you have similar issue, try to disable Night Shift and restart your machine.

2. Reset the System Management Controller (SMC)

Unplug your stationary Mac computer, wait 15 seconds, plug power back and turn power on.

3. Reset the System Management Controller (SMC) using keyboard

Press Shift - Control - Option when your macOS is turned off. While keeping keys pressed press and hold Power for 15 seconds. Your Mac will turn on and off at some point.

After 15 seconds, release everything and turn your Mac on again.

source: SMC

4. Use USB-C + adapter

Man, this is driving me crazy. I still have to fight this issue. I guess, I will wait for 10.14.6. So far, the only permanent solution was to switch to USB-C instead of using HDMI.


macOS Mojave and accessing TimeMachine’s
data from command line (iTerm2)

Whenever I restore (setup) new Mac, I do it manually. I simply install clean system, and transfer what I really need from TimeMachine’s backup – typically using CLI. In Mojave it’s a no-no.

If you use iTerm2, you will face following issue while accessing data inside TimeMachine’s storage.

> cd /Volumes/TimeMachine/Backups.backupdb/
> ls
ls: .: Operation not permitted

What you have to do, is adding iTerm2 to the list of trusted apps. Go to
System Preferences -> Security & Privacy -> Privacy
and make sure iTerm2 can access hard drive of TimeMachine.


Passing vector of vectors to Java from C++ using JNI

While using JNI, it becomes a little bit of burden whenever you want to pass something more complex than simple types back to Java.


How to find files that have certain string in last line

Let’s say you have few files

string
|-- 1
|-- 2
|-- 3
|-- 4
|-- 5
|-- 6
|-- 7
|-- 8
`-- 9

And they may end with two different endings: aaa or bbb.

Finding list off files that have given string at the end can be done following way

> find string -name "*" -exec tail -v -n1 {} \; | grep "bbb" -B1

on macOS you have to go slightly different way

> find string -name "*" | xargs tail -1 | grep "bbb" -B1

Running Java code in R

Let’s say you have a Java class StringTest

package somepackage;

public class StringTest {
    public String changeString(String str) {
        return "I have changed the string: " + str;
    }
}

inside file

src
`-- somepackage
    `-- StringTest.java

and you want to run it in R. All you have to do is to compile the code.

> javac -d target src/somepackage/StringTest.java

You will get compiled version of your class – it will have class extension.

target
`-- somepackage
    `-- StringTest.class

This is the class you want to run. Let’s take a look at R.

> R
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
...
...
> # if you don't have rJava installed yet, install it
> install.packages("rJava")
...
...
> library(rJava)
> # initialize Java environment
> .jinit()
>
> # we have to tell rJava where to look for our class
> .jaddClassPath(paste(getwd(),"/target", sep = ""))
>
> # we can create instance of our class
> obj <- .jnew("somepackage/StringTest")
>
> # and call the method with arguments
> result <- .jcall(obj, returnSig="Ljava/lang/String;", method="changeString", "Hello world!")
> result
[1] "I have changed the string: Hello world!"
>

Sometimes, it’s hard to say what is the signature of methods (e.g. it may have lots of arguments, strange return type). You can easily find the signature using javap.

> javap -cp target somepackage.StringTest
Compiled from "StringTest.java"
public class somepackage.StringTest {
  public somepackage.StringTest();
  public java.lang.String changeString(java.lang.String);
}

In case you have issues while installing rJava on macOS, make sure to take a look here: R 3.4, rJava, macOS and even more mess ;) and here: R, Java, rJava and macOS adventures.


And Now for Something Completely Different – Interwencje 2


Zbiory felietonów – one zawsze niosą ze sobą pewne ryzyka :(


←Older