How to map integers to doubles using Java stream

import java.util.Arrays;
import java.util.List;

public class HelloWorld{

     public static void main(String []args){
        List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        List doubles =;
        List doubleSquares =>i.doubleValue() * 2).boxed().collect(Collectors.toList());

How to add a new PostgreSQL version to Laragon

To achieve this, follow the steps listed below

  1. Download the zip archive of the postgresql version you wish to install from (
  2. Save it and extract it to your laragon path > bin > postgresql folder, usually this will be (c:\laragon\bin\postgresql\).laragon-folder
  3. This is the most important part, backup your postgresql data folder and then rename the folder, so that there is no folder (c:\laragon\data\postgresql).
  4. Initiate the database cluster to the location (C:\laragon\data\postgresql) using the command below
       initdb -D c:\laragon\data\postgresql --encoding=UTF8


  5. Once the operation in step (4) succeeds, then run laragon and select the new version of laragon and start it.laragon-select-new-version

Quick snippet – Selecting only certain columns for a model in laravel

With a model named (Person) that maps to a table named (persons) with a structure defined below

CREATE TABLE `persons` (
  `first_name` VARCHAR(255) NOT NULL,
  `last_name` VARCHAR(255)  NOT NULL,
  `email` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `persons` (`email`)

Then, Consider the eloquent statement given below

$result = Person::find(1);

this is equivalent to,


The above can be wasteful if all you require is just a few columns such as the firstname and lastname, to fix this, we use the eloquent statement below

$result = Person::find(1, ['first_name', 'last_name']);

This is equivalent to,

SELECT first_name, last_name FROM persons

Hope, you have been able to learn something new today.

How to configure the selenium standalone server to use chrome driver

Selenium is a browser automation tool that is incredibly useful for testing, especially when you are practicing Behaviour Driven Development (BDD) using tool like behat.

The selenium server runs using the firefox (gecko driver) by default, sometimes you wish to use a different browser, making this switch is very simple and in this tutorial, we will use the chrome browser. Follow the steps listed below

  1. Downoad the selenium driver for the web browser of your choice, in this case (chrome driver).
  2. place the chromedriver file in the same folder with you selenium standalone server jar file.
  3. If on linux or mac, you need to make sure the file is executable, so run the command chmod 777 or chmod u+x chromedriver
  4. Run the selenium standard alone server with the chrome driver using the command below
# running the selenium server with chrome driver
java -jar selenium-server-standalone-3.11.0.jar -D"chromedriver.exe"


Introduction to Logical Shift And Its Use Cases

If like me, you have a degree in computer science, you must have encountered logical shifts during the course of your academic studies, if not, if you have learnt pretty much any programming language, you would have encountered them. The issue is that most people treat them as something to be aware of but not really understood. If you give me a couple of minutes, I hope to help simplify it to you.

What is logical shift

Logical shift is a type of bitwise operation that shifts/moves the bits in its operands in a particular direction. In simple terms, if you logically shift X by Y, it means that the operation will move the bits in X by Y positions. Still sounds geeky, let us break it down together.

There are two types of logical shifts, namely

  1. Right Shift (denoted by >> )
  2. Left Shift (denoted by << )

If you consider the definition above, Right shift means that the bits in (X) would be shifted to the right by Y places, also Left shift means that the bits in (X) would be shifted to the left by Y places.

Example of Left Shift

let X = 4 and Y = 2, lets find X << Y

Convert X  to binary, then you have

X = 100  (i.e. the binary representation of 4 is 0000 0100 )

Note: you should use the 8 digits representation

If you find the binary calculation confusing, please read up about it here.

Now, to calculate (X << Y), i.e we move the bits in X  to the left by 2 places.

  1. before move X = 0000 0100
  2. after left move (1) , X = 0000 1000
  3. after leftmove (2) , X = 0001 0000

Now we convert (0001 0000) back to decimal and we have 2.

Hence, 4 << 2  == 16.

Example of Right Shift

let X = 8 and Y = 2, lets find X >> Y

Convert X  to binary, then you have

X = 1000  (i.e. the binary representation of 8 is 0000 1000).

Now, to calculate (X >> Y), i.e we move the bits in X to the right by 2 places.

  1. before move X = 0000 1000
  2. after right move (1) , X = 0000 0100
  3. after right move (2) , X = 0000 0010

Note: since the first 4 digits in the binary value of X is (0) and we are shifting to the right, we could have discared it and just used (1000).

Now we convert (0010) back to decimal and we have 2.

Hence, 8  >> 2  is equal to 2.

Use cases of logical shifts (both left and right).

Left shift (<<) is used to multiply a value by any power of 2 and Right bit shift (>>) is used to divide by any power of two. consider the table below

Cheatsheet or Ways of calulating the logical shifts faster

The left logical shift (<<) is the same as

Left Bit Shift
# Operation X Y Resolution Result
1 X << Y 8 2 8 * pow(2,2) 32
2 X << Y 2 4 2 * pow(2,4) 32
3 X << Y 3 2 3 * pow(2,2) 12


Right Bit Shift
# Operation X Y Resolution Result
1 X >> Y 64 4 64 / pow(2,4) 4
2 X >> Y 4 2 4 / pow(2,2) 1
3 X >> Y 8 2 8 / pow(2,2) 2

So, that is all. Hope i have made the use of logical shift alot clearer to you.


Did you know? You can fetch multiple Eloquent records with one command

The Eloquent class in Laravel has a method called find, this you must be aware of , you can use this to find an Eloquent Model record using the primary key. This is used as follows

// Retrieve a model record by its primary key...
$car = App\Car::find(1);

Now, what if we want to find all cars with primary key in the list [1,2,3]? You can suppluy an array of primary keys to the find method or use the findMany method. Consider the code snippet below

$cars = App\Car::find([1, 2, 3]);
$cars = App\Cr::findMany([1, 2, 3]);


Note: If you supply an array of keys to the find method, it calls findMany internally. Whichever you decide to use between the two methods described above, they both return an instance of  \Illuminate\Database\Eloquent\Collection.




Highlighting Active Bootstrap Menu Items (Nav – Item) Based On Route

In this post, I will show you a niifty little trick, one that is always required whenever you are working on some sort of web project with multiple routes.

You occasionally need to set the nav-item that inidicates the current route to be active (i.e. make it coloured ), to achieve this using laravel, consider the code snippet below

<ul class="navbar-nav">
<li class="nav-item {{ is_active('') }}">
    <a class="nav-link" href="{{ route('') }}">Route One</a></li>
<li class="nav-item {{ is_active('') }}">
    <a class="nav-link" href="{{ route('') }}">Route Two</a></li>
<li class="nav-item {{ is_active('') }}">
    <a class="nav-link" href="{{ route('') }}">Route Three</a></li>

As you can see from the snippet displayed above, for every <li> element, the is_active function call has been added to class attribute , this function takes the name of a route as its argument and it returns a class name (active) if the current route name matches that which was supplied. Consider the snippet below to see the logic in the function stored in a file called helpers.php in a new folder called custom (note:  you can store your helper file anywhere you deem logical, I have just chosen custom/helpers.php).

if (!function_exists('is_active')) {
     * @param string $routeName
     * @param string $activeClassName
     * @return string
    function is_active(string $routeName, string $activeClassName = 'active')
        $result = '';
        if (request()->route()->getName() === $routeName) {
            $result = $activeClassName;

        return $result;

How do you make your function available globally?

To make the function in the [core/helpers.php] file available globally, you need to autoload it using the files attribute of the composer.json file as follow.

"autoload": {
    "classmap": [
    "psr-4": {
      "App\\": "app/"
    "files": [

Hope you have found this helpful..