"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

libp2p performance benchmarking

2023-10-27

I invested some time in studying QUIC and libp2p In this article, I will show you how to benchmark the network transfer using perf module for 2 scanerios:

Let’s print help first:

 1     Running `rust-libp2p/target/debug/perf -h`
 2Usage: perf [OPTIONS]
 3
 4Options:
 5      --server-address <SERVER_ADDRESS>
 6      --transport <TRANSPORT>
 7      --upload-bytes <UPLOAD_BYTES>
 8      --download-bytes <DOWNLOAD_BYTES>
 9      --run-server                       Run in server mode
10  -h, --help                             Print help  

Read More...


Learning Rust by building Tetris: my favorite childhood game

2023-10-03

Play tetris 2-player mode in the terminal

After completing the Rust book and working through rustlings, I found myself standing at the crossroads, wondering where to go next. It was then that I had an idea - a project that would allow me to apply my newfound knowledge and create something meaningful. My favorite childhood game, Tetris, became the inspiration for my next coding adventure.

Since I want it to be playable on Windows, I chose the TUI library crossterm.

Read More...


SICP Exercise 2.77: expected a procedure that can be applied to arguments, given #f

2023-07-13

2.5.1 Generic Arithmetic Operations

Louis Reasoner tries to evaluate the expression (magnitude z) where z is the object shown in figure 2.24. To his surprise, instead of the answer 5 he gets an error message from apply-generic, saying there is no method for the operation magnitude on the types (complex).

To simplify the install-complex-package procedure, I made the following changes:

 1(define (install-complex-package)
 2  (define (make-from-real-imag x y)
 3		((get 'make-from-real-imag 'rectangular) x y))
 4	(define (tag z) (attach-tag 'complex z))
 5	(put 'make-from-real-imag 'complex
 6		(lambda (x y) (tag (make-from-real-imag x y))))
 7
 8(install-complex-package)
 9
10(trace-define (make-complex-from-real-imag x y)
11	((get 'make-from-real-imag 'complex) x y))
12
13(magnitude (make-complex-from-real-imag 3 4))

Read More...


A terminal UI for Taskwarrior

2023-04-21

When I first started using Linux, I came across Taskwarrior, a command line tool for managing to-do lists. However, I never got around to using it extensively, mainly because there was no Android app available at the time, making it difficult to sync tasks from my phone.

I did experiment with taskwarrior-pomodoro but unfortunately, it wasn’t as effective as I had hoped.

Recently, though, I stumbled upon foreground, a new discovery that reignited my interest in Taskwarrior,

Read More...


A simple terminal UI for ChatGPT

2023-04-01

When I started learning Linux, I immediately fell in love with the terminal. I still remember the feeling of typing commands into the terminal, pressing Enter and seeing if I got the expected result. As a system administrator and DevOps engineer, I always wanted to do everything on the terminal.

The reasons are simple: it allowed me know what was happening behind the scenes, and it was faster than switching to other tools, and then back to the terminal to continue working.

Read More...


gocloud - writing data to a bucket: 403

2022-12-23

Problem

We are writing some integration test using Go CDK. After writing some data to a bucket:

1	writer, err := buckOut.NewWriter(ctx, fileDst, nil)
2	if err != nil {
3		logger.Errorf("failed to write to fileDst: %v", err)
4		return err
5	}
6	defer writer.Close()

we got an error when reading:

1(code=NotFound): storage: object doesn't exist

By reading the documentation, I pay attention to this:

Closing the writer commits the write to the provider, flushing any buffers, and releases any resources used while writing, so you must always check the error of Close.

Read More...


Terraform failed to acquire state lock: 403: Access denied., forbidden

2022-11-17

Problem

We stored Terraform state in gcs. For some reasons, we got this error randomly when running on BitBucket pipelines:

 1 2│ Error: Error acquiring the state lock
 3 4│ Error message: 2 errors occurred:
 5* writing
 6"gs://bucket/path/to/default.tflock"
 7│ failed: googleapi: Error 403: Access denied., forbidden
 8* storage: object doesn't exist
 9101112│ Terraform acquires a state lock to protect the state from being written
13│ by multiple users at the same time. Please resolve the issue above and try
14│ again. For most commands, you can disable locking with the "-lock=false"
15│ flag, but this is not recommended.
16

Read More...


The King of Vietnamese language game show

2022-11-04

My family likes to watch “The King of Vietnamese language” game show together. I want to encourage our son to love Vietnamese. At the end of the game, the player has to find 7 complex words from the letters, for e.g,

đ / ă / n / g / c / a / y

One evening a few weeks ago, while we were watching the final round, my wife suddenly came up with an idea: this game could be programmed.

Read More...


SICP Exercise 2.43: Eight queens: interchange the order of the nested mappings

2021-11-02

Exercise 2.43: Louis Reasoner is having a terrible time doing exercise 2.42. His queens procedure seems to work, but it runs extremely slowly. (Louis never does manage to wait long enough for it to solve even the 6× 6 case.) When Louis asks Eva Lu Ator for help, she points out that he has interchanged the order of the nested mappings in the flatmap, writing it as

Read More...


SICP Exercise 2.42: Eight queens puzzle

2021-10-29

Exercise 2.42: The “eight-queens puzzle” asks how to place eight queens on a chessboard so that no queen is in check from any other (i.e., no two queens are in the same row, column, or diagonal).

One way to solve the puzzle is to work across the board, placing a queen in each column. Once we have placed k - 1 queens, we must place the kth queen in a position where it does not check any of the queens already on the board.

Read More...