Tuesday, April 22, 2008

Early vs Late Binding

I've been thinking recently about programming languages (surprised?), specifically about the things that make them different. One of the really nice things about C, is that it compiles into machine code which tends to run lean and mean. By that I mean it is blazing fast and doesn't take up much memory. On the other hand, programming in Python and JavaScript has really been growing on me. There is so much flexibility to create elegant solutions quickly and without rewriting lots of existing code. In fact, I'd say greater ability to reuse existing code is a natural outgrowth of programming language flexibility.

So where does this flexibility come from? One place I tend to notice it most, is in the ability to give an existing function a new body, in other words, you can plug in different behavior in place of the default.

Here's a simple example to illustrate the idea. Let's say that we created a simple checkout register which takes a receipt, adds the sales tax, and spits out the grand total. Here's our code foundation in both Python and JavaScript (these two examples do essentially the same thing):

Python:
def CalculateTax(amount):
return amount * 0.18

class Receipt(object):

def __init__(self, items=None):
self.items = items or []

def CalculateTotal(self):
return sum([item + CalculateTax(item) for item in self.items])
JavaScript:
function calculateTax(amount) {
return amount * 0.18;
}

function Receipt(items) {
if (items) {
this.items = items;
} else {
this.items = new Array();
}
}

Receipt.prototype.calculateTotal = function() {
var total = 0;
for (var i = 0; i < this.items.length; i++) {
total += this.items[i] + calculateTax(this.items[i]);
}
return total;
}
To use the above code, you might write something like this:

Python:
my_order = Receipt([5.50, 10, 7.89])
print my_order.CalculateTotal()
JavaScript:
var myOrder = new Receipt([5.50, 10, 7.89]);
alert(myOrder.calculateTotal());
Now let's say someone asks you to change the tax rate which is used when calculating the total. Here's the catch, you're not allowed to change the existing code. It turns out this is actually really easy. You can define a new function, then make an existing function name point to the new function. Here's an example of how to inject our new code:

Python:
def CalculateHigherTax(amount):
return amount * 0.25

CalculateTax = CalculateHigherTax

print my_order.CalculateTotal()
JavaScript:
function calculateHigherTax(amount) {
return amount * 0.25;
}

calculateTax = calculateHigherTax;

alert(myOrder.calculateTotal());
After adding the above code to the foundation we started with, you will notice that the calculate total method now uses calculate-higher-tax instead of the original function, even though you are calling the same method on the same object as before. Congratulations, you have just witnessed late binding in action.

