unit (in Haskell these two are
fail will be useful too.
// unit :: a -> Promise a
unit = x => new Promise(resolve => resolve(x))
// fail :: String -> Promise a
fail = str => new Promise((resolve, reject) => reject(str))
// bind :: Promise a -> (a -> Promise b) -> Promise b
bind = (p, np) => p.then(x => np(x), fail)
Let’s add also an operator for joining multiple operations into one:
// pipe :: [a -> Promise a] -> a -> Promise a
pipe = ps => x => ps.reduce(bind, unit(x))
..and some definitions for testing:
// add10 :: Int -> Promise Int
add10 = x => unit(x + 10)
// add40 :: Int -> Promise Int
add40 = pipe([add10, add10, add10, add10])
// fadd40 :: Int -> Promise Int
fadd40 = pipe([add10, add10, _ => fail("oops"), add10])
And now we can test our Promise monad:
add40(8).then(x => console.log(x))
fadd40(8).then(x => console.log(x), err => console.log("err " + err))
-------> “err oops”
The above code was tested on Firefox.
This is just a short note about how to use https in Tomcat (7)…
First, we have to generate a key with a password, e.g.
“%JAVA_HOME%\bin\keytool” -genkey -alias tomcat -keyalg RSA -keystore /etc/tomcat7/tomcat.keystore
Then, we need to edit the
/etc/tomcat7/server.xml file — uncomment
connector ssl 8443 there and add attributes
At the end, remember to restart tomcat7 service:
sudo service tomcat7 restart.
For more info, please visit https://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html.
If you want to make quick encrypted remote backup of your data, the only things you need are bash, tar, gpg and ssh.
“tar” packs your data into a single stream of bytes, “gpg” encrypts the stream and “ssh” remotely stores the encrypted stream to chosen file.
tar cv folder_to_backup | gpg -e -r gpg_user_id | ssh remote.host "cat > folder_backup.tar.gpg"
Note – you don’t need to compress “tar” stream as “gpg” during encryption compresses data for you.
An example situation we have had recently: Erlang Solutions have published a new version of esl-erlang package with the newest Erlang/OTP 20.0. This new major Erlang release contains a few incompatibilities with earlier versions and that is why we have had to hold this update in a system we have been building.
There is a simple way to temporarily prevent
apt-get upgrade from upgrading the ‘esl-erlang’ package to the newest version – the only thing you need to do is to put this package on ‘hold’ with
apt-mark hold els-erlang.
Later on you use
apt-mark unhold esl-erlang to again allow debian package manager to upgrade this package.
During the system upgrade (apt-get upgrade) which updates also the docker-engine package, the docker service is restarted, which means stopping all containers.
Theoretically, containers created with the restart policy set to „always” should restart themselves automatically, but some time ago we had a problem with restarting one of such containers. The container was part of the multi-container application:
Continue reading “Locked file system after restarting Docker service”