Friday, April 27, 2007

Get to know your inner eigenclass

I spent some more time looking for interesting articles on ruby metaprogramming. After deciding upon my method of search I quickly fired off an amazing google query for (hold your breath...) "ruby metaprogramming". I came across this article in no time and when I saw how horrible the site looked I quickly closed the page and begged my eyes for forgiveness. A little while later I came across another blog that was praising that particular article so I figured I should at least read a bit. It turned out to be a very well written article that helped me understand the concept of class vs. metaclass (aka eigenclass). I recommend viewing that page in elinks.

* Observant readers will note that the theme used in the aforementioned site is the exaxt same as the author of this blog. It's now become patent to me how hard it is to read. You should probably be reading this site in a feed reader anyway.

Wednesday, April 25, 2007

If you can read this you are too big to play here.

I remember when I was in preschool I used to climb on a huge tree in the middle of the playground. My friend David and I would catch caterpillars and then squish them on the steps of the school to see what color they were inside. That tree is barely standing now and I've long since realized that squishing things for mere novelty is a little strange. Another thing I discovered later in life was a sign that was hanging from the surrounding fence stating, "If you can read this you are too big to play here".

After my first pass reading this article on InfoQ I had the an all too familiar feeling as if there was something going on that missing me entirely. I read through it a second time and the uses of eval, class/module_eval and instance_eval are starting to become more apparent. Read the code and pay close attention to the use of eval. It might not be so evil after all.

Tuesday, April 24, 2007

JRuby 0.9.9 is out in the wild

If JRuby isn't on your radar it should be--especially with today's announcement of JRuby 0.9.9. The investments in optimization are starting to pay dividends. I think one of the most impressive aspects of this project is the momentum.

Aren't familiar with JRuby? Watch this video of a presentation by Ola Bini last month on JRuby 0.9.8:

Migration gotcha

Apparently sqlite3 is more forgiving than mysql when it comes to migrations. I found out today that there is no need to specify the ':id' column and if you try it with mysql5 you will get an error similar to:
Mysql::Error: #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(11), `suite_id` int(11) DEFAULT NULL, `text` varchar(128) DEFAULT NULL) ENGINE=' at line 1: CREATE TABLE surefire_notes (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `suite_id` int(11) DEFAULT NULL, `text` varchar(128) DEFAULT NULL) ENGINE=InnoDB
The problem has to do with the 'PRIMARY KEY(11)'. I pasted the above command directly into mysql and removed the '(11)' and everything worked just fine. With some more googling I came across this site which further confirmed my discovery.

Monday, April 23, 2007

The best explanation of metaclasses in Ruby I've found

I stumbled across "seeingMetaclassesClearly.html " today. I don't know how I never came across it. It's definately the best explanation of metaclasses in Ruby I've ever read. Now the whole "class << obj; def meth; puts "hello from the metaclass"; end; end;" syntax makes sense. Previously I had used "obj.extend(module)" before but the former is obviously more convenient if you are in a class definition.

Wednesday, April 4, 2007

getaddrinfo: name or service not known

Once again I find myself trying to get a ruby app working on a windows machine. I can hardly express bad I feel for anyone who is plagued to work in such an environment full time. The last time I was struggling to understand how Ruby's in-process threads on win32 are not concurrent. This time around it's trying to understand why getaddrinfo() was failing.

Basically I'm working with DRb which by default uses TCPSocket as the default protocol. Socket.getaddrinfo() was telling me 'name or service not known' when it was trying to connect to the DRb server on my unix host. After hours of googling around learning about getaddrinfo() on windows and cygwin I came to realize that my problem was probably not related to what most of the google (and yahoo) results were returning. Apparently there was a time when that call would simply fail or was not implemented in cygwin. It turned out my problem was actually related to the hostname of the machine it was working on: 'LENOVO-A0EFF48'. I can't say I totally understand the relationship between cygwin and windows understand of a machine's hostname but I eventually changed the hostname to 'localhost'. I rebooted I got a different error because my VPN was choking (and I suspected it to be related to the hostname change). I then changed the hostname to 'laptop' and rebooted. Voila, my VPN and getaddrinfo() worked. Now I think I'm back to fighting Ruby threading issues on windows.

When I get around to it I'll look microsoft's getaddrinfo() source and figure out why it was choking on 'LENOVO-A0EFF48', oh wait....


my google reader feed