Nate Silva

Jun 02 2008

How to tell if a Mac OS X application is “Cocoa” or “Carbon”

There are two ways that software developers can create Macintosh applications — known as Carbon and Cocoa. As has been said many times before, it doesn’t really matter to users if an application is Carbon or Cocoa, although developers do tend to prefer one or the other when writing applications.

A quick way to identify Carbon and Cocoa applications is to drag them to the bottom of the screen.

  • Carbon applications will not let you drag their title bar off the bottom edge of the screen.
  • Cocoa applications will let you drag the title bar partially off the bottom of the screen, but as soon as you let go of the mouse, it will bounce back into view.

This isn’t always accurate, as some well-known Carbon applications (the Finder) have Cocoa-like behavior.

And since it’s possible for Cocoa applications to call Carbon and vice-versa, you might say that many apps are not entirely Cocoa or Carbon, but a mix of the two.

May 20 2008

Python PostgreSQL interfaces: pg8000 vs. psycopg2 micro-benchmark

I have great hopes for the pg8000 project, which is a PostgreSQL interface written entirely in Python.

The current standard in this category is something called psycopg2. It depends on libpq (the official PostgreSQL client library). While it works great, it can be difficult to get it running on some platforms (ahem, OS X), because you need to download all of PostgreSQL to get the client library. You can install just libpq if you can suss out the correct build parameters, but it’s still quite a hassle when deploying software on random client machines.

What pg8000 offers is no dependencies. I can do database stuff without having the client install anything other than Python itself.

But this comes at a cost; namely: it’s very slow.

I used one of our build scripts that records metadata from a directory tree into a PostgreSQL database. The directory tree contains more than 3,000 files. The script reads some data from each file, as well as its last modification time. For each file, it then executes two statements: one SELECT to validate the data, and one INSERT to plunk it into the database. A single commit() is executed at the very end of the whole process.

Using psycopg2 gave the following results:

Processing complete. 3230 files total.

real    0m28.654s
user    0m4.419s
sys 0m6.582s

With pg8000 I got the following results:

Processing complete. 3230 files total.

real    7m53.424s
user    0m13.516s
sys 0m8.267s

So, for this test, pg8000 took 16 times as long to complete.

I haven’t figured out why it’s so much slower. Perhaps pg8000 is opening transactions for each statement instead of using a single transaction. Or maybe an all-Python database interface is just destined to be slow.

For everyday use (i.e., you’re not executing thousands of consecutive statements at once) you probably won’t notice much difference using pg8000. As always, you need to profile to find out where the bottleneck is. If your application only needs to do a few statements per minute then the speed of your database interface probably isn’t a constraint.

May 05 2008

When downloading an .EXE file in IE, it loses its file extension

Internet Explorer has odd behavior when downloading certain files. If you have an .exe file, but it’s served by a URL with a query string, IE will lose the file extension.

An example might be easier to understand.

Let’s say you’re using Amazon S3 to serve your downloads. You’ve got a file, myfile.exe, that your customer wants to download. Using S3 you generate a URL that allows them to download the file, and you can set the URL to expire after a certain time. The resulting URL might look like this:

https://nate.s3.amazonaws.com:443/myfile.exe?Expires=1210007779&AWSAccessKeyId=1HHMQMPRV9GFWH6BTP82 &Signature=5dfcG5OC9BSkDFSzjxQGjlbKNi0%3D

Notice that the URL contains /myfile.exe followed by some query string parameters (everything after the question mark is the query string parameters).

Most web browsers will interpret this as being a request for the file myfile.exe.

Internet Explorer will interpret this as being a request for a web page served by an application on the server called myfile.exe. The resulting download will be called myfile (instead of myfile.exe), which doesn’t work.

There’s a workaround, which is to add the filename to the end of the query string, like this:

