Skip to content
accelerando

Monthly Archives: October 2007

Why Apple users seems odd sometimes

29-Oct-07

Some Apple users are happy about a “goto line xy” function in a shitty text editor:

Leopard Love: “Go To” in TextEdit

Upgrading Mac OS X 10.4 to 10.5

27-Oct-07

Some more or less unordered thoughts and impressions of the latest iteration of Apples Mac OS X, nicknamed Leopard:

Despite all the naysayers who warn you “don’t upgrade, make a clean install”, i’ve updated two Intel Macs to today without much hassle.

In both cases, the famous “Welcome Movie Thingy” crashed :( Hurray, good first impression.

In a nutshell: Leopard boosts Apache finally to Apache 2 which forced me to reconfigure my development webserver. Timemachine sucks bigtime as it doesn’t work over samba shares at all and over afp shares only with an intermediate disk image which is dead slow.

Parallels works fine, my Pureftpd Manager doesn’t. Share Points is no longer needed as the sharing tab has an option to choose the folders that are shared via samba or afp. Also, all input managers have stopped working (like the great InquisitorX). I guess hacks exists, but i don’t wanna run into trouble the next system upgrade.

I need to adjust myself to the new look and feel. It’s nice, that brushed metal is gone and the widgets are somewhat consistent, but I don’t like the colors: Inactive is too white, active to dark. The new front row app is odd. I like the old one better. The effects in photo booth and iChat feel like an “aaah, nice” and then never use it again feature to me. Muhaha, how funny, standing in a fishbowl.

Some things are nice and handy, spaces for instance and the pimped, system wide dictionary, that lets you search wikipedia. OS X comes bundled with rails now, which is nice. Also very cool is the new screen sharing core service, that lets you remote control other macs. I used Chicken of the VNC before, but that tool didn’t like german chars and right mouse clicks at all. The screen sharing thing is way better.

I’m no benchmarker, but the system feels fast and smooth on a Core Solo Mac Mini and a Core 2 Duo Mac Book, haven’t run it on a G5 yet.

I’m curious, if and when something bad happens to the new system… I did some extensive testing the last 2 days but until now, everything works as it used, it just looks different. I’m wondering if that was money well spent, i’m not sure after all.

The new firewall settings are a joke, aren’t they? I have the terrible impression of a Zone Alarm clone… So now then, it’s time for me to write the ipfw rules per hand, once again. Also the new front row isn’t just odd, it’s crap. iTunes store everywhere… But the funniest thing is, it shows me the top 10 french songs bought on the very day. Not that i was interessted in the german ones, but thats just stupid commercials within a product i already payed for.

Workshops

25-Oct-07

Right now i’m in Frankfurt / Main, attending the iX Workshop Web Programming with Grails (Link in German).

The speaker, Dierk König, encouraged live blogging, so here we are:

Some ActiveRecord bashing and many, many windows machines around. People fiddling around with their Java Paths, IntelliJ IDEA, which should be way better and more impressive than Eclipse or my nifty little TextMate… In the meantime, everything works fine on a real OS (that is everything else than Windows, for that matter…)

I’m already bored and expecting something more to happen. Everything said in the last 3 hours or so has been written down somewhere on the Internet.

As i don’t want to bore anybody else, i’ll guess i have look at my feedreader.

Hey, the beat goes on, configuring some weird IDE has stopped…

Would anybody really read my live blogging? If a tree falls in a forest…

JEHOVA! He said G-String :)

So again, how are strings called in the Groovy JDK? G Strings?

Hm, breaks are wonderful… Too much to eat, too much coffee…

The guy next to me didn’t manage to get the command line version working neither any IDE… Help is not wished.

At least, there’s a recent issue of german magazin in the conference file… With the title story about Ruby on Rails, hrr, hrr ;) .
Sometimes i think the IT world needs more egomaniac, rockstar-like developers like Heinemeier Hansson

Why on earth does one guy write the code from the beamer down on a sheet of paper while he’s checking his emails at the same time?? Sometimes the outer world seems like a strange place to me. Strange and weird.

Funny thing: Received a 1&1 spam mail about some profiseller foobar this morning. There are two guys from 1&1 at the opposite desk… Well, i’m too good educated…

Is it a good idea to but lawyers and webprogrammers into the same hotel? ;)

“Divs are good for updating thingies on the page”

I guess its obvious that english isn’t my native language (can’t get the thought out of my head that tante is mocking me…), but language and spoken words always creates a frame for thoughts and far to often, a cage… And for that being said, one should pay more attention on how to paraphrase things.

I really hate it if the speakers machine is not prepared well. I really do enjoy giving little demonstrations but i’m fastidious to paranoid that everything is taken care of, tested and proved to be working… If their only 8 hours time, not working improvisation sucks.

I have to say, i really do like Groovy, it’s a chance to get some serious scripting into Java at home… err i wanted to say, at work. People tend to focus on just one language and limiting themselves, but with Groovy i can argue: It’s Java with some fancy things on top. And at least for me, it’s a good thing.

“Mit diesen Dingen kann man beliebig fancy werden” — Argh, my head schmerzts…

I should collect some pudding for the gay bar to see if this guy is really as witty as he writes. Would pudding suffer to pay you or do want some Hägen Dasz?

Party is over… Good night & good fight ;)

A fistfull of readers

23-Oct-07

