Tag Archives: code

Hacker’s Delight

I have been musing lately about the great disservice Apple did the world by making computers easy to learn — namely the fact that few people ever bother to learn about them. Who bothers to learn about them when, on the iPhone for instance, the case is sealed shut, the lifespan is 1 or 2 years for many purchasers, and the platform is closed in lots of ways?
Complete.org: My boys love 1986 computing

I hadn’t thought of the Mac that way before. I don’t know that I would go so far as to say that they have done everyone a “disservice,” but developing for Apple is not nearly as open or cheap as is developing for Android. Weighing the relative benefits of each is another discussion entirely.

To the point of the article, hacking away on some of my old Macs is something that I am looking forward to after I finish school. Back in the day, when I was plunking along on my Commodore 64, I was either playing cracked games or doing my homework in GEOS. GEOS was what got me to truly realize the computer’s potential, where I did a bunch of papers and art for classes. Even after the requisite computer classes, all I really walked away with was the ability to LOAD "*",8,1 enough to get to games and GEOS.

But now that I am wrapping up my computer science curriculum at school, and mopping up the last of my non-credit requirements, I am looking forward to booting up the original iMac in OS 8 I have sitting downstairs. I still have loads of old software and seeing some of what I missed using it the first time. I’m a different user than I was so many years ago. Sharing all that with the kids is a pleasant bonus.

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];

Github Student Developer Pack

There’s no substitute for hands-on experience, but for most students, real world tools can be cost prohibitive. That’s why we created the GitHub Student Developer Pack with some of our partners and friends: to give students free access to the best developer tools in one place so they can learn by doing.
Github Student Developer Pack

The list of software and subscription offers is truly impressive. I won’t use half the stuff, but others like Atom, I’ve been wanting to try, but haven’t for precisely the reason they give.

About that “conversational tone”…

I find the conversational tone sometimes found in entry-level technical documentation to be maddening at times. To wit…

[insert technical information]

Now because we are all friends here I’m going to share a secret with you. Come closer. Get in here. Let’s have a huddle. [insert non-intuitive technical information]


Now don’t get too worked up. [insert follow-up technical information]
Laravel: Code Bright

Clearly, I am not the target audience, but I think this is beyond necessary. I would speculate that anyone who is reading about a PHP framework has enough experience with technical material they don’t need their hand held like this. This amount of conversational tone makes using this material as a reference challenging later. There are ways to be conversational without being wasteful of everyone’s time and obstructive. I don’t see this very often where I roam around, but when I do, I cringe for the author every time I read it.

The same goes with including “um,” “hrm,” “erm,” and “well, let’s see…” and language devices of their ilk anywhere outside of an interview transcription. Just write the damn passage already.

A Dream Come True

The JavaScript OSA component implements JavaScript for Automation. The component can be used from Script Editor, the global Script Menu, in the Run JavaScript Automator Action, applets/droplets, the osascript command-line tool, the NSUserScriptTask API, and everywhere else other OSA components, such as AppleScript, can be used. This includes Mail Rules, Folder Actions, Address Book Plugins, Calendar Alarms, and Message Triggers.
Apple: Javascript for Automation Release Notes

This is a dream come true for me; really heady stuff. Applescript has been foundational to my career, but I never once—not once—liked the syntax nor the environment. Giving Javascript a first-class implementation could be very beneficial, I think, as there are a hell of a lot more Javascript developers than there are Applescript developers. The problem still exists with wonky scripting support in applications (I’m looking at you, Adobe with your fancy-pants JSX). Perhaps by removing the Applescript barrier to automation will bring some new talent into this niche area that has been too specialized for its own good. Up until now, the Yosemite update was pretty “meh,” but now I’m excited.

What do you care, Excel?

While doing some automation work, I unintentionally tried to open two files with the same name but from different directories in Excel. Then, this happened:


I don’t think this is something I’ve ever done in the past, but I also don’t understand why this would be a problem. If the complete paths were the same, I would understand because Mac OS treats all network volumes as /Volumes/path/to/file.ext. Statistically, small but not to the point of being pragmatically impossible, two files on two external volumes could have the same path. But going by just the name seems…short-sighted…or something. Weird.

U.S. Digital Services Playbook

Today, too many of our digital services projects do not work well, are delivered late, or are over budget. To increase the success rate of these projects, the U.S. Government needs a new approach. We created a playbook of 13 key “plays” drawn from successful best practices from the private sector and government that, if followed together, will help government build effective digital services.
U.S. Digital Services Playbook

Three of the plays—1, 6, and 7—focus on people alone. Solid advice for any project.

“You don’t choose what will work. You simply do the best you can each time.”

From a blog post by Neil Gaiman in 2009:

Yes, it’s unrealistic of you to think George is “letting you down”.

Look, this may not be palatable, Gareth, and I keep trying to come up with a better way to put it, but the simplicity of things, at least from my perspective is this:

George R.R. Martin is not your bitch.

But beyond that initial blast is this really great gem that I think applies to any creative endeavor including programming:

Sometimes it happens like that. You don’t choose what will work. You simply do the best you can each time. And you try to do what you can to increase the likelihood that good art will be created.

And sometimes, and it’s as true of authors as it is of readers, you have a life.

I have started more projects than I have finished, each for their own reasons. “Finished” is entirely subjective, but in my case it would likely mean “used by someone else” and/or “used in day-to-day production by me.” Some unfinished projects get revisited, but most don’t, again each for their own reasons. Outside of important deadlines, not getting hung up on whether something is finished is important, at least for me. What is just as important, however, is learning something new from that project, including how not to do something. Each project I started has been a learning experience of some kind, so even the unfinished ones have value.

Having a deadline is another matter entirely.

Apple hijacks Unix headers into Xcode in Mavericks

I am currently taking a class on Unix systems programming. While following along with lecture, the professor stated that almost always the header files needed for our type of work are located at /usr/include. However, that directory does not exist on my brand new Mavericks MacBook Pro. I have learned (after much searching the web) that the header files are now here:


After doing some more research, I found that to get those Unix header files back into /usr/include, one has to install Xcode’s command line tools. But, in order to get those, one has to be a registered member on Apple’s developer website. Not necessarily a paying member, but registered.

I was once a paying member for Apple’s developer tools but I gave it up because I was not actually using everything that was made available. My focus changed and the annual $99 was going to waste. In fact, because of that and that Apple has so much of their Cocoa documentation available externally for free, my need to log into their website has decreased over time to my not touching it in over a year. Now I am jumping through the hoops to figure out which account I was using and what was the password, but that is turning out to be harder than expected for a variety of reasons on Apple’s side, the servers not propagating my Apple ID resets to the developer site being one of them. Yes, I should have done a better job of recording my information, but a simple password reset shouldn’t be this hard either. At this point, I will likely just create a new account solely for getting me what I need.

I have no idea when Apple hijacked the header files, and i can understand the logic and convenience of doing so for tool updates, but knowing what little I do about Unix, hijacking seems to be anathema to the Unix culture. Apple has made my morning nothing but hassle trying to get this fixed and I will have an assignment due soon. So, cheers for that, Apple.

UPDATE: I wound up creating an account solely for the developer account, and it was, as expected, faster and easier than mucking about with a bunch of password resets. Once I did that, getting the command line tools was not straightforward though not hard (Xcode > Open Developer Tool > More Developer Tools… which then kicks you over to a downloads page on the developer website, with registration required for access).

As for my comment about the new default header location being anathema to Unix, I realize now that’s not necessarily true. If anything, Apple can do whatever they want with their distro. But the fact remains based on everything I have read so far that there are some clear expectations about there things ought to be and the header file location is one of them. But at least now I can establish a workflow where I can use the muscle of Xcode to develop and then confidently test outside before submission.