So what is late binding? The idea is that the computer decides which code should be executed while the program is running. This seems normal in scripting languages, but compiled languages often use this too (I'm looking at you Java and C++). For example, overloaded methods and polymorphism take advantage of late binding. With late binding you can change the meaning of an identifier (for example, change the behavior when you call a specific function) at just about any time.

Now lets take a look at a language which uses early binding. C is a great example. With early binding, the meaning of things like function names are locked in when the code is compiled. There is no dynamic lookup while the program is running to see which code should be executed, instead the address of the desired code is embedded directly into the binary machine code.

Here is how the same calculate-total example might look in C:
#include<stdio.h>

float CalculateTax(float amount) {
return amount * 0.18;
}

typedef struct {
float* items;
int num_items;
} Receipt;

float CalculateTotal(Receipt this_order) {
int i;
float total = 0;
for(i = 0; i < this_order.num_items; i++) {
total += this_order.items[i] + CalculateTax(this_order.items[i]);
}
return total;
}

int main(void) {
Receipt my_order;
float my_items[3] = {5.50, 10, 7.89};
my_order.items = my_items;
my_order.num_items = 3;
printf("%f\n", CalculateTotal(my_order));
}
If you try to set CalculateTax to a new function definition, you will get an error at compile time because a function cannot be changed once it is bound. Early binding tends to produce more efficient programs. However, if you want to, you can still use the flexiblity available in late binding in C.

Using function pointers, you can store the address of the code that you want to be executed, and change the address while the program is running. We can achieve the same late binding effects that I've illustrated in Python and JavaScript by making some small changes to the C code (marked in bold below). Declare a function pointer named TaxCalculator which will store the address of the desired calculate-tax function, then change CalculateTotal so that it uses the TaxCalculator instead of directly calling a calculate-tax function.
#include<stdio.h>

float CalculateTax(float amount) {
return amount * 0.18;
}

float CalculateHigherTax(float amount) {
return amount * 0.25;
}


typedef struct {
float* items;
int num_items;
} Receipt;

float (*TaxCalculator)(float) = &CalculateTax;

float CalculateTotal(Receipt this_order) {
int i;
float total = 0;
for(i = 0; i < this_order.num_items; i++) {
total += this_order.items[i] + (*TaxCalculator)(this_order.items[i]);
}
return total;
}

int main(void) {
Receipt my_order;
float my_items[3] = {5.50, 10, 7.89};
my_order.items = my_items;
my_order.num_items = 3;
printf("%f\n", CalculateTotal(my_order));
TaxCalculator = &CalculateHigherTax;
printf("%f\n", CalculateTotal(my_order));

}
There you have it!

Here's another way to think about this comparison. In high level languages which don't expose pointers, functions, variables, and other identifiers actually act like pointers.

Monday, April 21, 2008

Ubuntu Hardy Heron

Last week, I downloaded the beta release of Ubuntu 8.04 (Hardy Heron) to give it a try. I've been meaning to migrate our last Windows XP machine over to Linux for some time now (the other three computers I use regularly are Linux machines), but I've been reluctant to backup, repartition, and take the plunge. It seems like this is a common feeling among computer owners, but I think the Ubuntu community may have found an effective solution.

And the name of this new innovation: Wubi. Pop in the Ubuntu CD while running in Windows, and an auto-run installer opens which allows you to install Linux alongside Windows. When you reboot your computer, you see a menu of which operating system to boot into: Windows or Ubuntu. This means you can try out Ubuntu on your computer with zero risk to your existing files. In fact, you can access the files on your Windows installation from within Ubuntu. And if you decide Ubuntu is not your you, you can uninstall it as you would any other Windows program. Pretty slick.

Managing in the installation is just the beginning of the improvements the team has made. After I installed the latest version and booted into Ubuntu, it told me that there were propriety drivers for my NVIDIA graphics card and asked if I wanted to install them. I clicked the button, the download started, and I was up and running with 3D accelerated graphical desktop effects. I think I could sit there opening and closing windows all day. I'm looking forward to the upcoming official release.

Monday, April 14, 2008

A Musical Interlude... and back to Programming

I've been listening to Daft Punk and Justice quite a bit recently. Apparently I'm on a techno kick again. I've never found any electronic music that I've enjoyed as much as Joy Electric's The White Songbook. The purity of the tones and style has made it one of my all time favorite albums.

This got me thinking about a project which I thought of years ago, started, then abandoned. It was a music synthesizer/sequencer which you would program, by well, programming. I mean that the music would be controlled exclusively through a programming language. This would alter the creative process in several ways. Most music sequencers are graphical and allow you to lay out musical patterns in sequence. Writing a program is extremely non-linear, with classes, functions, and variables being defined in the code long before they are used. In this hypothetical sythesizer language. a composition might look something like this:

sequence "intro":
playSample("beat", start=0:32.1, end=0:33.5, beats=[1,3,9,11,15])
playSample("moog", beats=[5,7,11])
shiftPitch(start=A4, end=C4, duration=bars(8))

sequence "solo":
playSample("guitarRiff", start=1:15.3, end=2:09.0)

tempo 150 BPM
play("intro", now)
play("solo", end("intro"))
play("solo" now()+bars(5))

In the above example, the first play statement will be executed, then the third play statement (5 bars into the 8 bar intro), then the second solo will play again, probably before the first solo finishes. There are other interesting features in the pseudo-code above, but the fact that these sequences are played out of order was what I really want to highlight.

I've done live coding at several events over the years and I tend to have fun with it. It doesn't always go exactly as planned, but that is the whole idea. Live coding turns programming into a performance piece. I imagine there is a niche group of people who could really get into the live coding music scene.

Monday, March 24, 2008

XO Laptop

My XO laptop arrived in the mail recently and it is quite an amazing little machine. Conclusion up front: I'm extremely satisfied with it and in some ways this laptop computer is better than ones that sell for ten times the price.

You might recall from a previous post that I had downloaded the XO's operating system and taken it for a test drive in an emulator. Now I have the real thing in front of me, and it's safe to say that it is even better. After all, some of the most innovative features of this computer are in the hardware. My favorite feature is the screen. It is viewable in direct sunlight which makes it usable outdoors. Second up would be the wireless networking. The graphical network selector is fun to use and the connection tends to be more reliable than any of the other computers I've used with my home wireless router. The battery life is also impressive, easily five hours on a charge of its small battery. It even has a built-in camera and microphone.

It runs all of the software I need too. I used the instructions I wrote up when I installed firefox on the emulated operating system. Everything went smoothly and I was browsing the web using firefox in a few minutes (The XO laptop comes with a perfectly good web browser, but I wanted to use my favorite plugins and have more control over downloads).

I'm quite taken with the little machine. I've been using it as my primary computer at home, using it for all of the tasks I normally do (mostly browsing the web and programming). There are a couple of things that I would change if I had the chance. The first is the keyboard. It is an interesting design, made of a flexible rubber-like substance, and it works much better than other flexible keyboard that I've tried, but it took a while to get used to the shift key (I have to press in the corner of the key). The other difficulty is presented by the slower processor, but it doesn't get in my way most of the time. The only time I notice any slowness is when playing flash videos (like on YouTube). Perhaps part of the problem is flash for Linux, but I'm not sure. In any case, I don't really mind as I don't watch that much video, and if I want to, I have other computers that I can use.

It will probably come as no surprise that I wrote this post using the little green computer. I'm saddened by the end of the "give one get one" program, as I think there is still the opportunity for more people to donate and receive their own XO. If anyone is interested, it might be possible to order a batch of one hundred or more through the "give many" program.

Tuesday, March 11, 2008

BusyList

Andy and I started work on a simple little open source project for tracking tasks; it's called busylist. We wanted to experiment with Ajax, Python, and web service APIs, so we whipped up a basic system in a few hours. There is still quite a bit of work to be done, but it has been a great learning experience so far. An extremely alpha test version is available in subversion along with some instructions on the project's wiki pages. If you're interested, feel free to check it out (pun intended) and contribute if you like. It is an open source project after all.

Tuesday, March 04, 2008

(Portable) Ubuntu for Programmers

I've been trying over the past several weeks to find the best fit for Linux on a USB pen drive so that I can boot into my own operating system and get to my files no matter which computer I'm using. As you might notice from my other posts, I tend to spend quite a bit of my computer time in programming and browsing the Web, so the things I'm most interested in are a web browser (Firefox), support for wireless cards in several computers, and a variety of command line programming tools (gcc, python, vim, etc.). It should be possible to take one of the standard Linux distributions and install it on a USB drive (provided the drive is large enough), but I wanted to use a one gigabyte drive that I had, and with my simple needs I should really be able to get all of the necessities in under one gig. Along the way I've tried Puppy Linux, Slax, Feather Linux, DSL, and others, but I decided in the end to roll my own solution based on Ubuntu.

I'm a big fan of Ubuntu, but the standard desktop install is far too large for installation on a one gig drive. For a while I was using the live CD booting from a pen drive with a partition for my files. I used the instructions I found on Pen Drive Linux to set up the pen drive with the image from the live CD (only 750 megabytes). The only problem with this set-up was that all of my files were in a seperate partition and my home directory was wiped out each time. Since many Linux programs store settings in your home directory, this turned out to be a bit incovenient. I tried a few different options, but finally decided to go with a stripped down Ubunutu foundation and add the things I wanted.

I began with Ubuntu Server 7.10 and installed it on my USB drive using some of the recommendations in the installation instructions for low memory systems. During the installation process I selected guided partioning and I did not choose to install any of the software configurations in the "software to install" menu. After installing, I rebooted and added the following packages using sudo apt-get install:
lynx (optional)
screen (optional)
gcc (optional)
xorg
x-window-system-core
firefox
If you are using a laptop, you will likely want to install the following modules:
acpi
acpid
With the above installed you can check the battery's charge, remaining time, etc. by running acpi on the command line. For the graphical desktop window manager, I chose iceWM. I installed it by adding:
icewm
iceconf
icewm-themes
In the past I've worked quite a bit with Fluxbox as a window manager, but it seems like iceWM is easier to configure, especially under Ubuntu. The liQuid theme looks quite nice.

This set up boots into a text only command line mode because it is based on Ubuntu Server, to enter graphics mode, you simply run startx. I connected to my wireless network using wpa_supplicant and running iwconfig.

One of the benefits of working on a lightweight system on a flash drive is the bootup speed. In twenty seconds the computer boots from a cold start, connects to my wireless network, and enters the graphical desktop. I'm quite happy with my little portable operating system, and you probably won't be suprised to hear that I wrote this post using it.

Tuesday, February 26, 2008

In praise of Haikus

Programmers are no strangers to strict requirements on form and syntax, so working in the poetic medium of the Haiku comes almost naturally.

Programming is fun.
Little virtual widgets.
Poems that do work.


The brevity and compactness of the haiku lends itself well to writing something tighly focused. I find them quite enjoyable to write.

Of course, there are quite a few other poetic structures of note which can offer a fun challenge. The limerick and the sonnet are two of my favorites. Here's a limerick I wrote (beware, obscure programming reference ahead).

There once was a coder named Chuck.
And through all the source code he snuck.
  He changed not a line,
  it all worked just fine:
he programmed by punching a duck!


A sonnet would be a bit ambitious for this late hour. So unleash your creativity, let's see what you've got.

Monday, February 18, 2008

Happy Valentines Day

Vanessa prepared a wonderful meal for me this Valentines day. Four courses, the first one pictured here, all delicious. This was the roasted red pepper tomato soup with an artistic heart made of sour cream. And this was only the first course. Have I mentioned that the meal was delicious. I'm very thankful, I married quite a cook. Not only that but she decorated too.

It would seem I borrowed a page from one of Ben's blogs and wrote about food. What can I say, a meal like this makes an impression.

Wednesday, February 13, 2008

My Programming Journey so Far

One of the great things about working in computer science is that you never stop leaning. It seems that many programmer follow a progression from one popular language to the next, and I thought I'd dedicate a post to reminisce about my journey so far. I first learned to program in C. This was at the age of sometime around eleven or thirteen. I was instantly hooked, and since then, I've kept right on learning. I think the path I've taken has been fairly typical. From C, I learned C++ (starting in high school). I learned Java during a summer internship after my junior year of high school. In college, it was more C++, Java, and C (I really learned the ins and outs of C in my networking class) along with some other programming languages.

My favorite two classes in my college computer science curriculum were the ones in which I learned assembly language and designed an arithmetic logic unit and then a simple processor. I finally felt like I understood exactly how computers worked. With assembly language I learned a bit about machine code, how many clock cycles specific operations take, and it felt so good to optimize a bit of code to run blazingly fast. In circuit design I learned where those clock cycles come from, why operations take the time they do, and how those machine language op codes are determined. In all things software, at some point it all comes back to electronics.

College was also a time to get a taste of other, less widely used, but none-the-less important languages. Scheme and Prolog were particularly interesting to me, but I haven't had much occasion to use them very much recently.

Through my career, I've focused primarily on C++, then Java. After that I've had the opportunity to use a large number of languages. I learned Ajax programming using JavaScript, I wrote some PHP, C#, and a rather large amount of Python. Outside of work, I like to explore new concepts and languages and I've taken a look at some other languages too. Some notable examples include Ruby and Common Lisp, but I haven't built anything serious with them yet. Python is a language which I've really grabbed hold of recently and I've been learning quite a bit about it. At least half of the side projects I'm working on in my spare time these days are in Python. There seems to be quite a bit of momentum behind Python, and I'm very interested to see where this all goes.

So there you have it, a small glimpse into my journey thus far. How does it jive or differ from your own?

Friday, February 08, 2008

Firefox 3 Beta 2

I recently downloaded the second beta of Firefox 3 from Portable Apps. I didn't want to replace the version of Firefox I already had installed, so I used the version from Portable Apps which runs as a standalone binary. Sometimes it's really nice to unpack a program without touching the registry or worrying about installing.

Overall, I'm very happy with the changes I've seen in the latest version. I had heard that there have been some improvements to the JavaScript engine in this version, and they are noticeable. When I logged in to gmail it seemed a bit more responsive. I have to say though that my favorite changes are in the address bar. When typing the address, the address bar shows addresses, titles, and logos for pages that you've already visited. Firefox 2 did this too, but I think 3 gives more detail and a larger number of results. I found myself using it much more often than in 2. Part of the reason is that it shows the most recently visited page at the top instead of the shortest match. I also liked that you could star a URL to add it to your bookmarks, and you can even select a folder and tag the URL from within the address bar.

Tuesday, January 29, 2008

Programming Languages are Languages too

One of the reasons that people keep inventing new programming languages is that humans are good at using language and computers are not. So was we improve computers and add more complexity, programmers endeavor to make using these new features simpler and less painful. As a result, computer languages are moving in a general direction towards more natural human language. There will likely always be differences, but programming languages and human languages are strikingly similar if you understand some of the widely used syntax.

Here's an example. When you see something like this
z = x * y;
print(z);
it means that you want the computer to "store the value of x times y in the varibale z, then display z on the screen." As you can see, some programming syntax is borrowed from math. This example includes arithmetic and a function. Functions can also be though of as verbs, with variables as the nouns. In object oriented programming, variables can be nouns which are capable of performing actions. If you had a digital carrier pigeon, and you wanted to tell it to carry a letter to your grandmother's house, you might say something like:
myPidgeon.payload = myLetter;
myPideon.flyTo(grandma.house);
In human language, there are always multiple ways to say the same thing, and the same applies in programming. The programmer might just as easily design the program to give grandma the letter like this:
myLetter.setRecipient(grandma);
myPideon.deliver(myLetter);
Now for some fun. What do the following code snippets mean?
  1. if (jack.getWorkPercent() == 100.0 &&
    jack.getPlayPercent() == 0.0) {
    jack.dullBoyFlag = true;
    }
  2. Pie aPie = new Pie();
    Song aSong = new Song(sixpence);
    aSong.sing();
    fill(pocket, rye);
    aPie.add(new Blackbird()[24]);
  3. Mouse mice[3];
    for (i in range(3)) {
    mice[i] = new BlindMouse();
    }
    observe(run(mice));
  4. party = new Party(jack, jill);
    party.setTarget(water);
    party.equip(pail);
    party.ascend(hill);

Wednesday, January 23, 2008

A spoiled programmer

I've been writing quite a bit of Python code recently and I've become a bit spoiled. It's easy in Python to define new classes on the fly, create new functions, pass them here and there, and return arbitrary collections from a method. C will always have a special place in my heart (I think everyone's first language does), but I often think of ways I could make it a bit easier to do certain things like have functions that return functions or have a function return multiple values.

