Blog-o! Notes from latte.ca

Mon, 23 Mar 2009

(With thanks to Bunnyhero, both for the title, and the inspiration to get blogging again.)

As you can probably guess, if you’ve read Bunnyhero’s blog post, I recently learned that the AlertView delegate method alertView:clickedButtonAtIndex: can be called multiple times for one AlertView, much to my surprise.

And here’s how I found that out. A couple of weeks ago, I ran across a bug in my still-in-development iPhone game. I was displaying an alert when the game ended, and when the user clicked “Okay” it would go to the next level. And it all seemed fine until one day, when instead of clicking the “Okay” button, I hit the home button to exit the game while the dialog was displayed, and the next time I entered the app, there were, like, 40 robots where I was expecting 8!

As a favour to a friend of mine who’s a prof, I let the bug sit until I could debug the code in front of a room full of undergrads, as a part of the software engineering class he teaches. (The whole experience turned out to not only be something that I wished I could have seen when I was an undergrad, but also something really fun to do from the the industry-type person side of things! Anyone who has a laptop, and some code with a small bug that they don’t mind showing to a bunch of students should really give it a try!). Debugging the problem led me not to the archiver/unarchiver as I was expecting, but instead to the observation that when I hit the home button, my delegate method was being called up to 5 times!

This is why I saw way too many robots, because I was advancing 4 more levels than I should have been. And so when I re-entered the game, it happily put me on level 5-ish, instead of level 2.

The fix was fairly simple, if slightly inelegant. I merely added in a flag to tell me when I was handling an alert, and would only advance the level when I thought I had popped the alert up. (Now that I write it, I wonder if I can set the alert’s delegate to nil when I’m done handling it instead. Thoughts, anyone?)

[Posted at 21:55 by Blake Winton] link
Fri, 12 Dec 2008

The command to use is:

$ env CC=/usr/local/bin/arm-apple-darwin-gcc CC_FOR_BUILD=gcc ./configure --host=mac; make

Well, kind of. First you do that, then you copy gsc/gsc to gsc/gsc.onboard, then you go to a new directory, and type:

$ ./configure;make

and copy the gsc/gsc from that directory into the first directory.

To compile a script into an exe:

$ gsc/gsc -:=. -c euler.scm
$ gsc/gsc -:=. -link euler.c
$ /usr/local/bin/arm-apple-darwin-gcc euler.c euler_.c -Iinclude -Llib -lgambc -o euler

It's freaking huge!

$ ls -alh euler
-rwxr-xr-x   1 bwinton  bwinton  4M Jan 23 14:22 euler
$ ls -alh /WifiToggle
-rwxr-xr-x   1 bwinton  bwinton  17K Jan 16 14:07 /WifiToggle

And it's not a lot faster. 0.1643 seconds for the compiled version, as opposed to 0.1803 seconds for the interpreter.

But on my Mac:

