2009-11-28

SuperTunnel

Due to some problems I encountered while using GNU HttpTunnel (namely that HttpTunnel would get packets in the wrong order when I was trying to forward ports over SSH over HttpTunnel and cause SSH to disconnect with a failed MAC error), I decided to write an alternative. My dad's work firewalls all outbound traffic besides HTTP and HTTPS, which greatly inconvienences me when I go to work with him as I can't upload new versions of Evaluation Portal or JZBot to my web server.

Anyway, the alternative is called SuperTunnel. There are three main differences between SuperTunnel and HttpTunnel:
  • HttpTunnel has a tendency to get packets out of order when processing high-volume traffic. This caused SSH to repeatedly crash when I would use it to forward ports over HttpTunnel. SuperTunnel does not do this; I've verified that it works when both downloading and uploading data as fast as SuperTunnel will send and receive it.
  • HttpTunnel only allows one socket connection to be active at a time. SuperTunnel allows up to 200 concurrent connections, and in the future that limit will be specified by a configuration file.
  • HttpTunnel uses requests that are long-lived in the sense that a single request will be opened and data streamed down through it as data is received by the server. Since this causes problems with buffering proxies, SuperTunnel instead follows an approach where a single connection will only be used once to receive data. Once even a single byte is received, the connection ends and a new one is made. SuperTunnel waits one second between receive connections so that an excessive number of connections aren't made with each one holding only a couple of bytes.
Instructions are present at http://supertunnel.googlecode.com on how to download SuperTunnel. Currently, you'll have to check out the Subversion repository SuperTunnel is stored in. I plan on making a direct download available soon. You'll also need your own server to run SuperTunnel on.

2009-11-07

Wave Othello Gadget

A few days ago, I spent a day and wrote a Google Wave Othello gadget. The gadget's URL is http://trivergia.com/wavyothello/gadget/jw.othello.client.OthelloGadget.gadget.xml. Add it to a wave, play a game with a friend, and add a comment to this post and let me know how it went or if there are any new features you'd like.

2009-10-17

Single-file IRC server

Those of you that know what IRC is are probably already thinking I'm off my rocker, given the title of this post. And I probably am. I decided to try my hand at writing an IRC server in a single Java file. I've got it to the point that people can connect to it, join channels, set the channel topic, send messages (and receive them) at channels, send private messages, and change nicks, so I figured I'd blog about it and include a link to it if anyone wants to use it. It's not intended to become a production IRC server; I'm mostly writing it so that I can test out an IRC bot that I'm writing when I don't have an internet connection.

Anyway, here's the source code for the server. Download it, compile it with "javac Connection.java", and then run it with "java Connection <hostname>", replacing <hostname> with your computer's hostname. If you're not sure what your computer's hostname is, just use localhost as the hostname. Then, open your favorite IRC client, connect to "127.0.0.1:6667", and join any channel you want. You can switch nicks, set the channel's topic (even though you're not a channel op), and other users can connect, join channels, and chat with you. Sending messages directly between users also works. Modes do not, however (channels always act as if they are mode +nt, no matter what you set their mode to be, but anyone can change the topic even though the channels have +t present). I'm hoping to add more functionality to this server soon.Link

Java Proxy instance throws a NullPointerException

This is something I just found out, and I figured I'd blog about it for those that might come across this in the future.

I'm writing some code in a project (JZBot specifically, http://jzbot.googlecode.com) that uses java.lang.reflect.Proxy. At one point, I was calling a method on a proxy instance, and it was throwing a NullPointerException. The weird thing about this was that the NullPointerException was being thrown from within the proxy instance itself, not from the InvocationHandler that it is supposed to call. Other methods on the proxy worked, indicating that there wasn't some error with the invocation handler somehow being set to null.

Eventually, I found the problem: I had declared the method on the interface that the proxy implemented to return a boolean, but the invocation handler was returning null. The auto-unboxing that was being done by the proxy instance internally was messing things up. I changed the method's return type to void (which is what it should have been), and everything worked.

