Finances – Monthly Spending

11 Manageable Tips for Healthy Finances | SUCCESS
Image source: https://www.success.com/

In the past, I spent money how and when I felt like. I had no compass guiding how I spent money. In retrospect, this approach I would say isn’t sustainable especially when you start earning quite a lot of money.

I read a book that changed how I managed my expenses and I am really glad I did.

Here is a break down of how my expenses are being managed

I invest about 25% of my net salary into long/short term projects that will enable grow wealth on the long run. I divide the rest of the money as follows:

  • Savings (15%) : Savings for sudden/emergencies expenses e.g surgery for self or a family member etc.
  • Groceries (7%) : Used to purchase groceries and food stuff for the month.
  • Tfare (10%) : Used in moving around/ fuelling fixing your car.
  • Restaurants (5%) : Used to occasionaly eat out in restaurants.
  • Health and Welfare (5%) : Get drugs, books etc.
  • Entertainment (6%) : Netflx, Saving for Vacations etc fall in this category.
  • Personal Care (4%) : Body/Hair Cream, Spray etc. fall in this category.
  • Clothings (6%) : Clothes, Shoes etc. fall in this category.
  • Bills + Utilities + Housing (30%) : House rents, electric, water bills.
  • Givings + Dependencies (12%) : Support friends and family.

Most times, I don’t get to use all of the money in a month so I save the rest in a reserve space to use for other things in future.

DataStructures Series #13 – Binary Search Tree Datastructure

Trees, Binary trees and Binary search trees. » Learn Over Coffee

Image source: https://learnovercoffee.com/

A binary tree is a tree with every node having at most two children.

Example of a binary tree
Image source: https://en.wikipedia.org/

Please note that the node keys in the binary tree above isn’t arranged in any specific order. The only rule required is that every node has at most two children.

The Binary Search Tree is a type of Binary Tree datastructure that keeps its nodes keys in sorted order, lesser keys to the left and greater keys to the right.

Example of a binary search tree
Image source: https://en.wikipedia.org/

This arrangement enhances operations on the tree to be done using the binary search principle. The binary search principle searches for a node, starting from the root node and comparing between the left and right nodes to decide the next node to visit all the way down to the leaf node until it finds the search node.

Search Implementation

Search implementation pseudocode

// Node structure
class Node {
  Node left;
  Node right;
  int data;
}

search (int searchData, Node node) {
   if (node == null or node.data == searchData) {
      return node;
   }

   if (searchData < node.data) {
      return search(searchData, node.left);
   }
   
   if (searchData > node.data) {
     return search(searchData, node.right);
   }
}

REFERENCES

MySQL – Storage Engines

Note: A large chunk of this article was gotten from the official MySQL documentation https://dev.mysql.com/doc/refman/8.0/en/storage-engines.html

Database Corner: Beginner's Guide to MySQL Storage Engines ...

A database engine (or storage engine) is the underlying software component that a database management system uses to create, read, update and delete data from a database.

The two most used MySQL engines are InnoDB and MyIsiam among others like Archive, NDB, Memory etc.

InnoDB is the default and most general-purpose storage engine, and Oracle recommends using it for tables except for specialised use cases.

InnoDB engine is a transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback and crash recovery capabilities to protect user data. InnoDB implements row-level locking during update/delete operations which improves performance when compared to table-level locking.

It is important to note that different engines can be used for different tables in the same database. To know the supported engines in your MySQL server, run the SHOW ENGINES command.

Choosing between different storage engines

The various engines were designed with different use cases in mind, even though the InnoDB happens to be just enough in most cases, it is also important to know the capabilities of the other storage engines.

The following table provides an overview of some storage engines provided with MySQL, with clarifying notes following the table.

FeatureMyISAMMemoryInnoDBArchiveNDB
B-tree indexesYesYesYesNoNo
Backup/point-in-time recovery (note 1)YesYesYesYesYes
Cluster database supportNoNoNoNoYes
Clustered indexesNoNoYesNoNo
Compressed dataYes (note 2)NoYesYesNo
Data cachesNoN/AYesNoYes
Encrypted dataYes (note 3)Yes (note 3)Yes (note 4)Yes (note 3)Yes (note 3)
Foreign key supportNoNoYesNoYes (note 5)
Full-text search indexesYesNoYes (note 6)NoNo
Geospatial data type supportYesNoYesYesYes
Geospatial indexing supportYesNoYes (note 7)NoNo
Hash indexesNoYesNo (note 8)NoYes
Index cachesYesN/AYesNoYes
Locking granularityTableTableRowRowRow
MVCCNoNoYesNoNo
Replication support (note 1)YesLimited (note 9)YesYesYes
Storage limits256TBRAM64TBNone384EB
T-tree indexesNoNoNoNoYes
TransactionsNoNoYesNoYes
Update statistics for data dictionaryYesYesYesYesYes

