📜

This post was written in 2008. It's preserved here for historical purposes — the technical details may no longer be accurate.

🔍
2026 retrospective
LightWindow is long dead – it was a Prototype.js-era modal library that vanished around 2010. If you need modals today, the <dialog> HTML element does the job natively.

Well, this is the result of 2 days of head-banging with lightwindow:

Index: public/javascripts/lightwindow.js, line 444

  _removeLink : function(removed) {
    // remove it from the links array
    //
    this.links = this.links.reject(function(link) {
      if (link == removed.href)
        return true;
    });
    // remove it from the gallery links array
    //
    if (gallery = this._getGalleryInfo(removed.rel)) {
      klass = gallery[0];
      name = gallery[1];
      if (this.galleries[klass] && this.galleries[klass][name]) {
        this.galleries[klass][name] = 
          this.galleries[klass][name].reject(function(link) {
            if (link == removed.href)
              return true;
          });
      }
    }
  },

Call this function from your .rjs template, something like this:

page << "myLightWindow._removeLink($('element').down('a.lightwindow'));"

More details to follow, when this work will be complete ;).

We still can do it

Well, it seems that I’ve got no reason to be paranoid about my age: I still can do inline like I did (everyday) when I was a bit younger :).

On international workers day, 1st of May, Sam literally carried me out from home, far from the computer, and we went skating. It’s been an awesome day, we skated a lot, and shot some nice photos.

But the real good ones have been shot when ndstr caught us. He is by far the best photographer you could meet, and of course my favorite one (take a look at his site!).

He’s been also a skater, so he knows very very well how and when to shoot in order to take out the most from your tricks :). Here are two of them, portraying me and Sam while doing our best!

Skating Photo

It was fun. Really fun. Thank you Sam for taking me out of home :D.

Oh, and don’t forget to visit my deviantArt, and look at this one :D

📜

This post was written in 2008. It's preserved here for historical purposes — the technical details may no longer be accurate.

🔍
2026 retrospective
The single-user mode recovery (Cmd-S, fsck, mount writable) described here no longer works on modern Macs. Apple removed single-user mode in macOS Catalina (2019), the system volume became read-only with Signed System Volume in Big Sur (2020), and Apple Silicon Macs use a completely different recovery architecture.

Well, I’m really happy with OSX 10.5.2. Even though I’m not the one that blamed Apple for the translucent menu bar that everyone dislikes.. well, I like it. I don’t care about the TM menu bar tool, because I haven’t bought (yet) the nifty Time Capsule, I like the spinner in the Airport menu and, most of all, I really like the updates to the BluetoothSCOAudioDriver.kext that drives my bluetooth headset.

Spotlight also feels faster and faster on every upgrade, and I’m a heavy spotlight user, so this makes me really happy. Thanks Apple engineers!

Back to the topic: why odyssey? Because as per my battery hints, I managed to make my MacBook2,1 SHUT DOWN while at 74% of the “Writing files” phase of the combo update… resulting in a completely broken system, as every geek could imagine :). Apple updated some libraries, and upon reboot simply nothing worked, and the darwin console was filled with lots of error messages.

The standard apple fanb^Wuser would have simply archived and installed his system, but hey, I’m a proud geek! I know from experience that disaster recovery situations are the best ones to learn something about an operating system, because you have to help the system boot up, bringing services up by hand, and find some way to re-apply the combo update without using the easy Aqua interface.

📜

This post was written in 2008. It's preserved here for historical purposes — the technical details may no longer be accurate.

🔍
2026 retrospective
This advice is now the opposite of what Apple recommends. Modern lithium-ion batteries degrade faster from deep discharge cycles. Since macOS Catalina (2019), “Optimized Battery Charging” stops at 80% automatically. Apple recommends keeping your MacBook plugged in when possible and removed the “calibrate by full discharge” guidance around 2012.

3 simple rules:

  • DO NOT leave your charger connected when the battery is charged, even when you go to sleep.

  • DO let it discharge completely, when using it wait till it reaches 0%, when sleeping it leave it alone, when you’ll wake up and you’ll open it, a resume from suspend to disk will greet you. OSX FTW.

  • Monitor it and show off OSX performance counters to your friends (images courtesy of CoconutBattery.app and System Profiler.app)

Battery health Battery cycles

📜

This post was written in 2008. It's preserved here for historical purposes — the technical details may no longer be accurate.

🔍
2026 retrospective
Sun was acquired by Oracle in 2010 and Solaris is effectively abandoned since Oracle gutted the team in 2017. Python 2.4 and urllib2 are long gone — urllib2 was merged into urllib.request in Python 3.

While happily installing prerequisites to build an app on Solaris 11, i enjoyed having Mercurial already installed in the base system.. except for a BIG issue: digest authentication was broken. I tcpdump’ed the traffic exchanged between the mercurial client and the CGI server and I saw that no Authorization header was sent, and obviously the server refused to serve the hg repository.

Before reinstalling python, maybe from source and replacing the default installation or having side by side two different versions, with consequent nuisances and dirt around the system, I tried a very very small patch to urllib2.py that… amusingly enough, fixed my problem:

--- urllib2.py~ Fri Jan 25 02:35:59 2008
+++ urllib2.py  Fri Jan 25 03:27:52 2008
@@ -815,7 +815,7 @@
             auth_val = 'Digest %s' % auth
             if req.headers.get(self.auth_header, None) == auth_val:
                 return None
-            req.add_unredirected_header(self.auth_header, auth_val)
+            req.add_header(self.auth_header, auth_val)
             resp = self.parent.open(req)
             return resp

