2009.06.28

Stupid Documentation Tricks: Apple's "Using Subversion with Xcode 3 on Mac OS X Leopard"

Running the svnserve Server

If you've chosen to use the svnserve server over ssh, there isn't even a step two. The svnserve binary comes pre-installed on Leopard, and the ssh server (sshd) launches svnserve on demand, so svnserve doesn't need to run as a daemon. Therefore, as long as the repository is in place, and sshd is running on the server, svnserve will already accept connections. Skip ahead to the section, Using Subversion from Xcode to get started with your first project.  [emphasis mine]

Seems clear enough, doesn't it?  You're done.  You're ready.  Fire that puppy up and get started subverting!

Not so fast, though.  You can't actually connect to svn yet.  Let's enlarge the window on that document just a couple of lines or so....

Running the svnserve Server

If you've chosen to use the svnserve server over sshthere isn't even a step two. The svnserve binary comes pre-installed on Leopard, and the ssh server (sshd) launches svnserve on demand, so svnserve doesn't need to run as a daemon. Therefore, as long as the repository is in place, and sshd is running on the server, svnserve will already accept connections. Skip ahead to the section, Using Subversion from Xcode to get started with your first project.

Note: To start sshd on the server, open System Preferences, select the Sharing icon and select the Remote Login checkbox. [emphasis mine]

To recap: '...there isn't even a step two'; 'Skip ahead to the section, Using Subversion from Xcode to get started...'; but make sure you do something else first!

2009.06.24

The Joys of Memory Management, part 1

I've been playing with the iPhone SDK recently, and for whatever reason, I'm having much more success wrapping my head around the NextStep programming model adopted by Apple years ago.  Previous attempts were, shall we say, less than thrilling.

My first iPhone app is approaching beta, which means that I think the first version is done and I'm waiting on feedback from someone else before I consider submitting it to the App Store.

This morning I had a wrangle or two with memory management.  That's not surprising, because memory management is one of the bête noires of programming in c or c++, and Objective-c isn't going to be that different.

Or so I thought.

After creating a generally functional version of App#1, I decided to run it through some torture testing.  So I added a few buttons to the UI and wired them up to some test routines.  Essentially, I simulated thousands of uses of the basic functions.  There are two buttons that the user will press and three textfields, so I wired up the test buttons to call each button's target 10,000 times and one to change the value in each textfield 10,000 times and to call the various functions which use those values.

Everything worked, but Instruments told me that there was some serious memory usage going on.  Not a lot of leakage (although there was some), but some serious usage.  Not good. Especially since this is a simple program, without anything fancy going on, except for rolling about 14 million dice.

So I refined my tests a bit, and discovered some stuff worth recording.  Others may find this useful or not, but I know I need to remember this, and writing it down will help do that, even if I never come read it again.

This is a memory leak:

dcsText.text = [[NSString alloc] initWithFormat:@"%d", 15 + (i % 10)];


This is not:

NSString *temp = [[NSString alloc] initWithFormat:@"%d", 15 + (i % 10)];
dcsText.text = temp;
[temp release];


Discussion:

I wasn't actually using the first version, but the second. But I wanted to know if the first version was going generate a memory leak, so I tried it. And confirmed that I knew how the tool was working and that the version I had written was working correctly.  The first version is a memory leak because the allocated string is created and has a retainCount of 1, but it's never released to reduce the retainCount to 0, so dealloc never gets called.  It might be nice if it were an AutoPtr so that it got released when it goes out of scope, but that is a big whopping can of worms that I'd just as soon not open, so we'll let it go at that.  I will, however, write me a few helper routines of the second general form.

NSArray