Notes:

1. Implemented in the server, rather than in the storage engine.

2. Compressed MyISAM tables are supported only when using the compressed row format. Tables using the compressed row format with MyISAM are read only.

3. Implemented in the server via encryption functions.

4. Implemented in the server via encryption functions; In MySQL 5.7 and later, data-at-rest tablespace encryption is supported.

5. Support for foreign keys is available in MySQL Cluster NDB 7.3 and later.

6. InnoDB support for FULLTEXT indexes is available in MySQL 5.6 and later.

7. InnoDB support for geospatial indexing is available in MySQL 5.7 and later.

8. InnoDB utilizes hash indexes internally for its Adaptive Hash Index feature.

9. See the discussion later in this section.

REFERENCES

Software Licensing

WRATE - Software Licensing
Image source: http://www.wrate.co.uk/

Know your software rights when it comes to software licensing.

  • Right to Use for Personal Purpose
  • Right to Copy
  • Right to Publish
  • Right to Distribute
  • Right to Modify
  • Right to Sell
  • Right to Sublicense

There are generally five software licensing types:

  1. Public Domain
  2. Permissive.
  3. Copyleft (Protective Licence)
  4. Non Commercial
  5. Proprietary

Public Domain

Licenses in this domain usually give you the following rights:

  • Right to Use for Personal Purpose
  • Right to Copy
  • Right to Publish
  • Right to Distribute
  • Right to Modify
  • Right to Sell
  • Right to Sublicense

Licenses in the public domain gives the user all the available rights. Example of public domain licenses: Creative Common Licence (CCO)

Permissive

Licenses in this domain usually give you the following rights:

  • Right to Use for Personal Purpose
  • Right to Copy
  • Right to Publish
  • Right to Distribute
  • Right to Modify
  • Right to Sell
  • Right to Sublicense

The licenses here are similar to the ones in the public domain with the clause that all derivates from the software (excluding binary linking) for distribution must have the same license as the parent. Example of permissive licenses: MIT

Copyleft

License in this domain usually give you the following rights:

  • Right to Use for Personal Purpose
  • Right to Copy
  • Right to Publish
  • Right to Distribute
  • Right to Modify

The licenses here enforces all derivates including binary linked software to be redistributed under the same license as the parent. Example of copyleft licenses: GNU GPL

Non Commercial

License in this domain usually give you the following rights:

  • Right to Use for Personal Purpose
  • Right to Copy
  • Right to Publish
  • Right to Distribute
  • Right to Modify

Very similar to the Copyleft licences explicitly stating the software or its modification cannot be used for commercial purposes. Example of Non commercial licenses: Aladdin Free Public License

Proprietary

This is the original copyright license giving the owner exclusive rights to own the software and sell the license to others. This is useful for softwares that cannot be made hidden from the public, an example is the source code of a webpage that can be easily inspected in a browser.

Other Special License Types:

GNU Lesser General Public License

This license is in between the Permissive and the Copyleft type. It is a permissive license if it is linked unmodified in your software as a compiled binary otherwise acts as a copyleft license if it is modified or some part of it used in your software.

Trade Secret

Similar to the proprietary license but fully made private and internal.

REFERENCES

DataStructures Series #12 – Heap Datastructure

Note: I used a large part of this article – https://guides.codepath.com/compsci/Heaps#removal

The heap is a special tree-based datastructure and an implementation of the Priority Queue Abstract Data Type.

There are two types of heaps:

  • Max Heap
  • Min Heap

Max Heap

The max heap has the following property: For every node x with a parent node y, the value of y must always be lesser or equal to the value of x.

Min Heap

The min heap has the following property: For every node x with a parent node y, the value of y must always be lower or equal to the value of the value of x.

Heaps | CodePath Android Cliffnotes
Image source: https://guides.codepath.com/

Heap Operations

  • Insert(element)
  • Remove()

Insert – Inserts an element into the tree and readjusts the tree to maintain the heap property.

Remove – Removes the root element and readjusts the tree to maintain the heap property.

Implementation

Insert(data)

