Saturday, December 27, 2008

Another great reason to use a GPS when cycling

Back in the summer of 2007, I was riding my bike every day from John Muir Health to my home in Livermore. I am a fairly cautious rider, so I would take the the Iron Horse Trail to keep my interaction with automobiles limited to cross walks as much as possible.

One day (June 18th, 2007), I was riding home, and I got hit in a crosswalk crossing with the green light. I had stopped at the signal, pressed the button and waited for the light to change. Right after the light changed, as I pushed into the crosswalk, I noticed a guy who was making a U-turn just down the street. He looked like he was in a hurry, maybe he was lost, and I was a bit worried about him, but I figured I had a red light in my favor. Well, by the time I got about halfway into the lane, I saw that he was accelerating directly toward me. I jumped hard on my pedals, hoping to get out of the way before his SUV swallowed me under his tires.

I remember looking at the front of this huge car bearing down on me, thinking “I’m going to be killed”. I pedaled as hard as I could, and succeeded in getting my body out from in front of him (and actually most of the bike), but didn’t quite get all the way out and he hit my rear rack. I spun around felt something tweak, and slapped my hands on the pavement. I was about 10 ft outside the cross walk, and my bag was another 10-15 ft out.
Before he hit me I kept wondering “how many stitches is this going to be” (well at least after I stopped wondering “Am I going to die today?”).  I don’t know how fast you can get going in 90-100ft, but whatever it is it seemed like he was flying when it hit.

After he hit me, he started yelling at me saying “you came out of nowhere” and “you must have been flying”, at which point I started yelling back and pointing at the not yet flashing crosswalk sign to let him know I had the green, and made sure he knew that he must have run a red light.
A few seconds later an ambulance pulls up, and paramedics start looking at me (they just happened by – saw me yelling at the guy). They iced my wrist (which at this point I thought was my only injury), and urged me to go to the hospital. Then a couple of motorcycle cops pulled up (one left right away to chase a bank robber – really, somebody was robbing a bank in Danville), he took some info, and then interviewed the guy who hit me.  I went to the ER, and by the time they took Xrays and I saw the doctor, everything was starting to tighten up. Overall, I was lucky, and all I ended up with was some minor scrapes, a totaled bike, and some bruised ribs.

Now the interesting part about this accident to me was that I was now out a bike, and from what the cop said, it was likely that it would be a case of my word vs. the guy who hit me. I thought that I’d at least try to prove that I had stopped at the cross-walk, and since I always have my Garmin GPS running when I’m riding, I was able to do so.

Taking the data from my GPS, I was able to detail out exactly the time I got to the intersection, and send the following note to the investigating officer:

Thanks for stopping and doing the report on my accident. I feel very fortunate to have escaped with such minor injuries.

If you have the information on the guy who hit me (contact info, insurance) that would be helpful.

I apparently cracked (or bruised) my rib cage with my elbow during the impact. I think I showed you the damage to my bike at the hospital.

I wanted to pass along information that I have from my GPS (I have a Garmin Edge 305 that I use to track my workout with), which may be of interest to you.

I imported the data into Google Earth, and as you can see it shows the location of the accident and my bike ride. It appears that the image is shifted a bit to the south, but it’s within a few feet, and give the general route I took.

Google Earth of my bike ride

Here’s the timeline I got from my GPS:

4:24pm – Stopped at signal button at north side of cross walk in trail.
4:25pm – Started into street. Before starting to move I observed the car making the u-turn. Looked like he was slowing and going to stop.
Signal has a countdown from 25 seconds, so I still had plenty of time to cross.
Observed the car accelerating and realized he wasn’t going to stop (by this time I was out of the shade in the second lane)
Tried to avoid the car, and almost got out of the way – he was going pretty fast by that time (however fast you can go in the 80 feet or so from where he turned around).
Bike spun and I went forward about 10 feet.
He pulled over, and started yelling at me about my “coming from nowhere” and “moving fast” (fastest speed the GPS clocked me at was 3mph).
I yelled back and pointed to the crosswalk signal, which was still flashing (although I think the countdown was gone by that time).

Below is the same data in the Garmin software, showing my heart rate. The blue dot is where I was on the map, which corresponds to the line on the graph which is where my heart rate was the lowest. The next dot south of that is where I got hit (which corresponds to the huge spike in my heart rate with a small bump in speed).

Before getting hit

The next shot is after I got hit – approximately a minute after I stopped at the light.

After accident

I did go back to the scene of the accident, and found that as a driver, that intersection is less than obvious (it’s a cross walk in the middle of a very busy street). At the time of day that he hit me, the sun would have been directly behind the stop light, and he wouldn’t have been able to see me in the shade waiting for the light to change, so I understand much better why he ran the light (of course the beer he admitted to having probably didn’t help either). It really seems like they need a bridge or a tunnel at streets like that: it’s just way too easy to miss a stop light that is not placed at an intersection with another street (although I supposed it might be possible to architect this sort of crossing to look more like a normal intersection in order to trigger that recognition).