To explain by way of example, it would be fun to do something like this:
/* A function that returns multiple values */
int, char, int myFunction(int a, int b, int c, char d) {...}

...
/* Invoke the function and store the results */
int x, y;
char c;
{x, y, c} = myFunction(5, 6, 7, 'Z');

The above is a fairly Pythonic way of doing things, and it seems like it should be possible in C. The first way I thought of is using structs. I like to think of a struct as the precursor to a class. It allows the arbitrary grouping of variables into a single collection where they can be referred to by name. (In a couple of earlier posts, I showed how you could use structs to simulate classes in C.)

If I define a struct for each one of my multi-variable-returning functions, I can create functions which effectively return multiple values instead of just one. Yes, technically I am returning one value, the struct, but you know what I meant :-) Namely, if you look at the program's stack, there is probably no perceptible difference between returning a struct and returning multiple variables.
/* Create a 2 member struct to hold the return value */
struct myFuncReturn {
int first;
char second;
};

/* A function that returns an int and a char */
struct myFuncReturn myFunc(int a, int b, int c, char d) {
struct myFuncReturn to_return;
to_return.first = (a+b)*c;
to_return.second = d;
return to_return;
}

int main() {
struct myFuncReturn pattern;
pattern = myFunc(2, 3, 4, 'Z');
printf("Pattern: %i, %c\n", pattern.first, pattern.second);
}
This works ok, but I would like to avoid having to create a new struct for each one of my functions. It might be easier if I didn't have to worry about types at all, so the natural choice is to have the function return a type-less void pointer (void*). The calling code would then be responsible for interpreting the function's return struct correctly. If I want to return a new anonymous struct from a function, it might look something like this:
void* myFunc(int a, int b, int c, char d);
If I use the above, I'll need to allocate memory for the struct and return it's address. This is a bit of a bother as well, because now I need to worry about cleaning up that memory later. Instead of having the function allocate a new structure to return, why not pass in a structure and have the function modify it? The code I would need to write would be more aesthetically pleasing (in my opinion) for both the function definition and the calling code which invokes it, and it might even be more efficient.

If I pass in a pointer to the result struct as the first parameter to the function, my program could look like this.
/* Function definition, the out parameter is the return value */
void myFunc(void* out, int a, int b, int c, char d) {
((struct{int first; char second;}*)out)->first = (a+b)*c;
((struct{int first; char second;}*)out)->second = d;
}

int main() {
struct{int first; char second;} pattern;
myFunc(&pattern, 2, 3, 4, 'Z');
printf("Pattern: %i, %c\n", pattern.first, pattern.second);
}
Look ma, no type declarations! Now you might say that writing out the entire struct definition each time is a bit unpleasant, but you could always define a struct and use it instead. I wanted to show that you don't really need to declare a type for each function, which could create a bit of a mess if you start using multi-return functions everywhere. With the above pattern, you could also start to play some interesting games by having functions that actually return different structs in different situations (provided the out pointer's reserved space is large enough for the data you want to send back). If I've lost you by now, I do apologize.

For added effect, note that the anonymous structs don't need to match, you just need to make sure that the shape of the structure is the same so that you don't overwrite data. I could have written myFunc like this:
void myFunc(void* out, int a, int b, int c, char d) {
((struct{int first;}*)out)->first = (a+b)*c;
((struct{int x; char second;}*)out)->second = d;
}
Or if you want to go even further, like this:
void myFunc(void* out, int a, int b, int c, char d) {
*((int*)out) = (a+b)*c;
((struct{int x; char second;}*)out)->second = d;
}
Ah, the joys of programming. It's little games like this that make programming lots of fun. It's like working on a big wide open puzzle that you get to build yourself. No wonder I'm spoiled.

