Archive for July, 2009

Blog Spam Surprise

When I took up writing this blog,  I was prepared to get spam in the comments.  I’ve deleted quite a few so far.  But when I got one that said “Super post, Need to mark it on Digg”,  I have to admit,  I almost approved it by default. That seems like just “nice article” compliment.

But, being the person I am, and having experienced so many people trying to trick me,  I looked at the site in the commentor’s URL.  It was a site in a language I couldn’t read, but the format suggested that it was a sales site of some kind.

So the surprise?   I Googled for the exact string (with quotes) “Super post, Need to mark it on Digg”  and got over 16,000 results.  This exact string appears in blog after blog.  The name and URL changes in the blogs I examined, but it always leads to some sales site.

Well, it was a surprise to me.

Helping XCode find its files

I started moving files around in my project folder recently.   I wanted to re-organize code and non-code files into different folders.

Once the files had been moved and the project re-opened, there are many source files displayed in red, meaning XCode does not know where they are.

To help XCode find missing files, try this:  select the red file,  perform “Get Info”, select the “General” tab and click the “Choose…” button.   You can then find and pick the file.  You can even change the file if you like.

Warning:  when you are doing this with a missing file, it is possible to substitute a folder for the file.   If you manage to do this, you won’t be able to just re-choose the file.   You’ll have to delete the folder and re-add the file.

Tags: , , ,

default.png won’t display

Funny one today:  my default.png file would not display.  My application launched with a black screen zooming out instead.  A quick look at another app that did work properly showed the only difference: the “D” was capitolized.  A quick check and sure enough, it worked if the D was upper-case.

That was a surprise to me, being so used to the case-insensitive file system on the Mac for so long.

Tags: ,

Executing Terminal Commands Inside Xcode

A long time ago,  I remember using Apple’s MPW environment to create software for the Mac.   This environment was a lot like using terminals had been on the Unix machines back in college. This had its plusses and minuses but it was strange in one fashion:  I could execute command-line scripts inside the text editor.  This ability has returned in Xcode.  (Well, I just noticed it recently due to a lucky accident. It may have been there all along.)

The default setup for Xcode uses Control-R (and variations with Option or Shift keys) to execute the currently selected text as a bash terminal command. If no text is selected, the entire line containing the insertion point is used. You can change which key does this in Xcode’s “Key Bindings” preference panel under the “Text Key Bindings” tab.  (Note that the variations are listed in the bindings panel mentioned.)

This can have many small, cool uses.   Here are a few off the top of my head:
this will give you a timestamp like this one: “Fri Jul 17 14:04:02 EDT 2009”
“ls” will list directories of files directly into your text file – this can be useful if you are looking to put a file name into a file open command or  something

If you have a useful command-line tool whose output would be useful in an Xcode text file, this will work for you.

What you can’t do is run programs that don’t stop or require further input, like TOP or SSH.  For those, you’ll still need to use the terminal program supplied with your computer.   If you do try this,  you will cause problems for Xcode that will probably lead to it locking up or crashing.

I tried this with “top” and Xcode started having difficulty editing the file any further.  Other things seemed to work, but it eventually crashed.  As I figured out later, a “top” process had started.  The second time, I found it in the process list and used “kill” on  it from the real terminal.  The moment I killed it, the Xcode window filled with a ton of output generated by TOP.

In another case, I tried to use the SQLite3 tool, but it just quit with this error: “Incomplete SQL”.  So interactive tools don’t work for this.

Of course, its easy to capture the output of command-line tools for text files in different ways, so this is cool, but not really earth-shaking.  It can make some work much quicker and easier.   Enjoy.

Tags: , , ,

Idea for CAPTCHA’s

Ideas Disclaimer:  these are (random) thoughts of mine that I can’t make into a product or much of anything for one reason or another.  So I present them here for anyone who might use them.

Make a CAPTCHA an instruction for a human to interpret,  like “What’s 2 plus 2?”

