Older blog entries for Kay (starting at number 72)

Workaround for borderless Java Swing menus on Linux

Since years Linux users are plagued by a bug which affects the rendering of Swing popup menus. When using a modern GTK theme (Like Gnome's Adwaita or Ubuntu's Ambiance and Radiance) then menus in Java Swing applications have no borders and no separators:

Several bug reports exists (Like #6925412) but it seems to be unclear if this is a bug in the affected GTK themes or a bug in Java's GTKLookAndFeel class. Fact is: I'm pretty sure this bug will not be fixed anytime soon so we have to find a workaround and in this article I will show you two different approaches.


Continue reading "Workaround for borderless Java Swing menus on Linux"

Syndicated 2012-04-12 16:49:00 from K's cluttered loft

jQuery Fullscreen Plugin

Modern browsers (Like Chrome and Firefox) provide an interesting new feature: A fullscreen mode which can be controlled by JavaScript. It is even possible to switch a single HTML element to fullscreen. This is useful for videos or images for example. Unfortunately browsers currently only provide the necessary methods with the usual browser-specific prefixes:

// Firefox
element.mozRequestFullScreen();
document.mozCancelFullScreen();
document.mozFullScreen;

// Chrome
element.webkitRequestFullScreen();
document.webkitCancelFullScreen(); 
document.webkitIsFullScreen;

To simplify the usage of this new feature I wrote a small jQuery plugin.


Continue reading "jQuery Fullscreen Plugin"

Syndicated 2012-04-10 17:37:36 from K's cluttered loft

Shell scripts and space characters in command line parameters

I'm using Linux for more than 10 years now and it is embarrassing that I missed this shell feature for so long. But first let's explain the problem: Let's say we want to write a shell script which simply starts some application and which passes all command line parameters to this application. This is often useful if an application is installed in some directory which is not in the PATH and you want to put a starter script into ~/bin which is in PATH. Example:

#!/bin/sh
# Filename: ~/bin/startmyapp
cd ~/opt/myapp
exec ./myapp $*

$* is a place holder for all command line parameters which were passed to this shell script. Now let's feed some command line parameters to it:

startmyapp arg1 "arg2 with spaces" arg3

The ~/opt/myapp/myapp program is now called like this from the shell script:

./myapp arg1 arg2 with spaces arg3

So now there are five parameters instead of three. Bad thing. Using "$*" instead of $* also doesn't work because then all command line parameters are passed as a single parameter to the program. So far I never searched for a solution to this problem. Instead I always worked around this problem somehow. But today I took some time to find a solution and found it pretty fast. It simply looks like this:

#!/bin/sh
# Filename: ~/bin/startmyapp
cd ~/opt/myapp
exec ./myapp "$@"

This $@ parameter was completely new to me. The difference between $* and $@ is explained here.

Syndicated 2012-02-26 15:41:34 from K's cluttered loft

How to implement a Single Instance Application in Java

Recently I started processing command-line arguments in one of my Java Swing applications (Xadrian) so the application can load files directly on startup. This allows connecting the application with some mime-type or file extension and load files into the application by double-clicking the files. But unfortunately this isn't really usable because everytime a new instance of the application is launched by the operating system. So I searched for some technique to prevent this and found two articles: The first one explains how to use a lock file to prevent a second application instance while the second one explains how to use a local server socket to do the same.

The problem with the first solution is obvious: Even with a shutdown hook it is possible that the lock file is not removed properly (When JVM crashes for example). This prevents the application from being restarted. The user has to remove the lock file manually to be able to start the application again which is pretty annoying. The second solution doesn't have this problem because the server socket will be closed even when the JVM crashes. But this solution has a different problem: The port number must be fixed. And if there is already some other service using this port then this can cause a lot of confusion.

Both solutions have another problem: Just preventing the launch of a second instance isn't enough. When I double-click some data file and the operating system tries to open this file with a second instance of the application then I want the data file to be opened with the first instance instead. So the second instance must give the command line arguments to the first instance.

I haven't found a library which already does this so I had to write my own library.


Continue reading "How to implement a Single Instance Application in Java"

Syndicated 2012-02-09 21:55:25 from K's cluttered loft

How to use Java applets in modern browsers

Finding out how to embed a Java applet in current major browsers is quite a task. Lots of pages still suggest using the <applet> tag and describe how to use the mayscript attribute to allow communication between Java and JavaScript. Other pages recommend using this mysterious mayscript attribute even in <embed> and <object> tags. I think there is a lot of voodoo out there, attributes which sound important but are not necessary at all...

So I started studying this stuff by myself. My goal was embedding a Java applet on a page which must work in Internet Explorer 7+, Google Chrome, Firefox, Opera and Safari. The applet must receive an applet parameter and must communicate with JavaScript in both directions.


Continue reading "How to use Java applets in modern browsers"

Syndicated 2012-01-28 16:15:10 from K's cluttered loft

Move to Github complete

Today I finished moving the main batch of old projects from my own server to Github: ThreeDee (JavaScript), ThreeDee (Java), Jollada, GraMath, Scilter, crypt4j, Pherialize, JSP Math Taglib, Supervise Tools, Wasteland Suite, wludata

Some of these projects are pretty old but I think they are still worth keeping. Some other projects went to /dev/null instead because I couldn't find any reason why they should waste space on any server. For the projects which had web pages here on Ailis I configured permanent redirects so old external links may still work for some time.

Syndicated 2012-01-08 17:49:17 from K's cluttered loft

TwoDee

I just finished publishing TwoDee, a small, fast and simple 2D scene graph vector engine for JavaScript based on the HTML 5 canvas technology. This is the library used in my WebOS game Destroids which earned me $10,000 in one of the Palm Hot Apps Contests last year.

Syndicated 2011-12-27 23:01:36 from K's cluttered loft

Generic Jabber (XMPP) with webOS

WebOS (The operating system of the Palm Pre and Palm Pixi phones) has a built-in messaging application but unfortunately it only supports Google Talk and AIM out of the box. It's a shame that Palm has not enabled more protocols and especially generic XMPP support. The used library (libpurple) supports everything so it's only missing in the GUI.

Google Talk uses XMPP so in theory it should work with any other XMPP server but unfortunately Palm has put this nasty code in the LibpurpleAdapter (which is used as a connector between the GUI and the low-level libpurple):

if (strcmp(prplProtocolId, "prpl-jabber") == 0
    && g_str_has_suffix(transportFriendlyUserName, "@gmail.com") == FALSE
    && g_str_has_suffix(transportFriendlyUserName, "@googlemail.com") == FALSE)
{
    // Special case for gmail... don't try to connect to mydomain.com if the
    // username is me@mydomain.com. They might not have
    // setup the SRV record. Always connect to gmail. 
    purple_account_set_string(account, "connect_server", "talk.google.com");
}

This code means: If the protocol is Jabber (XMPP) and the entered username does NOT end with @gmail.com or @googlemail.com then the XMPP server is hardcoded to talk.google.com. So if you enter a username like johndoe@jabber.org then the Messaging app does not connect to jabber.org but instead it connects to talk.google.com because of the above code. So we must get rid of this code somehow.

With some knowledge about assembler you might be able to toggle some logic in the binary so the above if statement always evaluates to false but there is a much easier solution. You just need to replace the string "connect_server" with some invalid string. I use "nonnect_server". The result is that the line simply sets some unused property and therefore simply does nothing. But let me describe step by step:

Since WebOS 2 the LibpurpleAdapter program is renamed to imlibpurpletransport. In the following step-by-step instructions I will mention both variants for WebOS 1 and WebOS 2.


Continue reading "Generic Jabber (XMPP) with webOS"

Syndicated 2011-12-20 18:25:00 from K's cluttered loft

Fixing synchronization problems in fail2ban

fail2ban is a software which can be used to monitor service log files and ban IP addresses which executed a brute force attack or tried to use the mail server as a spam relay. In the default configuration in Debian GNU/Linux only SSH login attempts are monitored which works pretty nice. But when you try to add more services then you may run into the problem that fail2ban no longer starts up correctly. The log file contains errors like this:

fail2ban.actions.action: ERROR  iptables -N fail2ban-ssh
iptables -A fail2ban-ssh -j RETURN
iptables -I INPUT -p tcp -m multiport --dports ssh -j fail2ban-ssh returned 200

I searched on the net but only found more victims of this problem, no solution. So I analyzed what was going on here and I finally figured it out.


Continue reading "Fixing synchronization problems in fail2ban"

Syndicated 2011-09-13 17:37:43 from K's cluttered loft

Return a PHP array by reference

Looks like I'm using way to much Java in these days... I'm starting to forget PHP knowledge. Today I was searching for a function to clone an array but haven't found one. I was curious why PHP doesn't have an array_clone or array_copy function. But then I was nudged into the right direction: Arrays are always assigned by value, not by reference, so it simply doesn't need a clone function because a simple assignment already performs a clone (It's even some sort of deep clone (At least all values inside the array (Arrays are also values, not objects) are copied)). To assign it by reference you have to add an ampersand character:

$arr = array();
$arrClone = $arr; // A clone is created
$arrRef = &$arr; // A reference is created

I really forgot this basic PHP knowledge...


Continue reading "Return a PHP array by reference"

Syndicated 2011-07-28 11:39:37 from K's cluttered loft

63 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!