Archive for July, 2008

Firefox 3 javascript evaluating order problems

Thursday, July 31st, 2008

I found out the hard way the recently released third main version of Firefox has a serious issue related to the order in which the Javascript code is executed in a page. The bug is somehow related to the files being, or not, cached on the browser.

Wonder Ajax framework adds a lot of Ajax goodies to a standard WebObjects applications. The way a page is built is by placing on the page header all the calls to load Javascript files. There’s a special case, which is when you need a JSON proxy. That is useful if you need to write more powerful Ajax behaviour than all the component trickery Wonder offers you. The JSON proxy will not only load the necessary Javascript file, but run one code line to create the actual proxy and establish the communication with the server. So the page header will have something that looks more or less like this:

<script src="/some/path/prototype.js"></script>
<script src="/some/path/effects.js"></script>
<script src="/some/path/wonder.js"></script>
<script src="/some/path/english.js"></script>
<script src="/some/path/combo.js"></script>
<script src="/some/path/feedback.js"></script>
<script src="/some/path/jsonrpc.js"></script>
<script type="text/javascript">
var jason = new JSONRpcClient("proxyUrl");
</script>
<script src="/some/path/comboboxes.js"></script>
...

When the page loads, all those scripts will be loaded and the new JSONRpcClient() method will be executed during the page load, as expected.

The problem starts when you have a javascript method associated with the onLoad window event. This is done by using the onload attribute in the body element:

<body onLoad="initPage();">

The onLoad function should be triggered when the page finishes loading. This, implicitly, means that the onLoad will be run only after all the inline javascript code (in the page header or body) be run, because that is still considered to be part of the page loading process. So, in our case, first, load all the JS and create the JSON proxy, and then run the onLoad method.

This works on every browser, and also on Firefox 3 on the first page load. The problem is that most of the subsequent page loads on Firefox 3 won’t work, at least if your onLoad method depends on the existence of the JSON proxy. For some reason, when Firefox 3 has all the Javascript files already in the local cache, the onLoad event is triggered too soon, namely before the header scripts are executed and the proxy has been created. This will break all your code executed by the onLoad method that assumes the proxy is already ready to work.

I have tried several solutions for this. The only one I had success with is the following. It’s kind of dirty, but it works. The idea is simple: if the onLoad method is to be executed before the proxy exists, than we wait some miliseconds and try again later until the proxy is ready to be used. So, if your method is like this:

function myOnloadMethod() {
  runInitStuff();
}

Change it to:

function myOnloadMethod() {
  if( window.jason ) {
    runInitStuff();
  } else {
    setTimeout( 'myOnloadMethod();', 10 );
  }
}

This will check every 10 milliseconds if the proxy is already there. If it is, your method will be run. If not, it will keep trying.

MacBook Pro 17 vertical blue line

Thursday, July 24th, 2008

I’m really pissed off. Short story: MacBook Pro 17, HD display, bought this February. Blue line appeared today. I still remember when Apple hardware would work for more than six months.

iPhone: why I don’t care

Sunday, July 13th, 2008

So, this has been the iPhone week. It started right on monday, with Vodafone and Optimus, the two portuguese carriers that sell the iPhone, announcing their pretty ridiculous price plans. Then, the iPhone was launched, together with the App Store and a barely functional activation site. And I couldn’t care less. Why? Many reasons, some of them are Apple’s fault, some of them are consequences of the wildly spread stupidity that exists in my country. If you are one the 4 regular readers of my blog, you know that most of my articles are techie-focused, and not opinion-based. This one is an exception.

The iPhone itself

So, what’s wrong with the iPhone? What should have been made much better in the most popular gadget of the week? A lot.

First, the phone itself. I never had a smartphone. I don’t know how does the phone part operate in a smartphone. But I know how it works on a regular phone, say, a Nokia phone. And, pick up any Nokia and it will tear the iPhone apart in what relates to be a phone, you know, something to make calls with. My first complain is something really obvious: it’s hard or impossible to use the iPhone with just one hand. Of course it depends on how large your hand is, and how much are you willing to risk dropping the iPhone on a hard ground in the middle of a street (that glass keeps shouting “break me!”). But personally, I find it a challenge, specially if I’m walking in a hurry in the middle of the street carrying stuff in one hand, which seems to be the preferred time for people to call me. I never tried to operate one while driving but it should be a real pain (I know it’s illegal to make calls while driving without a loudspeaker, I just receive or start the call and turn on my Nokia’s built-in loudspeaker, so it’s not that bad). On top of this, you have to do all that scrolling-trough-the-alfabet, and then scrolling-trough-the-names-on-the-selected-letter, and finally call the person. That sucks, because not only it’s slow, but it also requires you to actually look to what you are doing and wait for the visual feedback. On a normal phone, with a numeric keypad, if I want to call John, I press the 5 key (jkl) once and I’m already on the J. If I want to call Fred, I press the 3 key (def) three times. No feedback needed, I know where I’ll end up. I just then need to scroll (with a key, thank god!) and push the green button. You are free to disagree, but I think Nokia is so much better.

