Thursday, December 4, 2008

Using a SQLite Database in an iPhone Application

I've been spending a lot of my spare time working on a killer iPhone application (doesn't everyone think their app is the killer app??). Like most applications, it requires the use of a database, and SQLite comes along for free on the iPhone. I own several iPhone development books, including:



What I find most frustrating / challenging is that none of these books are THE killer iPhone development guide. In fact, it often requires mining tidbits of technique and information from multiple books, Apple examples, and blog postings to find the answer to a problem.

While XCode will place everything inside of the Resources group into your application bundle, the app bundle on the iPhone is effectively read-only. Therefore, when you create a database on the Mac and place it into your app bundle- you can't actually do anything with it. Instead, you're application needs to have a routine to check for the existence of a database (and perhaps a version) and if one isn't found, physically copy over the database from the application bundle into your ~/Documents folder for your application on the iPhone.

As a case in point, the "Beginning iPhone Development" book provides a great section on working with SQLite, but it omits this fact, since its samples actually issue CREATE table statements. That's great for rudimentary work, but let's face it- it is more performant to already have the database tables created and avoid bloating the app with such unnecessary logic.

So the key tip here is simple- if you are doing iPhone development against SQLite, you have 2 options at your disposal:


  1. Let the SQLite APIs automatically create an empty database file when you issue the open command (occurs by default), and then detect the (lack of) tables and issue the CREATE statements from within your code, or

  2. Add logic in your app delegate at startup to check for the existence of the database, and if not found- physically copy the template database from your application bundle over to the ~/Documents directory



Happy coding!

Wednesday, November 12, 2008

Web Receipts Folder

Mac OS X offers a nifty ability to digitally archive your web receipts-- you know, all those web site transactions that result in a "Print this page for your records" message.  When you choose Print (or in the case of Safari, Print Page... as shown below).  




The resulting Print dialog shows up.  Most affluent Mac user's are well aware of the "PDF" button loitering in the bottom-left of the dialog.





In fact, I've used the "Save as PDF..." option for years, never paying attention what other options were below. Low and behold there is an option to save the PDF to a "Web Receipts Folder" (shown below).





Where is this mythical Web Receipts Folder? Can I change its location? With a quick google, these questions were (sorta) answered. The "Mail PDF," "Save as PDF-X," and "Save PDF to iPhoto" are all Automator workflows. The last one, "Save PDF to Web Receipts Folder" isn't- but that doesn't mean its behavior can't be modified!


Turns out the underlying functionality for each of these menu items is represented in the /Library/PDF Services directory. The Web Receipts Folder as shipped by Apple is a great example of how the OS can be extended in very powerful ways, but as-is out of the box the behavior is ugly. I call it "ugly" because there is no file name protection- in other words, if you print out your Amex payment receipt 10 times and don't manually adjust the file name, only the last PDF is in your Web Receipts Folder! You may think you have 10 receipts archived, when in fact you only have 1- and that is ugly, especially when it comes to financial receipts!


The Web Receipts logic is a package which can be easily expanded. Right-click (or control-click) on the file in /Library/PDF Services/Save PDF to Web Receipts Folder to access the popup menu and choose Show Package Contents. Open the file tool in your favorite editor- turns out it's just a simple Python script! How cool is that!


Recommended Script Changes: Add a time stamp as a file name prefix to ensure unique filenames every time, and (optionally) change the location where the Web Receipts Folder is created. Under "import sys" add two more lines:


import datetime
import time


Look for the line that reads title = safeFilename(title) and add the following 2 lines immediately before this line such that your script now reads like this:


printDate = datetime.date.today()
title = printDate.strftime("%Y_%m_%d) + "__" + time.strftime("%H-%M-%S) + " " + title
title = safeFilename(title)


What this does is append the time stamp as a prefix "YYYY-mm-dd__HH-MM-SS " to the file name, thus providing a guarantee that you won't overwrite previous receipts.

To change the directory where the web receipts folder is written, modify the line that reads:


destDirectory = os.path.expanduser("~/Documents/Web Receipts Folder")


As an FYI, you can place an absolute path in this location, even if it is considered a poor use of expanduser() method.
Now, digging deeper- think of all the powerful things you can do now that you know about these capabilities. You can write powerful Python scripts and place them into the PDF Services directory. Enjoy!

Tuesday, October 28, 2008

Color Schemes

