Dynamically lookup a property in deeply nested object

I was solving a challenge and got to a point where I had to implement a store that could hold arbitrarily deeply nested objects. The new me, I need to see what others have done. I found dot-prop npm package, which solves it quite well. But going through this gist, I found this answer. The author said a “functional way to solve it”… And this right here, is an example of declarative programming. ...

January 23, 2024 · 1 min · Aleem Isiaka

Imparative and Declarative coding?

As a software engineer, I have written a lot of lines of code, and taking hindsight back to the very first day of my career, I have written a log of bad code. I recently published a new version of my react-here-maps library which saw a sprinkle of my improved skill set. I had a coding interview where I was tasked to add functionality to support extra data points of the original response and think about adding weeks, months, and years to data that only returned days. The implementation worked but it wasn’t what was expected. ...

January 20, 2024 · 4 min · Aleem Isiaka

Byte Masking the ins and out

Byte masking is a deep CS concept reserved for the nerds. Here we will attempt to dissect the topic and provide a relatable experience for everyone. Welcome… Masking and its Relation to CS Masking is a process of concealing information. Take for example having a string "A" but revealing “X” to others such that only those with the information on how to get the hidden value can retrieve it. A byte is a group of bits(1 and 0) usually eight in number. Such that 00000000 becomes a byte but the individual zeros are known as bits. ...

January 17, 2024 · 4 min · Aleem Isiaka

Ruby - if statement?

In Ruby, the if statement looks like this 1 2 3 4 5 val = 1 if val == 1 p "Equality Checked!" end And for if else 1 2 3 4 5 6 7 val = 2 if val == 1 p "Equality Checked!" else p "Equality Unchecked!" end And for if, else if, else 1 2 3 4 5 6 7 8 9 val = 2 if val == 1 p "Equality Checked!" elsif val == 2 p "Equality Middle Checked!" else p "Equality Unchecked!" end Also, remember that everything in ruby returns a value, so your if statement can return a value that could be stored in another variable. ...

January 15, 2024 · 1 min · Aleem Isiaka

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 1 2 3 const foo = 1, bar = 0 console.log(foo | bar) -> 1 For the bitwise AND(&) operator 1 2 3 const foo = 1, bar = 0 console.log(foo & bar) -> 0 For the bitwise XOR(^) operator 1 2 3 const foo = 1, bar = 0 console.log(foo & bar) -> 0 This seems pretty basic until you understand it is not. ...

September 18, 2023 · 9 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 · 3 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. 1 2 num = 123 print(num) # -> 123 => nil The print method can be easily used for concatenating strings ...

September 5, 2023 · 3 min · Aleem Isiaka

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

The error: 1 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: 1 whereis xz Fix To fix, use the installation command for your Linux distribution: 1 2 3 4 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 1 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 1 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 1 mv "$FILENAME"$ "$FILENAME.new" This renames the file from aleem-isiaka.old to aleemisiaka.old.new ...

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. One of the exercises is to create an optimized version of the merge sort that runs the original merge sort algorithm for sufficiently larger inputs where it shines and to run insertion sort [ Θ(n^2) ] when the input size is sufficiently small enough. I have a solution for it on my Clio website, this post walks through the process for the solution. ...

June 20, 2023 · 1 min · Aleem Isiaka