Sunday, May 29, 2016

Living the American Dream

It has been a long time since my last kind of personal post. Lot's of things have been going on, and super exciting changes have actually taken place.

For starters, I don't live in Europe anymore. The stars lined up with the planets while I was having a pint of Guiness and I ended up moving to the USA, more specifically to the Pacific Northwest. The Seattle area is what I call home these days! It was sad to say goodbye to Ireland again. Ireland is the place I truly call home in my heart. Dublin is an amazingly vibrant city, and it will be sorely missed. I live good FRIENDS back there, but I know I'll be visiting often.



In terms of job, I have changed teams within Amazon. I no longer work for AWS CloudWatch, my new team is AWS Quicksight. We are building the future of Business Intelligence tools, and ground breaking new technologies for realtime processing of "Universe Scale" datasets ;).

Enjoy the views:




Tree command with boost::filesystem

The tree command is pretty handy to get an overview of the contents of small folders. By small I mean both in the number of files, and the number of levels in the directory structure.  A sample output of the tree command is as follows:

user@host:~/projects$ tree templates/
--CMakeLists.txt~
--app.s
--src
    |--CMakeLists.txt~
    |--#Templates.cpp#
    |--Templates.cpp
    |--Templates.cpp~
    |--CMakeLists.txt
--build
    |--Makefile
    |--CTestTestfile.cmake
    |--CMakeCache.txt
    |--src


Using boost::filesystem this can be achieved with a handful of lines, and your code is multi-platform without any extra effort:

#include <boost/filesystem.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/algorithm/replace.hpp>

#include <iostream>
#include <string>

namespace fs = boost::filesystem;

void print(const fs::path& p,
           std::ostream& os = std::cout,
           const std::string& preffix = "--") {
  try {
    fs::directory_iterator it{p};
    while (it != fs::directory_iterator{}) {
      auto filename = it->path().filename().string();
      boost::replace_all(filename, "\"", "");
      std::cout << preffix << filename << std::endl;

      if(fs::is_directory(it->status())) {
        auto pfx = std::string("    |") + preffix;
        print(it->path(), os, pfx);
      }
      ++it;
    }
  } catch(const fs::filesystem_error& err) {
    std::cout << preffix << err.what() << std::endl;
  }
}

int main(int argc, char** argv) {
  if(argc > 1)
    print(argv[1]);
  else
    print(fs::current_path());
}

Happy Coding.