Ever find yourself looking for just the right set of colors that compliment each other for your UI? Sadly, not everyone is blessed with the ability to pick great complimenting colors that make an application really stand out (and I'm one of those people). Never fret- there are a number of great ways to find a nifty color combination that shines.

Online, probably the best app I've seen for this is Adobe Kuler.

Offline, there is another great resource that isn't necessary obvious.  Paint stores!  I am fortunate to have a Monarch Paints store just around the corner from my house.  When I'm really looking to find a unique combination of colors, there is no better place to see their "wall of colors."  Here's an example of 2 strips of colors that I brought back from a recent trip:


So, if you aren't sure what color patterns to use for your next app, either of these solutions should be of great help!

Monday, October 20, 2008

It's the people, silly.

Today's tech companies throw around the word "culture" too much, at least in my opinion. An architectural team lead at a .com recently told me "Culture is a fragile thing." At first I conceded to his point, but upon reflection over this last weekend I realized he is completely and utterly wrong. People are fragile. A good leader shouldn't give a damn about the culture-- he should only care about taking care of his/her people! In the military and in the civilian world, true leaders know that if you take care of your people, everything else just falls into place—and your people will take care of you. As a manager, your people’s problems must be your problems. As a manager, your primary job is to be an advocate of your people, not the company’s culture as was cited in this case!

Let me ask you something- what do you think is THE most important resource in the US Navy. Aircraft Carriers for force projection? Nuclear powered ICBM submarines? The mighty war planes behind Naval Aviation? Ships, in general? No, no, no, and nope. The real answer is simple. People are THE most important resource in the US Navy (and all the other services, too), and people are the most important resource in an enterprise. We even have terms to describe what happens when talent starts to leave a company and/or country—brain drain. It’s about the people, silly.

When I was attending The Ohio State University on my Navy scholarship, I participated in the leadership curriculum required of all Naval Officers. Even in those 4th year classes one theme rang true: You can have the newest ship, the most powerful missiles and force projection systems known to mankind-- but if you don't take care of the people you lead, it all means nothing, and bad things happen. It's the people, silly.

I learned an important life lesson from my Naval experience (several, actually). It continues to surprise me that companies expect, and in extreme cases demand, loyalty from their employees day one, no excuses. They literally spend time and money on “culture” activities. They ask the wrong questions, like “how can we improve our culture?” instead of “how can we improve our people?” They incorrectly and inappropriately make decisions based strictly on culture instead of contribution and talent. At a previous position I was responsible for managing a large geographically distributed team. One of my engineers was a special talent (sincerely). He bordered on genius, literally. Personally, I wasn’t about to hang out with this individual on a weekend or invite him over for dinner, but he was my direct report, my responsibility. I had one job- take care of my team’s professional needs and be their advocate as they completed their work assignments. Everything else, like culture, would follow. However, HR and upper management had a term that I came to resent over time-- they called this incredibly gifted engineer a “Triple Threat” because he was openly gay, over 40, and suffered from a doctor-documented mental condition that left him incapable of understanding social cues. Was this individual hard to manage? Oh my- yes he was! But everyday I showed up to work, I had one job to do- be the advocate of my team while they completed their assignments, and do this to the best of my ability. In some cases, that meant defending this particular individual in front of upper management. (On other days, it entailed reminding him sternly that inhaling helium and speaking and speaking on technical pre-sales calls were best as two separate activities and shouldn’t be done, especially not at work). Managing this individual was challenging and exhausting work, but I can honestly say that I did my absolute best to take care of his professional needs—and I gave the same level of effort for everyone else that worked for me too—the best effort I could muster. I never worried about what impact he had on the “culture” of the company- my responsibility was to my direct reports, not some culture! Now then, that isn’t to say that I could totally disregard that company’s policies, contractual obligations, or business roadmap. The company was, after all, a for profit enterprise. But there is a big difference between meeting these very real obligations versus worrying about something as immaterial as culture. Instilling and protecting corporate culture doesn’t quality as a fiduciary obligation to my knowledge. How one protected corporate culture isn’t something that analysts ask about during quarterly earnings calls. It's the people, silly.

I can’t speak for the rest of the population, but I’ll take a manager who truly takes care of my professional needs at a company with a crappy culture (by crappy I think of the old school EDS days of blue suit, blue shirt, blue socks, and rigid (read long) work hours, etc.) over a superficial manager who doesn’t nurture my professional growth and instead worries about preserving a culture where you can wear jeans, come to work at 10:30-ish everyday, and spend your afternoon offering up unsolicited critiques of other people’s code ad nauseum. Great leaders of men (and women) are getting harder and harder to find out there. They are so rare that one could categorize them as an endangered species. It is truly disheartening to see more and more managers taking up a position similar to the architect team lead I spoke with last week—worrying more about the culture then about the people. It's the people, silly.

So I’m going to tell you right here, right now how you can earn both respect and loyalty from me for years and years to come, and how I hope to earn your respect and loyalty whenever I'm asked to fill a leadership position. Lead from the front, and lead with acts of leadership. Let me give you a concrete example of an act of leadership. There was a database company long ago that required some crucial code be written- so crucial that the engineering team responsible had to work literally on and over Thanksgiving weekend. The manager could have easily cut out on the team on Thursday, even Friday. In fact, the manager could have simply monitored the situation from afar. Instead the manager did something brilliant- the manager chose to lead from the front. You see, that manager hoped on a flight to San Francisco to spend the Thanksgiving holiday with the engineering team in the lab. That manager actively dug into the code to help out, too. That manager led from the front, and that is an example of what I term an act of leadership. Not only was there the obvious bonding that came from the long hours-- but the manager indirectly nurtured loyalty, recognizing the best choice was to be there for the team, in person, in the trenches beside them, doing whatever it took to help the team get the job done. That manager demonstrated an act of leadership.

If companies want loyalty from their employees, they have to realize that they have to earn it. Loyalty doesn’t come from a marketing campaign; you can’t “buy” true loyalty. Loyalty doesn’t come from a perceived “culture” in the hallways. And as I've experienced first hand managing some challenging individuals, protecting the "culture" isn't as important as being an advocate for your people. Letting good talent walk out (or be pushed out) of the door because they didn’t fit into some perceived “culture” is just plain ridiculous.

It's the people, silly. Take care of your people, and your people will take care of you.

Saturday, May 10, 2008

The Putrid Recruiting Industry

Last year I put up some blog postings on Flex and Java. Blogging just isn't my thing- I can't find the time on a daily or weekly basis to put up a meaningful post. Instead, I opt for the lecture circuit- well known in advance, easy to coordinate around work, etc. I've lectured at SD West I think 4 or 5 times now, going all the way back to the mid 1990s when I spoke on PowerBuilder (boy, those Client/Server powerscripting days are long gone!). This month, I gave a keynote at the 2nd Annual European NFC Developers Summit entitled "NFC Applications: Here and Now."

At my ugly but functional personal web site, I do keep a somewhat updated resume online- it is a nice way when I submit a paper to quickly reference my credentials (URL versus PDF). As a result, my name is out on the web, and I get my fair share of emails from recruiters- something I'm sure every blogger or speaker or author or networked techie endures.

Recruiter emails are hysterical. Some are novels. Some are short stories. Some are equivalent to an SMS message from a teenager (and in fact may be!). You just never know who you're going to hear from, what the opportunity may be, etc. so I humor many of them and read their emails. What happens next, my action in response to the email, can always be categorized into 1 of 4 actions:

  1. Sincere interest, sincere reply.
  2. No interest, sincere reply- maybe next time though, let's keep in touch!
  3. No interest, insincere reply- they asked for it!
  4. No interest, no reply.

I'll get to how I choose which of the 4 categorical responses I pursue after a brief sidebar on job boards and working for "the man."

I've also been know to throw my resume up on some job sites from time to time to see if there are greener opportunities out there. I prefer to work for myself in long term contracts (my present situation is a strong example- 15+ months now with the same client). I've just never felt rewarded working for "the man" at one of these Fortune 500 companies. Sure they have benefits and neat job titles, but in the end the 9-5 corporate environment just isn't for me. I'm objective focused- tell me what needs done, let me get you an estimate I'm willing to commit to, and then I crank out that work- repeat. Very agile, scrum (choose your word here). I also like working with sharp people on cutting edge ideas, and sadly most Fortune 500 companies don't push the boundaries like the rest of the companies might in the Fortune 2000. The other problem (in my perception) is that ultimately that new development transitions to maintenance development. To be clear, I am a trail blazer, not a pot hole patcher. I excel on being given THE tough problems to solve with very little business details-- because it (the problem) is from unchartered waters, so there aren't a lot of meticulous details to give. It's a perfect match for the work I've been doing at Over-C, but soon they too will take the inevitable transition from heavy R&D over to maintenance and up keep.

In the end, I've never found a job I liked from a job board. Not one. That isn't to say I haven't found (and taken) a job from a recruiter, just that the recruiter found me, I didn't find them on a job board.

In literally every meaningful position I've had, I've either cultivated the relationships myself and found (made) the work myself, or I simply launched a new startup to pursue something that interested me greatly (something I've done 3 times, twice in the tech industry- ultimately making a modest profit in each case). The point of this paragraph is simple- for me, posting my resume on a job board only opens the flood gates, and I get bombarded with emails from recruiters.

Which brings us back to my selection of which categorical response I pursue after reading their email.  And over my career I've read a lot of recruiter emails and I'm convinced that, in general, recruiters just don't get it.  I think examples speak volumes, and here's one that recently found my inbox:

 




Hi,
Please find A HOT job description below. Please send me your updated RESUME, RATE, AVAILABILITY information ASAP...

Position: Flex (JAVA)
Duration: 6 Months
Location: NC

**************ONLY Citizen or GC or EAD or H1 Transfer*****************
Skills:
· Java
· Flex
**************ONLY Citizen or GC or EAD or H1 Transfer*****************


Let's analyze this, um, job description(?) shall we. Java and Flex. Boy, that's almost too good to be true- I wonder when I can start! (Yes, that's sarcasm). C'mon people! This is clearly an example of an email that gets either a Category 3 or Category 4 response.


Then you have the recruiters who send you spam.  That's the only way to describe it.  I implore you- show me where on my resume does it say I'm a PHP guru with heavy LAMP experience? It doesn't, but yet the recruiter goes on to ask me for an updated resume and contact information. You guessed it, Category 3 or Category 4-- usually a Category 3.  In fact, I love to reply back and tell them that I have 3 light years of experience with PHP version 27.2, and in fact I use a Linux distro that I created just last week based on a black market copy of the Windows XP source code that I found on a recent trip to a Baltic state. ~LOL~ (The best was when I had one recruiter still not get that they were being screwed with- they wanted to confirm with me my hourly rate and start date before they submitted me!)

Then there are ones who earn a Category 1 or 2 response.  They do things like use my name, cite something meaningful from resume, demonstrating that they actually read about me before contacting me.  The true professionals will even use a voice mail and an email to get in touch with me.  I go out of my way to offer them a polite and sincere response- because they have demonstrated that they are professionals in their own rite.  That isn't to say I spend 30 minutes on the phone with them, or that I offer them an elaborate email back, but I ensure it is a sincere response.

Which leads to my concluding thoughts on how recruiters can change (everyone's?) perception and prove that they "get it" and aren't there to waste our time.  Any contact should at a minimum offer up pertinent details:

  • Is the job permanent or contract?
  • If contract, what is the posted versus expected duration?  We all recognized that companies will open up a req for say 3 months, but expect you to be around for a year.
  • Geography - saying the job is in "Texas" doesn't say much.  My home state, the Great State of Texas, represents 7% of the land mass of the United States of America, covering over 268,500 square miles (take that France, with your mere 210,000 square miles!).  Texas.  It's bigger then France.  So tell me a meaningful location!
  • MEANINGFUL overview of the job/technologies.  Saying "Java" doesn't cut it!  I may know the Servlet specification by heart (sadly, not far from the truth!), but I've never done a lick of JSF development in my life, and I can't even spell Java SWUNG (think about it- you'll get it).
  • It's ok to ask questions- availability, rate, US citizenship, etc. - that's cool, so long as you done your part with the first 4 bullets.
Do these things- you'll probably get a Category 1 or Category 2 response back from me- and perhaps more meaningful ratios from your job inquiries to qualified candidates.  Tell me about a "hot job in Texas doing Java" and you're just asking for me to screw with you!  I'll think it's hysterical- but in the end, were just wasting each other's time-- time you should spend looking for a job doing something other then recruiting!

Well I have no metrics, no scientific studies, my gut tells me that I speak for experienced professionals everywhere with this post.  When the recruiting industry as a whole acts more professional, it will probably be able to begin shedding its horrid and putrid reputation.  So long as bozos keep sending out emails about jobs in "some state" with "some technology" - it's only going to become the target of more and more jokes.