Introduction In this post we will explore an example of how to test code with unit test that uses an HTTP client. Code with HTTP Client The following code is a typical example of a function that uses an HTTP client to do some requests. package main import ( 'context' 'errors' 'fmt' 'io' 'log' 'net/http' 'strings' ) var ( ErrFailedToCreateRequest = errors . New ( 'failed to create request' )…
Introduction In this post we will explore an example of a Go binary that combines features such as Go Embed and Go-Migrate to have a self-contained binary that runs the appropriate migrations before starting any actual work. What is embed? Go Embed was introduced in Go 1.16 as a core library that allows binaries to contain external files embedded and they are accessible from inside the binary.…
Introduction Lately I have been in need of cropping some images, the easy thing to do would have been to install Gimp and do it there, but that is not fun. I end up using ImageMagick to do some basic image manipulations. Since it took me few searches to find what I needed I decided to write a post in my blog so whenever I need it again, I know where I can find it easily. Crop Images The most…
Introduction We all have used naked boolean parameters at some point during our lives , specially when we were starting to learn to program. Other times we add them when refactoring code, or we are just hacking somthing together. However, naked boolean parameters are a code smell and signs of a bad code . First, they hurt the readability of the code and since we spend the vast majority of our time…
Introduction Before we start, I want to define a couple of terms: In place : the algorithm does not require extra space to be executed. In other words, if you have to sort and array of n elements, the algorithm will use only that array of n elements. Stable : if two elements of the array are the same, they will keep the same relative order in the array after being sorted. For example, if you want…
Introduction Have you ever thought about how the for loop is implemented in Python? I always thought it would iterate over all elements in the sequence, like it does, but that first it would query the sequence to know its length and then request that many elements. Turns out, it does not work like that. >>> for item in range( 5 ): ... print(item) ... 0 1 2 3 4 So, how does it work? Basically, the…
Introduction As for any other language I develop with, I like to make use of tools and utilities to help me spot problems as soon as possible. For that reason I like to have three things in all my projects: Formatter Linter (Static Analysis) Unit Test Framework When developing in Bash there is no difference in this regard. Some people would say that Bash is just for scripting. I mostly agree with…
Introduction As we all know the process of looking for a job is hard. And you have to stand out from the crowd . Therefore, when I saw s0ulshake’s CV I wanted to do something similar, but with other technologies (you know I do not know JavaScript) and add the ability to move forward and backward. I decided to code it in Rust because I have been looking for an excuse to start using it and…
Introduction There is plenty of meterials such as talks, tutorials and posts talking about Go , but I want to give my opinion about what I think are the strenghts and weaknesses of Go . Full disclosure : I do not use Go at work. I use Go in my personal projects. Therefore, take my opinions with a grain of salt. Pros Go is one of the best programming languages I have seen in my whole life. I think…
Introduction Boost ASIO library is the defacto standard for network and low-level I/O programming . It has a great documentation available online , but there are a lot of methods and classes in the library. Therefore, if it is your first attempt to use it, it can be a bit challenging. Since there is a lot of ground to cover in the Boost ASIO library, I will only cover the work scheduler and the…
Introduction In the C++11 standard several concurrency related classes were added. I will talk about thread , future and promise . Yes, I know there are others more useful than these three. However, I think that it is really important to know well the bases to be able to use the more complex ones properly . As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the…
Introduction Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end. In this post I talk about some of the sanitizers available in Clang (some are avilable in GCC as well). They help you detect problems at run time (dynamic analysis). As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the…
Introduction In this post I talk about what has been added in the C++ standard regarding lambda expressions since they were introduced in C++11 . All the code and configuration files used in this post are available in this repo in GitHub. What is a lambda expression? A lambda expression is a simplified notation for defining and using an anonymous function object. Instead of defining a named class…
Introduction I am working on a pet project to create a C compiler for the ARM architecture . You can find more information about this topic in my previous post ARM C Compiler (ACC) - Basic Compiler I . The source code of this project can be found in GitHub . What is the current state of the project? Currently, I have implemented a very basic compiler , this version is available in GitHub as v0.2 .…
Introduction NOTE: The code used to replace the user’s path with the one provided is BAD, never change user’s pointer content unless he/she is expecting that to happen. Don’t do that at home kids I decided to explain the basics of a Linux Kernel Module with humor. I am not saying this is a good idea for April’s fool, but it is quite close ;) This module shares some ideas…
Introduction In this post I talk about three data structures I implemented to compare their performance in different scenarios. The three data structures are Trie , Ternary Search Tree and Radix Tree . All the code for the data structures as well as the tested scenarios are available in this repo in GitHub. What is a Prefix Tree? It is an ordered tree data structure that is used to store a dynamic…
Introduction This post is a continuation from a previous post called Unity; unit test for C , but in this post we are going to use FFF . FFF is one of the available mocking frameworks for C. In this example I will use CMake to configure the project and build it. All the code and configuration files used in this post are available in this repo in GitHub. Why do we need to mock functions? To answer…
Introduction Why do you want to create your own compiler? To answer this question I have to give you some background. For Christmas I got a BeagleBone Black , perfect to learn ARM assembly . After a few weeks of doing the usual stuff I decided I wanted a bigger project to improve my knowledge. However, the idea to start the development of a compiler comes from…
Introduction Unity is one of the available frameworks to create unit tests for C. In this example, I will use CMake to configure the project and build. All the code and configuration files used in this post are available in this repo in GitHub. Can you do unit test in C? And what is Unity? Some people do not know you can do unit tests in C and people must do unit tests in any language. My choice…
Introduction This post is a continuation from a previous post called Unit test with Google Test for C++ , but in this post we are going to use Google Mock , that extends the functionality of Google Test . Google Mock is one of the available frameworks for C++ to mock objects in unit tests . In this example I will use the same technologies as for the previous one: CMake to configure the project and…
Introduction Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end. There are also several awesome tools build on top of Clang and I am going to show the three of them I use the most. As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the tools from the repository (clang,…
Introduction rr is a debugging tool from Mozilla that enhances the behaviour of GDB . It can be found in GitHub , but my recomendation is to go first to the website of the project . In the website you can find really useful information and documentation. As usual, I am working from an Arch Linux computer. Therefore, I can install rr from the AUR repository (rr). For other distributions you can…
Introduction Cling is an interactive C++ interpreter , built on top of Clang and LLVM compiler infrastructure. It can be found in GitHub (Note: Lately there has not been that much development on it). Since I use Arch Linux I am lucky to have cling in the AUR repository (cling-git). For other ones you can use the cling-all-in-one repo that contains a script to download all dependencies, compile and…
Introduction I have seen LD_PRELOAD used in several cases. From using it to allow programs that link to a newer version of the libstdc++ , to cracks for applications that hijack some calls and provide the expected result to tell the application they have a valid license . The aim of this post is to show how to find these dangerous calls in applications that you are running which you cannot fix…
Introduction Google Test is one of the available Frameworks to create unit test for C++. In this example I will use CMake to configure the project and build. Furthermore, for the dependency manager I will use the new and shiny conan . Before starting, why use a dependency manager such as conan or software to configure and build such as CMake ? Because these technologies are widely use it in real…
ACC is a pet project with the purpose of improving my knowledge of three topics. The C language, compilers and the ARM assembly. I think this is a good exercise to go deep into both topics. The ACC is a LALR(1) parser , that means it is a Look-Ahead Left-to-Right parser . The current Grammar of the ACC is the following: S -> int main '(' ')' '{' E '}' E -> return I; | if '(' B ')' '{' E '}' | if…
Trie, Ternary Search Tree (TST) and Radix Tree is aimed to compare the performance of these three data structures. The three data structure are an implementation of the abstract data type dictionary , but they are enhanced with an extra method called “keys”. That method returns the keys with that share a provided prefix. This can useful to use it in tasks such as autocomplete searches.…
This resume is an interactive application written in Go and using the Bubble Tea library it can be found in https://github.com/maitesin/tui-cv/ . The idea for this project was inspired by S0ulshake’s CV , however, I preferred to use other technologies, since I do not know JavaScript. I have packaged the application inside a Docker image, so people can run it on their computers with the…
YAUS , Y et A nother U RL S hortener, was first written in Python3 using the Flask web framework, and deployed in Heroku : https://yaus.dev . The code of that version can be seen here: https://github.com/maitesin/yaus/tree/e938b0d218849f50df7ab5a4a46923faf235762b . However, the project has been rewritten in Go and I have applied some Domain Driven Design (DDD) and Command Query Segregation (CQS)…