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 fix logrotate cron job error (/etc/cron.daily/logrotate)

After migrating my database to a new server running Ubuntu 14.04.4 LTS i received an email with the following content:

Subject

Cron test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.daily )

Body

/etc/cron.daily/logrotate:
error: error running shared postrotate script for ‘/var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/error.log ‘
run-parts: /etc/cron.daily/logrotate exited with return code 1

The reason why i was getting this error was because i imported my old mysql tables, including the users.
This particular cron job uses a mysql user debian-sys-maint to flush the logs, but i changed the password by importing all of my old tables.

You can fix this by creating the user with the correct password which can be found in the /etc/mysql/debian.cnf file:
Continue reading


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:

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

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


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

1
2
3
4
5
String a = "Test";
String b = "Test";
if (a == b) {
  // Do something
}

just use this:

1
2
3
4
5
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

1
2
3
4
5
String a = null;
String b = "Test";
if (a.equals(b)) {
  // Do something
}

it will result in a NullPointerException!

Continue reading


EML to PDF Converter

I just finished a new project, an EML to PDF Converting tool which i released for free under the Apache V2 License to github. This tool allows you to convert your E-Mails in the EML format to PDF’s, which is necessary for archivability. Since E-Mails reference external resources such as images they tend to be an impermanent medium. To deal with this they can be converted to a format which is permanent such as PDF.

You can download it for free or check out the source code at github!

Screenshot
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 few simple steps.

1. Download

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

 

2. Extract

Open with 7-Zip

Open the .exe file with 7-Zip. It contains a single file tools.zip, which contains all the files we need.
Extract the tools.zip to the desired JDK directory (e.g. “D:\JavaJDK\”).
Continue reading