Showing posts from 2014

Where is my direction pole?

Somewhere in a village in Tuscany a direction pole has been installed, and while I was looking around I've asked myself how precise are the distances, and also if giving a glance to the direction pole from one side is possible to triangulate the location.

This is essentially a small exercise of spherical geometry for which Python is perfect. First a look at two photos of the direction pole: it has a total of 18 directions of which 8 pairs of cities share the same direction on opposite faces of the arrow, as shown in the following photos:

Continue reading with the details and solution. If you like guessing a place from a picture you can try GeoGuessr that uses Google Street View for creating geographical quizzes.

Sandboxing your scripts in OSX

Sandboxing is a system level feature that allows to limit the capabilities of an application due to security reasons or simply because we are developing the application or the script. Sandboxing is also the starting point for application-level virtualization because the next step of system call interception is system call detour.

OSX provides application level sandboxing since a long-time and it is worth looking at it while developing a new bash script, or simply when we want to perform a command line that involves sensitive data. Let's say we want to perform rsync of our family pictures and we really want be sure that we will not mistakenly impact our files.

The objective is to protect the execution of an executable or script file allowing it to write only on a given path. The idea is to make a shell script as follows: TARGETPATH CMD ARGS*

The sandbox-exec utility of OSX executes another program using the provided sandboxing configuration file. The configuration file…

Type switch for Algebrical Data Types in C++11

This is a short post to complete the discussion on Algebrical Data Types in C++11.

An important point for the adoption of Algebrical Data Types (ADTs) is the possibility to perform a select operation based on the active type in an ADT variable. While the use of a class with overloaded function members is practical it is not as clean as it should, in particular if compared with languages with native ADTs.

The syntax in Haskell is:

depth :: Tree -> Int depth Empty =0 depth (Leaf n)=1 depth (Node l r)=1+max(depth l)(depth r) In particular we would like to easily express it in C++ as follows:

sumtype<int,std::string> adt(10);std::cout<<[a](int x) return(int)10+a; },[](std::string w) {return(int)20; }); The select function receives a list of lambda expressions and, at run-time invokes the one whose first argument type matches the active type in the ADT. Thanks to the direct use of lambda expressions everything is inlined by the compiler.

The implementation of the a…

Variant invocations of function members using C++11

This post addresses the case of wrapping functions for reflection for the aim of supporting run-time invocation through variant parameters.  This is the case of reflection frameworks and codes that makes C++ classes accessible to scripting runtimes such as Boost.Python.

I will focus on the case of exposed functions that are bound to a specific instance.

The approach taken here is based on constructs of C++11, in particular the variadic templates, std::function type, and auto return types.

cmakego: Simpler access to external libraries in CMake

CMake has greatly simplified the process of building libraries and applications across different platforms, and it is adopted by several large projects. Libraries can be easily found through find_package but the result of the lookup has to be manually added to the target through different commands. This post discusses how include the external libraries in an easier way:

add_executable(glapp1 glapp1.cpp ...)
target_link_libraries(glapp1 p::glew p::glfw p::boost ...)

The usage of cmakego is similar to the one of packages or meta-packages such as catkin:

find_package(cmakego REQUIRED COMPONENTS glew glfw)

For boost the sub-components can be specified as:

set(CMAKEGO_BOOST program_options)
find_package(cmakego REQUIRED COMPONENTS boost)

Details after the break.

For a general package management of sources there is catkin for the ROS world and hunter for the others.

A journey on Linux from Console to Desktop

This post is aimed at giving an overview of the different elements, commands and configuration files that are involved when Linux switches from console to Desktop, with a focus in the context of Ubuntu 13.04. For an in-depth overview of X11 look at this great series of posts: Xplain.

The following is the structure of the software layers involved in the following discussion: Kernel Runlevel manager: Upstart, SysVinit or systemd Display Manager: lightdm or gdm X11 server: xorg Session Manager/Shell: KDE or Gnome Shell Window Manager/Compositor: compiz, metacity (Gnome), xfwm4 (XFCE) or xcompmgr X11 Application

The execution structure can be summarized as follows:
Upstarts manages the system events, and in particular the runlevel Display Manager Task (of upstarts) is invoked when entering runlevel 2 The default Display Manager (DM) is activated when by the DM Task The DM launches the X11 server Then the Session Manager is started invoking also the Window Manager and other supporting applications
The f…

Algebrical Data Types in C++

Update: next post is here

The subtitle of this post could be C++11 is cool, but let's start from the beginning.

The starting point is the long standing argument on reporting error states of functions by means of exceptions or by multivalued functions. Recent languages such as Go by Google and Swift by Apple prefer to manage error states in the second form, while C++ and Java are biased toward exceptions (See [6] for a discussion). 

Multivalued functions are based on the concept of sum-types, also called algebrical types in other languages such as Haskell, or tagged unions. A sum-type is defined by a list of types, and a sum-type variable contains a typed value from such a list. A sum-type is similar to unions, except that the current type of the union is managed automatically; also a sum-type can be considered complementary to C++11 tuples. In particular we can say:
multi-type, single-value: sum-type/variant multi-type, multi-value:  tuplesingle-type, multi-value: vector or array …