Public domain Netstrings encoder/decoder class for Java

January 17, 2010 by Brian

According to D. J. Bernstein, who created the simplistic protocol in 1997, a netstring “is a self-delimiting encoding of a string. Netstrings are very easy to generate and to parse. Any string may be encoded as a netstring; there are no restrictions on length or on allowed bytes. Another virtue of a netstring is that it declares the string size up front. Thus an application can check in advance whether it has enough space to store the entire string.” (More information on Wikipedia.)

Netstrings are great for when you are writing a network program that needs a simple protocol to communicate data between client and server (or client/client). Because of this, it has been my choice for small pieces of software that I write. I was sad to find, however, that Java does not have built-in netstrings capabilities — so I decided to write my own. The source code to my minimalistic yet functional implementation is below.

// Public domain Netstrings encoder/decoder class for Java
// Version 1.0 - Written by Brian Nez

public class Netstrings {

    public static String encode(String message) {
        int length = message.length();
        message = new String(length + ":" + message + ",");
        return message;
    }

    public static String decode(String original) {
        String result = original.split(":", 2)[1];
        if(result.length()-1 != Integer.parseInt(original.split(":")[0])) {
            System.out.println("Netstring integrity error: Expected length " + original.split(":")[0] + " but got length " + (result.length()-1) );
            return null;
        } else {
        	return result.substring(0, result.length()-1);
        }
    }

}

Nokia N900: I love this phone

December 11, 2009 by Brian

Nokia N900 stock imageI just bought a Nokia N900 which runs Maemo Linux 5 and after three days I would like to share my initial impression of the device.

Pros: Phone is very well built and comparable to my old iPhone 3G in every way. The 5MP camera is absolutely amazing, I will probably use this as my primary camera for normal photos and bits of video. The Maemo platform in use by the phone is super responsive and feels faster than anything I have ever used. Things open instantly and the multitasking is very smooth. The Linux OS underneath is impressive and I can run emulators for games, although the OpenGL ES 2.0-enabled accelerometer-based 3D game it comes with (Bounce, it is called) is really impressive. I hope this phone lives up to its potential.

Cons: Most apps are in landscape mode only. Also, physical keyboards are overrated. Can’t figure out how to use FM Radio yet. Not a lot of apps out, although there is a huge community around the OS so I expect this to change quickly. T-Mobile 3.5G service is not available everywhere and this phone depends on a fast data connection. Battery life could be better. I wish it took a regular SD card instead of a microSD. Also, where is Ovi sync, Nokia?

Other Thoughts: An expensive device, even after rebates and promo codes. The Maemo forums are very active and you should join them.

This is the second Nokia product I have purchased that runs the Maemo operating system, the first being the now-defunct Nokia N800 Internet Tablet, which I blogged about a while back when I first got it.

T-Mobile MMS Settings for Unlocked iPhone 3G

November 7, 2009 by Brian

I recently unlocked my iPhone 3G using the free blackra1n jailbreak and blacksn0w unlock in order to use it on T-Mobile’s service. After you do this, you will not be able to send or receive multimedia messages (MMS) without the correct MMSC and proxy settings. To enter these settings, go to Settings, then tap General > Network > Cellular Data Network, and scroll to the second (MMS) section.

APN: wap.voicestream.com
MMS Proxy: 216.155.165.050:8080
MMSC: http://216.155.174.84/servlets/mms

All other fields should be blank. If you have problems receiving messages, you might also want to enter:

Max Message Size: 1048576
MMS UA Prof URL: www.apple.com/mms/uaprof.rdf

Now reboot your phone and enjoy.

After contacting T-Mobile I was given an alternate set of instructions that also seems to work.

APN: epc.tmobile.com
MMS Proxy: (leave blank)
MMSC: mms.msg.eng.t-mobile.com/mms/wapenc

Hopefully this should resolve any issues that arise, although if you still have problems I suggest giving T-Mobile a call as the tier-3 tech who helped me out was very knowledgeable.

The Tao of Programming

October 24, 2009 by Brian

When the program is being tested, it is too late to make design changes.

—The Master Programmer

Read the rest of this entry »

Diesel Sweeties #405: Souls

October 20, 2009 by Brian

Open-Source Games for Linux

October 15, 2009 by Brian

I was recently looking around to see the state of Linux-capable games, and I was surprised to stumble upon a bunch of really cool looking ones:

Let me know if you have any particularly fun Linux games in the comments!

Setting locale failed error on Ubuntu or Debian

October 13, 2009 by Brian

Sometimes I get a weird error message when using apt-get or dpkg on certain Ubuntu or Debian systems. More particularly, this happened on a server I was running and confused me quite a bit. Basically, when working with packages, I kept getting the following message:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.

After some research online, I found the quickest was to fix this was to run (as root):

apt-get install language-pack-en-base

I was also told to execute the following, but I found it to be unnecessary:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

I hope this helps someone else, too. Remember to change en_US to your desired locale.

My Conky Configuration

October 1, 2009 by Brian

Screenshot of Conky
Conky is a really cool Linux program that displays vital system stats right on your desktop. You can configure it to show other cool things by calling external programs. I’ve seen people add media player stats, the weather outside, and even a stock ticker. Conky is available at http://conky.sourceforge.net, and you can also see some more examples and more documentation there. My configuration is fairly simple, and I’ve attached it to this post to let you all see.
My .conkyrc file

Slashdot Comment: Architecture Astronauts

September 25, 2009 by Brian

I don’t think this guy ever worked with any software engineer with any significant amount of experience. Or maybe he just works with people that suck as software engineer.

The typical evolution towards wisdom in Software Engineering goes like this (simplified):

Read the rest of this entry »

Pictures of My New Acer 1410 Notebook

September 10, 2009 by Brian

Picked up this awesome laptop/netbook hybrid called the Acer 1410 for $450 shipped and it arrived today. (Called the Acer 1810 in Europe.) Here’s some pictures:

Acer 1410 - frontAcer 1410 - topAcer 1410 - sideAcer 1410 - box

It’s really thin and light for a laptop but more powerful than the average netbook (not to mention a full-size keyboard). It pack a Core 2 Solo (Penryn) processor rather than the typical Atom and has the new Intel integrated graphics with HDMI output!

I’ve pasted the exact specs below if your interested in that. What I’m happy for is that this will be a joy to bring to around in comparison to my heavy 15.4″ MacBook Pro, even if I don’t get to use Snow Leopard on it.
Read the rest of this entry »