My first iPhone app approved - finally

Posted in apple, iphone, mobile development on May 11th, 2009 by Hamish Rickerby – Be the first to comment

Send real postcards to your family and friends with SendIt4.me, now available as an iPhone client. The application is 100% free and each postcard you send will cost $2USD. The postcards can be sent anywhere in the world, and postage time is dependent on your international and local mail services (they are posted from the US, so if you live there you should get it quicker).

Download now!

sendit4me

Sidenote: I submitted this application initially to Apple on the 18th Jan 2009. It was finally approved tonight. There was only 1 “Please wait” mail, and one “We need some help testing it” mail - too long in my opinion.

Feedzirra

Posted in ruby, software on March 20th, 2009 by Hamish Rickerby – Be the first to comment

Feedzirra is an RSS feed fetching and parsing library that I quite like. For a project I’m working on with a mate we need to be able to parse and receive updates from (potentially) a large number of RSS feeds. Feedzirra seemed the ticket, but didn’t have support for itunes style RSS feeds - so I added it.

This was basically my first (well, second, but that wasn’t public) go with github, and first contribution to an open source project. Paul Dix accepted my code, and I’m oddly excited about it all.

AND to make things even better, someone has already started to enhance my contribution. Woo hoo!

ESTA and Confusion

Posted in travel, web on March 2nd, 2009 by Hamish Rickerby – 1 Comment

I went to look at the ESTA website today as my girlfriend needs to apply for one of these authorisations to be allowed to travel to the US.

The website was very intimidating, and confusing.

  1. The URL - if you’re providing an online site that every traveller to the US has to visit to get an authorisation to travel my advice would be choose a URL that is easier to remember than https://esta.cbp.dhs.gov/
  2. The warning message - one sure fire way to scare users is to show them a message that looks like this when they connect to the site

    picture-5
    Note: There is no expectation of privacy when you use this computer system
  3. Make it doubly confusing by completely contradicting the previous message on a “Help” page within the site.
    picture-4
    Note: Is this Web site secure and private? Yes.

Dealing with SemanticHacker in Ruby

Posted in ruby on February 26th, 2009 by Hamish Rickerby – Be the first to comment

I’m having a bit of a play with SemanticHacker at the moment, seeing what their service thinks of some text I’m poking at it. To make this a bit simpler I created a small ruby lib that wraps their API to make my life a little easier. And hopefully it’ll make someone elses life easier - enjoy.

(It requires hpricot for XML parsing - make sure it’s installed)

require 'rubygems'
require 'hpricot'
require 'cgi'
require 'open-uri'

class SemanticHacker

  URL = "http://api.semantichacker.com"
  attr_accessor :token, :doc, :content

  def initialize(token)
    @token = token
  end

  def get_signature(content)
    @content = ::CGI::escape(content)
    url = "#{URL}/#{@token}/signature?content=#{@content}"
    @doc = Hpricot.XML(open(url))
  end

  def get_concepts(content)
    @content = ::CGI::escape(content)
    url = "#{URL}/#{@token}/concept?content=#{@content}"
    @doc = Hpricot.XML(open(url))
  end

  def get_categories(content)
    @content = ::CGI::escape(content)
    url = "#{URL}/#{@token}/category?content=#{@content}"
    @doc = Hpricot.XML(open(url))
  end

  def type
    (doc/:response/:about/:systemType).inner_html
  end

  def config_id
    (doc/:response/:about/:configId).inner_html
  end

  def categories
    response = []
    (doc/:response/:categorizer/:categorizerResponse/:categories/:category).each do |item|
      response << {:id => item.attributes['id'], :weight => item.attributes['weight']}
    end
    response
  end

  def concepts
    response = []
    (doc/:response/:conceptExtractor/:conceptExtractorResponse/:concepts/:concept).each do |item|
      response << {:label => item.attributes['label'], :weight => item.attributes['weight']}
    end
    response
  end

  def signatures
    response = []
    (doc/:response/:siggen/:siggenResponse/:signature/:dimension).each do |item|
      response << {:index => item.attributes['index'], :weight => item.attributes['weight']}
    end
    response
  end

