Category Archives: Uncategorized

Sanitizing Strings with NSCharacterSet and NSScanner

Funny how, after all these years, I hadn’t needed to clean a string of an arbitrary set of unwanted characters on a large scale, but I am doing a ton more XML work these days, so it was bound to happen. I don’t remember where I stumbled upon the idea to use NSScanner, but once I saw it, it made perfect sense. I think there’s some excess baggage between the buffer string and the fact that the string is scanned anywhere between O(n)O(n2) (if not worse, actually). But, this is certainly a more elegant solution than doing all the heavy lifting myself between the set and the string.

- (NSString *)sanitizeString:(NSString *)str withSet:(NSCharacterSet *)set {
	
	NSScanner *scanner = [NSScanner scannerWithString:str];
	NSString *buffer;
	while ( [scanner scanCharactersFromSet:set intoString:&buffer] ) {
		NSRange range = [str rangeOfCharacterFromSet:set];
		if ( range.location != NSNotFound ) {
			str = [str stringByReplacingCharactersInRange:range withString:@""];
		}
	}
	return str;
}

To use:

NSString *string = "A string that might have funny characters in it.";
NSCharacterSet *set = [NSCharacterSet illegalCharacterSet]; 
NSString *result = [foo sanitizeString:string withSet:set];

Cape Cod

I have been told that the part of Cape Cod where I am staying is considered the “Irish Riviera.” I’m not sure whether this is based on a misunderstanding of what comprises the Riviera or the Riviera has been knocked down a few notches over the years. I don’t think I have ever seen a denser concentration of ice cream, pizza, and seafood than here. Seeing signs like “Finest Quality Fried Seafood” is laughable. The food here is, in a word, shit.

Cape Cod is nice, but it’s not “every summer for multiple generations” nice. If anything, Cape Cod is seasonal townie hell.

The Macintosh is 30.

The Macintosh is 30. Like so many other people I am asking the same question: How the hell did that happen?

I remember the first time I used a Macintosh. I was a junior in high school in 1988 taking a basic drafting and architecture class. In the corner of the classroom was a small bank of Macs all loaded with illustration and CAD programs. Students who achieved a high enough grade got to use those computers for their projects. I was getting an “A” (one of my precious few at the time) and so I scored some much-ballyhooed computer time.

When I sat down in front of the Mac, I had no idea what it was. I don’t think I had even heard of it until I walked into that class. This will likely sound cliche but the whole experience was intuitive right from the start, from creating a new file, drawing the lines and shapes with the mouse to create the machine part plans, to saving the file, and the rest. I was always good at visualizing things, and the Mac was the first computer I had ever used that spoke my internal language. I could use my hand to draw and I was finally able to make a connection between the files I saw on-screen and the data on the disks. I loved using the Mac.

At home, I had a Commodore 64 and all I knew how to do with it was really basic BASIC programming and run games, both bought and pirated. When the 8-bit GEOS operating system was released, my use of the Commodore really took off because all of a sudden it could be used just as easily as the Mac. All of these disparate applications were finally unified in a single interface. I had a joystick as opposed to a mouse—if a mouse existed to use with GEOS I never knew about it—but that didn’t matter. Mucking about with files and navigating to the apps I needed to write papers and do homework was a lot easier. GEOS really brought value to the Commodore for me, more than anything I had ever done before, but it was never as streamlined an experience as using the Mac.

Around 1993, I finally got a Mac at home (thanks, Mom) and the Commodore went into a closet. Many years later, 2000 I think, I sold the still-unused Commodore and all of my software at the MIT Flea Market to some random college student for $50. I never looked back.

Part of the appeal of getting into graphic design for me was that the Mac was so prevalent. I knew that if I got a job doing graphic design that I could probably get my company to buy a Mac for me to use. Honestly, if it weren’t for the Mac, I’m not sure what I would have done for a living. As I proceed down the path to getting my computer science degree, using a Mac has yet to hold me back and I see a lot of Macs in the classroom, so I look forward to another 30 years of use.

Happy birthday, Macintosh.

Rush’s Vapor Trails Remix

“We overcooked it,” bassist/singer Geddy Lee tells Rolling Stone now. “The mixes were really loud and brash. The mastering job was harsh and distorted.”

Outside of electronic music, I’m not one who is terribly keen on artists remixing their work, but I’m really glad Rush remixed Vapor Trails now that I’ve had a chance to listen to it a few times. While it is still not a favorite of mine, there are some choice moments for me, much more so with the new mix. It is a much more reasoned album, and I am glad to have this on my iPhone in its entirety again. Well done, guys.

Metadata Equals Surveillance

Imagine you hired a detective to eavesdrop on someone. He might plant a bug in their office. He might tap their phone. He might open their mail. The result would be the details of that person’s communications. That’s the “data.”

Now imagine you hired that same detective to surveil that person. The result would be details of what he did: where he went, who he talked to, what he looked at, what he purchased — how he spent his day. That’s all metadata.

This is not to say that what the NSA does is right or wrong, but this does set forth a clear definition of what actually is the content under contention. The above is the bulk of the article, the analogy is really spot on as what consists of metadata, but the rest is worth reading since the implications of this categorization are made inarguably clear. For those who wish to dive deeper, Mr. Schneier linked to a lengthy but fascinating article on how metadata can actually be used.

The Atlantic: The Case Against High School Sports

As states and districts continue to slash education budgets, as more kids play on traveling teams outside of school, and as the globalized economy demands that children learn higher-order skills so they can compete down the line, it’s worth reevaluating the American sporting tradition. If sports were not central to the mission of American high schools, then what would be?
The Atlantic: The Case Against High School Sports

That should be neither a rhetorical question nor one difficult to answer for anyone even with only half a brain.

The Atlantic: Getting Drunk in North Korea

The Taedonggang, named after Pyongyang’s river, is one of the city’s most notable nightlife stops, producing seven types of beer. Although these are named with typical Soviet flair — Beer Number 1, Beer Number 2, Beer Number 3 and so forth — the equipment used in their brewing actually comes from a well-regarded, though now defunct, British brewery. “When I was visiting North Korea, I was pleasantly surprised at the quality of their Taedonggang beer, of which we drank quite a lot,” recalls Alistair Humphrey – or “Humph” – whose father was chief brewer for the British ale makers Usher’s of Trowbridge, before he died and the brewery was sold. “When we got back to Beijing, I went out with Nick [Bonner] and Simon [Cockerell] of Koryo to the Great Leap Brewery, and the subject of Usher’s came up. They asked if I knew what happened to the brewery, exchanging conspiratorial looks. ‘It folded. I think it’s now a supermarket,’ I said. ‘No!’ said Nick, gleefully. ‘It was sold to the North Koreans – they’ve been using it to brew the beer you were drinking last week!’ So the equipment my father bought to brew English ales lives on in Pyongyang.”
The Atlantic: Getting Drunk in North Korea