Archive for July 2010

Apple Service

I had reason to make my first visit to the new Perth Apple store this evening. I’ve had some trouble with my iPhone and made an appointment at the Genius Bar to see if they could sort it out.

Earlier this week I felt the iPhone get quite hot in my pocket and took it out to have a look. It felt hot to the touch, something seemed to be going wrong. I turned the phone off to give it a chance to cool and see if a power cycle would solve the problem. After turning it off, the phone would not turn back on and continued to generate heat for another 20 mins.

I’m not sure what went wrong, I thought maybe the CPU got pegged at 100% by some runaway process, but when it would not restart I thought maybe there was some fault with the battery chemistry. I guess I’ll never know.

In any case, I took the iPhone to the Apple store and explained the issue to a genius. He checked the phone for exposure to liquids and ran it through some other diagnostics. The phone didn’t respond to any of the tests, so the outcome was that the phone was replaced on the spot. Needless to say I’m quite pleased.

The interaction with the genius was very methodical, almost formal. My permission was asked before the phone was handled, and again before the SIM was removed. It was an unusual experience to not feel as though I was getting bullied by a salesperson.

Code that doesn’t suck

Once in a while I manage to belt out a bit of code that doesn’t suck. This is a post with one example. I have a csv file with a bunch of rows of data that need to be added to a database. I’m using the django python framework to develop a web front-end for the database, so using django to add bulk data from a csv file seemed like a good idea too. Here is some code:


#-------------------------------------------------------------------------------
def buildModel( model, row ):
# constuct an instance of the model
m = model()

# get a list of the fields in the model
fieldList = [ f.name for f in m._meta.fields ]

# add data to the fields
for i, fieldName in enumerate( fieldList ):
setattr( m, fieldName, row[i] )

return m

#-------------------------------------------------------------------------------
def loadData( fileName, appName, modelName ):
import csv
from django.db.models import get_model

# fetch the relevant model
model = get_model( appName, modelName )

# open file using csv module
csvReader = csv.reader( open( fileName ) )

# loop over every line in the csv file
for row in csvReader:
# create a model object using the data in row
o = buildModel( model, row )

# save company
o.save()

The loadData() method processes the csv file row by row. buildModel() takes advantage of the direct correspondence between the order of items in the row with the fields of the django model. The returned model is then save()’d to the database.

Nothing special, just worked out small and neat.