When a new element is inserted into a heap, it is added in the next empty spot in the heap, in the right most position in the last level of the heap, in order to maintain the full shape of the heap. However, this new item may violate the other key property of the heap, its ordering.

In a min heap, if the parent of the new element is greater than it, it gets swapped with the parent. This element keeps getting bubbled up in the tree until it either reaches the root of the heap or it has been placed in the right order. The check to ensure that the node is in the proper position is that the parent node is greater than the new node.

The same process applies to max heaps as well

Image source: https://guides.codepath.com/

Remove()

When removing from a heap, the root node is always removed. Then, the last element, the right most node in the last level of the heap, is removed and set as the root. This removal process retains the heap shape, but this new ordering may violate the proper ordering of the heap.

In a min heap, if either one of the new element’s children are less than their parent, the new element is swapped with the smaller of the two children. This element keeps getting bubbled down in the tree until it either reaches the last level of the heap or it has been placed in the right position. The same process applies to max heaps as well, but the ordering is such that the children are both greater than the current node.

Image source: https://guides.codepath.com/

The heap datastructure can also be represented easily with an array and manipulated as follows:

  • Parent: (current index – 1) // 2 (round down)
  • Left child: (current index * 2) + 1
  • Right child: (current index * 2) + 2

This way, new elements are always inserted at the end of the array, then the readjusts itself to maintain the heap property.

Inserting 0 will be:

1 – 3 – 2 – 4 – 6 – 5 – 0

Then readjustments takes place as follows:

  1. Start from the last element
  2. Swap element with parent (currentIndex – 1) if parent is greater than element
  3. Repeat step 2 until it is false

PsuedoCode Implementation:

// zero indexed array
array = [1, 3, 2, 4, 6, 5, 0];

 currElem = 0;
 parentElem = 2;
 currElemIndex = 6;
 parentElemIndex = 2;

 while (parentElem > currElem) {
   tmp = currElem;
   array[currElemIndex] = parentElem;
   array[parentElemIndex] = tmp;
   currElemIndex = parentElemIndex;
   parentElemIndex = round_down((currElemIndex - 1) / 2);
   parentElem =  array[parentElemIndex];
 }

After readjustment, the new array becomes:

0 – 3 – 1 – 2 – 4 – 6 – 5 – 2

REFERENCES

DataStructures Series #11 – Priority Queue ADT

The Priority Queue ADT

Priority Queue
Image Source: https://www.programiz.com/

The Priority Queue is an abstract data type similar to the Queue data type in which each element additionally has a priority associated with it. In a priority queue, an element with high priority is served before an element with low priority.

In some implementations, if two elements have the same priority, they are served according to the order in which they were enqueued, while in other implementations, ordering of the elements with the same priority is undefined.

Priority Queue Operations:

  • Enqueue (data, priority)
  • Dequeue ()

Enqueue (data, priority) — This will insert element with its priority into the priority queue.

Dequeue ( ) — This will return the element with the highest priority from the priority queue.

Implementation

A naive implementation is to keep all elements with their priorities in an unsorted list and go through the list to look for the element with the highest priority whenever the highest priority element is requested.

In this case, Enqueue operation will be done in constant time while the Dequeue will be done in linear time.

The usual implementation is to use the heap datastructure to improve performance. The heap uses O(log n) for inserts/removals and O(n) to build the priority queue initially from a list of n elements.

Real life Applications

  • Operating System Task Scheduler — Some tasks are more important than others to the operating systems and the priority queue is best for this.

REFERENCES:

HTTPs Communication

How to Prepare for Google's HTTPS Update in October 2017 | Hallam
Image source: https://www.hallaminternet.com/

HTTPs (Hypertext Transfer Protocol Secure) is an extension of the HTTP, it is used to secure communication over a computer network. In HTTPs, the communication protocol is encrypted using TLS (Transport Layer Security), or, formerly, its predecessor, SSL (Secure Sockets Layer).

HTTPs uses asymmetric cryptography to establish connection between the client and server and then uses symmetric encryption for transmission of actual data between server and client.

Asymmetric encryption involves having a key pair (usually private/public key pair) with the rule that one of the pairs can encrypt the data and only someone with the other pair can decrypt it to make sense of the data while Symmetric encryption involves using one key to encrypt and decrypt data.

