Filter a string using Javascript

Filtering a string in Javascript could have been straightforward but unfortunately it is not.

"this_is_it".filter(c -> c != '_')

This code will throw the following exception

Uncaught TypeError: "this_is_it".filter is not a function
    at <anonymous>:1:14
Read more

Writing pure functions in Scala with mutable structures

Functional programming is a paradigm which can be difficult to define, is it because the language uses First class function like the name suggests? From Wikipedia’s definition, I like to focus on the pure functions, mostly because it is the reason I like functional programming:

In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) each time. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.

Yet in Scala, it is possible to use mutable variables like ListBuffer or even a mutable reference like var. How is it possible to write pure functions with mutable structures?

Read more

My first impressions with Elm

Elm is a domain-specific programming language for declaratively creating web browser-based graphical user interfaces. Elm is purely functional, and is developed with emphasis on usability, performance, and robustness.

Source: Wikipedia

Elm is a functional programming language created in 2012 by Evan Czaplicki for his thesis. The platform is now used in production by a few companies: NoRedInk or Pivotal Tracker.

The idea is to compile Haskell Elm to Javascript to create web site. I wanted to give it a try because:

  • The Javascript fatigue I just can’t keep up with all framework and library in JS to setup a website, I has became so complex, maybe there is a more stable and easier platform,
  • I love functional programming and Javascript is only partly functional, the language is not fully immutable (even if it’s better with const keyword in EcmaScript6),
  • I wanted to feel like a hipster again.

TL:DR: My expectations are partly achieved: there are not 42 libraries to do the same thing but you still need too much tools around your project. The language being close to Haskell is definitely functional, there is no state (at least they are “hidden”) and the language rely on Message to exchange informations. It feels sometimes a bit of a burden but only because I am a beginner.

Note: I discovered the Awesome List of Elm with all the needed pointers.

Read more

How I removed two databases in one pull request

I would like to thanks my coworkers at Octo for their precious feedbacks

My first project right after school was called KISS which means

Keep it simple, stupid

Three years and a few IT projects later, I thought that I got it right and applied the following rules:

  • keep your applications small and simple,
  • remove most of its complexity,
  • don’t over-engineer,
  • all code and user stories have to be maintained (YAGNI)

Yet a few weeks ago, I learned that you can always remove useless things. You just don’t know it yet.

Read more

Centralize logs from Docker applications

I would like to thanks my coworkers at Octo for their precious feedbacks

This article aims at showing how we can centralize logs from a Docker application in a database where we can then query them.

This article is built around an example where our application consists of an nginx instance, an Elasticsearch database, and Kibana to render beautiful graphs and diagrams. The code of the example is available on github.

We need to collect and transport our logs as a data flow from a distributed system to a centralized remote location. That way, we can get an aggregate vision of the system in near real time.

The logging system is plugged at the container level because the application should be loosely coupled with the logging system. Depending on the environment (development, pre-production, production) we might not send logs to the same system: a file for development, Elasticsearch for pre-production, Elasticsearch and HDFS for production.

Read more