Command Line Efficiency With Tmux

I’m a a Software Developer that uses Ubuntu as his main OS and Vim as his main editor. I like Ubuntu (more specifically Gnome) because it allows me to move windows around without having to use the mouse. If I need to maximize a window, move a window to a different screen or split the screen between two windows, I just need to type a keyboard shortcut.

When I’m focused on writing or reading code, Vim also allows me to move around the code easily without a mouse.

Tmux is a tool that allows us to expand the capabilities of the terminal so we can manipulate terminal panes similar to how we can manipulate windows with Gnome, or navigate code in a similar fashion as with Vim.

Read More

Verifying Github commits with GPG

At the time of this writing, Github is the most popular place to host open source projects on the internet. It has a lot of features that make it easy to collaborate, navigate the code, test, deploy, etc.

Since it’s so popular, it’s important to understand a little about how security works on Github.

Security

When we create a new repository on Github we are the only ones who are allowed to write to that repository.

If we want to allow other people to write to a repository we can add them as a collaborator. Collaborators have a lot of power, so they should be people we know well and trust.

Read More

Dependency injection (Inversion of Control) in Spring framework

In this article we are going to learn about one of the foundational pieces of the Spring Framework; its implementation of Dependency Injection (which they usually refer by the more confusing name: Inversion of Control or IoC).

If you don’t know what Dependency Injection is, you can start by reading the first section of my Dependency Injection with Dagger and Bazel article. That section explains what is dependency injection and how it’s typically used.

Spring Beans

The term bean is used to refer to a few things in the Java world, so it’s important to know what it means when used in the context of Spring.

A Spring bean refers to an object that is injected by Spring’s depedency injection framework (Usually referred as IoC framework or IoC container).

ApplicationContext

The ApplicationContext interface takes care of creation and injection of beans. There are different implementations of this interface that allow us to configure our beans using different methods. We’ll start by looking at the traditional way: ClassPathXmlApplicationContext.

Read More

Kubernetes networking with Istio

A few months ago I wrote an Introduction to Kubernetes. In that article I created a service to achive communication between containers. This service acts as a load balancer that redirects requests to pods that are part of a deployment. We communicate with this load balancer via an IP that is assigned to it.

A service that needs to communicate with another service can query Kubernetes to discover the IP address for the load balancer and use that IP address for communication. This is does the job, but there are some things that are not possible with this configuration that we get from Istio.

Read More

Flyway - Version control for Databases in Java

Database migrations

Database migrations (or Schema migrations) are the technique used to keep track of changes in the schema of a database. There are many tools for handling database migrations for different languages and frameworks; They typically provide these features:

  • Represent schema changes in code (so they can be added to source control)
  • Keep track of the last migration applied
  • Apply only the necessary migrations

Having all the schema changes in code also makes it easy to ensure all environments are running exactly the same DB schema.

Read More

Concurrency in computer systems

In this article we are going to learn what is concurrency in computer systems. To understand it better, we’ll see what are the problems that occur when there is concurrency and what are some ways to prevent those problems.

What is concurrency?

Concurrency referes to the ability of a computer system to do different things at the same time.

We see concurrency in action in our computers when there are multiple programs executing at the same time. We can be playing some music in our computer and at the same time browsing the internet, for example.

At a high level, there are two ways of doing concurrency:

  • Time slicing
  • Parallel execution

For hardware that supports parallel execution, time slicing can be done on top of it.

Read More

Jackson - Working with JSON in Java

Jackson is a set of tools for working with JSON data in Java. Jackson contains a wealth of features, so don’t expect this article to cover them all.

Parsing arbitrary JSON strings

To get started with Jackson, let’s look at how we can parse an arbitrary JSON string:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package example;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Exampler {
  public static void main(String args[]) throws Exception {
    String json = "{\"hello\":\"world\"}";
    JsonNode root = new ObjectMapper().readTree(json);
    if (root.has("hello")) {
      System.out.println("Value of hello is: " + root.get("hello"));
    }
  }
}

The example above prints:

1
Value of hello is: "world"
Read More

Immutables and Java

What are immutables?

An immutable is a type that can’t be modified after it has been created.

The most common way to define an object in Java is by instantiating a class; Once the class is instantiated, we can modify its properties directly or by calling methods that modify them. Let’s look at an example of a mutable object:

1
2
3
public class MyClass {
  public int value;
}

This is a very simple type that we can instantiate and modify:

1
2
MyClass obj = new MyClass();
obj.value = 4;

Immutables differ from these types in that once instantiated, they can’t be modified (Properties can’t be changed and there are no methods to modify them).

Read More

Setting up LSP in Vim

In a previous article, I explained a little about how Language Server Protocol clients work. This time I’m going to explain how we can take advantage of this protocol in Vim.

Installing vim-lsp

Configuring vim-lsp is a little more complicated than installing other plugins, because it requires many pieces to be put together in order for it to work correctly.

Let’s start by installing vim-lsp:

1
2
cd ~/.vim/pack/my-plugins/start
git clone https://github.com/prabirshrestha/vim-lsp.git
Read More

Implementing a Language Server Protocol client

There are a lot of IDEs out there that offer features like auto complete, go to definition, etc. Traditionally each IDE has logic for parsing and understanding code in a project, and plugs this understanding into its UI. How good the IDE’s understanding of a particular language together with their user experience are their most powerful selling points.

In the past, different IDEs that supported the same language had their own proprietary code that gave them insights into a programming language.

LSP is an open source standard created by Microsoft. It defines a protocol for a program that understands a programming language to talk to another program (typically an IDE) that wants to take advantage of these features. This protocol allows anybody to build a server that understands a language and make it available to the world. Programmers can leverage these servers to provide powerful tools or IDEs.

The server

The server takes care of understanding the structure of a program and implementing an API to share this understanding.

There are various server implementations out there and they vary widely in the number of features they support.

Read More