Communication steps using HTTPS

  • Client checks the URI for the scheme, if it sees HTTPs, it makes a request to the host for it its certificate. The certificate contains the information of the host, host’s public key, issuer (Certificate Authority) and issuer’s signature.
  • Server returns the signed certificate issued by a Certificate authority. The certificate authority usually signs the certificate with its private key. The signing process involves encrypting the certificate data with its private key and generating a hash in return. This hash is also included in the certificate.
  • Clients are usually built with a list of public keys owned by known trusted Certificate Authorities.
  • Client checks the issuer on the certificate and checks its list of known certificate authorities for the public key. Decrypts the hash on the certificate and confirms the certificate is truly from the certificate authority.
  • Client now trusts the host and generates a new key, encrypts the key with the server’s public key and sends to the server.
  • Server receives this encrypted key and decrypts it with its private key.
  • At this point, a successful connection has been established between the server and client. And only these 2 machines know this key that can now be used to encrypt and decrypt data.

References and More Resources:

APIs – OpenAPI Specification

OAS building blocks
Image Source: https://dev.to/mikeralphson

The OpenAPI Specification previously known as Swagger specification is a community-driven open specification within the OpenAPI Initiative, a Linux Foundation Collaborative Project.

The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for APIs which helps to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic.

Use cases for machine-readable API definition documents include, but are not limited to: interactive documentation; code generation for documentation; and automation of test cases.

OpenAPI specification documents describe an API’s services and are represented in either YAML or JSON formats. These documents may either be produced and served statically or be generated dynamically from an application.

The version of the OpenAPI specification currently as at the time of writing this article is version 3.

There are two well-known processes for developing APIs with OAS:

  • Contract First Approach
    • Define the contract
    • Use an OAI Tool to generate a code skeleton for your APIs, OAI supports many programming languages.
  • Code first / Contract Last Approach
    • Write the code for the APIs in your programming language with annotations
    • Use an OAI Tool to generate the contract

The Contract First Approach can be very useful for collaboration, for example, in a scenario where you are developing APIs for a mobile app developer, the contract is defined first, a mock server and a documentation can be generated from the contract with OAI tools, and then both the API developer and the mobile app developer can work simultaneously on the API actual implementation and API integration using the mock server and documentation respectively.

You can find a list of other OAI tools here

References and More Resources:

Algorithms – Time Complexity

Originally posted on my medium page: https://medium.com/@otarutunde

Understanding Big-O Notation With JavaScript - Better Programming ...
Source: https://medium.com/better-programming/understanding-big-o-notation-c3245b8112dc

Time complexity is probably the most used term in the world of algorithms and data-structures. This article will introduce you gently into understanding time complexity also known as the Big Oh notation

Understanding the Basics

Every code you write in a programming language is always transformed to binary instructions on the computer. A CPU (Central Processing Unit) in a computer executes these instructions.

The CPU includes:

  • ALU (Arithmetic Logic Unit) : performs arithmetic and logic operations
  • Process Registers : that supplies operands to the ALU and store the results from the ALU operations.
  • Control Unit : coordinates all actions between components in the CPU.

To make things simpler, let us abstract the operations a computer can perform to be:

  • Assignment operation
  • Arithmetic operation
  • Comparator Operation

Using this code snippet as an example below:

for (i = 0; i =< n; i++) {
   m += 5;
}

Using the operations listed above, the following are the steps the computer will perform below:

  • Assign 0 to i
  • Compare i to n
  • Continue steps below if i =< n,
  • Add 5 to m
  • Increment i by 1

— it is clearly seen that this process continues until i > n

Now from the above, if n = 0, the number of instructions executed by the computer will be 5.

if n = 1, the computer will execute 5 * 2 = 10 instructions.

if n = 2, the computer would execute 5 * 3 = 15 instructions.

We can create a function for the number of instructions to be executed for n in the program above to be: f(n) = 5(n+1)

Big Oh Notation

The Big Oh tells how a function behaves as the size of the input approaches infinity (as the input grows very large).

In our case above, the input is n , if we assume n to be (100,000,000), the computer will perform 5(100,000,000 + 1) operations. We can afford to remove smaller terms from the equation as n grows very large because they become insignificant. We remove the constants 5 and 1 to make f(n) = n.

The function f(n) = n, is a linear function and thus can confidently say the time complexity for the operation above is in linear time O(n).

The function f(n) = n, is a linear function and can clearly see that this algorithm executes in linear time as n grows, this is also called O(n) in the big Oh notation. There are other Big Oh Notations derived from the same process above:

f(n) = n² — quadratic time O(n²)

f(n) = log n— logarithmic time O(log n)

and so on….

More Resources