$ more m1.c
power_of_2 (int x) { return 1<<x; }
$ more m2.scm
(c-declare "extern int power_of_2 ();")
(define pow2 (c-lambda (int) int "power_of_2"))
(define (twice x) (cons x x))
$ more m3.scm
(write (map twice (map pow2 '(1 2 3 4)))) (newline)
$ gsc/gsc -:=. -link -flat -o foo.o1.c m2 m3
$ /usr/local/bin/arm-apple-darwin-gcc -Iinclude -bundle -D___DYNAMIC m1.c m2.c m3.c foo.o1.c -o foo.o1
$ ls -alh foo.o1
-rwxr-xr-x   1 bwinton  bwinton    13K Jan 23 14:45 foo.o1

then on the iTouch,

# scp bwinton@latte.ca:/Users/bwinton/Programming/Bazaar/iTouch/gambc-v4_1_2/foo.o1 .
# gsi foo.o1
((2 . 2) (4 . 4) (8 . 8) (16 . 16))
# gsi
Gambit v4.1.2

> (load "foo")
((2 . 2) (4 . 4) (8 . 8) (16 . 16))
"/private/var/root/foo.o1"
> (twice 5)
(5 . 5)
> (pow2 10)
1024
[Posted at 17:09 by Blake Winton] link
Wed, 19 Nov 2008

Okay, one game in particular this time. One of my favourites from back in my Palm days.

Bike Or Die 2.
I can totally land this!

It’s awesome. It’s harder than I remember the Palm version being, but that's probably as much because I'm out of practice as anything else. After a couple of weeks of playing the beta version, I’m now at the point where I rarely hit the wrong button, even though they're on-screen instead of being hard buttons.

Not only is it a great game for what it is, but it’s got a ton of user-created levels, and an online high score board (which I’m nowhere near the top of). The re-playability of this game is stunning.

If you're still undecided, you can read the thread about it on TouchArcade. (Yeah, I’ve been answering a bunch of questions over there.) There’s also a video showing gameplay from the beta.

Finally, it only costs $2.99, but I hear it’s going up to $7 after the introductory period is over. (I suggested he sell it for $7.99-$9.99, but he’s apparently a nicer person than I am.)

(No, he’s not paying me for this. Heck, I didn’t even get an iTunes gift certificate for all my hard work finding bugs. I just really like the game.)

[Posted at 13:47 by Blake Winton] link
Tue, 30 Sep 2008

What more could I say?

VNC

Yeah, it’s my Windows box, displaying my iTouch’s screen, over VNC.

Pure coolness.

(Oh, and the song it’s playing is Fancy Footwork by Chromeo.)

[Posted at 17:03 by Blake Winton] link
Wed, 24 Sep 2008

A co-worker recently got a new iPhone, and I since he didn’t have many apps on it yet, I thought I’ld send him a list of the stuff I had bought/downloaded and enjoyed. So, without any further ado, here are a few of my favourites, all available on the AppStore.1

Toy Bot Diaries. (The link is to the free version, but I bought the full version.)
Wheeee!

Galcon. (The link is to the free version, but I bought the full version.)
Whoa!

Line Rider. ($2.99, but c’mon, it’s Line Rider. How can you not get it? ;)
Aaaaaah!

Twitterrific. (Free, but only useful if you’re on Twitter. Which I am. As bwinton.)
Chat!

TimmyMe. (Free, finds the closest Tim Hortons to you.)
Caffeine!

Tap Tap Revenge. (Free, like Dance Dance Revolution, but for your fingers. I actually don’t play this much, but it’s free.)
Ba dum dum dum!

PapiJump. (Free. By the guy who made the world’s most addictive Palm game, SFCave.)
Boing!

Labyrinth. (The link is to the free version. I didn’t buy the full version of this.)
Easy now!

Cube Runner. (Free. I got this after watching someone play it on the subway.)
Whoo-ha!

Enigmo. ($4.99, but really impressive. Really, really impressive.)
Ahhhh!

That’s about it…


  1. As opposed to Jailbreak apps, which I’ve got a few of. They tend to be more productivity/programming apps, which I didn’t think he’ld be interested in.  

[Posted at 13:58 by Blake Winton] link
Tue, 04 Mar 2008

Last night I was browsing the newest iTouch apps, and I saw one called LEDBanner. It allowed you to scroll text across your screen as if your screen was a set of LEDs. My only problem with it was that I couldn’t programmatically change the text. Fortunately the source was available, and so, with only minor changes, I now have a version which lets me change the text to whatever I want.

For instance, the following scheme code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#! /usr/bin/gsi(define (flmod x y) (fl- x (fl* (floor (fl/ x y)) y)))
(define (%100 time) (flmod (floor (time->seconds time))
(fixnum->flonum 100)))
(define (f)
  (begin
    (with-output-to-file
      (list
        path: "~/Library/Preferences/org.akamatsu.LEDBanner.msg"
        truncate: #t)
      (lambda () (display (%100 (current-time)))))
    (thread-sleep! 3)
    (f)))
(f)

changes the text every three seconds to the number of seconds, modulo 100. Which turns out to be a mostly-random number, as shown below.

The number 8.

[Posted at 16:09 by Blake Winton] link
Sat, 01 Mar 2008

One of the things I wanted to add to WifiToggle was having the icon show you whether your wifi was on or off, by having the switch be up or down (and the blue glow be on or off, since in Australia a down switch means that the light is on, whereas in Canada, it’s the opposite). Sadly, it didn’t seem possible, since Springboard1 seems to cache your icon.png, and ignore any updates you do to it. And so that was where I left it for a long time…

Recently, however, I was browsing through AppFlow and I noticed that the MobileCalendar application’s icon was different than the one in Springboard. Specifically, the one on AppFlow was blank, whereas the one in Springboard showed me the current day and date (i.e. "Saturday" and "1" for today). How did it do that? I grabbed the source, and grepped through it for the answer, which turned out to be a special key in the Info.plist:

<key>SBIconClass</key>
<string>SBCalendarApplicationIcon</string>

When I set WifiToggle’s SBIconClass key to be the same, I too had the day and date drawn on top of my icon! Partial success! So now I’m at the point of trying to figure out if I can use any class that implements the correct interface (I’m thinking specifically about adding a class to my application to handle the updates.) Of course, I have no idea what that interface is, but hey, I’m way closer than I was this morning, so that’s got to count for something.


  1. The application launcher on the iTouch.  

[Posted at 21:11 by Blake Winton] link
Fri, 18 Jan 2008

Yeah, like I was done messing with my iTouch. Whatever.

I've been playing around a lot with the iTouch, and developing quite a few programs for it. The first one was by request, although I’m also finding it very useful. (And apparently a few other people are as well! Cool!) It’s called WifiToggle, and it’s a small app that simply toggles on and off your Wifi connection, so as to save batteries. The next thing I did was a port of the SpiderMonkey Javascript interpreter. It works, and it wasn’t that hard to get compiled and installed, which is really pretty cool when you stop to think about it.

The final thing I got working just tonight (which I was playing around with mostly to take my mind off of stuff. See tomorrow’s post for details), was a port of the Gambit Scheme interpreter. I know, Scheme is just like Javascript, only with an uglier syntax, but I still like it, and hopefully the lack of punctuation will make it easier to use on the iTouch. Heh.

Anyways, if you own an iPhone or iTouch, and have jailbroken it, be sure to add http://iphone.latte.ca/ to your list of Installer sources, and geek out!

[Posted at 21:06 by Blake Winton] link
Fri, 28 Dec 2007

Because I was curious, and because it has Python, I figured I'ld give it a try, and see what happened...
The results are:

# ./bzr selftest
testing: /private/var/root/bzr-1.0/bzr
   /private/var/root/bzr-1.0/bzrlib (1.0.0 python2.5.1.final.0)

bzr: ERROR: exceptions.ImportError: No module named pyexpat

Traceback (most recent call last):
  File "/private/var/root/bzr-1.0/bzrlib/commands.py", line 802, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/private/var/root/bzr-1.0/bzrlib/commands.py", line 758, in run_bzr
    ret = run(*run_argv)
  File "/private/var/root/bzr-1.0/bzrlib/commands.py", line 492, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/private/var/root/bzr-1.0/bzrlib/builtins.py", line 2659, in run
    coverage_dir=coverage,
  File "/private/var/root/bzr-1.0/bzrlib/tests/__init__.py", line 2373, in selftest
    suite = test_suite()
  File "/private/var/root/bzr-1.0/bzrlib/tests/__init__.py", line 2531, in test_suite
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
  File "/private/var/root/bzr-1.0/bzrlib/tests/TestUtil.py", line 89, in loadTestsFromModuleNames
    _load_module_by_name(name)
  File "/private/var/root/bzr-1.0/bzrlib/tests/TestUtil.py", line 96, in _load_module_by_name
    module = __import__(mod_name)
  File "/private/var/root/bzr-1.0/bzrlib/tests/test_bundle.py", line 32, in <module>
    from bzrlib.bundle.bundle_data import BundleTree
  File "/private/var/root/bzr-1.0/bzrlib/bundle/bundle_data.py", line 42, in <module>
    from bzrlib.xml5 import serializer_v5
  File "/private/var/root/bzr-1.0/bzrlib/xml5.py", line 26, in <module>
    from bzrlib.xml_serializer import SubElement, Element, Serializer
  File "/private/var/root/bzr-1.0/bzrlib/xml_serializer.py", line 47, in <module>
    from xml.parsers.expat import ExpatError as ParseError
  File "/usr/lib/python2.5/xml/parsers/expat.py", line 4, in <module>
    from pyexpat import *
ImportError: No module named pyexpat

bzr 1.0.0 on python 2.5.1.final.0 (darwin)
arguments: ['./bzr', 'selftest']
encoding: 'ascii', fsenc: 'utf-8', lang: None
plugins:
  launchpad            /private/var/root/bzr-1.0/bzrlib/plugins/launchpad [unknown]
  multiparent          /private/var/root/bzr-1.0/bzrlib/plugins/multiparent.pyc [unknown]
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.

Doing a bit of googling led me here (or rather, the google cache of that page). which says:

# 1/ The python installation from the installer ("unjailed iphone") does not come with the pyexpat module.

So, that's a little surprising.

I tried to install easy_install, to try an "easy_install pyexpat", but because I'm missing a Makefile, that fails with the following:

# python ez_setup.py
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c7-py2.5.egg
Traceback (most recent call last):
  File "ez_setup.py", line 229, in <module>
    main(sys.argv[1:])
  File "ez_setup.py", line 163, in main
    from setuptools.command.easy_install import main
  File "build/bdist.linux-i686/egg/setuptools/__init__.py", line 2, in <module>
  File "build/bdist.linux-i686/egg/setuptools/extension.py", line 2, in <module>
  File "build/bdist.linux-i686/egg/setuptools/dist.py", line 5, in <module>
  File "build/bdist.linux-i686/egg/setuptools/command/__init__.py", line 13, in <module>
  File "/usr/lib/python2.5/distutils/command/bdist.py", line 29, in <module>
    class bdist (Command):
  File "/usr/lib/python2.5/distutils/command/bdist.py", line 37, in bdist
    "(default: %s)" % get_platform()),
  File "/usr/lib/python2.5/distutils/util.py", line 78, in get_platform
    cfgvars = get_config_vars()
  File "/usr/lib/python2.5/distutils/sysconfig.py", line 493, in get_config_vars
    func()
  File "/usr/lib/python2.5/distutils/sysconfig.py", line 352, in _init_posix
    raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: invalid Python installation: unable to open /usr/lib/python2.5/config/Makefile (No such file or directory)

And that was the end of that. Interesting, though...

Oh, yeah, and I ended up going with the iPod Touch (hereafter referred to as the iTouch) to replace my Palm TX. It's not the perfect device, as the above stack traces show, but it's pretty good, and a fair bit closer than the Palm TX was.

[Posted at 15:36 by Blake Winton] link