Sunday, July 10, 2011

iOS -- Things I Forget

The App Icon of an iPad Application is 72x72 pixels.
Get all icon sizes here and advice here.

Remove the shine effect from the iPad App Icon:
Info.plist > Open As > Source Code
<key>UIPrerenderedIcon</key>
<true/>

Run your App only in landscape mode:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); }

Remove the Status Bar
Info.plist > Open As > Source Code:
<key>UIStatusBarHidden</key>
<true/>

To add a background image to your application, do the following in your AppDelegate didFinishLaunching, where wall1.png is a 1024x760 vertical wallpaper, and mainView is your view controller.
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wall1.png"]];
self.mainView.view.backgroundColor = [UIColor clearColor];

Custom Fonts:
It seems you can only customize the font of your labels programatically. See Creating a UILabel programmatically for some sample code that you could drop in your viewDidLoad

Iterate (for loop) over a string array:
NSArray * words = [NSArray arrayWithObjects:@"one",@"two",@"three",nil];
for(NSString * str in words) {
    NSLog(@"%@",str);
}

Static UIColor
...

Friday, May 20, 2011

Display Binary Contents Of A File

Use the od command to dump a file to the console as binary (ascii-hex). This even works on the MAC. It's useful when you're having problems with control characters like line endings.

$ od -t x1 test1.sh
0000000    23  21  2f  62  69  6e  2f  6b  73  68  20  2d  65  70  75  0a
0000020    0a  65  63  68  6f  20  22  46  69  6e  69  73  68  65  64  21
0000040    22  0a  0a                                                   
0000043
$ od -t x1 test2.sh
0000000    23  21  2f  62  69  6e  2f  6b  73  68  20  2d  65  70  75  0d
0000020    0a  0d  0a  65  63  68  6f  20  22  46  69  6e  69  73  68  65
0000040    64  21  22  0d  0a                                           
0000045

Getting Started With iOS

If you're completely new to programming the iPhone/iPad, know nothing about iOS/xcode, and have never used a MAC, the following might be useful.

Development Platform
Probably the cheapest way to start developing is to buy a Mac Mini. It easily has enough power for xcode. I got mine from carbon computing (2.4GHz 2GB, 320GB, SuperDrive, AirPort, HDMI, GeForce 320M Video). It comes with a powercoard and an HDMI to DVI converter. You can plug in your existing DVI monitor and windows USB mouse/keyboard.


Of course, you probably can't live witout two monitors, so you'll need to additionally buy a Mini-DisplayPort to DVI converter. I got this from carbon computing for $40. You can get it from monoprice for $7, but I was in a hurry and don't fully trust knock-offs. I did however buy a usb switch from monoprice for $25 that lets me toggle my keyboard/mouse between the PC/MAC. My monitors have both DVI and VGA out, so I have the DVI cables running to the MAC and the VGA cables running to the PC. To swap the station, you just punch the usb-switch button and the swap buttons on the front of the monitors.

Setting up the MAC OS
Unboxing is easy. Plug it in and hit the power button on the back. It walks you through a friendly first-time-setup. Finder is the magnifing glass at the top-right of your screen. You can use it to search for applications by name, like "update" to find "Software Update". You'll want to run this a few times and update everything. Specifically your OS is probably too old for the latest xcode. Your mac came with some disks, but you don't need these. I also changed my desktop backround and customized the dock (the shortcut icons at the bottom of the screen). Just click and drag to remove them (a little dust-cloud icon appears). And drag from finder to the dock to add them.

Even if you're not using a windows keybard, the change in position of the control-command keys might drive you mad. You can get it to behave more like you're used to by downloading the latest version of doublecommand.
  • [double-click] DoubleCommand-1.6.9.pkg
  • Continue > Continue > Install > [password] OK > Close
  • Eject the installer
  • Finder "DoubleCommand" > System Preferences > DoubleCommand
  • [uncheck] Enter Key acts as Command Key
  • [check] Command Key acts as Control Key
  • [check] Control Key acts as Command Key
  • [check] PC sytle Home and End keys
  • Click activate button
  • Click system button (and provide password)
  • Close double command
Xcode
You need to download Xcode. It was free, but the latest version costs $5. If you're serious about development, you'll want to put stuff on the device which requires a $99/year subscription and gives you access to stuff like Xcode. So you might as well start out by enrolling in the Apple Developer Program. Then you download the latest Xcode (which is gigs, and takes a while). Note that Xcode 4 is considerably different than its predecessors, so if you buy any books, make sure they're the new enough. There are a bunch of tutorials and books out there. I'll probably end up posting some sample code here, but for now, I'll just give a list of resources that I found most helpful.

Absolutely Required Reading
iOS Technology Overview -- Cocoa Touch Layer
iOS Technology Overview -- Core Services Layer