Eventually with this evidence (along with the fact that the guy that hit me had lied about having insurance), the cop ruled that the accident was not my fault, and I was able to get my bike replaced using the uninsured motorist portion of my policy (which I now know covers me for accidents where I’m not actually driving a car). Now, this never went to court, but I think had it done so, the GPS evidence would be pretty compelling (especially since it shows I stopped long enough for my heart rate to drop off, and there are data points for every second of the ride).

Friday, December 26, 2008

EJB or not JB? That is the question (sort of) …

I recently read a post on LinkedIn on the WAFUG group by Andrew Hedges:

Frameworks or libraries?

“Frameworks are larger abstractions than libraries. Abstractions leak, cost performance and take up mental resources.” … http://tr.im/20fm

Is the whole framework craze overkill for most projects? At what point does it make sense to use a framework over libraries that just do what you minimally need? Is it better to start with a large, leaky abstraction or only impose it if/when the project gets big enough to need it?

The answer to this for me is “it depends”, and it’s what keeps architects up at night. Frameworks are usually attempts to encapsulate some best practice or design patterns in a way that will help the developer achieve some gain in productivity, scalability or reliability.

During the dotBomb era, I worked for a small boutique consulting company designing web sites for a lot of startups. All of them were convinced they would be the next big thing, and most of them had extremely aggressive targets for scalability.

Because of this, we spent quite a bit of time with various frameworks trying to understand the balance between the complexity introduced and the scalability that the framework would give us. At the time, Sun was busy pushing the EJB framework, which was a study in how to over-engineer software. The big benefit promised by EJB was that you could theoretically scale your application to infinity and beyond. The downside was that it basically took a huge team of rocket scientists to get off the ground (this was not the nice simple POJO based EJB of today).

What we found was that in most cases, we could get the same sort of scalability for our clients out of simple Model 2 JSP based applications (MVC approach) by taking care to design the application from the database forward. By using the database for what it is really good at (caching, storing and reading data), building DAOs to interact with the database, and factoring the business logic out of the JSP’s, we were able to build a reliable MVC framework that we used with many clients. The framework was very similar to Struts, which didn’t yet exist, and which we started using once Struts2 was released.

Turns out that the amount of traffic that you have to experience to require the overhead of a complex framework like EJBs is not realistic for any but a handful of web sites.

Fundamentally as an architect, it’s my job to figure out what the real problem is, to solve that in a way that will answer the business need (immediately),  and to build it in a way that will allow for some level of deviation from today’s needs (future scalability and flexibility). So for almost every case that we came across, there was too much complexity and overhead in the EJB framework to make adoption a valid choice back then. Not only did an EJB design require significantly more developer work than the alternatives (making it more costly and harder to change), the initial application wouldn’t perform as well (since it was burdened with all the code that was required to make it scale seamlessly).

All of that said, EJB is also a great study in how a framework can be improved. With the current value proposition of EJB3, the objections that were so clear before have gone away: it no longer takes a rocket scientist to engineer EJBs, and in fact any complexity is fairly well hidden from the developer. Most of the overhead of the framework has been moved into the run-time, so it scales much more appropriately.

As an architect, my decision becomes much easier to include a framework like EJBs when it both saves development time, and gives me a clean and simple path to change. There’s always a balancing act between the time to market, and anticipated change in the application too. I worked on some applications that used MS Access or Domino to get off the ground quickly because when used as a framework those applications are great RAD tools. You can prototype and get to the 95% level of usability for an application very quickly, and for many apps this is better than good enough.

The problem with these (as with almost any framework) is when you get to the point you need to do something that the framework wasn’t designed for. You built a killer app in Access, and now you want to roll it out to the entire company. Well, even though Access claims to work for multiple users, turns out it is a pain, and uses some very archaic methods for things like sharing the database. And even if you reengineer it to store your data in an enterprise DB, it still has the problem of needing to be deployed somewhere or being shared (which again runs you into the locking and corruption problems).

Every problem requires thought and some knowledge of the limitations of the tools in your tool box. By understanding the business problem, and coming to a reasonable understanding of what sorts of changes you can anticipate (including unanticipated ones), you can choose the right level of complexity to solve the problem for today and tomorrow.

Wednesday, December 24, 2008

Content that’s too dynamic …

Recently I’ve been noticing that ad content is being served up much more dynamically than I’d expect. When I’m looking at the menu on TiVO, or surfing Facebook, there are always little ads displayed that don’t immediately catch my attention. In fact most of the time, the ad doesn’t even register until I’ve clicked something and am waiting for the next page to load.