Or make it a picture-interpretation.  Ask what is this? and show a picture of a dog.  That does mean that you must be prepared to receive a wide array of possible answers, but its not too hard.  Many a photo are being tagged already.

Or make a multiple-choice test.  Show a question or a picture and ask the user to pick the appropriate response.  You can change the order and wording of questions and responses easily (or rotate pictures) while still making them easy.

Or vary it like this:  tell the user “put ‘answer’ in the 3rd slot below:”  or “put the name of the pictured item in slot 2”.    You then give many slots to place the answer.  The underlying HTML form can have randomized entry names so only the server knows which is supposed to have data returned.

Update: 8-8-09

On July 31, I found a website with this CAPTCHA:

What is the third word in the phrase “laqoc cufuyeg vobipic eqigig cuw”?:


Click of Death from My External Drive! SAVED!

A little over a year ago, I had a chilling experience: I came into my office and the external drive connected to my desktop was making nasty clicking noises non-stop.  You may already know what this means; the drive is dead.

This time was little different though, partly because this box has 2 drives in a striped RAID for a nicely fast and large total, and partly just because I really liked it. What really made this time different was that I noticed that the power supply was really HOT.  (The power supply was in a black plastic brick that sits outside the drive box.)

When I picked it up, I thought I heard something, so I put it up to my ear.  Surprisingly, there was a buzzing, arcing noise coming from it that had not been there before.  So, maybe the problem is only the power supply?  It had 4 pins which were supposed to be +5 volts and +12 volts according to the printing on the brick, but they didn’t say which pin was supposed to have which voltage, so I couldn’t really check it with a volt-meter.

On a hunch, I Googled for the product number listed on the brick and got lucky. had them as individual parts for a reasonable cost. (About $30 after shipping and all.)  And they take PayPal, which was convenient for me since I had a little more than that in my PayPal account.

The cheap shipping took several days to make it across the country, but when it arrived, I put it in place of the old one and PRESTO! My drive was back in all its glory.  YES!

So now fast-forward to 2 weeks ago.  I again came into my office to the sounds of clicking from my cool external drive.  I gave it a moment of silence thinking it to be dead, but then remembered what happened before.  Once again, the power supply was making that arcing noise.

I did a quick search for the product number again and found the original receipt.  I looked up the company and found they still had the product in stock. Not only was it cheaper than when I bought it last time, there was a yet cheaper version if I didn’t buy the power cord that connects it to the outlet.

Once again, the new power supply saved the day. My drive is again chugging away.

Sadly, I noticed that the receipt was about 1-year and 1-month old.  So power supply #2 made it just over its 1-year warrantee. No free replacement.

So, now the moral?  I have to remind myself that in all the time I’ve worked on computers, I’ve learned (and re-learned) not to trust hard drives, but their deaths never fail to be inconvenient.

But at least when an external dies, it might not mean your data died. The drive inside might be fine. You can put it in another box or inside a computer to see.   In my case, the box had done the RAID work as well, so it wasn’t that easy.  Thankfully it was as easy as buying a new part (as long as the part was available.)

Tags: ,

DevBits06: Debugging with Instruments causes Bugs?

Here’s one that just about caused me to pull out another chunk of hair:  I was getting ready to send a product to a customer and was giving it the final test runs on my device.  I was using Instruments to check for leaks when the program started crashing, somewhat randomly with array-bounds-exceptions.  It didn’t crash in the same place every time, or even after the same amount of use.  It could happen quickly, it could take a while.  (Well,  you know the kind of thing I’m talking about.)

After a LOT of work going over code trying to find the problem, I was thinking it must be something device-specific because it hadn’t happened in the simulator at all.  I looked through all my notes, I looked through posts online, nothing seemed to narrow it down.

After a lot of debugging, I noticed that it only happened with instruments running.  That seemed weird, but usually this kind of thing means there is a bug, but the presence of something like instruments is just bringing it out.  But since I couldn’t run the debugger and instruments at the same time, I was having trouble seeing what was wrong beyond the bounds-exception.  So, I added a bunch of calls to NSLog to give me info about the situation while instruments was running.  (If there are good articles on using Instruments alongside gdb or something, I’d love to hear about them.)