This is yet another example of where to watch out for autoboxing and unboxing. Admittedly, it would be more helpful if the NPE had a message stating something like, for example, "null can't be unboxed to a boolean", which would most likely have saved me quite a bit of time. Oh well.

2009-09-10

Airplane problem simulator

I just got back from a party where a friend of mine told me the classic "Airplane seating problem", and the resulting answer. The answer was somewhat hard for me to believe, so, since I had brought my laptop, I pulled it out and spent 10 minutes writing this program to simulate the airplane problem. It turns out that the answer he had told me is correct. I'll be darned.

Anyway, here's the program, written in Java. Paste it into a file called PlaneSim.java, run "javac PlaneSim.java" and then "java PlaneSim" to run it. The javadoc at the beginning of the program explains what the airplane problem is, in case you haven't heard of it before.

import java.util.Random;

/**
* There's a common puzzle that goes something like this: There's a plane that
* has 100 seats in it. Each person has a ticket that assigns them to a
* particular seat. However, the first person doesn't follow his ticket, instead
* choosing a random seat to sit in. Each successive person tries to sit in the
* seat listed on their ticket. If that seat is already taken, they choose a
* random vacant seat to sit in. This goes on until all 100 passengers have been
* seated. What is the chance that the last person will be in his correct seat?
* The puzzle's correct answer is 0.5 (IE he's in his correct seat about half of
* the time on average). This program simulates the airplane problem several
* thousand times to verify this answer, and it does, indeed, verify that 0.5 is
* the correct answer.
*
* @author Alexander Boyd
*
*/
public class PlaneSim
{
private static int seatcount;

/**
* @param args
*/
public static void main(String[] args)
{
seatcount = 100;
// Run 100,000 simulations
int simcount = 100000;
int correctTimes = 0;
for (int i = 0; i < simcount; i++)
{
correctTimes += ((sim() == (seatcount - 1)) ? 1 : 0);
}
System.out.println("Simulation count: " + simcount);
System.out.println("Last person was in correct seat " + correctTimes
+ " times");
}

public static int sim()
{
int[] seats = new int[seatcount];
// Change all seats to be empty
for (int i = 0; i < seats.length; i++)
{
seats[i] = -1;
}
// Run the simulation
for (int i = 0; i < seatcount; i++)
{
if (i == 0)
{
// First person, so random seat
seats[random()] = 0;
}
else
{
// Put this person in their seat if it's empty
if (seats[i] == -1)
{
seats[i] = i;
}
// If it's not empty, randomly place this person until we get an
// empty seat to put them in.
else
{
int randomIndex = random();
while (seats[randomIndex] != -1)
randomIndex = random();
seats[randomIndex] = i;
}
}
}
// Simulation is done. Now see who's in the last seat.
return seats[seatcount - 1];
}

private static Random random = new Random();

public static int random()
{
return random.nextInt(seatcount);
}
}

2009-09-04

Natural bee repellant

This is a new discovery made by my mom that I figured might be helpful to other people. In our yard, we grow spearmint. I don't remember exactly why she tried using it against bees, but placing a cutting of spearmint on our picnic table has proved to be a very effective bee repellant. Like I mean one day we were getting swarmed with meatbees while eating outside, so we put a cutting of spearmint on the table, and we didn't see a single bee after that. So if you want to get rid of bees, plant spearmint and use cuttings of it whenever you eat outdoors.

And if you're going to plant some spearmint, I should probably tell you that it's extremely agressive in terms of spreading by root. So plant it in a pot for best results.

2009-08-07

A test blog post

I'm posting this with a GNOME applet to see if it works. So everyone can pretty much ignore this post.

UPDATE: it appears to work, except that it doesn't place the title correctly.

2009-07-07

Chinese Firebox

This one is my dad's brainchild. He came up with the design for it a couple of years ago, and we've built one at my grandma's every 4th/24th that we're there since. Here's a video:


Cool, huh. The whole thing is made with the contents of 24 crackle bombs (the little green round things about the size of a smoke bomb). It takes its name from the fact that the actual firework, once built, looks like a miniature take-out box from a Chinese restaurant. I'll post instructions on how to make one, along with some pictures of the actual firework, sometime in the future.

