I figured it was time for a redesign of my redesign. This time i'm obeying the laws of Phi... mostly, and there's a little W*b 2*0 thrown in.

Restarting sequence columns in db2

It's a quickie this time. I figured i'd just make a note of how to update/restart a sequence column in db2, because it's something I use on a semi regular basis, and the syntax is ever so slightly odd. Here is how it should be done:

alter table card_transaction alter card_transaction_id restart with 923845384

- antony 18-09-2008 at 04:12AM

Allowing JDBC to access DB2 on Ubuntu Linux

One of the problems with installing the db2exc deb on Linux is that by default, it doesn't allow external (including local JDBC) connections. The way to enable this functionality is quite simple, as documented by tldp.org First, edit /etc/services

db2c_db2inst1       50001/tcp        # IBM DB2 instance - db2inst1
Then, su to your instance owner, probably db2inst1 and type:
db2 update dbm cfg using SVCENAME db2c_db2inst1
db2set DB2COMM=tcpip
db2stop
db2start
It's as simple as that. To do the same for admin access, open /etc/services once again and put:
ibm-db2           523/tcp          # IBM DB2 DAS
ibm-db2           523/udp          # IBM DB2 DAS
Then run (as your DAS owner, probably dasadm1)
db2admin stop
db2admin start
done!

- antony 19-06-2008 at 02:24AM

Running tapestry on alternate ports

I found that it was an unneccessarily difficult task to run Tapestry T5 on a webserver which didn't run on ports 80/443, considering it's a very common requirement, and that it really should be a simple bit of xml configuration. It's a pain because the first thing that happens is that links which hit secure pages don't point to the correct port. After a long search, I found the following contribution could be placed in the project's AppModule.java to (unfortunately) hard-code some new port and url values for Tapestry to build URLs from

    public void contributeAlias(Configuration<AliasContribution> configuration) {
    	
        BaseURLSource source = new BaseURLSource() {
        	
            public String getBaseURL(boolean secure) {
            	
                String protocol = secure ? "https" : "http";
                int port = secure ? JettyRunner.DEFAULT_SECURE_PORT : JettyRunner.DEFAULT_PORT;
                String url = "localhost";

                return String.format("%s://"+url+":%d", protocol, port);
            }
        };

        configuration.add(AliasContribution.create(BaseURLSource.class, source));
    }

- antony 18-06-2008 at 08:37AM

sql-maven-plugin and random build order

I've been using codehaus' sql-maven plugin recently for rebuilding my project's database. I love it to bits, but I noticed something weird going on. I have two sets of patches, one for staging test-data, and one for the schema itself. I specify them as follows in my pom.xml

