On the bleeding edge

Case 1

We use JRuby with Mongrel and Derby, developing in Eclipse. We wrote many custom scripts to ease development, to start/stop servers, run rake scripts. We hack Mongrel because it couldn’t work with JRuby then. We patch ActiveRecord JDBC manually to make Derby behave correctly. Eclipse RadRails wouldn’t play well because we’re not using CRuby.

Few months after the release of our product, Aptana releases an Eclipse IDE with RadRails that completely supports JRuby, therefore run rake scripts, supports running the Rails app in Mongrel, and supports the Derby database.

Case 2 (today)

Deployment test of a new JRuby app on a new machine. During gem install we realize a new version of ActiveRecord 2.1 (from 2.0.2). Rake migration wouldn’t run after it because the SQL statement generated a “DEFAULT NULL NULL” in a CREATE TABLE statement.

Traced the code, found issue to be likely in activerecord-jdbc. Looked at JRuby Extras, and activerecord-jdbc-adapter had 0.8.1, release June 4, 2008 (today). Checked the SVN source, Nick Sieger checked in barely 6 hours ago at 5:19am to “Fix problem with AR 2.1 and Derby with ‘DEFAULT NULL NULL’ in column defs” (as per SVN commit comment).

Upgraded the gem from 0.8 to 0.8.1, but we got an “undefined method `true?’ for false:FalseClass” right at the line of Nick’s fix.

Filed my second JRuby (ActiveRecord) bug.

* We did force versions during gem install, but we didn’t expect the new version to screw up so much.

Intel Core

Haven’t been following up on hardware. I’ve actually read these numerous times but keep forgetting. I needed to look up some PC specs today, so its now here for my own reference.

Intel Core is the series of Intel’s 32-bit dual-core processors. Intel Core Duo is the one with the dual core, and the Intel Core Solo is the one with dual core, but only one active. According to Wikipedia, it’s so that Intel can sell those with manufacturing defects on one core but not the other. Sounds logical to me, but can’t find supporting information elsewhere.

Intel Core 2 is the 64-bit series. So Intel Core 2 Duo means a 64-bit dual core processor, and Intel Core 2 Quad are the 64-bit quad cores.

On the other side, there was this (old) HyperThreading technology by Intel, which also have a “dual-core” impression because it shows up as 2 processors on XP. However its actually just one processor that simulates an additional one for doing useful work during otherwise idle cycles.

AMD’s naming is 64 means 64-bit, and X2 means dual core. So you have series like Athlon 64, Athlon 64 X2, Turion 64, Turion 64 X2.

Combine physical disks into one logical drive

Got asked this interesting question today. Usually I hear one big physical disk split into multiple logical drives, but this time a single logical drive made up of smaller physical disks is desired.

I think RAID 0 fits this scenario, but to store a piece of file equally in 2 places for personal use (not a server) looks pretty useless to me. If one disk breaks, you’re left with half of every file, which is no different from breaking both. As compared to if you had two logical drives on two disks, if one disk break, you have the other disk with some complete files.

Are there other alternatives?

Unlocker

Fed up with the Windows Explorer message that I can’t delete a folder, because it’s locked. By who? I closed my Firefox and Eclipse and it’s still there. Short of killing my explorer.exe process like I always tool, I checked out a freeware tool called Unlocker.

Right-clicking the offending folder from Explorer and selecting Unlocker showed me it was really Explorer, but I had an option to “Unlock” it instead of killing the process. Quickly done.

Note: Remember to uncheck all other options when you install the tool (such as eBay shortcuts). I’m not sure what Assistant does, I unchecked it too.

The geek is not idle

The geekblog hasn’t been updated, but the geek has not been lazing. We’ve been looking at:

ExtJS –[JSON over HTTP]–> Apache/Lighttpd –[FastCGI/HTTP]–> Mongrel/Thin/etc -> Ruby on Rails –[WebService]–> Java –[etc]–> etc

Why? Because:

  1. We have a set of Java API that we’d like to expose, even to other languages, as a service.
  2. We previously use Mongrel, Rails with JRuby, as we want to invoke Java from within, as well as use JDBC. This restricts us to pure-Ruby libraries or those that has a JRuby port.
  3. Most servers and cluster options are written for Unix. We need an easier Windows solution to run a ruby-server cluster. The cluster is necessary as Rails is single threaded.
  4. We previously had PrototypeJS (came with Rails) implementing a “rich client” on the client side, and communicated in a mixture of data and presentation. We struggled with many features, including drag and drop, resizable layouts, split panes, spinners, trees (plus lazy loading, icons), toolbars (plus icons, dropdowns, disabling highlight), tables (plus sorting, selection, multi-select, column hiding, pagination), tabs, right-clicks, and more. All these seem to be handled by ExtJS. At the same time it allows easy customization by extension and even hooks. This was important as the given widgets may not fit requirements.

This is all interesting to the geek, maybe because it looks like an ‘architecture’.

IE7 cancel onbeforeunload

I was using the onbeforeunload event to confirm the user wants to leave the page with changes, something similar to when you create a new mail in Gmail. Supposedly, setting the event.returnValue to a String will activate a browser prompt when you leave the page. Setting it null makes it not prompt, after I decided that there were no changes made.

But that only worked in FF2. IE showed a “null” as the message. No matter what I set for the event.returnValue in IE, it prompted. I even tried setting the returnValue to false, and event.cancelBubble = true, but nothing worked.

Finally by trial and error, the only way to make IE not prompt is to NOT set it at all. Don’t call event.returnValue = something. This works for FF2 too, so I’m done.

Rails logger rotation

The mongrel rails log file grows rather quickly, even in production mode since every request is logged. Log rotating becomes a basic necessity. After googling there appears to be 2 standard ways of rotating logs: use the built in rails logger parameters or use an external rotator such as logrotate. Many have also expressed problems with clustering using the built-in logger rotation.

I couldn’t find a ready Windows implementation of logrotate (I was avoiding having to build it myself) and therefore I settled for the built-in rails logger. Clustering wasn’t really an option for me due to some internal reasons. I set up the test rotation for 20 files having 10kb each, and I thought I was done when I saw backup log files of 10kb created. But when it hit the 20files, it didn’t erase the last file. Instead, it continued to increment the latest file beyond its 10kb limit!

Well, that wasn’t what I thought about rotation. After various searches in vain I took a plunge into the source pool. There, I found the implementation performs a rename of the previous log files to “shift” them. A-ha. I did a quick test with the rename function using Ruby and JRuby and found that JRuby doesn’t do rename the same as Ruby. It was supposed to overwrite it but it didn’t, nor did it throw an error.

I did a quick patch to delete the file to be rename if it exist, so that it would rename successfully. Following that, I filed a JRuby bug. Not sure if it’s really a bug, but well. Let them decide.

Internationalized domain names

ICANN is testing out URLs in 11 languages other than those that supports the roman characters, such as Chinese, Tamil, Arabic, Korean and Japanese. To do this, 11 new TLDs (top level domains) and secondary domains representing http://example.test have been created and inserted into the DNS servers. Interestingly, as the Arabic and Hebrew languages are read left-to-right, the URL will be reversed.

Try http://例子.测试. It can actually be resolved.

You can find the plan at http://www.icann.org/topics/idn/idn-evaluation-plan-v2-9-2-14aug07.pdf

Internet Explorer (IE) limits CSS imports to 32

Although the link is talking about a vulnerability when more than 32 imports are used, I’m actually having issues with a web page that actually needs more than 32 css imports. The page works fine in Firefox 2 but fails in IE 7. The article also didn’t explicitly mention IE 7, but rather older MS browsers. Even if the vulnerability may not be there, the limit of 32 stylesheet imports may still be imposed.

http://www.juniper.net/security/auto/vulnerabilities/vuln3394.html

I’m still trying to find formal documentation to support this fact, I can’t seem to find it in MSDN (as usual). Don’t ask me why I have > 32 imports. Some things are beyond my control.

Apache James

Needed a SMTP server for testing our application today, and after evaluating a few options (company smtp, various free/open source solutions) it turned out that James worked best.

James was able to run as a standalone SMTP/POP3/NNTP server or Windows Service all at the same time, and highly configurable with its XML file. I was able to get it running quickly with its installation instructions. However the site documentation wasn’t so explicit on SSL configuration; its instructions assumed a lot about the user knowing about JSSE, keystores, SSL and the such. (Well, they probably are thinking someone who didn’t know these shouldn’t be setting up a secure mail server)

http://james.apache.org/server/2.3.0/usingTLS.html
http://wiki.apache.org/james/UsingSSL

These are two good references to getting it setup. In short, do the following:

  1. Use java keytool to create a keystore containing the key pair for SSL.
  2. Edit {james}\apps\james\SAR-INF\config.xml
  3. Uncomment the ssl section of the section, replacing the values of file, password, and key-password with those of your keystore.
  4. Edit your SMTP server section and uncomment the useTLS element. Change the port number if preferred.
  5. Copy {jre}\lib\ext\sunjce_provider.jar file into the {james}\lib directory.
  6. Restart James.
  7. Test using a mail client. For a self-signed cert you may need to configure your mail client to accept the certificate.

Remember always to check your log file for error messages. It saved me loads of time from guessing what’s actually wrong. Also important is to copy {jre}\lib\ext\sunjce_provider.jar file into the {james}\lib directory. Yes, this is the step I missed that was causing a NoSuchAlgorithmException which I found in the log file.