Dating Advice

If you’re a woman interested in persuading a man that you’re wife material, it might be best to avoid mentioning that you’ve read (or, worse, liked) “Eat Pray Love“. The whole celebration-of-the-breaking-of-commitments thing probably isn’t the message you want to send.

(Naturally, this post is ironic.)

P.S.: If you want to read a much more interesting book on the same general template — the author talks a publisher out of a biggish advance and spends it having fun — then I recommend Andres Martinez’s 24/7: Living It Up and Doubling Down in the New Las Vegas.

Posted in Jack Handy | Comments Off

Foreign Expressions

The Chinese (near?) equivalent to “casting pearls before swine” is “playing music to the cows”. I think it’s cute.

Posted in Jack Handy | Comments Off

Six Word Stories: Merry Christmas

We wish you a Merry Christmas.

Posted in Six Word Stories | Comments Off

NSURL, Trailing Slashes, and OAuth

Here’s a surprisingly important note from the documentation for the NSURL class’ path method:

Return Value

The path of the URL, unescaped with the stringByReplacingPercentEscapesUsingEncoding: method. If the receiver does not conform to RFC 1808, returns nil. If this URL is a file URL (as determined with isFileURL), the return value is suitable for input into methods of NSFileManager or NSPathUtilities. If the path has a trailing slash it is stripped.

Trailing Slashes

Trailing slashes in URLs are sort of funny things; whether URLs should include them or not is a matter of some debate, determined in practice by the conventions of the framework used to implement the server at the endpoint of the URL. For instance, Django strongly suggests (although it doesn’t really require, due to all those regexes) that all your URLs end with trailing slashes.

Example

Let’s say you’re dealing with URLs that include trailing slashes. And let’s say you use NSURLs to reach them, with something like this:

// Set up request ...
NSURL* url = [NSURL URLWithString:@"http://www.example.com/foo/bar/baz/"]
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url
						       cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
						   timeoutInterval:30];
request.HTTPMethod = @"POST";
	
// Set up delegate
MyNSURLConnectionDelegate* delegate = … set up an appropriate object …
	
// Create and start request
NSURLConnection* conn = [[[NSURLConnection alloc] initWithRequest:request
							 delegate:delegate] autorelease];
[conn start];

This will produce an HTTP request on the wire that looks something like this:

POST /foo/bar/baz/ HTTP/1.1
Host: www.example.com

On the other hand, url.path will return /foo/bar/baz. The path returned by url.path is not the same as the path sent over the wire.

Signing

“So what?”, you might ask. Well, the less-important point here is that /foo/bar/baz and /foo/bar/baz/ are not the same thing, and don’t (in principle) refer to the same object. (In practice, they’re often hacked to be synonyms on the server-side, but that’s not an assumption that a client should really be making.) The more important point is that if you’re signing your request (with, e.g., OAuth), then you need to know the exact path sent over the wire.

The slash-stripping behavior of path hides the precise path sent over the wire. If you’re handed an NSMutableURLRequest and asked to sign it (by, e.g., appending an OAuth authorization header) you can’t use the path method to construct the signature without some other information that specifies whether or not the path on the wire ends with a slash.

FWIW, absoluteString does not strip trailing slashes. This is helpful, but complicated by the fact that other parts of the URL (e.g., the query string) follow the path; a trailing slash won’t necessarily be the last character in a URL’s absoluteString.

This is all a little inconvenient.

Posted in iPhone, Python, Web stuff | Comments Off

Pacquiao/Mosley

Well, Pacquiao vs. Mosley is scheduled for 7 May.

When I first thought about this fight (after Mayweather/Mosley), I thought it would be an easy win for Mosley; even after he was out-boxed by Mayweather, I figured that Mosley was too big, too strong, and too fast for Pacquiao. Since then, however, Pacquiao has looked good against Margarito, and Mosley has looked bad against Mora.

As a result, I now have to lean towards Pacquiao on this one. I still think Mosley has an excellent chance: Remember that Mosley KO’d Margarito, and that Pacquiao didn’t. Furthermore, Pacquiao isn’t the physical type (tall, rangy) or style of fighter (slick boxer) that’s given Mosley fits in the past. In the end, though, since Mosley hasn’t looked good since the 2nd round against Mayweather, he has to be the underdog here.

I’d like to see Mosley win this one. (And then retire!) I’m also glad, on a personal level, that the fight got made. Boxing is a tough way to make a living, and a fighter’s lifetime earnings are heavily influenced by his ability to land a few key fights like this one. Mosley was a great fighter at LW, and so I’m happy to see him able to trade on his name for (another) good payday. I just hope he doesn’t get hurt or embarrassed earning it.

Posted in Boxing | Comments Off

Happy Things

The blog’s been getting a little grumpy lately, so, today, just a list of a few things and people that I like:

and, as I’ve mentioned before:

Posted in Jack Handy | Comments Off

Six Word Stories: Oklahoma!

Oklahoma! did surprisingly well in Yemen.

Posted in Six Word Stories | Comments Off

Discussion

Today I was reminded that there are two ways to use one’s intelligence during a discussion: One can try to ascertain the truth, or one can try to win the argument. People who routinely engage in the latter are boring, people who confuse the two are foolish.

Editorial note: Surprisingly, this is not related to yesterday’s post.

Posted in Jack Handy | Comments Off

Atheists

The least charming aspect of atheism is the smug certainty of many of its adherents that their particular belief system[1] is indicative of, or due to, superior intelligence.

It’s a general human tendency to pat oneself on the back for cunning and perspicacity, but most people in most circumstances seem to have the good sense to realize how unbecoming this looks, and to tone it down a bit. Atheists seem to belong to one of the few groups that positively champion this sort of obnoxious preening.

Which is ironic, because atheism is probably the least intellectually demanding of all metaphysical cosmologies.

[1] Yes, it’s a belief system. You don’t know, you merely suspect.

Posted in Jack Handy | Comments Off

Six Word Stories: Rationalization

Increasingly fragile rationalizations covered growing disappointments.

Posted in Six Word Stories | Comments Off