Calling a DLL from MQL

There are times when we want access to additional data structures and function libraries than the ones provided by MetaTrader’s MQL. Besides native open-source MQL options, we can create our own Dynamic Link Library (DLL) in C# or C++ and link it to our programs. In this article, we research how to connect to DLLs created with these languages. We must keep in mind that the code generated by C# is managed code running on the .

Parsing Json with the Play Framework

This article discusses different common scenarios for JSON parsing and conversion, useful when working with the Play Framework library. All the examples in the article, use one or more of the following library imports: import play.api.libs.functional.syntax._ import play.api.libs.json.{Format, JsError, JsNull, JsPath, JsResult, JsString, JsSuccess, JsValue, Json, OFormat, Reads} The first import is required to use the special and and or functions found through the examples below. JSON that matches property names The first snippet allows us to parse different basic data types from a json-formatted input.

Scala Lectures

A curated list of Scala lectures on functional programming and design patterns. Functional programming design patterns Wlaschin, Scott. “Functional programming design patterns.” 30 Aug 2015, In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID. The functional programming community has design patterns and principles as well. This talk will provide an overview of some of these, and present some demonstrations of FP design in practice.

Using Cats Effect IO with the Play Framework

Cats Effect IO operations have to be performed at the highest level possible. So when working with the Play Framework the solution is to execute unsafeToFuture() in the controller methods. def get = Action.async { implicit request => service.get().map { items => Ok(Json.toJson(items)) }.unsafeToFuture() } We can as well write an Action implementation that automatically calls unsafeToFuture: object IOHttp { implicit class ActionBuilderOps[+R[_], B](ab: ActionBuilder[R, B]) { import cats.effect.implicits._ def asyncF[F[_] : Effect](cb: R[B] => F[Result]): Action[B] = ab.

Cats Effect IO - Retry with backoff pattern

Scala example for using the retry-with-backoff pattern with Cats Effect IO.

Quick notes on functors


A functor is a design pattern that allows us to apply a function to a contextualized (wrapped) type. This is accomplished by implementing the map function:

fmap :: (a -> b) -> f a -> f b

Notes on lazy evaluation

Lazy evaluation is a strategy that delays expression evaluation until their value is needed. It also avoids repeated evaluations by returning previously computed results by storing them in a lookup table. Why isn’t lazy evaluation used everywhere? Lazy evaluations are not used everywhere (not used in every software currently produced) because of the following reasons: Lazy evaluation requires book-keeping overhead - you have to know if it’s been evaluated yet and such things.

Future Either

This implementation is based on the work of Malcolm, and exists because it provides the cleanest use of similar monads. The base monad wraps an Either class in a Future class: import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success, Try} final case class FutureEither[+E, +A](value: Future[Either[E, A]]) { def map[B](f: A => B)(implicit ec: ExecutionContext): FutureEither[E, B] = FutureEither(value map { case Right(a) => Right(f(a)) case Left(e) => Left(e) }) def flatMap[EE >: E, B](f: A => FutureEither[EE, B])(implicit ec: ExecutionContext): FutureEither[EE, B] = FutureEither(value flatMap { case Right(a) => f(a).

Generate a random string using the console

Generate a random string using the command line: cat /dev/urandom | tr -cd [:graph:] | head -c 32 On OSX, the previous command might return a tr: Illegal byte sequence error, so try: export LC_ALL=C; cat /dev/urandom | tr -cd [:graph:] | head -c 32

AES Encryption with Base64 encoding

We start by adding our imports. import java.nio.charset.StandardCharsets import import java.util.Base64 import javax.crypto.Cipher import javax.crypto.spec.SecretKeySpec For this example we’re going to use the CBC (Cipher Block Chaining) variation of AES. val Algorithm: String = "AES" val Transformation: String = "AES/ECB/PKCS5Padding" def aeskey: String => Key = key => new SecretKeySpec(key.getBytes, Algorithm) Our encrypt function receives a key and some text to encrypt. The function will return a base64-encoded string if everything goes ok.