Git Cheat Sheet

Below is a table with commands I don’t run frequently enough to remember them, and have to rely on searching on internet again and again. Now it’s saved somewhere. 😀 Last update: October 3rd, 2023. Operation Command Commit without files git commit -m "some message" --allow-empty List commits in one line each git log --oneline Remove local tag git tag -d <tag_name> Remove remote tag git push --delete origin <tag_name> Stash changes git stash Retrieve changes from stash git stash pop Delete local uncommitted changes git reset --hard Delete commits until ID git reset --hard <commit_ID> Delete local changes to file git restore <file> Revert a commit git revert <commit_ID> Rebase git rebase <branch> Rebase interactive git rebase -i <branch> Add a remote git remote add <alias> <uri> What about you?

Read More

5 ways to write better code

Forget for a moment about correctness, efficiency, or performance. If your code has 10 nested ifs or nested loops, the computer will be able to process and run it the same way as if it had one or two. No matter how badly written is the code, once it is compiled or interpreted without failure, the computer can run it. However, developers should write code not only for computers to run but also for other developers to understand and continue evolving it.

Read More

Spring Multirabbit

SpringBoot doesn’t offer a very easy way of handling multiple RabbitMQ servers without introducing the complexity of SpringCloud Stream or the need to manually provide multiple connection factories in code. The spring-multirabbit library solves this problem, requiring none or minimal changes to the code and very simple extension of the configuration. How to use? Add spring-boot-starter-amqp and spring-multirabbit into the dependencies of the project. Bellow, an example for Maven. <dependency> <groupId>com.

Read More

Two and a half years away

It’s been a long time since a last published a post on the blog. Shame shame shame! My last published post was Your first SpringBoot app in 5 steps on September 2019, 2.5 years ago. SpringBoot was in its version 2.0.8. Today, SpringBoot is in version 2.6.6. But why did this happen? The reason is clear: laziness! Kidding! Or better described… partially kidding! Besides a bit of laziness, many things happened during this time:

Read More

Your first SpringBoot app in 5 steps

SpringBoot is made to be powerful and easy! It’s very nice to work with and you will need only these 5 steps for your first app in a Maven project: Define the SpringBoot parent lib Define the dependency to the SpringBoot web library Define the Maven plugin for SpringBoot Create the main method Create a controller with an endpoint Parent SpringBoot lib This is the main and first step when creating a SpringBoot application.

Read More

5 popular decorators from Java

As a software developer, you probably know the Decorator Design Pattern, described in GoF. If not, read this first. Java has some nice decorators that can make your life easier, or tougher, depending on the case. Below, you will see a list of five decorators present in Java that you didn’t even realize they were decorations. java.util.Collections.synchronizedList(List list) Java 8 provides many synchronizedX() methods, for lists, sets, maps, etc. They are analog.

Read More

The Decorator design pattern in software development

A decorator is like a picture frame. It wraps the main object, adding some other functionality to it. The main goal of the Decorator pattern is to enable the addition of functionalities or behaviors dynamically to objects. To enable additional functionalities or behaviors in classes, a simple inheritance could easily do the job and no design pattern would be necessary. However, pay attention to the term “dynamically”. It means that the decorator must be instantiated after the original object already exists, and therefore inheritance couldn’t be the best solution.

Read More

4 rules to write deadly fast and efficient unit tests in Java with Mockito

Unit testing in OOP is the test of the smallest testable piece of code: the class. It’s used to make sure a single class does what it’s supposed to do. After some years of experience, I got to see unit testing as a crucial part of the software development process, since they give me some important advices that I couldn’t identify before writing them. Not being able to write a good and simple unit test might be a sign of code smell, advising you that your code is too coupled or is being responsible for too many things.

Read More

Lombok Constructors

In the post Lombok Getters and Setters, we talked about the use of Lombok to provide quick and easy getters and setters.

In this post, I will cover another great feature from Lombok, that provides quick and easy constructors. For this post, I will use Lombok v1.16.16.

Read More