Monthly Archives: August 2022

Array Merge Sort Code in JavaScript and its Big-O

Array Merge Sort Code in JavaScript function mergeSort(arr) { if (arr.length === 1) { return arr; } let mid = Math.floor(arr.length / 2); let leftArr = arr.slice(0,mid); let rightArr = arr.slice(mid); return merge(mergeSort(leftArr), mergeSort(rightArr)); } function megre (leftArr, rightArr) { let output = []; while (leftArr.length && rightArr.length) { if (leftArr[0] < rightArr[0]) { output.push(leftArr.shift()); [...]

Array Selection Sort Code in JavaScript and its Big-O

Array Selection Sort Code in JavaScript function selectionSort(arr) { for (i =0; i<arr.length; i++) { indexSelection = i; for (j = i+1; j< arr.length; j++) { if (arr[j] < arr[indexSelection]) { indexSelection = j; } } //end for j if (indexSelection !== i) { let temp = arr[indexSelection]; arr[indexSelection] = arr[i]; arr[i] = temp; } […]

Install Keycloak in ubuntu behind nginx reverse proxy using postgresql database

Below we show how to install Keycloak in ubuntu behind Nginx proxy and also use PostgreSQL as its database. //download keycloadk and unzip wget https://github.com/keycloak/keycloak/releases/download/19.0.1/keycloak-legacy-19.0.1.zip //create admin user cd keycloak-legacy-19.0.1/ ./bin/add-user-keycloak.sh -r master -u admin -p mypassword //start keycloak ./bin/standalone.sh //enable proxy for keycloak by adding proxy-address-forwarding=”true” vim standalone/configuration/standalone.xml <http-listener name=”default” socket-binding=”http” redirect-socket=”https” enable-http2=”true” proxy-address-forwarding=”true”/> […]

Linked List Data Structure Code in JavaScript

In the examples below we show how to implement Linked List Data Structure in Javascript class Node { constructor(data, next=null) this.data = data; this.next = next; } } class LinkedList { constructor(data) { this.head = null; } /////////// insertStart(data) { this.head = new Node(data, this.head); } /////////// size() { let cnt = 0; let node […]

Tree code in Javascript and Breadth-First-Search and Depth-First-Search

In the examples below we show how to implement Tree in Javascript including Breadth-First-Search and Depth-First-Search class Node { constructor(data) this.data = data; this.children = []; } addData(data) { this.children.push(new Node(data)); } removeData(data) { this.children = this.childern.filter((item)=> { return item.data !== data; }); } } class Tree { constructor(data) { this.root = data; } breadth_first_search(fn) […]