So, as the page disappears, I notice that the ad is something I’m interested in. On some sites, I can simply hit the back button and the ad will still be there, but on a lot of others (Facebook for example), the ad gets replaced with something else. So now instead of the “Virtual Cycling” ad that piqued my attention, I see an ad for Phoenix University.

It always seemed to me that if I hit the back button, I should see exactly the same page that was just displayed, since after all the browser just rendered it, so shouldn’t it be able to just redisplay the previous rendering? The problem is that the actual way pages are rendered causes this. The ads are actually links that point to dynamic content, so when the page rerenders, the content is rendered again, which in the case of Facebook means I lose my ad.

Seems to me that they could take advantage of the session to understand that I’ve just hit the back button, and redisplay the same ads again, just in case that’s why I hit it. The current approach is losing click-through revenue for Facebook (at least from me for my “Virtual Cycling” example).

TiVO has something similar: they display little ads in the menu system. One liners like “sign up for a Visa” or “see Lost previews”. The same thing happens there, by the time I realize the line said something interesting, I’m on to the next screen. Luckily with TiVO, these choices actually cycle, so all I have to do is go back and forth a few times to see all of the current ad lines, so eventually I can get back to the one that piqued my interest.

Monday, December 22, 2008

They don’t shoot Eagles do They ?

When I was a boy, we lived in south eastern Alaska in the small chain of islands north of Ketchikan, first on the island of Wrangell, then the island of Petersburg. This was one of the most amazing places to be as a boy, the perfect place to learn about nature, and beauty.In Petersburg, we lived a couple miles out of town along this road that ran to the other end of the island, in this house that sat on stilts hanging over a cliff that looked out on the strait (almost all the islands there are so close together that if the water wasn’t 35 degrees you could swim to the next one). The house was nestled in the pine trees, and always looked like one of those postcards of a green forest with wisps of fog floating around the trees. It rained constantly, which was incredibly fun for us, since we got to play in the mud every day. We could always spot the tourists because they would be the ones trying to walk around the mud puddles.The house on the cliff was separated far enough from the neighbors that it felt remote, and we were surrounded by nature. We’d often see the bald eagles circling and once in a while see one flying home to their nest with a fish in their talons, or skimming the glass like surface of the water. All in all a very peaceful place to be.One day we had a very different experience with the bald eagles. It was a quiet morning and we heard a commotion out on the deck (the top story of the house had a deck that hung out over the hill), so we all hurried to see what was going on. When we got to the window, we were amazed to see a bald eagle flapping about on the deck, banging into the window and trying to find his balance. It’s hard to imagine the sheer size of this bird when you see them flying high up in the air. But with six feet of wings he didn’t fit too well on the narrow deck, and after a moment he fell to the ground below.He had been shot. He flapped around for a bit more on the ground below the deck, and eventually died. None of us could understand why anybody would shoot at such a beautiful and protected creature, symbol of our nation, but we could definitely understand why his mate was circling overhead. I don’t know how long she circled overhead, although I’m pretty certain it was over a week. They mate for life and she wasn’t about to give up easily. Her mournful cries echoed overhead as she circled, and it made us all sad and mad.The Forest Service came and collected the body, and I remember my Dad asking them questions about what they would do, and if they would catch the person responsible.  I also remember he wrote a very moving piece about the insanity of the killing in his column called Weaver’s Loom.As a boy in Alaska, I fished almost every day. And most days, I could simply look down in the water, and pick which fish I wanted to catch. So what sort of insanity would make a hunter think that an eagle could even make a dent in schools of fish that number in the thousands. And if the hunter wasn’t just stupid? What if he was a poacher, thinking that he’d get a bald eagle and sell it to some collector for thousands of dollars? Well, at least then we could take some comfort in the fact he didn’t get his prize.

Using LinkedIn to generate a PDF “resume

I ran across a post on one of my LinkedIn groups from a fellow member named Mike Smith, the text of this post is on his blog at http://dominoconsultant.blogspot.com/2008/12/export-pdf-resume-from-linkedin-without.html

Basically the trick is to make sure your profile on LinkedIn is up to date with all of your best resume information in the career section, then use the magic icon on your profile to produce a PDF. My friend Walt Feigenson posted an entry on his blog that takes this idea one step further by introducing a web site that allows you to pick and choose which pages to include in the PDF before you send it. Walt’s post can be found at http://feigenson.us/blog/?p=163

While this isn’t an ideal resume, it does get to the “good enough” level for recruiters (assuming you’ve actually updated your profile with all the salient information), and as Walt points out, you can extend the idea by splitting out information like your references to send along to a hiring manager.

A couple of people suggested to me that perhaps using a PDF printer would be an easier way to accomplish this same task. The advantage that using the PDF button on LinkedIn has over this approach is that it produces a nicely formatted version of your profile, which doesn’t include all of the buttons and other things that are displayed on your profile. By downloading the PDF in the format that LinkedIn produces, you get a relatively simple resume that you can send out (either with the technique that Walt talks about, or printing to a PDF printer the pages you want to keep).

