Archive for the Coding / Development category

April 4th, 2008

Web design pet peeves (number 352 in a series of 23238434)

Posted in Coding / Development, The Web by Diggory

Email addresses are not case-sensitive

I hit this *so* many times and it always drives me mad. Here’s the thing: email addresses are not case-sensistive. i.e. FOO@.BAR.COM is the same as foo@bar.com and FoO@bAr.CoM

Web designers always seem to forget this though – and it’s incredibly irritating, especially if you have a browser which has some form of ‘remember my details and auto-complete them’ function.

I can understand why it happens though, and here’s why. As a coder you think of things in terms of types and logic.

Types: Number-types are generally either floats (floating point numbers: 1.2, 3.1415, etc…) or integers (whole numbers 1, 2, 100232 etc…). Computers ‘think’ of numbers differently depending on whether they are whole number or not. Bits of text are often thought of as ‘strings’ (‘strings’ of characters) – think of a string of pearls where each pearl is a character.

Logic: Coders use logic to define behaviour in code – they set down rules for the computer to follow. i.e. ‘if this thing over here is equal to that thing over there then do this other thing.’ Many of these logical statements are combined to create behaviours that make-up software products – from your mobile phone, to this weblog, to your TV.

Anyway – back to the point – humans forget that computers see things in different ways – the human brain with it’s amazing ability for language and symbol analysis sees ‘Hello’ as having the same meaning as ‘hello’, whereas to a computer these two strings are completely different, so to a computer the correct response to the question ” is ‘Hello’ equal to ‘hello’ ” is “No.” Normally that’s fine in logic terms – the two strings are not identical – but when it comes to email addresses – this logic lets us down. It doesn’t matter what case the letters are, what we should be asking the computer is “does this string that the user gave *spell* the same as the string we are using as a reference?”

Of course a clever coder will take the case of the letters out of the equation by using a function which makes the two strings to compare both upper-case before it checks them for equality – so however the user types the email address (as long as it’s spelled correctly), the logic will come back and say – “yes – these two email addresses are the same.” This is such a common task that there are always (I assume) ready-made functions available to the coder in any language to turn a string into an upper-case string.

It just takes a little thought to make sure that you apply that function when checking email addressees. You’d be surprised how often it doesn’t happen though…

The same thing happens in other problem domains – e.g. usernames – my router has an admin account which allows me to configure it – let’s call it ‘admin’. If I use ‘Admin’ it fails to authenticate me. Usernames should not be case-sensitive, whereas passwords should.

Web servers / filenames are another case: http://www.foo.com/badger/ should be the same as http://www.foo.com/BADGER/ – Mac OS computers treat these two the same – UNIX machines don’t.

To humans, most strings are not case-sensitive, whereas to computers they are. Coders should think about this more often. Alas it’s easy for them to be caught out, since we don’t think like computers, and computers are ruthlessly logical and unforgiving when it comes to rules (which is why they work). They’re a bit like traffic wardens in that respect.

Rant over….

March 8th, 2008

Time machine is a little confused about maths (and iPhone SDK ramblings)

Hmmmm

“The backup is too large for the backup volume. The backup requires 4.2GB, but only 22.9GB are available.”

Just posting this bug so I can reference it in a bug report. It may be my fault though, because I’m using an unsupported volume: a drive on a remote machine on my local network backed-up over airport. Worth noting anyway.

Half of the backup happens to be a disc image of the iPhone SDK.

It looks from what I’ve seen so far: i.e. nothing but the video of the Apple announcement, and a few iTunes U Apple Developer Connection introduction videos, pretty good. I’m getting more and more keen to get an iPhone. I’ve been waiting for three things before I do: Version 2.0 of the phone hardware (hopefully with GPS and 3G), the SDK and an end to the network lock-in. I hate being told that to use a specific handset I have to use a specific GSM network, it’s just wrong. Now the SDK is here, I’m weakening…

The info about the SDK looks very impressive so far – Apple taking 30% of the revenue from sales of the apps seems a little bit steep – but (in my opinion) they generally tend to be a benevolent dictator. Symbian has had voluntarily signed apps for a long time, however, very few developers bother to sign their apps, so users tend not to care or know about code signing. Even worse – when they find out about code signing it tends to confuse them. Apple mandating signing of all code means it can be seamless.