end

And to make things happen

sh = SemanticHacker.new("mysecrettoken")
sh.get_signature("Wow!  Some semantic analysis on my text")
puts sh.signatures.inspect
#returns an array of hashes with the weights and indexes of the categories

Installing f2c on a mac

Posted in Uncategorized on February 20th, 2009 by Hamish Rickerby – 3 Comments

I have recently had to install f2c on my mac to convert Fortran to C code - for the gory details about this library check http://www.netlib.org/f2c/f2c.pdf

Also, don’t ask why I’m installing this - lets just say there is some maths that needs doing, and fortran has the libraries to help with it.

The installation process on the mac isn’t really catered for with the package, and it’s not available via macports.  I found an install script at http://hpc.sourceforge.net/buildf2c but I found it doesn’t work as advertised.

Below is a fixed version of this script - hope this helps someone. This will download the source as well as build and install it.

#!/bin/sh
############################################################
# This UNIX script builds the f2c FORTRAN --> C translator #
# under Mac OS X.                                          #
# Make this script executable with "chmod +x buildf2c"     #
############################################################
echo "==================================="
echo "Build f2c FORTRAN --> C translator."
echo "==================================="
echo "USAGE:  ./buildf2c"

######################################
# Set trap to allow abort on signal: #
######################################
trap 'echo "Interrupted by signal" >&amp;amp;2; exit' 1 2 3 15

########################################################
# 1. Download f2c source from Bell Labs.               #
# (Tar file is not visible - it's created on the fly.) #
########################################################
echo "--------------------------------------------"
echo "1. Downloading f2c source from Bell Labs ..."
echo "--------------------------------------------"
# wget --passive-ftp ftp://netlib.bell-labs.com/netlib/f2c.tar
curl http://netlib.sandia.gov/cgi-bin/netlib/netlibfiles.tar?filename=netlib/f2c -o "f2c.tar"
echo "... done."

