Ubuntu 8.04 gnome session manager is very unreliable and unintuitive. You can hardly accomplish anything using the UI. It is amusing that while one can think of it as a helper program to help you restore your programs between system restarts it can also be used to kill programs currently running on your computer, unexpectedly. The author clearly had no idea of how UI should be designed in general, nor a plan for what he was trying to get accomplished with this program specifically. It is the single worst piece of software included with Ubuntu. Oh well one of these days I'll write a better one and get it included with Ubuntu.
However you can partially turn off this useless software by clicking "Automatically remember..." in the Session Options Tab and instead edit the file ~/.gnome2/sessions by hand.
E.g. I added this program to get started automatically with my X session:
16,RestartCommand=/usr/bin/gvim /home/dmitri/Documents/Status.txt /home/dmitri/Misc/GTD.txt
Unfortunately, this displays a strange error message in VIM. The error message only has an error icon and the path to the file. However after I click on it, all the files are opened just fine, except the second one is opened twice. Oh well, it's still 2008 I guess: it's 2009 that will be the year of the Linux desktop.
Tuesday, December 30, 2008
Wednesday, December 10, 2008
Compensating for lack of unsigned types in Java
For some reason Java has no unsigned primitive types, which makes it really limiting when writing network code or doing bit manipulation.
One workaround is to cast to a longer-type and mask out significant bits.
E.g.:
Int wrong will work most of the time, except when you have most-significant bit of the byte set. Because in Java most-significant bit holds the sign, the following happens:
In fact the Java compiler checks this so the following assignments would show compile errors:
One workaround is to cast to a longer-type and mask out significant bits.
E.g.:
byte b = getAByte(); // Get a byte from somewhere
int wrong = (int) b;
int right = (int) b & 0xff;
Int wrong will work most of the time, except when you have most-significant bit of the byte set. Because in Java most-significant bit holds the sign, the following happens:
byte b = getAByte(); // let's say this holds 0xff
int wrong = (int) b; // becomes -127 or -0x7f
int right = (int) b & 0xff; // becomes 255 or 0xff
In fact the Java compiler checks this so the following assignments would show compile errors:
byte wrong = 0xff;
byte wrong = 0x80;
byte right = 0x7f;
Monday, December 01, 2008
Getting complete Java exception stack trace
JDK Throwable.printStackTrace() function attempts to compact the stack trace of an exception by eliminating common parents of all stack elements. However it is often helpful to see the entire stack trace.
E.g. if using JDK you may write this function to get the stack trace of an exception as a String:
To obtain the complete stack trace you may use this function:
E.g. if using JDK you may write this function to get the stack trace of an exception as a String:
public static String formatStackTrace(Throwable e) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
return stringWriter.toString();
}
To obtain the complete stack trace you may use this function:
private static String formatStackTrace(Throwable e) {
StringBuffer str = new StringBuffer();
str.append(e.getClass().getName()).append(": ");
str.append(e.getMessage());
StackTraceElement[] stack = e.getStackTrace();
for (int i = 0; i < stack.length; i++) {
StackTraceElement element = stack[i];
str.append("\n\tat ").append(element.getClassName()).
append(".").append(element.getMethodName()).
append("(").append(element.getFileName()).append(":").
append(element.getLineNumber()).append(")");
}
Throwable cause = e.getCause();
if (cause != null) {
str.append("\nCaused by: ").append(formatStackTrace(cause));
}
return str.toString();
}
Subscribe to:
Posts (Atom)