02.03.08

Reading Old GW-Basic Programs

Posted in personal, programming at 3:50 am by danvk

I found a disk image I’d made of an old hard drive of mine today (circa 1995) and had some fun browsing through my files. Back then, I was programming in a combination of QBASIC and GW-BASIC. It’s easy to read old QBASIC programs, since QB saved code as human-readable text.

Not so, GW-BASIC. To save space, it stored code in a compact, binary format. This seems like an unnecessary optimization now, but back in 1984 it made a lot of sense. GW-BASIC was an interactive environment, and it stored all your code in memory. Memory was a scarce resource at the time, so every byte counted. Hence the binary format.

I wanted to read my old GW-BASIC programs, so I dug around and found this discussion of the GW-BASIC binary file format. It’s incredibly detailed, which let me whip up a decoder in Python over two solid hours of hacking. Without further ado, here it is:

GW-Basic Program Decoder

For a sample decoding, see below the fold.
Read the rest of this entry »

12.24.07

Using Track Parser

Posted in music, programming, web at 12:27 pm by danvk

pitchfork-tracks.png Pitchfork Media has released their two standard year-end lists, the Top 100 Tracks of 2007 and the Top 50 Albums of 2007. As usual, they’ve been lampooned all over the web, including one critique in pie chart form. For me, they made for perfect listening on a long car drive this weekend.

In my case, this list led to a good use of my Track Parser script, which is in all likelihood the most useful program I’ve ever written. It’s an AppleScript for iTunes (i.e. Mac only, sorry) that lets you apply regular expressions to track names/tags. Here’s how I used it today…

Through some strange turn of events (certainly nothing to do with this), I found myself with a playlist of the top 100 tracks. The music was all there, but none of the songs had their “Artist” field filled in! Here’s where my Track Parser script came in.

I googled around and quickly found this page, which has some commentary on the list, as well as what we’re interested in: a copy of all the songs/artists in simple text form. (For what it’s worth, I agree with his reactions.)

I copied the list and ran two regular expressions to get it down to just the artist (s/ ".*//g and ^\d*: if you must know). The tracks are in reverse order of what we want (100 to 1 instead of 1 to 100). So I ran pbpaste | tac | pbcopy to put the #1 track at the top of the list. Or I would have, if Mac OS X had the tac command. Instead, I ran this monstrosity:

pbpaste | perl -ne 'push @x, $_; END { print for reverse @x }' | pbcopy

to do the same thing. In retrospect, I should have just sorted my playlist in reverse track order.

Next I went into iTunes and selected my songs. I ran “Track Parser (Clipboard)” from the Scripts menu, clicked “New Pattern” and put in “%a” to extract the artist from each line. Track Parser handled the rest. Total time: about five minutes.

12.16.07

C++ STL sort weirdness

Posted in programming at 9:59 pm by danvk

I ran into a weird bug at work this past week. What does this code do?

#include
#include
#include

struct Compare {
int operator()(int a, int b) { return a – b; }
};

int main(int argc, char** argv) {
std::vector blah;
for (int i=0; i<20; i++) blah.push_back(20 - i);
std::sort(blah.begin(), blah.end(), Compare());
std::copy(blah.begin(), blah.end(),
std::ostream_iterator(cout, “\n”));
}

If you said “segfault”, give yourself a pat on the back! Bonus points if you know that changing the “20″ to a “16″ will prevent the segfault.

After spending several hours staring at this, I figured out what was going on. Rather than taking a compare function that returns an int (like qsort or Perl’s sort), it wants a “LessThan” function:

struct LessThan {
bool operator()(int a, int b) { return a < b; }
};

If I’ve ever been happy that C++ silently casts ints to bools, I have now done my penance. I’m still somewhat surprised that std::sort segfaults when given a strange comparison function, rather than returning an unsorted list.

10.26.07

NS-Tower in a Canvas Tag

Posted in programming, web at 2:49 pm by danvk

nsticonw.gif I recently noticed that Rice has unceremoniously purged my Owlnet site, so I’ll be moving some of its content over here. First up: my JavaScript implementation of Nagi-P Software’s NS-Tower.

This is one of the few games I’ve ever seen with only one control: jump. Your character bounces off the walls and you have to power him up for jumps. My record is 282 floors on Hard. Can you beat it? No fair using the JavaScript version, though. More details below (warning: it takes a hard right turn for the nerdy)…
Read the rest of this entry »

10.09.07

A Java Surprise

Posted in boggle, programming at 11:44 pm by danvk

java.png
I’ve always been a Java and Eclipse naysayer, but I’m afraid new experiences are forcing me to reevaluate my skepticism. The last time I used Java was JDK 1.3 on a Sparc workstation back in early 2004. Eclipse was hella slow on that hardware, and somehow my workspace wound up in a temporary directory. This was a very bad thing, because as soon as I logged out, my project was gone forever. So I had good reason to swear off Eclipse.

More generally, Java left off a mighty stink back in 2004. Any GUI that I ran on the Mac would look out of place and felt clunky. Performance was poor. But in retrospect, I suspect much of the rank Java smell was really coming from the design patterns gibberish I was being force-fed at the same time. Why use a simple array when you could use an AbstractListFactory that does the same thing with 10x code bloat?

Regular readers only get one guess what program I wrote to get in the swing of things.
Read the rest of this entry »

« Previous Page« Previous entries Next entries »Next Page »