Thursday, July 7, 2011

The + in Google+ is Temporary

It seems obvious to me now that the + in Google+ is just temporary. Google+ is the next major version of Google. It is Google 2.0, a grand unification of all of their products which we will soon collectively refer to as just Google.

Videos, Pictures, Search, Mail are becoming features of the product called Google. It won't be long until people start saying things like "Did you see the pictures I posted to Google?".

The + is going away. And it is going to happen very fast.

Sunday, April 10, 2011

Optimizing a Batting Order With Brute Force Code

It is spring time and for me that means another softball season. With it comes many of the same bar arguments my softball buddies and I have year after year. Most often these arguments are around softball strategy. Yes, we like to have fun in our co-ed softball league but we also like to win! One of the more common debates we have is how to best optimize our batting order. The two competing strategies on the team are:
  • strategy #1: stack the lineup - put all your best players together (up front) so we have a few very strong innings at the expense of more weak innings.
  • strategy #2: spread the lineup - mix your best players with the weaker players so you reduce the number of very weak innings.
Today I decided to try to finally settle the issue by doing one of the few things I enjoy as much as playing softball: writing code.

I figured it shouldn't be too hard to write a program to simulate a bunch of softball games with various lineups and report back the average runs scored per game per lineup. Then we can look at the best and worst performing lineups and see what it tells us.

Obviously no simulator is perfect. You must always make simplifications and assumptions. With that said, here are the basic rules I used to develop my simulator:
  • A player is defined by 1) a batting average and 2) a "hit profile".
  • The batting average defines the probability he/she will get a hit (instead of an out).
  • If the batter gets a hit the "hit profile" specifies the probability of getting each type of hit.
  • I defined 5 different types of hits:
  • bloop single - advances everyone 1 base
  • line drive single - advances everyone 2 bases (except the batter who stops at 1st base)
  • double - advances everyone 2 bases
  • triple - advances everyone 3 bases
  • homerun - advances everyone 4 bases
  • For each lineup I simulate 100 games and calculate the average runs scored per game.
  • I defined 5 general classes of players:
  • "power" - .600 average, 45% singles, 30% doubles, 5% triples, 20% homeruns
  • "hitter" - .500 average, 70% singles, 30% doubles
  • "avg" - .400 average, 80% singles, 20% doubles
  • "belavg" - .300 average, 100% singles
  • "weak" - .200 average, 100% singles
  • On my roster I defined 11 players:
  • 2 "power" hitters
  • 1 "hitter" hitter
  • 2 "avg" hitters
  • 3 "belavg" hitters
  • 3 "weak" hitters
With 11 players on the team we have almost 40 million different possible lineups (11! = 39,916,800). My simulation tried ALL of them. It took about two hours to run on my mac book pro (2.66 GHZ Core 2 Duo with 8GB ram) and produced a 4.8GB output file.

And the results?

The worst performing lineup scored an average of 2.57 runs per game. This losing lineup (with batting averages in parenthesis) was:
  1. belavg (.300)
  2. hitter (.500)
  3. avg (.400)
  4. weak (.200)
  5. weak (.200)
  6. weak (.200)
  7. avg (.400)
  8. belavg (.300)
  9. belavg (.300)
  10. power (.600)
  11. power (.600)
The best performing lineup scored an average of 6.4 runs per game. This winning lineup (with batting averages in parenthesis) was:
  1. power (.600)
  2. hitter (.500)
  3. avg (.400)
  4. avg (.400)
  5. power (.600)
  6. belavg (.300)
  7. weak (.200)
  8. weak (.200)
  9. weak (.200)
  10. belavg (.300)
  11. belavg (.300)

For now I will reserve judgement and just report the findings. What do you think?

The code I developed for this simulator can be found here: http://dl.dropbox.com/u/376612/battingordersim.c

Note: Two important factors that my simulation currently ignores are player speed and gender:
  • player speed - the simulation currently assumes that all players will advance the bases at the same speed which obviously does not match reality. A slow base runner may cause a hitter to get a single or double when he/she might have had a triple or homerun with faster runners on base. Slow runners on base will also cause the current batter to have a lower batting average since the base runners are more likely to get forced out at theur next base.
  • gender - our league has a few rules with respect to gender that are not currently simulated. One rule for example will penalize a team for "walking a male player to get to a female player". Whether it was intentional or unintentional, if a male walks, and the next batter is female, the male gets two bases instead of one. This effectively increases the likelihood of male batters, who hit directly before females, getting doubles.
These may be supported in version 2 of my sim. :-)

Saturday, September 4, 2010

