Other Other Programming

Still waiting…. but this time with a measure of patience!

I’ve been waiting for over 3 weeks to hear back from IBM.  I eventually heard from them, when they apologized for taking so long.  All this is understandable as they interviewed a TON of people.  The good news is that they want to offer me a job!  They bad news, is that they can’t give me my offer yet because of corporate red-tape.  It has to finalized, stamped, copied in triplicate, etc, etc.  Either way, I’m very excited to see what they have to offer.

I also got an interesting call today from MSU.  I applied for a position as a web developer there almost a month ago, and got a call to interview today.  I was caught off guard, so I hope I didn’t sound not-interested.  I have an interview with them on 12/15.  I look forward to hearing about the position, hopefully answering some interesting questions, and seeing what they have to offer.  While I doubt they can match IBM’s pay scale, they have other incentives like tuition reimbursement and then like, which make a job there very enticing.

Also, along a different line, I created a URL shortener the other day.  It’s called  It works like any other URL shortener, except faster :)*

That’s all I have for now.  I’ll leave an update when I’ve made some job decisions.

*It’s probably not faster, but it’s at least as fast as most other shorteners.  I use Apache mod_rewrite to handle the url, and then a quick sql query to find out the original URL.

Other Programming

Playing with Go: Channels and Go-Routines

Edit:  I’m implementing a new version of this that isn’t limited by overflow.  I’m doing this by adding the numbers on a per digit basis, carefully managing the overflow, and storing the numbers as strings.  Theoretically, we should be able to calculate LARGE Fibonacci numbers like this.

When I heard about Google’s new programming language Go last week, I immediately jumped on it.  I had used Limbo before for a distributed programming course, so I thought that I might write some code to help other people get their feet wet.

My example is a simple Fibonacci number calculator.  It works by creating a new Go-routine every time it needs to calculate the next number.  There are a couple different approaches to doing this:  Create the entire pipeline first (faster calculation, slower set up), Create the pipeline as we go (not a bad way to go, smaller overhead), or create a ring and have the calculation take place within the ring.  Communication between the Go-routines and the main thread are handled via channels.

I heavily documented the code so that beginners might be able to make sense of what’s going on.  If you have any questions, please leave a comment!

Download the code here.

