Hamish Rickerby

Moving to Melbourne and planning a big project

Undefined Method Rewind and Rails 2.3.3

| Comments

Today I updated a project I’m working on from rails 2.2.something to 2.3.3. Then, I started getting the following wacky error.

undefined method `rewind' for #<TCPSocket:0x3631e58>

Turns out if you see this after a rails 2.3.3 update, you might just need a phusion passenger update (I was on passenger 2.1.3, apparently this error happens on passenger 2.1.2 too)

sudo gem update passenger sudo passenger-install-apache2-module

Put the lines recommended by the install script in your apache config file, restart apache and you’re good to go.

Hope this helps someone.

USSD Codes on iPhone

| Comments

makeuseof.com have recently posted about 11 cool iPhone keypad codes - these are special codes (known as USSD codes) that send messages via the signalling channel direct to the core of a mobile operators network. These codes are nothing new, they have been around for years and years. They are also not generally universal (there are some standard, but they provide relatively boring functionality). Different networks can enable different functionality on different codes.

The codes can do boring things like retrieve your divert status from the network, return your IMEI or perhaps ICCID, but they can also interact with specialised applications driven via USSD Gateways to return useful information and execute transactions. These are applications that are sent specific codes by an operators core network, perform some processing on the data received, and return a response. Things that are non-standard that are enabled by USSD Gateways are services such as USSD-based prepay balance retrieval, USSD-topup, or interactions with NGIN features to alter a network based service.

I looked into USSD codes on the iPhone a while back, not to be used by users typing them in, but more to be used by applications querying information from the network via them. The reason why I wanted to programatically access them? To look at what’s possible for network operators or enterprises to release as iPhone based network service management applications.

Sadly, Apple have disable the use of USSD codes from within the (legitimate) iPhone sandbox available to developers (via the open URL methods, passing in a tel://xxxxxx URL). This means that there won’t be any applications from your operators that will make it easy to retrieve and change network settings that can be released thru the app store - at least not until Apple change their mind about interactions with USSD codes. Which is a pity - there are lots of useful services that would be useful to expose simple interfaces for usage for to the operators end users. USSD is an efficient, fast way to configure the network, using capabilities that most operators already have.

Yahoo and Microsoft - Micro-hoo, or Bingy!

| Comments

The recent deal announced between Microsoft and Yahoo strikes me as odd.

I understand that they are looking to create a competitor to Google in both search and advertising, but the “price paid” seems very high - at least on the part of Yahoo.

Major terms of the deal:

  • Microsoft will be powering Yahoo search
  • Microsoft have licensed Yahoo’s search technology for 10(!) years
  • Microsoft will run paid search via their search engine
  • Yahoo will be providing the advertising sales force for their combined “paid search” capability
  • Each company will still maintain separate advertising sales forces for other advertising
  • They enter a revenue sharing agreement, but Microsoft guarantee Yahoo will get at least existing revenues for the next 18 months
  • Microsoft pay most of its traffic acquisition costs

So, boiling it down, it appears Yahoo are giving up their search engine technologies (for at least 10 years) in conjunction for (at least current) revenues to be paid by Microsoft for algorithmic search advertising.

Microsoft have to maintain a sales force to sell other advertising, so they aren’t saving costs there. They are still having to maintain search so they aren’t saving costs there. They are paying Yahoo for traffic acquisition, and revenue for algorithmic search advertising, so they are losing money there. Their benefit seems to be

  1. Acquisition of a license for Yahoo’s search technology - given they’ve just released their own shiny new engine, is this an asset or liability?
  2. Traffic - this is what Microsoft are in the deal for for. Traffic from Yahoo.

10 years is a long time. Search changes a lot in 10 years. Google was only just starting out 10 years ago. Altavista (at least where I was using the web) was top dog back then. I’d be interested to see if Yahoo are going to maintain their search technology, or just let it die off. Is this a sign that they no longer want to compete in search, but be a destination that pulls together other properties (harking back to their very early days I guess). I guess time will tell if Yahoo’s apparent specialisation strategy was a sensible or dumb move. Microsoft are banking on Bing becoming a google killer, or at least a serious competitor, in the long term. They also apparently believe that paid search results are the way of the future - that’s why they want the traffic.

iTunes Connect Now Has Keywords

| Comments

Apple have added an extra attribute to applications on iTunes store - keywords.

You can configure your keywords with the “Edit Information” link against the application. SendIt4.me (iTMS) has already been updated :-)

Be careful though. It appears you can only update your keywords ONCE per application update - so make sure you choose the right ones the first time around - otherwise you’ll have to go through the painful approvals process to get it corrected.

The keywords should help with searching for your application within the store. Fingers crossed.

— EDIT —

You can also only have up to 100 characters for the keywords. Don’t get caught out! If you submit with more than 100, it tells you too late - you’ll have to resubmit your app to fix it.

My First iPhone App Approved - Finally

| Comments

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

| Comments

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

| Comments

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

| Comments

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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

1
2
3
4
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

| 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/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" >&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

| Comments

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.

1
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.

?