Having a single channel of delivery for iPhone apps may, to many, seem draconian and I would imagine it’s not long until someone writes an app which Apple denies distribution, yet most people find inoffensive.

I don’t know…. I’m torn – Steve’s Reality Distortion Field has really got me this time, yet I still in my heart of hearts think ‘hey – this is *my* miniature, hand-held computer – how dare you tell me what I can and can’t install on it.’

My resistance to not having a physical keyboard is also waning, and although being a Nokia devotee since I first had a mobile phone (back in oooh 1996), and therefore a Symbian fan of late – my experience with the mail client on my E61 and the limitations of Series 60 compared to Mobile OS X (network/email/voip config on the E61 is a real bore – and it doesn’t get the concept of falling back to different networks depending on what’s available) make the iPhone a very desirable next phone. Plus I’m familiar with the development environment.

I have noticed, from my limited peeking around, that there is no access to the Bluetooth functions of the phone. I could be wrong about that though. I think that the intention is that most external comms are to be done via TCP/IP over the wifi hardware.

Anyway, enough of my prattling – congratulations to all the engineers at Apple who are delivering the SDK, it’s a stunning feat of engineering.

March 7th, 2008

Communications Specifications for the GlobalSat DG-100 GPS DataLogger

Time for one of my annual blog posts.

I recently bought a GlobalSat DG-100 GPS datalogger, which is a device that records your GPS position over time, so that you can later review those data, and do all sorts of fun things. I specifically wanted it for aviation, so you can review your flight track, and see how good your navigation is and how far off your desired track you wandered.

DG-100

There are Windows drivers for the device, and only a Windows utility for extracting the recorded tracks and altering it’s preferences. Normally this would preclude a Mac user like me from buying it, however, the nice people at GlobalSat have published the specifications for communicating with the device, and some people have made their own apps for talking to it. There’s a Windows .net application for it and a linux project for talking to it as well.

I’m in the early stages of writing a Cocoa app which will do the same for Mac OS X users.

Anyway – The spec was a bit dry, being a .txt file – so I’ve spruced it up a bit and put it into a web page for Google to index.

[edit] – Good lord, Google indexed this post in less than 17 minutes!

April 1st, 2007

Put XHTML template on Clipboard AppleScript

Posted in AppleScript, Coding / Development, Mac OS X by Diggory

Here’s another AppleScript: This one puts an xHTML template on the clipboard: Again, remove the Growl parts if you don’t use Growl.

set XHTMLTemplate to "< !DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">



"

set the clipboard to the XHTMLTemplate

tell application "GrowlHelperApp"
-- notify title "AppleScript Notification" description (noteText as string) icon of application "Script Editor.app"

set myAllNotesList to {"XHTMLTemplateToClipboard"}
register as application "XHTML Template to Clipboard" all notifications myAllNotesList default notifications {"XHTMLTemplateToClipboard"} icon of application "Finder.app"

notify with name "XHTMLTemplateToClipboard" title "XHTML Template 2 Clipboard" description "The XHTML Template has been put on the clipboard" application name "XHTML Template to Clipboard"
end tell"


Click this link to make a new Script in ScriptEditor containing the above script

April 1st, 2007

Put current IP address on Clipboard AppleScript

I never remember to post these scripts which I write and often use onto the web, so that Google can index them.

So in an attempt to solve that, here we go: Here’s an AppleScript that I use often via QuickSilver. It calls Growl so – if you don’t have Growl, remove the growl parts otherwise AppleScript will ask you where GrowlHelperApp is.


set theIP to do shell script "ifconfig | grep 'broadcast' | awk '{print $2}'"

set the clipboard to theIP

tell application "GrowlHelperApp"
set defaultNotification to "Put IP address on Clipboard"
set myAllNotesList to {defaultNotification}
register as application defaultNotification all notifications myAllNotesList default notifications {defaultNotification} icon of application "Finder.app"
notify with name defaultNotification title defaultNotification description "Your IP Address (" & theIP & ") has been put on the clipboard" application name defaultNotification
end tell

Click this link to make a new Script in ScriptEditor containing the above script

October 25th, 2005

Front Row / Back Row