Second, the keyboard. Yuck. It’s true that I never set it to portuguese, but even when I try to write in english, it SUCKS. Man, it sucks big time. I rarely can get the word I actually want. The phone suggest wrong things. It’s hard to understand how to NOT accept the suggestion. I actually think that removing all the “intelligent” guess-what-the-user-is-trying-to-write stuff would actually improve the usage a lot, because most of the times I screwed up writing on an iPhone keyboard was actually not because I placed my finger on the wrong “key”, but because iPhone decided that I pressed a key that I actually didn’t. And of course, not having the physical feedback of a real keyboard is also bad, but I can understand that as a compromise between size and functionality.

Third, Safari. I do believe iPhone’s Safari is the best web browsing experience in the mobile market, I really do. But it sucks. It’s painfully slow. And I don’t mean the network. I mean the CPU of that thing. Even with a high-speed WiFi network, it’s slow. Rendering is slow. Panning is slow (hate that checkerboard pattern). Zooming is slow. Argh. I don’t know exactly how to make this better, but having a faster CPU would be a nice start. Yes yes, I know that faster CPU = less battery time, but as a client, I can demand! :)

Fourth, the GPS. Are you kidding?! What’s the use of a GPS if it doesn’t support turn-by-turn mode? I usually know where I am, thank you. My problem is knowing how to get to where I want while driving. If the iPhone GPS can’t do it, it’s useless. It’s worth zero for me. Now is the part you say, hey, but iPhone is an open platform, so someone will develop a better GPS software, right? Who cares. First, it won’t be free. I don’t understand why I’m buying a device with a GPS receiver and then I have to pay more for something that will actually make it work as expected. And second, and worse, it probably will not happen. Why? Because on the iPhone development SDK agreement, there’s a clause that explicitly forbiddens you from doing it: “Applications may not be designed or marketed for real time route guidance”. Period. (Waiting to be processed by Apple for copying that sentence from the SDK)

Fifth, it doesn’t work as a modem/router for a laptop. I need mobile internet access in my laptop. That comes with a monthly payment. But hey, if I have an iPhone, that means TWO monthly payments for the same service. Now wait a minute. I said “same service”! So why can’t I share it? Well… because the iPhone won’t do it. Any other phone can be used as a modem, via bluetooth, so that you can access the Internet from your laptop using the phone connection. Nokia. Sony. You name it. But hey, not Apple. So, as I don’t like to give away my money to the phone carriers for a stupid reason, iPhone is a no-go.

Sixth, the bluetooth implementation is totally crippled. It will only power your headset, and nothing else. No vCard sharing via bluetooth with nearby phones. And worse, no synching with your mac via any wireless means. Yes, that’s right. Remember using iSync with your Nokia or Sony or whatever phone? Forget it with the iphone. You have to carry the USB cable with you all the time. Which is actually a good thing, because battery life time seems to be not that great, so you’ll often need to pump in some juice to keep it going.

So, the iPhone, as a device, sucks. But it’s a good mobile platform, and platform means really great third party software to use. Or doesn’t it?

The app store

It’s 1984. Apple will introduce Macintosh. And what better way to do it than with the famous 1984 commercial, where IBM is pictured as the evil Big Brother and Apple as the liberating force that will provide everyone with their deserved freedom from the evil empire?

It’s 2008. Reality check. Apple is the Big Brother.

The app store seems to be a great ideia. An organized, controlled, easy to use place for users to go and buy the apps they want to use. But what does it mean for the developers?

Big Brother is what it means. Apple reserves the right to accept, or not, your application to be on selling on the App Store. Also, it imposes some very strict guidelines on what you can actually do, like the GPS example I stated above, and also VoIP and other stuff. Even worse, the App Store is the only way to publicly distribute applications for the iPhone, assuming you didn’t jailbreak it, and most people didn’t. So, Apple has the power to decide that you are out of business if they decide so. The only way to reach your customers is trough Apple.

In my opinion, this is not only ridiculous, but also a very dangerous precedent. If I buy an iPhone, it’s mine. I should be able to do whatever I want with it. And if I’m a developer, I should be able to reach my clients directly. It’s very dangerous to have someone saying what is OK to run on your phone and what’s not. Some claim it’s a security issue. After all, you don’t want your software to call people on foreign countries without your knowledge, because those calls will be billed on you. Bah. What about computers? Don’t we have really important information on them? Information that can compromise much more than just your phone bill? Why don’t we create a desktop App Store, to control everything you have on your Mac? It’s simply ridiculous. And what pisses me off about this is watching developers and users accepting this without a single complaint. What’s next? All the books you buy must be approved? All the movies you see must be “decent”? All the music you hear must be controlled? It’s ridiculous. And dangerous. It’s Apple totally forgetting about 1984, totally forgetting about it’s roots, and going totally Big Brother, totally enterprise-who-wants-to-make-money-no-matter-what. As someone who entered the Apple world in 1987, with the Mac PLUS, it’s really, really sad to see this.

The plans and the hype

