Notes

Tips for my future self

Note #7: Nested Promises in JavaScript

Jun 09, 19

In JavaScript, nested promises will automatically be flattened by .then and await: await Promise.resolve(Promise.resolve(5)) === 5. This will cause issues with asynchronous methods taking generic values; as they will behave different if they take a Promise than with any other object.

Read more...

Note #6: Weird blocking behaviour when using custom Java Input-/OutputStreams (eg. in conjunction with scanners)

May 04, 19

Java Scanners (and other classes) use buffering behind the scenes. Therefore, when experiencing unexpected blocking when using custom Java Input-/OutputStreams, additionally override the read(byte[], int, int) and write(byte[], int, int) methods along with their no-argument variants. Counter-intuitively, these may return less bytes than requested (but at least one), without blocking. However, the default implementation does not make use of that. Therefore, buffers use them to do non-blocking buffer reads.

Additionally, you might want to consider overriding flush() and available(), but these seem to be of lesser significance.

Note #5: Drag-scrolling a map out of a web browser window

Apr 12, 19

When creating a draggable map, it might act weird when you move your mouse too quickly or outside the window, for example:

drag me, I suck

However, if we listen to mouseup and mousemove on window or document, it works:

Read more...

Note #4: Forwarded ports from a VM don't work?

Mar 20, 19

If you’re running a process that listens on localhost in a Docker container/VM/…, and you want to access it from the outside world but it doesn’t work (even if forwarding works correctly), try explicitly setting the process host to 0.0.0.0 instead of 127.0.0.1. That may or may not fix it.

Note #3: Letter frequency analysis tool

Mar 20, 19

Here’s a simple tool to perform letter frequency analysis for characters and n-grams.

Read more...

Note #2: SCP Protocol

Mar 20, 19

The SCP protocol is largely undocumentated, which is why you’re left in the dark if you’re trying to write your own implementation. However, by experimenting, I found some of the inner workings, and also how to write your own client and server.

First of all you might want to think about whether you really want to make your own implementation, or whether the -S argument to change the transport layer is maybe sufficient already. The transport program must use stdin and stdout to communicate with scp. For detailed information, run scp -v -S echo 0.0.0.0:file.in file.out and scp -v -S echo file.in 0.0.0.0:file.out. Please make sure that you don’t accidentally print log messages or similar to stdout, as this will cause the process to fail.

If you decide you want to dig deeper, there are two undocumented scp flags. The first is -f, which reads from disk into stdout, and the other is -t, which writes to disk from stdin.

Read more...

Note #1: Quitting VIM

Mar 16, 19

Esc -> : -> q -> ! -> Enter

git config --global core.editor="nano" might help you, too :)