Breadth-First Search with Java 8 Stream API

I recently had the problem to walk through some data and collect elements on the go. I thought it would be nice to use the (relatively) new Stream API in Java 8. After a short search in “the internet” I found a solution in this blog post for tree structures and in this one for recursing through a file system (which is a tree structure again). So, story told? No way! I needed to walk through graph structures (i.e., there might be cycles in it). In contrary, the solutions above will run forever, or more precisely they will terminate relatively fast with a StackOverflowException.
(more…)

Read More

Lazy Recursive Drill-Down of Tree Structures in Swift 2.1

I really do like the Swift programming language, because of features like multiple return types, nice support for optionals, value types (i.e., structs), enums with associated values, method overloading just with the return type, operator overloading, and many more.

But there are some language decision that are quite alien to me and I want to write them down (and my workarounds to them, which might help you), starting with this post. Perhaps you (yes I mean you 🙂 ) have a better answer for me, then please comment.
(more…)

Read More

LaTeX: replacing “-quotation marks with \glqq{} and \grqq{} in vim

If you ever had the problem that your LaTeX document contains wrongly formatted quotation marks (either in a german or english text), you most likely went all the way through your document searching for quotation marks and replacing them accordingly. Here are easy vim commands using the substitution feature (similar to the unix sed command) to replace all occurrences of quotation marks with the correct replacement for english texts:

:0,$s/\(\s\)"/\1``/g
:0,$s/\(\S\)"/\1''/g

And this one for german texts:

:0,$s/\(\s\)"/\1\\glqq{}/g
:0,$s/\(\S\)"/\1\\grqq{}/g

Exciting.

Read More

Apple Swift: Emulate Partial Fully Applied Functions

This article is only a short one, that tells an obvious fact, but I love it; hence, I will let you participate. Currently, I am doing a project with the new language Swift from Apple. Swift is a object-functional language like e.g. Scala.

Both languages have the nice functionality partial application of functions. This means you can set some of the parameters which returns a function that has the remaining parameters, only. So, it is not yet executed, but the already passed parameters are stored into the partial applied function and used if it is called with the rest of the parameters. Just for the seek of completeness, currying is then, when a function with multiple parameters is decomposed into a chain of functions that each has exactly one parameter (this is not the same).

But hey, this should be a short one. Here comes the punch line: You can partially apply functions, so that they have only one parameter, but what if I would like to preset all the parameters? It is very simple: Use a closure to create a new anonymous function, that simply executes the function of interest with all its parameters.
(more…)

Read More

VirtualBox v4.2.18 with Native Hard Drive Partition in Mac OSX Lion

Most of the time you use desktop virtualization, you simply add a virtual hard drive and install a guest operating system (like (K)Ubuntu Linux) in it. But some times – as in my case – you already have another operation system on a partition on your native hard drive. For a mac it’s either via Bootcamp or via something like rEfit enabling you to install a BIOS boot manager like Grub. Since it is kind of uncommon using such an existing partition for desktop virtualization, it is not supported (and documented) so good in the different virtualization solutions.
(more…)

Read More

Trouble with Black Screen in Parallels Desktop v9 with Linux Guest OS on Native Partition

This post is a follow up to Using Parallels Desktop v9 with Linux Guest OS in a Native Partition. After the successful utilization of an existing Linux installation in Parallels Desktop v9 you might want to install the Parallel Tools, in order to have a much nicer integration of the guest system.

But I had the problem, that right after installing the Parallel Tools for Linux AMD 64: The screen went black after the login, when the video driver had been loaded. So I uninstalled the parallel tools again and uninstalled all nvidia drivers which I had installed for dual boot use. Afterwards I reinstalled parallel tools and everything was fine.

Read More

Using Parallels Desktop v9 with Linux Guest OS in a Native Partition

Most of the time you use desktop virtualization, you simply add a virtual hard drive and install a guest operating system (like (K)Ubuntu Linux) in it. But some times – as in my case – you already have another operation system on a partition on your native hard drive. For a mac it’s either via Bootcamp or via something like rEfit enabling you to install a BIOS boot manager like Grub. Since it is kind of uncommon using such an existing partition for desktop virtualization, it is not supported (and documented) so good in the different virtualization solutions.
(more…)

Read More