https://nate.s3.amazonaws.com:443/myfile.exe?Expires=1210007779&AWSAccessKeyId=1HHMQMPRV9GFWH6BTP82 &Signature=5dfcG5OC9BSkDFSzjxQGjlbKNi0%3D&filename=myfile.exe

There’s no reason in the HTTP standard why this should be required; it’s just a way that Microsoft developed to work around the bug in IE.

More information, including Microsoft’s creative interpretation of the HTTP standard, can be found in Knowledge Base Article 221805. The article says the bug is fixed, except not for .exe and .dll files! This is another case of inconsistent behavior in IE.

Feb 20 2008

How to get some HP network printers to work with Mac OS X Leopard

Some HP network printers — such as the HP Color LaserJet 3600n and 3600dn — don’t have what Apple calls “modern” printer drivers. As a result, you may not be able to print over the network. This will happen if both of the following things are true:

  • The printer doesn’t have a modern driver.
  • You are not using Bonjour to print; for example, if you are on a different network subnet than the printer.

The correct driver won’t even be available in the driver list. Apple has a list of supported printers; an X in the right-hand column indicates modern drivers.

The good news is that there’s a solution. For this to work the printer must have built-in networking and it must be an HP printer (Canon and Epson owners see my note below).

  1. In System Preferences, open the Print & Fax Preference Pane.
  2. Click the plus sign to add a printer.
  3. In the dialog that appears, click the “More Printers” icon at the top.
  4. In the More Printers dialog, choose “HP IP Printing” from the drop-down list.
    • If your printer is on the same subnet as your Mac, you should see it listed. Select it and click Add.
    • If you don’t see it listed, click the “Manual” tab and enter the printer’s IP address, click “Connect”, then “Add”.

That’s it. Most of the time the printer model will be automatically detected and you won’t even have to select a driver.

Note for Epson and Canon owners

The steps above are for HP printers only. But the “More Printers” dialog also offers options for “Canon IJ Network” and “Epson TCP/IP” printing. I have no way to test these, but if your printer has built-in networking choosing one of these may work for you.

Feb 15 2008

Engineers and early adopters vs. the customers

“We thought it was a mistake and made our engineers check the logs again,” said Vic Gundotra, head of Google’s mobile operations.

Google receives 50 times as many searches from iPhone users than from any other mobile handset. It’s the very definition of usability: how many people actually use their phones to browse the web. Apparently only iPhone users.

Products that are popular with engineers and early adopters—the previous generations of smartphones, loaded with features—aren’t necessarily what customers want. They want usability. It looks like Apple has figured that out.

Jan 25 2008

Time Machine only runs if your MacBook is plugged in

Time Machine is a great feature of Apple’s computers. It backs up your Mac every hour, as long as you have a backup disk connected to the USB or Firewire port. Because it only needs to back up whatever changed in the last hour, it only takes a few seconds to do.

But on my wife’s MacBook it was not doing automatic backups:

The “Next Backup” field just contains two dashes.

The solution was easy: plug in the computer.

It turns out that Time Machine doesn’t run automatically when your notebook computer is not plugged in. It does this to preserve battery life. As soon as you plug it in, the “Next Backup” time shows up and automatic backups will continue.

Nov 07 2007

Notes on using Cocoa-Python in Mac OS X Leopard

I’ve been looking at Leopard’s amazing new Cocoa-Python support. It uses PyObjC 2.0 to give Python programmers access to the Cocoa frameworks that Mac OS X is built on.

Working from the Apple tutorial, which is based on an older version of PyObjC, I was able to build a working application. But I hit a few roadbumps and those are what I want to document here for other would-be Cocoa-Python programmers.

The first problem was figuring out how to instantiate my Averager object in Interface Builder. I found the solution on the macosxhints Forums:

  1. Drag an instance of NSObject from the Library into your xib file.
  2. Click on the new instance of NSObject and bring up the Identity Inspector (⌘-6 or find it in the Tools menu).
  3. Set the object’s class name to your class name, which is Averager if you’re following the Apple tutorial.