#####################################
# 2. Uncompress f2c tarred archive: #
#####################################
echo "-------------------------------"
echo "2. Uncompressing f2c source ..."
echo "-------------------------------"
tar -xvf f2c.tar
gunzip -rf f2c/*
cd f2c
mkdir libf2c
mv libf2c.zip libf2c
cd libf2c
unzip libf2c.zip
cd ../..
echo "... done."

###############################################################
# 3. Prepare the unix makefiles for building the f2c library. #
#    Note: CC compiler switched from 'cc' to '/usr/bin/cc'   #
###############################################################
echo "-------------------------------------------"
echo "3. Preparing makefiles for building f2c ..."
echo "-------------------------------------------"
sed 's/CC = cc/CC = \/usr\/bin\/cc/' f2c/libf2c/makefile.u > f2c/libf2c/makefile
sed 's/CC = cc/CC = \/usr\/bin\/cc/' f2c/src/makefile.u > f2c/src/makefile
echo "... done."

##########################################
# 4. Create and install f2c header file. #
# If you use a C++ compiler:  make hadd  #
# Otherwise:                  make f2c.h #
##########################################
echo "----------------------------------------------------"
echo "4. Creating and installing f2c header file f2c.h ..."
echo "----------------------------------------------------"
cd f2c/libf2c
make f2c.h
if test ! -d /usr/local/include; then
mkdir -p /usr/local/include
fi
cp f2c.h /usr/local/include/
echo "... done."

################################################
# 5. Create and install f2c library "libf2c.a" #
################################################
echo "-----------------------------------------------------"
echo "5. Creating and installing f2c library "libf2c.a" ..."
echo "-----------------------------------------------------"
make
if test ! -d /usr/local/lib; then
mkdir -p /usr/local/lib
fi
cp libf2c.a /usr/local/lib/
ranlib /usr/local/lib/libf2c.a
echo "... done."

######################################
# 6. Make executable f2c translator: #
######################################
echo "---------------------------------------------"
echo "6. Creating and installing f2c translator ..."
echo "---------------------------------------------"
cd ../src
make
if test ! -d /usr/local/bin; then
mkdir -p /usr/local/bin
fi
cp f2c /usr/local/bin/
ln -s /usr/local/bin/f2c /bin/f2c
echo "... done."

################################################################
# 7. Install fc script:                                        #
#                                                              #
# 1. Remove "-Olimit 2000" in the -O processing options within #
#    the 'fc' script.                                          #
# 2. Eliminate all references to the math library (-lm) in     #
#    the script 'fc' since it is included the System framework #
#    and is linked by default under Mac OS X.                  #
# 3. Eliminate '-u MAIN__' at the bottom of the 'fc' script.   #
#    You will have to explitly load FORTRAN MAIN programs      #
#    (explicitly mention the relevant .f or .o file).          #
################################################################
echo "---------------------------"
echo "7. Installing fc script ..."
echo "---------------------------"
cd ..
mv fc fc.orig
sed 's/ -Olimit 2000//g; s/ -lm//g; s/ -u MAIN__//g' fc.orig > fc
chmod +x fc
cp fc /usr/local/bin/
ln -s /usr/local/bin/fc /bin/fc
ln -s /usr/local/bin/fc /bin/f77
echo "... done."

#########################
# 8. Install man pages: #
#########################
echo "---------------------------"
echo "8. Installing man pages ..."
echo "---------------------------"
cp f2c.1t /usr/share/man/man1/f2c.1
echo "... done."

################
# 9. Clean up: #
################
echo "------------------"
echo "9. Cleaning up ..."
echo "------------------"
cd src
make clean
cd ../libf2c
make clean
cd ../..
echo "... All done!"

#############################################
# 10. Test f2c on your FORTRAN source code: #
#############################################
echo "======================================================"
echo "======================================================"
echo "======================================================"
echo "   === To test f2c on your FORTRAN source code: ==="
echo "   === cd ~/wherever/your/code/is               ==="
echo "   === 1. f2c myprog.f                          ==="
echo "   ===    cc -O -o myprog.exe myprog.c -lf2c    ==="
echo "   ===    myprog.exe                            ==="
echo "   === 2. fc -O -w -o myprog.exe myprog.f       ==="
echo "   ===    myprog.exe                            ==="
echo "======================================================"
echo "======================================================"
echo "======================================================"

exit

cocos2d-iphone blocking touch events

Posted in apple, iphone, mobile development on February 1st, 2009 by Hamish Rickerby – 1 Comment

The game development is going well so far.  From yesterday when I knew NOTHING about game development I’ve managed to figure out how to use sprites, labels, timed actions, sequenced actions, scenes and layers with cocos2d-iphone.

I did hit a strange error though.  On the simulator the touch events were working correctly - screens transitioning, sprite/label touches generating events and triggering animation and so on.  On the actual device the story was quite different.  My menu items were triggering correctly, but no subsequent touch events were doing anything on the phone.  When the application exited (home button) all the touch events were then passed through as I could see them all fly up the screen in the console.

A long search in google yielded the following page:  http://groups.google.com/group/cocos2d-iphone-discuss/browse_thread/thread/8aae440d81721ff4

I don’t know what causes the actual issue, but the fix is to alter the Director.m’s main method - adding the following code fixed the issue right up.


while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES) ==  kCFRunLoopRunHandledSource) {}; 

The odd thing is (and let me know if I’m wrong here) that that code doesn’t actually do anything.  It performs a test, but changes nothing.  I don’t get why this fix works.

?

error on line 1987

Posted in apple, iphone, mobile development on January 31st, 2009 by Hamish Rickerby – Be the first to comment

I am having a bit of a play with the cocos2d game engine for iPhone and encountered a very strange error in the console - I don’t believe it’s at all related to the game engine itself, so it’s just coincidence that I was trying something new out.

error while killing target (killing anyway): warning: error on line 1987 of “/SourceCache/gdb/gdb-962/src/gdb/macosx/macosx-nat-inferior.c” in function “macosx_kill_inferior_safe”: (os/kern) failure (0×5x)

I figured out that it had to do with definition of a selector… Naughty code below.

MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
                                        target:self
                                      selector:@selector(startGame)];

The problem is that the method name inside @selector() MUST have a colon on the back of it.

Good code

MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
                                        target:self
                                      selector:@selector(startGame:)];

Hope that’s useful to someone.

User Preferences on iPhone

Posted in apple, iphone, mobile development, software on January 4th, 2009 by Hamish Rickerby – Be the first to comment

Getting and setting user preferences on iPhone is pretty darn easy.  I was looking for a way to automagically store a users email address between different application sessions, and found the linked tutorial immensely helpful (iphonedevelopertips.com).

I needed to store a string (NSString object actually) however, and the tutorial didn’t help me with that. The NSUserDefaults object has dedicated methods for storing and retrieving BOOL, float, and NSInteger values.  It also has a setObject:forKey: method - which is what I ended up using.  The setObject method handles data of types NSData, NSString, NSDate, NSArray or NSDictitionary - making it incredibly useful indeed.

My Preferences.h

#import <Foundation/Foundation.h>
#import "Constants.h"
@interface Preferences : NSObject {
}
+ (NSString *)emailAddress;
+ (BOOL)setPreferences:(NSString *)emailAddress;
@end

My Preferences.m

#import "Preferences.h"

@implementation Preferences

/*-------------------------------------------
* Return the users default email address
*-------------------------------------------*/
+ (NSString *)emailAddress {
  NSString *returnValue;
  // If preference exists
  if ([[NSUserDefaults standardUserDefaults] stringForKey:kPreferencesEmailAddress]) {
    returnValue = [[NSUserDefaults standardUserDefaults] stringForKey:kPreferencesEmailAddress];
  } else {
    returnValue = @"";
  }
  return returnValue;
}