Someone has hacked FrontRow so that it doesn’t require the Apple Remote control. The torrent file seems dead – but you can download it from here. (Standard warning – Downloading hacked software from unknown sources could be dangerous.)

Seems to work OK on my Powerbook.

I’ve been mucking around with trying to make my own clone of FrontRow (I call it BackRow) – so far it doesn’t do anything but scroll one menu. I’m not trying to make a MediaCentre app (like CenterStage – just a remote control like thing that uses AppleScript to control other apps.)

BackRow version 0.00000001a

April 15th, 2005

Natural Date Formatters are Cool.

The Cocoa Frameworks on Mac OS X have some very cool things in them.

One of the very, very coolest – that relatively few people know about, and I should imagine even less people use, are NaturalDateFormatters.

Bascially they allow you to enter a date in English-like syntax, and it will be automatically converted into a form that the computer recognises.

e.g. It’s a friend of mine’s birthday today, and another’s was a couple of days ago. I realised that I didn’t have their birthdays in the Address Book, so I added them pretty quickly, without ever looking at iCal – or clicking on the clock to get the date.

Here’s how: (2.4mb MPEG-4 Quicktime Movie)

Click for movie

Cool, n’est pas?

p.s. Rendez-vous’s new name (‘Bonjour’) is terrible.

March 3rd, 2005

OpenSource Updates

Posted in Coding / Development, Software by Diggory

I tend to swing between two different development modes: Web and Mac. I’ll get obsessed by one field for a while, then get very annoyed by it (or my lack of abilities in it) and switch to another.

At the moment, I’m on the software side and I’ve finally got into collaborating in some OpenSource projects – specifically:

Growl
A Notification System for Mac OS X. — 0.6 was Released a few days ago and has some nice improvements from 0.5. I predict that Growl will be one of the apps that really takes off in 2005. Together with QuickSilver it has totally changed my workflow. Look out for an extra called HardwareGrowler in the next release…
iTele
Bring the Digital TV into your digital hub. Drivers for various digital TV receivers (DVB/Freeview and the US ATSC system) and an app called iTele that allows you to watch and record. Yes, you’ve been able to have analogue tv capture for a while – but analogue is rubbish. Using Digital keeps the whole thing clean and you don’t get a generational loss. Another cool thing about DVB is that you can decode several channels at once (as long as you have the horsepower and the channels are on the same Multiplex.) There are several relatively cheap PCI or USB2 tuners which are compatible.

Decoding BBC 1 2 3 4

In related news – more info on Sky’s HD plans.

The CenterStage Project
A project to build a ‘Media Centre’ app for Mac OS X. Less than two weeks old, but already has a nice site and what looks like the beginnings of a good, highly expandable architecture. Haven’t actually contributed here, but am watching its infancy with great interest. Could well tie in with iTele in the future
Cocoalicious
Buzz Andersen’s client for posting to del.icio.us. Essential for us delicious junkies.
February 3rd, 2005

DysleXcodia

Posted in Coding / Development by Diggory

What happens when XCode goes mad and decides that certain letters are evil?

DysleXcodia

I know that code looks Greek to most people – but it’s not meant to look like that. Have a look at the pop-up menu in the toolbar called “Active Build Style” – it’s like a crossword puzzle. (It’s meant to say ‘Development’)

Most peculiar.

August 13th, 2004

Subversion

Posted in Coding / Development by Diggory

I’ve always wanted to get to grips with Source Control Systems, not because I work on code simultaneously with others – but for their ability to keep old versions of sources long after you’ve changed them. CVS (Concurrent Versions System) is the standard tool for this kind of thing – but I always put off learning about it in any great detail because it seemed rather complex.

XCode 1.5 was released recently and one of the new features is support for Subversion. Subversion is widely touted as the sucessor to CVS and has several features that CVS lacks.

Great timing then for O’Reilly’s MacDevCenter to publish an article that wraps up how to set-up your own Subversion repository on Mac OS X.

It’s really more straightforward than I thought – and after a few hours reading the Subversion Book I had a working repository and a rough knowledge of how to use it.

Apple has documention for how to use Subversion in XCode.

Then, once you’ve got the hang of it all – revel in the glory that is SCPlugIn – A framework and Finder plug-in that allows svn commands via the contextual menu in the Finder – and badges the files icons depending on their status:

Subversion Badged Folders

