PHP snippet to filter AirBnB Not available events and fix the end date

I wanted to import the AirBnB calendar via ical into my Google calendar but all the blocked days were annoying. Also the end date was one day too early on all events..

So i hacked a php snippet together which filters the “Not available” events and corrects the date. Then i simply added the php URL to Google calendar and now everything works fine!

If you want to use this snippet just replace the AirBnB URL with your own.

How to get random unique integers in a range with Java

If you are able to use Java 8 or up you can make use of the various methods of Random that return an IntStream.

E.g. if you want to generate random distinct numbers from a range [0, 100) you can use:

OfInt iterator = ThreadLocalRandom.current().ints(0, 100).distinct().iterator();
for (int i = 0; i < 100; i++) {
  System.out.println("Next random number: " +;

Since our range contains 100 Integers and .distinct() was used we can’t draw more than 100 numbers from the stream!

How to convert a String to int / Integer in Java

When you want to convert a String to int or Integer you can use two simple methods from the Integer class.

To convert a String to primitive int use Integer.parseInt(String s)

String a = "1234";
int x = Integer.parseInt(a);

To convert a String to an instance of Integer use Integer.valueOf(String s)

String a = "1234";
Integer x = Integer.valueOf(a);

Continue reading

How to compare Strings in Java

A common mistake Java novices do is using the == operator to compare Strings. This does almost certainly lead to unexpected and unwanted behaviour. There is a simple solution to this problem and a not so simple explanation why it is such a common mistake.

The simple solution is to use String.equals instead of the == operator.

So when you want to know if two String objects hold the same value instead of

String a = "Test";
String b = "Test";
if (a == b) {
  // Do something

just use this:

String a = "Test";
String b = "Test";
if (a.equals(b)) {
  // Do something

But look out for null Strings, == handles null Strings nicely but when you call

String a = null;
String b = "Test";
if (a.equals(b)) {
  // Do something

it will result in a NullPointerException!

Continue reading

How to install a (portable) JDK in Windows without admin rights

It recently happened to me that I was stuck at work on a Windows installation without access to admin privileges. While I could use a bunch of portable apps I could not find a portable JDK. To get a portable JDK without admin privileges in Windows you have to follow three simple steps.

1. Download

Download the JDK from Oracle (e.g. JDK 8 8u111).


2. Extract

If you want to use the x86 version simply open the .exe file with 7-Zip. It contains a single file, which contains all the files we need.
Open with 7-Zip

For x64 the can be found in .rsrc\1033\JAVA_CAB10\111\

Extract the to the desired JDK directory (e.g. “D:\JavaJDK\”).
Continue reading

How to get the current windows wallpaper in C#

Being able to make software is great. Not only because you can make a living from it, but also because it helps you in everyday life. Like when you have to manage your 10k+ wallpaper library. I for once always get baited by these “575 awesome wallpapers you absolutely need” posts and download them right away into my library. Every now and then a black sheep sneaks in but i only see it after it pops up on my Desktop (as if i would review all of these 575 wallpapers).

And here it comes together: as a software developer i have the means to write a small piece of code that gets rid of these ugly wallpapers.

So i hacked this snippet that moves the current wallpaper out of its current folder and into a “reject” folder.
The current wallpaper path can be found in a registry entry “TranscodedImageCache” in “HKCU\Control Panel\Desktop” (at least in Windows 8.1). It’s encoded with unicode though and has to be cleaned a little bit.

Continue reading

String replace with callback in Java (like in JavaScript)

When you use JavaScript a lot you are more or less used to the callback-hell, but i hope you love the benefits of passing functions around as much as i do.

For example when replacing a portion of a string:

"test6test12test".replace(/\d+/g, function(str){
  return parseInt(str) * 2;

When doing such things in Java it can be a bit of a hassle, but Lambda-Expressions to the rescue!