Tech Used in Documenting My Mt. Washington Hike

A couple of weeks ago my girlfriend and I hiked Mt. Washington (in New Hampshire) for the first time. I have to say that the hike was 10X harder than I expected but 10X cooler and prettier than I expected. It took us 7 hours to get up and down the mountain and at certain points involved crawling over huge boulders on all fours. It was no joke! The temperature was 80 degrees at the base and 30 at the summit.

Not too long before the trip I received my iPhone 4 and knew I wanted to use it to document the hike. The iPhone 4 camera is much improved over the last generation and actually supports capturing 1080p HD videos. It can also run Apple's new iMovie for iPhone app that supposedly makes it easy to create and share movies right from the device.

The first problem I knew I had to solve upfront was battery life. As you probably know the iPhone battery drains quickly and Apple designed it to be non-removable so you can't carry a charged spare battery even if you wanted to. I ended up buying a Kensington Travel Battery Pack and Charger which is the next best thing. At $70 it is far from cheap but it worked well and kept my phone charging in my backpack for the entire trip.

Over the course of the weekend I took well over a hundred pictures and a handful of short videos. The day we got back I went to work. The first thing I did was purchase a mushy love song I thought my girlfriend would like. I bought Hey Soul Sister by Train for 99 cents on iTunes right from my phone (OK fine, I like the song too).

Next I started a new project in iMovie for iPhone but immediately realized it wasn't going to work. It doesn't let you import more than one picture at a time and it takes a few seconds per picture to import. It would have taken far too long with the number of pictures I had. Instead I moved to the desktop version of iMovie which proved much more efficient. It ended up taking me a few hours to create and edit the movie to my liking.

Once it was done I needed to share it and YouTube is the obvious place for video sharing right? I went to upload the video and it quickly became apparent that I had a new problem. YouTube was asking me if I had permission from all copyright owners to publish this video. Until then I hadn't given much thought to the fact that I was embedding high quality audio from one of the top songs on the charts. I was seriously conflicted about what to do here. I spent so much time working on the video and only a few friends would be watching it but clearly I didn't have the copyright permission from Train. After thinking about it for a while I decided to just go for it and see what happens next. After uploading the video YouTube notified me that it auto detected copyrighted material and knew the exact song name and artist. It then told me that it was actually OK for me to publish because YouTube and the content owner, in this case Sony music, had a deal in place. My video would be shown (in most countries) but it would have a small advertisement below it. The ad would identify the song name and artist and include a link to purchase it.

Awesome!

I believe this was the first time I've every been pleasantly surprised by anything related to copyright issues. Thank you YouTube, Sony, and Train!

If you are interested in seeing my directorial debut, check out the HD version of the video here as the embed below is getting cut off by Blogger. You may also want to change the video quality option from 360p to 720p. I changed my YouTube settings to "Always play HD when switching to fullscreen (when available)" so it always chooses this option when available.


Toy Car

Last night I came across a car parked in my neighborhood that was covered with hundreds of plastic toys. Pretty much every person that walked took one or more pictures. Check these out:







Sunday, July 25, 2010

Benefiting From Your Credit Card

Credit card debt is a huge problem for millions of Americans. Some put the blame for this on the credit card companies and their "deceptive business practices." I would certainly agree that the credit card companies do some pretty shady stuff and should be better regulated but I more strongly believe in personal responsibility. It wasn't the credit card company that made you buy that flat screen TV now was it?

I know about this all too well because starting in college and for a few years after graduation I carried far too much debt. It all began when I charged my first major purchase for $2300. It was a Dell computer with a 233 MHz processor and a 3.2GB hard drive (worse specs than my current cell phone). I spent years paying off that thing. Back then the only attribute of a credit card that I was (properly) concerned with was interest rate.

I am happy to report that I have long ago paid these cards off and now use them for convenience purposes only.

If you have no debt and pay your cards off each month than, contrary to most people, you are in an excellent position to really benefit from credit cards. There are hundreds if not thousands of different cards out there with a wide range of benefits. Choosing the right one depends on matching up your personal spending habits (e.g. do you buy mostly gas & groceries?) with cards that reward those habits with what you want (e.g. travel discounts?).

