How big is big anyway?

Posted on April 5th, 2009 in The Universe by aaron

Let’s say the human race makes a very massive leap forward in technology. We invent a space probe that can instantly jump to any star in our galaxy. Once the probe arrives at a star, it takes one second to scan the star, it’s planets, and any other interesting object in the area (for instance, signs of life). So, traveling to any star and scanning it takes a total of one second.
Now for a bit of simple math. According to wikipediaмебель в болгарии, there are at least 200,000,000,000 stars in our galaxy. Our super probe will take 200,000,000,000 seconds at minimum to return from it’s mission. That’s almost 6342 years!
This was just a thought experiment to try to get a grasp on how big our universe is. Ignore any parallel advances in technology that would happen, creation of a swarm of probes, or prioritizing high interest stars for a phased mission.
Wikipedia also has an estimation that there are 9 x 10^21 stars in the observable universe. That’s 9 billion trillion stars. We’ll need more probes, it would take about 285 trillion years at 1 second per star for our probe to scan the observable universe.

Quantum theory and fractals

Posted on March 31st, 2009 in The Universe by aaron

I may not be qualified for the janitorial staff at the Perimeter Institute, but I’m placing my bet on Tim Palmer’s idea that fractals may make sense of the quantum world. Besides, representing our universe with a set of fractals and seed values would compress all of our universe nicely into a portable simulator for an alien kid’s 1st grade science project. The fractal iteration count could be time. When all those brilliant physicists prove that Tim Palmer was right, I will be standing behind them pointing my finger and saying “I told you so”.

We Will Be Legend?

Posted on December 29th, 2007 in Biology, Movies by aaron

I saw I Am Legend last night, and overall I liked it. Its not a big screen must-see, but worth renting. After the movie, some friends and I were thinking that gasoline would be inert after 3 years so Will Smith’s Shelby GT 500 would be collecting dust and weeds. Turns out, gasoline can still ignite after 10 years.

Now the real reason for this post, and a reiteration of why any scientists should be required to watch all major sci-fi movies before saying “Hey, what could go wrong?”. I read an article on using a virus to destroy cancer. Do I think this research should stop? No, I just found it humorous and ironic that I read this article right after seeing I Am Legend.

ASCII Vision?

Posted on September 7th, 2007 in Catch All, Links by aaron

I’m back from a brief blogging hiatus, 10 of those days spent at Disney World with some friends. We had a great time, and I even managed to resist the Disney marketing machine for the most part. Wow, do they have pushing goods down to a science. I didn’t know whether to be appalled or impressed, maybe both?

Anyway, do you want to view the world in ASCII?. Very cool. The video makes me think that once ultra-light-weight goggles in the form of glasses or Virtual Retinal Displays are common-place, many people will wear them all day as a visual overlay on life. We are constantly connected now, but with bulky devices we have to hold in front of our faces and use our hands to control. Commercial devices are really just starting to come out with non-clunky user interfaces.

I believe that calculators in grade school put a nice dent in the average person’s ability to perform basic math in their head. I wonder if the increasing offload of our brain-work to the internet will dumb us all down, or will our brains actually work better by adapting to use the internet as an extension of itself? If the internet is seriously disrupted (it is very possible), how much of the world would slow to a crawl until it came back online?

Software Chewbacca Defense?

Posted on August 15th, 2007 in Catch All by aaron

A co-worker sent me a great story about The Cool Cam. Now this is actually a pretty cool feature, but many feature requirements that come out of operations are seemingly non-important (read: absurd) but somehow make people buy the product. Does your project have a software feature that is equivalent to the Chewbacca Defense?

Would you eat here?

Posted on August 15th, 2007 in Catch All by aaron

Some co-workers and I were talking about a restaurant where you would sit down, say “I want to spend $7″, and the food you received would be randomly chosen based on what the chefs were cooking that day and how much you want to pay. I think this works very well for the demographic of people that go out to lunch all of the time and are sick of every restaurant within a 10 mile radius.

So here’s another idea along those lines. Once OLEDs are less expensive, it would be cool to have an interactive menu where you could quickly rank 1-5 how much you like different ingredients such as chicken, pork, tomatoes, onions, etc. These preferences would act as a filter and could highlight or gray-out menu items based on the ingredients you like.
If you want to get fancy, a thumb-print scanner could store your preferences so if you return to the restaurant you would press your thumb on the menu and it would load up the preferences from your last visit. To one-up that, an online site could host your preferences so they always travel with you. Press your thumb on the menu and your favorite foods and ingredients could be pulled down from your MySpace account or something. There are many other cool ideas along these lines, but I’ll stop rambling now :P

