Thursday, January 27, 2011

Solving one IE rendering problem...

I know this has been posted elsewhere, but since I recently ran into the issue and had to do some digging and coding to work around it, I thought I'd post it for others to find.

While working with a drop-down select box in a form, I wanted to be able to show/hide different sections of the form depending on the value of the selection (I'm currently using the Prototype javascript library for this project). It all worked fine in every browser except IE (surprise... NOT!). IE was not setting the "value" property of the select box.

After some testing, I found that IE DID properly set the selectedIndex attribute, so I could use that to get IE to work like I wanted it to; here's the code:

MHC.select_display = function(select_id, select_value, select_number, toggle_id) {
/***
* NOTICE IE6 properly sets the selectedIndex value but does NOT set the value property; therefore, we have to give both values to this routine
* to handle both browsers.
* alert("Hi - I've been changed! / " + select_id + " / " + select_value + " / " + toggle_id + " / " + $(select_id).selectedIndex + " / " +  $(select_id).options[$(select_id).selectedIndex].value + " / " + $(select_id).value) + " / " + $(select_id).options.value;
**/     
if(Prototype.Browser.IE) {
  if($(select_id).selectedIndex == select_number) {
    $(toggle_id).appear();
    }
  else {
    $(toggle_id).hide();
    }
  }
else {
  if($(select_id).options[$(select_id).selectedIndex].value == select_value) {
    $(toggle_id).appear();
    }
  else {
    $(toggle_id).hide();
    }
  }
};
While I don't know this for a fact, I'm guessing that other problems with IE form fields (such as checkboxes and the "checked" attribute) may be due to the timing of updates to the attributes; you may be able to find alternative attributes that you can interrogate to get things done.

Tuesday, January 25, 2011

KPackagekit / aptitude woes... solved

Recently I was trying to make some updates to my Kubuntu 10.04 machine (where I do all my Rails development) and ran into a serious problem: both KPackagekit (KDE package manager) and aptitude were unable to even start.

KPackagekit gives:
"an unknown error has occurred"
or
"The package list needs to be rebuilt. 
This should have been done by the backend automatically"

aptitude gives:
E: Read error - read (5: Input/output error)
E: The package lists or status file could not be parsed or opened.

Turns out it was a "simple" problem -- Kpackagekit and aptitude are both based on the Debian APT package. That package manager has a built-in limit as to the amount of cache space that it supports. If you exceed that limit (by having a bunch of repositories and packages stored on disk in /var), then APT and its descendents just give up. The error messages above are indicative of this kind of error (and certainly aren't very descriptive).

The problem is that - once you get to this point - you can't do much of anything. Attempts to run either command just fail.

Searching for KPackagekit info yielded nothing useful, but when I searched on aptitude and its error message, I found the solution: increase the cache limit.

Here's the source of this information. The fix is simple; just run this command and then you should be OK.
sudo apt-get update -o APT::Cache-Limit=25165824
If you need, you can increase the Limit even further... it's only 24 megabytes which is nothing on today's systems.

Thursday, January 13, 2011

Excel spreadsheets & Ruby => :tricky

I've been working on an ERP data conversion project, using Ruby to convert the data before it gets dumped into the Oracle database.  I only recently got involved to help out, and an earlier decision mandated that we produce our converted data in spreadsheets [I know, I know -- not what I would have decided, but they wanted folks to be able to easily manipulate the data].

Anyway, we're using the Spreadsheet gem which is pretty nice; however, it does have some limitations, which can result in oblique error messages such as the following:

ruby customer_fix_zip.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:376:in `validate!': OLE2 signature is invalid (Ole::Storage::FormatError)
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:368:in `initialize'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:110:in `new'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:110:in `load'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:77:in `initialize'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:83:in `new'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/ruby-ole-1.2.11.1/lib/ole/storage/base.rb:83:in `open'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/spreadsheet-0.6.5.0/lib/spreadsheet/excel/reader.rb:1144:in `setup'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/spreadsheet-0.6.5.0/lib/spreadsheet/excel/reader.rb:121:in `read'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/spreadsheet-0.6.5.0/lib/spreadsheet/excel/workbook.rb:32:in `open'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/spreadsheet-0.6.5.0/lib/spreadsheet.rb:62:in `open'
    from /Users/jseidel/.rvm/gems/ruby-1.9.2-head/gems/spreadsheet-0.6.5.0/lib/spreadsheet.rb:68:in `open'
    from customer_fix_zip.rb:12:in `'

Googling for help didn't... there are only a few posts out there about this situation, but not many responses.

This may be caused by a password on the spreadsheet -- at least that was the cause in my case. Once I had removed the password protection, everything worked just fine.  Hopefully, this will help other folks out there who are experiencing the same problem.