Archive for January, 2008
20th Jan 2008
The End of the Mouse
Robert X. Cringley — far and away the best thing related to high technology coming out of Charleston, South Carolina — suggested in his annual tech predictions that Apple would deliver a replacement for the mouse in 2008. Here we are just two weeks later, mere days after MacWorld 2008, and the world has the new MacBook Air with a touchscreen built into the laptop!
I’m not sure if it’s too early to claim victory on that prediction, but Bob must be looking closely at the new touchscreen. So is Steve Ballmer. It won’t be long before Microsoft announces they are working with hardware manufacturers to create the best touchscreen UI ever which will trump any competing product, integrate seamlessly with spellchecking in Office, and own this new hardware market segment. It’ll be delivered in 2009, baked into the next OS, and be integrated with the next generation of Zune. Yawn.
Robert X. Cringley — far and away the best thing related to high technology coming out of Charleston, South Carolina — suggested in his annual tech predictions that Apple would deliver a replacement for the mouse in 2008. Here we are just two weeks later, mere days after MacWorld 2008, and the world has the new MacBook Air with a touchscreen built into the laptop!
I’m not sure if it’s too early to claim victory on that prediction, but Bob must be looking closely at the new touchscreen. So is Steve Ballmer. It won’t be long before Microsoft announces they are working with hardware manufacturers to create the best touchscreen UI ever which will trump any competing product, integrate seamlessly with spellchecking in Office, and own this new hardware market segment. It’ll be delivered in 2009, baked into the next OS, and be integrated with the next generation of Zune. Yawn.
Posted by Mark Turansky under
Technology
No Comments »
18th Jan 2008
HOW TO: Download & sort pictures from your camera using Python
I’ve got tens of thousands of photos. When I last checked, the size on disk was over 25gb. And why not? Film is free!
How do I keep track of them all?
First, there’s Picasa from Google. It’s awesome. It’s the iTunes of photos.
Second, there’s a little Python script I called “DownloadPhotosFromCameraAndSort.py” (It’s .txt on the server, rename to .py if you download it).
If you couldn’t tell, I like meaningful names for my scripts. Likewise for my Java classes, components, projects, etc. Good code communicates it’s purpose clearly without too much human parsing.
The script does the following:
- Find my camera
- Download all pictures/movies to 1 or more destinations
- Confirm the download before deleting the picture from the camera
- Sort the pictures into a dated subdirectory based on the individual picture’s last modified time
The dated directories give me a running chronology of my life and the lives of my wife and daughter. It’s not a fancy archival system, but it’s simple and easy for me. It may work for you, too.
The archive looks like this:

I’ve got tens of thousands of photos. When I last checked, the size on disk was over 25gb. And why not? Film is free!
How do I keep track of them all?
First, there’s Picasa from Google. It’s awesome. It’s the iTunes of photos.
Second, there’s a little Python script I called “DownloadPhotosFromCameraAndSort.py” (It’s .txt on the server, rename to .py if you download it).
If you couldn’t tell, I like meaningful names for my scripts. Likewise for my Java classes, components, projects, etc. Good code communicates it’s purpose clearly without too much human parsing.
The script does the following:
- Find my camera
- Download all pictures/movies to 1 or more destinations
- Confirm the download before deleting the picture from the camera
- Sort the pictures into a dated subdirectory based on the individual picture’s last modified time
The dated directories give me a running chronology of my life and the lives of my wife and daughter. It’s not a fancy archival system, but it’s simple and easy for me. It may work for you, too.
The archive looks like this:

