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 desktop counterpart. I recommend you to use the phone version to make sure you have access to all the required features. On Telegram 1.

How to create a self-contained jar file (fat jar) using sbt

A fat jar is a jar file that contains any dependencies required by a Java or Scala program. Deployment becomes an easy task if we only have to deal with one single file. In this article we’ll go through the steps required to create a fat jar using Scala and sbt. The following procedure has been tested using Scala 2.12.8, sbt 1.2.8 and jdk 11. 1. project/assembly.sbt Create project/assembly.

Add your GMail account to Metatrader Notifications

On this article we’re going to set up Metatrader for email sending. This is recommended so you don’t miss important messages happening to your account. Getting a password from Google If you want to connect your Google email account, you have to generate a new password for Metatrader. To generate a Google password: On the GMail page click on the Apps menu at the top right corner and then click on Account.

Implementing put and delete operations using BatchWriteItem

The BatchWriteItem operation allows us to work with groups of up to 25 items per request. Additionally, we can put and delete items to one or multiple tables. Amazon DynamoDB’s page says: A single call to BatchWriteItem can write up to 16 MB of data, which can comprise as many as 25 put or delete requests. Individual items to be written can be as large as 400 KB. In this article we are going to go through the process of putting and deleting items to a table that looks like this:

Undoing the Last Git Commit

A command so important, it deserves its own page: git reset --soft HEAD~1 The previous command undoes the last commit to git. I think this is one of those commands that I have typed many times during the last year. It’s very important to know which branch we currently are on, but sometimes excitement (or stress) may make us forget checking it. If this is not enough, then you can reset your branch to master like this: (this will lose all your changes):

Inserting and updating items to DynamoDB lists and maps

Should I use a map or a list? A simple rule: If you need to update or remove an item, lists only allow you to do it by index. While maps let you do it by key. Their simplified representation goes like this: { "someMap": { "key1": "value1", "key2": "value2", }, "someList": ["value1", "value2"] } Inserting and updating to a map The following example adds or updates an instance of “SomeItem” as a json string into a map field called someMapField.

Testing scala classes and controllers

This article discusses different approaches for testing classes, services, and PlayFramework controllers using scalatest. Setting up the project dependencies First step is to add to build.sbt the next dependency: "org.scalatest" %% "scalatest" % "3.2.2" The following template unit test uses the WordSpec style which offers a natural way for writing tests. scalatest offers more styles, but I find this one more expressive. PlaySpec (found in the PaylFramework) extends WordSpec and has a similar behavior.

Enumerations

Using case object Unlike other languages, Scala does not have a keyword for enumerations. One way to implement them is by using case objects. For example: sealed trait OperatingSystem case object FreeBsd extends OperatingSystem case object Debian extends OperatingSystem case object Alpine extends OperatingSystem case object Arch extends OperatingSystem case object Osx extends OperatingSystem To use it, just define a value of type OperatingSystem. You can even get a string representation from these values:

Installing Rancher on Ubuntu/Docker

On this article we are going to install a rancher server on Ubuntu. Let’s start by getting the rancher image from docker hub: sudo docker run -d --restart=always -p 8080:8080 --name=rancher-server rancher/server Go to http://ip-address:8080 and click on Add Host. It is important that you do not use a localhost address (127.0.0.1, localhost). If you do so, and you want to add your local computer as an agent, you will not be able to reach it.

From MySQL to Postgres - Useful commands

This article shows a list of basic commands on MySQL and their corresponding versions for PostgreSQL. Connecting to a database MySQL $ mysql -u root -p Postgres $ su pgsql $ psql Or using a different user: $ psql dbname If you can’t connect because you don’t know what databases are available, try any of these: psql -l psql postgres psql template1 The postgres database is a default database meant for use by users, utilities and third party applications read more.