After presenting a working InputStream on a ByteBuffer, i have to more readers for you out there.

First, the StringBufferReader to efficient read data from a StringBuffer. One can use new java.io.StringReader(sb.toString()) but that would convert the whole StringBuffer (sb) to a string, loosing a whole lotta memory if the string is just big enough. If you can assure that the StringBuffer don’t need to be modified, use the following code:

import java.io.IOException;
import java.io.Reader;
 
public class StringBufferReader extends Reader {
	private int pos;
	private final StringBuffer sb;	
	private boolean closed;
 
	public StringBufferReader(final StringBuffer sb) {
		this.sb = sb;
		this.pos = 0;
		this.closed = false;
	}
 
	@Override
	public void close() throws IOException {
		this.closed = true;
	}
 
	@Override
	public int read(char[] cbuf, int off, int len) throws IOException {
		if(closed)
			throw new IOException("Reader is closed");
		int _len = Math.min(len, sb.length() - pos);		
		sb.getChars(pos, pos + _len, cbuf, off);
		pos += _len;
		return _len == 0 ? -1 : _len;
	}
}

It uses no intermediate buffer.

In the same context i stumbled upon the Byte Order Mark (BOM) in some UTF8 files (especially ones that were created with tools under Microsoft Windows).

The InputReaders and Streams in the JRE don’t skip the BOM, neither does the org.dom4j.io.SAXReader so parsing of such XML files or strings fails with something like “Content not allowed in prolog”. Enter my simple BOMSkippingReader:

import java.io.IOException;
import java.io.Reader;
 
/**
 * This reader skips a possible Byte Order Marker at the 
 * start of UTF8 files which java doesn't.
 * @author michael
 *
 */
public class BOMSkippingReader extends Reader {
	private final Reader decorated;	
	private final boolean rewrite;
	private final int firstchar;
	private int pos = 0;
 
	public BOMSkippingReader(final Reader decorated) throws IOException {
		this.decorated = decorated;
 
		this.firstchar = decorated.read();						
		this.rewrite = firstchar != 65279;			
	}
 
	@Override
	public void close() throws IOException {
		decorated.close();
	}
 
	@Override
	public int read(char[] cbuf, int off, int len) throws IOException {					
		int redone = 0;					
		while(rewrite && pos < 1) {
			cbuf[off + pos++] = (char) firstchar;
			++redone;
		}
		return redone + decorated.read(cbuf, off + redone, len - redone);				
	}
}

If there’s a BOM in the underlying reader, it’s skipped, otherwise written back to the reader. Works well for me and the small while loop doesn’t have much impact on the performance in my app.

Java: Creating a Stream on a ByteBuffer

18-Oct-07

This example is plain wrong. The InputStream will cause an endless loop as it always returns a value >= 0. Working code as follows:

private static InputStream _newInputStream(final ByteBuffer buf) {
	return new InputStream() {
		public synchronized int read() throws IOException {				
			return buf.hasRemaining() ? buf.get() : -1;
		}
 
		public synchronized int read(byte[] bytes, int off, int len) throws IOException {			
			int rv = Math.min(len, buf.remaining());				
			buf.get(bytes, off, rv);
			return rv == 0 ? -1 : rv;
		}
	};
}

JDBC: Get autogenerated keys on a Oracle DB

09-Oct-07

With the current and latest Oracle JDBC Drivers it’s possible to retrieve one automatically generated key based on a sequence or any other arbitrary value (autogenerated-keys or identity columns in other databases).

Certainly it isn’t as simple as just use using Statement.html#getGeneratedKeys() as it simply returns an emtpy resultset.

After browsing around, i saw that java.sql.Connection can prepare a statement with a flag to return generated keys like so:

connection.prepareStatement("INSERT INTO FOOBAR VALUES(id.nextval, 1), Statement.RETURN_GENERATED_KEYS);

(By the way, it’s always a good idea to use prepared statements from a performance point of view as they can be reused)

Anyway, it wouldn’t be an Oracle product if something is different like any other products and i still was left alone in the dark with an empty result set.

Follow the path to enlightment:

final String sql = "INSERT INTO foobar(id, b) VALUES (id.nextval, ?)";
stmt = connection.prepareStatement(sql,new String[]{"ID"});			
stmt.setString(1, "bar");
stmt.execute();		
rs = stmt.getGeneratedKeys();
rs.next();
rv = rs.getInt(1);

Telling oracle which column contains the generated value does the trick. It’s really well hidden on their website. Be aware, you cannot refer to the returned keys by name, you need to address them 1 based.

Be aware that this doesn’t work inside a 9.2.x.x or 10.2.x.x Oracle Database as a Java Stored Procedure. Either the driver isn’t JDBC 3 (9.2) or the methods are not supported (10.2). You can work around this problem with 2 statements, first select id.nextval from somewhere, then execute your insert. Lame, but i didn’t find any other solution.

Ran on the client side with the latest JDBC from Oracle on the other hand works just fine.

The Pan-Computer-Programming-Language Conference

05-Oct-07

Ruby (grabbing the microphone): Um so yeah I’d just like to kick this bad boy off by saying that THE REST OF YOU SUCK A**!!! Yeah, I said it! The A-word! A**! Oh yeah! Boom, baby! Woo! Ruby FTW!

Read the whole conference here, found at the gay bar.

Close
E-mail It