Very cool.

July 26th, 2004

Local HTML Validation

Posted in Coding / Development by Diggory

W3C

How to install the W3C HTML validator on your own mac.

“Arise, Sir Tim!”
Arise, Sir Tim!

November 28th, 2003

A joke stolen from a Slashdot Post

Posted in Coding / Development by Diggory

A Software Engineer, a Hardware Engineer and a Departmental Manager were on their way to a meeting in Switzerland. They were driving down a steep mountain road when suddenly the brakes on their car failed. The car careened almost out of control down the road, bouncing off the crash barriers, until it miraculously ground to a halt scraping along the mountainside. The car’s occupants, shaken but unhurt, now had a problem: they were stuck halfway down a mountain in a car with no rakes. What were they to do?

“I know”, said the Departmental Manager, “Let’s have a meeting, propose a Vision, formulate a Mission Statement, define some Goals, and by a process of Continuous Improvement, Change Management, Re-Engineering and Service Integration, find a solution to the Critical Problems, and we can be on our way.”

“No, no”, said the Hardware Engineer, “That will take far too long, and besides, that method has never worked before. I’ve got my Swiss Army knife with me, and in no time at all I can strip
down the car’s braking system, isolate the fault, fix it, and we can be on our way.”

“Well”, said the Software Engineer, “Before we do anything, I think we should push the car back up the road and see if it happens again.”

October 22nd, 2003

Note To Self – Conditional Logging

Posted in Coding / Development by Diggory

Some times when developing an application it makes life easy if your code spits out information to the console using NSLog. This is known as CaveMan debugging :)

You don’t want end users to have to endure console Tourettes though, and commenting out the logging statements every time you build for distribution would be a little annoying. What to do?

Here’s a way to have logging statements that don’t appear in release code.

In Project Builder you have different Build Styles for Targets. These Build Styles contain Build Settings that affect the how the Product (your application) is built. The Build Settings add to, or override, the Target’s Build Settings.

With every new Project in Project Builder there are two default Build Styles.
Development
Development Build Style
and Deployment.
Deployment Build Style

When you build with the Deployment style the final product will be smaller in file size, but harder to debug. This is because this build style asks the compiler to strip out debugging symbols and optimise the code.

We are going to add a new Build Setting to the Development Style:

OTHER_CFLAGS = -D_DEBUG_

The OTHER_CFLAGS key is described in The Project Builder Build Settings Documentation:

“This setting defines flags passed to the compiler for all C and ObjectiveC compiles. This flag can be used cases where there is no other build setting for a particular feature.”

The Value for this build setting: -D_DEBUG_ is the flag we are passing to the compiler (GCC)

man gcc tells us that the -D switch defines a macro with a value of 1. The macro name we have chosen is _DEBUG_

So what the build setting does is define a macro so that whenever _DEBUG_ is found in the source the pre-processor will substitute 1. (And of course this only applies to the Development Build Style.)

Now we can put statements like this into our code:

#if _DEBUG_

NSLog(@”awakingFromNib”);

#endif

So – if we are building with the Development Style – the Logging line gets compiled in also.

Cool.

October 22nd, 2003

note to self – App Name Formats

Posted in Coding / Development by Diggory

[this entry is a note to myself - I always forget which way round these are]

?Display name? is the short name for this bundle; for example, ?Sketch.? It should contain only one or two words and a maximum of 16 characters. For an application, this is the name of the first menu in the menu bar. It corresponds to CFBundleName. By default, the field is empty.

?Short version? is the bundle?s full name and version number; for example, ?Apple Sketch 1.1.0.? By default, the field is empty.

?Get-Info string? is any information you want to appear in the Finder?s Info window. Generally, it?s the bundle?s full name, version number, and copyright information. For example, ?Apple Sketch 1.1.0; Copyright ©2001, Apple Computer Inc.? It corresponds to CFGetInfoString. By default, the field is empty.

September 12th, 2003

All the way back…

Posted in Coding / Development by Diggory

I was looking through my audio CDs looking for old CDs to rip that I had previously overlooked. I came across this:

you can see more of them here:

Ah – that sends me back – 1990 – AppleTalk networking and HyperCard ;)

The CD sleeve notes are quite funny in a “Thank God for USB / FireWire” kind of way :