Wikipedia on Objective-C
One thing that drove me crazy for a long time was the difference in function naming between C++ and Objective-C. I finally found a good explanation of this on wikipedia.
- (return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;
Note that instanceMethod2WithParameter:andOtherParameter: demonstrates Objective-C's named parameter capability, for which there is no direct equivalent in C/C++.
The named parameter article goes on to explain that function name is actually interleaved with the arguments. In other languages like Ada, this lets you supply arguments in an arbitrary order. Not so with Objective-C. The only purpose for this is to make the code "more readable". So in the above, andOtherParameter is actually part of the function name. Very weird.

Mac OS X Developer Library
iOS Developer Library 
Other Good Stuff
Understanding iOS 4 Backgrounding and Delegate Messaging
This is absolutely essential to understanding your application's life cycle. Read this before you try writing anythign from scratch. When a text is guiding you through a sample, you're fine, but when you try to do something original, you'll die without this.

Basics (Note, I'm assuming you're using DoubleCommand, so I'm substituting CTRL for Command)
CTRL-Shift-3   = capture desktop as png
CTRL-Shift-4   = capture a cross-hair selected portion of the screen as png
CTRL-Shift-4 + Spacebar   = capture an application windows as png

Monday, March 28, 2011

No Junk Mail

Here's what I discovered while hunting around for a No Junk Mail sign.

The Canadian Marketing Association (CMA) has a central registry to stop some unwanted addressed advertisements. It's not clear if you need to periodically renew your registration.
cornerstonewebmedia.com/cma/submit.asp

The Canadian Government has a national Do Not Call List to reduce telemarketer calls. Your registration will last for five years, after which you must re-submit your number.
www.lnnte-dncl.gc.ca/insnum-regnum-eng

The City of Ottawa has an Admail Reduciton By-Law that prohibits distribution of unaddressed advertising material. All you have to do is post this sign on your mailbox. You can buy it for $2.00 at any of the seven client service centres, such as 580 Terry Fox Drive which is open 8:30-5:00 monday-friday. It comes to $2.26 with tax, and you're required to sign and address a form that is witnessed by the city. The sticker itself has a white background, unlike the gif above.

They gave me a pamphlet that contains more information than the above URL. It says that Canada Post is exempt. It also says that the admail distributors local to Ottawa are Flyer Force (742-7782) and Sun Distribution (739-7200). If posting the sign doesn't work, you're supposed to contact the distributors. If that doesn't work, you're supposed to "call the City of Ottawa Call Centre at 580-2400 and identify, where possible, the name of the distributor or the type of material delivered".

Monday, February 28, 2011

How to feel about Egypt

In response to the Ottawa Citizen "Do you really want revolutionary change you can believe in the Middle East, Mr. Obama?"

First, I don't know anything about Egypt, Islam, or war.

Second, I don't consider the Citizen article trustworthy because contemptuous statements like "He's so desperate" and "as their liberal puppet" are designed to make me feel a certain way, without providing reasons. I'd suggest that the wikipedia article on ElBaradei is far more believable.

Third, I don't accept the claim that revolution is bad, even if it involves the death of thousands of innocent people. Consider the Costa Rican Civil War for example. In any case, I haven't seen convincing evidence that current events in Egypt will reduce the joy value of the universe.

Fourth, even if I were convinced that there was a majority chance that events in Egypt would lead to disaster, I wouldn't agree that the U.S. or Canada should have supported Mubarak. That is after all, the only meaningful question for an average North American, since most of us won't participate any further than our next Federal vote.

Perhaps I misunderstand them, but this Citizen article and the many other arguments that are unhappy about events in Egypt all seem to say that things were better off when Mubarak kept his people quiet. While that may be true for me personally when you define "better off" as "the price of a big mac, etc.", I'm not very interested in it and am personally shocked by the implications.

Based solely on the fact that he was in power for 30 years, I assume that Mubarak was corrupt and was unwanted by many reasonable people.
Based on my understanding of Emergency law in Egypt, I assume that average Egyptians are denied rights that I consider basic and treated in ways that I would resist.

Therefore the argument that we were better off with Mubarak is the argument that Alice, Bob and I live in a maze together, and Alice routinely treats Bob in ways I consider reprehensible, but never in my presence, and every so often I'm asked to modify some switches in the maze to prevent Bob from defending himself from Alice based on the argument that I have never seen Bob outside of Alice's presence and if I don't help Alice suppress Bob, he might one day hurt me. 

This, I am not willing to do.

Monday, October 18, 2010

Theatre Tickets and the NAC

The NAC phoned to sell me theatre tickets. Normally I hate telephone solicitation, but the lady was nice and I'm convinced that ticket master is corrupt, so I thought I'd give it a try. I told her I'd talk it over with my wife and would call back next week. I'm a busy guy, so it was closer to a month later before I called back. In the mean time, they tried to call me maybe twenty more times (don't do that!), which I just ignored.

The thing is, that we don't appreciate most of the theatre that they put on at the NAC. It's just not our style. But they're partnering with the GCTC for Vimy, and you can trade in theatre tickets at cash value for NAC dance tickets (some of which are amazing).

Ticket Master
I went through the online Ticket Master process, and canceled out just before paying. Here's what would have happened.

Vimy (Nov 9 - Dec 5) GCTC (in the main Theatre)
Sat. Dec 4th, (all seats same price), $40.80 x 2 + $5.50 x 2 + $4.00 = $97.60

The Year of Magical Thinking (Jan 11-29) NAC (in the main Theatre)
Tue. Jan 25th, (centre orchestra, 4th row), $60.27 x 2 + $5.50 x 2 + $4.00 = $135.54

Wayne McGregor, Random Dance, Entity (only one day) NAC (in the main Theatre)
Tue. Feb 8th, (balcony, 1st row, orchestra was sold out), $43.17 x 2 + $5.50 x 2 + $4.00 = $101.34

Cedar Lake Contemporary Ballet, Orbo Novo (Mar 3-4) NAC (in the main Theatre)
Thu. Mar 3rd, (side orchestra, 3rd row), $46.28 x 2 + $5.50 x 2 + $4.00 = $107.56

NAC Theatre Package
I called back, Tuesday Oct.12th at 10pm and bought a 3pack (6tkts) over the phone with visa. They arrived in the mail on Friday Oct.15th, and I stopped by the NAC Saturday afternoon to swap the 3rd event (which we didn't want) for dance tickets. The tickets from the 3pack that we used for trade-in were Saint Carmen of the Main, $44.98 x 2 + $3.00 x 2 = $95.96. These where accepted for trade as a value of $95.96. Also, since we're now a subscriber, we get a discount on all subscription events of the season (i.e. the dance tickets). This seems to be 10% off most events. The NAC Box Office is open Monday to Saturday, 10am to 9pm. The NAC may look closed, but the box office on the far side facing the river is open. Here's what happened.

Vimy (Sat. Dec 4th) GCTC (in the main Theatre, orchestra, D16/17)
$27.77 x 2 + $3.00 x 2 = $61.54 (saved $36.06)
 
The Year of Magical Thinking (Tue. Jan 25th) NAC (in the main Theatre, orchestra, D18/20)
$49.29 x 2 + $3.00 x 2 = $104.58 (saved $30.96)


Wayne McGregor, Random Dance, Entity (Tue. Feb 8th) NAC (in the main Theatre, balcony, B45/47)

$29.74 x 2 + $2.69 x 2 = $64.86 (saved $36.48)
Cedar Lake Contemporary Ballet, Orbo Novo (Thu. Mar 3rd) NAC (in the main Theatre, orchestra, D49/51)
$37.05 x 2 + $2.69 x 2 = $79.48 (saved $28.08)











Result: Saved $131.58
Conclusion: Ticket Master is the enemy.

Another good way to save money that I haven't tried, is to buy Rush Seats. The NAC website says that last-minute 50% discounts on some NAC performances are available from 4:00pm to 6:00pm on the day of the show.

You can exchange your tickets (in person, by fax or by mail) up until the day before the show (with no service charge) for any NAC subscription event during the same season.

Monday, October 11, 2010

How To Lend On Kiva

I like Kiva. Sarah-Jane Whittaker sent me a kiva gift certificate circa 2006 and I've been lending ever since. It's fun and it probably makes the world a better place. I added more of my own money and have recently been lending under the Church of the Flying Spaghetti Monster.

I wonder though how to maximize the world's-a-better-place-ness of kiva interactions. Each time you lend, they by default ask for a donation to kiva. I always unselect this. I'm not convinced they need that kind of support from their lending base and it seems underhanded to have it selected by default.

Another thing you'll notice after lending on kiva is that your loans are always paid back. That's nice, but absurd. People default on loans, especially poor people on unstable countries. It must be that the field partner covers the defaults to maintain their high kiva rating.

If you think about it for a while, you'll have to conclude that kiva is not what it seems. David Roodman gives an excellent explanation of this. The reality is that you're not lending directly to some far-away entrepreneur. That would be inefficient and absurd. You are in fact supporting Kiva Field Partners aka Microfinance Institutions (MFIs).

So when you decide to lend on kiva, the crucial world's-a-better-place-ness question is not: Should I lend to Mohira Kholikova from Tajikistan or Nelly from Bolivia? The question is: Which Kiva Field Partner should I loan through? or Which Kiva Field Partner gives the best deal to the borrower/entrepreneur?

I searched through the Kiva Field Partners in Oct. 2010 looking for all that met the following criteria.
- Field Partner Risk Rating: at least a three stars.
- Portfolio Yield: no more than 35%
- Profitability (Return on Assets): no more than 2%
- Average Loan Size (% of Per Capita Income): no more than 200%

That may not be the best metric. I'm open to suggestions. It's hard to know. Low profitability might just mean bad management. High yield might just mean that borrowers cover a wide region with bad roads and therefore represent larger operating costs. But you have to draw the line somewhere. Here they are:

Armenia > Nor Horizon Universal Credit Organization Limited Liability Company
Nicaragua > Fundación Leon 2000
Guatemala > Asociación ASDIR
Ecuador > Banco D-MIRO S.A.
Ecuador > Cooperativa San Jose
Lebanon > Ameen s.a.l.
Mongolia > XacBank
Peru > Asociación Arariwa

Each of the field partner pages has a link on the right-sidebar to "See all fundraising loans from this field partner", so you can first pick a partner you trust, then a profile you like then lend. Have fun.