Space-jumping, puffy planets, OpenGL, Beautiful Code, Bacteria,

Posted on August 9th, 2007 in Books, Links by aaron

Java Vampires??

Posted on August 6th, 2007 in Java by aaron

I wanted to share a mistake that I made while coding the other day, in the hopes that others will avoid it. This example will show how to use reflection in Java to retrieve all defined public fields of a certain class, and add them to a List. Or will it?

First let’s define the interface that our detectable fields will implement:

public interface Vampire {
	void stabWithWoodenStake();
}

Great, we have a way of killing our Vampires. Now let’s make an abstract class that will represent a Coven, and provide an easy way to build a list of all Vampires that are defined within it.

public class AbstractVampireCoven {
	private final List<vampire> vampires = new ArrayList<vampire>();

	public AbstractVampireCoven() throws IllegalAccessException {
		super();
		Field[] fields = getClass().getFields();
		for (Field field : fields) {
			Object fieldValue = field.get(this);

			// store all vampires in the coven list
			if (fieldValue instanceof Vampire) {
				vampires.add((Vampire) fieldValue);
			}
		}
	}

	public Vampire[] getVampires() {
		return vampires.toArray(new Vampire[vampires.size()]);
	}
}

The common functionality of a Coven is now defined, we need to make our super-coven of the most powerful Vampires of all time!

public class SuperVampireCoven extends AbstractVampireCoven {

	// these fields will be returned by getClass().getFields()
	public final Vampire DRACULA = new DraculaVampire();
	public final Vampire CHOCULA = new ChoculaVampire();
	public final Vampire LESTAT = new LestatVampire();

	public SuperVampireCoven() throws IllegalAccessException {
		super();
	}

	public static class DraculaVampire implements Vampire {
		@Override
		public void stabWithWoodenStake() {
			System.out.println("Dracula turns to dust!");
		}
	}

	public static class ChoculaVampire implements Vampire {
		@Override
		public void stabWithWoodenStake() {
			System.out.println("Chocula turns into a marshmellow!");
		}
	}

	public static class LestatVampire implements Vampire {
		@Override
		public void stabWithWoodenStake() {
			System.out.println("Lestat bursts into song!");
		}
	}
}

We know how to kill a Vampire, we know about the SuperVampireCoven, it’s time to launch an attack:

public class AttackSuperCoven {
	public static void main(String[] args) {
		try {
			SuperVampireCoven coven = new SuperVampireCoven();

			// stab each vampire with a wooden stake
			System.out.println("Executing all vampires...");
			for (Vampire vampire : coven.getVampires()) {
				vampire.stabWithWoodenStake();
			}
		} catch (IllegalAccessException iae) {
			iae.printStackTrace();
		}
	}
}

Will we be victorious? Here is the output when AttackSuperCoven is run:


Executing all vampires...

What happened? No vampire carnage? It seems our Vampires can not be accessed via reflection.

The lesson for this example is that we must always remember the order of operations during the construction of an instance. The SuperVampireCoven constructor is called, which immediate calls super() before it’s instance fields are initialized. Here’s the order in which construction occurs:

  • super() is called
  • Instance fields are initialized
  • The constructor method body is executed

What’s the easiest way to fix this? We will use the power of the ClassLoader to reveal our Vampires by changing the SuperVampireCoven fields to static:

public static final Vampire DRACULA = new DraculaVampire();
public static final Vampire CHOCULA = new ChoculaVampire();
public static final Vampire LESTAT = new LestatVampire();

Since these fields are now static, they will be initialized by the ClassLoader when the SuperVampireCoven class is loaded as opposed to when an instance is created. Run the AttackSuperCoven application with these code changes, and watch the carnage!

Thanks to Tim and Nathan for immediately realizing what I had done wrong when I explained my problem ;)

Zimbra: Week 1

Posted on August 6th, 2007 in Admin, Zimbra by aaron