2009-05-26

Compiz and vanished animations in Jaunty

I figured I should probably mention this in case anyone has this problem and is stupid enough not to see the solution like I did...

I recently upgraded my system to Ubuntu Jaunty, and noticed that a ton of window animations in compiz had disappeared. This, of course, frustrated me, as the burn animation is my personal favorite and the one I use on all normal windows.

For some reason (and I can't figure out why), the animation add-ons appear to be disabled by default in Jaunty. Or maybe it happened when it upgraded compiz, I'm not really sure and I don't know enough about Ubuntu to say. But either way, enabling the animation add-ons fixed the problem. So anyone out there, if you're all the sudden missing a ton of animations, make sure that animation add-ons is enabled before you go to irc.freenode.net/#ubuntu and make a royal idiot of yourself.

2009-05-12

TrayTimer

I spent most of today writing another useful utility, TrayTimer. It adds a tray icon that you can click to set timers, much like a kitchen timer. Here's a screenshot:




When you click on the tray icon, that window pops up, much like when you click on the clock in Windows Vista. You can then add timers using the text fields on the right. The timers that you've added show up to the left. You can click on the button that shows the time remaining to pause the timer. When a counting-down timer reaches 0, a window opens up that says "Timer 1: Time's up".

The code for the program is available at http://jwutils.googlecode.com/svn/trunk/projects/text/binutils/src/com/googlecode/jwutils/timer/. Download all four source code files, compile them, and run TrayTimer. Or you can svn export that url and compile it. I'll post a download soon that contains the whole thing already compiled.

2009-05-11

Javawizard's Surveyer now up and running

I just got another web application up and running, Javawizard's Surveyer. It's a web application for creating and taking surveys. It's not fancy or anything (I wrote it in less than 2 days), but it's easy to use, and free. In a few days, I'm going to add the ability to actually embed a survey within an email. When you open an email with a survey, there isn't a link or anything; the email actually appears inside of the survey. I've tested it out with gmail and yahoo mail, and it works with both.

2009-05-03

Pastebin API for Java

For those out there that would like to access pastebin.com from within a java class to create, read, and delete posts, I decided to write a class that does just that. Currently, it only creates pastebin posts, but I'm working to add functionality to read and delete posts as well.

You can download the current version at http://code.google.com/p/jwutils/source/browse/trunk/projects/jzbot/src/org/opengroove/jzbot/utils/Pastebin.java. This will automatically update as I add more code to the class.

2009-03-27

In the news

Check this out:

http://www.sltrib.com/news/ci_12005706

My company (Trivergia) got our risk assessment tool in the news!

2009-03-17

BZFlag 3.0 = vaporware

As most of you know, I'm a developer for the online game BZFlag. I recently had a conversation with one of the project managers that went something like this:

When is bzflag 3.0 going to be released?
When it's finished, tested, and bug-free.
Ok, when do you estimate that will happen?
When it happens.
Right, but could you give me an estimate as to when it will probably happen?
When the developers have time.
--- At this point, I start to get a bit frustrated. ---
Ok. Based on how much time the developers have had so far, when would you estimate it will be out?
When it's done.
--- I'm so close to spamming the guy until he bans me or something ---
So could you estimate to the nearest number of years when it will be out?
Yes. Within the next 100 years.

I've asked and asked, and no-one has an estimate as to when it will be out. The last release that changed a lot of stuff was over 4 years ago, and people are sick of waiting. To the BZFlag developers: Please, for the sake of the players that want to see the improvements made in 3.0, fix up the few major bugs that are there and release a beta version of 3.0. That way, people can actually download and try it, and I won't have to put up with people pestering me to find out when it will be out.

Until this happens, I'm going to regard 3.0 as vaporware. The really cool new version that would improve everything. The really cool new version that wasn't actually going to be released.

GWT and reflection

I've decided to use GWT in some of my more recent projects. It's been an awesome tool to have, except for one thing. It doesn't support java reflection. This makes coding pluggable applications really hard.

Google's excuse is that it would be too hard to do reflection, what with trying to find the .js file that holds the class. In my opinion, this is a wimpy excuse. Why not allow reflection for classes within the module itself? I can definitely see the issue with accessing classes not compiled with the module, which is what their excuse covers, but I really can't see any issues with accessing classes compiled with the module.

Granted, the code is currently obfuscated. That throws a wrench in the works, but it's only a minor one. A module could be compiled with support for reflection, which could build a list that maps real class names to obfuscated class names. This would cut down on security, assuming that a developer is using obfuscation to protect intellectual property, but then at least reflection would work.

GWT developers, please add reflection. I know there are libraries out there that can help with it, but it would be really nice to have it just built in to GWT.

2009-02-09

JMLogo works!

JMLogo now works, complete with support for creating programs and creating procedures within those programs! I've tested it (successfully) on the Motorola Razr V3 and the Pantech C300.

If you'd like to install JMLogo, open your phone's web browser and go to http://trivergia.com/jml.jad , and install it when prompted. Drop me a line if it works for you.

I know people aren't going to like this, but JMLogo only works on java-enabled phones. Most AT&T phones are java enabled, most Verizon phones aren't.

2009-02-07

JMLogo released as open-source

I finally got around to releasing JMLogo (a logo interpreter for mobile phones) as open-source. For those out there that are interested in viewing (and editing) JMLogo's source, you can now get it by using subversion to checkout https://jwutils.googlecode.com/svn/trunk/projects/jmlogo/jmlogo and you can view the code online at http://code.google.com/p/jwutils/source/browse/#svn/trunk/projects/mobile/jmlogo/jmlogo .

2009-02-06

JSRSupport

Yet another of my applications for mobile phones is JSRSupport, a really simple application that I just wrote. It's intended for mobile phone developers, and displays which mobile phone related JSRs a phone supports.

You can download JSRSupport by visiting http://trivergia.com/jsrsupport/js.jad in your mobile phone's browser. JSRSupport is about 2KB in size, so keep in mind that you'll probably get charged by your wireless carrier for downloading stuff. Other than that, JSRSupport is free.

2009-02-04

JMLogo - A Logo interpreter for mobile phones

These last few days, I've been working on JMLogo, a Logo interpreter for mobile phones. It's UI is somewhat based around the UI of Microsoft Windows Logo, but there are some changes. Currently, you can't create procedures, and it only has a limited set of built-in commands.

JMLogo is a MIDlet, so it will only work on Java-enabled phones. The Motorola razr v3 and the Pantech C300 both support JMLogo, although there's currently a bug that prevents JMLogo from starting up on the razr. JMLogo will not work on Verizon phones.

To download JMLogo, open your mobile phone's browser and go to http://trivergia.com/jml.jad and install it. If you have Sun's Wireless Toolkit installed, then you can go to that URL in your regular computer's browser, and a mobile phone emulator will open and run JMLogo.

I'm planning on releasing this as open-source, although I don't know when I'll get around to it. If anyone would like the code for the logo command interpreter itself, or for the whole JMLogo MIDlet, contact me, or post a comment, and I'll get around to releasing it as open-source sooner.

If it doesn't work for you, send me a comment. I just started work on this a few days ago (Monday to be precise), so it's bound to be full of bugs.

I'll be adding support for editing and saving programs, and editing and saving procedures within those programs.

2009-02-02

Top-down and Bottom-up parsing

The topic of parsing is a rather complex one, so I've decided to post some examples of two parsing strategies: top-down parsing and bottom-up parsing.

Top-down parsing is determining how to interpret a particular piece of data by splitting around nonterminals first and sorting these into a hierarchy that ends with terminals. Bottom-up parsing is determining how to interpret a particular piece of data by resolving sets of terminals into terminals themselves, and braching up until the whole set has been resolved.

Let's take an example that most people are familiar with: mathematical expressions. We'll use this expression:

2 + 3 - 4 * 5 + 6

This is usually interpreted as (2 + 3) - ((4 * 5) + 6). So how would a computer arrive at that conclusion using each of the parsing methods above?

Let's take top-down parsing first. If we're using top-down parsing, then we'd look at the lowest-precedence operator that we have. In this case, it's the minus sign. We'd then split the expression around the minus sign, so we now have a new expression:

(2 + 3) - (4 * 5 + 6)

Now we analyze each of those in the same manner. In this case, 2 + 3 is now a terminal expression, so we can look up what we're supposed to do with the + operator (the answer is that we're supposed to add the number, if you didn't know that already) and do it, replacing the expression with the result. So in this case, we resolve 2 + 3 to 5, for a new expresion that looks like this:

(5) - (4 * 5 + 6)

Now we'll analyze 4 * 5 + 6. + is a lower precedence operator than *, so we'll split around + first. Now we have this expression:

(5) - ((4 * 5) + (6))

6 doesn't need resolving at this point, 4 * 5 is a terminal expression, so we can resolve that to 20. Now we have:

(5) - ((20) + (6))

20 + 6 is now a terminal expression, so we can resolve it to:

(5) - (26)

5 - 26 is also a terminal expression, so we can likewise resolve it to:

-21

which is the answer.

Now let's see how we'd go about resolving the expression using bottom-up parsing. Here's the expression again:

2 + 3 - 4 * 5 + 6

With bottom-up parsing, we find each occurrence of the highest-precedence operator, and resolve it first. In this case, * is the highest precedence operator. We'd split this out, then, into:

4 * 5

And then resolve it to

20

And then insert it back into the expression, for a new expression of

2 + 3 - 20 + 6

The next highest precedence operator is +. We'll work left-to-right, so the first one we're going to resolve is

2 + 3

This resolves to

5

So our expression now looks like

5 - 20 + 6

We'll do the same thing to the other + character, splitting it out to

20 + 6

and resolving it to

26

for a new expression of

5 - 26

The next highest precedence operator (and the only one left) is the - sign. We take the expression

5 - 26

and resolve it to

-21

which is our final answer.

Both top-down parsing and bottom-up parsing work for most applications. It's up to you to decide which one you want to use, although in my opinion bottom-up parsing is a lot simpler. You can just add some sort of while loop that checks to see if there are any operands in an expression, and if so, finds the highest one, then the leftmost one out of the appearances of the highest one, then resolves the members immediately surrounding it. This would be a little expensive, but it's very simple to implement.

2009-01-30

Mozilla Bespin

UPDATE: Mozilla released Bespin today. Their post is at http://labs.mozilla.com/2009/02/introducing-bespin/.



I was at a conference today, and heard about a new software program or something that's coming out: Mozilla Bespin (pronounced like "best pin", but without the "t" at the end of "best"). It's essentially an online IDE, and a dang good one at that. From what was shown at the conference, it has integrated syntax highlighting and formatting.

The editor was shown editing javascript. I don't know how it's syntax highlighting and editing features are supported for other languages.

Bespin has an integrated file explorer, used for exploring files within the project to be edited. It looks similar to Mac OS X's Finder when it's set to show each nested folder in a pane, with deeper levels to the right. (if someone knows mac's name for that type of view, post a comment and let me know.) You can open files and edit them, and then save them.

Bespin also has an integrated command line, which supports a lot of standard commands (such as rm and mkdir).

Bespin either has or will have support for integrating with version control systems. I can't remember if they said that it would integrate with CVS or Subversion, or both, but it was one of those.

Bespin is going to be officially released in a week or two, according to Mozilla, so let's see what happens. Until it officially comes out, take everything that I say here with a grain of salt, since I completely forgot a pen and paper (and my computer), so I couldn't take notes during the presentation.

2009-01-26

Wood Puzzle

I've been looking for a particular wood puzzle at stores and such for the last few years, and haven't been able to find it, so I finally decided to create a 3D model of it. Has anyone seen a puzzle that looks like this?

Click to see a larger version


The puzzle is roughly the height of an electric outlet, maybe a bit taller.
There's a loop of string with a wood ball on the end (the wood ball on the string is about the same size as the one attached to the end of the dowel in the puzzle), and the string loops around the lower end of the dowel with the ring on it. The objective is to try to remove the loop of string. I'll probably create a 3D model of the string as well, but string is so much harder to create than rigid objects.

By the way, if anyone really cares, the image was modeled in Google SketchUp 7, and rendered in Kerkythea. A Google search should turn up the location to download and install those, if you're interested them. It took me about a half hour to model the puzzle, and it took the computer (no work by me during that time) about 10 minutes to ray-trace the image. If anyone wants the SketchUp source file, I'd be happy to provide it. Post your request as a comment, and I'll upload it.

2009-01-21

Cookie Recipe

NOTE: I'm continually improving this recipe, and I'm keeping this post up-to-date with the latest changes. So if it's different than the last time you saw it, that's why. Anyway, on to the original post...

I've frequently taken cookies to places that I'm going, and I've had a ton of people ask me for my recipe. I'm beginning to tire of writing it down over and over again, so I decided that I'd post it.

The recipe takes some of it's ingredients from my Grandma's cookie recipe, but a lot of things are different. For example, hers uses shortening, while this one uses butter, and less butter than the amount of shortening in her recipe.

My recipe uses powered eggs, which I've found turn out a lot better than using regular eggs. At the end of the recipe is a note on how to use real eggs. Be forewarned that I haven't made it with real eggs in over a year, so your results may vary. Also, I mention a specific brand of powdered eggs. You can try using other brands, but I've never used them, so, again, your results may vary.

When I make the recipe, I typically make it in a Bosch mixer, using the hook (if you use the Bosch mixer with beaters, they will snap). You can make it using just a wooden spoon, but you'll probably have to mix some of it together with your hands when it gets too thick to use a wooden spoon with. Don't try making it with electric beaters, as it gets so thick that it will burn them up.

Anyway, here's the recipe.

Group 1:
  • 2 1/4 cups brown sugar
  • 2 1/4 cups white sugar
  • 6 cubes (3 cups) butter (works best if softened to the point that a tiny bit of it has melted)
Group 2:
  • 3/4 cup hot water
  • 1/4 cup vanilla
Group 3:
  • 4 1/2 cups flour (white only; whole weat will cause the cookies to fall apart)
  • 1 Tablespoon baking soda
  • 1 Tablespoon salt
  • 1/3 cup Honeyville Powdered Eggs (1/3 cup of the actual powder; do not reconstitute them)
Group 4:
  • 6 cups rolled oats
Group 5:
  • 4 cups chocolate chips (typically 2 bags)
Makes 120 cookies.

In a Bosch mixer (see note above for how to mix without one), mix together Group 1 until thoroughly mixed. You'll want to make sure that there aren't any lumps of brown sugar, or they will end up as crispy chunks in the cookies. Once you've mixed this together, mix Group 2 by itself in a cup. Slowly add this to Group 1 while mixing. It's a good idea to get out a rubber spatula and scrape the dough from the middle of the bowl toward the edges as the liquid from Group 2 has a tendency to pool in the middle of the bowl and not get mixed in. After you've done that and mixed a bit more, mix Group 3 by itself in a separate bowl. Make sure that all ingredients are evenly mixed together. Add this to the Group 1 / Group 2 mixture. Add Group 4, then mix slowly. Then add Group 5 and mix again, but not longer than about 30 seconds or the chocolate chips will start to fall apart.

Set your oven to 350 degrees Fahrenheit. Place a piece of Bakery Pan Lining Paper on a cookie tray (you can get some from Orson Gygi in Salt Lake City), or grease with butter. I've always used paper, so your results may vary with butter. Drop onto the cookie sheet in balls of dough about 1 1/2 inch in diameter, or slightly larger if you want. These should be spaced about 3 inches or so apart from each other. If you want square cookies, you can place them closer. Bake for about 8 to 12 minutes. (I bake mine for exactly 7 minutes 35 seconds, but your oven is likely to be different than mine. Try different baking times and see what works best.)

If I've forgotten anything, feel free to leave a comment. I once forgot to mention the temperature to bake them at when I was giving the recipe to something, and I hope I haven't done anything like that here.