<includes>	                           <include>buildup/*.sql</include>							<include>patches/*.sql</include>						</includes>
Now that's all very well on my local machine, but on my Hudson ci machine, it was trying to run staging first, and failing! I swapped them around, sure, it changed the order locally, but to no avail on hudson. That's odd... I thought. I examined the plugin docs. After a while, I add
<orderFiles>descending</orderFiles>
to my plugin config stanza. perfect. except not. I then study my plugin definition:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
...
</plugin>
oh that's odd... no version number. I'll whack 1.1-SNAPSHOT in there to regain at least some control. et voila. It seems like whatever version maven was picking up on hudson was a version of the sql-maven-plugin prior to 1.1-SNAPSHOT which doesn't respect the <orderFiles> option. It's a valid option there, but it is ignored. This is actually the second configuration option in this plugin which I have experienced being ignored. Watch out.

- antony 17-06-2008 at 02:58PM

.local domains not working on Ubuntu?

One of the first things I do when I install ubuntu at work is disable avahi-daemon. Why? For some reason, avahi-daemon takes over the .local domain and internal domains/servers simply wont resolve. I recommend (if you have .local domains) at your workplace or home:

sudo /etc/init.d/avahi-daemon stop
then disable the service in Administration->Services->Multicast DDNS Service should fix it. Works like a treat.

- antony 17-06-2008 at 02:56PM

Abstractions with JAXB

One of the less obvious things about Java's JAXB is that it is, by default (and by the virtue of the way java works) unable to intelligently map subclasses, interfaces, and abstractions. Let's say I'm trying to create an XML document which starts like this (it's for the Bibit payment provider, actually):

<paymentDetails>
   <VISA-SSL>
      ...
Although in actual fact, the VISA-SSL element can also say SOLO_GB-SSL or ELV-SSL depending on payment method. So I create an abstract class 'Method' which has three subclasses, ElvSsl, SoloGbSsl and VisaSsl. If I try to map this in JAXB the element is empty.
<paymentDetails />
After a lot of rooting around i stumble upon the XmlSeeAlso annotation, which tells the JAXB Marshaller to also load definitions for the provided classes into itself. I apply it to the root class as follows, explicitly naming all my subclasses:
@XmlRootElement
@XmlSeeAlso({SoloGbSslPaymentDetails.class, 
	ElvSslPaymentDetails.class, VisaSslPaymentDetails.class})
public class PaymentDetails {
et voila!
<paymentDetails>
	<VISA-SSL>
		<...

Although the one thing it does is include all the namespacing rubbish in the paymentDetails element now so that it can unmarshal it correctly. If I can fix that, even better, but for now, not to worry.

- antony 26-03-2008 at 02:51AM

Enabling SSL support on embedded Jetty

Considering Jetty, Maven, and SSL are all mature technologies, which need to be integrated often and by many people, there is a surprising lack of documentation online about how to enable SSL in the Maven2 Jetty plugin. Needless to say after a fair bit of google searching, I found the answer, and thought it best to document my findings here. First of all you need to create the certificate. There is a lot of complexity to this, as is very well documented at http://docs.codehaus.org/display/JETTY/How+to+configure+SSL#HowtoconfigureSSL-step4 however for my needs (development), only steps one and two are neccessary. I will replicate them here. First of all, run keytool to generate your certificate, keytool is provided by the JDK

keytool -keystore keystore -alias jetty -genkey -keyalg RSA
Note, don't use DSA, it causes problems after a few uses. You will be presented with a number of questions, which you may answer how you like. I would recommend sticking to the suggestions here, replacing 'what is your first and last name' with the domain you are generating the certificate for. *.enzy.org will work here too:
keytool -keystore keystore -alias jetty -genkey -keyalg RSA
Enter keystore password:  password
What is your first and last name?
  [Unknown]:  jetty.mortbay.org
What is the name of your organizational unit?
  [Unknown]:  Jetty
What is the name of your organization?
  [Unknown]:  Mort Bay Consulting Pty. Ltd.
What is the name of your City or Locality?
  [Unknown]:
What is the name of your State or Province?
  [Unknown]:
What is the two-letter country code for this unit?
  [Unknown]:
Is CN=jetty.mortbay.org, OU=Jetty, O=Mort Bay Consulting Pty. Ltd.,
L=Unknown, ST=Unknown, C=Unknown correct?
  [no]:  yes

Enter key password for <jetty>
        (RETURN if same as keystore password):  password
After doing this, copy your keystore to a known location /etc/keystore perhaps, and add the jetty maven plugin configuration as below. The following example is taken from http://markmail.org/message/3dcqftyb675jqdu3
<connectors>
   <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">   
      <port>8080</port>
      <maxIdleTime>60000</maxIdleTime>
   </connector>
   <connector implementation="org.mortbay.jetty.security.SslSocketConnector">   
       <port>4080</port>
       <maxIdleTime>30000</maxIdleTime>  
       <keystore>/etc/keystore</keystore>
       <password>password</password>
       <keyPassword>password</keyPassword>
       <truststore>/etc/keystore</truststore>
       <trustPassword>password</trustPassword>
       <excludeCipherSuites>
            <excludeCipherSuite>SSL_RSA_WITH_3DES_EDE_CBC_SHA</excludeCipherSuite>
           <excludeCipherSuite>SSL_DHE_RSA_WITH_DES_CBC_SHA</excludeCipherSuite>
           <excludeCipherSuite>SSL_DHE_DSS_WITH_DES_CBC_SHA</excludeCipherSuite>
       </excludeCipherSuites>
    </connector>
</connectors> 
It's worth noting that generally the OBF: prefix would be used to obscure passwords, however this did not work for me (keystore tampered or invalid password) so I put them in plaintext. Fine for development!

- antony 07-03-2008 at 02:22AM

Genius EasyPen in Ubuntu Linux / Xorg 7

I've spent the last day or so playing with some old pen-tablets I found lying around the house. I got both of them working on an Ubuntu Linux 7.10 machine without any trouble whatsoever, but the serial-port based one needed a bit of manual intervention which I will document here. The Tevion/Medion/Aiptek USB tablet was plug and play, by the time i'd plugged it into the USB, Linux had loaded the kernel modules and was ready to go. The Genius EasyPen Serial, being a very legacy product, required some editing of my X configuration. To make it work in Xorg 7.x, add this code to xorg.conf

Section "Module"
   Load "summa"
EndSection
Section "InputDevice"
   Driver "summa"
   Identifier "EasyPen"
   Option "Device" "/dev/ttyS0"
   Option "InputFashion" "Tablet"
   Option "Mode" "Absolute"
   Option "Name" "EasyPen"
   Option "Compatible" "True"
   Option "Cursor" "Stylus"
   Option "Protocol" "Auto"
   Option "SendCoreEvents" "on"
   Option "Vendor" "GENIUS"
EndSection
Add this code to the ServerLayout section
InputDevice     "EasyPen"       "SendCoreEvents"
Install the package for the kernel module
aptitude install xserver-xorg-input-summa
Add this to your ~/.profile or /etc/profile
gpm -t genitizer -m /dev/ttyS0
Then restart X, and you should be up and running! A nice, but cheap device.

- antony 30-12-2007 at 09:11AM

Useful DB2 Command

If you want to allow user <user> to use explicit schemas. You wouldn't believe how hard this is to find on line.

grant IMPLICIT_SCHEMA on database to user <user>

- antony 18-12-2007 at 05:26AM

five years old

How many five year olds could you take in a fight? <a href="http://www.justsayhi.com/bb/fight5" style="display: block; background: url(http://assets.justsayhi.com/badges/960/283/fight5.eyd544uuyz.jpg) no-repeat; width: 296px; height: 84px; font-family: Arial, sans-serif; font-size: 42px; color: #fff; text-decoration: none; text-align: center; padding-top: 145px;">23</a>

- antony 14-12-2007 at 02:56AM

branch the codelines

This piece of code approximates the inverse square root of a number. It was written during the making of Quake3. It's a very, very clever piece of code.

float InvSqrt (float x){
    float xhalf = 0.5f*x;
    int i = *(int*)&x;
    i = 0x5f3759df - (i>>1);
    x = *(float*)&i;
    x = x*(1.5f - xhalf*x*x);
    return x;
}

- antony 28-11-2007 at 03:08AM

about the breadline

I live to extravagance; and I spent all my money on expensive bread.

- antony 14-08-2007 at 08:26AM

encouraged transferral

"You don't know what it is to be a struggling author!", but by the very nature of my reply... I did.

- antony 01-08-2007 at 06:02AM

solitary confinement

Brings with it a wealth of ideas. The situation itself implies that such ideas cannot be logged nor brought to fruition. The situation is, therefore, not conducive to such thought.

- antony 30-07-2007 at 04:22PM

redesign

The web changes far too fast. I don't know why I'm trying to keep up but bam! Here's a new design.

- antony 30-07-2007 at 04:10PM