Once I had established the validity of the above form, I went on to see if I could figure out why the app was: 1) slowing down over time; and 2) using so frickin' much RAM.  I'd been pretty careful, and I was reasonably certain that everything I was allocating was being deallocated, so where was the leak?  Instruments pointed me right at it.  Every leaked block was associated with an Array class of some sort.  I was only using two arrays: one of NSMutableArray and one of NSArray (basically I built the array using the NSMutableArray and then created an NSArray from that so that client code couldn't alter the array).  So what if I just use the NSMutableArray, eliminating the creation of the NSArray?  No help.  What's the retainCount on the NSArray immediately after I create it?  2?  2?  2!

That's not right.  It should be one.  So try releasing it immediately after creation.  Big time crash later in the program.  Obviously something is holding onto it for some reason.  Look at the documentation.  Whenever you use a factory method, the allocated object is added to the autorelease pool.  But the top-level autorelease pool isn't drained until the end of the program, which is why every last one of the 1 million NSMutableArray and NSArray instances are still hanging around.  Obviously I need to add a nearer-scope autorelease pool.  But it's recommended in iPhone programming that you limit your use of autorelease pools.

Clearly that advice is not meant for this situation.  By adding a local autorelease pool where the NSArray is being created and then draining that pool in the same method which creates the NSArray, only one NSArray is kept around at a time, drastically (like, 30MBs of RAM) reducing my memory footprint.  Also, incidentally, locating the spot where I was not releasing one bit of allocated memory, thus the actual memory leak.

The most commonly used function now operates nearly 100x faster than it used to, probably because of vastly decreased memory usage.

Live and Learn.

2009.06.21

iDisemvowelU

IDisemvowelU

In order to assist Sara with managing comments, I have created a disemvoweling utility application for Mac OS X.  I call it iDisemvowelU (control-click to download).  It was remarkably easy to create now that I seem to have finally wrapped my head around the basic Mac programming environment.

It works very simply.  Once you have started iDisemvowelU, just:
  1. Get the text you want to disemvowel into your clipboard.  This would typically be done by using Cut (Command X) or Copy (Command C).
  2. Click on the 'i Disemvowel U!' button.  The original text will be displayed in the left hand view, the disemvoweled text in the right hand view, and the disemvoweled text is also put into your clipboard in place of the original text.
  3. Now you just Paste (Command V) the disemvoweled text wherever you want it.  Typically that might be wherever the original text was :-).

2009.03.14

Choosing an Energy Source


I was reading The Transition Handbook in preparation for a workshop next weekend, and there's a couple of great charts showing the carbon intensity (grams of CO2 equivalent produced per kilowatt-hour) and EROEI (Energy Returned on Energy Invested) of various energy sources (although oil is prominent by its absence, I added some in later).  Those charts are online at The Ecologist magazine.  Although I found them interesting and useful, I thought they would be much more useful if they were combined.

The result is above: a scatter chart showing the relationship between EROEI and Carbon Intensity for various forms of energy.  Because a high EROEI is good, we would prefer to use energy sources far to the right.  Because low Carbon Intensity is good, we would prefer to use energy sources far down on the chart.

Several energy sources were "outliers" -- they didn't fit nicely on the chart as scaled, so they are marked by half cut-off blue dots at the very edge of the plot.  Their label includes the actual value, so although the "Tar Sands (465)" dot is at about 260 gCO2e/kwh, the actual value is 465 gCO2e/kwh as indicated by the (465).

For any given application, this chart provides a (roughly) optimal ordering of energy sources.  Wherever possible, Tidal Range power is the highest EROEI and the lowest (or very very close to the lowest) Carbon Intensity.  Next is a choice between Offshore Wind (if you prefer to reduce Carbon Intensity a bit more in exchange for a bit less EROEI) or Sewage / Landfill Gas.  And so on.

You'll notice that the included petroleum and petroleum like fuels (US oil, tar sands, Coal) are very dirty, except for possibly "Clean" Coal, which doesn't really exist yet.  And there are alternatives to each of them which have higher EROEIs.  But none of them have the physical energy density that these carbon based fuels like oil have.

