Climate science is Nate Silver and U.S. politics is Karl Rove | Grist

Climate science is Nate Silver and U.S. politics is Karl Rove | Grist:
"Empiricism won. It didn’t win because it’s a truer faith or a superior ideology. It won because it works. It is the best way humans have figured out to set aside their prejudices, their perceptual limitations, their cognitive shortcomings, and get a clear view of what’s to come."
Let’s be clear about this.... There are serious scientists who doubt that human civilization can endure at all in the face of 7.2 degrees. And we are headed for 10.8.
…on the biggest, most pressing risk facing the country, those involved in U.S. politics might as well be witch doctors. Or worse, Karl Rove. It’s not a wise approach, because in the climate race, losses are permanent and irreversible. There will be no recount.

For more than 20 years I've been hearing that our response to climate change needs to take into account the health of the economy. OK. How healthy will our economy be when we can't keep factories cool, or grow enough food to keep its employees from starving?

iOS 6 and un-syncable Safari bookmarks

Shortly after iOS 6 was released I upgraded my iPhone. About the same time I set up iClouds backups of Safari bookmarks. Within days (hours? It's all a blur) I discovered that I could no longer sync Safari bookmarks via iTunes. Worse, I could no longer edit them on my iPhone.

The problem proved to be a corrupt schema in Mobile Safari's bookmarks database.

Here's the quick repair procedure. It does not require you to restore your phone to factory settings. (It should go without saying, but: do this at your own risk!)

  1. Buy iBackupBot — it will save a lot of hassle in editing your phone backups
  2. Export Library/Safari/Bookmarks.db
  3. Using sqlite3 /path/to/exported/Bookmarks.db, run the following commands on your exported bookmarks database to re-create missing tables and indices
    CREATE TABLE bookmark_title_words (id INTEGER PRIMARY KEY, bookmark_id INTEGER NOT NULL CONSTRAINT fk_bookmark_id REFERENCES bookmarks(id) ON DELETE CASCADE, word TEXT, word_index INTEGER);
    CREATE INDEX title_bookmark_id_index ON bookmark_title_words(bookmark_id);
    CREATE INDEX title_word_index ON bookmark_title_words(word);
    
  4. Re-import the modified Library/Safari/Bookmarks.db
  5. Use iTunes to "Restore from backup…"

Note that the last step should read "Use iBackupBot to restore the bookmarks file to your iPhone." I haven't yet tried doing that. I didn't even know iBackupBot could restore individual files until after my problem had been solved. Ah, ignorance :)

Also note that the exact set of required schema restoration commands may vary from one phone to another. These were the bits which were missing on my phone.

I learned a lot of interesting trivia while bumbling along toward this solution. Writer's block permitting, I'll try to summarize it in subsequent posts. Meanwhile, here are some links which helped me find a solution. Thanks to all for sharing!

Google Go: Interfaces, not Inheritance

This item showed up on today's "4 Short Links" by Nat Torkington, on O'Reilly Radar. I was struck by Nat's chosen excerpt:

What matters isn't the ancestor relations between things but what they can do for you. That, of course, is where interfaces come into Go. But they're part of a bigger picture, the true Go philosophy. If C++ and Java are about type hierarchies and the taxonomy of types, Go is about composition.

Setting Go aside for a moment, that first sentence captures one of Python's most useful traits: duck typing. Or, I don't care who your parents are. Can you do this job?

In any case, Rob Pike's post is thoughtful and well written, and its treatment of "programming in the large" makes me want to go play with Go.

command center: Less is exponentially more:

"

Less is exponentially more

[…]

I was asked a few weeks ago, "What was the biggest surprise you encountered rolling out Go?" I knew the answer instantly: Although we expected C++ programmers to see Go as an alternative, instead most Go programmers come from languages like Python and Ruby. Very few come from C++.

[…]

Python and Ruby programmers come to Go because they don't have to surrender much expressiveness, but gain performance and get to play with concurrency.

Placeholder text in UITextView

For a recent iPhone app I wanted a multi-line editable text field, in which I could display placeholder text so my user would know what to do with the field.

Placeholder text is a common affordance provided by several UI classes such as UITextField. But UITextView in iOS 4 does not support placeholder text.

A web search turned up several implementations. Some of these seemed too complex, and some failed to provide the behavior I wanted:

  • If the view is empty, show the placeholder.
  • Whenever the view is the first responder, hide the placeholder.

Here's my implementation. It's very basic. For example it doesn't let you customize the color of the placeholder text; and the placeholder is always centered vertically within the bounds of the text view. But it does provide the behaviors listed above.

PlaceholderTextView.h

#import <UIKit/UIKit.h>

@interface PlaceholderTextView : UITextView {
    UILabel *placeholderLabel;
    NSString *placeholderText;
}

@property (nonatomic, retain) NSString *placeholderText;
@end

PlaceholderTextView.m

#import "PlaceholderTextView.h"

@implementation PlaceholderTextView
@synthesize placeholderText;

- (void)hidePlaceholder {
    if ([placeholderLabel superview]) {
        [placeholderLabel removeFromSuperview];
    }
}

