Sunday, June 21, 2015

When working on a website or application, it's better not to waste your time trying to make it perfect. Instead you should focus on making it work first, creating a simple demo. And the faster you go, the better it is.

Only after the first demo is finished, you can massage it by refactoring the code,
dealing with the performance, etc. But not at beginning, otherwise you'll never finish it.

Saturday, June 13, 2015

An awfully simple definition of a monad

Here's a definition of a monad from wikipidea which seems pretty simple


Formally, a monad consists of a type constructor M and two operations, bind and return (where return is often also called unit). The operations must fulfill several properties to allow the correct composition of monadic functions (i.e. functions that use values from the monad as their arguments or return value). The return operation takes a value from a plain type and puts it into a monadic container using the constructor, creating a monadic value. The bind operation performs the reverse process, extracting the original value from the container and passing it to the associated next function in the pipeline, possibly with additional checks and transformations.


That is, a monad is a type which is used by some functions (that accept monads) to combine them into a chain.

Tuesday, June 2, 2015

A simple javascript notification

If you want to show a simple notification on the page using javascript and don't want to use any third-party librariy because of their overhead, here's what you can do: you can create a div, show and then remove it automatically.

  function showAlert(msg) {
    var el = document.createElement("div");
    el.setAttribute('style', 'position:fixed; top:50%; left:40%; background-color:white;');
    el.innerHTML = msg;
    setTimeout(function(){
      el.parentNode.removeChild(el);
    }, 1000);
    
    document.body.appendChild(el);
  }

That's a pretty light and easy solution which requires no third-party libraries.