Posted by Mark Turansky under
HOW TO, Python
2 Comments »
11th Jan 2008
HOW TO: Bootstrap Java programs in isolated classloaders
Bootstrapping is the process by which you load a very small and very simple pure java program with no dependencies that, in turn, loads, configures, and runs more complex programs with varying dependencies. Bootstrapping lets you run your container without polluting the system classpath. This allows you to run your deployed applications with the unpolluted system classpath as its parent. You’ve achieved classloader isolation.
When would you want to bootstrap? Any time you want an unpolluted system classpath, which I’m finding is often convenient.
Let’s say you want to write some kind of middleware product, a container of some sort that deploys other applications within it. You will run into classloading issues. The dependencies that your container has (say, Spring 2.0.6) may not be what your deployed application requires (maybe, Spring 1.2.6). You will find that you cannot have commons-logging in both applications (container and child). There are many ways to encounter java.lang.LinkageErrors. It’s very easy to cross the streams when running in a mutli-app environment.
What you want to do is load your container and deployed apps in splendid isolation from each other. How do you do that? Bootstrapping!
Here’s how you bootstrap…
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
public class Bootstrap {
public static void main(String[] args) throws Exception {
/*
Assume your application has a "home" directory
with /classes and /lib beneath it, where you can put
loose files and jars.
Thus,
/usr/local/src/APP
/usr/local/src/APP/classes
/usr/local/src/APP/lib
*/
String HOME = "/usr/local/src/YOURAPP";
String CLASSES = HOME + "/classes";
String LIB = HOME + "/lib";
// add the classes dir and each jar in lib to a List of URLs.
List urls = new ArrayList ();
urls.add(new File(CLASSES).toURL());
for (File f : new File(LIB).listFiles()) {
urls.add(f.toURL());
}
// feed your URLs to a URLClassLoader!
ClassLoader classloader =
new URLClassLoader(
urls.toArray(new URL[0]),
ClassLoader.getSystemClassLoader().getParent());
// relative to that classloader, find the main class
// you want to bootstrap, which is the first cmd line arg
Class mainClass = classloader.loadClass(args[0]);
Method main = mainClass.getMethod(”main”,
new Class[]{args.getClass()});
// well-behaved Java packages work relative to the
// context classloader. Others don’t (like commons-logging)
Thread.currentThread().setContextClassLoader(classloader);
// you want to prune the first arg because its your main class.
// you want to pass the remaining args as the “real” args to your main
String[] nextArgs = new String[args.length - 1];
System.arraycopy(args, 1, nextArgs, 0, nextArgs.length);
main.invoke(null, new Object[] { nextArgs });
}
}
You can try this code out for yourself. Cut & paste the bootstrap code above into your favorite IDE, put that single Bootstrap.class onto your classpath, and run it like so:
java -cp . Bootstrap sample.HelloWorldMain Hello!
.
Click here to download the sample /usr/local/src/YOURAPP application.
Tip for Windows users, you can make the path c:\usr\local\src\YOURAPP it’ll work.
Bootstrapping is the process by which you load a very small and very simple pure java program with no dependencies that, in turn, loads, configures, and runs more complex programs with varying dependencies. Bootstrapping lets you run your container without polluting the system classpath. This allows you to run your deployed applications with the unpolluted system classpath as its parent. You’ve achieved classloader isolation.
When would you want to bootstrap? Any time you want an unpolluted system classpath, which I’m finding is often convenient.
Let’s say you want to write some kind of middleware product, a container of some sort that deploys other applications within it. You will run into classloading issues. The dependencies that your container has (say, Spring 2.0.6) may not be what your deployed application requires (maybe, Spring 1.2.6). You will find that you cannot have commons-logging in both applications (container and child). There are many ways to encounter java.lang.LinkageErrors. It’s very easy to cross the streams when running in a mutli-app environment.
What you want to do is load your container and deployed apps in splendid isolation from each other. How do you do that? Bootstrapping!
Here’s how you bootstrap…
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
public class Bootstrap {
public static void main(String[] args) throws Exception {
/*
Assume your application has a "home" directory
with /classes and /lib beneath it, where you can put
loose files and jars.
Thus,
/usr/local/src/APP
/usr/local/src/APP/classes
/usr/local/src/APP/lib
*/
String HOME = "/usr/local/src/YOURAPP";
String CLASSES = HOME + "/classes";
String LIB = HOME + "/lib";
// add the classes dir and each jar in lib to a List of URLs.
List urls = new ArrayList ();
urls.add(new File(CLASSES).toURL());
for (File f : new File(LIB).listFiles()) {
urls.add(f.toURL());
}
// feed your URLs to a URLClassLoader!
ClassLoader classloader =
new URLClassLoader(
urls.toArray(new URL[0]),
ClassLoader.getSystemClassLoader().getParent());
// relative to that classloader, find the main class
// you want to bootstrap, which is the first cmd line arg
Class mainClass = classloader.loadClass(args[0]);
Method main = mainClass.getMethod(”main”,
new Class[]{args.getClass()});
// well-behaved Java packages work relative to the
// context classloader. Others don’t (like commons-logging)
Thread.currentThread().setContextClassLoader(classloader);
// you want to prune the first arg because its your main class.
// you want to pass the remaining args as the “real” args to your main
String[] nextArgs = new String[args.length - 1];
System.arraycopy(args, 1, nextArgs, 0, nextArgs.length);
main.invoke(null, new Object[] { nextArgs });
}
}
You can try this code out for yourself. Cut & paste the bootstrap code above into your favorite IDE, put that single Bootstrap.class onto your classpath, and run it like so:
java -cp . Bootstrap sample.HelloWorldMain Hello!
.
Click here to download the sample /usr/local/src/YOURAPP application.
Tip for Windows users, you can make the path c:\usr\local\src\YOURAPP it’ll work.
Posted by Mark Turansky under
Code Hints, Engineering, HOW TO
15 Comments »