- (void)maybeShowPlaceholder {
    if ([placeholderText length] > 0) {
        if (![self hasText] && ![placeholderLabel superview]) {
            CGRect frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
            placeholderLabel.frame = frame;
            placeholderLabel.text = placeholderText;
            [self addSubview:placeholderLabel];
        }
    }
}

- (void)initCommon {
    if (!placeholderLabel) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beganEditing:) name:UITextViewTextDidBeginEditingNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endedEditing:) name:UITextViewTextDidEndEditingNotification object:nil];

        placeholderLabel = [[UILabel alloc] init];
        placeholderLabel.numberOfLines = 0;
        placeholderLabel.backgroundColor = [UIColor clearColor];
        placeholderLabel.textColor = [UIColor lightGrayColor];
        placeholderLabel.font = self.font;
        placeholderLabel.lineBreakMode = UILineBreakModeWordWrap;
        placeholderLabel.textAlignment = UITextAlignmentCenter;
        [self maybeShowPlaceholder];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self initCommon];
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initCommon];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initCommon];
    }
    return self;
}

- (id)init {
    self = [super init];
    if (self) {
        [self initCommon];
    }
    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [placeholderLabel release];
    [placeholderText release];
    [super dealloc];
}

- (void)setPlaceholderText:(NSString *)newValue {
    [newValue retain];
    NSString *oldValue = placeholderText;
    placeholderText = newValue;
    [oldValue release];

    [self maybeShowPlaceholder];
}

- (void)beganEditing:(NSNotification *)notification {
    [self hidePlaceholder];
}

- (void)endedEditing:(NSNotification *)notification {
    [self maybeShowPlaceholder];
}
@end

Adding images to the iPhone Simulator

Occasionally I need to create an iPhone app which can either take a picture or select one from the user's library. Testing such an app on the iPhone simulator is a pain; the simulator doesn't include a simulated camera, and it doesn't provide a way to sync photos from iTunes.

I keep forgetting how to load images into the simulator's photo library. Here's a method that works well, courtesy of Stack Overflow:

  • Launch the iPhone Simulator.
  • In the simulator, launch Safari.
  • Drag an image from the Finder into the simulator. It should appear in Safari.
  • Click and hold the mouse on the image.
  • An action sheet should appear. Choose 'Save Image'.

To confirm that the image got added you can launch Photos in the simulator. The image should appear in your Saved Photos album.

Mercurial - Abort: path 'foo/' is inside repo 'foo'

A trailing slash can be hard to see.

This morning I tried to commit to a Mercurial repository which contained sub-repositories. One of those subrepos had been added a few days earlier, along with the corresponding .hgsub entry. .hgsub had been committed explicitly, without incident.

$ vi .hgsub
  # add entry for src/baz/foo
$ hg ci -m "Some comment." .hgsub
$

Today, for the first time since adding the subrepo, I tried an hg commit at the top-level of my repository. Mercurial responded with an error message:

$ hg ci -m "Blah."
abort: path 'src/baz/foo/' is inside repo 'src/baz/foo'

Say what?

It took a few minutes of quiet contemplation before I finally saw the problem:

abort: path 'src/baz/foo/' is inside repo 'src/baz/foo'

Once the extraneous slash was removed from .hgsub, everything was fine.

Good on you, Apple

From Engadget:

"In particular, we are relaxing all restrictions on the development tools used to create iOS apps, as long as the resulting apps do not download any code. This should give developers the flexibility they want, while preserving the security we need.
"In addition, for the first time we are publishing the App Store Review Guidelines to help developers understand how we review submitted apps. We hope it will make us more transparent and help our developers create even more successful apps for the App Store."

Hover on Multi-touch Devices

I try to keep this blog focused on software development: design, bug fixes, etc. That's why the following post originally appeared elsewhere.

It appears here, now, because it's loosely connected to software development and because — well, it's interesting (to me). I've been seeing so many references to the idea of proximity-based user interfaces, it seems likely that "hover-free Mobile Safari" will become a historical anomaly.


Original Post (2010/06/23)

Technical Note TN2262: Preparing Your Web Content for iPad:
"For example, a mouse pointer can hover over a webpage element and trigger an event; a finger on a Multi-Touch screen cannot."
This is certainly true for multi-touch devices available now, but I wouldn't be surprised to see, someday, touch-sensitive devices which are also proximity-sensitive. Update 2010/07/08: Others are thinking about implications of hover on multi-touch devices: http://trentwalton.com/2010/07/05/non-hover/ via http://news.ycombinator.com/item?id=1497108

I'm not a Star Trek fan, but a recent Ars Technica article, exploring the similarities between the iPad and ST:TNG's PADD, caught my eye. It provides several good examples of how science fiction guides technology development. This excerpt seems particularly relevant:

"Still, what new frontiers are out there for interacting with computing devices? Michael Okuda believes that removing the touch requirement will bring new advances in gesture-based control. "Once you don't have to physically touch the screen," he told Ars, "I think yet another window is going to open up.""

Update 2011/01/27

AppleInsider reports on Apple's recent hover-related patent work.