Split Pane jQuery plugin

I have created a jQuery plugin for adding split panes to you web site or web application.

Split panes can be nested. Component min-widths and min-heights are supported. I have not implemented support for max-width and max-height, yet.

Component size can be set programmatically.

I’ve tested the code in the latest versions of Chrome, Firefox and Safari on OS X, and in IE8 on XP.

The source code can be found at github.

Please give me you feed back!

Check out the following pages for examples on how to use it:

N.B., not all markup in the examples are needed for setting up the split panes. <div class="pretty-split-pane-frame"> and <div class="pretty-split-pane-component-inner"> are used for styling purposes only. Feel free to use them, but you might want to style things your own way.

JMenuBar not working for JApplet in Firefox on Mac

I’m having this issue with Firefox 12.0 on Mac OS X 10.7.4 using the following code:

import javax.swing.*;

public class AppletWithMenuBar extends JApplet {
	public void init() {
		JMenuBar menuBar = new JMenuBar();

		JMenu fileMenu = menuBar.add(new JMenu("File"));
		fileMenu.add(new JMenuItem("New"));
		fileMenu.add(new JMenuItem("Open"));
		fileMenu.add(new JMenuItem("Save"));

		JMenu editMenu = menuBar.add(new JMenu("Edit"));
		editMenu.add(new JMenuItem("Cut"));
		editMenu.add(new JMenuItem("Copy"));
		editMenu.add(new JMenuItem("Paste"));

		setJMenuBar(menuBar);
	}
}

and

<applet code="AppletWithMenuBar.class" width="400" height="100"></applet>

Whenever I select an item from the “Edit” menu the “File” menu gets highlighted.

Check it out for yourself here or have a look at the videos below.

This issue is also discussed here.

rApache on Debian 6.0 squeeze or Ubuntu 10.04 Lucid Lynx

This is how I installed and configured rApache on Debian 6.0 (squeeze). It should work on Ubuntu 10.04 Lucid Lynx also.

Install R and Apache MPM prefork (I assume that Apache 2 is installed already):

> sudo aptitude install r-base r-base-dev apache2-mpm-prefork apache2-prefork-dev

Download and build rApache from source:

> cd /usr/local/src
> sudo wget http://biostat.mc.vanderbilt.edu/rapache/rapache-1.1.17.tar.gz
> sudo tar xzf rapache-1.1.17.tar.gz
> cd rapache-1.1.17
> sudo ./configure
> sudo make
> sudo make install

Create file /etc/apache2/mods-available/R.load with content:

LoadModule R_module /usr/lib/apache2/modules/mod_R.so

Enable mod_R:

> sudo a2enmod R

Create folder /var/www/r-scripts .

Add the following to /etc/apache2/sites-available/default inside <VirtualHost *:80>:

<VirtualHost *:80>
	...
	<Directory /var/www/r-scripts/>
		SetHandler r-script
		RHandler sys.source
	</Directory>
	...
</Directory>

Created file /var/www/r-scripts/hello.R with the following content:

setContentType(type='text/plain')
cat('Hello')
DONE

Restart Apache:

> sudo /etc/init.d/apache2 restart

Verify that it works:

> curl -s http://localhost/r-scripts/hello.R
Hello

Done.

References:

Apache Server, Tomcat and mod_jk on Debian 6.0 squeeze

This is how I integrated Tomcat 6 with Apache 2 on Debian 6.0 (squeeze) using mod_jk. It should also work on Ubuntu 10.04 Lucid Lynx.

Install Apache Web Server:

> aptitude install apache2

Verify that the server is running:

> curl -s http://localhost | grep "It works"
<html><body><h1>It works!</h1>

Install Tomcat (you don’t need to install tomcat6-examples, I did it only for the purpose of this How To):

> aptitude install tomcat6 tomcat6-examples

Verify that Tomcat server is running:

> curl -s http://localhost:8080 | grep "It works"
<h1>It works !</h1>

Install mod_jk:

> aptitude install libapache2-mod-jk