Last week I installed a Network Edition evaluation of the Zimbra Collaboration Suite at work as a replacement for our Exchange server. Our Mac and Linux users actually outnumber our Windows users, and the Outlook web client really sucks. Many of us just forward our email to GMail, but it was time to move our start-up to a real infrastructure and Exchange just doesn’t fit the needs of our users. Google Apps was disqualified for a lack of IMAP support or offline capabilities, and weak migration and integration with non-Google applications.

For now, I’ve set up my Exchange account to forward a copy of my email to the Zimbra server. I’ve also set the Zimbra server to send emails via the Exchange SMTP so Zimbra doesn’t complain about our users that have no Zimbra account yet. So far I’ve only encountered minor bugs with the web client, and I’ve used it exclusively. Time to start migrating the rest of our users, wish me luck ;)

If you want to see more about Zimbra, they have some nice demos that showcase Zimbra’s large feature set.

Java 6 + enums + Proxy pattern?

Posted on July 24th, 2007 in Java by aaron

I’ve been hacking away on a prototype game using Project Darkstar (SGS). I’m using SGS channels for main categories of data (e.g. players, world, chat), but I still need a way to dispatch payloads to the proper message handler implementation. I was never completely happy with my past structures, most involved some kind of registry/wiring/mapping bureaucracy for each command. I had to remember to update the wiring each time I extended the protocol. My next attempt!? Enums that function as a numeric identifier and handler Proxy.

Let’s say we have a message handler interface:

public interface MessageHandler {
	void handle(byte[] message);
}

and some very simple MessageHandler implementations:

public class SayHandler implements MessageHandler {
	@Override
	public void handle(byte[] message) {
		System.out.println("Say: " + new String(message));
	}
}

public class TellHandler implements MessageHandler {
	@Override
	public void handle(byte[] message) {
		System.out.println("Tell: " + new String(message));
	}
}

public class PartyHandler implements MessageHandler {
	@Override
	public void handle(byte[] message) {
		System.out.println("Party: " + new String(message));
	}
}

Now let’s define an enum that also implements MessageHandler and dispatches to our implementations:

public enum ChatDispatcher implements MessageHandler {
	Say(new SayHandler()),
	Party(new PartyHandler()),
	Tell(new TellHandler());

	private final MessageHandler target;

	private ChatDispatcher(MessageHandler target) {
		this.target = target;
	}

	@Override
	public void handle(byte[] message) {
		target.handle(message);
	}
}

Notice that each enum is given a MessageHandler implementation when it is constructed, such as SayHandler, PartyHandler, or TellHandler. It’s also important to understand that each enum entry has an ordinal value associated with it, which is always assigned in the order in which the enums are defined. Check out the javadocs for Enum and the ordinal() method for more information. I plan to send a numeric value across the network that maps to these ordinal values for dispatching.

We’ve defined our dispatcher and handlers, now let’s see what some usage scenarios look like. Here’s a direct call to one of the enums:

ChatDispatcher.Say.handle("Hello World".getBytes());

This code will output:

Say: Hello World

That’s pretty neat, but I only have a handler ID and a payload coming across the net. How do I get my handler within that context? Class.getEnumConstants() and generics are what I want. Here’s a method that will find my enum:

public static <T extends Enum<T> & MessageHandler> T
  getMessageHandler(int id, Class<T> dispatcherClass) {
	T[] enumValues = dispatcherClass.getEnumConstants();

	if (id >= 0 && id < enumValues.length) {
		return enumValues[id];
	}

	return null;
}

That funky looking generic defined as “T” gives us a compiler time check to make sure the dispatcherClass parameter is an enum that implements the MessageHandler interface. Absolutely required? Nope. Stops some potential issues that would otherwise only appear during runtime? Yep.

Now let’s have a look at more usage code, minus NPE checks for brevity’s sake:

MessageHandler handler = getMessageHandler(1, ChatDispatcher.class);
handler.handle("Hello fellow teammates!".getBytes());

MessageHandler handler2 = getMessageHandler(0, ChatDispatcher.class);
handler2.handle("Hey everyone!".getBytes());

MessageHandler handler3 = getMessageHandler(2, ChatDispatcher.class);
handler3.handle("Psst...don't forget your resist gear!".getBytes());

Here’s the output:

Party: Hello fellow teammates!
Say: Hey everyone!
Tell: Psst...don't forget your resist gear!

We can see that our output reflects the fact that each enum is assigned an ordinal, starting at 0, in the order in which they are defined. This example is just one of many cool tricks that can be done with enums, but I need to get back to coding my game :P

Next Page »