John Attebury

Web design, programming and administration

July 23, 2011
by John Attebury
3 Comments

Xcode from Snow Leopard to Lion

Update: The App Store doesn’t install Xcode. It installs an app called “Install Xcode”. I had to search for this app and found multiple copies as I’d previously downloaded Xcode from the App Store. Right click to check the version. It should be 4.1. The install went smoothly after that.

****

I had the misfortune of paying $4.99 for Xcode just 2 weeks before Apple made reduced the price to “Free” in the App Store.

After upgrading to Lion, I received message that I needed to install the Xcode tools version for OS X Lion. So I fired up the App Store. Clicked install. And waited. (Actually, I did alot of other stuff while Xcode downloaded.) This process differed from typical App Store updates in that no progress bar was displayed beneath the app icon.

Eventually the App Store told me that I had successfully downloaded Xcode, but I received the same error. I still had the wrong version of Xcode for OS X Lion.

A search suggested uninstalling Xcode and then reinstalling using the “Install Xcode” app (which appears to function similarly to the “Install OS X Lion” app.

Alas, no luck. Not even after a reboot.

Here’s the error:

****

UNCAUGHT EXCEPTION (NSInternalInconsistencyException): Couldn’t load plug-in ‘com.apple.dt.IDE.IDEiPhoneSupport’ while firing fault for extension ‘Xcode.Device.iPhonePlaceholder’
UserInfo: {
NSUnderlyingError = “Error Domain=DVTPlugInErrorDomain Code=2 \”Loading a plug-in failed.\” UserInfo=0x400db8a80 {DVTPlugInIdentifierErrorKey=com.apple.dt.IDE.IDEiPhoneSupport, DVTPlugInExecutablePathErrorKey=/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/IDEiPhoneSupport.ideplugin/Contents/MacOS/IDEiPhoneSupport, NSLocalizedRecoverySuggestion=The plug-in or one of its prerequisite plug-ins may be missing or damaged and may need to be reinstalled., NSLocalizedDescription=Loading a plug-in failed., NSFilePath=/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/IDEiPhoneSupport.ideplugin, NSLocalizedFailureReason=The plug-in \U201ccom.apple.dt.IDE.IDEiPhoneSupport\U201d at path \U201c/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/IDEiPhoneSupport.ideplugin\U201d could not be loaded. The plug-in or one of its prerequisite plug-ins may be missing or damaged., NSUnderlyingError=0x4003a0b80 \”The bundle \U201cIDEiPhoneSupport\U201d couldn\U2019t be loaded because it is damaged or missing necessary resources.\”}”;
}
Hints: None
Backtrace:
0 0x00007fff8f10596a __exceptionPreprocess (in CoreFoundation)
1 0x00007fff8de52d5e objc_exception_throw (in libobjc.A.dylib)
2 0x000000010a6edc98 -[DVTExtension _fireExtensionFault] (in DVTFoundation)
3 0x000000010a6d87f9 __38-[DVTDispatchLock performLockedBlock:]_block_invoke_0 (in DVTFoundation)
4 0x00007fff92f58afd _dispatch_barrier_sync_f_invoke (in libdispatch.dylib)
5 0x000000010a6d87a9 -[DVTDispatchLock performLockedBlock:] (in DVTFoundation)
6 0x000000010a6eda45 -[DVTExtension _valueForKey:inParameterData:usingSchema:] (in DVTFoundation)
7 0x000000010a6ed9ab -[DVTExtension valueForKey:] (in DVTFoundation)
8 0x000000010a6ed167 +[DVTDevice _knownDeviceLocators] (in DVTFoundation)
9 0x000000010a6eccea -[DVTDeviceManager startLocating] (in DVTFoundation)
10 0x000000010ac1d07a IDEInitialize (in IDEFoundation)
11 0x000000010af8fc0b -[IDEApplicationController applicationWillFinishLaunching:] (in IDEKit)
12 0x00007fff8b405716 __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 (in Foundation)
13 0x00007fff8f0ae51a _CFXNotificationPost (in CoreFoundation)
14 0x00007fff8b3f19cb -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation)
15 0x00007fff932c46c8 -[NSApplication finishLaunching] (in AppKit)
16 0x00007fff932c427d -[NSApplication run] (in AppKit)
17 0x00007fff9354252a NSApplicationMain (in AppKit)
18 0x000000010a6cfeec (in Xcode)

I’m not alone in this issue https://discussions.apple.com/message/15662283#15662283.

It’s always something. (Of course, I upgraded asap knowing some problem would turn up. Sue me.)

June 27, 2011
by John Attebury
0 comments

Prep addresses for geocoding

