Posts

Showing posts from March, 2009

Personal: Offline

I'm going to try to go offline for about a week. Call me if you need me.

Oz: Concurrency Doesn't Have to be Hard

I'm reading a book called Concepts, Techniques, and Models of Computer Programming which is being hailed as following in the tradition of Structure and Interpretation of Computer Programs.

One of the things that I found interesting about the book is that it says that concurrency doesn't have to be hard:Concurrency in Java is complex to use and expensive in computational resources. Because of these diffculties, Java-taught programmers conclude that concurrency is a fundamentally complex and expensive concept. Program specifications are designed around the diffculties, often in a contorted way. But these diffculties are not fundamental at all. There are forms of concurrency that are quite useful and yet as easy to program with as sequential programs (for example, stream programming as exemplified by Unix pipes). Furthermore, it is possible to implement threads, the basic unit of concurrency, almost as cheaply as procedure calls. If the programmer were taught about concurrency in …

Books: JavaScript: The Good Parts (Part 2)

I just finished reading JavaScript: The Good Parts. The book weighed in at a mere 145 pages and was written by one of the premier experts in the field of JavaScript. To put it simply, if you code JavaScript and if you read books, you should read this one. Not since K & R's C Programming Language have I seen a book that was so slim and yet so useful.

Previously, I blogged about a lot of the things I learned in the book. In this post, I'm going to concentrate on some specific questions, some disagreements, and some high-level discussion. Let me make it very clear that while I may occasionally disagree on a minor point, I really enjoyed reading this book!QuestionsMy first question has to do with "augmenting basic types" (p. 33). I was a bit surprised to see Crockford adding a "trim" method to the "String" type. I thought that a lot of JavaScript communities considered this bad practice. He shows how to add a method conditionally, but I am …

Books: JavaScript: The Good Parts

These are some things that I found interesting, surprising, or profound when I read JavaScript: The Good Parts. Test your JavaScript Fu by seeing how many of these you already know!// I'm doing my best to match Crockford's style. The code passes JSLint,
// except in cases where I'm showing what *not* to do.
//
// I'm using a bunch of anonymous functions as blocks just so that the namespace
// doesn't get out of hand. Sorry if that's confusing.
//
// I'm allowing evil (i.e. eval) just so that I can use document.writeln. I'm
// not actually using eval itself anywhere.

/*jslint browser: true, evil: true */

// This is a method to create a method.

Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};

// Create a new object using the given object as a prototype.

Object.beget = function (proto) {
var F = function () {};
F.prototype = proto;
return new F();
};

// Unlike Python and Ruby, two strings with the same va…

Apple: Bluetooth TCP/IP Network

My boss and I are at a coffee shop. We had to buy $5 worth of stuff for one of us to get a wireless connection. We both have Macs. Within 15 minutes, we were able to create a bluetooth network, and I'm sharing my wireless connection with him over bluetooth.

I'm positive this sort of thing would work in Linux too, but the fact that we got it working in 15 minutes without any documentation is truly a testament to Apple's user friendliness.

MySQL: Case-sensitivity Hell

After narrowly escaping Encoding Hell, I fell into Case-sensitivity Hell.

I work with data in big batches. This time around, I was starting with an empty database and importing some data. I noticed that it said that some rows were deleted, which is a funny thing to see when importing data into an empty database. I came up with a plausible explanation which I won't get into and just moved on.

During my batch processing, I pull down all the URLs from a table into a Python dict. My program was getting a KeyError because it couldn't find the URL "http://www.example.com/layout/keywords/Broken%20heart". I did a select statement in the MySQL shell, and I could see it.

Hmm, that's weird. I looked at the code for pulling down all the rows, and it looked fine. I did a count(*) on the table, and it matched the size of my dict. Very weird. I couldn't figure out why my dict didn't have the URL even though it should clearly be there.

After an agonizing, multi-hour…

MySQL: Encoding Hell

Every once in a while, I end up in this weird place called Encoding Hell, and it takes me about a day to get out of it. Usually it's related to MySQLdb, the MySQL driver for Python; however, this time it was related to URLs.

I was trying to do a MySQL import. I kept getting a lot of warnings, which I usually try to fix. I couldn't even figure out what the warnings were because I was using the mysqlimport tool. After a while, I figured out that if you do the import from within the MySQL shell, you can run "SHOW WARNINGS;".

Anyway, I got a warning like "Incorrect string value: '\xF1os' for column 'category' at row 76997". I traced it back to a URL like "http://www.example.com/themes/keywords/southside%20sure%F1as". That's an ASCII URL, so I couldn't figure out what the problem was.

I had some code that was splitting the URL into two other parts. It used a regex to pull out the parts I wanted, and then it unurlencoded the …

Computer Science: Faster, Smarter, More Robust

My wife and I like to play video games together cooperatively. Generally, she plays the exploratory parts, and I play the parts the require quick reflexes.

Recently, we've been enjoying a game called iNinja for the GameCube. (Thanks Ben Bangert!) As we neared the end of the game, we reached a level called "Egg Shell Skull" that seemed impossibly hard. We each spent a couple hours trying to beat it, but to no avail. It required 100% accuracy, very fast reflexes, and a little bit of multitasking. I could "program myself" to have fast reflexes with high accuracy, but every time I mixed in the multitasking, my reflexes went out the window.

Finally, I had the idea of playing the level together. I used the left side of the controller which involved ducking with 100% accuracy and very fast reflexes, while she focused on the right side of the controller which involved planning, combos, and monitoring a timer. After several tries, we finally beat the level :)

Since…