Monday, January 14, 2008

Twitter

If you've never tried Twitter, it might just be worth your while. I've been using it for a few months now and I'm quite pleased. As much as I try to make frequent blog updates, writing an entire entry sometimes feel like a large task. In contrast, twitter imposes a strict 140 character limit. This limit is both challenging and freeing in some ways: How much can you pack into a sentence or two? In addition to providing a place to share small updates, Twitter introduces a social aspect as well. By using @username notation, you can let everyone know your post was directed to a specific person so that they have a window into the conversation.

If you are familiar with Facebook, using Twitter is a bit like having a website made of just your profile status and your wall. These are my two favorite features of Facebook, so perhaps this is why I enjoy Twitter. The main difference is that you never post on someone else's wall, your posts show up on their wall if they choose to "follow" you (subscribe to your updates). I've never really used my phone to twitter (yes twitter is also a verb) or receive updates, but supporting posts from multiple platforms is a big selling point for some users.

My Twitter page is here and I also include a feed viewer gadget here on my blog to display my last few Twitter posts. If you have an account post it below!

Sunday, January 06, 2008

Trying out the XO Laptop Operating System

In a recent post I mentioned that I had ordered an XO Laptop from the One Laptop Per Child program. It is still on order but being the slightly impatient person that I am I decided to see if I could test drive the software on the laptop before it arrives. It is based on Linux after all which usually means the software is freely available somewhere on the Internet.