I needed to geocode several thousand addresses from an old database. The addresses were exported into a pipe-delimited CSV file which contained extra info I didn’t need. After extracting and prepping the addresses into a separate text file I geocoded the addresses via a simple bash script.

Using Sed & Awk to extract and prep the addresses

# the exported CSV file using pipe | as delimiter

"SomeID"|"BusinessName"|"StreetAddress1"|"StreetAddress2"|"City"|"State"|"Zip"|"Phone"|"Fax"
"34"|"Super Store"|"12345 Main St"|""|"Amarillo"|"TX"|"79109"|"123-456-7890"|"234-567-8901"
"85"|"OK Store"|"234 Wescott"|"Suite 100"|"Oklahoma City"|"OK"|"73104"|"345-678-9012"|"456-789-0123"

# piped commands

$ sed '1,1 d' exported.csv | sed s/\"//g | sed s/\ /\+/g \
| awk -f addresses.awk | sed '/^ *$/d' > prepped.txt

Let’s take a look at each piped command

# remove 1st line (header info we don’t need)

$ sed '1,1 d' exported.csv

# results are piped to remove double quotes

| sed s/\"//g

# and those results are piped to replace spaces with +
# (Google’s geocoding service recommends separating words with pluses + rather than spaces)

| sed s/\ /\+/g

# results are piped to an awk script (see below) to get only the address fields we want to use
# awk -f specifies the script to use

\ | awk -f addresses.awk

# those results are piped to remove blank lines
# and save results to the text file the bash script will use

| sed '/^ *$/d' > prepped.txt

A closer look at the straightforward awk script

# addresses.awk - - print addresses

# set the pipe as delimiter
# (our CSV file used pipe delimiter rather than commas)
BEGIN { FS = "|" }

{
 # the business name is in field 2
 # business = $2

 # concatenate typical address fields
 # street in 4, city in 6, state in 7, zip in 8
 # we earlier replaced spaces with pluses within address fields
 # hence "Oklahoma City" became "Oklahoma+City"
 # now we insert pluses between fields
 address = $4"+"$6"+"$7"+"$8

 # the data we're looking for
 # will later be processed by the bash script
 print address
}

# print the number of lines that were processed
# use this as a quick validation of the number of addresses
END { print NR }

# and the prepped.txt file

12345+Main+St+Amarillo+TX+79109
234+Wescott+Oklahoma+City+OK+73104

With a text file of addresses to geocode, the bash script is up next.

Until this project, I’d never worked much with Sed & Awk, but using these powerful tools has really crystalized for me the Unix Philosophy.

June 25, 2011
by John Attebury
4 Comments

SpiderMonkey, jsawk & resty on Snow Leopard

I recently needed to parse JSON from the command line. A GIS yielded a StackOverflow answer: jsawk.

There were other possibilities V8, Python, Perl and PHP, but a Javascript and Awk solution looked promising (and as a Javascript guy, the easiest to pickup). So after a bit of trial and error, here’s what worked for me.

[Edit- In the comments Bob Kuo suggested using Homebrew instead of MacPorts.]

Install MacPorts if you haven’t already.

# If you already had MacPorts installed, update and sync if necessary.

$ sudo port selfupdate
$ sudo port sync

# Install SpiderMonkey (nspr is installed for you)

$ sudo port install spidermonkey

# Test your install

$ js

#You’ve been dropped into an interactive javascript shell, counts to 99

js> for(var a = 0; a < 100; a++){ print(a) }

# Quit.

js>quit()

# Install jsawk – you can put this wherever you like, I used ~/Code
# For more info, see https://github.com/micha/jsawk

$ mkdir ~/Code
$ cd !$
$ curl -L http://github.com/micha/jsawk/raw/master/jsawk > jsawk
$ sudo ln -s jsawk /usr/bin/jsawk

# Install resty
# For more info, see https://github.com/micha/resty

$ curl -L http://github.com/micha/resty/raw/master/resty > resty
$ source resty

# View the current host (you can change this at anytime), outputs URL

$ resty

# For this demo, set the host to Twitter

$ resty http://api.twitter.com

# View host again to verify the change, outputs http://api.twitter.com/*

$ resty

# Get an array of dates from recent tweets on Twitter’s public timeline

$ resty GET /statuses/public_timeline.json | \
jsawk  'return this.created_at'

# Get my recent tweets

$ resty GET /statuses/user_timeline/johnattebury.json | \
jsawk  'return this.text'

Integrate jsawk into your shell scripts and you’ve got an excellent JSON parser ready for interesting problems. Combine jsawk with resty and a world of JSON api’s is just a prompt away.