Lucas Viana’s developer blog

Welcome to my blog. If you like something I’ve written, it would make my day to hear about it. If you dislike it, hit the dislike button below.

Python f-strings cheat sheet

Python f-strings The image above is in SVG format, so it is infinitely scalable: zoom in at will! Some further notes on Python f-strings: Never use the f or F formats for floating point numbers. Use g instead. The problem is the f format fixes the number of digits after the decimal separator and that is most probably not what you want. >>> f'{0.00001234:.2f}' # Gets converted to zero 0.00 >>> f'{0....

April 17, 2023 · 1 min · Lucas Viana

Parsing command line arguments in Bash

If you don’t have a CLI option parser in your scripts, you’re probably being inneficient. As a software developer, you are the product of the systems you’ve built to assist you in your thinking: We should minize the time spent getting in position to think. Instead of wasting time, we should be building systems. Those systems must get better and better as time goes by. Without option parsing, our scripts will crumble as soon is it reaches a small amount of complexity....

February 20, 2023 · 12 min · Lucas Viana

Bash word splitting

The problem The code examples below make my eyes bleed, and if you don’t see it, read on – or stop writing Bash. for f in $(ls *.mp3); do rm -rf "$f" done for f in $(find -name '*.mp3'); do rm -rf $f done We will go over what’s wrong with such code, but before, we need to understand Bash a little better. How bash executes commands The argument vector and execve At its core, Bash is simply a command executor....

February 7, 2023 · 5 min · Lucas Viana

Learn `sed` and be happy

When you’re done reading this article, you’ll be ready to become a sed expert. Yes, you read it right – So let’s hit the ground running. What is sed? Ever wanted to edit a file without having to open it in a text editor? Or maybe you want to modify several files and don’t want to do it manually? With sed, you just issue a short command in the terminal and bam!...

July 5, 2022 · 7 min · Lucas Viana

Encodings part 1: Unicode, ASCII, UTF-8 and... Latin-1?

What is Unicode, why is it used everywhere, and what are the options? We, software developers, use string data types daily and yet, there is a lot under the surface that nowadays we don’t even think about anymore. This makes character encodings a basic thing, but is it simple? This is part 1 of a series of posts on Unicode and encodings: Encodings Part 1: Unicode, ASCII, UTF-8 and… Latin-1? Encodings Part 2: The down and dirty of UTF-8 Encodings Part 3: The down and dirty of UTF-16 Encoding, you say?...

November 3, 2021 · 8 min · Lucas Viana

Encodings part 2: The down and dirty of UTF-8

What the double UTF is UTF-8? Let’s decode this, bit-by-bit. This is part 2 of a series of posts on Unicode and encodings: Encodings Part 1: Unicode, ASCII, UTF-8 and… Latin-1? Encodings Part 2: The down and dirty of UTF-8 Encodings Part 3: The down and dirty of UTF-16 Unicode and UTF-8 In part 1, we dug a little deeper into the reasons to be for Unicode and found out that Unicode is an immense character table containing all the characters in the world....

November 3, 2021 · 4 min · Lucas Viana

Encodings part 3: The down and dirty of UTF-16

This is part 3 of a series of posts on Unicode and encodings: Encodings Part 1: Unicode, ASCII, UTF-8 and… Latin-1? Encodings Part 2: The down and dirty of UTF-8 Encodings Part 3: The down and dirty of UTF-16 A very short background At the end of the ’80s, there were two competing forces for standardizing character sets: ISO 10646 and Unicode. ISO was idealistic and Unicode was pragmatic. ISO created a character set containing more than 2 billion code points (of course, most were not allocated)....

November 3, 2021 · 5 min · Lucas Viana