What is Byte Masking and how useful is it?

Part of the operators we get introduced to when learning to program is Bitwise Operators, examples are: The Bitwise OR | (a single pipe character) The Bitwise AND & (a single ampersand character) The Bitwise XOR ^ (a single caret character) Each of these has its usage, a refresher can be demonstrated considering these two variables foo=1 and bar=0 For the bitwise OR(|) operator const foo = 1, bar = 0 console....

September 18, 2023 · 8 min · Aleem Isiaka

Creating multiple copies of objects in Ruby

Since everything is an object in Ruby having a functionality that can duplicate objects is not a bad idea. Ruby ships with two methods for making copies of an object: the dup method and the clone method. In Ruby, all variables hold a reference to an object. In a case where a section of a code modifies an object that is not meant to be modified, it is ideal to make a copy of that object to be used in that section of the code, protecting the integrity of the copied object....

September 7, 2023 · 2 min · Aleem Isiaka

When to use puts, print, and p in Ruby

Usually, programming languages have methods for printing out variables. Ruby is not an exception. We will explore the 3 popular methods for printing variables in the Ruby Programming language. The print method The way print(var) works is basically converting its value to a string by calling the to_s method on the object(everything is an object in Ruby) before printing the value and returning nil to its caller. num = 123 print(num) # -> 123 => nil The print method can be easily used for concatenating strings...

September 5, 2023 · 2 min · Aleem Isiaka

tar (child) xz Cannot exec No such file or directory

The error: tar (child): xz: Cannot exec: No such file or directory Is majorly an issue with the xz command not found on the host machine. To verify, run: whereis xz Fix To fix, use the installation command for your Linux distribution: sudo apt-get install xz-utils # Debian / Ubuntu sudo yum install xz # RHEL / CentOS sudo zypper in xz # OpenSuSE sudo pacman -S xz # Arch Linux Then untar again with:...

July 10, 2023 · 1 min · Aleem Isiaka

Change files extension in a directory

A onliner for f in *.old; do mv "$f" "${f%.old}.new"; done How??? To change the name of a file on Linux/Unix use the mv command mv currentfilename newfilename If there is a file named aleemisiaka.old and want to rename to aleemisiaka.new We can store the filename to a variable with export FILENAME=aleemisiaka And use the variable name in the mv command mv "$FILENAME"$ "$FILENAME.new" This renames the file from aleem-isiaka.old to aleemisiaka....

June 22, 2023 · 1 min · Aleem Isiaka

Optimizing Merge Sort

Going through Chapter 2 of CLRS, I was introduced to the concept of divide and conquer, which is a very interesting algorithm technique, and a popular example of the divide and conquer algorithm is merge sort. Merge sort has an Θ(nlgn) run time, which is very good for large inputs. When the input is sufficiently small enough, the algorithm has a worse run time compared to a sorting algorithm that completes in Θ(n^2) time....

June 20, 2023 · 1 min · Aleem Isiaka

Searching for a pattern in the man pages

To search through the man pages for some keywords, use the -k option. man -k [keyword] This shows a result of the commands, and routines that match the keyword with a one-line description of what they are about. man -k passwd shows all the possible entries for passwd in the manual pages. The apropos The man -k [keyword] command is similar to a help utility called apropos which is available both on Unix and Linux....

June 20, 2023 · 1 min · Aleem Isiaka

Know the man(nual) pages

There are many ways to get help as a Linux administrator, manual pages are one of them as they are always close - accessible via the terminal. The manual pages, called “man pages” is a local documentation and description of software packages, drivers, routines, and libraries on a Linux machine. To use it run man [command|library|routine|driver] and replace the command with the name of a command to find a manual....

June 18, 2023 · 1 min · Aleem Isiaka

Send message from a service worker

Communication between service workers and the clients browser window can be achieved by simply doing: self.clients.matchAll().then((clients) => { clients.forEach((client) => client.postMessage({ msg: "Hello from SW" })) }) The variable self is a reserved keyword in a service worker context. It references the global scope of the current worker execution scope and has some useful properties. It is like the window object of a JavaScript browser context. In the above snippet, all the clients that run the service worker are loaded, then the ....

January 22, 2023 · 3 min · Aleem Isiaka

Autocompile Go

First, install CompileDaemon: $ go get github.com/githubnemo/CompileDaemon && go install github.com/githubnemo/CompileDaemon Then, from the root of the project, create a Make file: $ touch Makefile And add the below content: GOCMD ?= go GOBUILD = $(GOCMD) build GOCLEAN = $(GOCMD) clean GOTEST = $(GOCMD) test GOGET = $(GOCMD) get BINARY_NAME = project_name BINARY_UNIX = $(BINARY_NAME)_unix default: all all: test build build: $(GOBUILD) -o ../$(BINARY_NAME) -v -ldflags="-X main.VERSION=$(TAG)" test: $(GOTEST) -v ....

August 21, 2021 · 1 min · Aleem Isiaka