Sunday, December 21, 2008

A nod to my Dad …

My dad was a newspaper reporter and editor, and for a time in my youth (and his too, I suppose), he was an editor of a couple of small papers in Alaska.

During that period, as the editor, he wrote an editorial column that he called “Weaver’s Loom” where he wrote stories and posted his opinions. I remember all sorts of entertaining stories in that column, things about the family, events that happened to us, and even a posting of my creative writing about Santa (where I had him upgrade the sleigh with a rocket ship).

So when I started this blog, I thought I would borrow his column name in honor of the fabulous tradition of Weavers spinning their tales. If you want to see the professional writer at work, check out my Dad’s blog at http://www.virtualbob35.blogspot.com/

I don’t have a particular focus, and I expect this won’t be the sort of blog that has lots of followers because of that (more of a journal that might be interesting to people I know). Anyway, the experiment is begun, and I’ve started “blogging“, so expect to see short stories here in between the technical and business postings.

Saturday, December 20, 2008

Moving my VolunteerCake to my Mac …

I have been running my development for VolunteerCake with a database on my Windows box which sits in my office with my Mac. I went to meet some people at a coffee shop, and realized that I couldn’t show them the app running on my MacBook because I was no longer on the same subnet with my Windows box, so I decided to move the database to the Mac to allow me for this.

Since I had everything in place to run Cake on my Mac except for MySQL, the first step was to install MySQL. This turns out to be pretty painless. Just grab the DMG from the MySQL site, and voila, new MySQL running on my Mac. Checked everything out using the MySQL administration tools, and it all looks good (I can access the DB, set up users, etc.)

Next I need to put the data in the database, so I just do a quick export from the phpmyadmin page on the PC. I end up with a file that is the SQL needed to replicate the entire database on my Mac. I run this SQL into the Mac MySQL, and now I have an exact copy of the database on my Mac.

After that, I go to the SQL administrator tool and make sure I have the user set up to give access to that database and make sure the username and password are the same as I was using on the PC (if I were more of a DBA, I’d probably have done this with command line MySQL, but I like GUIs, especially for things I don’t do every day, and the MySQL tools are pretty cool).

Then I need to change my database.php to point at the local database in order for VolunteerCake to get the data from the Mac. This should be as easy as changing the name of the host name to ‘localhost’ from ‘monet’ since I’ve set up the user and access to the database exactly the same as what I had on the PC.

Finally, all that’s left is to fire up the same URL that I have established for my app on my Mac (http://test.lctd.org/VolunteerCake) and … wait, that didn’t work. It says it can’t find the table acos for the Aco model …

Weird, the table is there, I can connect just fine, what could this be? A quick trip to the IRC channel, and I get the suggestion of clearing my cache. OK, try that … But hit the URL again and no change.

OK, now I’m confused, so I try running ‘cake bake’ … Now something interesting: I get an error that tells me that it was unable to connect to /var/mysql/mysql.sock – what does that mean? I thought I was connecting with a TCP socket, why does it want a file? Is this some sort of file permissions issue ?

Back to the IRC chat for some guidance, thinking maybe it’s a common problem, a permissions issue or something, of course they tell me to do exactly what I’d tell somebody else to do: verify that you can connect from PHP first. Good idea – so I whip up a quick connection test page, and get the same error. So now I’ve confirmed that it’s a PHP problem, and not a Cake issue.PHP can connect to a remote DB, but not the one on my local Mac …

Now it occurs to me that I often have problems that end up being related to the open source software that came bundled with the Mac, so I do some Google searches on PHP connection to MySQL for Mac OS X, and with the connection error messages. Eventually I find what looks to be the issue: for some reason the MySQL configuration sets the socket file to /tmp/mysql.sock but the PHP that comes with the Mac is looking somewhere else (at /var/mysql/mysql.sock to be specific). So I basically have three choices, edit the php.ini, edit the mysql config file, or build symlinks to make the file accessible at both locations.

I decide to change the php.ini file, which turns out to be another excercise in hunting, since Mac OS X likes to hide the files you’d expect to find in the /etc directory. After some more Google searches, I find that the PHP5 install that comes with Leopard puts the php.ini file into /private/etc, so I edit that file, changing the part of the file that looks like the following:

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

To be:

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /tmp/mysql.sock

In order to have PHP find the mysql.sock in the location that MySQL is actually creating it. Check my URL again, and voila, everything is working !!!

So, to make a long story even longer, I relearned that mixing actual open source with vendor open source is often problematic. It was suggested by at least one person (Mark Story) on the IRC channel that the best way to set up for Cake development on the Mac is to use MacPorts, since then you end up with matching versions of the software all in a “normal” open source location.