Taking the XO for a spin turned out to be pretty easy and I have been able to add all of the applications I've wanted so far. I mentioned in my last post about the XO that I wanted to use it for programming and web browsing so I had a few requirements in mind. The laptop comes preinstalled with a custom web browser and Python but I often like to program in C and C++ so I wanted to install gcc. The web browser has a few wrinkles too, in the development build I tested I wasn't able to get some flash plugins to load (could be the version of flash or the fact that the XO version I downloaded wasn't a production release). The browser is tabless and it is a bit difficult (though not impossible) to figure out where downloaded files are stored. In short it wasn't quite was I've grown accustomed to, so I thought I would try installing Firefox. He's my step by step instructions for trying out the XO Laptop virtually and customizing it.

I began with the XO's wiki and found out that there are instructions for emulating the XO and VMWare virtual machine images for recent builds of the system. VMWare is a program which creates a simulated computer that runs within your current operating system. For the past few years I've tested all of the Linux distributions I've considered on VMWare Server (free to download and use at home). Once I started VMWare, I opened the ship.2-OLPC-655.vmx file and started it up.

After the initial configuration, I wanted to add gcc, a collection of open source compilers. I thought it was going to involve downloading several RPM files, but I found out about a tool called yum which manages RPM packages. This is similar to Ubuntu's apt-get. As root I was able to run
yum install gcc
and it downloaded and installed all prerequisites.

Next I wanted to install Firefox, and to download it I thought I would try Lynx (a text based web browser). Installing Lynx was just as easy, as root I ran:
yum install lynx
I ran lynx www.google.com and searched for firefox and downloaded the tar.gz Linux version. After downloading I unpacked the archive using
tar zxvf firefox-2.0.0.11.tar.gz
I tried running firefox, but got an error about a missing shared object library. Yum was able to find this as well. One final time as root, I ran
yum install libstdc++.so.5
After installing the C++ library, firefox ran just fine. The menus and graphics in Firefox matched the XO's theme, which I thought was pretty nifty. I was also able to install Flash. Well there you have it, why not take it for a test drive yourself.

Tuesday, January 01, 2008

New Year's Resolutions

Well folks, it's that time of year again. Time to set goals with the best of intentions and aim high to better myself. I'm borrowing quite a few of my new years resolutions from last year, there were a couple that didn't go as well as I had hoped. Daily time for devotions, reading, and mediation tops the list. More frequently journaling and blogging also made the cut.

I noticed a handy goal tracking website on Lifehacker which I'm using at the moment. However, I often find that the online nature of tools used to track things like to-do lists and finances can create a small inconvenience which leads to an eventual breakdown. A plain old pen and paper still holds an important place.

In any case, here's to a new year and to best-laid plans.

Friday, December 21, 2007

An open source JavaScript library: q12

I've written some JavaScript utility functions as part of my ongoing wiki/note taking application. It is growing into a full fledged Ajax application with a web server and now a minimal Ajax library which I've decided to release as a separate open source project.

From the project's front page:

I found myself needing a few common utilities as I was writing an Ajax application. Rather than use a heavyweight or verbose library, I wanted something compact that minimized the amount of typing I needed to do. This is where the name q12 comes from, just three little keys up there in the upper left corner of the keyboard.

This library provides functions for the following:

  • Basic DOM manipulation
  • Asynchronous HTTP requests with callbacks
  • Class methods and inheritance
  • Base64 encoding and other forms of data escaping
  • AES encryption
Writing your own Ajax library is also a great way to learn JavaScript (IMHO). I'll be making little tweaks as I work further on my project, it's getting quite close. I think I've probably said that before but rewriting from scratch tends to set one back a bit. Third iteration's the charm?

Wednesday, December 05, 2007

One Laptop Per Child, Give One Get One

If you are looking for a cheap, power efficient, portable laptop for wireless web browsing and programming, like I was, consider the XO Laptop from the One Laptop Per Child association. I ordered one to keep and one as a donation through the Give One Get One program. It looks like it will be a lot of fun, I'm especially interested in the wireless mesh networking and social aspects to using the laptop. Some of the the music software looks like fun as well.

I'm ordering one for mostly selfish reasons, but this is probably my first computer purchase which will benefit someone else. Who knows, perhaps a child in a developing nation will discover a new world of seemingly limitless possibilities through programming just like I did as a child. This is my personal take on the vision behind this unique program. The opportunity to order one is slipping away fast, the offer to buy one and give one away ends December 31st. Let me know if you've ordered one, perhaps we can organize a laptop party (Arne I'm looking at you ;-)

Thursday, November 29, 2007

Something like Lisp

Ever since compilers class in college, I've toyed with the idea of creating a new programming language. Every year or so a spend a few days thinking about one and get off to a short start. The problem is I often try to bite off more than I can chew and start dealing with the most difficult parts first. So I recently decided to get a minimal language up and running. Something with simple syntax, no concern for efficiency, and an easy to build base.

Lisp has some of the simplest syntax of any of the languages I've worked with (perhaps with the exception of BF). I was looking for something simple which I could quickly implement, so I used it as a model and created an interpreter in Python. The whole project took just a couple of hours, but I was able to write an interpreter that would run the following program:
set[x 5]
set[x add[1 2 3 4 5]]
set[y add[1 2]]
println[get[x]]
println[get[y]]

As you might have guessed, this program displays the following in the terminal:
15
3
I implemented a simple parser using Python's regular expression module re (The group method can come in quite handy), and I defined each of the above functions in a dictionary which maps function calls in my custom language to functions in a Python script which I import. You might have noticed that each of the methods is designed to take a variable number of arguments (thought only they may not all be used), and all function calls are made recursively, with nested functions being evaluated first. The syntax looks slightly like s-expressions but it's a bit more accessible for someone who has worked with C-like languages (except there's no need to reach for the shift key for those tricky parenthesis). I haven't added a mechanism for lambda expressions yet, but defining new functions might look something like this:
function[my_fun group[x y] group[multiply[x add[x y]]]]
The above would define a function named my_fun which takes two arguments, and multiplies the first by the sum of the two arguments.

I just made up this micro language, and haven't given this a great deal of thought. The idea was to create something quick and dirty to create a working interpreter, rather than the usual of intense planning without a working prototype. This language will probably never see any further development. It was a mental exercise, but I found it quite enjoyable. If you'd like to see the source code for the interpreter, please let me know (I get the feeling Matt might be somewhat interested).

Monday, November 12, 2007

Fluxbuntu 7.10

Long time readers may remember the saga of my old laptop (a Compaq Presario 1700T circa 2000). I had ditched openSUSE several months ago in favor of Fluxbuntu, a variant of Ubuntu which used the light weight Fluxbox windowing system in place of the Gnome desktop. My old computer has only 128 megabytes of RAM, so memory is at a very high premium. With the release of Gutsy Gibbon, Fluxbuntu picked up a few new features, so I upgraded and gave it a try. I have been extremely pleased. All the good stuff is there that I enjoyed before (installing new free software using Synaptic or Aptitude, Firefox, XMMS, etc.) but there were a couple of great new additions. For one, automounting of USB drives. I have a small pen drive that I carry around to hold many of my files: music, programming projects, etc. Mounting had always been a bit of a pain with my laptop's OS. Now I just plug it in, it mounts, and an icon for the drive appears on my desktop.

The discovery came at a perfect time. My in-laws decided they wanted to resurrect an old PC so they could browse the web side by side. All they really needed was Firefox, Open Office, and Picasa and their computer had the same amount of RAM as my old laptop (probably from about the same time frame). Fluxbuntu to the rescue ;-) Can you believe it, my in-laws are running Linux.

Thursday, November 08, 2007

IE, XMLHttpRequest, and caching

I recently noticed an oft cited irritation with using XMLHttpRequest in Internet Explorer. Turns out, the browser intercepts HTTP GET requests made from within JavaScript and gives your Ajax application a cached response instead of fresh data.

I was running some tests on scorpion_server, using the JavaScript client in the example that I've packaged with the server, and I noticed that I could change the data stored in a resource when using IE6, but I couldn't get the value I had just set. This means my client-server pair is pretty much useless in IE6 (probably 7 too). But I thought of a solution. IE is just performing a test for exact match when checking the cache, so if any part of the URL is different, IE will actually perform the query like I want it to. So I added a timestamp URL parameter to all GET requests made by the client if the browser is IE, and I configured the server to ignore all URL parameters on GET requests. I wasn't using them anyway, perhaps someday I will, but I don't foresee a need because all I want is a super simple remote data store. (Who knows, YAGNI might just be my new mantra.)

Note that IE was the only browser (of those I tested) that exhibited this annoying behavior. Mozilla based browsers (Firefox, SeaMonkey, Flock), Opera, and Safari all behaved correctly and don't require the timestamp URL parameter hack.

Sunday, November 04, 2007

JavaScript client for my Scorpion Server

I've added a JavaScript client to the simple web server project: scorpion server. The client is able to set the username and password and make authenticated GET and POST requests to retrieve and modify resources on the server. Now that this portion is complete, I'm ready to rebuild my Ajax Wiki application to run on top of this simple web server.

Saturday, October 27, 2007

Hey look, a simple web server

I think I'm done writing my web server. I have gotten it to do what I want, namely this. This server will:
  1. Run just about anywhere. I sometimes run it off of a USB pen drive.
  2. Send all traffic over an HTTPS connection.
  3. Handle user authentication and permissions. You can only read and write where you have permissions.
  4. Allow you to store data in a remote location. Just POST to a URL to store something at that location, GET to retrieve it.
There really wasn't much to it. I was able to write this quickly and there wasn't that much code. The main thing it is lacking (in my opinion) is speed. This could be fixed by making it multithreaded and adding some caching since right now it always reads from the disk. Without further ado, here's the code. I also wrote a Python client and a JavaScript client to go with it will be coming soon. If you found this to be useful, please let me know.

I've also been looking at CherryPy as a framework to create the same type of portable, simple, and secure web server. As usual, stay tuned for details.

Wednesday, October 24, 2007

Varieties in Code Design

One of the interesting things about writing software is the myriad of ways to express what it is that you would like the computer to do. When designing a class, function, or something else, you can make the syntax looks just about any way you like. The real interesting bit, is when multiple people need to work on a large project together. Everyone needs to be able to understand the code, so it's probably a good idea if you agree on code conventions beforehand. All of the below would do equally well, but which is most clear?

x = a + 5;
x = a.plus(5);
x = 5.plus(a); (You could do this in Ruby/)
x = plus(a, 5);
plus(a, 5, x);
a.plus(5, x);
set(x, plus(5, x)); (This looks a bit like Lisp.)

The list goes on and on.

Tune in next time for simple Python web-server fun.

Thursday, October 18, 2007

Design for the simple secure storage server

In my last post, I mentioned my motivation for writing this server and pointed to the foundation I'm building on. Now it's time for more detail.

This server may not be supper fast (single thread execution) and it may not be super secure (user data stored in plaintext on the server) but it will be super easy to set up.

Allow me to clarify the security point in the above summary. In the initial version of this server, all traffic will be sent over an SSL connection (HTTPS) and users will authenticate with the server using Basic Auth. In Basic Auth, the users password is sent to the server in plaintext. There are better authentication schemes out there, but for this version of the server, I'm going for quick and simple. Basic Auth is just barely acceptable for this project because the connection is secure, but the server will likely store these passwords in plaintext as well (for now) so server disk security may be the weak link. With that said, the idea for this server is to provide a simple and portable back-end for my AJAX applications.

Thursday, October 11, 2007

A simple HTTPS server

Recently, I've been working on an AJAX application in my spare time and there's something I could really use: a simple network data store.

A JavaScript application isn't very useful without some persistent data. However this usually requires running a web server. My original idea was to distribute the application as a file which is loaded from the local disk. At this point you may be saying, "Wait a minute JavaScript running in a browser can't access the local disk." But scripts can read and write to the local disk if they are loaded from disk instead of the Internet. See TiddlyWiki for a great example of a useful application that uses this design. The problem though, is what happens when you want to sync the data from the AJAX application across multiple computers. Well, once again, it looks like I need a web server after all.

So I set out to build a simple server. All it really needs to do is allow applications to store and retrieve data. To make sure that the data remains a secret, the traffic will be sent over an HTTPS connection. Access to certain directories and files on the server will be granted only to select users, so usernames and passwords are required too. Since I've been working with Python recently, I tried to see if it was possible to create a simple HTTPS server which could handle GET and POST requests and perform dynamic behavior. I found a great example on activestate.com which uses an open SSL .pem file. The instructions in the article made setting up this server a breeze. I've been working on a customized version of the above example, but it isn't quite ready. As usual, stay tuned :)

Wednesday, July 18, 2007

New Domain and A New Project

A quick update on the domain name, I've registered jeffscudder.com and set up an email account, so you may be getting some mail from a new address the near future. I'm still looking for an idea on a domain to register for hosting projects. I'd like to get a name where my friends and I can all hook our email monikers (I don't imagine anyone wants to be bob@jeffscudder.com).

I've been working on a new project. I'm a huge fan of tiddlywiki, I've been using it almost a year now for keeping my notes organized. As I've continued to use it, I've found three things I would like to change:
  1. Contents are saved in plaintext. I carry my tiddlywiki around on a pen drive and some of the notes contain personal information that I'd like to keep safe. Plus, I like playing with cryptography.
  2. Notes are saved to a local file. This is both a strength and a weakness, the problem is I sometimes use multiple computers and I want to easily move between them. I'd like to have the option of saving to a local file or a server.
  3. It is sometimes slow. There is a lot of eye candy and it is very customizable, but I just want something lighweight, small, and simple.
I've gotten pretty far on my own wiki web app. but it's not quite ready to share. Keep an eye out for a release sometime in the near future.

I leave you with a song that has been stuck in my head all of last week: Deathbed by Relient K.

Friday, June 01, 2007

Domain Name Ideas

I've been thinking about getting my own domain for some time now, and I've finally decided to make the leap. The only problem now is that pesky task of choosing. I have a few ideas, but I'd like to hear what you guys come up with. Think of it as a distributed brainstorming session, no idea is too strange. (I was inspired by a discussion on Yed's blog where we helped him choose custom license plates.) I'm keeping the post short and sweet, stay tuned for details.

