Always Question Your Assumptions!

During a guided tour of an asylum, a visitor asks the director how he determines whether a patient is crazy or not.

"Simple" replies the director, "we fill a bathtub with water, we give patients the choice of a spoon, a cup, or a bucket, and ask them to empty the bathtub".

"I see!" exclaims the visitor. "So obviously a sane person will choose a bucket!"

"No" says the director, "a sane person pulls the bath plug. Would you like our standard room or one with a view?"

(Hat tips to my father for the joke, and to shell belle for the picture)

Solving the Hyperpublic Coding Challenge in Mathematica

I quite enjoy the various coding challenges that appear to be gaining in popularity. Greplin's was a lot of fun and yesterday Hyperpublic released one of their own. Since I just noticed that a number of people have posted their answers I thought I'd post mine.

I like to use Mathematica for these challenges. Why? It's a really powerful environment, it's a lot of fun to use, I have a copy :-), and completing these challenges always teaches me more about Mathematica itself.

Challenge 1

In this test you're given a file that represents which users have invited others, defines an influence metric, and asks you to find the influences of the top three influencers.

Read in the sample file
l = ReadList[NotebookDirectory[] <> "Hyperpublic Q1.txt", String];

Define a function that returns the positions of the Xs in a line
CalcFriends[s] := Map[(#[[1]] &), StringPosition[s, "X"]]
This returns a list of the positions of the Xs in a String
E.g. CalcFriends of the fifteenth line (which represents a user with four friends) generates the indices of those friends
{12, 23, 84, 93}
A line with all Os (no friends for this user) gives
{ }

Map CalcFriends over the list of lines
f = CalcFriends[#] & /@ l

A recursive function to calculate a user's influence
Influence[l_List] := Length[l] + Fold[Plus, 0, Influence[f[[#]]] & /@ l]

Now we just map Influence over the output of CalcFriends and take the top 3

Take[Reverse[Sort[Influence[#] & /@ f]], 3]

Challenge 2

Here we're (essentially) asked to find the minimum of moves to achieve a target.

For some reason, even though I knew this was a linear optimization problem, I started coding it. A mistake caused me to rethink my approach which, when you're using Mathematica, usually goes along the lines of "Why am I writing code?! I'm sure there's a function for this in here somewhere!" :-)

Lo and behold, there was:
FindMinimum[ {p1 + p2 + p3 + p4 + p5 + p6, 
2 p1 + 3 p2 + 17 p3 + 23 p4 + 42 p5 + 98 p6 == 2349 && 
p1 >= 0 && p2 >= 0 && p3 >= 0 && p4 >= 0 && p5 >= 0 && p6 >= 0 && 
p6 ∈ Integers && p5 ∈ Integers && p4 ∈ Integers && p3 ∈ Integers && p2 ∈ Integers }, 
{p1, p2, p3, p4, p5, p6}]

But you should see Yaroslav Bulatov's solution for this problem, it's much more elegant.

Fun stuff... Not only does Mathematica give you some great tools for solving problems, it also solves them fast.

Rails3 Custom Password Validators

As I was writing validators for the User class of a Rails 3 app, I wanted to make sure that people wouldn't use their names, usernames, or email addresses as passwords.
Unfortunately I couldn't find a way to accomplish this with the built-in validators. Fortunately Rails 3 makes it easy to write your own custom validators.

Here's an extract of my User class

The "password => true" tells Rails to call my custom validator which, in this case, has to be called password_format.rb.

I keep my custom validators in /lib/validators, so I need to add the following to my config/application.rb file:

And finally the validator itself:

(Don't forget to write the specs to test this! :-)

"You're a leader of servants, not a servant leader" and other warning signs

Yesterday I was surprised by this post from the Wall Street Journal: Five Signs You're a Bad Boss. Surprised because most of the signs listed were so obviously bad only the worst bosses could be oblivious to them. I quote:

1. Most of your emails are one-word long
2. You Rarely Talk to Your Employees Face-to-Face
3. Your employees are out sick–a lot.
4. Your team's working overtime, but still missing deadlines.
5. You yell.

Yelling? That's all they can come up with?  Or am so out of touch with how most bosses perform?

Of all the signs listed above I think #3 is the most interesting: given a large enough team size, this is an external metric HR could track as an indicator that something's wrong... Though of course there are many more reasons for people to take sick days than having a bad boss.

Reason #4, working overtime and missing deadlines, is clearly bad but in my experience many companies (certainly in high tech) don't track their employees' hours and so may not detect long periods of overtime. Moreover an organization that tolerates long periods of overtime and missed deadlines is itself guilty of poor performance, nevermind the boss.

It's always easy to criticize so here's my attempt at creating a more useful set of signs. These aren't all encompassing, there's a lot that could be added: fostering innovation, continuous improvement, recognition...

Think of these as a leadership Minimally Viable Product.

1. You communicate by "telling" not by "sharing", and infrequently at that
Telling is top down and usually focused on "we need to do X". Sharing is egalitarian. It's "here's why we're doing this" and "here's what's going on outside our group". By explaining or emphasizing the purpose of the team's projects, your employees will be bought in and better equipped to make decisions about priorities and tasks.

Recommendations: Communicate often and use multiple forms of communication, especially with large and/or dispersed teams.  At RelayHealth we used email, daily standups, experimented with Yammer, and had weekly / bi-weekly / monthly all hands meetings (as the size of the team grew I made those meetings left frequent to make space for managers to gather their teams together). Focus on context and purpose, not just nuts and bolts.

 

2. You don't know your employees
Do you know every person on your team by name? Do you know them as a person instead of someone who's on project X? Are you aware when something of importance happens in their private lives (e.g. birth of a child, passing of a relative)? If your team is large enough that you can't know everyone, are you making sure your managers are getting to know their employees?

Recommendations: Even if you don't interview all new members, welcome them to your group personally. Their manager will explain their duties but sometimes you're best placed to give them the wider context of the organization and the purpose of the group's projects. 

At RelayHealth, I took every new employee out to lunch after they'd been on the team a couple months: it gave me another touch point after welcoming them to the team, I could make sure they were doing OK, and it was an opportunity to find out if there were any improvements they thought we could make to our tools, processes, habits, etc. I learn a lot from doing this and often discussed the feedback I'd received with my managers.

 

3. Your employees aren't taking on new responsibilities
Are your employees growing? When was the last time you promoted someone? Or even had an employee take on a new or expanded role within your group? They should be, and you need to help them. 

Recommendations: Identify your top performers, ensure they have mentors, help them grow. At least once a year you and your managers should review all employees in your group and focus on how they are performing in the current role, what their career aspirations are, what opportunities you see, and how the management team can facilitate that growth. At RelayHealth, this meeting took us the better part of a day but it was time very well spent.

 

4. You're not mentoring one of your employees to replace you
This will likely be the most controvertial recommendation but I believe one of the best things you can do for your organization and your employees is mentor one or more of them to replace you. If you're worried about job security: it's too late! Extrinsic job security is an illusion. Intrinsic job security comes from performing to your fullest potential. Helping to grow the next generation of leaders is one of the most rewarding things you can do.

 

5. You don't give your employees realtime performance feedback. And, more importantly, you don't expect the same from them
The best time to catch and correct a performance problem is when it happens. If you've cultivated an open and honestly environment this feedback shouldn't be contentious, it should be a gift. You're helping someone improve, or someone's helping you!

Recommendation: Be mindful how you communicate. Don't blame. State the behavior you witnessed as objectively as possible and then explain how it made you feel personally or how you feel it impacted the group. Discuss alternative options. And when someone gives you constructive feedback? Thank them profusely, esp. if they report up to you. Giving feedback to your boss or your boss' boss takes courage. 

 

6. You tolerate poor performers and poor cultural fits
You can't afford to tolerate either for long or they'll impact the wider organization. Poor performers waste your team's time. Poor fits can destroy morale and productivity.

Recommendations: Periodically ask yourself "Would I hire this team member again in their current role? Would I hire them in a different one?" If it's a skill set issue then help the person learn. A cultural misfit shouldn't be tolerated long. In either case, realtime feedback is important to give the person a chance to change. I've long admired what Zappos does here: if, within a month of joining, you don't think you'll be happy there, Zappos will pay you $2,000 to leave. A very smart way to incent poor fits to manage themselves out of an organization.

 

7.You're a leader of servants, not a servant leader
If you're managing knowledge workers, they'll likely know more than you do in at least some areas, and often in many areas. Not giving your employees the autonomy to own their work is one of the worst ways to waste human capital.

Recommendations: In my experience a manager rarely has all the answers. A good leader focuses on asking the right questions. Helping your employees think through a problem, avoid pitfalls, and learn from the experience is a lot better than giving an answer (which may not be that great anyway!)

 

 

In the end here's what matters: Celebrate your employees!
Celebrate them by doing what you can to make them shine. The more your employees thrive, the more you're doing a good job. 

And when they outshine you? You'll know you've succeeded!

(Thanks to Mike Myers for letting me mod one of his pics)

The Day We Didn't Start eBay

Today has been a day of walking down memory lane. I've been looking through projects I worked on 15 years ago as I was studying in Europe and the US.

One in particular caught my eye. At the time I was studying for an MBA at the Solvay Business School in Brussels. It was a fun time: lots to learn, students from all over the world, and for the geeks among us, the dawn of the web.

Here's the startup a group of us researched for our New Ventures class. I've only reproduced the proposal below, we did a lot more analysis. We even interviewed Christies and other brokers...

March 1, 1995.

New Ventures

To: Professor Spindler

From: Michael ...
Won ...
Bart ...
Paul Clip

Re: New Ventures Proposal

The creation of a on-line collectibles brokerage. Collectibles (stamps, telecards, basecards, currency, etc.) are a worldwide phenomenon attracting vast crowds of collectors and money. Our company will setup an Internet World Wide Web server enabling customers anywhere anytime to buy, sell and exchange collectibles.

Could we have founded eBay before eBay? Unlikely... In early 1995 the web was in its infancy and the situation was much worse in Belgium, as high telco costs kept users from spending much time online (those few who actually knew what being "online" meant). We were also students with limited means and much to do before graduation.

Setting all that aside I think our biggest drawback was that we just didn't believe it would work, or at least I didn't. Would users really want to buy and sell from anonymous people online? Was the market really that big? Starting a company in Belgium takes effort (or used to, things may be different now) was it worth it?

Here's how eBay started, quoting Wikipedia:

The online auction website was founded as AuctionWeb in San Jose, California, on September 3, 1995, by French-born Iranian computer programmer Pierre Omidyar as part of a larger personal site [...]
One of the first items sold on eBay was a broken laser pointer for $14.83. Astonished, Omidyar contacted the winning bidder to ask if he understood that the laser pointer was broken. In his responding email, the buyer explained: "I'm a collector of broken laser pointers." 
The frequently repeated story that eBay was founded to help Omidyar's fiancée trade Pez candy dispensers was fabricated by a public relations manager in 1997 to interest the media.

This I think is the key lesson: Pierre Omidyar had an idea and tried it. Yes, he was lucky: he tapped a motherlode of pent-up demand. Yes, he had first mover advantage (as far as I can remember). But the fact is that he acted on his idea. He gave it a shot, learned from it, and turned it into a business.

And that's truer today than ever before. The barriers to entry on the web are very very low. It's easier than ever to find people to work with. There are many ways to reach people. And there are tons of us online.

So are you going to keep coming up with ideas? Or are you going to take one and make it happen?

(Picture credits)

Making the most of OS X Spaces

I read with particular interest a blog post proposing a navigational re-design for Apple's Spaces, the OS X feature that implements multiple screens user can switch between. What sparked my interest is that I'd just diagrammed how I layout my Spaces this weekend, thinking I'd blog this someday. Like today.

I configure my Macbook Pro with 9 Spaces, arranged in a 3 x 3 configuration. The center space (#5) is my dedicated "Home" space: the one I always come back to. The blue spaces are for key activities. The rest for auxilliary ones.

In practice the center space is where I do email (Gmail), catch up with Twitter, take notes, and surf the web. Right now, I find I don't need four blue "dedicated activity" spaces and only use three, The remaining "sand spaces" usually have the programs listed but will change as needs dictate. For instance if I'm doing a lot of Rails development (#4) then I may use the spaces above and below (#1 & 7) to display documentation or work with files on the server with Cyberduck.

Advantages of this layout:
  • Using the center space as "Home" makes it easier to return to it, my fingers can find their way without me thinking about it
  • The four spaces above, below, left and right of center are very quickly accessed, and there are two spaces either side of them if I need more room to work
  • I don't use MacFreedom (even when I'm focused I still need the net) but I'm a firm believer in eliminating distractions. Keeping email and Twitter on the center space achieves this just fine 
  • I do use Optimal Layout as my task switcher (love it!). It sorts my windows / apps according to the screen I'm on: very handy

One detail I've left out: I often use my MBP with an external 24" monitor, effectively doubling my total real estate to 18 screens. Here's an example of this looked like over the weekend. (Oh, and 8GB RAM helps to run all those programs smoothly :-)

Other tips? Let me know!

Mining the OSX Console for Fun and Profit

Well... Fun? Yes (if you're a geek). Profit? Not very likely but if you search long enough who knows? :-)

I rarely open the OSX Console app. This morning, while waiting for a call, I did and found this cry for help from Firefox:

11.1.31 9:25:12 [0x0-0xbb0bb].org.mozilla.firefox[2734] SHOULD NEVER HAPPEN

In fact I found dozens of them. Intrigued I started looking for other messages. Chrome, it seemed, was having problems of a more existential nature.

11.1.31 9:34:37 [0x0-0x2a42a4].com.google.Chrome[12790] objc[12794]: Class CrApplication is implemented in both [...] and [...]. One of the two will be used. Which one is undefined.

As long as one of them's used that's OK right?

Pages should really know better.

11.1.31 8:58:43 Pages[12487] *** WARNING: Method setDrawsGrid: in class NSTableView is deprecated. It will be removed in a future release and should no longer be used.

Uh-oh.

11.1.30 17:56:04 AppleMobileBackup[8848] WARNING: Backing up bf6f8237f787cbf4206d1e107b24aacd55c44b5b

Hmmm... Does MDRP phone home when you rip a DVD? Kind of: by default it will "Anonymously report rip statistics" but you can turn this behavior off in its preferences. I don't think this should preference should be checked by default but I like the fact that MDRP is at least logging this activity.

The most common message I saw? Variations of this one:

11.1.29 1:12:15 <Many Different Programs Here>[229] Can't open input server /Users/[...]/Library/InputManagers/Edit in TextMate

It seemed as if everyone was complaining about TextMate (I know, I should move to Vim, it's on the list...). Fortunately, there's a solution.

After scanning a day's worth of logs I decided I had better things to do!

Why Developed Countries Don't Experience Food Riots

I was listening to NPR on the iPad this morning (nice app, but so unstable). The subject was rising food prices (30+% increase over the last few years) impacting poorer countries, like those in northern Africa, and that this was one of the main causes of the riots in Tunisia and Egypt: when people go hungry for too long, revolution happens.

Still, if food prices are rising why haven't we seen price increases here in the US? After a bit of digging, I found this explanation. It turns out that in the US (and I expect developed countries in general) the actual cost of the food we eat is a fraction of what we actually pay for (the bolding is mine):

Production and marketing costs determine the minimum price of food in the retail marketplace. Production costs are typically called the "farm value" of food, and they comprise about 20 percent of the final food cost. This percentage varies by type of food, depending on how highly processed or perishable the food is. The farm value for meats and dairy products is around 28 percent, for poultry around 41 percent, for cereals around 5 percent, for fresh fruits 16 percent, and for fresh vegetables 19 percent. As consumers demand more highly processed foods, fresh foods from distant places, and foods ready to eat, the farm value falls as a percentage of the retail price.

So when you buy a $4 box of cereals at the grocery store, the raw ingredients only cost about $0.20. In a country like a Egypt where 20% of the population subsists on $2/day or less (some articles I've seen put this at 40%), people spend a substantial portion of their income on food. A 30% percent increase is going to hurt. A lot.

In the US most citizens probably wouldn't notice a 30% increase for two reasons. One is that we're (on average) over 20 times more affluent than our Egyptian counterparts, so we spend a much smaller portion of our income on food, and we can tolerate an increase.

(Hard not to notice how 30 years of dictatorship have flatlined Egypt's GDP per capita...)

The second reason we don't notice is that a 30% hike would push the farm value of that $4 box of cereals to $0.26, which is usually absorbed by the rest of the value chain without being passed on to consumers. So what are we paying for then?

Raw commodities (farm value), labor, and packaging comprise 67 percent of the cost of food. The rest of the costs are in transportation, advertising, rent, profits, energy, business taxes, depreciation, interest payments, miscellaneous costs, and repairs. These last types of costs have increased at about the rate of inflation and have not changed their share of the food dollar much over time. 

No wonder more and more people (ourselves included) are buying local.

Note: Yes, I know there are many other reasons developed countries don't have food riot (e.g. democracy & the ability vote bad leaders out of office). What struck me most is how most of the money we, in the developed world, pay for food doesn't even go towards the food itself.