* Name:   fibonacci.go
* Date:   November 16, 2009
* Author: Jack Slingerland (
* Description:  This program is a Fibonacci number calculator.
*   It may be invoked as follows:  “./8.out [goal]”, where [goal]
*   is the Fibonacci number that you want to computer.  Currently
*   the program is limited to the 46th Fibonacci number due to
*   overflow, however a new implementation is in the works that
*   won’t have that limitation.  The real purpose of this program
*   is to show how Go-routines work, and how communication and
*   sychronization between them is handled using channels.

package main

import (

*  This ADT holds all the information needed to calculate the next
*  Fibonacci number in the sequence.  Current is the current index
*  in the series (ex, 5 = We’re on the 5th number in the sequence).
*  Goal is of course, the number in the sequence that we’d like to
*  achieve.
type fibonacci struct {
a int;
b int;
current int;
goal int;

func main() {
//Check the command line arguments for sanity.
goal, err := checkArgs();
if(err != “”) {
fmt.Fprintf(os.Stdout, “Error: %s”, err);

//Special case:  If the goal is 2 or less, the Fibonacci number is always
//1.  This isn’t really worth creating channels + go routines for.
if(goal <= 2) {
fmt.Fprintf(os.Stdout, “Fibnonacci Value %d is: %d\n”, goal, 1);
} else {
//Construct two channels, the input channel acts as our communication
//between the Go routines.  As you can see, it can be typed as an
//ADT(struct), which makes passing data REALLY easy between go routines.
//The final channel is for passing back the goal Fibonacci number to
//the main thread.
input := make(chan fibonacci);
final := make(chan int);

//Create a new fibonacci object and set it’s values.
var x fibonacci;
x.a = 1;
x.b = 1;
x.current = 2;
x.goal = goal;

//Create a new Go routine with the addNumber function.  We pass it the
//two channels that were declared earlier.  This is similiar to “spawn”
//in Limbo.
go addNumber(input, final);

//The first addNumber() Go routine will block until it gets input from
//the input channel.  So, we pass it our fibonacci object.
input <- x;

//Now, we block and wait for the Go routines (addNumber()) to finish up
//and send us back the final value.
number := <- final;

//Print the value out and we’re done!
fmt.Fprintf(os.Stdout, “Fibnonacci Value %d is: %d\n”, x.goal, number);

* The addNumber() function takes two channels as parameters.  One is a
* channel of fibonacci, which holds information about which number to
* calculate and when to stop, and then a channel of type int, which will
* be used to send the final goal number back to the main thread.
func addNumber(input chan fibonacci, final chan int) () {
//Block here and wait for input from the previous thread
//or the main thread, depending on the situation.
x := <- input;

//Here we check to see if we have met our goal, if we
//have, we return the goal value back to the main thread
//via the final channel.  Otherwise, we calculate the
//next number in the sequence.
if(x.current < x.goal) {
fib := x.a + x.b;

//This is fun because you can assign multiple values at once.
//x.a <- x.b and x.b <- fib.  🙂
x.a, x.b  = x.b, fib;
x.current = x.current + 1;

//Make a new channel of type fibonacci so that we can communicate
//with the new Go routine that we are about to create.
output := make(chan fibonacci);

//Pass the new Go routine the newly created channel, as well as the
//final channel that was passed in from the caller.
go addNumber(output, final);

//Send the fibonacci object out on the channel.
output <- x;
} else {
//Send the goal value out on the channel back to main.
final <- x.b;
//Go routine dies now.

* The checkArgs() function is a great example of returning multiple
* values.  We return an integer and a string to the caller, so handling
* errors is fairly straight forward.
func checkArgs() (int, string) {
//Fetch the command line arguments.
args := os.Args;

//Check the length of the arugments, return failure if that are too
//long or too short.
if((len(args) < 2) || (len(args) >= 3)) {
return -1, “Invalid number of arguments.\n”;

//Convert the goal argument to an integer.
goal, err := strconv.Atoi(args[1]);

//Make sure the conversion went correctly, otherwise return failure.
if(err != nil) {
return -1, “Invalid argument.  Argument must be an integer.\n”;

//Since this implementation is limited, make sure the user can’t go
//beyond the program’s limits.
if(goal > 46) {
return -1, “This program only calculates up to the 46th Fibonacci number.\n”;

//Check the lower bound as well.
if(goal < 1) {
return -1, “Invalid range.  Number must be >= 1.\n”;

//On success, return the goal value and an empty string indicating
//that everything is good.
return goal, “”;

Other Other Programming

Geocities : Salvaged

As much as it pains me to look at, I decided to salvage one of the earlier web pages that I ever made.  I have long since forgot earlier web pages, but “The NannyMUD Guide” really stood out to me because it was my first serious effort at web development.

It’s nasty sure (big crappy flash animations, talking to myself, awful menu design, crap color scheme,…), but it was an important to me then.  Click the link below to check it out.

The NannyMUD Guide

Edit:  I’ve been asked for a quest walk-through for NannyMUD.  Click here to download it.

Other Programming

Functional Programming with Erlang

For the past 8 weeks in my graduate operating systems course, we’ve been dealing with the issues of inter-process communication in massively parallel situations.  For development of such applications, we’ve been using an operating system called Inferno (of Plan 9 origins) which has a built in language called Limbo.  Limbo is a great language for learning network programming and multi-threaded programming.  It has communication channels which are typed, so you can pass whatever you want along them without pre-processing the data.  However, you still have to manage all of those channels.  It also has a nice C + Pascal style syntax:

message := “Hello World!”;
sys->print(“%s\n”, message);

While discussing languages that support massive concurrency with my professor, the subject of functional programming came up.  I mentioned to him that I wanted to learn a functional language, but wasn’t sure where to start.  He suggested Erlang due to it’s easy support for massive concurrency.  My question to my readers (if I have any left), is do you have any experience with programming multi-threaded and/or distributed programs with Erlang?  Is it worth the time to learn, or would my efforts be better off elsewhere?

Other Other Programming

Epiphany of Development

I’ve been doing web development for a long time.  I made my first (crappy) web page in 6th grade using the then awesome Geocities.  After that, I graduated to Front Page express.  Throughout my development career, I’ve had a series of epiphanies that have brought my skills to the next level.  Bold entries are where they happened.

  • 1998 – First web page – I knew that the internet existed, but it never dawned on me to actually create content.  I didn’t realize it at the time, but this simple act has been the anchor for the rest of my life.
  • 1999 – Discover Front Page (Express) – With my new found web skills, I started to use more advanced WYSIWYG editors.  Frontpage is hardly advanced, but it allowed me to separate my menus from my content using frames.  It opened up numerous paths for me to take.
  • 1999 (late) – Dreamweaver – Not super important, but discovering Macromedia Dreamweaver really changed how I did web pages.  I stopped using frames to make menus and started using layers.  Little did I know that layers were actually “<div>” tags that were positioned by CSS.
  • 2000 – Flash – Flash was still rather immature at this point, however it showed me what could truely be accomplished on the web.  No longer did menus have to be boring images and text links.  We could have tweening!  It was around this time that I build my first web page with heavy flash components.
  • 2001 – Discover PHP, HTMl, and CSS – This was a big year for me.  I discovered PHP, HTML, and CSS all at the same time.  I had no idea how any of these worked though.  At the time, PHP was well beyond my grasp.  CSS and HTML seemed do-able though.
  • 2003 – HTML + CSS  Zen – I was a junior in high school at this point, and had been appointed to wor on the school’s web site.  Actually, it was the entire district’s domain.  My brain had matured enough for me to make a web site BY HAND using nothing more than HTML and CSS.  I still didn’t understand programming, but using markup languages like HTML and CSS because second nature to me.
  • 2004 – Servers – Around this time I discovered that I could make servers on my own!  Not really code them persay, but rather run server software.  I’m pretty sure my first server was an FTP server so that I could share files with my friends.  It was tedious though, since I was still using 56k dial-up at the time.
  • 2005 (Early) – First Computer Science Course – The biggest eye opener ever.  I never realized how deep the rabbit hole went.  I was only learning assignmen, logic, loops and a few other things, but it made my thirst for knowledge inquentiable.  I started to learn C++ here.
  • 2005 (Late) – Assembly Language & C – Taking a course in SPARC assembly and a bit of C is an eye opener for every Computer Science student.  You’re pretty much at the bottom of the rabbit hole, and you spend the rest of your career climbing back out.  Coding in low level languages made me a much better programmer though, because it forced me to think.
  • 2006-2007 – School & Languages – These years were spent diving into new languages, learning new programming styles and domains, and generally having a good time.  I didn’t spend a lot of time doing web development, but I did teach myself how to make a web server in Python.  Not especially helpful, but still fun.
  • 2008 – PHP, MySQL, LAMP – I had already learned Linux in 2006-2007, however I never really dove into Linux as a server.  That was at least, until I found out (again) about PHP.  Turns out PHP needed Apache to run.  And all the fun PHP stuff also needed a database server  (MySQL).  I set up a PHP + Apache + MySQL server and went from there.  It was at this time that I started development on the first edition of Wrestling Addix.  I made my own CMS for it (bad idea) and in general the site worked fine, however it was a bear to maintain.  I decided that the next version would use a pre-built CMS so that my life would be easier.
  • 2009 – Ajax, WordPress, OOP, CMS – This year I’ve learned lots of stuff.  Most of it revolved around web development though.  I’ve learned to bend WordPress to my will (it runs this site).  I’ve learned how to use Ajax to make my web apps for responsive.  I’ve learned how to use Object Oriented Programming in my web sites, and how using a CMS WILL make your life easier.
Other Programming

The “Project You Don’t Want to Do” Life Cycle

  • Day 1: Okay, quick and easy project.  I should at least try to have fun with it.
  • Day 2: What!? I have to do this in Visual Basic?  I don’t even have visual studio, let alone any VB knowledge.
  • Day 3: Visual Studio is installed, created a gui for this project.  Hey, this gui designer is pretty nice.
  • Day 4: Beginning to realize why I love PHP so much.  I’ve never had so much trouble connecting to a database in my life.
  • Day 5: Screw this, I could make this program in 10 minutes in Python!
  • Day 6: Crap, my Python is rusty.  Oh well, I’ve made some good progress.
  • Day 7: Man, gui programming in python is weird.  I guess making a gui in any language kind of sucks.
  • Day 8: Bleh, back to Visual Studio.
  • Day 9: Suck it up and do is VB.  Learn something new!
Other Programming

Computer Information using WMI Scripting

A few years ago, I worked at the OIT Help Desk at Central Michigan University.  While there, I was asked to write a little utility that would pull information about the machine out of the system.  In order to do so, I learned VBScript and the WMI library that comes with Windows.  WMI is really handy for projects like this because it allows you to pull machine specific information in an easy way.  For instance, let’s say I want to get the machine name:

Option Explicit
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strComputer

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2”)
Set colComputer = objWMIService.ExecQuery _
(“Select * from Win32_ComputerSystem”)

For Each objComputer in colComputer
Wscript.Echo “System Name: ” & objComputer.Name _
& vbCr & “Total RAM ” & objComputer.TotalPhysicalMemory


Easy as pie.  The only problem is that you have to have a loop in there.   Even with only 1 computer.

Other Programming

Ajax Utility Function

Edit:  This post was made before I started using JQuery or Mootools.  This can safely (luckily) be ignored now.

For the past couple months I’ve been playing around with Ajax style events on a few pages I’ve been working on.  One of the main problems I’ve run into is cross-browser compatibility (surprise!).  To solve that problem, I took the advice of a book that I’m reading and made a utility file for some of the most annoying cross-browser issues:  Event Handlers, Activated Objects, and Request Objects.  You can download the utility file by clicking the link below.

Download utils.js here.

Enjoy!  If you have any questions, please leave them in the comments and I’d be happy to get back with you.