Debugging MongoDB’s 2dsphere geoIndex

When I first learned about MongoDB’s geospatial capabilities similar to PostGIS, I was beyond excited because it meant I would not have to write helper functions to find data along geohash borders.  Currently my data is indexed by geohash, which has great ordering properties, but is a little unwieldy for the “find me x near y”-type queries.

Unfortunately, it seems as though the 2dsphere index doesn’t cover geoWithin queries.  As my collection of geoJSON documents grew from GBs to TBs,  I noticed my tools taking extraordinary amounts of time to perform find queries, which caused me to investigate what was happening under the hood.

First, I double-checked that my geospatial index was present:

mongos> db.my_collection.getIndexes()
		"v" : 1,
		"key" : {
			"_id" : 1
		"name" : "_id_",
		"ns" : "telemetry.********"
		"v" : 1,
		"key" : {
			"value.avg_location" : "2dsphere"
		"name" : "geoindex",
		"ns" : "telemetry.*******",
		"2dsphereIndexVersion" : 2

So, the index was clearly there.  I also verified that its size was appropriate — it was around 50mb, which seemed fine for this amount of test data.

Next, I ran .explain() on a query to see if it was hitting the index:

Continue reading Debugging MongoDB’s 2dsphere geoIndex

Swift 1.2 and Facebook’s New Login SDK

I’ve had the pleasure of working with Apple’s new Swift over the last few months, and recently ran into some problems integrating Facebook’s API with an iOS 8 app I’m building.

The problem I was having is that, immediately after login, I couldn’t seem to get the user’s access token.


was always returning nil, even with the user logged in.

You need to get this token so that you can send it to your Rails app (or whatever you’re using on the back end) and perform Facebook authentication on behalf of your user up there.

Continue reading Swift 1.2 and Facebook’s New Login SDK

Project: Automated Lawn Room

I recently finished creating a 3D-printed, Raspberry-Pi-powered, Twilio-backed lock for one of the oldest rooms in Charlottesville.   The goal? To allow my friends anytime access to my space on the Lawn while simultaneously staying secure.

I was originally going to grant access to all of my Facebook friends  (the Raspberry Pi would use Facebook’s API to check who my friends were), but thought that it might be less chaotic to design my own registration system, so that I can easily control when individual users are permitted to enter my room.


  1. Not destroying a UNESCO World Heritage Site
  2. Designing/Printing a container and transmission to adapt a servo motor to the existing door lock.
  3. No existing “Instructables” for this project (or pieces of it therein)
  4. Learning how to make the Arduino talk to the Raspberry Pi
  5. Getting through the University’s draconian firewall to Twilio. (ended up using a few servers as mirrors to get there)
  6. Allowing manual override for maintenance workers who occasionally let themselves in.

Here’s a video I submitted to the Engineering Student Council as part of a contest.  (The second half shows how it works)

Update:  Some new features!

I’ve been working on a few new features to make my room more intelligent.  One of the features will save electricity by turning lights on only when there are people in the room, and turning them off automatically when the visitors leave.  Another new feature  sends me a text with a picture of the visitor who entered the room.  Finally, I’ve created a lockdown mode so that I can go on vacation without worrying about what will happen to my room when I’m out of town for a weekend.

Calling a method I wrote to control the lights in my room via DMX protocol by way of the raspberry pi.
Calling a method I wrote to control the lights in my room via DMX protocol by way of the Raspberry Pi.



Cloudification of Things

Cloudbursting, the ability to rent additional servers in the cloud on demand, has been an extremely successful concept in enterprise computing recently. When a researcher has the need to perform complex computations, rather than investing in a supercomputer, she can rent a cluster of Amazon’s idle servers for just the duration of the calculations. She pays for the power when he needs it, and when she doesn’t she avoids having an expensive asset sitting idle and depreciating.

Expansion into the cloud has been made possible in part by improved networking. Analogous to decreased shipping costs, more bandwidth reduces the friction in moving large sets of data from the firm to the cloud. What will enable the Cloudification of Things is the decreased friction in loan logistics.

Take Zipcar, for example. Some people do not need a car 7 days a week. Rather than having a depreciating asset sitting in a car park, Zipcar users can rent a vehicle for only the time which they need. The proliferation of GPS tracking devices has reduced the friction in trusting customers to return a vehicle, allowing this business to be viable.

Another example is fashion site Rent the Runway. Rather than paying for an outfit which is to be worn but a few times, customers can rent these items for a special occasion. Courtesy of improved shipping routes and delivery algorithms, shipping costs have actually decreased while fuel costs increase. Decreased transitional costs combined with large inventory availability has removed the friction that prevented previous clothing rental companies from being successful.

From records, to 8 tracks, to CDs, to iTunes, the music industry has never been complacent with any particular medium. Shifting from iTunes, users begun favoring “rented” music with services like Spotify, Pandora, and iTunes Match.

There are many other examples of users transitioning from ownership to renting, most of which have been enabled by reduced friction in transactional logistics. Going forward, there are many other businesses that have the ability to “cloudify” their business model.

Further, the nature of this model need not be B2C. Consumer-to-consumer rentals can also lead to a more efficient utilization of underutilized assets. Photography equipment, vacation homes, office space, restaurants, energy production equipment, and farming equipment are just a few possibilities.

It’s been estimated that Manhattan was sold by Native Americans to explorers for only $24. The reasoning for the low price was that the Native Americans believe that it was impossible to “own” land. How humanity defines ownership has never been consistent across time and cultures.

“Imagine no possessions,
I wonder if you can.
No need for greed or hunger,
A brotherhood of man.
Imagine all the people, sharing all the world”

– John Lennon, 1971