Archive for the 'Code' Category

Howto build devkitARM on Mac OS X 10.4 (Tiger)

devkitARM release 23b is compiled on OS X 10.5 (Leopard) and most likely will not work on OS X 10.4 (Tiger) because it has been linked against different libraries (libiconv, libSystem.B). devkitARM is the toolchain of choice (read: only) for developing Nintendo DS Lite applications.

Here’s a summary on how to build it yourself:

My system
OS X 10.4.10
gcc version 4.0.1 (The version that comes on your install CD)
Target: i686-apple-darwin8

Building pre-requisites and devkitARM

FreeImage 3.10.0 (http://freeimage.sourceforge.net/download.html)
wget http://downloads.sourceforge.net/freeimage/FreeImage3100.zip
unzip FreeImage3100.zip
cd FreeImage
make
sudo make install

GMP 4.2.2 (http://gmplib.org/#DOWNLOAD)
wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.2.tar.bz2
tar jxf gmp-4.2.2.tar.bz2
cd gmp-4.2.2
./configure –build=none-apple-darwin –disable-shared –enable-static –prefix=/usr/local
make
sudo make install

MPFR 2.3.1 (http://www.mpfr.org/mpfr-current/#download)
wget http://www.mpfr.org/mpfr-current/mpfr-2.3.1.tar.bz2
tar jxf mpfr-2.3.1.tar.bz2
cd mpfr-2.3.1
./configure –disable-shared –enable-static –prefix=/usr/local
make
sudo make install

Buildscripts (devkitPro source)
Get it from http://sourceforge.net/project/showfiles.php?group_id=114505
&package_id=124206&release_id=609056

rm -rf /opt/devkitpro
tar jxf buildscripts-20080624.tar.bz2
cd buildscripts
mv config.sh config.sh.old
sudo ./buildscripts.sh

Choose devkitARM and say you want to download source packages
Enter install directory as: /opt/devkitpro

devkitARM will be installed in /opt/devkitpro if all went well. Make sure you moved anything important out’ve the directory before rm -rf’ing it.

I think that’s all - I typed this from memory - took about 25 min to build everything on my Intel macbook.

Obsessing over Processing

Processing is a programming language I discovered a few months ago - it’s a domain-specific language meant to introduce and teach non-programmers the basics of computer programming, via a visual context. It has been aimed at artists and design groups, but despite offering a very low barrier of entry to graphic programming, I think that the majority of users come from a technical background (or perhaps technical/design).

The inimitable John Resig of jQuery fame, has by some super-human feat, managed to port Processing to JavaScript, calling it Processing.js.

Here’s a pretty example to look at if you’re in Firefox/Webkit browser. Watch out for major CPU use (heaven forbid CPU’s are used for processing!).

Shortly after this ridiculousness, I discovered Obsessing.org, which is a web-based IDE and runtime environment for Processing.js. The editing seems a bit um, poor - I couldn’t get copy/paste to work - but nevertheless, this is awesome.

First post (in months)!

This week was the first time I’ve looked at AppleScript, Apple’s built-in scripting language that can be used for routine tasks, or controlling other applications. The reason I even bothered to investigate it was because when I moved all my work onto my laptop I also moved my music collection to an external hard drive and played it via the laptop (since it seemed a bit silly to have a whole other computer on just playing music). And as it goes, iTunes is _the_ music library/player for this platform, so I didn’t really have a huge choice in what to use. Granted, iTunes on OS X is a lot better than the Windows version, much like Safari Windows versus OS X Safari.

Anyway, one feature that that iTunes really lacks is the ability to find a track in your music library and hit “queue” to queue the selected song to play directly after the current song has finished. There is “Play this song next in Party Shuffle”, but it stops the song that is currently playing and jumps straight to the party shuffle playlist.

I decided to try write some code to add this feature in, and a very cool feature of AppleScript is that you can write something in the editor and then copy it to the application’s Script folder, and it’ll automatically appear in the Script menu (provided the application has an AS bridge) when you fire up the app (pretty much like a plugin). This is great, because it means I can write a helper script for a closed source program and have it installed in a matter of minutes. There’s no need to recompile the parent application, or find a suitable scripting bridge language, it all just works straight away.

I’m sure I have missed a simpler way of adding this functionality, but as far as I can tell because these scripts are external to the application, you cannot implement stateful operations without using a “Stay open” script, which is Apple-speak for a script that stays in the background until you tell it to quit (most scripts are once off operations that quit once finished).

To install, open ScriptEditor in your applications folder, paste the below code in, then Save as:

/Users/username/Library/iTunes/Scripts/Queue Next

Make sure you save the script as “application” type, with the Stay Open checkbox checked. Restart iTunes and there should be a new menu icon just before “Help” in the menu bar, it looks like a little scroll. Click it and you’ll find the name of your script. You can then open System Preferences - Keyboard & Mouse, and add a new keyboard shortcut to iTunes that calls the script.

global queuePlaylist

tell application "iTunes"
  if not (exists playlist "Queued") then
    make new user playlist with properties \
      {name:"Queued", shuffle:false, song repeat:off}
  end if

  set queuePlaylist to playlist "Queued"

  if current playlist is not queuePlaylist then
    set curtrack to (duplicate current track to \
       queuePlaylist)
  else
    set curtrack to {}
  end if

  if selection is not {} and current playlist is not \
      queuePlaylist then
    set sel to a reference to selection
    duplicate sel to queuePlaylist
  end if

  if curtrack is not {} then
    set playPosition to (player position + 1)
    play curtrack
    set player position to playPosition
  end if
end tell

on idle
  tell application "iTunes"
    if player state is not stopped and current playlist \
        is queuePlaylist then
      return (duration of current track) - player position
    else
      play playlist "Music"
      set view of front browser window to playlist "Music"
      tell me to quit
    end if
  end tell
end idle

The original code for the queue script came from Mac OS X Hints.

Here’s a post explaining how to use Ruby to replace AppleScript.

This syntax highlighter doesn’t like long lines, and this new Wordpress keeps fucking my stuff up (I’ve marked wrapping lines with \’s in the code). Trying to fix.

Google Gears

Google have released a beta of Gears - a browser plugin (.xpi for Firefox) that allows you to store offline content on a user’s hard-drive, via javascript. This allows AJAX web applications to continue working offline, using the stored content. I lambasted JavaFX for the same feature, but I only realised what they might’ve meant after looking at the Gears examples, and the potential therein. It’s not so much a case of fetching new data from the server, but say in the case of Google Apps, continuing to edit a spreadsheet even though you’re offline. Gears could then synchronise your local copy to the server when you connect again. JavaFX should’ve compared itself to Gears, if it were around.

There’s also a local SQLite database you can run queries on through javascript, and it also provides a non-blocking thread system so that you can run intensive javascript without locking up your web app.

Unfortunately this all only works after you’ve installed the plugin, which I imagine is some horrid ActiveX affair in IE on windows.

Does JavaFX Spell The End Of AJAX? No.

World, this is a press release. Press release, say hi to the world…

Does JavaFX Spell The End Of AJAX?

You know all that AJAX code you’ve been writing and tearing your hair out over as you attempt to get the JavaScript working in both Internet Explorer and Firefox? Yeah, that AJAX code.

Oh, that thing I use JQuery for (or some another reasonable library)? No, I’ve never really had javascript compatibility issues - I’m more scared of the inconsistencies in HTML and CSS between the two browsers.

It’s all going to be useless real soon.

Sure, I’m sure there are more people with the Java Runtime installed with a vaguely decent internet browser than people with just a vaguely decent internet browser.

JavaFX will also trigger desktop integration of over-the-wire applications with Java, rather than relying on a constant connection for the JavaScript used in AJAX.

There are more perks with JavaFX, Sun officials claim. One of the knocks on AJAX applications, aside from browser compatibility, is that it requires a large amount of JavaScript to be sent over the wire; that script could have something malicious embedded in it.

Constant connection? Large amount of javascript? 3kb of cacheable javascript versus a 50mb JRE download? Ok, so javascript code that is plainly visible for anyone to read via their view source option in the browser, is worse than some proprietary module that sits on my machine and has potential access to my HDD?

So instead of relying on the browser to sandbox off JavaScript code, the applications use the security features in Java SE to control an application’s hard drive access. Because it runs on the client and is not dependent on code sent over the wire, it also means applications written in AJAX, such as Google Apps, can be used offline.

Where exactly are you going to get the information to return via JavaFX if you’re offline? Wait, unless all you’re talking about is fancy special effects… which AJAX can also do whilst disconnected…

I think someone has gotten very confused and is comparing JavaFX to the nearest big thing she/he could think of. JavaFX is obviously some kind of competitor to Silverlight and Adobe’s Flex or whatever it’s called, and hence is catering to a different kind of development problem that AJAX caters for.

coza Registration

Does registering a .co.za domain annoy you? Having to copy/paste your address everywhere? Well, it annoyed me enough to make this little web-based form that’ll spit out a copy of the text form ready for you to email off (once you’ve confirmed it manually, of course).

coza Registration form generator

Also, some people are under the impression that registering a .co.za is hard - quite the opposite, it’s just a bit time-consuming. Once you have your nameservers and they have records for your domain, fill in the form and send it off. Provided everything is ship-shape you’ll get a confirmation email back shortly, and you can then deposit your annual registration fee.

What else is up? Not much, working. Saturday’s Nirvana tribute at Mercury was really good, louder and heavier than the Armchair gig (which is good, but the quieter gig was also really cool). Hot Fuzz (the new Simon Pegg/Edgar Wright movie) is really funny, I’d recommend seeing Shaun of the Dead first though. Actually, try pick up some copies of Big Train before as well… if you’re really dedicated!

Job part 2

Time for that follow-up post; but first, let’s take a look at something deeply disturbing.

Like me, the author is having trouble with the fact that 199 out of 200 applicants for every programming job can’t write code at all. I repeat: they can’t write any code whatsoever.

Why can’t programmers… program?

Maybe 2 years ago - fresh from my degree - I would’ve thought that perhaps half of people claiming to be able to program would be bullshitting, or at least vastly exaggerating their skills. *cough* Nowadays, after spending my time with various people and companies, helping out, working, I think I can quite strongly agree that there is a large group of very deluded people out there.

Programming isn’t some trivial task that anyone can do, neither is it rocket science (ok, bad analogy), but it is a skill like any other. Some people can do it, some people can’t - some people are insanely good at the little details, some people are great at seeing the bigger picture. Some people should not be left in charge of a computer system. Ever.

I might not be a great programmer, but I’m consistent and thorough - thorough, to me, doesn’t mean releasing 0-bug code though; I am strongly of the opinion that the end-user must test and report back bugs or mis-labeled features. Doing so requires a cooling-period, there should always be a period of time where things are tested and reviewed. Yet, time and time again people I have worked with have scrapped production code for basically new untested code. Why on earth would this ever be a good idea.

Anyway, reporting back on fresh travesties of code and assaults on common sense:

Apparently a Javascript script running on a user’s PC (Javascript is NOT Java by the way) can cause a CPU load spike on the web server that is serving the content. So, a script that doesn’t communicate with the server (no AJAX), a script that runs in a sandbox, in a browser, on a PC miles away from the server, is responsible for a 328 load on a single CPU box. For those of you not in the web development field, the mere statement that Javascript is capable of running server-side is akin to me telling a car mechanic that the puncture in my front left tyre is making my back right tyre deflate. Back in the real world, the obscene load was caused by some circular requires (no use for require_once here, thanks).

Similarly, back in outer space, MySQL is now able to store multi-byte data in single-byte data columns. Even kanji, of which there are around 10 000, can be stored in a column with a 255 character space. 7Zip move over, we have a new compression contender. Additionally, for those of you who thought that internationalising your project was going to be a huge hassle, it now seems that the quickest and easiest way to add UTF8 support is to open each source file and go to your IDE’s File menu, and then change the file encoding to ‘UTF8′. It really is that easy.

I’d continue, but I actually feel bad for what I’ve written already. I think further illustration of what is painfully obvious is unnecessary.