List largest MongoDB collections

I wanted to know the top five largest collections in my MongoDB database in terms of document count. This JavaScript gets the job done.

// config
var dbname = 'dev_bv';
var measure = 'count'; // or 'size'
var numTopCollections = 5;
function updateTopCollections(collection, stats, topCollections) {
    var thisCollectionObj = {
        'name' : collection,
        'count' : stats.count,
        'size' : stats.size
    for(var i = 0; i < topCollections.length; i++){
        if (stats[measure] > topCollections[i][measure]) {
            topCollections.splice(i, 0, thisCollectionObj);
    if (topCollections.length < numTopCollections) {
    if (topCollections.length > numTopCollections) {
db = db.getSiblingDB(dbname);
var collections = db.getCollectionNames();
var topCollections = [];
for(var i = 0; i < collections.length; i++){
    if (collections[i].match(/^system/)) {
    var stats = eval('db.' + collections[i] + '.stats()');
    updateTopCollections(collections[i], stats, topCollections);
printjson (topCollections);

Save it to a file, edit variables in the config section, and execute like so:

mongo --quiet topCollections.js

Here’s a gist of same:

Go ahead, put it on top of the car

You’re getting in the car, and you’re in a hurry. You’ve got your hands full of important objects, yet, there’s a handy, flat, perilous surface right in front of you: the top of the car. Perilous because of the off chance you forget to remove said important objects from the top of the car before you race off to your destination.

But fear no more. Go ahead and use this handy surface. Just set your keys down, too!

Yeah yeah, you’ve got a spare key in your pocket, one of those start buttons that works when the key is nearby, or something like that. If that’s you, you’re on your own.

But if you’re me, you’re stoked.

BreadVault iPhone app in 2½ minutes

BreadVault is a tool to help you teach a child and yourself fiscal responsibility. It’s also my job! Here’s how to add a goal using our iPhone app.

  1. Install BreadVault using the App Store.
  2. Touch “Log in with Facebook”.
  3. Add a family member. If you don’t have kids, add yourself. Set allocation sliders to 100% Save (you can change this later).
  4. Log in as the family member you just added and scan a barcode (see photos, below). Don’t worry if the price isn’t right, you can change this later, too.

Initiate barcode scan from family member dashboardScan a barcode

The next time you’re in line at the store, add a goal instead of making a discretionary purchase!

Other Tips

  • For some more why and what about BreadVault, see How my 3-year-old bought herself The Lorax.
  • iPhone+Facebook is probably the easiest and most convenient (but definitely not the only) way to use BreadVault. BreadVault HD is the iPad-optimized version. And of course there’s our full-featured website. We’ve got plans to support Android and Windows 8, too, so keep your eyes peeled for those.
  • You added this goal when logged in as a family member. To make progress towards the goal, add funds using the Family Dashboard. Touch the upper leftmost corner of the app, and touch “Family Dashboard”. Try adding, say, $2 per week to the family member. To check goal progress, log out, then in as the family member. Touch the piggy bank to view Save goals.
  • Once the goal is met, a blue Buy button will appear next to the goal progress bar. Use that to purchased the earned item.
  • Saving for discretionary purchases is one facet of fiscal responsibility. Charity and investments are others, so next time check out the Give and Invest channels!

Science Fiction

I like Science Fiction because it scares me. It opens my mind to new ideas.

And sometimes the fiction becomes reality.

Just the other day I finished Robopocalypse (a great read!). Today I thumb through my news feed and hear that California just joined a couple other states in legalizing self-driving cars and Toyota continues to make progress with domestic helper robots.

I don’t see the singularity coming any time soon, but it’s easy to see our tools evolving rapidly. Our responsibility towards each other must grow commensurate with the evolution of our tools.

Amped is great so far, too. I just happened to watch The Hunted lately, which also explores the theme of technology-enhanced individuals being rejected by mainstream society. Like Dr. Steve Mann’s beating in France. Discrimination is certainly old news; I believe we love the familiar, and it follows the unfamiliar generally is harder to accept. But this challenge is exactly what makes the unfamiliar awesome.

Wanted: fair curated tweet list

I think I like Twitter. I’m getting to like it, anyway. One problem I have with it is what appears to be an overwhelming emphasis on timely and copious posting.

I often miss tweets from my VIPs (friends, family), especially those who post infrequently. I want something that shows me the last few tweets for a list of people I specify.

Twitter’s “lists” feature comes close to this goal, but (like every other Twitter client I’ve seen) it shows every tweet and the most recent first, so infrequent tweeters are still penalized.

What would really unlock this problem for me is if there existed a REST API to pull a few tweets from several users at once. Anyone know if such a thing exists?

I’m also interested to know if there’s an extant client that does what I’m describing. I wouldn’t mind not coding this.

UPDATE (30 minutes later):

I cobbled something together that basically does what I want. I only slightly modified Kevin Liew’s dead-simple jQuery-based example to make my app. I just factored out the user parameter to JQTWEET.loadTweets() and now call it multiple times, once per VIP. Even with a list of 50 VIPs I can run this less than once per hour and still avoid rate limits.

UPDATE (2012-09-27):

Another idea, no coding required: subscribe to the RSS feeds for each VIP in your favorite feed reader.

3 Reasons Why You Should Never Use Enlocked

Enlocked advertises easy, secure email. Sounds good to me! My current solution (Thunderbird+Enigmail) works, barely, but it is a big pain in the tukhus. I’d go for something better. Heck, I’d pay for it. And Enlocked is free!

I gave their Chrome plugin a try. Installation was a breeze and it worked exactly as advertised. It integrates almost seamlessly into GMail (when replying, quoted text is still encrypted, but they’ll probably fix that soon). It really was friendly enough for anyone! But I’m not dusting off the old blog just to tell you that. No ma’am.

Unicorn and Cow (and sentry)

1. They encrypt and decrypt using their own key.

If you’ve ever spent the not-insignificant time to learn and use PGP yourself, you’ll know that one point of going through all the trouble is complete, end-to-end encryption. You don’t have to trust your email handlers. Any of them. And there can be many! So, uh, you just never give your private key to anyone, ok? Everyone gets their own keys (there are plenty for everyone, and they’re free!). That’s the way PGP works.

I should say that I’m not positive Enlocked uses their own key. It could just be a key they generate using some secret they securely get through you via OpenID or something fancy like that (even so, they’re free to brute force your secret day and night since they have the key). But without knowing for sure, you might as well assume it’s their key and they can decrypt your messages anytime they darn well please. Or if someone forces them to decrypt messages (like a government, or someone with lots of power or money), same result.

2. They encrypt and decrypt on their servers.

From their How it Works page:

The systems at Enlocked only have access to your messages for the short time we are encrypting or decrypting them, and then our software instantly removes any copies.

This is really more of the first reason (no end-to-end encryption), but it’s just another place where their inevitable security breach could occur.

3. Their software is closed-source.

If you know me you know I’m a Free² Software zealot, so you expect this kind of propaganda from me. But transparency is really important where the actual encryption and decryption takes place. They must at least make their client-side code available for review.

Sorry Enlocked, nobody serious about security will adopt your software until you address these issues.

Disclaimer: I’m no security expert. But Bruce Schneier is. If you really want to get schooled on security, read anything he’s written. For instance: Secrets and Lies: Digital Security in a Networked World.

How to securely connect an AWS load balancer to EC2 instances

Here’s the magic sauce to securely allow traffic to your webservers only from your load balancer. Run the following:

ec2-authorize --region REGION -C /path/to/cert.pem -K /path/to/key.pem ELB_NAME -u OWNER_ALIAS -o SOURCE_SECURITY_GROUP

The tricky bits for me were:

  • having to generate an X.509 key and cert just for this purpose (there’s gotta be a way to do that from the web console)
  • OWNER_ALIAS above and in the web console equates to SOURCE-OR-DEST-GROUP-USER in the ec2-authorize(1) manpage.
  • SOURCE_SECURITY_GROUP above and in the web console equates to SOURCE-OR-DEST-GROUP in the ec2-authorize(1) manpage.
  • to remember to include --region

The documentation for same is confusing to someone like me who doesn’t know much AWS security group terminology.

As far as I know, there’s no way to perform, view, or manage this special security setting through the web console.