avatar

Andres Jaimes

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 we can reset our branch to master like this: (this will lose all our 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 extends Product with Serializable object 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.

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 $ psql -h <host> -U <username> <database-name> Try the following if you don’t know the name of the available databases: psql -h <host> -U <username> -l Some installations add your current user to the list of allowed users to the database. In that case you can connect without specifying a username.

Ideas for successful software projects

This article describes some ideas on getting a successful software development process. A successful project: Depends on the expertise of the team. Don’t try to push many new technologies into a project. It will be difficult for the team to get acquainted with them and deliver a good quality project. Small steps are the best. Depends on the level of communication among the participants. Enforce communication among the team members.

Storing MySQL credentials on a file

MySQL allows you to store credentials in a file called ~/.my.cnf. The contents can look like this: [mysqldump] user=myuser password=mypassword We have to modify the file permissions and give read/write permissions to the owner only: chmod 600 ~/.my.cnf And done. We can now use it: mysqldump mydatabase mysqldump is going to read the credentials from that file.

Why you should not initialize a random generator with a static number

The following examples use random generated numbers initialized with a static seed. Never do it like this. Run the following examples multiple times to understand why it is important to have a good seed. PHP version: #!/usr/bin/php <?php srand(2); echo rand(0,10)."\n"; echo rand(0,5)."\n"; echo rand(0,4)."\n"; echo rand(0,6)."\n"; Java version: import java.util.*; /** * @see https://docs.oracle.com/javase/7/docs/api/java/util/Random.html */ public class RandomDemo { public static void main( String args[] ){ Random r = new Random(2); System.