• CORS on Apache: Cross-Origin Resource Sharing

    The Cross-Origin Resource Sharing or CORS policies of a webhost indicate whether a browser should allow a script to access their resources.

    Traditionally, the browser do not allow scripts loaded from an origin to interact with resources from another origin. This behaviour is the same-origin policy. CORS allows hosts to relax those constraints by instructing which external origins are allowed to interact with it. The host communicates this intent via a specific set of headers.

    Note that the same-origin policy is client-enforced and as such does not restrict access to the resource with any other method than XHR.

    As webservers can typically modify response headers, they allow you to set up a CORS policy. In this example, Apache acts as a proxy for Jenkins, an automation server. Jenkins provides API access to its information but does not allow the administrator to modify the CORS settings easily. The goal is to allow external origins to access the Jenkins API information that Apache proxies.

  • Trigger build for all jobs in Jenkins organization

    Learn how to trigger all builds in a Jenkins organization or folder through the Groovy script console.

    Jenkins is the automation server of choice for thousands of organizations. Though it is a bit quirky at times, it offer the features, flexibility and community that projects require. Central to Jenkins is the scripting language Groovy which allows for automating configuration and management.

  • distcc as a Docker system service

    Distcc allows you to distribute the compilation of C, C++ and Obj-C. It wraps your typical compiler executable and offloads the compilation to remote and local compiler instances with the help of the distcc service. This reduces the compile-time of projects with many compilation units.

    For distcc to work properly, it should run the same compiler version on all compilation servers. This is typically not a big issue when running the same Linux distribution on both client and servers. But what if your use Arch while the server runs CentOS, or you run Ubuntu Bionic while the server runs Eoan? Or what if you have upgraded your local compiler while the server is still on the previous version of a compiler?

    Yes, containers.

  • Get PhpDoc @params of a method

    A well-written PhpDoc is a goldmine of information. It may feel redundant, however, to document values that you use in your code too. Why not parse the PhpDoc itself and use that value? Reflection is the way to go.

    Consider an Api class that requests users by ID from the Api’s user endpoint. We like to document the name of this endpoint in the PhpDoc for documentation purposes.

    class Api {
         * @param int $id
         * @return User
         * @endpoint users
        public function user(int $id) : User {
            $this->request('users', $id);
  • Chunk an Iterator into Arrays

    Iterators can take the heat out of memory consumption when processing big datasets. Typical for such datasets is that workers process them in manageable chunks of a limited size. As these workers typically are independent of each other, it might be necessary to pack chunks of the source in arrays that can be sent with the job metadata to the worker. This is when you might want to chunk an iterator into arrays.

    A Generator function is useful to achieve this purpose. As opposed to a normal function, a generator function yields return values as the caller asks for them. Take this dice roller:

    function dice() {
        return rand() % 6 + 1;
  • Secure an NGINX Docker container with Let's Encrypt

    For web-applications, securing the communication between client and application is essential. As containerisation of such applications becomes the standard, I will be looking into one another method to achieve SSL encryption with a containerised NGINX web server using Let’s Encrypt.

    A full-blown multi-application server typically runs a web server that hosts applications. To secure the communication between this server and clients, a secure (HTTPS) connection is initiated that uses an SSL/TLS certificate and a corresponding key to encrypt the data on a per-domain basis. A trusted Certificate Authority like Let’s Encrypt can issue certificates that indicate that you are the valid owner of a domain. To proof this ownership, Let’s Encrypt uses a protocol called ACME. Tools like CertBot and implements this protocol and can as such allow you to obtain and renew SSL/TLS certificates signed by the Let’s Encrypt CA. 

    Diagram of connections

    Figure 1: Infrastructure of a server with 2 public IP addresses, one hosting two applications through a proxying webserver and another with a dedicated application webserver.

  • Compact `switch` alternative

    Some situations in PHP require a set of variables to have values depending on some condition. To achieve such variable-assignment, a switch statement is the traditional GOTO, but PHP’s array syntax combined with the list() language construct. 

  • Filtering and Control Library

    Check out this header-only C++11 library of control and filter tools. Currently it features PID control, bi-quads (or second-order-sections), state-space systems and a PRBS (pseudo-random-binary-signal) system identification function. 

    The code-documentation and tests provide reference and example to use the library. Creating a second order floating-point state-space is easy:

  • True color support with (iTerm2 + tmux + Vim)

    The terminal can be an effective workhorse for achieving a job. It is fast and agile and allows you to do get things done that would have taken you much more time than when you are limited to using the graphical user interface alone. The GUI, however, treated us with elegant visuals and a clear design that made working with it a comfortable experience that is easy on the eye. When working a lot in the terminal, one might want to borrow a piece of this visual experience in the form of an attractive true color terminal.

    There is, however, some configuring to do to get a true color scheme working on a terminal emulator like iTerm, especially when combined with a terminal multiplexer like tmux.

    Example of terminal with True Color color scheme

  • Quick-fix: MATLAB FMU import error

    MATLAB 2017b introduced support for the Functional Mock-up Standard by providing FMU-import blocks in Simulink. This open standard enables mixing of simulation models created with different tools, like prototype controllers before coding them. This is an extremely powerful feature that I will write more about in soon. This memo, however, is about an error that occurred to me when importing an FMU in Simulink and how to fix it. 

    The error is something like:

    Error parsing FMU <fmu-name>. Caused by:
    Error in supplied FMU: Dynamic library file <lib-file> does not exist in FMU <fmu-name>.
    The FMU error dialog, shown by MATLAB
    Error parsing FMU ‘dq.fmu’. Caused by: – Error in supplied FMU: Dynamic library file (‘dq.dylib’) does not exist in FMU ‘dq.fmu’.

subscribe via RSS