Now, with all the logging, I finally see that the index was jumping by 2 rather than 1 at wrong moments.  That was sending the index beyond the limit.  Now Why? WHY?  The only increment code was in an IBACTION called by a button on the view, and it only incremented by 1.

In the end,  I could hardly believe the answer:  I was incrementing by 1 – TWICE.  The IBACTION was being called multiple times by MY rapid clicking (touching) on the button. I thought it was cool that while the animation was transitioning between 2 views, the destination view was actually loaded and ready to be touched. It made everything faster. I was going through views at a rapid pace in my testing and thinking nothing of it. Every new touch would interrupt the animation and do whatever the touch would do. Most of the time, the offending view would disappear before the button could be pushed again.  However, with Instruments running, things on the device slowed down just enough for the button to sometimes get pushed again and send the message to the IBACTION a second time. The indexes incremented incorrectly as a result.

The first thought I had was “I shouldn’t use Touch-Up-Inside. I should send the event on Value-Changed or something”.   That might have worked, but the button in question was a button bar item. It didn’t have the option to choose the event.

The solution: add some code to the program to prevent incrementing beyond the array bounds.

The solution I probably should have used (and will use in the next version): add code to the IBACTION to prevent it from executing more than once before the view disappears (and re-appears a little later.)  I’ll just add a member variable to the view controller that turns false/NO on entering the IBACTION, and resets to true/YES in ViewDidAppear.

The moral:  do not assume that an IBACTION can only be called once just because it changes the view or view controller.  The system controls that.


iPhone Developer Bits 5

Your downloaded certificate file doesn’t seem to contain a private key?  You turned down the arrow in the Keychain Utility and there wasn’t anything there?  I’ve had this happen twice and I’ve got the following I wrote down.  I wish I had written something more detailed at the time, but here is this if it helps.

–  the original private key for the request is held on the computer that generated the certificate request (CSR) file, so you must download the certificate on that same computer. (And hopefully a crash or drive corruption hasn’t hurt that key in the meantime.)  I’m not an expert on security, but I believe the idea is that the request (CSR) is actually a public key, or contains one, so when Apple creates the certificate, only you can decrypt it with the private key for the CSR.

– Create a different CSR for each certificate: One for development, one for distribution.  I’m not exactly positive on this one.  I’m wishing I wrote more, but I’m sure that doing this won’t hurt anything.

– Do you have an individual developer account? You must revoke the “bad” certificate and its associated provision profiles, then regenerate them, starting with certificate. (Be sure you can find and save the certificate private key before generating provision profiles with it.)

Remember: to be able to give free updates to your customers, you must have the original distribution private key.  Back it up in places that will survive the death, destruction, disappearance and theft of the hard drive it is stored on.


iPhone Developer Bits 4

Changed your bundle identifier and now XCode won’t load the result app onto the iPhone or iPod Touch device?

– Try deleting the old version of the application from the device before loading/running the new one.

Tags: ,

iPhone Developer Bits 3

error “syntax error before ‘AT_NAME’ token”

This one frustrated me for longer than I care to think about. (It wasn’t really all that long, but my pride was hurt that I didn’t figure it out much more quickly.)  It appeared to be something wrong in the generated token stream but the messages gave no real clue as to why this was happening.  My first thought was that I had accidentally edited an SDK file.

However, when my own thinking doesn’t turn up the answer in an effective amount of time, I find it pays to Google for it. My usual practice is to duplicate the error text as exactly as possilbe so that I can find posts about the same problem.  (Start with the very specific and become more general if the answer doesn’t present itself.)

It turned out to be that I had gotten some extra text after the “@end” directive in a .h file

Special thanks to John Muchow for his post on which quickly lead me to the correct answer.  No doubt you saved me time and hair-pulling.

Tags: ,