Wednesday, May 02, 2007

China Trip - Part 5

I will close my retelling of our China trip with our days in Hangzhou and Shanghai. (The Wikipedia articles have great pictures of many of the sites I took pictures of, including the tea plantations and Shanghai's waterfront.) In Hangzhou, we began with a boat ride on the West Lake and took a walk through the gardens nearby. We also visited a tea house and sampled traditional green tea. The next day, we traveled to Shanghai. There, Vanessa and I saw the new developments and skyscrapers which have sprung up over the past few years. It is a city which is growing extremely rapidly, yet all of the land is still owned by the government. They have started a lease program, in which an entity can get a lease from the government to use the land for 70 years. When property changes hands, the lease isn't renewed, you only have the remaining time on the original lease. Some of the real estate prices were outrageous (even by California standards) if you consider that you may only have your property for 50 years before the government can take it back. I imagine this system will seem extremely odd to most Americans. While we were in the waterfront we saw the construction of what will be the tallest building in the world, when it is completed before the 2008 Olympics.

In closing, I offer some reflections on the trip. We saw amazing sights, experienced a different culture, and met new and interesting people. Several thoughts occurred to me as I think over my journey, I noticed that their culture had common themes and ideas. Similar stories, values, and ideals, it seems that in some ways, the core of most societies is very much alike. I was also struck by the pace of growth, it seems that China is an economic force to be reckoned with, and they appear to be rapidly expanding. Perhaps I saw only the "good parts"; my view may be inaccurate. Perhaps my view was colored by the pessimism which people say is characteristic of my generation when it comes to our nation's future. Perhaps I was just tired of the Chinese food ;)

Tuesday, April 17, 2007

China Trip - Part 4

We begin this installment of our ongoing series on our China trip in my favorite location. The Lingering Garden is a masterpiece of architecture and oriental style gardens complete with bonsai trees (However, it was devoid of bonsai kittens). I'm not surprised that Chinese poets came to this garden to find inspiration in beautiful Suzhou. I could have easily spent a few more hours walking around the pond and I can't believe that the entire complex of gardens and buildings once belonged to one family.

The third picture in this post is from the leaning Huqiu Tower in Suzhou. The brick work on the structure was amazing and it is older than the Leaning Tower of Pisa. Vanessa took this one from a plaza to the side of the tower. Next time, I'll write about the very end of our trip in Hangzhou and Shanghai.

Tuesday, March 20, 2007

China Trip - Part 3

There were only a few moments where we caught a glimpse of what everyday life is like for the people of China and a couple of them came on this day of traveling. We continued our journey with a rickshaw ride through some of the older areas of Beijing and then we took a trip to the Temple of Heaven. As we walked the long corridor to the temple, we saw a large group of people playing cards, dancing, and making music. It was a glimpse of life that I would like to have taken part in, but I felt like an outsider. I'm still not sure what card games they were playing. The Temple of Heaven was a breathtaking structure and from the top of the hill you could see the entire city.

Tuesday, March 13, 2007

China Trip - Part 2

   I'm picking up my narrative on the second half of the first full day in which we visited the Great Wall. It was absolutely breathtaking and the pictures don't do it justice. You could see the wall winding through the mountains for miles standing dark against the new fallen snow.

The next morning, we visited Tiananmen Square and the Forbidden City. It was extremely cold when the wind picked up, but the sights were impressive. The Forbidden city is quite a palace, and the bold colors and detailing have been recently restored in preparation for the Olympics. One of the largest buildings was still under wraps. I was struck by the size of the palace. As I walked through the last few corridors I thought I was nearing the end only to walk into a massive courtyard. I think it was about seven courtyards, but don't quote me on it. (Check out the satellite image on Google Maps.) In my next post, I'll write about our rickshaw ride through Beijing and our visit to the Temple of Heaven.

Sunday, March 11, 2007

China Trip - Part 1

Vanessa and I just got back from our trip to China and I'm going to spread out some of the details over several days. We took over eight hundred pictures, so I'll be sharing a few from each of the days. In this first (of many) posts about the China trip I'll talk about our first day of sight seeing in Beijing.

It snowed on our first morning in China and it was a welcome if not shocking change from the weather back home. I've been missing the snow since I moved to California so it was good to be in it again, even if it made walking around a bit difficult. We started the day with a short tour of the Summer Palace, which was a gift from the emperor to his mother for her 60th birthday. It was quite a gift, a man made lake and acres of gardens.

After seeing the palace, we traveled to the Ming Tombs and visited the largest tomb. The buildings were massive and filled with artifacts buried with the emperors of days long gone by. The styles and designs of the ancient crowns and armor were very interesting and not quite what I was expecting. If you'd like to see more pictures, I'll point you to a place where you can view them. Tune in for more details from the trip in the very near future.

Wednesday, February 28, 2007

We're going to China

My wife and I leaving for China in the very near future. We're both really excited, I've never been to the eastern hemisphere before and I'm looking forward to experiencing a different culture. The trip will also give Vanessa plenty of opportunities to practice her Chinese.

I'll have a vast array of experiences to share with you, gentle reader, upon our return. So for now I'll leave you with some half finished thoughts. I started no less than three blog posts over the past two weeks, but they are all sitting as unfinished drafts. Here's a brief summary of one of the things I started to talk about. (In the end it turned out to be not quite so brief.)

Cellular Automata
I've been looking into Cellular Automata recently as a source for complex data interactions. There has been some discussion among cryptographers about the use of cellular automata as possible pseudo random number generators. The best known example of a cellular automata is John Conway's Game of Life and I think it illustrates the kind of complex interactions which can occur within a cellular automaton, even though it is a "universe" with very few rules.

I started to look at the behaviors in Wolfram's rule 30 and rule 110 cellular automata because those have been selected as possible candidates for cryptographic systems. I wrote a program to evaluate patterns produced by these rules in a finite two dimensional field which wraps on both ends. I think I may have found other rules which may also prove promising for cryptographic use, but I need to do more evaluating. I'd ultimately like to use a three, four, or five dimensional system to see if I could build a useful PRNG but I will need to spend considerably more time ensuring that the patterns created by the rules remain complex. In the 2D system I evaluated, the vast majority of rules produces very predictable patterns.

See you when I get back.

Friday, February 02, 2007

Simulating Classes in C - Part 2

Well the $1 C contest has come to an end after generating lots of interest but no full blown solutions. I'm okay with that, thanks to all of you who expressed interest and started on it. From conversations with several of you over chat, I know that there were some great ideas out there. If you don't mind taking the time, please describe your idea in the comments section. As my friend Matt can attest, I love discussing software, ideas, designs, and just about anything related to creative problem solving. This is probably why I really enjoyed math in high school and college. I looked at each problem as a logic puzzle which could be solved multiple ways. Finding the most elegant solution made me feel like I had just written a poem of supreme beauty.

/* JSObject functions */
void InvokeObjectMethod(JSObject* object, char* methodName,
JSListOfObjects* inputParams,
JSListOfObjects* outputParams) {
int i;
JSClass* class_of_object;
int method_index = -1;

/* Impossible to invoke a method on a NULL pointer */
if(object == NULL) {
/* ToDo: send a "NULL object" error code in the outputParams. */
return;
}

class_of_object = (JSClass*)(object->type);

if(class_of_object == NULL) {
/* ToDo: send a "NULL class" error code in the outputParams. */
return;
}

/* Find the index of the methodName in the object's class. */
/* This part of the code is O(n) efficient, but this could be
improved if the function names were sorted or if a hash
algorithm was used. Hashing could reduce to O(1). */
/* I could also allow the calling code to specify the desired
method directly by index to avoid requiring a string
lookup for each invocation. */
for(i = 0; i <>method_count; i++) {
if(strcmp(class_of_object->method_names[i], methodName) == 0) {
method_index = i;
break;
}
}

/* If the method name was not found in the list of class methods,
return an error code. */
if(method_index == -1) {
/* ToDo: send a "method not found" error code in the
outputParams. */
return;
}

/* Invoke the method at the index corresponding to the method
name. */
(*(class_of_object->methods[method_index]))(object, inputParams,
outputParams);
}

I wrote my solution a few weeks ago, then started researching how other object oriented schemes are implemented. I found out that my code has several disadvantages and some significant advantages as well. For example, I started to comapre the likelyhood of missing the RAM cache to solutions in C++ and Java. There were a few other intersting comparisons but I won't go into all of the nitty gritty details. Overall, I'm very pleased because I learned a lot. Lets discuss!

Tuesday, January 23, 2007

What is ogg vorbis?

I'm glad that you asked. Ogg Vorbis is a format for music files like MP3. In many ways, I think that Ogg Vorbis is better. It produces higher quality output at a lower bit rate than MP3's. This means Ogg Vorbis files sound better and are smaller than MP3 files. In addition, Ogg Vobis is an open format and it uses open source software. This means that if you wanted to create an Ogg Vorbis player, or write a program that uses Ogg Vorbis, you don't need to pay any licensing fees on the technology. The MP3 format is patented by a German company (Fraunhofer Society) and they charge licensing fees to use it.

So, why isn't it more popular you may ask? I think it all comes down to timing. Ogg Vorbis was introduced much later than MP3, and several MP3 codecs have been released as free software for individual use. I'm hoping that Ogg Vorbis will gain momentum and eventually win out.

If you are interested in free and open audio compression you might also want to check out the Free Lossless Audio Codec (FLAC). The is no degradation to the quality of the sound and it is free and open like Ogg Vorbis.

Wednesday, January 10, 2007

Simulating classes in C

I have to admit, I like to program in C. In some ways, it is simpler than some of the newer, high level languages, and I really enjoy being closer to the machine code. Perhaps I'm a bit obsessive about efficiency. Still, I sometimes long for classes and objects in my C programs, (This is where you tell me that I should use C++ or Objective-C.) so I decided to figure out how I could simulate classes in plain old ANSI C.

It turned out to be quite easy. After I read up on function pointers, I created a struct which contains references to functions (kind of like class methods). Here's a simple example of what I'm talking about:

#include<stdio.h>

typedef struct {
int (*test)(int); /* This is the function pointer */
} functionholder;

/* At runtime, I will point to this function */
int thefunction(int x) {
printf("thefunction says %i\n", x);
return 0;
}

int main() {
functionholder fholder;
fholder.test = &thefunction;
(*fholder.test)(7);
return 0;
}

When I run the above, the program prints "thefunction says 7".
From there, I decided to create a family of structures which would simulate classes, objects, and allow polymorphic function calls.

One way to divide up data and methods in an OO way is to say that the class dictates the methods which can be used with the data in an object instance. So we could say that a class contains a list of functions. Using function pointers, the method called can be changed at runtime, as long as all of the functions have the same stack profile. Have I lost you yet? So what I needed to do was create a generic function prototype which abstracts the parameter list into a common format. While I was at it, I decided to lose the restriction that methods return only one value, so the results of a method call will be stored in a structure which is passed in as a parameter. (The method should probably be called a procedure instead of a function.) Perhaps it would be simpler to show you the code.

typedef struct {
void* type; /* This will point to a JSClass. */
void* data;
} JSObject;

typedef struct {
int object_count; /* number of objects in the array */
JSObject** objects; /* An array of pointers to JSObjects */
} JSListOfObjects;

typedef struct {
char* name;
/* Each JSClass contains a list of pointers to the methods which belong
* to that class. */
int method_count;
/* strings naming the functions (allow method lookup by string) */
char **method_names;
/* An array of pointers to functions */
void (**methods)(JSObject* x, JSListOfObjects* y, JSListOfObjects* z);
} JSClass;

I was going to discuss the functions I created to streamline "class" method invocation, but this post is getting a bit long. So I've decided to try something fun. I'm going to ask you, gentle reader, to suggest a design for a function which simplifies invocation of an object method. I will mail $1 (USD) to the person who posts the "best" working solution in the comments below. (I'll be compiling using gcc -ansi. Oh, and US residents only, I don't want to run into any strange rules.). In addition to a dollar, you'll have won bragging rights for the first of my blog challenges. After a week or two, I'll post my solution and we can all compare notes. Happy coding!

Saturday, January 06, 2007

A Clockwork Orange

I just finished reading A Clockwork Orange by Anthony Burgess and I would recommend it. If you decide to read it, be prepared for a rip roaring ride of emotions and strange slovos (words). At times, it can be difficult to stomach and after the second chapter, I was ready for the main character to be killed off. (I'd have tolchoked his merzky litso all on my oddy knocky, oh my brothers, 'til the krovvy flowed real horrorshow and his zoobies come all out.) There are some comic moments, (it can be a malankey bit silly) but at it's core, this book explores the deep topics of morality and free will (and all that cal). I've never viddied the movie, but I tend to think that it wouldn't come off so well. Some things just work better in print.

Monday, December 04, 2006

Wii have a Wii

This weekend my wife and I joined some friends to wait in line to buy a Nintendo Wii. My friend m3tus had a hot tip that the local Circuit City had exactly 27 units which they were going to sell on Sunday morning. Vanessa and I arrived at 2:30 AM for place number 18 in line. (Two friends of ours had arrived earlier.) It was quite cold, but we came prepared with a tent, sleeping bags, camp chairs, and quite a few layers of clothes. We even managed to catch some zzz's in the wee (wii?) hours of the morning. I think line member number 27 arrived at 4:30. He almost left, but Vanessa told him that the two of us were only getting one, so he would be the last to get one.

A couple of trips to a 24 hour Safeway and a nap later, some of the Circuit city employees arrived to hand out vouchers. I think it was around 8:00 AM (the store opens at 10:00). We packed up our gear and hit Denny's! Ah sweet food.

We returned to the store to find a long line of customers all waiting to get a Wii and Wii accessories. Some employees announced that they had already given out vouchers, and that all ticket holders should move to the front and form their own line. They called out tickets in order and we paid for our Wiis. My friend m3tus wanted to make sure that no one tried to take his. So he claimed it the old fashioned way and licked it! This would have made a great picture, I wish I had known he was going to do it. The whole line had a good laugh. Then it was time to head home and get some proper sleep. Are we getting too old for this?

Wednesday, November 29, 2006

Pomegranates!

A couple of weeks ago I had a pomegranate for the first time. Eating it was quite an intricate task, made all the more so by the challenge in keeping pomegranate juice off of my clean white shirt. (It's a new favorite of mine and states proudly "Debugging Sucks. Testing Rocks.", but I digress.) If you have the chance to try one, do it! I've never eaten anything quite like it. I think I would describe the inside as if someone shrank red (seeded) grapes and made the grow on the inner wall of a squash. Check out the pictures.

Wednesday, November 01, 2006

A Steganography Scheme - Part 2

My text based steganography program is here! I completed the program yesterday, and Vanessa came up with a great name: Steganosaurus. Get in touch with me if you would like me to send you the program and the source code. I'm still considering publishing it on an open source hosting site.

You may recall my previous post about this steganography scheme, and I said I would tell you how it all works. So here goes:

My steganography program needs 4 pieces of information to embed or extract a secret message, it needs a file which will be converted, the base, the shift value, and a filename to which the converted message will be stored. The base and shift need a bit of explanation.

Base: All data on a computer is a number, and a number can be expressed multiple ways. I wrote about this in "A Steganography Scheme - Part 1". So the base tells Steganosaurus how to express the data. Should each number in the source file be converted into a series of values between 0-10, 0-50, 0-200? The choice is yours.

Shift: My program outputs a range of values from the source file, and each of them is between 0 and Base. How does this become readable text? That is the purpose of the shift, it is a value added to each piece of the converted file to make it into a character. So the result of the whole process is the contents of the original file expressed as numbers in the range Shift to Base + Shift. These numbers are converted into Unicode characters (UTF-8) so the end result is a readable file. You can see an example in my wiki entry about Steganosaurus. (It's probably easiest to see an example.) By using different shift values, you can hide the data from your original file in text from any language in the world.

So check it out, give it a shot, and ask me to send Steganosaurus to you.

Thursday, October 19, 2006

Some random items

Usually, my blog posts center on one theme or one idea which I try to explore in depth. Tonight I'm not feeling so focused, so here is a scatterbrained snapshot, developed from my tired mind. It has been a long week.

What am I up to?

I wanted to write a quick update, because it has been a while. I'm still working on my steganography project. I decided to build UTF-8 support into it, and this has complicated things slightly, but it's good because I'm learning new things. I spend an hour or two on it a couple of days a week and it is coming along quite well.

I'm reading a book. Neverwhere by Neil Gaiman and I'm really enjoying it. Many thanks to m3tus for letting me borrow it. I will probably finish it on the flight tomorrow.

And where is this flight taking me you might ask. Well, homecoming of course (this is for my University, just to clarify). I'm looking forward to meeting old friends and hanging out in the old haunts, so to speak.

And now I will close with a random link: http://206.220.43.61/primespeaks/votePrime/. I don't know if you have heard about the upcoming Transformers movie. I'm mildly interested because this was one of my favorite shows when I was very young. Apparently, they are having a contest to choose a line which will be said by Optimus Prime during the movie. The whole thing seems like a giant publicity stunt (and a way to collect email addresses), but it is kind of fun to watch people try to hijack the election to choose the line. One individual was campaigning to get the line "I Guess I'll Transformer Into A Truck Now." entered into the contest. Unfortunately his line didn't make it. Personally, I'm pulling for "These pretzels are making me thirsty!"

Random.

Friday, October 13, 2006

Seeking Simplicity

Simplicity. Life can so easily get too complicated. I often feel that it is so already, and there is still so much ahead of me. So I've been thinking about how to simplify my life, I've even been reading about it. If you are looking for a good book to read, check out Celebration of Discipline by Richard Foster. I read through it a couple of years ago and found it to be extremely refreshing. The perspective offered by Richard Foster is quite different from that we usually find in our affluent, consumer culture.

Speaking of simplicity, I've been complicating my web presence by creating a new webpage and signing up for del.icio.us. I wrote more about it a couple of days ago on my wiki page.

Saturday, September 30, 2006

A Steganography Scheme - Part 1

I've been thinking lately about steganography. Previous tools have hidden information in images, videos, sound files, and other large chunks of information. But I have not seen many examples of steganography with text (here is one). I decided to put together a simple and flexible text steganography tool just for fun.

The secrecy in a stegonography scheme rests in a shared algorithm between the sender and receiver which is not known by those trying to intercept the message and the fact that a hidden message is not apparent in the message being sent between the individuals. Anyone trying to find the hidden message faces two challenges:
  1. How do I know when a hidden message is present?

  2. How do I extract the hidden message?

Because I am explaining my stegenography idea to the world at large, item number two is no problem. I hope that the first question will not be so easily answered. In any case, you should not rely on this, or any other steganographic method to keep a secret. For that, you need encryption.

Now, on with the scheme!

I wanted users of my system to be able to send any kind of data by hiding it in a plaintext message. In order for the information to be hidden in text, it may have to be converted from one form to another. The same information can be expressed in multiple ways. For example, the number 14 can also be expressed as 1110 (binary), 16 (octal), and E (hexadecimal), depending on the encoding or base of the information. When information is converted into another form, someone who is decoding or reconstructing the information needs to know what form it is stored in. In many steganography schemes, the form of the data is constant and is a secret shared only by those who are supposed to be able to read the hidden message. I wanted to allow flexibility in the encoding, or alphabet, which is used to express the hidden message, so a message from my system will include a definition of the alphabet used to hide the secret message. Here are the steps for using my scheme:
  1. Write the secret message

  2. Choose an alphabet to encode with

  3. Convert the secret message to the desired alphabet

  4. Embed the converted secret message into an innocuous public message.

Now I've shared with you what it is that my steganography scheme will do. In my next post, I'll talk about how.

Tuesday, September 19, 2006

Back on the Internet


It's good to be back on the Internet. My wonderful wife and I relocated a couple of weeks ago to our new domicile and our connection was set up today. A lot had happened while I was out. The facebook newsfeed situation was addressed, new Strong Bad emails were released, and, best of all, my uncle Doug signed up on myspace and has written a mighty fine blog (rss feed). It seems that my return to cyberspace was none too soon:

So, I've been on myspace for a couple of days now. My profile echos when it loads, a soft lonely sound. Tom's still smiling away like a leprechaun (I should be having so much fun), lovin' you Tom, you haven't removed yourself from my page, yet. Off in the distance I hear crickets or is that my knees? Anyway, I'm waiting in breathless anticipation for at least my wack-job nephew and his lovely, vivacious bride to answer my request to be their friend. Maybe someone in an induced stupor of some sort will accidently stumble upon my page and be touched by my incessant whining and think to themselves "that poor bastidge, I'm gonna be that fargin' Snuncle_Fudge's friend!!"*

Good show Uncle!

* Quoted directly from Doug's blog, a Doug's blog production, copyright Doug 2006, all rights reserved, available for a limited time only, while supplies last, act now and get two for the price of one, a $50 value for only $19.99.

Sunday, September 03, 2006

Reviving my laptop

I have an old laptop which I would hate to see go to waste, an Intel 796 megahertz processor with 128 megabytes of ram and the weight of Windows XP has become too much for it to bear. I want a system that will run quickly and smoothly. I need a web browser and programming tools (gcc, make, python, perl, svn, etc.) and an mp3 player might be nice too. I had been running OpenSUSE, but the performance was still a bit sluggish. Then I tried Damn Small Linux (DSL) and it had almost everything I need. Fluxbox is a great windowing system and it ran extremely well. Things started to break down when I tried to install make, a series of dependencies and library downgrades prevented me from being able to get everything I needed. The problems continued the more I tried to modify the system. So I've tried others, five distributions so far, but none seem to work just right. This is turning into quite the weekend project.