Over the last few weeks I decided to finally investigate a good rewards card for myself. After quite a bit of research I ultimately decided to go with the American Express Blue Cash card. Below are some of the benefits of the card and reasons I choose it.

  • Earn cash back
    • It has a very simple cash back reward program. Many rewards cards are "point" based which require you to redeem the points at specific locations. With this card you just earn straight up cash back at rates of between .5% and 5% depending on the type of purchase and how much you use the card.
    • The reward is given as an automatic cash credit to your account once a year. Other cards I found make you jump through hoops (call and request) the reward or issue you gift cards instead of cash.
    • NOTE: You can earn these cash back rewards by paying your recurring bills (gym membership, phone bills, etc..) with American Express Automatic Bill Pay.
  • No annual fee
    • Many other cash back cards (and many other AMEX cards) have an annual fee but this one does not.
  • Purchase Protection on your purchases
    • Covers theft or damage (whether by accident or vandalism) of your purchases for up 90 days.
    • NOTE: Pays up to $1000 per incident with a $50,000 maximum per calendar year.
  • Extended warranty on your purchases
    • Extends the length of the original manufacturer's warranty on purchases by up to one additional year. So no need to buy one year extended warranties from places like BestBuy.
    • NOTE: Pays up to $10,000 per item with a $50,000 maximum per calendar year.
  • Return protection on your purchases
    • If a store won't take an item back within 90 days of purchase AMEX will refund you the full purchase price.
    • NOTE: Pays up to $300 per item with a $1000 maximum per calendar year.
  • Car rental insurance
  • Roadside assistance
  • Global assist hotline
    • Provides 24/7 emergency medical, legal, and financial assistance, and more, when you're more than 100 miles away from home.

It is very important to realize though that these cards usually have a much higher interest rate than you could otherwise get so if you don't pay them off in full each month the benefits you may earn will be completely outweighed by the interest rate payments you make. So don't bother with these cards until you can pay them off in full each month.

P.S. I want to thank American Express for sponsoring my blog this week. Just kidding. I did all this research and figured I'd share what I found with everyone.

Saturday, July 17, 2010

Managing Multiple Installations of Xcode

If you are developing for the iPhone you will quickly discover the need to support multiple installations of Xcode. The most common case is when you want to install the latest "beta" SDK to try out the hot new features while maintaining the latest "official" SDK for production purposes.

Supporting side by side installations is relatively simple but may not be immediately obvious if you haven't done it before. Several screens into the Xcode installation wizard, on the "Installation Type" page, there is a subtle drop down dialog for Location that lets you choose where to install. The default is /Developer but you can change it to what ever you like.

Many developers choose to always install the latest official release in the default location /Developer and the latest beta release in something such as /DeveloperBeta. Each time a new version is put out they upgrade the appropriate one.

I started out doing it this way but occasionally found it limiting to not have the older SDKs:

  1. Can't rebuild an old release of your product that was made with an old SDK
  2. Can't test using an old version of the simulator
  3. Can't compare differences in behavior between older SDKs / simulators
  4. Apple may release a broken SDK or you may not realize the consequences of upgrading the SDK. That may result in you needing to spend time uninstalling the new and reinstalling the old.
Starting tonight I'm trying out a new installation scheme. I'm now installing each new version (whether it is release or beta) to /iSDKs/[version_number]/ and simply ignoring the default /Developer location.

One point worth noting is that it turns out not all of the developer tools get placed in the location you choose! The fine print of the installer says that "System Tools" and "Unix Development" can only be installed once and are always installed to /Developer and the boot volume.

One important implication of this is that when you uninstall the version at /Developer you may also remove the single installations of "System Tools" and "Unix Development" which could cause problems with your other installations or build scripts. This is exactly what I did tonight and immediately discovered that version control in the other Xcode installs broke because it couldn't find cvs.

The main take away from this is that if you go down this route the order you install / uninstall can be important. I recommend:
  1. uninstall your current installations first (especially the one at /Developer)
  2. install each version one at a time proceeding from the oldest to the newest
P.S. The way to uninstall an XCode install is:
sudo [xcode-install-dir]/Library/uninstall-devtools --mode=all

UPDATE:
If you use macports you will need to update the "developer_dir" setting in macports.conf (usually /opt/local/etc/macports/macports.conf) to point to the version it should use. I set it to /DeveloperCurrent and created a symlink there to point to the most recent release version.

Thursday, July 8, 2010

Remove Interface Builder from the iPhone Project Templates

I find it frustrating that the XCode iPhone project templates are set up to use Interface Builder. Here are the steps to remove Interface Builder from the project templates:

  • Create a project using a template
  • Delete the .xib files from the project
  • In the .plist file, delete the "Main nib file base name*" properties
  • In main.m, pass the name of your Application Delegate class to the UIApplicationMain() function as the forth argument
  • Remove the IBOutlet keywords on the properties
  • Update application:didFinishLaunchingWithOptions: to create / initialize the application window