Create file /etc/apache2/workers.properties with the following content:

worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

Create file /etc/apache2/mods-available/jk.conf with the following content:

JkWorkersFile	/etc/apache2/workers.properties
JkShmFile	/var/log/apache2/mod_jk.shm
JkLogFile	/var/log/apache2/mod_jk.log
JkLogLevel	info

Enable jk conf:

> a2enmod jk

Add mount point to /etc/apache2/sites-available/default:

<VirtualHost *:80>
	...
	JkMount		/examples/* worker1
	...
</VirtualHost>

Uncomment the following line in /etc/tomcat6/server.xml:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Restart Tomcat:

> /etc/init.d/tomcat6 restart

Restart Apache web server:

> /etc/init.d/apache2 restart

Now verify that everything works:

> curl -s http://localhost/examples/ | grep "Tomcat Examples"
<H3>Apache Tomcat Examples</H3>

Done.

References:

MacPorts, Clojure and ClassNotFoundException

After installing Clojure with MacPorts I got the following exception when running a basic Clojure script:

Exception in thread "main" java.lang.NoClassDefFoundError: Pad:/opt/local/share/java/clojure/bin////lib/clojure/jar
Caused by: java.lang.ClassNotFoundException: Pad:.opt.local.share.java.clojure.bin....lib.clojure.jar
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

As it turned out, I had run the script from a folder with a space in it’s name, “Scratch Pad”. After moving the script to an other folder, the script ran just fine.

Grails, CoffeeScript and Eclipse

I’m using the Grails CoffeeScript plugin, but when running my Grails application from Eclipse, with run-app, I got the following error:

Compiling CoffeeScript Files ...ERROR Launching CoffeeScript compiler: Cannot run program "coffee": error=2, No such file or directory

Now, in order to fix this you need to tell the CoffeeScript Grails plugin where to find the coffee command. You can do this in BuildConfig.groovy by adding this line:

grails.coffeescript.compiler.location="/opt/local/bin/coffee"

But, this is not enough, because now I get the following error:

Compiling CoffeeScript Files ...env: node: No such file or directory

The solution I found to this problem was editing /opt/local/bin/coffee, changing

#!/usr/bin/env node

to

#!/opt/local/bin/node

Now I’m able to do run-app from within Eclipse.

Keep in mind that I’m on a Mac having installed CoffeeScript with npm, and node and npm with MacPorts. You might have your CoffeeScript installation in a different location.

How to sync MacPorts without rsync

If port 873 is blocked on your network and you need to sync MacPorts do this:

In /opt/local/etc/macports/sources.conf replace

rsync://rsync.macports.org/release/ports/ [default]

with

http://www.macports.org/files/ports.tar.gz [default]

and run

sudo port sync

instead of

sudo port selfupdate

MacPorts is now synching using http over port 80 instead of rsync over port 873.

Fastest JavaScript framework

I had to implement what I call a “row selector” for a web application.

It looks something like this (try it out by clicking the checkboxes in the first column):

Now, the tricky part is that this should work for large documents, say 500 rows.

I have implemented this with jQuery, Prototype, MooTools and pure JavaScript, and these are the results I get when toggling all 500 rows in IE8 on a Windows box with 512MB RAM:

  • jQuery 1.6.1: 2000ms
  • Prototype 1.7.0: 2450ms
  • MooTools 1.3.2: 6300ms (first toggle) / 1100ms
  • JavaScript: 250ms

These are some numbers for Firefox 5, running on the same machine:

  • jQuery 1.6.1: 150ms
  • Prototype 1.7.0: 120ms
  • MooTools 1.3.2: 230ms
  • JavaScript: 100ms

We have to support IE, so choosing the pure JavaScript version was a no-brainer.

Here are the results for the jQuery version on an iMac with 2GB RAM:

  • Google Chrome 12: 380ms
  • Safari 5: 150ms
  • Firefox 5: 140ms

It looks like Chrome is falling behind…

Try it out for yourself: jQuery, Prototype, MooTools and JavaScript.