This next subject depends, of course, where you are. I live in Portugal, and as I said, we have ridiculous data plans for the iPhone. Vodafone’s plans were all limited to 250 MB per month, and of course, they will charge the hell out of you for every extra bit. After some complaints, they bumped the limit on the most (and ridiculously) expensive plan to… 500 MB. Optimus’ plans are not better. It’s sad to compare this to other countries like Netherlands, where all the plans include unlimited data, and, depending on the plans, you can get your phone for 1 euro. The problem is that the carriers didn’t really understand what this product is about (or they pretend to not understand while they happily rip you off). The iPhone is a mobile platform. It depends on the Internet for most of it’s features. The fact that the iPhone is a phone, and allows you to make calls, is a minor detail. The iPhone depends on the Internet, so it’s ridiculous to sell data plans as if it would be just another phone with internet access. It’s a completely different product, and should be looked to by the carriers as what it is. Unfortunately, portuguese carriers didn’t go along with this vision, and are happily raping their clients.

To conclude, something that makes me really pissed off and sad is all the hype, and the way the iPhone was promoted here. In San Francisco, lines were formed near the stores, and you could see geeks, with their eyes shinning about the new stuff they would be able to do with this new platform. Here, lines and launch parties were constituted mostly by VIPs. Most didn’t even know what the iPhone was, they just wanted one because they have money and it’s cool to have the latest Apple gadget. Carriers wanted those people to be there because they are famous. Because, even being incredibly stupid and ignorant, they have big (sometimes artificial) half-naked boobs they show to the TV cameras resulting in more attention in the news reports. Because they think they are funny comedians, making jokes about knowing nothing about technology, being proud of their ignorance. It’s sad to see a new piece of technology being used as a glamour toy, a coolness factor, and not as a new device that will allow new and incredible stuff to be made. Oh well. It’s Portugal.

Upgrading Mac OS X Leopard Server

Friday, July 11th, 2008

I was expecting that. Fortunately, I was ready for it. So, I’ll describe some details of upgrading Leopard Server from 10.5.2 to 10.5.4 to avoid you the same trouble.

If you read my previous article about Leopard Server, you know that I had to recompile MySQL, PHP and Apache to PowerPC 32 bits, because I could not use the 64 bits version on our G5 server. The story was a bit complicated, but the idea was that I needed PostgreSQL and MySQL support on PHP. As the MySQL default installation on OS X Server doesn’t include the shared libraries, I had to recompile MySQL to be able to recompile PHP. But I could not make MySQL compile for 64 bits, so I compiled everything (including Apache) to 32 bits.

So, I was expecting it: as soon as I would upgrade my server, the installers would replace Apache with a more recent version, and it would not start because PHP and MySQL stuff was compiled for 32 bits. And it happened.

How to fix it? Simple. You have to do two things: first, remove the PowerPC 64 part from the httpd binary. Second, recompile your customized version of PHP, because PHP gets replaced too.

To remove the PowerPC 64 part of the binary, you don’t need to recompile Apache as I did before. There are two very useful commands you can use: file and lipo. If you do the following commands:


cd /usr/sbin
file httpd

The result will be:


httpd: Mach-O universal binary with 4 architectures
httpd (for architecture ppc7400): Mach-O executable ppc
httpd (for architecture ppc64): Mach-O 64-bit executable ppc64
httpd (for architecture i386): Mach-O executable i386
httpd (for architecture x86_64): Mach-O 64-bit executable x86_64

As you can see, Apple ships httpd compiled for their four possible architectures. In my case, I want to remove the ppc64 one to force httpd being executed in 32 bits. That’s where lipo comes in hand:


lipo -remove ppc64 -output httpd32 httpd
mv httpd httpd64
mv httpd32 httpd

That’s it. The ppc64 part of the binary has been removed, and a new binary was created. I then just switch the binaries, and there you go, Apache running on 32 bits mode on PowerPC:


httpd32: Mach-O universal binary with 3 architectures
httpd32 (for architecture ppc7400): Mach-O executable ppc
httpd32 (for architecture i386): Mach-O executable i386
httpd32 (for architecture x86_64): Mach-O 64-bit executable x86_64

Then I just needed to recompile PHP and everything was back on track.

Also, be careful because the 10.5.4 update will upgrade WebObjects to 5.4.2. If you are still using WO 5.3 like me, you’ll have to reinstall 5.3 again, as described in the Mike’s document.

iPhone mania

Thursday, July 10th, 2008

iPhone iPhone iPhone iPhone. iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone!

iPhone iPhone iPhone iPhone… iPhone iPhone iPhone iPhone. iPhone? iPhone iPhone iPhone iPhone iPhone iPhone. iPhone iPhone iPhone iPhone iPhone iPhone! iPhone iPhone iPhone iPhone :) iPhone iPhone.

iPhone iPhone iPhone. iPhone iPhone iPhone iPhone iPhone! iPhone iPhone? iPhone iPhone iPhone? iPhone? iPhone!

iPhone iPhone iPhone iPhone iPhone. iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone. iPhone. iPhone iPhone iPhone.

iPhone.