<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Talk Funnel &#187; Tech</title>
	<atom:link href="http://ramin.firoozye.com/category/tech/feed/" rel="self" type="application/rss+xml" />
	<link>http://ramin.firoozye.com</link>
	<description>Ramin Firoozye's Public Whisperings</description>
	<lastBuildDate>Fri, 02 Jul 2010 22:19:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A Visitor&#8217;s Guide to WWDC and San Francisco</title>
		<link>http://ramin.firoozye.com/2010/06/04/a-visitors-guide-to-wwdc-and-san-francisco/</link>
		<comments>http://ramin.firoozye.com/2010/06/04/a-visitors-guide-to-wwdc-and-san-francisco/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 09:14:21 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[San Francisco]]></category>
		<category><![CDATA[wwdc]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=261</guid>
		<description><![CDATA[It&#8217;s time, once again, for the annual love-fest that is WWDC and that starts next week. I&#8217;ve been to each one since the iPhone launch (I know, that makes me a relative newbie) but having spent a good chunk of the past two decades living in San Francisco, I figured I&#8217;d combine tech-tips for first-time [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right;" src="http://ramin.firoozye.com/wp-content/uploads/2010/06/wwdc20102.jpg" border="0" alt="wwdc2010.jpg" width="144" height="150" /></p>
<p>It&#8217;s time, once again, for the annual love-fest that is <a href="http://developer.apple.com/wwdc/">WWDC</a> and that starts next week. I&#8217;ve been to each one since the iPhone launch (I know, that makes me a relative newbie) but having spent a good chunk of the past two decades living in San Francisco, I figured I&#8217;d combine tech-tips for first-time attendees with social things to do for out-of-towners.﻿</p>
<h3>Tech Tips</h3>
<ul>
<li>You can register and get your badge on Sunday, the day before WWDC starts. That saves you a bit of time doing it on Monday when everyone stands in line to get into the keynote speech. If you do go in on Sunday then you may want to pop into <a href="http://sfmacindie.com/">sfMacIndie</a> at <a href="http://sanfrancisco.jilliansbilliards.com/">Jillian&#8217;s</a> in the Metreon at 6pm. It&#8217;s across the street from Moscone West. Grab a drink and chat up fellow developers. You may want to pace yourself. The next day is the big event and you want to be able to get there early &#8212; at least by 8am if not sooner. They don&#8217;t start letting you in until 9:30am so wear comfy shoes. Make sure to say hi to fellow line-standers as you hop from foot-to-foot trying to stay warm.</li>
<li>This is San Francisco. In June. This means chances of early morning sun are slim to none. Standing in line for the keynote means no moving for hours in the cold, blowing fog. Unless you&#8217;re seriously thick-skinned (like the poor, freezing <a href="http://venturebeat.com/wp-content/uploads/2009/06/iporn.jpg">iPorn girls</a> of last year) bring layers and be prepared to discard them as the day wears on and temperatures rise.</li>
<li>The on-screen keyboard on the iPad is nice, but don&#8217;t forget your laptop. You will want to take notes. Lots of notes. And fast. As <a href="http://www.marco.org/661870733">Marco Arment says</a> WWDC is one giant info-dump and there is no way to absorb everything. You&#8217;ll need a real keyboard to keep up. I like to create separate folders for each session and save note files in TextMate. Under each folder you can also save sample code for the sessions. Then I throw the whole top-level folder into TextMate as a project so I can quickly search and find what I&#8217;m looking for. I suggest you try to capture as much as you can while there and take time later to go over things. They were pretty quick about posting up the videos of each session last year, but there&#8217;s no replacement for one&#8217;s own notes.</li>
<li>Head down to the lunch area on the ground floor around noon. The food&#8217;s nothing to write home about (yeah, I&#8217;m being polite) but it&#8217;s a good chance to meet people and find out common interests. Most of the other times you&#8217;ll be standing in line or in-session. This is your chance to have a decent conversation and who knows, learn a thing or two from fellow developers. I&#8217;ve always enjoyed these random encounters.</li>
<li>If you have questions or want to get feedback from Apple engineers and designers, sign up for the labs and do it early. Spaces fill up fast, especially for the UI Design reviews. Drift down to the cafeteria area on the ground floor and find out what the sign-up protocol is. On the rare occasion there isn&#8217;t an interesting session, hover around the lab areas. You&#8217;ll pick up great info just by listening to Apple folks explain how things work.</li>
<li>Try to bring a Verizon or Sprint MiFi. The Apple-supplied WiFi network is OK, but most of the time it gets overloaded. Forget AT&amp;T&#8217;s 3G network. It&#8217;s a joke. With most people carrying a MacBook, an iPhone, and an iPad, your best bet is to bring your own network. The downside to this is you probably won&#8217;t be able to access the WWDC attendee-only content accessible to those on the network there. But once you&#8217;ve snagged all the goodies you can switch back to your own network and zip along. [<em>Update:</em> OK, maybe <a href="http://gigaom.com/2010/06/07/steve-jobs-survives-gizmodo-but-not-mifi/?utm_source=gigaom&amp;utm_medium=recent-posts">not such a good idea</a> if everyone turns them on at once.]</li>
<li>If you bring your own network, make sure you set a secure password for access to the wireless hub. And for crying out loud, don&#8217;t make it the 40-bit WEP. Go for the WPA2. Way too many people running <a href="http://www.wireshark.org/">Wireshark</a> or <a href="http://www.kismetwireless.net/">Kismet</a> out there. Also, while you&#8217;re at home set up all your network devices to log in, then set the hub to not broadcast its SSID. That way all those other people around you won&#8217;t have to scroll through a gajillion wireless hotspot names.</li>
<li>Bring a comfortable backpack. The one they&#8217;ve been handing out to WWDC attendees the last few years is pretty minimalistic. If you need space for all your gear (and an extra sweater) then bring your own. Don&#8217;t worry about food, unless you need to snack often. They provide bagels and cookies and whatnot to keep you fueled up.</li>
<li>Sync up your dev iPhone or iPad at home and back everything up. There&#8217;s a good chance there will be a new SDK drop there with a bunch of new goodies. Recommend you not try to download over the WiFi. Walk over to one of the round tables outside the session rooms and plug into the Ethernet firehose. Much, much faster.</li>
<li>Please, oh please remember to turn down the volume on your phone/iPad/Mac during sessions. Yes, you know you&#8217;re on Twitter and now we do too. You can thank <a href="http://furbo.org/">chirping bird man</a> for that.</li>
<li>If your backside is sore from all the sitting down or you feel like taking a quick nap, there are bean-bags on the top floor. First come-first serve.</li>
<li>If you&#8217;re looking for a job or have a job to post there are white-boards in the bean-bag lounge area.</li>
<li>Stash a power-strip in your pack &#8212; it&#8217;s a good way to make friends.  Among tech conferences WWDC is one of the better ones for providing power to attendees. Even so, they sometimes run out of plugs. I&#8217;m partial to the <a href="http://www.monstercable.com/productdisplay.asp?pin=4220">Monster Outlets to Go</a> units. They&#8217;re small and you can charge up most of your devices in one sitting. Some models even come with built-in USB charging ports. While you&#8217;re at it remember to bring separate power-to-USB adapters for your iPhone and iPad. The iPhone is happy with the <a href="http://store.apple.com/us/product/MB352LL/B">small 5W units</a> but the iPad needs the beefier <a href="http://store.apple.com/us/product/MC359LL/A">10W adapters</a>. If space is a premium you may want to grab a couple of <a href="http://www.amazon.com/gp/product/B00295RB3S">retractable USB cables</a> too.</li>
<li>If you&#8217;re missing anything or forget to bring any hardware, your two nearby geek supply outlets are the <a href="http://www.apple.com/retail/sanfrancisco/">Apple Store</a> on Stockton Street and <a href="http://www.centralcomputers.com/">Central Computer</a> on Folsom at 4th.</li>
</ul>
<p>OK, so much for the conference itself. What about the social life?</p>
<h3>Organized Events</h3>
<p>Here&#8217;s a good reference for organized after-session gatherings: <a href="http://wwdcparties.com/">http://wwdcparties.com﻿</a>. On Tuesday between 7:30 and 10:30 pm, however, a lot of people will likely head over to the Apple Design Awards ceremony. A large number will stick around for the Stump the <span style="text-decoration: line-through;">Chumps</span> Experts session. On Thursday night Apple throws a bash in Yerba Buena Gardens. You&#8217;ll need your WWDC badge to get in. If you&#8217;re of drinking age you&#8217;ll need to get a wrist-band at Moscone before heading over. Pace yourself on the booze if you plan on hitting any other places afterward. You get all the food and beer you can consume plus a (surprise) live musical act. And there&#8217;s still Friday&#8217;s sessions left.</p>
<h3 style="font-size: 1.17em;">Quick Eats</h3>
<p>If you get tired of eating pre-packaged sandwiches and are hankering for something slightly different, here are a few places within easy walking distance of Moscone. However, no guarantee they&#8217;ll get you in and out in time for the afternoon sessions:</p>
<ul>
<li><a href="http://westfield.com/metreon/ourstores/all-dining-2043.html">Food court at Metreon</a> - Walk across the street, grab yourself something and go sit outside in Yerba Buena Gardens to decompress. Absolutely glorious if it&#8217;s sunny.</li>
<li><a href="http://www.chow.com/restaurants/39386/taqueria-cancun">Taqueria Cancun</a> - Bit of a hike up on 6th and Market, but decent enough Mexican fare.</li>
<li><a href="http://www.outthedoors.com/">Out the Door</a> &#8211; (sorry, Flash site) is by the same people who run the outstanding <a href="http://slanteddoor.com/">Slanted Door</a> in the Ferry Building. This one&#8217;s in Westfield (Nordstrom) shopping center on Market and 5th.</li>
<li><a href="http://www.specialtys.com/">Specialty&#8217;s</a> &#8211; Great sandwiches. Best part is they have an <a href="http://www.specialtys.com/mobile">iPhone-friendly ordering service</a>. Closest one is on New Montgomery between Mission and Market.</li>
<li><a href="http://www.thesentinelsf.com/">The Sentinel</a> &#8211; I haven&#8217;t eaten there yet, but people keep recommending it and it&#8217;s top of my list for lunch places to try. Fancy-looking sandwiches.</li>
</ul>
<h3 style="font-size: 1.17em;">Coffee</h3>
<p>The swill they serve at WWDC may be fine for getting you over your previous night&#8217;s hangover, but you owe it to yourself to get some decent coffee while in town. Good places within walking distance:</p>
<ul>
<li><a href="http://bluebottlecoffee.net/cafe.html">Blue Bottle</a> - Just go. Get the Latte if you&#8217;re in a hurry or the drip coffee if you have time. Don&#8217;t worry, it&#8217;ll make sense once you get there.</li>
<li><a href="http://www.peets.com">Peet&#8217;s</a> - Closest one is on Mission between 3rd and New Montgomery. Strong coffee. Puts hair on your chest, whether you want it or not.</li>
<li><a href="http://www.chatz.com/">Chatz</a> - Bit of a hike on 2nd Street between Howard and Folsom, but good place to go if your feet need some stretching.</li>
</ul>
<h3>﻿Local Watering Holes</h3>
<p>For some reason after a day of technical brain-melding a lot of people are extra-primed to kick back and partake of adult beverages. Go figure. If that&#8217;s what you&#8217;re looking to do, here&#8217;s a number of local hangouts where you are sure to bump into fellow WWDC attendees:</p>
<ul>
<li><a href="http://sanfrancisco.jilliansbilliards.com/">Jillian&#8217;s</a> &#8211; It&#8217;s across the street, doubles as a sports bar, has a large selection of beers on tap, and has pool tables in the back.</li>
<li><a href="http://www.thirstybear.com/">Thirsty Bear Brewing</a> &#8211; Upscale brewpub. Decent beers and Tapas-style dishes, only a block away.</li>
<li><a href="http://www.thechieftain.com/">Chieftain&#8217;s</a> &#8211; Grungy Irish pub. First stop for a lot of die-hard old-timers before they inexplicably head all the way out to&#8230;</li>
<li><a href="http://www.tommystequila.com/">Tommy&#8217;s Mexican Restaurant</a> &#8211; A favorite of Apple folks, but it&#8217;s all the way out in outer Richmond. With places like <a href="http://www.tresagaves.com/locations/sf">Tres Agaves</a> or dive bars like City Bar in the Mission you&#8217;d think someone would try to find something more accessible. It&#8217;s far away, in the fog zone, and the place is usually mobbed but if you do decide to head out to Tommy&#8217;s try to snag a ride with someone else&#8211;preferably a teetotaler. There&#8217;s a chance you&#8217;ll end up slamming tequila shots and trust me, you won&#8217;t want to be driving, flagging down a rare cab, or being at the mercy of Muni late at night.</li>
<li><a href="http://www.harlotsf.com/">Harlot</a> &#8211; Decent, but small. Odds are there will be a line to get in.</li>
<li><a href="http://www.starwoodhotels.com/whotels/property/overview/index.html?propertyID=1153">XYZ bar at W Hotel</a> &#8211; Upscale drink spot. Excellent place to hang out if you&#8217;re on a corporate expense account or your app just cracked the Top 10.</li>
</ul>
<h3>A little further out &#8212; but still worth it</h3>
<p>Want to pretend you&#8217;re a local? Some are a bit of a walk, but if you get in with a group of fellow developers and want to get out of the Folsom/Howard zone, here are a few places to try (in no particular order):</p>
<ul>
<li><a href="http://theirishbank.com/">Johnny Foley&#8217;s</a> - Irish Pub within walking distance. It can get a bit touristy, but there&#8217;s nightly live music and (natch) Guinness on tap.</li>
<li><a href="http://www.zeitgeistsf.com/">Zeitgeist</a> - Sort of a cross-road of cultures and styles. No other way to describe it.</li>
<li><a href="http://www.sfstation.com/orbit-room-cafe-a892">Orbit Room Cafe</a> - Best damn Bloody Marys in town.</li>
<li><a href="http://www.thehotelutahsaloon.com/">Hotel Utah</a> - Grungy local spot, sometimes with good music.</li>
<li><a href="http://www.bottomofthehill.com/">Bottom of the Hill</a> - Great place for local live indy bands. Out in Potrero Hill (accessible via the Muni T-line) but the music&#8217;s usually worth the trip.﻿</li>
<li><a href="http://asiasf.com/">AsiaSF</a> - The waitresses double as transgender stage performers &#8212; and they&#8217;re awesome.</li>
<li><a href="http://www.21st-amendment.com/">21st Amendment Brewery</a> - Big with the local tech types floating around 2nd street. Decent brews.</li>
</ul>
<p>Obviously I&#8217;m leaving a lot out, but this should give you a decent starting point. Feel free to post any corrections or favorites in the comments. Hope to see you all at WWDC. If anyone wants to look me up and say hi, I&#8217;m <a href="http://twitter.com/raminf">@raminf</a> on Twitter.</p>
<p> </p>
<p><em>Update</em>: Added a few more places &#8212; for those in a hurry to get back to hacking and getting their mind blown.</p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2010/06/04/a-visitors-guide-to-wwdc-and-san-francisco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoPark: my first iPhone app</title>
		<link>http://ramin.firoozye.com/2010/02/01/autopark-my-first-iphone-app/</link>
		<comments>http://ramin.firoozye.com/2010/02/01/autopark-my-first-iphone-app/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 16:30:01 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[autopark]]></category>
		<category><![CDATA[frolicware]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=256</guid>
		<description><![CDATA[There&#8217;s been a lot of behind-the-scenes activity around these parts and I hope to be posting more actively from here on out. But first I&#8217;d like to announce my first iPhone product on the AppStore, published under the FrolicWare label: AutoPark: Say Goodbye to Parking Tickets. It lets you keep track of time on your [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s been a lot of behind-the-scenes activity around these parts and I hope to be posting more actively from here on out. But first I&#8217;d like to announce my first iPhone product on the AppStore, published under the <a href="http://frolicware.com" target="_blank">FrolicWare</a> label:</p>
<p><img src="http://d1avqodpi540yc.cloudfront.net/i/screenshots/ap06s.png" alt="" /></p>
<p><a href="http://autoparkapp.com" target="_blank">AutoPark</a>: <em>Say Goodbye to Parking Tickets.</em> It lets you keep track of time on your meter so you avoid parking tickets. It uses push notifications to send out an early-warning and a separate meter expiration alarm. The intent behind it, however, was to be an all-in-one driving assistant so it does a few more things, like:</p>
<ul>
<li>Help find a parked car using the GPS.</li>
<li>Remember where you parked in a parking lot (floor, section, color zone, etc).</li>
<li>Work with or without push alarms enabled (if away from the data network).</li>
<li>Track time on parking meters or with pre-paid parking machines.</li>
<li>Attach a text and picture note &#8212; handy for remembering what that rental car looks like.</li>
<li>Email all parking data out via a rich HTML message with embedded map and links.</li>
<li>Get a list of nearby local services (bank, gas station, bathrooms) you might need when you&#8217;re parking your car or right before leaving.</li>
</ul>
<p>it&#8217;s available for $4.99 <a href="http://itunes.apple.com/us/app/autopark/id335354555?mt=8" target="_blank">on the AppStore</a> and the first user reviews have been pretty positive. It&#8217;s already made it into <a href="http://macworld.com/article/145871/2010/01/autopark.html" target="_blank">MacWorld Magazine</a>!</p>
<p>But this isn&#8217;t just about a single iPhone app. There are a lot of posts rattling around my head that I&#8217;ll be rolling out gradually: from the evolution of the UI and graphic design, to running a one-person development shop, the economics of app development, the transition to iPad, tips and tricks on developing a push server, and the process of marketing an iPhone app. From conversations with fellow iPhone developers I get the feeling this is information that could be useful to others in their own efforts.</p>
<p>When the AppStore was first announced, I remember thinking this is the first time an individual or a small team can easily bring a software product to market without having to worry about a lot of the hassles of full-bore software publishing. I still think that&#8217;s the case, but I was off by an order of magnitude on the <em>it&#8217;ll be easy</em> department. I&#8217;m going to write about this experience because I think it&#8217;s good to get these things out there for all those people dreaming about starting their own gig.</p>
<p>In the meantime, here&#8217;s a <a href="http://slideshare.net/raminf/iphone-backend-servers" target="_blank">presentation</a> I gave at the January 2010 Silicon Valley iPhone Developer Meetup on development of back-end servers for iPhone apps. I tried to avoid making it about a specific product but it relies heavily on the experience of putting together the AutoPark push notification server.</p>
<p>This is only the first app out of the chute and this is the first post on what goes on behind the scenes. So stay tuned&#8230;</p>
<hr />
<p>P.S. I&#8217;ll be showing off AutoPark (and maybe a peek of an upcoming app) at <a href="http://macworldexpo.com" target="_blank">MacWorld Expo</a> in San Francisco February 9-13, 2010 at the Mobile Application Showcase. This is the first year they&#8217;re featuring iPhone apps so it&#8217;ll be interesting to see how they&#8217;re received in a historically Mac-only conference. It&#8217;s also my first time as an exhibitor (and yes, I&#8217;ll be blogging about it).</p>
<p>Feel free to pop over and say hi.</p>
<hr />
<p><strong>Update</strong>: AutoPark won <a href="http://www.macworld.com/article/146297/2010/02/bos2010_winners.html">Best of Show</a> at Macworld 2010 and got <a href="http://www.find.macworld.com/appguide/app.html?id=369299">4.5 out of 5 mice</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2010/02/01/autopark-my-first-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Push Notification and Python (Django)</title>
		<link>http://ramin.firoozye.com/2009/09/09/push-notification-and-python-django/</link>
		<comments>http://ramin.firoozye.com/2009/09/09/push-notification-and-python-django/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 09:36:25 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=128</guid>
		<description><![CDATA[I&#8217;ve been trying to get the iPhone Push notification services introduced in OS 3.0 working with Python (specifically, Django). It took a while but I figured I&#8217;d post my notes so it&#8217;ll spare someone the suffering I had to go through. Other attempts at this (apns-python-wrapper (aka APNSWrapper) and Lee Packham&#8217;s code) both use the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to get the iPhone Push notification services introduced in OS 3.0 working with Python (specifically, <a href="http://www.djangoproject.com/" target="_blank">Django</a>). It took a while but I figured I&#8217;d post my notes so it&#8217;ll spare someone the suffering I had to go through.</p>
<p>Other attempts at this (<a href="http://code.google.com/p/apns-python-wrapper/" target="_blank">apns-python-wrapper</a> (aka <code>APNSWrapper</code>) and <a href="http://leenux.org.uk/2009/07/14/push-on-the-iphone/" target="_blank">Lee Packham&#8217;s</a> code) both use the standard <code>ssl</code> libraries which I couldn&#8217;t get to work under Snow Leopard and Python 2.6.</p>
<p>I eventually got it going with Django and <a href="http://sourceforge.net/projects/pyopenssl/" target="_blank">pyOpenSSL</a> libraries. The easiest way is to get the prebuilt <a href="http://www.egenix.com/products/python/pyOpenSSL/" target="_blank">pyOpenSSL binaries from eGenix</a>. If the test server is running on Snow Leopard the <em>Python 2.6 UCS2</em> version seems to work best.</p>
<p>The thing about <code>pyOpenSSL</code> is that it expects the certificate and private key to be in separate <code>.PEM</code> files so you have to export each one from <code>KeyChain Access</code> in <code>.P12</code> format then convert them to <code>.PEM</code> from the command line. For the development key it&#8217;s easier to specify the password during export then strip it out on the command line. In production you may not want to do that.</p>
<pre class="brush: bash">
   % openssl pkcs12 -clcerts -nokeys -out devcert.pem -in devcert.p12
   % openssl pkcs12 -nocerts -out devkey.pem -in devkeypw.p12
   % openssl rsa -in devkeypw.pem -out devkey.pem
</pre>
<p />
<p />
Now copy <code>devcert.pem</code> and <code>devkey.pem</code> (with no password) into the server directory.</p>
<p>The following bit of code is in a file called <code>PushSender.py</code> and does the actual talking to the push server (I heavily edited out project-specific bits and standard exception and error-handling stuff. Hopefully didn&#8217;t bork it too badly <img src='http://ramin.firoozye.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Also, in this example the actual communication runs in a thread. In some cases it might make more sense to run it as a main routine:</p>
<pre class="brush: python">
import os, sys
import struct, binascii, ssl, datetime
import threading
import simplejson as json
from socket import socket
from OpenSSL import SSL

class PushSender(threading.Thread):
def __init__(self, sandbox, token, message, badge, sound):
	super(PushSender, self).__init__()
    		self.token = token
    		self.sandbox = sandbox
    		self.message = message
    		self.badge = badge
    		self.sound = sound
    		self.ctx = SSL.Context(SSL.SSLv3_METHOD)
    		if sandbox:
    			self.apnHost = &quot;gateway.sandbox.push.apple.com&quot;
    			self.ctx.use_certificate_file(os.path.join(PROJECT_ROOT, &quot;devcert.pem&quot;))
    			self.ctx.use_privatekey_file(os.path.join(PROJECT_ROOT, &quot;devkey.pem&quot;))
    		else:
    			self.apnHost = &quot;gateway.push.apple.com&quot;
    			self.ctx.use_certificate_file(os.path.join(PROJECT_ROOT, &quot;prodcert.pem&quot;))
    			self.ctx.use_privatekey_file(os.path.join(PROJECT_ROOT, &quot;prodcert.pem&quot;))

    	def run(self):
    		payload = {}
    		aps = {}
    		if (self.message):
    			aps[&quot;alert&quot;] = str(self.message)
    		if (self.badge):
    			aps[&quot;badge&quot;] = self.badge
    		if (self.sound):
    			aps[&quot;sound&quot;] = str(self.sound)

    		payload[&quot;aps&quot;] = aps

    		token = binascii.unhexlify(self.token)
    		payloadstr = json.dumps(payload, separators=(&#039;,&#039;,&#039;:&#039;))
    		payloadLen = len(payloadstr)
    		fmt = &quot;!cH32sH%ds&quot; % payloadLen
    		command = &#039;\x00&#039;
    		msg = struct.pack(fmt, command, 32, token, payloadLen, payloadstr)
    		sock = socket()
    		s = SSL.Connection(self.ctx, sock)
    		s.connect((self.apnHost, 2195))
    		s.send(msg)
    		s.shutdown()
    		s.close()
</pre>
<p>[ <a href="http://www.firoozye.com/download/PushSender.txt" target="_blank">PushSender source</a> ]</p>
<p>To invoke it in a thread (the first param is <em>True</em> for sandbox and <em>False</em> for production server) from the main routine:</p>
<pre class="brush: python">
	from PushSender import PushSender
	...
	pushsender = PushSender(True, token, pushmessage, pushbadge, pushsound)
	pushsender.start()
</pre>
<p />
<p />
On the phone the token returned by the <code>didRegisterForRemoteNotificationsWithDeviceToken</code> method is in the form <code>&lt;xxxxxxxx xxxxxxxx ...&gt;</code>. To pass it along to the server you have to strip out the <code>&lt;&gt;</code> and spaces. The <code>unhexlify</code> method then converts this string into a 32-byte hex binary value. The easiest way to strip out the extraneous stuff is to just do it on the client-side:</p>
<pre class="brush: cpp">
    NSString *deviceToken = [[[[tokenString description]
			stringByReplacingOccurrencesOfString:@&quot;&lt; &quot; withString:@&quot;&quot;]
			stringByReplacingOccurrencesOfString:@&quot;&gt;&quot; withString:@&quot;&quot;]
			stringByReplacingOccurrencesOfString: @&quot; &quot; withString: @&quot;&quot;];
</pre>
<p />
<p />
One last thing: at least with the sandbox if the phone is running on WiFi sometimes push notices don&#8217;t come through. This may be due to router NAT or firewall configuration issues. One way to check is to go into XCode Organizer while the phone is tethered and run your app, then under the Organizer Console you can check for errors. To get around this you&#8217;ll want to turn off the WiFi on the phone and go with 3G. This usually makes push notices arrive as expected (and strangely enough the WiFi method goes back to working for a few minutes). </p>
<p>There&#8217;s more that needs to be done to make it production-ready but at least it&#8217;s good to know it&#8217;s doable:</p>
<div style="text-align:center;"><img src="http://ramin.firoozye.com/wp-content/uploads/2009/09/cp18s.png" alt="cp18.png" border="0" /></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2009/09/09/push-notification-and-python-django/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Debugging peer-to-peer and wifi apps on the iPhone</title>
		<link>http://ramin.firoozye.com/2009/06/18/debugging-peer-to-peer-and-wifi-apps-on-the-iphone/</link>
		<comments>http://ramin.firoozye.com/2009/06/18/debugging-peer-to-peer-and-wifi-apps-on-the-iphone/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 21:48:53 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=114</guid>
		<description><![CDATA[If you&#8217;re developing an iPhone application that uses WiFi networking or the new Gaming Kit (Bluetooth) at some point you&#8217;ll want to test the code on two devices side-by-side. At this point you will realize that: a) You can only run one instance of XCode on your machine at a time. b) Debugging one device [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ramin.firoozye.com/i/wifi.jpg" width="119" height="53" alt="" /> <img src="http://ramin.firoozye.com/i/bluetooth.jpg" width="210" height="56" alt="" /></p>
<p>If you&#8217;re developing an iPhone application that uses WiFi networking or the new Gaming Kit (Bluetooth) at some point you&#8217;ll want to test the code on two devices side-by-side. At this point you will realize that:</p>
<p>a) You can only run one instance of XCode on your machine at a time.</p>
<p>b) Debugging one device at a time is a royal PITA.</p>
<p>c) Your only option is to beg, borrow, or steal another Mac then install all of XCode and your code onto it just so you can do some debugging.</p>
<p><img class="alignleft" src="http://ramin.firoozye.com/i/musicman.jpg" width="144" height="199" alt="" /></p>
<p>I&#8217;m here to tell you there&#8217;s a better way.</p>
<p>The solution is to use <a href="http://www.vmware.com/products/fusion/" target="_blank">VMWare Fusion</a> with Leopard or Snow Leopard <em>server</em> as a &#8220;guest OS.&#8221; (In VMWare-speak your regular machine is a <em>host OS</em> while each virtual OS instance running on it is a <em>guest OS</em>.)</p>
<p>The reason this works is because the latest version of VMWare allows you to run OS X Server as a guest OS <em>on top of another OS X host OS</em>. VMWare also allows you to assign specific USB devices to each VM instance so you can tell it that one iPhone/Touch belongs to the guest and the other to the host OS. Now I&#8217;ve only tried this with Snow Leopard Server so I&#8217;ll stick with that but VMWare says it can also install Leopard Server but I have&#8217;t tried that. Since Snow Leopard is still under NDA I&#8217;m not going to go into any specifics of the OS itself. Instead, I&#8217;ll show you how to set up VMWare so it can pull this off.</p>
<p>To start you&#8217;ll want the <a href="http://www.vmware.com/download/fusion/" target="_blank">latest VMWare version</a> (<strike>2.0.4</strike> 2.0.5 as of this writing). Earlier versions may not support OS X as a guest OS. To get access to the Snow Leopard releases you&#8217;ll need to be part of the <a href="http://developer.apple.com/mac/" target="_blank">Apple Mac Developer program</a>. You&#8217;ll want the <em>Server</em> release. During WWDC 2009 some people were reporting having trouble installing Snow Leopard under VMWare from a  disk image file so you might have to sacrifice a blank DVD and burn it to disc before installing it. </p>
<p>With the disc all you have to do is pop it in and it does the right thing. Or you can walk through and manually choose which versions you want to load.</p>
<p><img src="http://ramin.firoozye.com/i/vmwareinstall.jpg" width="396" height="299" alt="" /></p>
<p>Technically VMWare is only supposed to run Leopard/Snow Leopard Server which installs a lot of extra background services, etc. and needs a pretty hefty chunk of memory. If you Google around there are ways to patch the VMWare settings files to let it install <em>Client</em>. Far be it from me to suggest you do this, since it&#8217;s not certified and is not recommended for production use. All I&#8217;m saying is it might be less resource intensive and prevent your MacBook Pro from catching fire after the fans run on full-bore trying to cool down 100% loaded dual-core CPUs. But then again, YMMV.</p>
<p>So once you have VMWare and Leopard/Snow Leopard installed, you&#8217;ll want to install XCode (which comes on the OS install disk under &#8220;Extras,&#8221; or it can be downloaded separately from the Developer Connection website). Once that&#8217;s done you&#8217;ll also need the iPhone SDK. If you&#8217;re a member of the <a href="http://developer.apple.com/iphone/" target="_blank">iPhone Developer Program</a> (and really, who isn&#8217;t nowadays?) you&#8217;ll want to download and install the latest SDK (note that there are different downloads for Leopard and Snow Leopard).</p>
<p>Inside VMWare you&#8217;ll want to set up directory sharing. I won&#8217;t walk you through that here but if you have trouble getting the VMWare &#8220;folder-mapping&#8221; feature to work (like I did) one workaround is to turn on file-sharing in the host OS and mount the networked filesystem from the guest OS. If you do this, make sure you restrict access to only your own account on the shared volumes and turn it off for everyone else, otherwise all your pals at the coffee shop sitting on the WiFi and running Bonjour will have access to your source files.</p>
<p>Next you&#8217;ll want to end up with two separate projects, one for the host and the other for the guest OS. The reason for this is because each instance of XCode makes changes to the project settings each time you do a build. If you share the projects and load them from two XCode instances, you&#8217;ll end up with an endless litany of XCode warnings asking you if it should reload the project from disk. Save yourself a lot of headache. Just create separate projects but keep all your source and media files in the same shared folder. This way if you do actually make changes to the source code during debugging you only have to do it once from either side, otherwise it&#8217;s a nightmare keeping track of deltas.</p>
<p>(<em>Handy tip</em>: if you have dual monitors, install VMWare tools and  put the guest OS on the second monitor then have it go full-screen. It&#8217;s like having two actual systems in one.)</p>
<p>So now comes the fun part: plugging in the actual devices. Make sure you&#8217;re not running XCode or any other app that accesses the USB devices behind the scenes. If you have iTunes set up to auto-run and sync when a device is plugged in you either haven&#8217;t done much real iPhone device debugging or you have a much higher tolerance for Annoyingly Intrusive Software. I turn off all auto-sync, auto-run, auto-whatever features that iTunes throws in to make itself the consumer-friendly app that it is. But that convenience gets in the way of debugging, so do yourself a favor and turn it all off. Manual sync mode is your friend.</p>
<p>iTunes also installs an iTunesHelper app that runs in the background. I personally take that out too by going into System Preferences > Accounts<br />
then clicking on the &#8220;Login Items&#8221; tab button, finding &#8220;iTunesHelper&#8221; and hitting the &#8216;-&#8217; button (or delete) to take it out. The point is, if iTunes snags your USB port before VMWare gets to it you won&#8217;t be able to switch it over.</p>
<p>So now we have the two devices plugged in. Do NOT give in to temptation and start XCode just yet. In VMWare bring up the &#8220;Virtual Machine Library&#8221; which lists all your VM instances (if it&#8217;s not already showing, go under Windows > Virtual Machine Library). Select your Leopard/Snow Leopard instance then push the &#8220;Settings&#8221; button. </p>
<p><img src="http://ramin.firoozye.com/i/sl1.jpg" width="350" height="210" alt="" /></p>
<p>Now go into the USB devices section. Note that you can only make changes to the guest OS once it&#8217;s powered up and running. So if the guest OS isn&#8217;t already running, boot it up. You&#8217;ll be faced with a list of all the USB devices on your host machine, something like this:</p>
<p><img src="http://ramin.firoozye.com/i/sl2.jpg" width="362" height="282" alt="" /></p>
<p>Unfortunately VMWare doesn&#8217;t actually show the device names as assigned through iTunes so there&#8217;s no way to tell which device is which. If you have two iPhones plugged in they both show up as <em>Apple iPhone</em>. You can always test an iPhone against a 2G touch (the Touch shows up as <em>Apple iPod</em>). Then again, if both devices are running the same code it may not really matter.</p>
<p>Turn on the checkbox next to the device you want assigned to the guest OS. If it doesn&#8217;t stick then it&#8217;s likely you&#8217;ve got some other app locking up your USB ports. Go back and re-check (might have to do a clean reboot). I should note that this was the most frustrating part of the whole exercise. The trick that made it work for me was to make sure XCode is not running until AFTER you&#8217;ve done your USB port assignments.</p>
<p>Once it&#8217;s checked, *now* start up XCode on both sides. The host OS should be seeing one device and the guest OS the other. Verify by loading up the XCode Organizer and seeing that each device shows up with a little green dot next it. If you haven&#8217;t done it yet, you&#8217;ll want to tell the XCode Organizer that the devices are to be used for Development.</p>
<p><img class="alignleft" src="http://ramin.firoozye.com/i/organizer.jpg" width="184" height="247" alt="" /></p>
<p>Getting excited? Almost there. Now choose <em>iPhone Device</em> from your XCode Active SDK pop-up. </p>
<p><img src="http://ramin.firoozye.com/i/xcode-run.jpg" width="192" height="83" alt="" /></p>
<p>Ready to hit <em>Build and Run</em>?</p>
<p>Not so fast.</p>
<p><img class="alignleft" src="http://ramin.firoozye.com/i/sadclown.jpg" width="161" height="210" alt="" /></p>
<p>Your iPhone development certificate is only installed on your host OS. The guest OS is a whole other machine and it needs to be set up as if it was a brand new machine. Fortunately, it&#8217;s fairly straightforward to get the keys moved over.</p>
<p>Launch the <em>Keychain Access</em> application (in Applications > Utilities) on your host OS. If you followed the iPhone SDK instructions and created a provisioning profile for your application on the iTunes Connect site, you should have a private key certificate installed in your keychain. If you&#8217;re like me and have done this a number of times, you&#8217;ll have lots of similar looking keys floating around. The trick is to look for the <em>private</em> key with your name and a drop-down disclosure arrow next to it. Open those up and verify that they say <em>iPhone Developer</em> and/or <em>iPhone Distribution</em> next to them. If you&#8217;ve followed Apple guidelines you should have one for development and another for app-store or ad-hoc distribution.</p>
<p><img src="http://ramin.firoozye.com/i/keychain.jpg" width="309" height="236" alt="" /></p>
<p>While you&#8217;re there, it&#8217;s a good time to make sure the expiration date is in the future. I got bit once and boy, was it a pain to diagnose. Stuff that was working one minute magically stopped the next. So stay on top of your certificate expiration dates. If the date is pretty close or already gone by go back to iPhone developer site and follow instructions to regenerate new keys, then install them and come back when you&#8217;re done.</p>
<p>Command-select all the private certificates you want moved and export the lot of them (File menu > Export Items&#8230;) Make sure they go out as .p12 (Personal Information Exchange) files. You will be prompted for passwords. Pick something pithy but memorable and save the exported file to a shared folder you can get at from the guest OS. While you&#8217;re at it, you may also want to move over your app&#8217;s provisioning profiles just in case you need it later.</p>
<p>Back in the guest OS, double-click the exported certificate file, enter the password, and install it in your keychain. You&#8217;ll probably have to restart XCode so it picks up the changes. To verify that it worked, bring up the XCode project in the guest OS, do a <em>Get Info</em> on the target and make sure the Code Signing Identity is selected and is the same as the private key you just installed.</p>
<p>So NOW you&#8217;re ready to go. Select <em>iPhone Device</em> from the Active SDK on both sides, hit Build and Run, go grab a cup of coffee or an adult beverage, and wait until both instances come up side-by-side.</p>
<p>So, yay!</p>
<p><img class="alignleft" src="http://ramin.firoozye.com/i/yay.jpg" width="173" height="202" alt="" /></p>
<p>That wasn&#8217;t too bad, was it?</p>
<p>A few final thoughts: I ended up running Snow Leopard as both host and guest OS since I wanted to run XCode 3.2 with the latest goodies on both sides. You&#8217;ll definitely want separate project files if you want to run Leopard in host and Snow Leopard in guest OS. At this point it&#8217;s not clear if app-store submissions can be built using unreleased versions of XCode. So you might want to check on the developer forums before doing the crazy thing I did and upgrading everything everywhere to the new shiny version.</p>
<p>Also, there&#8217;s no reason this shouldn&#8217;t work for three or more devices (for group peer-to-peer or mass WiFi testing) but you&#8217;ll need a beefy Mac with a lot of CPU and memory. You&#8217;ll also be needing a USB hub (I ended up with this <a href="http://catalog.belkin.com/IWCatProductPage.process?Product_Id=367680" target="_blank">Belkin Ultra Mini</a> model based on advice from <a href="https://twitter.com/schwa" target="_blank">@schwa</a> on Twitter) if you run short on USB ports. All it takes is another VMWare instance and assigning the right device to the right OS instance.  Lather, rinse, repeat.</p>
<p>Happy debugging!</p>
<p><b>Update:</b> <i>Make sure you read VMWare update release notes.</i> In the latest release there are two known issues that directly impact this  way of using VMWare:</p>
<blockquote>
<ul>
<li><b>When being installed on a Mac running Mac OS X 10.6 (Snow Leopard), VMware Fusion does not install MacFUSE </b>
<p>MacFUSE might cause the installer to fail or become non responsive, so the VMware Fusion installation process does not install it by default on a Mac with OS X 10.6.</li>
<p />
<li><b>Selecting the Sleep option on a Mac OS X Server guest operating system causes it to stop responding </b><br />
The default setting for Mac OS X Server is for it to never sleep. However, if you change the setting or use <b>Apple > Sleep</b>, the virtual machine might stop responding.<br />
Workaround: Shut down the virtual machine and restart it, and make sure that in the <b>Energy Saver</b> window of <b>Apple > System Preferences</b>, the <b>Put the computer to sleep when it is inactive for:</b> slider is set to <b>Never</b>. Do not use <b>Apple > Sleep.</b>
</li>
</ul>
</blockquote>
<p>You&#8217;ll definitely want to turn off Sleep mode as soon as you&#8217;ve installed the guest OS and before you walk away from the system for an extended length of time otherwise you&#8217;ll have to hard-reboot the VM instance. I even turn off the screen-saver. If the system is idle for any length of time the host OS should be the one doing the sleeping and screen blanking.</p>
<p>The first issue is also easily solved. You can manually download and install <a href="http://code.google.com/p/macfuse/" target="_blank">MacFUSE</a>. It allows you to use not only third-party file systems on top of MacOS, but file systems on local disk, across the network etc. There are some issues with folder sharing across guest/host applications that clean install of MacFUSE might clear up.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2009/06/18/debugging-peer-to-peer-and-wifi-apps-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WWDC 2009 Predictions</title>
		<link>http://ramin.firoozye.com/2009/03/26/wwdc-2009-predictions/</link>
		<comments>http://ramin.firoozye.com/2009/03/26/wwdc-2009-predictions/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 18:31:38 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[wwdc]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=108</guid>
		<description><![CDATA[Word came today that Apple&#8217;s WorldWide Developer Conference is going to be running from June 8-12 2009 in San Francisco. Since Apple&#8217;s no longer going to be participating in MacWorld this is one of the few public conferences where Apple and its partners can make public product announcements. So now&#8217;s a good time to start [...]]]></description>
			<content:encoded><![CDATA[<p>Word came today that Apple&#8217;s <a href="http://developer.apple.com/wwdc/" target="_blank">WorldWide Developer Conference</a> is going to be running from June 8-12 2009 in San Francisco.</p>
<p>Since Apple&#8217;s no longer going to be participating in MacWorld this is one of the few public conferences where Apple and its partners can make public product announcements. So now&#8217;s a good time to start floating <strike>outlandish rumors</strike><br />
predictions as to what&#8217;s going to be announced.</p>
<p>Since Apple already announced its intention to release iPhone 3.0 software around that time, a lot of products will be taking advantage of those features. One of them was access to the external USB port. The <a href="http://www.engadget.com/2009/03/17/live-from-apples-iphone-os-3-0-preview-event/" target="_blank">announcement demo</a> featured a heart-monitor. My prediction is it will be totally upstaged by one of these:</p>
<p><img src="http://ramin.firoozye.com/i/iPhoneCoffeeWarmer.jpg" width="413" height="356" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2009/03/26/wwdc-2009-predictions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtually sponge-worthy</title>
		<link>http://ramin.firoozye.com/2009/03/08/virtually-sponge-worthy/</link>
		<comments>http://ramin.firoozye.com/2009/03/08/virtually-sponge-worthy/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 20:22:56 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[social-network]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=102</guid>
		<description><![CDATA[Fans of TV&#8217;s Seinfeld in the 1990&#8242;s will remember an episode where Elaine ponders whether someone is sponge-worthy: JERRY: I thought you said it was imminent. ELAINE: Yeah, it was, but then I just couldn&#8217;t decide if he was really sponge-worthy. JERRY: Sponge-worthy? ELAINE: Yeah, Jerry, I have to conserve these sponges. JERRY: But you [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ramin.firoozye.com/i/todaysponge.jpg" width="178" height="189" alt="" /></p>
<p>Fans of TV&#8217;s Seinfeld in the 1990&#8242;s will remember an <a href="http://www.seinfeldscripts.com/TheSponge.html" target="_blank">episode</a> where Elaine ponders whether someone is <a href="http://www.urbandictionary.com/define.php?term=sponge-worthy" target="_blank">sponge-worthy</a>:</p>
<blockquote><p>
JERRY: I thought you said it was imminent.</p>
<p>ELAINE: Yeah, it was, but then I just couldn&#8217;t decide if he was really sponge-worthy.</p>
<p>JERRY: Sponge-worthy?</p>
<p>ELAINE: Yeah, Jerry, I have to conserve these sponges.</p>
<p>JERRY: But you like this guy, isn&#8217;t that what the sponges are for?</p>
<p>ELAINE: Yes, yes &#8211; before they went off the market. I mean, now I&#8217;ve got to re-evaluate my whole screening process. I can&#8217;t afford to waste any of &#8216;em.
</p></blockquote>
<p>In this case, Elaine is in possession of a finite amount of discontinued <i>Today</i> contraceptive sponges and she wants to save her stash for someone really worth it.</p>
<p>There is a large number of blogs, twitterers, and web-sites out there vying for our attention and we have limited time in a given day to spend with them. So a few end up moving up to the top &#8212; the people, places, and things with which we have a steady, recurring relationship &#8212; in essence making them <i>sponge-worthy.</i></p>
<p>If you&#8217;re a writer, publisher, or content-producer forget <i>unique visitors</i>, <i>friends</i>, or <i>followers.</i> Sponge-worthiness  is the status to which you should aspire.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2009/03/08/virtually-sponge-worthy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NSArray debugging on the iPhone</title>
		<link>http://ramin.firoozye.com/2009/02/15/nsarray-debugging-on-the-iphone/</link>
		<comments>http://ramin.firoozye.com/2009/02/15/nsarray-debugging-on-the-iphone/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 21:42:35 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=96</guid>
		<description><![CDATA[If you&#8217;re debugging on the iPhone and encounter a lot of NSArray objects, you&#8217;ll notice that dumping out the contents doesn&#8217;t give you too much information. To help remedy this situation, I whipped out a quick-and-dirty &#8216;helper&#8217; to show a bit more detail. As with the UIView helper all you have to do is include [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re debugging on the iPhone and encounter a lot of <i>NSArray</i> objects, you&#8217;ll notice that dumping out the contents doesn&#8217;t give you too much information. To help remedy this situation, I whipped out a quick-and-dirty &#8216;helper&#8217; to show a bit more detail. As with the <a href="http://ramin.firoozye.com/2008/12/11/easy-uiview-debugging-on-the-iphone/" target="_blank">UIView helper</a> all you have to do is include the <b>NSArrayDebugExtras.m</b> file in your project and build it. This works through the standard Objective-C <i>category</i> mechanism by adding an extra method to an existing class.</p>
<p>To use it, set a debugger breakpoint and enter:</p>
<blockquote><p>
<code>(gdb) po <i>array-variable-name</i><br />
</code>
</p></blockquote>
<p>What you will get is a recursive dump of the array and its contents. If the array contains strings, labels, text fields, or text views, the actual text value is shown. If it contains other arrays, it recursively walks down the array of arrays and shows the contents.</p>
<p>Since there&#8217;s no garbage collection on the iPhone, probably the most useful information is the <i>retainCount</i> for each array and item.</p>
<p>If the array contains a lot of custom objects, of course, you&#8217;ll only see rudimentary information. In that case, I suggest you make a point of defining a <i>debugDescription</i> method for each object so the contents can be properly shown.</p>
<p>Of course, you&#8217;re welcome to tweak the display format to show whatever information makes sense to you, but this should give you a good starting point.</p>
<p>[ Download: <a href="http://www.firoozye.com/download/NSArrayDebugExtras.zip" target="_blank">NSArrayDebugExtras.zip</a> ]</p>
<p><b>Update:</b> The <i>[obj className]</i> method is no longer accessible. Fortunately, the runtime function <i>object_getClassName(obj)</i> provides the same service. The attached code has been updated. Thanks to Howard Katz for noticing the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2009/02/15/nsarray-debugging-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Games for the iPhone (and other platforms)</title>
		<link>http://ramin.firoozye.com/2009/01/02/building-games-for-the-iphone-and-other-platforms/</link>
		<comments>http://ramin.firoozye.com/2009/01/02/building-games-for-the-iphone-and-other-platforms/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 01:45:08 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=92</guid>
		<description><![CDATA[Almost overnight a lot of apps have popped-up for the iPhone and many of them are games. Quite a few of them look like they were developed by hobbyists over a weekend (not that there&#8217;s anything wrong with that). But developing a quality, professional game for the iPhone is still a time-consuming and difficult task. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ramin.firoozye.com/i/itunesstore.jpg" width="382" height="206" alt="" /></p>
<p>Almost overnight a <a href="http://148apps.com/10000/" target="_blank">lot of apps</a> have popped-up for the iPhone and many of them are games. Quite a few of them look like they were developed by hobbyists over a weekend (not that there&#8217;s anything wrong with that). But developing a quality, professional game for the iPhone is still a time-consuming and difficult task. </p>
<p>Once you&#8217;ve settled on the game concept, you have to create the play logic, then generate the graphic assets and multimedia. And somewhere along the line you actually have to write the code to make it all happen. </p>
<p>To build a serious iPhone game you currently have several choices:</p>
<ol>
<li><b>Create a custom one-off app in Objective-C</b> (or C++): This gives you the most control but it means your game is pretty much going to stay on the iPhone. No desktop version. No Wii. Just iPhone. That might be fine, but if you&#8217;re investing tons of hours in content creation and game design, you may want to think hard about whether it makes business sense to leverage all that work and hit more platforms. Building a custom one-shot app also means that all your development effort is only for that one game. Instead, you may want to&#8230;
</li>
<li><b>Develop a general-purpose iPhone gaming engine</b>: Where the gaming logic and media content are kept separate and defined in configuration files. This way, you can get two, three, maybe even 100 bangs for your buck. Hopefully, the configuration language is expressive enough so you can build a whole class of apps, not just the same thing over and over. You should be mindful, however, that the iPhone SDK prohibits use of scripting languages, so you can&#8217;t embed a Javascript, Lua, or Python interpreter into your code. If you don&#8217;t have the know-how or are short on time, you may want to&#8230;
</li>
<li><b>License a third-party gaming engine</b>: This takes you away from the pleasure of writing raw Objective-C code (I&#8217;m not kidding &#8212; it actually is a lot of fun) but it also gives you support tools like 3D modelers, asset managers, physics engines, networking, etc. so you can focus on the high-level logic instead of low-level coding. Most also support some sort of scripting, but get around the SDK restriction by compiling it into executable code.</li>
</ol>
<p>I have worked on several Objective-C-based iPhone apps so far and developed a custom animation engine for a client, so I have squarely followed options #1 and #2. But I also have ideas for quick, fun entertainment/game apps that I&#8217;d like to whip out quickly without spending months on building a custom animation engine. I&#8217;d rather spend my time on polishing the game logic and generating nice looking multimedia assets instead of working around iPhone Core Animation&#8217;s strange quirks (please, don&#8217;t get me started).</p>
<p>So I decided to look around and see what&#8217;s out there and came up with the following. To be fair, I haven&#8217;t had time to dig too deeply into each one, but as a public service I figured I&#8217;d share what I&#8217;ve found so far. If I&#8217;ve missed any other platforms  or made any factual errors, please feel free to post a comment and I&#8217;ll issue an update.</p>
<p>Here they are (in alphabetic order):</p>
<table border="0" >
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href="http://www.stonetrip.com/shiva/shiva-3d-game-engine.html" target="_blank"><img src="http://ramin.firoozye.com/i/shivalogo.jpg" width="120" height="63" border="0" alt="" /></a></td>
<td><a href="http://www.stonetrip.com/shiva/shiva-3d-game-engine.html" target="_blank">ShiVa</a> (with the <a href="http://www.stonetrip.com/shiva/publish-3d-game-on-iphone.html">iPhone Authoring Tool</a>) from <a href="http://www.stonetrip.com/" target="_blank">StoneTrip</a>.</td>
</tr>
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href="http://www.garagegames.com/products/torque/tgb/" target="_blank"><img src="http://ramin.firoozye.com/i/torquelogo.jpg" width="127" height="49" border="0" alt="" /></a></td>
<td><a href="http://www.garagegames.com/products/torque/tgb/" target="_blank">Torque Game Builder</a> (with the <a href="http://www.garagegames.com/products/torque/iphone">iPhone SDK</a> addition) from <a href="http://www.garagegames.com/" target="_blank">GarageGames</a>.</td>
</tr>
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href="http://unity3d.com/unity/features/iphone-publishing" target="_blank"><img src="http://ramin.firoozye.com/i/unitylogo.jpg" width="112" height="68" border="0" alt="" /></a></td>
<td><a href="http://unity3d.com/unity/features/iphone-publishing" target="_blank">Unity iPhone</a>.</td>
</tr>
</table>
<p>In terms of features it&#8217;s hard to tell them apart from their spec sheets. They all feature 2D or 3D graphics, support a  variety of media and content (including shaders, sound, movies, etc), handle physics and collision detection, and playback audio and video. On the iPhone, there&#8217;s also support for the accelerometer (for tilt moves). All three engines support server-based multi-user playing which requires licensing their servers (or their hosting services). It&#8217;s not clear at this point whether they support WiFi-based Bonjour peer-to-peer networking which the iPhone and Touch both support.</p>
<p>What differentiates the three engines is what other platforms they support and their pricing model, so let&#8217;s dig into that.</p>
<h3>ShiVa</h3>
<p><img src="http://ramin.firoozye.com/i/shivaeditor.jpg" width="388" height="241" alt="" /></p>
<p><a href="http://www.stonetrip.com/shiva/shiva-3d-game-engine.html" target="_blank">ShiVa</a> comes in three versions, <i>PLE</i>, <i>Advanced</i>, and <i>Unlimited</i> (here&#8217;s the <a href="http://www.stonetrip.com/shiva/comparison.html" target="_blank">feature comparison table</a>). The development platform runs under Windows (or Parallels on the Mac). The <em>PLE</em> version is free and allows you to create an application, but you can&#8217;t publish the output commercially. For publishing you&#8217;ll need the <em>Advanced</em> or <em>Unlimited</em> versions. <i>Advanced</i> costs &euro;169 Euros (approximately $235 at today&#8217;s exchange rate) whereas <i>Unlimited</i> will set you back &euro;1,499 Euros (approximately $2080). </p>
<p>The main difference between the two seems to be that the <em>Unlimited</em> edition has additional benchmarking and optimization tools and supports team development. There is no extra cost for output to iPhone (and it looks like they intend to support Windows Mobile and Symbian). You can also target your game so it can run in a browser, but it requires the user to download and install a plugin. A standalone desktop app generator lets you target Windows, Mac OS X, and Linux. However, you&#8217;ll likely need to repurpose your media to fit the different screen sizes.</p>
<p>As far as console platforms are concerned, not much there yet.</p>
<p>To support multi-player mode, you&#8217;ll need to license the <a href="http://www.stonetrip.com/ston3d-server/ston3d-server.html" target="_blank">Ston3D Server</a> which comes in <i>PLE</i>, <i>INDIE</i> and <i>PRO</i> flavors. PLE is free but is limited to a single application and 6 simultaneous users. Clearly, it&#8217;s intended only for development and testing. The <i>INDIE</i> version runs on Windows, Ubuntu, and FreeBSD, but is limited to 64 sessions (game instances) and 4 sessions per server. It runs &euro;359 Euros (approximately $500) and the PRO server without the session limitations runs &euro;599 Euros (approximately $832). </p>
<p>There are also <a href="http://www.stonetrip.com/stonbox/stonbox.html" target="_blank">extra server-side features</a> like managed hosting, payments module, and direct messaging to the user (via SMS, MMS, and email).</p>
<h3>Torque</h3>
<p><img src="http://ramin.firoozye.com/i/torquesdk.jpg" width="390" height="195" alt="" /></p>
<p><a href="http://www.garagegames.com" target="_blank">GarageGames</a> offers a dizzying array of products and <i>Torque</i> variations, targeted at anything from simple 2D to networked 3D games. The basic 2D package is the <a href="http://www.garagegames.com/products/torque/tgb/" target="_blank">Torque Game Builder</a> which runs $100 for Indie apps (those earning less than $250K per year) or $495 for Commercial version. The <i>Pro</i> version also gives you access to the source code for both the engine and the editing tools ($250 for Indie, $1250 for Pro).</p>
<p>If you want 3D support then there&#8217;s <a href="http://www.garagegames.com/products/torque/tge/" target="_blank">Torque Game Engine</a> ($150 Indie, $749 Commercial). In both cases, you get a lot of tools that support building levels, media, sprites, etc. and take care of a lot of the low-level grunt work for you.</p>
<p>But that&#8217;s not all, Bob. There&#8217;s also <a href="http://www.garagegames.com/products/torque/tgea/" target="_blank">Torque Engine Advanced</a> ($295 Indie, $1495 Commercial). This gets you all the tools to develop advanced 3D games for consoles and desktops. To deploy your game to a console, you&#8217;ll want to look at <a href="http://www.garagegames.com/products/torque/twii/" target="_blank">Torque Wii</a> or <a href="http://www.garagegames.com/products/torque/t360/" target="_blank">Torque 360</a> (for the XBox 360). License fees for these have to be negotiated.</p>
<p>But it&#8217;s the iPhone we care about and to output there, you&#8217;ll want <a href="http://www.garagegames.com/products/torque/iphone" target="_blank">Torque for the iPhone</a>. First you&#8217;ll need a license to one of the existing &#8216;builder&#8217; tools (<i>Tool Builder</i> for 2D, or <i>Engine</i> for 3D). for the 2D version, you pay an additional $500 for an Indie license. That lets you publish a single iPhone title. Each additional title you want to publish requires an additional $100 license fee. You also have to show the GarageGames splash screen when the game starts and mention them in the game credits (and app web-site). 3D game support on the iPhone hasn&#8217;t been released yet so there&#8217;s no price listed.</p>
<p>Want <a href="http://www.garagegames.com/products/27/" target="_blank">server-based networking</a>? The basic server is open-sourced under GPL. If you want to use it in a commercial app, however, the cost is $295 for Indies and $995 for Commercial apps (consoles are separate). This is for games delivered on Windows, Mac, or Linux. It&#8217;s not very clear if networking is supported on the current iPhone version, but I imagine it&#8217;ll be there soon.</p>
<h3>Unity</h3>
<p><img src="http://ramin.firoozye.com/i/unityeditor.jpg" width="388" height="248" alt="" /></p>
<p><a href="http://unity3d.com" target="_blank">Unity</a> supports 2D and 3D content with a visual editor to help you develop and design your game content. The underlying scripting technology is based on C# and Javascript but their <a href="http://unity3d.com/unity/features/iphone-publishing" target="_blank">iPhone Publishing</a> product spits out an XCode project that they claim &#8216;just works,&#8217; compiling the scripting code into fast ARM assembler code (and thus avoiding the iPhone SDK&#8217;s edict against built-in scripting languages).</p>
<p>Under Unity, the Editor is the main point of creating apps. You visually adjust parameters and get live previews, then create scripts to handle game logic. In iPhone &#8216;preview&#8217; mode, you adjust settings on your desktop screen inside the visual editor and watch it update live on the target test iPhone. It&#8217;s a very cool way to quickly adjust and position your objects and verify that they look right on the iPhone screen.</p>
<p>To develop Unity apps, you need the editing system ($199 for Indie developers earning $100K or less &#8212; with free 30-day eval, or $1499 for Pro) which lets you generate output for Mac, Windows, browser plugin, and OS X dashboard widget. To output to the iPhone you can got for the <em>Basic</em> iPhone license for $399 for Indie developers and requires showing the Unity splash screen, or $1499 for the <em>Advanced</em> license. Wii/WiiWare output is separate and carries a hefty license fee ($15K-$30K per title).</p>
<p>The Advanced edition also gets you .NET sockets. This means that you can write your own back-end server and aren&#8217;t locked into theirs, but you don&#8217;t necessarily get Bonjour/WiFi support. You can also stream assets on-demand (which requires an asset-server client license for $499) but I can&#8217;t imagine anyone wanting to stream assets unless the user was on WiFi.</p>
<h3>Risks</h3>
<p>There are inherent risks with using a third-party middleware. Will the platform continue to be supported? Are they actively fixing bugs? What happens if they go out of business and you want to continue developing your app? If these are concerns, then you may want to consider <em>Torque&#8217;s</em> Pro versions since they come with source code.</p>
<p>On a resource-restricted platform like an iPhone there&#8217;s also the matter of having a whole extra layer of runtime between your app and the OS. If your app is going to be pretty media-heavy you may want to roll your own and keep tight control over memory use. </p>
<p>Don&#8217;t be scared by these caveats. For certain classes of games these engines will amply make up for the risks by letting you concentrate on content instead of engine technology and getting your app out that much sooner. If used properly, they can also act as &#8216;force multipliers&#8217; if you are an individual developer or a 2-3-person team. With these tools, you can rapidly create cool apps that would otherwise require a small army of coders and designers.</p>
<h3>Which one?</h3>
<p><img src="http://ramin.firoozye.com/i/puzzled.jpg" width="122" height="112" alt="" /></p>
<p>Which one you choose will depend primarily on what features you need, so the first thing I suggest is to download and try out each package (here are direct download pages for <a href="http://www.stonetrip.com/download/shiva-ple.html" target="_blank">ShiVa</a>, <a href="http://www.garagegames.com/demos/browse/development/?platform=&#038;sort=popular" target="_blank">Torque</a>, and <a href="http://unity3d.com/unity/download" target="_blank">Unity</a>). All three have free or eval versions and offer <i>Indie</i> pricing for small developers. If your app turns into a big hit and brings in enough revenue, it&#8217;s easy to justify the cost of the <i>Pro</i> or <i>Advanced</i> licenses.</p>
<p>If you intend to eventually move to the XBox then <em>Torque</em> is the only way to go. If Wii is where you might be heading, then it&#8217;s <em>Torque</em> vs. <em>Unity</em>. All three platforms support standalone desktop apps. I&#8217;m not sure with the prevalence of Flash in the browser if anyone&#8217;s willing to download and install a browser plugin just to run an application, so I&#8217;ll call web-based delivery a wash. </p>
<p>If licensing fees are a concern, then you may want to go with <em>ShiVa</em>. If you only need 2D support, then <strong>Torque</strong> may work for you (although their iPhone per-app licensing fee is a little too strange for my taste). Mac-only developers will want to look at <em>Unity</em> or <em>Torque Engine Advanced </em>. All others require Windows (but may work under Parallels or VMWare).</p>
<h3>iPhone-only features</h3>
<p><img src="http://ramin.firoozye.com/i/bonjourlogo.jpg" width="81" height="81" alt="" /></p>
<p>At this point, nobody seems to support peer-to-peer Bonjour-based networking on the iPhone. Quite a lot of games support that feature. Unlike a Nintendo-DS which allows two players to form an <i>ad-hoc</i> network just by sitting near each other, this only works when all the players are on the same WiFi subnet. It works pretty well when players are in the same room or dorm floor and doesn&#8217;t require going out to a central server. It&#8217;s especially handy in places where data access is metered and hitting a central server through the cell network can get expensive. Hopefully Bonjour support is something that will be supported soon. </p>
<p>All three engines appear to have decent support for the accelerometer but no mention yet of other iPhone-only features like multi-touch, GPS, or camera. One other thing to keep in mind is that all the license terms and prices listed apply to <i>games only</i>. If you want to develop a social networking or business app you may have to negotiate a separate license.</p>
<h3>Bottom line</h3>
<p>Which one will I use myself? My development environment is currently 100% Mac based and I have a lot of 3D, graphics, and sound production tools there so that will probably influence which way I go. That makes <em>Unity</em> a strong contender for me. However, I&#8217;ll defer final judgment until I&#8217;ve had a chance to seriously beat up each platform.</p>
<p>Remember that regardless of platform, you&#8217;ll need to sign-up separately for Apple&#8217;s iPhone development program (a $99 cost for individuals) to get a distribution certificate. You&#8217;ll also need to do the actual legwork of submitting the application to the app-store. And once the app is out, there&#8217;s the matter of marketing and promoting so your app stands out against <a href="" target="_blank">all those other ones</a> out there. </p>
<p>Ah yes, marketing. Let&#8217;s leave that for a future post&#8230;</p>
<p><b>Update:</b> For those interested in going the open-source route, <a href="http://sio2interactive.com" target="_blank">SIO2</a> and <a href="http://oolongengine.com/" target="_blank">Oolong Game Engine</a> are two 3D gaming engines for the iPhone/iPod Touch. (<i>Many thanks to Justin Hall for the tip.</i>) </p>
<p>Both look plenty capable for iPhone-only game development (NOTE: there&#8217;s no desktop or console output support). Based on a casual first-pass, it looks like SIO2&#8242;s tight integration with <a href="http://www.blender.org/" target="_blank">Blender</a> 3D editor and support for <a href="http://www.lua.org/" target="_blank">Lua scripting</a> makes it easier for those who want to focus on content-creation instead of low-level coding. Oolong, however, is targeted more at C++/Objective-C coders. According to the <a href="http://code.google.com/p/oolongengine/" target="_blank">Oolong source code site</a> it is the technology underlying <em>Torque Game Builder for iPhone</em> (see above). </p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2009/01/02/building-games-for-the-iphone-and-other-platforms/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Easy UIView debugging on the iPhone</title>
		<link>http://ramin.firoozye.com/2008/12/11/easy-uiview-debugging-on-the-iphone/</link>
		<comments>http://ramin.firoozye.com/2008/12/11/easy-uiview-debugging-on-the-iphone/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 07:49:38 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=80</guid>
		<description><![CDATA[The user interface of the iPhone is based on a series of nested UIView objects, arranged in a view-subview/parent-child relationship. When building a complex application with a lot of views, sometimes it&#8217;s handy to be able to see exactly what that relationship is. But if you try to print out the value of a UIView [...]]]></description>
			<content:encoded><![CDATA[<p>The user interface of the iPhone is based on a series of nested UIView objects, arranged in a view-subview/parent-child relationship. When building a complex application with a lot of views, sometimes it&#8217;s handy to be able to see exactly what that relationship is.</p>
<p>But if you try to print out the value of a UIView in the debugger (or through an <em>NSLog</em> function) you&#8217;ll be sorely disappointed. In this example we have a variable called <em>front</em> that is derived from a UIView. Setting a breakpoint in the XCode debugger, I type in a <code>po</code> (print object) command to show what that variable contains:</p>
<blockquote><p><code>(gdb) po _front<br />
&lt;BCCardSideView: 0x106b020&gt;<br />
</code></p></blockquote>
<p>What you see is that the variable is of type <code>BCCardSideView</code> and its hex address. Not very helpful.</p>
<p>One solution is to take advantage of the Objective-C dynamic runtime and override UIView&#8217;s default <code>describe</code> method. This is the method that is called every time you try to display the value of an object. Here we have just such an override that recursively walks the view tree and dumps out the values. The code is contained in a file called <code>UIViewExtras.m</code>. All you have to do to enable it is include the file in your XCode project. There are no explicit methods to call.</p>
<p>Here&#8217;s the same output after <code>UIViewExtras.m</code> is included in the project (the indentation is a little messed up because of the column width of this blog. In the debug window, it should look fine):</p>
<blockquote><p><code>(gdb) po _front<br />
+ BCCardSideView retain:3 - tag:0 - bgcolor:(r:0 g:0 b:0 a:1.00)<br />
bounds: x:0 y:0 w:130 h:80 - frame: x:5 y:5 w:130 h:80 - center: x:70, y:45<br />
++ BCCardBackgroundView retain:4 - tag:0 - bgcolor:(r:255 g:255 b:0 a:1.00)<br />
bounds: x:0 y:0 w:130 h:80 - frame: x:5 y:5 w:130 h:80 - center: x:70, y:45<br />
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:0 g:255 b:255 a:1.00)<br />
bounds: x:0 y:0 w:100 h:20 - frame: x:0 y:0 w:100 h:20 - center: x:50, y:10<br />
text (len:4 - color:r:0 g:255 b:0 a:0.00): 'name'<br />
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:255 g:255 b:0 a:0.00)<br />
bounds: x:0 y:0 w:100 h:20 - frame: x:0 y:20 w:100 h:20 - center: x:50, y:30<br />
text (len:5 - color:r:0 g:255 b:0 a:0.00): 'title'<br />
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:0 g:0 b:255 a:1.00)<br />
bounds: x:0 y:0 w:100 h:20 - frame: x:0 y:40 w:100 h:20 - center: x:50, y:50<br />
text (len:5 - color:r:0 g:255 b:0 a:0.00): 'email'<br />
++ BCCardTextView retain:4 - tag:0 - bgcolor:(r:255 g:0 b:0 a:1.00)<br />
bounds: x:0 y:0 w:60 h:20 - frame: x:0 y:60 w:60 h:20 - center: x:30, y:70<br />
text (len:7 - color:r:0 g:255 b:0 a:0.00): 'phone.1'<br />
</code></p></blockquote>
<p>For each view object you see:</p>
<ul>
<li>The retain count.</li>
<li>The tag value (if specified).</li>
<li>The background color value in RGBA. RGB values are scaled up to 0..255 and alpha is shown as a floating point value between 0 and 1.</li>
<li>View bounds rectangle (x, y, width, height)</li>
<li>View frame rectangle (x, y, width, height)</li>
<li>View center (x, y)</li>
</ul>
<p>If view is a UILabel or UITextField, you also get:</p>
<ul>
<li>- Length of text</li>
<li>- RGB value for text itself (vs. the background)</li>
<li>- Actual value of the &#8216;text&#8217; inside the field.</li>
</ul>
<p>Subviews are indented by multiple &#8220;+&#8221; (plus) signs. So the top-level has one &#8216;+&#8217; all its subviews have two &#8216;+&#8217; signs, *their* subviews will each have three &#8216;+&#8217; signs etc.</p>
<p>I personally find this handy in debugging views &#8212; especially those created dynamically. I hope you do too.</p>
<p>[ Download: <a href="http://www.firoozye.com/download/UIViewExtras.zip" target="_blank">UIViewExtras.zip</a> ] (<em>Update:</em> Link updated.)</p>
<p><strong>Update 2 [06-Oct-09]</strong> : Modified method of obtaining class name so it should work with newer SDK releases.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2008/12/11/easy-uiview-debugging-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Slowing down Time Machine</title>
		<link>http://ramin.firoozye.com/2008/11/08/slowing-down-time-machine/</link>
		<comments>http://ramin.firoozye.com/2008/11/08/slowing-down-time-machine/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 02:35:26 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[time machine]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/?p=64</guid>
		<description><![CDATA[Time Machine is great, especially if hooked up to a network storage device like Drobo so you can just have it run in the background. In my case the Drobo is connected to a Mac Mini acting as a network file server (yes, I know it&#8217;s not officially supported, but it works fine under Leopard). [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ramin.firoozye.com/i/timemachine.jpg" width="102" height="102" alt="" /></p>
<p>Time Machine is great, especially if hooked up to a network storage device like <a href="http://drobo.com/" target="_blank">Drobo</a> so you can just have it run in the background. In my case the Drobo is connected to a Mac Mini acting as a network file server (yes, I know it&#8217;s not <em>officially</em> supported, but it works fine under Leopard). </p>
<p>However, lately the backups have been taking a lot of system and network resources, rendering the machine (in this case my development laptop) practically unusable while they run. But since Time Machine runs in the background, it&#8217;s OK to lower the backup daemon&#8217;s priority and let it run a little slower.</p>
<p>On Mac OS X Leopard, this is the command that does the trick. From the terminal:</p>
<blockquote><p>
<code>sudo renice +5 -p `ps -axc | grep backupd | awk '{ print \$1 }'`</code>
</p></blockquote>
<p>Here&#8217;s what&#8217;s going on:</p>
<ul>
<li><i>sudo</i> &#8211; This runs the command as the root. You will need to enter the administrator password.</li>
<li><i>renice</i> &#8211; This is the standard Unix command for changing the priority of a running application.</li>
<li><i>+5</i>: Process priorities under BSD Unix-based systems typicall run from -20 to +20, with +20 being <i>lowest</i> (i.e. running slowest) to -20 being maximum (yes, I know it&#8217;s unintuitively backward, but there&#8217;s an old historical reason for it). What we&#8217;re doing is bumping Time Machine daemon&#8217;s nice priority up by 5 (or any number you want) to let it run slower.</li>
<li><i>-p pid</i> &#8211; This is the process id of the process you want to adjust. Since this changes every time Time Machine runs, we have to have a way to find it dynamically at runtime &#8212; which is where the rest of the line enclosed in ` back-quotes come in. On most Unix shells, items enclosed in back-quotes get executed and the result returned back to the command line. So we&#8217;re going to look up the process ID of the current Time Machine server process and return it here.</li>
<li><i>ps -axc</i> &#8211; The <i>ps</i> command returns a long list of all running processes on the system. We need to filter out the one we want, which we do by piping the output into a <em>grep</em> filter next&#8230;</li>
<li><i>grep backupd</i> &#8211; We&#8217;re taking all the output from the <i>ps</i> command and only keeping those lines that contain the string <i>backupd</i> &#8212; which happens to be the name of the Time Machine server. So we end up with a single line of <i>ps</i> output that looks something like this:<br />
<blockquote><p><code>19041 ??         1:07.48 backupd</code></p></blockquote>
<p>But what we need is the process ID to pass back up to the <i>renice</i> command. In this case, it&#8217;s the  first number on the line. We need a way to extract only that, which is where <i>awk</i> &#8212; the amazing text processing Swiss-Army knife &#8212; comes in&#8230;</li>
<li><i>awk &#8220;{print \$1 }&#8221;</i> &#8211; By default, <em>awk</em> splits its input into chunks based on whitespace. We&#8217;re simply asking that the first item be returned. Any time you do this, you should apologize to <i>awk</i> for so massively under-utilizing what it can do. It&#8217;s like driving your Formula-1 car down to the grocery store to buy milk. In this case all we&#8217;re doing is asking it to split up some text and return one item to us, something that <i>awk</i> can do practically in its sleep.</li>
</ul>
<p>When you run this, the <i>sudo</i> part of the command will ask you for your admin password, then proceed to do its thing. Put it all together and you&#8217;ve got yourself a simple way to slow down Time Machine so it&#8217;s not such a CPU hog. </p>
<p>If you&#8217;re enterprising, you can put the whole thing into a shell function and run it over and over. The following code goes inside your <code>.bash_profile</code> file.<br />
<blockquote><code><br />
function tmslow {<br />
        &nbsp;&nbsp;&nbsp;&nbsp;echo "Reducing Time Machine priority..."<br />
        &nbsp;&nbsp;&nbsp;&nbsp;sudo renice +5 -p `ps -axc | grep backupd | awk '{ print \$1 }'`<br />
}<br />
</code></p></blockquote>
<p>Start a new terminal session (to make sure the shell function is loaded) then invoke <code>tmslow</code> and enter your admin password. It prints out a little message reminding you what it&#8217;s about to do.</p>
<p>Remember, the <i>renice</i> command doesn&#8217;t stick, so every time you reboot or a new Time Machine session starts, the process goes back to normal priority. There are ways to automate the priority lowering scheme or even make it permanent, but I don&#8217;t recommend doing that. Sometimes, you may want backups to run full-speed.  Unix makes it trivial to do what you want by stringing together some built-in commands.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2008/11/08/slowing-down-time-machine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