A simple conclusion is obvious: carbon based fuels should not be used for electrical generation (that's what most of these energy sources are, with the exception of Solar Thermal and the generalized cogeneration of electrical power and heat intrinsic to Sewage / Landfill Gas, Concentrating Solar Power, Solid Biomass, and so on) if any of these other alternatives are available and can supply a significant fraction of the required power.

2009.01.17

Printing Over Airport

With the advent of Leopard and perhaps the 5.7 version of Airport firmware, there are some problems printing using the wireless system.  They can manifest a couple of different ways, including:

  • Time Capsules "lose" the printer every so often;
  • Airport Extreme Base Stations print the first document through them, but freeze on the first page of the second document.

I got a Time Capsule to encourage my wife to make backups, and it replaced a first or second generation Airport Extreme Base Station (the one that looks like a spaceship).  Unfortunately, it exhibited the first behaviour listed above.  So today I add the Airport Extreme Base Station (hereafter AEBS) to the network and hooked my Samsung ML-2150 laser printer to the AEBS instead of the Time Capsule.

Whereupon it exhibited the second behaviour listed above.

After much testing and cursing and installing of drivers, I came to the following fix: by using IP addressing instead of Bonjour, I don't lose the printer.  The step by step procedure is:

  1. Bring up your System Preferences...
  2. Select 'Print & Fax'
  3. Click on the '+' to add a printer
  4. Click on the 'IP' icon
  5. Select 'HP Jetdirect - Socket' from the Protocol dropdown (it defaults to 'Line Printer Daemon - LPD')
  6. Put the IP address of the AEBS in the 'Address' box
  7. Leave the 'Queue' box blank
  8. Put whatever name you want into the 'Name' box -- it will default to the IP address
  9. Select your desired print driver from the 'Print Using:' dropdown which defaults to 'Select a driver of printer model'
  10. Click 'Add'


As a side note, if you have an ML-2150 and you lost long-edge bound duplex printing at some point, the gutenprint 5.2.3 version restores it.

2008.11.24

Zack Learns How to Throw

Sometime over the last couple of years, Zack learned how to throw things.

When World War Zed started, Zack relied on human zombie wave attacks.  Some had millions in them, walking toward us with their groans and their smell and their teeth.  We had to rely upon heavy firepower to deal with them, because they’re not like people.  Zack never gets scared.  Zack never gets tired.  Zack never sleeps.  Zack never needs food, even though he’s always hungry.  But Zack couldn’t hurt you if he couldn’t reach you.

Now things are different.  Now Zack throws things.  I don’t know what they are, but if they cut you, it’s curtains.  Whatever it is that makes Zack Zack, it’s in those things he throws at us.

The first time I found out about them we were clearing a couple of houses.  When we’re training, we call this “Jail Break”.  I don’t know why.  Zack had at least a couple in the structures and the yards.  We had to get close to clear the houses.  You spread out and check behind and under everything you go past, because Zack can be anywhere.  Zack doesn’t breathe, so you can’t hear that.  Sometimes Zack makes noise, but he can be quieter than any human you’ve ever seen.  You keep your weapon up so the muzzle tracks with your eyes.  As soon as you see Zack, you’re on target.

We were crossing the field toward the houses when we saw Zack, standing in the right hand yard.  I let the right side of the line handle him, but he threw something at Fred.  Fred screamed and went down.  I had to run forward about 20 feet to get a clear shot across the front of the line.  My PDW burped softly as Zack got three in the head. It was hard to hear the silenced rounds over Fred's screaming.

Running forward while you’re clearing ground is dangerous, because you don’t have the chance to make sure of every space when you’re in a hurry.  Once you’ve stopped clearing space, sometimes it’s best to just keep moving.  I charged the house on the left and circled it.  Zack was there too, but looking toward where Fred was still screaming.  He didn’t even start to turn until my first round missed his head and hit his shoulder.  The burst walked up and across the right side of Zack’s head and he dropped like a puppet without any strings.

I hear the right side of the line running forward toward me, and I called “Crash 3 behind the structures, one Zack down” into my mike so I wouldn’t catch any friendly fire.  With my buddies coming in I did a 360 to check the open space for Zack.  It was clear.

When I turned back to the first kill I saw Fred leaning over Zack.  He was pulling something out of the skull and jamming it into his mouth.  Fred looked up at me and started in my direction.  There were grey and red scraps hanging from his mouth, and his fingers were bloody.  He groaned.  That long, low, moaning, growling sound that only Zack makes.

I put three in his head.

Influenced by a game of Zombie Jail Break at North Shore Paintball over the weekend.  It was an epic Zombie fail, and just playing the game, much less taking down all the zombies, absolutely made my day.

2008.11.06

Fall Convocation 2008: Simon Fraser University

Caps


Last month, I received my MBA from Simon Fraser University. My family persuaded me to attend convocation, although my previous experience (BACS, UC Santa Cruz, 1983) had left me disinclined to attend

I am so very grateful that I was persuaded. After gowning, lining up, precessing, and waiting (since there were no doctorates to be awarded, we MBAs were the first of about 400 students to reach our seats), we were sitting and listening to what I expected would be the traditional boring platitudes about how wonderful we were, how fantastic our experience at school had been, and how we would now proceed to change the world, preferably through good capitalist means.

I had forgotten that I was in Canada.

Dr. Michael Stevenson, President of the university, gave a fantastic speech:

The movement over the last quarter century to lessen the size and cost of the state, and to liberate the market from bureaucratic regulation and inefficiency, has been characterized by many contradictory trends. For example, the promise of less government has been undercut by the continued growth if redirection of government spending; the promise of the free market has been undercut by “irrational exuberance” of poorly regulated capital markets; the assurance of better services has been undercut by the health and safety threats in deregulated water, power and food systems or the increased visibility of homelessness and drug addiction following the deinstitutionalization of mental health care. Domestic “wars” on drugs or crime are as ineffective in achieving their announced objectives as the international War on Terror. And claims to political superiority grounded in the defense of human rights and civil liberties are devalued by arbitrary arrest and the abrogation of legal rights in defense of “homeland security,” and by the more general pressure to liberate executive power from judicial restraint.

For reasons like these, the events of the last few weeks underline the limits of American and North American domination, whether economic, military or political. The world is a much different place than it was even a decade ago, when we celebrated the advent of a new millennium.

As new university graduates you know the world is a more complicated and dangerous place. You know that this is not only a question of the rapid restructuring of economic and political power in the global market and international order. It is also a question of the life of the planet itself…of fundamental changes in climate and ecosystems, the intensified risks of natural disaster and reduced biodiversity, and the hugely complex issues of adaptation to and mitigation of environmental change.

Despite the magnitude of these challenges, and despite the rhetorical drum-beat of electioneering calls for change, the political response is so far not encouraging. Governing and opposition parties still vie for the embrace of lower taxes, knowing apparently that most of us will favour a marginal increase in private consumption over any collective investment in public infrastructure or social services. Courageous leadership on climate issues is the exception rather than the rule, and it is met with opportunistic opposition to carbon taxes, unless they be levied on someone other than ourselves. Public investment in the arts as a means to building the creative economy and improving the quality of life is opposed as a sop to cultural elites and a subsidy to work that affronts the sensibilities of ordinary men and women, as great art tends to do when first produced. And public investments in education, which are so urgently required in order to rethink the fundamentals of our ways of life and to redefine long term strategies for social change, are increasingly targeted to the short-term demands of the existing labour market and to the shortest possible return on investment through the commercialization of research.

Serious discussion of these and other issues is muted by the forces governing our electoral politics. In the age of mass communications simple plurality, first-past-the-post, electoral systems force convergence on issues and differentiation on image. Trash advertising and spin, segmentally targeted to different “demographics,” manipulate political sentiment and undermine rational discussion.

This is a different place.

2008.08.19

McCain Speaks Out of Both Sides of His Mouth

Ambition_large


Photograph: John McCain 2008 Campaign Website
Photoillustration: Evan Robinson, Mischievous Ramblings II

http://www.thecarpetbaggerreport.com/archives/16605.html

2008.07.26

Testing

Test blog post from iPhone.

2008.03.22

Snowboarding

As a long-married man, it's dangerous for me to say that I've been inspired by another woman, but since Ducky talked about her (almost) first snowboarding experience this weekend, I guess I need to talk about mine last weekend.

I agreed quite a while ago to go snowboarding with Kiernan, but it's taken at least a month to find a usable weekend day, which turned out to be last Saturday.  Kiernan has taken a few lessons before deciding he liked skiing better, but I haven't been interested in skiing since I was a kid, and boarding seems to have more fascination potential for me.

We started with a two-hour lesson from a young lady named Louise.  Kiernan did better than I did, of course.  Not only does he have some experience, he's a natural athlete.  While Louise showed me how to push myself along, use my edges, go down the hill forward and backward, Kiernan simply did it all.

As Ducky says, boarding is, well, boarding makes you sore :-)

When boarding down hill, you dig in with your uphill edge to slow down, and ease off digging in to go faster.  If you dig in with your downhill edge, you fall down.  Fast.  You slide from side to side by shifting weight from one side to the other.  In order to do all these things, you use your leg muscles.  A lot.  You bend your knees and and shift your weight back and forth (or side to side, depending upon how you look at it) to control direction and speed of travel, as well as to cushion vertical impact.  When getting up, you go from kneeling or sitting to standing using primarily (or exclusively) your calves and thighs.  It's hard work.  When pushing your uphill edge in, you use your calves and feet.  And I, at least, had to use a lot of leg strength to shift my weight enough to go left (right was easier for some reason).  Rest was essential -- and I got it by falling down whenever I needed it.

The night after spending 2 1/2 hours boarding for the first time, I woke up several times with severe thigh cramps (a first for me -- I've had calf and arch cramps, but never as high as the thigh).  I wanted to scream, but we had to get up early to get Sara to the airport, and I wanted her to have as much sleep as possible.  So I went downstairs to scream :-).  A week later, my legs still hurt, and I'm actually bruised on my right thigh.  Bruised from mere exercise.  Quite an experience.

Still, it was fun,and I certainly plan to try it again.