avatar

Andres Jaimes

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:

 1import scala.concurrent.{ExecutionContext, Future}
 2import scala.util.{ …

Generate a random string using the console

Generate a random string using the command line:

1cat /dev/urandom | tr -cd [:graph:] | head -c 32

On OSX, the previous command might return a tr: Illegal byte sequence error, so try:

1export LC_ALL=C; cat /dev/urandom | tr -cd [:graph:] | head -c 32 …

AES Encryption with Base64 encoding

We start by adding our imports.

1import java.nio.charset.StandardCharsets
2import java.security.Key
3import java.util.Base64
4import javax.crypto.Cipher
5import javax.crypto.spec.SecretKeySpec

For this example we’re going to use the CBC (Cipher …

Monoid definition and examples

We are going to cite the definition of a Monoid found on this post:

Conceptually, a monoid is anything that:

- Has a "zero-value": `mempty`, e.g., `0`
- Can be "appended" together: `mappend`, e.g., `+`
- Has an identity with the …

Creating an sbt project from scratch

Files and project structure

sbt projects use the same structure as Maven. Creating a project from scratch involve the following steps:

1mkdir some-new-project
2cd some-new-project
3mkdir -p src/{main,test}/{resources,scala}
4mkdir project

Create a …

Sending a message using telegram and scala

In this article we are going to use scala to send a message via Telegram. The process is very simple and pretty much involves setting up a bot and making a GET request to Telegram’s api.

The Telegram app on the phone has more features than its …