I’m no fscking python expert (but the language is interesting), so don’t ask me WHY it works, i simply followed the add_header comment that said “this method is useful for adding authentication headers” and replaced the unredirected_header method with the former. I really don’t know why with Python2.5’s urllib2 “everything works” even with that method, something must be broken somewhere else. A diff between the two urllibs gave me nothing, I really should learn Python one day or another.

Active Gibberish

📜

This post was written in 2008. It's preserved here for historical purposes — the technical details may no longer be accurate.

🔍
2026 retrospective
The Gibberish plugin and this entire approach are long dead. Rails 2.2 (2008) added built-in I18n support, and since Rails 3 the standard way is config/locales/*.yml with the i18n gem. ActiveRecord error messages, field names, and all UI strings are handled natively — no plugins, no monkey-patching.

UPDATE: you don’t need this code, because starting from the 2.2 version of Rails, localization support is built-in.

Localization for Active Record error messages

Today I had to answer one of the questions every non-English Rails developer stumbles upon sooner or later.. how to localize AR error messages for pleasant appearance to a non-english customer ;).

First off, thanks to defunkt’s excellent gibberish plugin and to the way AR validation errors are exposed, the task was accomplished in an easy and clean manner, without messing too much with AR’s internals.

I started by translating every default AR error message, with this translation file located in lang/it.yml:

# Active Record errors
#
ar_accepted:     "deve essere accettato" 
ar_not_a_number: "non è un numero" 
ar_blank:        "è un campo obbligatorio" 
ar_empty:        "è un campo obbligatorio" 
ar_inclusion:    "non è nella lista dei valori validi" 
ar_too_long:     "è troppo lungo (massimo %d caratteri)" 
ar_exclusion:    "è riservato" 
ar_too_short:    "è troppo corto (minimo %d caratteri)" 
ar_invalid:      "non è valido" 
ar_wrong_length: "è errato, dovrebbe essere di %d caratteri" 
ar_confirmation: "non corrisponde" 
ar_taken:        "esiste già" 
# This one is not a default key, but I use it in my validations
ar_greater_zero: "deve essere maggiore di zero" 

and four lines in config/environment.rb:

Gibberish.current_language = :it
ActiveRecord::Errors.default_error_messages =
  ActiveRecord::Errors.default_error_messages.inject({}) {|h, (key, string)|
    h.update(key => string["ar_#{key}".intern]) # <em>Gibberish magic</em>
}

The first one simply sets Italian (:it) as the default language, the inject builds a new error_messages hash using Gibberish to translate the default ones. I named every AR error key in my translation file with an “ar_” prefix, in order to avoid possible future key clashes. Finally, AR array is overwritten with the new one freshly built.

Extracting data from Apple Safari's cache

📜

This post was written in 2008. It's preserved here for historical purposes — the technical details may no longer be accurate.

🔍
2026 retrospective
Safari abandoned this SQLite cache format years ago. Since roughly Safari 10 / macOS Sierra (2016), the cache moved to com.apple.WebKit.Networking in a binary blob format — the old Cache.db no longer exists.

Five minutes ago, I overwrote the super-shining-new CSS stylesheet that implements the current color scheme, because i wanted to restore the original one and put it in a new theme for this site, so that people who enjoyed the old theme could continue to use it. But, as the most kiddie system administrator, i uncompressed the original files from the backup archive OVER the current ones..

Safari to the rescue! Every cached item by safari is stored into a SQlite3 database located in ~/Library/Caches/com.apple.Safari, let’s inspect how it is structured:

 13:54:42 vjt@voyager:~/Library/Caches/com.apple.Safari$ sqlite3 Cache.db 
SQLite version 3.5.1
Enter ".help" for instructions

sqlite> .tables
cfurl_cache_blob_data       cfurl_cache_schema_version
cfurl_cache_response      

sqlite> .schema cfurl_cache_response 
CREATE TABLE cfurl_cache_response(
  entry_ID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  version INTEGER,
  hash_value INTEGER,
  storage_policy INTEGER,
  request_key TEXT UNIQUE,
  time_stamp NOT NULL DEFAULT CURRENT_TIMESTAMP);

sqlite> .schema cfurl_cache_blob_data
CREATE TABLE cfurl_cache_blob_data(
  entry_ID INTEGER PRIMARY KEY,
  response_object BLOB,
  request_object BLOB,
  receiver_data BLOB,
  proto_props BLOB,
  user_info BLOB);

sqlite> select * from cfurl_cache_response limit 3;
1|0|1897220634|0|http://..../|2008-01-19 11:10:33
2|0|-662909776|0|http://..../|2008-01-19 11:10:33

Wow. Impressive. That’s why i love Apple products, because they are so well structured that you can freely inspect them and use them and their resources for every unplanned task you could have to complete.. even to fix your own mistakes ;). And it’s also intriguing, because you have to scratch your own itch and find the solution while exploring a beautifully constructed software product.

Today's row

05:01:24 vjt@voyager:~/Antani/trunk$ replace(){ sed -e "s|$1|$2|g" 
< $3 > ${3}X; mv ${3}X $3; }; egrep -r 'XP_[A-Z_]+[[:space:]]+-?[[
:digit:]]' Headers |ruby -ne "f,m=scan(/(.+):.+(XP_[\w_]+)/).first
;puts '%s %s %s' % [ f, m, 'kXP'<<m.scan(/(_[A-Z])([A-Z]+)/).map {
|a,b| a[1..1]<<b. downcase }.join ]" | while read hdr from to; do
replace $from $to $hdr; for src in `grep -rl $from Sources`; do
replace $from $to $src; done; done

On this page