Adding SSH support to PHP on Ubuntu

I have previously written a post on how to add SSH support to PHP, but that post is old, and it has now become even easier to get it up and running. And therefore making it much easier to auto upgrade WordPress via SSH. (automatic, yay!)

As root, do the following:

1: apt-get install libssh2-1-dev libssh2-php

2: Check that is installed: php -m |grep ssh2

3: Restart apache: service apache2 restart

And you should now have SSH support in PHP.

How to make iframes scrollbable on iPad (even in GWT)

I am currently working on a GWT app that some places uses iframes. When i tested this on a iPad, i noticed that it was not possible to scroll the contents, even with the two fingers swipe trick.

This required a lot of testing, googling, failing and then some more testing.

Somebody solved this by setting parent elements of the iframe, to the iframe`s size, this did not give the wanted behavior. But what i did notice was that there was a lot of pointing towards the CSS rule: “-webkit-overflow-scrolling”. I tried this too, but it did not “just work”.

After some testing, i made it work when i added the CSS rule for almost all parent elements for that iframe. With the 3 parents of the iframe corrected, the ipad started working as expected. Yay!

-webkit-overflow-scrolling: touch;

But then, i got to the next problem. All the HTML elements that were hidden because of overflow, started disappearing, shrinking, getting cut in half, and other “fancy stuff”.

Luckily, there is a CSS fix for that too:

*:not(html) {
-webkit-transform: translate3d(0, 0, 0);
}

tl;tr: iPad gets correct iframe scrolling with two lines of CSS.

PS: This is verified on iPad3.

java.io.file renameTo return false

Had a issue today where a java function which moves files stopped working. I realised that Java`s io.file.renameTo only throws Exceptions for some scenarios. For some errors, it will only return false when something goes wrong.

Only getting true/false on a rather vital operation is rather silly, so my “fix” was to move over to a library from Apache, aka FileUtils.

So now i simply do this: FileUtils.moveFile(oldFile, newFile);

That function actually throws exceptions when something fails 🙂

MRTG: ERROR: CFG Error in “Interval”: should be at least 5 Minutes (unless you use rrdtool)

Just setup MRTG the other day. And due to having some old switches to monitor, i chose to run the MRTG cron every minute, in order to be able to read traffic above 100Mbit. But even when i had specified rrdtool in the server config, i got these error messages:

ERROR: CFG Error in "Interval": should be at least 5 Minutes 
(unless you use rrdtool) at /usr/bin/../lib64/mrtg2/MRTG_<wbr>lib.pm line 739 </wbr>

The solution was pretty simple. Simply add the following line in mrtg.cfg:

Logformat: rrdtool
Interval: 1

GWT: “For security purposes, this type will not be serialized.”

The full error message you can get is: “Foo was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.”

This is normally caused by using a non-serializable class, which can happen if your class does not implement serializable or if you have forgotten to add a empty constructor.

Guice: java.lang.IllegalStateException: No SessionHandler or SessionManager

One reason for this error would be that you should inject the session object directly, not via constructor:

So instead of:

@Singleton
public class Foo {
 
@Inject public Foo(HttpServletSession s) {
this.session = s  }
}

do this:

@Singleton
public class Foo{
 
@Inject Provider<HttpServletSession> session;
 
}

And it should work much better 🙂

class Foo is public, should be declared in a file named Foo.java

When working with Java you might encounter this error. The reason for this is that you have tried to declare a public class in a file with a different name. Each java file can only contain one public java class, which is named the same as the java file itself. If you need another class inside your other class you should looking into private inner classes.