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 :(


Welcome back my friends :)


And Now for Something Completely Different – Król


Odczarowuje


Be careful with JVM library location while building JNI based code

In case you want to compile JNI based code on macOS, be careful. Pay attention to @rpath.

If you compile the code like this (it will work in Linux)

ld -L${JAVA_HOME}/lib/server -ljvm ...

you will end up with reference to /usr/local/lib/libjvm.dylib. You will end up with lots of issues as code might be running to some extent.

To make sure your code is properly linked with version you really want to use, make sure to use -rpath

ld -rpath ${JAVA_HOME}/lib/server -ljvm ...

This time, you will use libjvm.dylib that is coming from the location you are interested in.


And Now for Something Completely Different – Królestwo


Do kompletu to chyba brakuje jeszcze tylko Królewicza.


And Now for Something Completely Different – Wieczny Grunwald


Potrafi wciągnąć.


And Now for Something Completely Different – Modern Java in Action


If you have stuck with pre 1.8 Java but you have to go back to the future, it’s definitely worth it!


And Now for Something Completely Different – Serotonina


Po taniości :(


VNC – The first attempt to start Xvnc failed

At some point I was struggling with the strange issue. It came out of nowhere. VNC simply stopped working. Eventually, it turned out that reason was completely awkward. Missing directory on LD_LIBRARY_PATH. Yes, I know how it sounds, but it’s true. You can try it by yourself

> setenv LD_LIBRARY_PATH /some_fake_location
> vncserver -geometry 800x600

WARNING: The first attempt to start Xvnc failed, possibly because the font
catalog is not properly configured.  Attempting to determine an appropriate
font path for this system and restart Xvnc using that font path ...
Could not start Xvnc.


Xvnc TigerVNC 1.3.1 - built Nov 16 2016 13:38:44
Copyright (C) 1999-2011 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 11702000, The X.Org Foundation


Wed May  8 23:59:59 2019
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on all interface(s), port 5902
 vncext:      Listening for HTTP connections on all interface(s), port 5802
 vncext:      created VNC server for screen 0
(EE)
(EE) Backtrace:
(EE) 0: /usr/bin/Xvnc (xorg_backtrace+0x55) [0x5bb935]
(EE) 1: /usr/bin/Xvnc (0x400000+0x1bf7a9) [0x5bf7a9]
(EE) 2: /usr/lib64/libpthread.so.0 (0x2b8c5b8ad000+0xf370) [0x2b8c5b8bc370]
(EE) 3: /lib64/ld-linux-x86-64.so.2 (0x2b8c59945000+0x5f79) [0x2b8c5994af79]
(EE) 4: /lib64/ld-linux-x86-64.so.2 (0x2b8c59945000+0x86db) [0x2b8c5994d6db]
...
...
(EE) Segmentation fault at address 0x2b8c59b65de0
(EE)
Fatal server error:
(EE) Caught signal 11 (Segmentation fault). Server aborting
(EE)

Stopping node.js – an elegant way

If you want to stop node.js you have basically two ways:

– brute force (⌃ – C),
– gentle way, via socket inside your application.

I will show you how to do that using simple code (https://nodejs.org/en/about/).

/* app.js */
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Brute force

This is the simplest way, just kill your app inside console using Ctrl-C (macOS: ^-C). All we have to do is to start node (node app.js) and terminate it.

Gentle way

Here, we are using socket to listen for messages from client. We have to modify server a little bit, we have to add socket.

/* app.js */
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

const io = require('socket.io')(server);
io.on('connection', (socketServer) => {
  socketServer.on('stop', () => {
    process.exit(0);
  });
});

Make sure to install socket packages as well

> npm install socket.io
> npm install socket.io-client

Once we have server part, we can focus on client

/* app.stop.js */
const io = require('socket.io-client');
const socketClient = io.connect('http://127.0.0.1:3000/');

socketClient.on('connect', () => {
  socketClient.emit('stop');
  setTimeout(() => {
    process.exit(0);
  }, 1000);
});


What kind of programmer are you…
take this simple C based ‘loop’ test

You still remember good old days with your Atari/Commodore machine. You like to annotate the code and you miss line numbers so much

void main() {

loop:
  printf("Hello\n");
  goto loop;

}

You like it ‘low level’ style. In high school you were the master of assembler. There is nothing wrong about working with bare metal, close to the chip.

#include <setjmp.h>

jmp_buf ljenv;

void main() {

    setjmp(ljenv);
    printf("Hello\n");
    longjmp(ljenv, 0);

}

There is also nothing wrong with procedural languages. Do you recall ‘the father’ of clean procedural code – mister Pascal?

#define true 1

void main() {

  while( true ) {
    printf("Hello\n");
  }

}

You are the Z-generation coder. Scala is the language to rule them all. Recursion, recursion everywhere.

void loop() {
  printf("Hello\n");
  loop();
}

void main() {

  loop();

}

Invalid CSS after “body”: expected 1 selector or at-rule, was “{ “

This error drove me crazy for a while.

Find one difference :)

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css'

body { 
  padding: 0; 
}
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

body { 
  padding: 0; 
}

find without .git and .svn

> find . -not -iwholename '*.svn*' -type f -name "*"
> find . -not -iwholename '*.git*' -type f -name "*"

Apple keyboard symbols – how to type them

– U+2318
– U+2325
– U+21E7
– U+2303
– U+232B

If you don’t know how to type Unicode characters in mac OS, take a look here: Unicode frames in macOS.


Capture whole HTML page into PNG

1. Start Chrome
2. Open the page
3. Open DevTools (⌥⌘I)
4. Open the Command Menu (⇧⌘P)
5. Choose Capture full size screenshot


←Older