lørdag den 24. oktober 2009

The simplest possible "wget"/"curl" downloader in Java to bootstrap a new Java environment

Occasionally you have to work or deploy code on a server where you are severely limited in what you can and may do. If so, you may not have access to a browser so you can download files, or a gzip implementation so you can unpack files or a compiler so you can add programs that can do those things you need. I am frequently in this position as my job is to run Java program on AS/400 machines.

Plenty of Java programs exist which can help with all this, but you still need to download them in the first place. You may have access to an ftp program but these days that is often not enough as things tend to be accessible for browsers only. I have not found an out-of-the-box way to get Java to run code from the net in a telnet connection which doesn't have a GUI so the hen-and-egg-problem is getting to download a program which allow you to download programs.

Fortunately most telnet programs allow for pasting in information, so a Java program that will fit on a single editor screen can easily be saved to a file, and compiled with javac to running code. So save the following snippet as "Get.java":

=======================================
      import java.io.*;
import java.net.URL;

public class Get {
public static void main(String[] args) throws Exception {
System.out.println(args[0] + " -> " + args[1]);
InputStream in = new URL(args[0]).openStream();
OutputStream out = new FileOutputStream(args[1]);
byte[] buf = new byte[4096];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
=======================================

Compile it with:

=======================================
javac Get.java
=======================================

If you have a CLASSPATH variable then put Get.class in the CLASSPATH otherwise you can just run it with:

=======================================
java Get http://www.google.dk google.txt
=======================================

This saves the Google home page in the file "google.txt". You can then download zip-files directly and unzip them with jar. For instance to download and unpack ant so you can use build.xml-files you can use

=======================================
java Get http://mirrors.dotsrc.org/apache/ant/ant-current-bin.zip ant.zip
jar xvf ant.zip
=======================================

If you need to go through a proxy, then do the same configuration as you would do for any other Java program.

mandag den 20. april 2009

Java Webstart does not check the JNLP-file for well-formedness

I have spent some time playing with the extension mechanism available in Java WebStart 1.5+ and found that Java WebStart does NOT check the JNLP-files for well-formedness so a lot of time can be spent in not noticing if you have forgotten the closing /'s in the


<jar href="foo/bar.jar">
<jar href="foo/bar.jar">
<jar href="foo/bar.jar">

section.

Well, now I know a LOT more about JNLP-file processing than I did earlier today :)

tirsdag den 17. marts 2009

Piccolo and Piccoline disks

A very long time ago I spent a lot of time with the Piccolo (RC702 and the trusty RC701B) and Piccoline systems from the Danish computer producer Regnecentralen which ran CP/M-80 and CCP/M-86 respectively.

Not SO many years ago I played with reading the old Piccolo and Piccoline 5.25" diskettes from MS-DOS using the 22DISK program from SYDEX ()

Yesteday I found the old files and decided to share my results from back then (but unverified as I do not have a 5.25" drive hooked up).
The following definitions worked with version 1.40 of SYDEX:


BEGIN R702 Rc702 Piccolo - SSDD 48 tpi 5.25"
DENSITY MFM ,LOW
CYLINDERS 36
SIDES 2
SECTORS 9,512
SIDE1 0 1,3,5,7,9,2,4,6,8
SIDE2 1 1,3,5,7,9,2,4,6,8
BSH 4 BLM 15 EXM 1 DSM 135 DRM 127 AL0 0C0H AL1 0 SOFS 36
END

BEGIN LINE RC Piccoline - 5.25" DSHD
DENSITY MFM ,HIGH
CYLINDERS 77
SIDES 2
SECTORS 8,1024
SIDE1 0 1,2,3,4,5,6,7,8
SIDE2 1 1,2,3,4,5,6,7,8
ORDER SIDES
BSH 4 BLM 15 EXM 0 DSM 616 DRM 511 AL0 011111111b AL1 0 SOFS 32
END

Hopefully this may help some computer archeologist some day :)

tirsdag den 24. februar 2009

Pinnacle Nano Stick Ultra (73e) under Ubuntu 8.10

Played around with a Pinnacle Nano Stick Ultra (model 73e) where the Mac software (EyeTV Lite) was really nice, and the Windows XP software from Pinnacle was rather so so. As I had Ubuntu 8.10 installed in a virtual machine anyway, and I would like to have a Linux router do the recording I need, it was a good time to play with that.

It turned out to be really simple. Install Kaffeine, plug in the USB-adapter, start Kaffeine (I had to do it from a root shell) and tell it to AUTOSCAN. Go to DVB and Scan channels.

The channels are listed in the right panel, select all, and move them to the left. That's it. Now the channels can be chosen and the TV shown.

"Instant recording" records the transport stream to a m2t-file named after the show and channel in the current directory. This can be viewed directly with mplayer.

The Linux software is more powerful but a very unfinished product in my opinion.

mandag den 26. januar 2009

Eclipse editor font under OS X 10.5

I spend a lot of my time inside Eclipse and have found that one of the most important things to get right is to get a very readable font in the editor window.

Under XP, there are plenty of alternatives - currently I use the Consolas font - but fonts render differently under OS X. So I spent some time getting this right on my MacBook with a 1200 x 800 display. I have found that spacing between lines is very important to me


This is the default Monaco as chosen by Eclipse. It is a bit too small for using on a 13" Mac.


Monaco at size 13. This is actually quite nice with proper spacing and large, readable characters and may be perfectly fine for most. Unfortunately I don't like the asymmetry in the characters (they all look like they were pushed on the upper left corner), but it is ok.

This is size 13 of the Liberation Mono fonts from Red Hat (which were designed to have the same physical size as the fonts Microsoft provides), and which is really nice. I have used it for a while and it is fine.

The Inconsolatas font at size 14. This is my personal favorite - fine spacing and kerning, not too black letters but not too thin either. The author was inspired by the Consolas font and has done a great work.