The second problem was this error:

This class is not key value coding-compliant for the key calculatedMedian

This was caused by not importing the Averager class. To fix it, add the following to your main.py file:

from Averager import *

Some tips:

  • The debugger console window (Shift-⌘-R) is your friend.
  • Beware of Xcode’s tab handling. You can force it to use spaces under Preferences > Indentation.
  • If you are doing the tutorial and you get “ValueError: invalid literal for float()”, it’s because you’ve passed something that doesn’t look like a number — most likely a comma. Python’s split method only recognizes lists separated by spaces. In the debugger console you can see what exception is raised. You can of course catch the exception and handle it in your Python code.

Oct 30 2007

How to make readline support work in IPython on Mac OS X Leopard

Many Python programmers use the IPython shell for interactively testing their code.

But if you recently upgraded to Mac OS X Leopard then you may have noticed that a key feature — tab-completion — doesn’t work.

It doesn’t work because IPython uses the GNU Readline library, and Mac OS X doesn’t include that. Instead, OS X ships with a similar library called Editline.

You can make IPython work with EditLine by adding the following lines near the top of your ~/.ipython/ipy_user_conf.py file:

import readline 
readline.parse_and_bind ("bind ^I rl_complete")

Note: You must be using a recent version of IPython. You can install the latest version by typing sudo easy_install ipython from the OS X command-line.

(Found in this message thread on the Pythonmac-SIG mailing list)

Oct 21 2007

How to fix an SSL certificate error in Exchange System Manager

For the longest time I’ve had this error in Exchange System Manager when managing public folders:

The SSL certificate server name is incorrect.
ID no: c103b404
Exchange System Manager

This can happen when using Outlook Web Access if your webmail URL doesn’t match the server’s internal name. Exchange System Manager expects your SSL certificate to match the server’s internal name. OWA users — including Windows Mobile devices — expect the certificate to match the server’s public URL.

One solution is to manually change the SSL certificate every time you need to manage a public folder, then change it back when you’re done. That gets old quickly.

Another solution, suggested in a knowledge base article, is to turn off SSL for the IIS Exadmin virtual root. This didn’t work: SSL was turned off for Exadmin but the problem remained.

Here’s an alternate solution that works:

  1. Run adsiedit.msc.
  2. Navigate to: CN=Configuration > CN=Configuration,DC=YOURSITE > CN=Services > CN=Microsoft Exchange > CN=YOURDOMAIN > CN=Administrative Groups > CN=first administrative group > CN=Servers > CN=YOURSERVER > CN=Protocols > CN=HTTP > CN=1 > CN=Exadmin.
  3. Right-click on CN=Exadmin and choose Properties.
  4. Find the attribute called msExchSecureBindings and click Edit.
  5. Remove the value :443: from the list.
  6. Click OK twice to close the dialog boxes.

(Found on Jim McBee’s Mostly Exchange Web Log)

Oct 08 2007

How to make Safari work behind a SonicWALL firewall

Do you have a Mac behind a SonicWALL firewall? Do you find that some URLs (like certain pages at the New York Times) won’t load in Safari, but they work in Firefox? Is the problem worse when you’re behind a secondary router, such as a wireless router?

If so, Edward Marczak of Tech Zendo has the solution for you.

The basic solution is to access the SonicWALL’s hidden diagnostics page at http://your.ip.address/diag.html and turn off the checkbox that says “Enforce Host Tag Search for CFS”.

It turns out the SonicWALL drops some web connections where the HTTP request headers are split across multiple packets. It does this to make it harder to bypass content filtering, but it can cause Safari’s legitimate traffic to be dropped.

Thanks Edward!

Followup: 2007-10-10

This support document from SonicWALL explains the problem in more detail. WebKit (Safari) is waiting for a TCP ACK before sending out the next packet; apparently it is not supposed to do that.

Technorati Tags: , , ,

Page 2 of 3 Newer entries →