State: hooked.

Just a big fat hook. [Image source]

In this post I’ll be making a quick intro to the useState hook, as well as giving some tips when using it.

useState basics

The useState hook is the most commonly used hook in ReactJS, and helps us with two things:

  • It preserves the value of a variable between renders.
  • It helps us easily re-render our component.

Now, how can we use it? First, we need to import it from the ‘react’ package. We may do this in two different ways: using a named import or accessing from the default export of ‘react’.

The named import would be done as follows:


All you need to get started

It’s time to learn Golang. [Image source]

This post intends to be an introduction to the Go programming language, also known as Golang.


I’m not an expert in Go. In fact, I’ve started learning about Go very recently. Therefore, take everything in this post with a pinch of salt.

Then… why am I writing a post about Go? It’s simple: I want to use this post as a tool to reinforce my learning process. I believe that working on a blog post and publishing it will force me to get every detail straight. Moreover, I’ll be crafting the guide that I would have liked to have found…

It’s not just about coding

Chema: my debugging companion

Rubber duck debugging

Have you ever wondered why there’s a rubber duck on your colleague’s desk? If there’s no tub in your office, it may be because he’s rubber duck debugging.

It has happened to all of us: you are stuck on a piece of code that you cannot get to work. You examine every line of code and still have no idea why it does not work. You go and get a coffee from the machine, hoping to get that moment of brilliance after returning to your desk. Ugh, it seems that’s not the case… at least not today. In a moment…

Try it yourself in this post!

Fractal art — source

First of all, what is a geometric fractal? A geometric fractal is a geometric shape with a repeating structure at different scales: it doesn’t matter whether you get closer to the image or not, you’ll always see the same pattern. Or, as defined by Benoit Mandelbrot, “a rough or fragmented geometric shape that can be split into parts, each of which is (at least approximately) a reduced-size copy of the whole”.

Now, how can we build a fractal in Python? Given that we are repeating a structure at different scales, we’ll need to apply a recursive solution. Moreover, we’ll be…

Learn how to generate them

In this post, I’ll be showing how to generate a pseudo-random strings in Python. Let’s get started!

Image from Free-Photos in Pixabay

The “random” module

In the first approach, we’ll be using the random module. This module allows us to create pseudo-random numbers or sequences and can be useful for generating non-security-related strings. As we’ll see in the next section, we should use the secrets module in that case.

Let’s get started with this approach. For starters, we need to define the type of characters that we want to include in our string (upper-case letters, lower-case letters, numbers, etc.). We can do this by using the string module

Master the basics

Image from StockSnap in Pixabay

This post will be a very practical one, providing you with simple and quick tips to work with strings in Python.

String multiplication

Python allows multiplying not only numbers, but also strings! Repeat a string as simply as follows:

>>> "a"*3

You may also multiply strings by a boolean value. For instance, the following snippet pads a number with a leading zero if it’s lower than 10:

>>> sn = lambda n: '{}{}'.format('0' * (n < 10), n)
>>> sn(9)
>>> sn(10)


Nowadays, it’s common to write titles (even in Medium), capitalizing the first letter of each…

Get rid of that awkward tmp.

In this post, I’ll be showing 3 ways to swap two values without needing a third variable. Even though these approaches may (well, might) be applied in any language, I’ll be showing their implementation in Python.

Swapped assignment

This is probably the most widely known approach, which consists of assigning to each variable the value of the other one in a single statement. This solution may be implemented as follows:

x = 3
y = 5
x, y = y, xprint(x) # 5
print(y) # 3

A simple approach to save us from an extra variable!

Arithmetic swapping

This approach uses an elegant…

How does the GIF format work?

GIF image from

In this post, we are going to explore LZ78, a lossless data-compression algorithm created by Lempel and Ziv in 1978. As an example, the GIF format is based on LZ78. LZ78 takes advantage of a dictionary-based data structure to compress our data. In this case, it makes use of a trie data structure, as it’s more efficient for this compression technique.

The motivation behind this approach was to get rid of the parameterization that was required to optimize LZ77’s performance. For instance, in LZ77 if our search buffer was too small, the resulting encoding would require more space, although the…

Start the year off right.

In this post, I’ll be presenting 3 powerful libraries that you may not know about. Let’s get started!


You’ve probably already used Python’s standard datetime module and, even though it’s already quite good in the most common situations, you’ve probably felt that it was missing something. Well, let me tell you, that something is probably already available in python-dateutil, which you may install as follows:

pip3 install python-dateutil

This library offers many powerful functionalities, for example, you may parse a string that contains a date in natural language. Let’s see how we can do this with an example:

from dateutil.parser…

Reduce the complexity of your code.


In this post I’ll be talking about partial functions and how we can use them to make our code cleaner.

What can partial functions do for us?

A partial function allows us to call a second function with fixed values in certain arguments. For instance, we may have a function that computes an exponentiation. Then, we may need to create a new function that assigns a fixed value to either the base or the exponent. We can easily do this by using functool’s partial function, without having to replicate the body of the original function. …

Dhanesh Budhrani

Multidisciplinary software engineer. Constantly learning. Software Engineer@Wubook. MSc@DTU. BSc@UC3M. LinkedIn:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store