“Cannot connect to iTunes Store”

If you’re trying to test a new in-app purchase on iOS, and you get this mysterious error:

Error Domain=SKErrorDomain Code=0 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}

… make sure you’re using a real device. This error will be given if you try to complete a purchase in the Simulator. That’s right, although you can list purchases in the simulator, actually buying something with a Test user in the sandbox environment will simply fail with this vague error.

Arduino without the Arduino

AVR ATMega328P controlling multiple stepper motors

I built a custom PCB to host a ATMega328P in DIP form factor. I want to control two stepper motors for a project. I considered doing it “the hard way” : E.g. using my own driver transistors and protection diodes… and I’ve also ready about a variety of silicon that makes driving them easy. But I’m still not ready to learn to do surface mount soldering, and I wasn’t finding any stepper motor drivers in DIP configuration. So I opted for something I’ve used on other projects, the “Easy Driver” from SparkFun.

A few of the features of this PCB is the 6-pin header that allows for it to be programmed using the linux command-line tool avrdude. I found that avrdude runs on raspberry pi, and I have one unused in a drawer. My plan was to make it so I could slide the pcb right onto the GPIO of the pi. But I neglected to consider the height of the various components on the pi, so I had to opt for use wires to hook it up instead… Not elegant but functional.

The wifi went out on my pi (which is why it is in a drawer). So I used a internet sharing on my mac to connect to it using a thunderbolt ethernet adaptor. I ssh into the pi, and use avrdude to upload to the PCB with the ATMega328p. I have a simple makefile that compiles my “C” program using avr-gcc.

The PCB was printed by OSH Park. First time using the Eagle software and first time getting a PCB made. It took about 2-3 weeks for the PCB to arrive…

It’s a beautiful board. I don’t think I’ll ever build something out of a generic perf board again.

I made some mistakes:

  1. The vias for my Easy Driver were too small to use regular wire. But I had some resistors with thin enough leads I could use those.
  2. For some reason my status LED’s weren’t actually grounded. I soldered a jumper wire
  3. The problem with the programming connection for the pi I mentioned before
  4. I’m sure I think of some others.

But the fact that the thing actually drives a motor is kind of amazing….

gitflow tools on github

We’ve adopted gitflow for one of our projects. The git command line tool integrations found on github are very handy. Note: be sure to adopt the -avh version of the tools found in this repo: gitflow for git on github. To install on Mac OS use `brew install git-flow-avh`. The non `-avh` version of this tool is 7 years out of date — we mistakenly used that version initially and ran into bugs that have been around for many years (and which are fixed in the `-avh` version).

Watching program flow in a time-sensitive situation

I’m working on some unit test in Java (well, Kotlin) for an Android project. When I set a breakpoint, the failure mode changes because there are timeouts and races going on. This is not an ideal situation, but I’m debugging someone else’s code here. So I found a clever way to log what code is getting called, and from where, by using breakpoint actions. Just put `new RuntimeException().printStackTrace()` in as a breakpoint action! Now your log shows when code got hit, and why it got there, but doesn’t actually stop execution, so it does less intrusive shift to the timeouts and race-conditions.

Receipt Validation on iOS

This has been a pretty major headache: Trying to validate a receipt for an in-app purchase on iOS.


  1. Use cocoapods OpenSSL-Universal pod to get openssl
  2. Copy Apple’s suggested code, but add the key missing call OpenSSL_add_all_digests() prior to PKCS7_verify()
  3. This last thing is what fixes the mysterious error that reads, “error:2107D06D:PKCS7 routines:PKCS7_BIO_ADD_DIGEST:unknown digest type”

Now, to explore the contents of my ASN1 package!

Kotlin, please allow return from closures

Edit: After writing this, I was helped by Andrey on Twitter and now I know about the return@

The simple answer is:

sequence.flatMap {
if (it.containsKey("connnected") {
return@flatMap Observable.just(it.getBoolean("connected"))
return@flatMap Observable.empty()

Here is the original post.

Today’s kotlin frustration… trying to map a Bundle into types. E.g. if the bundle has the key “connected” get it out as a boolean. otherwise, skip the event.

so I do

sequence.flatMap {
if (it.containsKey("connnected") {
return Observable.just(it.getBoolean("connected"))
return Observable.empty()

Except, oh Kotlin, you back-stabbing-friend… closures don’t allow `return`

So I edit it…

sequence.flatMap {
if (it.containsKey("connnected") {

That’s probably obviously wrong to you now, but it took me a long time to see the problem.

And the fix.

sequence.flatMap {
if (it.containsKey("connnected") {
return Observable.just(it.getBoolean("connected"))
} else {
return Observable.empty()

I don’t see why Kotlin disallows the return — and it makes this kind of error much less likely. The fact that closures evaluate to the last expression is handy for doing tiny bits of work, but I find that reactive networks in RxJava are much easier to express with blocks — and if they get more than a few lines long, you sometimes really want the ability to do an early return without introducing the nested scope of an `if` statement.

After installing openvpn I cannot connect to my raspberrypi

So I installed openvpn on my Raspian distro on my Raspberry Pi 2. As soon as I started it up, I lost all connectivity to my Pi.

And I don’t have a display, keyboard, or mouse — all my management has been over the network.

How to recover?

I tried a bunch of things, but here’s what worked, in brief.

  • Power off PI and put SD card in my Mac.
  • Copy the SD card to an image file using `dd`
    • dd bs=32768 if=/dev/rdisk2 of=raspberrypi.raw
    • VBoxManage convertdd raspberrypi.raw raspberrypi.vdi --format VDI

Use Disk Utility to see which device is your card reader. The Pi’s SD card has two partitions, and the first can be mounted by your mac. Note by using ‘rdisk2’ instead of ‘disk2’ it does unbuffered reading which is faster, or so I’m told.

Now we edit the image. If you have a way to open ext4 filesystems already, just remove the files (see rm step below). Here’s how I did it:

  • Install VirtualBox with the latest Finnix Recovery Distro.
  • Add the .vdi file created above to the Finnix VM.
  • Boot Finnix
  • Mount the image
  • mkdir -p /mnt && mount -t ext4 /dev/sda2 /mnt
  • The reason RPi doesn’t boot with open vpn is because ifplugd tries to HOT plug it.  To fix this, explicitly list the real network interfaces in `/etc/default/ifplugd`:
    • Replace
    • INTERFACES="auto"
    • with
    • HOTPLUG_INTERFACES="eth0 wlan0"

    Failling that, you can always just remove all the init scripts that start openvpn.

  • rm /mnt/etc/rc*/*openvpn
  • Unmount
    • umount /mnt
  • Power off Finnix
    • shutdown -h now
  • Convert back to RAW format
    VBoxManage clonehd raspberrypi.vdi raspberrypi.raw --format RAW
  • Copy the image back onto the SD card:
    • sudo dd bs=32768 if=raspberrypi.raw of=/dev/rdisk2

Put the SD card in your Raspberry Pi and reboot!