Posterous
Arthur is using Posterous to post everything online. Shouldn't you?
3286618267_3db31c4cec_o_thumb
 

Arthur Chang

Getting data in rails ready for the iPhone with Property Lists (.plist)

Took me awhile to finally figure out exactly what the Property Lists were all about, once it came together, putting together a nice property list was pretty easy.  The problem I'm solving is giving a fairly static list of teams to an iPhone app.  The iPhone parses out binary plist files the most efficiently, so here it is if you want to generate these plists from a rails app:

First get an array of all the objects you want to put into the property list and create an plist array

 

teams = Team.find(:all)

plist_array = Array.new

teams.each do |team|

plist_array << {:id => team.id, :name => team.display_name}

end

 

This creates a nice array with a few attributes we want to add.  If you want all attributes added to the plist_array, instead of adding in a hash just add in team.attributes, which returns a hash of all attributes.  What comes next is the use of the plist gem

$ sudo gem install plist

 

The above will install the plist gem onto your machine, make sure it's unpacked and/or avai lable on your production servers if you want this to be performed there as well.  Once you have the gem installed, require the gem in your controller and you can use the .to_plist to basically dump the plist_array into the accepted XML Property List format.

plist_array.to_plist

 

This of course does not give you a binary file yet.  For that, use the plutil that is usually installed on mac osx machines.  Mine just came with it.  If your machine doesn't have the util, it's part of the developer tools on your OSX install disks.

$ plutil -convert binary1 filename.plist

 

The option -convert basically takes one conversion parameter, either being binary1 or xml1.  binary1 converts the file, designated in the next parameter (in our case filename.plist), that contains the output of the to_plist.  The to_plist outputs the XML format of the Property List, and -convert binary1 will convert it to a nice binary representation.  You can go backwards with -convert xml1

$ plutil convert xml1 filename.plist

 

When it converts, it resaves the file, filename.plist for example.  Once you get that binary file, you can use it easily on the iPhone for retrieving the data.

For some more examples of how people are using the plist gem see this post to get you started: http://stackoverflow.com/questions/1264329/getting-active-records-to-display-as-a-plist

Tagged  //   code   iphone   property lists   ruby on rails  
Posted December 1, 2009
// 0 Comments

On our way to Dog Patch Labs for #railsrumble

Woke up super early (5am) for the Rails Rumble 2009 competition.  The competition started about 12 hours ago, but we decided to get a little sleep in and start early this morning.  Here's our walk from the Embarcadero BART over to Dog Patch Labs on Pier 38 (townsend and embarcadero).  All photos taken from my iPhone and processed 2x through the Magazine filter on CameraBag.

Tagged  //   iphone   iphone photography   photography  
Posted August 22, 2009
// 0 Comments

Public transportation yields great photo ops

I'm in love with taking photos with my iPhone.  I'm never looking for perfect quality, sharp, well exposed shots, but more composition.  It's always really handy and super discreet.

I'm also completely infatuated with public transportation, and the stories it shows you in the form of riders.  Here's a shot I snapped while on the N Judah Muni train today:

 

Muni

Tagged  //   iphone   photography  
Posted August 21, 2009
// 0 Comments