/*-------------------------------------------
* Write preferences to system
*-------------------------------------------*/
+ (BOOL)setPreferences:(NSString *)emailAddress {
  // Set values
  [[NSUserDefaults standardUserDefaults] setObject:emailAddress forKey:kPreferencesEmailAddress];
  // Return the results of attempting to write the preferences to system
  return [[NSUserDefaults standardUserDefaults] synchronize];
}
@end

kPreferencesEmailAddress is a constant I’ve defined with the key value of the users email address. It just makes sure I don’t mistype anything.

Key (only) differences between my code and the code at iphonedevelopertips.com are the use of the objectForKey method to set the NSString value, and stringForKey to retrieve the object and cast it to a NSString object.

Hope that helps someone!

Last Days: Woolworths

Posted in business on January 2nd, 2009 by Hamish Rickerby – Be the first to comment

Went into Woolies here in Reading a couple of days ago to see what was left on the shelves. They truly are selling everything. People were literally buying the shelves the remaining products were sitting on. I also saw them offering the tills for £150 - considered getting one so I could play shopkeeper, but no.

Some pics of the carnage

Pretty much everything was gone. Apart from the below fella’s book. Give it up!  People won’t even buy your work when it’s heavily discounted.

Poor Cliff.

That’s not the end of Woolworths for those in the southern hemisphere however.  The brand lives on as a supermarket - I do remember Woolworths being a cheap department/variety store in New Zealand when I was very young, but it transitioned to a supermarket there many years ago.

I won’t miss Woolworths. I only ever bought 1 pair of gardening gloves and a can of “V” from it.

Zazzle discount vouchers / codes

Posted in Uncategorized on December 27th, 2008 by Hamish Rickerby – Be the first to comment

I received a package I ordered from Zazzle today and it contained some discount vouchers that I won’t be using. Codes below - tell me if they don’t work so I can update the post to show they are gone.

  • $10 (USD I assume) orders of over $10 or more - expiring 31st Dec 2008 - ZAZZLE10GIFTAYJTRYRM and ZAZZLE10GIFTDFWCINBI
  • $5 off purchase of $50 or more (I reckon this is multi-use) expiring 18th Jan 2009 - ZAZZLEWINTER

Enjoy!