├── .DS_Store ├── .vscode └── settings.json ├── Algo ├── Common │ ├── Fibonacci │ │ ├── Fibonacci.java │ │ └── fibonacci.py │ ├── MinMax │ │ ├── MinMax.java │ │ └── minMax.py │ ├── MissingNumber │ │ ├── MissingNumber.java │ │ └── missingNumber.py │ ├── PairsOfSum │ │ ├── PairOfSum.java │ │ └── pairsOfSum.py │ ├── Palindrome │ │ ├── Palindrome.java │ │ └── palindrome.py │ ├── ReverseArray │ │ ├── ReverseArray.java │ │ └── reverseArray.py │ ├── ReverseOddArray │ │ ├── ReverseOddArray.java │ │ └── reverseOddArray.py │ ├── ReverseString │ │ ├── ReverseString.java │ │ └── reverseString.py │ └── SecondMax │ │ ├── SecondMax.java │ │ └── secondMax.py ├── LinkedList │ ├── reverse │ │ └── reverse.py │ └── reverseWithMiddleElement │ │ └── reverseMiddleElement.py ├── Search │ ├── Binary │ │ └── binary.py │ └── Linear │ │ └── linear.py ├── Sort │ ├── Bubble │ │ └── bubble.py │ ├── Insertion │ │ └── insertion.py │ ├── Merge │ │ └── merge.py │ ├── Quick │ │ └── quick.py │ └── Selection │ │ └── selection.py └── allAlgo.py ├── Database ├── Presentation │ └── Presentation - DB Kuppi Full.pptx ├── References │ ├── Advantages of database view.pdf │ ├── IN 1400 Tutorial EER.pdf │ ├── Indexing and Hashing.pdf │ ├── Views, Stored procedures.pptx │ ├── Week 1- Introduction.pdf │ ├── Week 10 - SQL 2.pdf │ ├── Week 10- Relational Algebra.pdf │ ├── Week 11 - Indexing.pdf │ ├── Week 2- ER (part1) V2.pdf │ ├── Week 3-4- ER (Part 2) V2.pdf │ ├── Week 5 - EER.pdf │ ├── Week 5 - ERD _General Concerns.pdf │ ├── Week 6 - Relational Model.pdf │ ├── Week 7- ER to Relational Mapping.pdf │ ├── Week 9 - Normalization.pdf │ └── Week 9 - SQL 1.pdf └── Scripts │ ├── MSSQLVersion │ ├── Examples(MSSQL).sql │ └── Script(MSSQL).sql │ └── MySqlVersion │ ├── Examples(MySql).sql │ └── Script(MySql).sql ├── JavaScript ├── AsyncJS.js ├── Hoisting.js ├── JIT.js └── VariablesAndScope.js ├── README.md └── ReactJs ├── React-Redux-Class-Component └── react-redux.md ├── React-Redux-Hooks └── react-redux-hooks.md ├── potential-Interview-Questions.md └── react-kuppi ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.css ├── App.js ├── App.test.js ├── Counter.js ├── Fragments.js ├── List.js ├── ObjectState.js ├── State.js ├── StateHandle.js ├── index.css ├── index.js ├── logo.svg ├── reportWebVitals.js └── setupTests.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/.DS_Store -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.pythonPath": "/usr/bin/python3" 3 | } -------------------------------------------------------------------------------- /Algo/Common/Fibonacci/Fibonacci.java: -------------------------------------------------------------------------------- 1 | class Fibonacci{ 2 | public static void main(String args[]){ 3 | System.out.println(fibonacci(3)); 4 | } 5 | 6 | public static int fibonacci(int number) { 7 | if (number == 0){ 8 | return 0; 9 | } else if (number == 1 || number == 2) { 10 | return 1; 11 | } else { 12 | return fibonacci(number-1) + fibonacci(number-2); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Algo/Common/Fibonacci/fibonacci.py: -------------------------------------------------------------------------------- 1 | # recursive 2 | def fib(n): 3 | if ( n == 0): 4 | return 0 5 | elif( n == 1 or n == 2 ): 6 | return 1 7 | else: 8 | return fib(n-1) + fib(n-2) 9 | 10 | print(fib(9)) -------------------------------------------------------------------------------- /Algo/Common/MinMax/MinMax.java: -------------------------------------------------------------------------------- 1 | class MinMax{ 2 | 3 | public static void main(String args[]){ 4 | int[] arr = new int[] {3,7,2,8,3}; 5 | minMax(arr); 6 | } 7 | 8 | public static void minMax(int[] arr) { 9 | int min = arr[0]; 10 | int max = arr[0]; 11 | for(int value: arr) { 12 | if (value > max) { 13 | max = value; 14 | } 15 | if (value < min) { 16 | min = value; 17 | } 18 | } 19 | 20 | System.out.println("Min is " + min); 21 | System.out.println("Max is " + max); 22 | } 23 | } -------------------------------------------------------------------------------- /Algo/Common/MinMax/minMax.py: -------------------------------------------------------------------------------- 1 | def minMax(arr): 2 | min = arr[0] 3 | max = arr[0] 4 | for i in arr: 5 | if( i > max): 6 | max = i 7 | if( i < min): 8 | min = i 9 | return min, max 10 | 11 | arr = [1 , 3 , 7 , 8 , 12 , 13 , 17 , 20 , 24] 12 | print(minMax(arr)) -------------------------------------------------------------------------------- /Algo/Common/MissingNumber/MissingNumber.java: -------------------------------------------------------------------------------- 1 | class MissingNumber{ 2 | 3 | public static void main(String args[]){ 4 | int[] arr = new int[] {1,3,4,5,6}; 5 | System.out.println(missingNumber(arr)); 6 | } 7 | 8 | public static int missingNumber(int[] arr) { 9 | int arraySum = 0; 10 | int expectedSum = 0; 11 | for (int i = 1; i <= arr.length; i++) { 12 | expectedSum += i; 13 | arraySum += arr[i - 1]; 14 | } 15 | return expectedSum - arraySum; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Algo/Common/MissingNumber/missingNumber.py: -------------------------------------------------------------------------------- 1 | def missingNumber(arr): 2 | n = len(arr) + 1 3 | sumOfarray = sum(arr) 4 | sumOf_N_numbers = (n * (n + 1))//2 5 | missingOne = sumOf_N_numbers - sumOfarray 6 | return missingOne 7 | 8 | arr = [1,2,3,5,6] 9 | print(missingNumber(arr)) -------------------------------------------------------------------------------- /Algo/Common/PairsOfSum/PairOfSum.java: -------------------------------------------------------------------------------- 1 | public class PairOfSums { 2 | public static void main(String[] args){ 3 | int[] arr = {1,1,2,3,4,5,6,7,8,8,9,10}; 4 | int sum = 15; 5 | 6 | int i = 0; 7 | int j = arr.length - 1; 8 | 9 | int total = 0; 10 | 11 | while(i < j){ 12 | total = arr[i] + arr[j]; 13 | 14 | if(total == sum){ 15 | System.out.println(arr[i] + " , " + arr[j]); 16 | i++; 17 | j--; 18 | }else if(total < sum){ 19 | i++; 20 | }else{ 21 | j--; 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Algo/Common/PairsOfSum/pairsOfSum.py: -------------------------------------------------------------------------------- 1 | 2 | arr = [1,1,2,3,4,5,6,7,8,8,9,10] 3 | sum = 15 4 | 5 | i = 0 6 | j = len(arr) - 1 7 | total = 0 8 | 9 | while(i < j): 10 | total = arr[i] + arr[j] 11 | if(total == sum): 12 | print(arr[i],arr[j]) 13 | i += 1 14 | j -+ 1 15 | elif(total < sum): 16 | i += 1 17 | else: 18 | j -= 1 19 | -------------------------------------------------------------------------------- /Algo/Common/Palindrome/Palindrome.java: -------------------------------------------------------------------------------- 1 | class Palindrome{ 2 | 3 | public static void main(String args[]){ 4 | String word = "abcba"; 5 | 6 | if (isPalindrome(word)) { 7 | System.out.println("Palindrom"); 8 | } else { 9 | System.out.println("Not Palindrom"); 10 | } 11 | } 12 | 13 | public static boolean isPalindrome(String word) { 14 | int wordLength = word.length(); 15 | char[] letters = word.toCharArray(); 16 | 17 | for (int i = 0; i < wordLength/2; i++) { 18 | if (letters[i] != letters[wordLength-1-i]) { 19 | return false; 20 | } 21 | } 22 | return true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Algo/Common/Palindrome/palindrome.py: -------------------------------------------------------------------------------- 1 | def palindrome(str): 2 | for i in range(len(str)//2): 3 | if not str[i] == str[len(str)-1 - i]: 4 | return False 5 | return True 6 | 7 | print(palindrome('abcba')) -------------------------------------------------------------------------------- /Algo/Common/ReverseArray/ReverseArray.java: -------------------------------------------------------------------------------- 1 | public class ReverseArray{ 2 | public static void main(String[] args){ 3 | 4 | int[] arr = {1,4,6,8,4,3,2,9}; 5 | 6 | /* 7 | i and j are the pointers and i is pointing to the start of the array and j is pointing the end of the array 8 | */ 9 | int i = 0; 10 | int j = arr.length - 1; 11 | 12 | // swap elemets of the array using two pointer mechanism 13 | int temp = 0; 14 | while(i < j){ 15 | temp = arr[i]; 16 | arr[i] = arr[j]; 17 | arr[j] = temp; 18 | i++; 19 | j--; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Algo/Common/ReverseArray/reverseArray.py: -------------------------------------------------------------------------------- 1 | arr = [1,4,6,8,4,3,2,9] 2 | 3 | # i and j are the pointers and i is pointing to the start of the array and j is pointing the end of the array 4 | i = 0 5 | j = len(arr) - 1 6 | 7 | # in python you dont need temp variable to do the swap ( python is awsome ^.^) 8 | while(i < j): 9 | arr[i] , arr[j] = arr[j] , arr[i] 10 | i += 1 11 | j -= 1 12 | 13 | print(arr) 14 | 15 | # from for loop 16 | arr2 = [1,4,6,8,4,3,2,9] 17 | n = len(arr2) - 1 18 | for i in range(len(arr2)//2): 19 | arr2[i] , arr2[n - i] = arr2[n - i ] , arr2[i] 20 | 21 | print(arr2) 22 | -------------------------------------------------------------------------------- /Algo/Common/ReverseOddArray/ReverseOddArray.java: -------------------------------------------------------------------------------- 1 | public class ReverseOddArray { 2 | public static void main(String[] args){ 3 | int[] arr = {1,4,6,8,4,3,2,9}; 4 | 5 | int i = 0; 6 | int j = arr.length - 1; 7 | 8 | int temp = 0; 9 | while(i < j){ 10 | if(arr[i] % 2 == 1 && arr[j] % 2 == 1){ 11 | temp = arr[i]; 12 | arr[i] = arr[j]; 13 | arr[j] = temp; 14 | i++; 15 | j--; 16 | }else if(arr[i] % 2 == 0){ 17 | i++; 18 | }else if(arr[j] % 2 == 0){ 19 | j--; 20 | }else{ 21 | i++; 22 | j--; 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Algo/Common/ReverseOddArray/reverseOddArray.py: -------------------------------------------------------------------------------- 1 | 2 | arr = [1,4,6,8,4,3,2,9] 3 | 4 | i = 0 5 | j = len(arr) - 1 6 | 7 | while(i < j): 8 | if(arr[i] % 2 == 1 and arr[j] % 2 == 1): 9 | arr[i] , arr[j] = arr[j] , arr[i] 10 | i += 1 11 | j -= 1 12 | elif(arr[i] % 2 == 0): 13 | i += 1 14 | elif(arr[j] % 2 == 0): 15 | j -= 1 16 | else: 17 | i += 1 18 | j -= 1 19 | 20 | print(arr) -------------------------------------------------------------------------------- /Algo/Common/ReverseString/ReverseString.java: -------------------------------------------------------------------------------- 1 | class ReverseString{ 2 | 3 | public static void main(String args[]){ 4 | String input = "hello"; 5 | 6 | byte[] strAsByteArray = input.getBytes(); 7 | 8 | byte[] result = new byte[strAsByteArray.length]; 9 | 10 | for (int i = 0; i < strAsByteArray.length; i++) 11 | result[i] = strAsByteArray[strAsByteArray.length - i - 1]; 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /Algo/Common/ReverseString/reverseString.py: -------------------------------------------------------------------------------- 1 | def revStr(str): 2 | newStr = '' 3 | for i in range(len(str)): 4 | newStr += str[len(str) - 1 - i] 5 | return newStr 6 | 7 | print(revStr('hello world!')) -------------------------------------------------------------------------------- /Algo/Common/SecondMax/SecondMax.java: -------------------------------------------------------------------------------- 1 | class SecondMax{ 2 | 3 | public static void main(String args[]){ 4 | int[] arr = new int[] {19,4,17,16,17,30,13,8,30}; 5 | minMax(arr); 6 | } 7 | 8 | public static void minMax(int[] numbers) { 9 | int secondMax = numbers[0]; 10 | int max = numbers[0]; 11 | for (int value: numbers) { 12 | if (value > max) { 13 | secondMax = max; 14 | max = value; 15 | } 16 | } 17 | System.out.println("Max is " + max); 18 | System.out.println("Second Max is " + secondMax); 19 | } 20 | } -------------------------------------------------------------------------------- /Algo/Common/SecondMax/secondMax.py: -------------------------------------------------------------------------------- 1 | def secondMax(arr): 2 | max1,max2 = 0 , 0 3 | if( arr[0] > arr[1]): 4 | max1 = arr[0] 5 | max2 = arr[1] 6 | else: 7 | max1 = arr[1] 8 | max2 = arr[0] 9 | for i in arr: 10 | if(i > max1): 11 | max2 = max1 12 | max1 = i 13 | elif( i > max2 and max1 != i): 14 | max2 = i 15 | return max2 16 | 17 | arr = [ 1 , 3 ,5 , 2 , 10 , 9 , 22 , 15 , 8] 18 | 19 | print(secondMax(arr)) -------------------------------------------------------------------------------- /Algo/LinkedList/reverse/reverse.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | class LinkedListNode: 8 | def __init__(self, node_data): 9 | self.data = node_data 10 | self.next = None 11 | 12 | class LinkedList: 13 | def __init__(self): 14 | self.head = None 15 | self.tail = None 16 | 17 | def insert_node(self, node_data): 18 | node = LinkedListNode(node_data) 19 | 20 | if not self.head: 21 | self.head = node 22 | else: 23 | self.tail.next = node 24 | 25 | 26 | self.tail = node 27 | 28 | def print_linked_list(node): 29 | while node: 30 | print(str(node.data)) 31 | node = node.next 32 | 33 | # 1 - 2 - 3 - 4 - 5 - None 34 | # None - 5 - 4 - 3 - 2 - 1 35 | def reverse(head): 36 | current = head 37 | prev = None 38 | while current is not None: 39 | nextNode = current.next 40 | current.next = prev 41 | prev = current 42 | current = nextNode 43 | current = prev 44 | return current 45 | 46 | 47 | if __name__ == '__main__': 48 | 49 | llist = LinkedList() 50 | arr = [1, 2, 3, 4, 5] 51 | for i in arr: 52 | llist_item = i 53 | llist.insert_node(llist_item) 54 | 55 | llist1 = reverse(llist.head) 56 | 57 | print_linked_list(llist1) -------------------------------------------------------------------------------- /Algo/LinkedList/reverseWithMiddleElement/reverseMiddleElement.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | class LinkedListNode: 8 | def __init__(self, node_data): 9 | self.data = node_data 10 | self.next = None 11 | 12 | class LinkedList: 13 | def __init__(self): 14 | self.head = None 15 | self.tail = None 16 | 17 | def insert_node(self, node_data): 18 | node = LinkedListNode(node_data) 19 | 20 | if not self.head: 21 | self.head = node 22 | else: 23 | self.tail.next = node 24 | 25 | 26 | self.tail = node 27 | 28 | def print_linked_list(node): 29 | while node: 30 | print(str(node.data)) 31 | node = node.next 32 | 33 | # 1 - 2 - 3 - 4 - 5 - None 34 | # None - 5 - 4 - 3 - 2 - 1 35 | def reverse(head): 36 | current = head 37 | Next = current.next 38 | prev = None 39 | while True: 40 | current.next = prev 41 | if Next == None: 42 | break 43 | prev = current 44 | current = Next 45 | Next = Next.next 46 | head = current 47 | return head 48 | 49 | 50 | if __name__ == '__main__': 51 | 52 | llist = LinkedList() 53 | arr = [1, 2, 3, 4, 5] 54 | for i in arr: 55 | llist_item = i 56 | llist.insert_node(llist_item) 57 | 58 | llist1 = reverse(llist.head) 59 | 60 | print_linked_list(llist1) -------------------------------------------------------------------------------- /Algo/Search/Binary/binary.py: -------------------------------------------------------------------------------- 1 | def binary(arr , elem): 2 | m = len(arr) // 2 3 | if( len(arr) == 1 and arr[m] != elem): 4 | return False 5 | elif (arr[m] < elem): 6 | return binary(arr[m:] , elem) 7 | elif (arr[m] > elem): 8 | return binary(arr[:m] , elem) 9 | elif(arr[m] == elem): 10 | return True 11 | 12 | arr = [ 1 , 3 , 7 , 8 , 12 , 13 , 17 , 20 , 24] 13 | 14 | print(binary(arr, 5)) 15 | print(binary(arr, 8)) -------------------------------------------------------------------------------- /Algo/Search/Linear/linear.py: -------------------------------------------------------------------------------- 1 | def search(arr , k ): 2 | for i in arr: 3 | if( i == k ): 4 | return True 5 | return False 6 | 7 | 8 | arr = [ 1 , 3 , 7 , 8 , 12 , 13 , 17 , 20 , 24] 9 | 10 | print(search(arr, 5)) 11 | print(search(arr, 8)) -------------------------------------------------------------------------------- /Algo/Sort/Bubble/bubble.py: -------------------------------------------------------------------------------- 1 | arr = [ 0, 1, 3 , 2 , 6 , 9 , 4] 2 | 3 | def buble(arr): 4 | for i in range(len(arr) - 1): 5 | for j in range(len(arr) - 1 - i): 6 | if(arr[j] > arr[j+1]): 7 | arr[j],arr[j+1] = arr[j+1],arr[j] 8 | return arr 9 | 10 | print(buble(arr)) -------------------------------------------------------------------------------- /Algo/Sort/Insertion/insertion.py: -------------------------------------------------------------------------------- 1 | arr = [ 0, 1, 3 , 2 , 6 , 9 , 4] 2 | 3 | def inser(arr): 4 | for i in range(1, len(arr)): 5 | key = arr[i] 6 | j = i - 1 7 | while j >= 0 and key < arr[j]: 8 | arr[j+1] = arr[j] 9 | j -= 1 10 | arr[j+1] = key 11 | return arr 12 | 13 | print(inser(arr)) -------------------------------------------------------------------------------- /Algo/Sort/Merge/merge.py: -------------------------------------------------------------------------------- 1 | arr = [ 0, 1, 3 , 2 , 6 , 9 , 4] 2 | 3 | def merge(arr , l , m , r): 4 | n1 = m + 1 - l 5 | n2 = r - m 6 | 7 | L = [0] * n1 8 | R = [0] * n2 9 | 10 | for i in range(n1): 11 | L[i] = arr[l + i] 12 | 13 | for j in range(n2): 14 | R[j] = arr[m + j + 1] 15 | 16 | i , j , k = 0 , 0 , l 17 | 18 | while i < n1 and j < n2: 19 | if L[i] <= R[j]: 20 | arr[k] = L[i] 21 | i += 1 22 | else: 23 | arr[k] = R[j] 24 | j+=1 25 | k += 1 26 | 27 | while i < n1: 28 | arr[k] = L[i] 29 | k += 1 30 | i += 1 31 | 32 | while j < n2: 33 | arr[k] = R[j] 34 | j += 1 35 | k += 1 36 | 37 | 38 | def merge_sort(arr , l , r): 39 | if l < r : 40 | m = (l + (r-1)) // 2 41 | merge_sort(arr , l , m ) 42 | merge_sort(arr , m + 1 , r) 43 | merge(arr , l , m , r) 44 | 45 | merge_sort(arr , 0 , len(arr) - 1 ) 46 | 47 | print(arr) -------------------------------------------------------------------------------- /Algo/Sort/Quick/quick.py: -------------------------------------------------------------------------------- 1 | arr = [ 0, 1, 3 , 2 , 6 , 9 , 4] 2 | 3 | def part(arr , l , h): 4 | i = l - 1 5 | pivot = arr[h] 6 | 7 | for j in range(l , h): 8 | if(arr[j] <= pivot): 9 | i+=1 10 | arr[i] , arr[j] = arr[j] , arr[i] 11 | 12 | arr[i+1] , arr[h] = arr[h],arr[i+1] 13 | return (i+1) 14 | 15 | 16 | def quick(arr , l , h): 17 | if len(arr) < 2: 18 | return 19 | if( l < h ): 20 | pi = part(arr , l , h) 21 | quick(arr , l , pi - 1) 22 | quick(arr , pi + 1 , h) 23 | return arr 24 | 25 | print(quick(arr)) 26 | -------------------------------------------------------------------------------- /Algo/Sort/Selection/selection.py: -------------------------------------------------------------------------------- 1 | arr = [ 0, 1, 3 , 2 , 6 , 9 , 4] 2 | 3 | def selection(arr): 4 | for i in range(len(arr)): 5 | min_idx = arr[i] 6 | for j in range(i , len(arr)): 7 | if (arr[i] > arr[j]): 8 | min_idx = j 9 | arr[i], arr[min_idx-1] = arr[min_idx-1],arr[i] 10 | return arr 11 | 12 | print(selection(arr)) -------------------------------------------------------------------------------- /Algo/allAlgo.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | class LinkedListNode: 8 | def __init__(self, node_data): 9 | self.data = node_data 10 | self.next = None 11 | 12 | class LinkedList: 13 | def __init__(self): 14 | self.head = None 15 | self.tail = None 16 | 17 | def insert_node(self, node_data): 18 | node = LinkedListNode(node_data) 19 | 20 | if not self.head: 21 | self.head = node 22 | else: 23 | self.tail.next = node 24 | 25 | 26 | self.tail = node 27 | 28 | def print_linked_list(node): 29 | while node: 30 | print(str(node.data), end = ' -> ') 31 | node = node.next 32 | 33 | 34 | arr = [ 0, 1, 3 , 2 , 6 , 9 , 4] 35 | 36 | 37 | #bubble 38 | def buble(arr): 39 | for i in range(len(arr) - 1): 40 | for j in range(len(arr) - 1 - i): 41 | if(arr[j] > arr[j+1]): 42 | arr[j],arr[j+1] = arr[j+1],arr[j] 43 | return arr 44 | 45 | 46 | #insertion 47 | def inser(arr): 48 | for i in range(1, len(arr)): 49 | key = arr[i] 50 | j = i - 1 51 | while j >= 0 and key < arr[j]: 52 | arr[j+1] = arr[j] 53 | j -= 1 54 | arr[j+1] = key 55 | return arr 56 | 57 | 58 | #selection 59 | def select(arr): 60 | for i in range(len(arr)): 61 | min_idx = arr[i] 62 | for j in range(i , len(arr)): 63 | if (arr[i] > arr[j]): 64 | min_idx = j 65 | arr[i], arr[min_idx-1] = arr[min_idx-1],arr[i] 66 | return arr 67 | 68 | 69 | # mereg / merge two arrays 70 | def merge(arr , l , m , r): 71 | n1 = m + 1 - l 72 | n2 = r - m 73 | 74 | L = [0] * n1 75 | R = [0] * n2 76 | 77 | for i in range(n1): 78 | L[i] = arr[l + i] 79 | 80 | for j in range(n2): 81 | R[j] = arr[m + j + 1] 82 | 83 | i , j , k = 0 , 0 , l 84 | 85 | while i < n1 and j < n2: 86 | if L[i] <= R[j]: 87 | arr[k] = L[i] 88 | i += 1 89 | else: 90 | arr[k] = R[j] 91 | j+=1 92 | k += 1 93 | 94 | while i < n1: 95 | arr[k] = L[i] 96 | k += 1 97 | i += 1 98 | 99 | while j < n2: 100 | arr[k] = R[j] 101 | j += 1 102 | k += 1 103 | 104 | # merge 105 | def merge_sort(arr , l , r): 106 | if l < r : 107 | m = (l + (r-1)) // 2 108 | merge_sort(arr , l , m ) 109 | merge_sort(arr , m + 1 , r) 110 | merge(arr , l , m , r) 111 | #merge_sort(arr , 0 , len(arr) - 1 ) 112 | 113 | 114 | # quick sort partition 115 | def part(arr , l , h): 116 | i = l - 1 117 | pivot = arr[h] 118 | 119 | for j in range(l , h): 120 | if(arr[j] <= pivot): 121 | i+=1 122 | arr[i] , arr[j] = arr[j] , arr[i] 123 | 124 | arr[i+1] , arr[h] = arr[h],arr[i+1] 125 | return (i+1) 126 | 127 | 128 | # quick 129 | def quick(arr , l , h): 130 | if len(arr) < 2: 131 | return 132 | if( l < h ): 133 | pi = part(arr , l , h) 134 | quick(arr , l , pi - 1) 135 | quick(arr , pi + 1 , h) 136 | return arr 137 | 138 | 139 | # linear search 140 | def search(arr , k ): 141 | for i in arr: 142 | if( i == k ): 143 | return True 144 | return False 145 | 146 | 147 | # binary search 148 | def binary(arr , elem): 149 | m = len(arr) // 2 150 | if( len(arr) == 1 and arr[m] != elem): 151 | return False 152 | elif (arr[m] < elem): 153 | return binary(arr[m:] , elem) 154 | elif (arr[m] > elem): 155 | return binary(arr[:m] , elem) 156 | elif(arr[m] == elem): 157 | return True 158 | 159 | #fibanochi 160 | def fib(n): 161 | if ( n == 0): 162 | return 0 163 | elif( n == 1 or n == 2 ): 164 | return 1 165 | else: 166 | return fib(n-1) + fib(n-2) 167 | 168 | 169 | #linked list reverse 170 | # 1 - 2 - 3 - 4 - 5 - None 171 | # None - 5 - 4 - 3 - 2 - 1 172 | # def reverse(head): 173 | # current = head 174 | # prev = None 175 | # while current is not None: 176 | # nextNode = current.next 177 | # current.next = prev 178 | # prev = current 179 | # current = nextNode 180 | # head = prev 181 | # return head 182 | 183 | # linked list reverse with middle node 184 | # 1 - 2 - 3 - 4 - 5 - None 185 | # None - 5 - 4 - 3 - 2 - 1 186 | def reverse(head): 187 | current = head 188 | Next = current.next 189 | prev = None 190 | while True: 191 | current.next = prev 192 | if Next == None: 193 | break 194 | prev = current 195 | current = Next 196 | Next = Next.next 197 | head = current 198 | return head 199 | 200 | llist = LinkedList() 201 | arrLinkList = [1, 2, 3, 4, 5] 202 | for i in arrLinkList: 203 | llist_item = i 204 | llist.insert_node(llist_item) 205 | 206 | llist1 = reverse(llist.head) 207 | 208 | print('before reverse the linked list : ', arrLinkList) 209 | print('linked list reversed : ', end = ' ') 210 | print_linked_list(llist1) 211 | print() 212 | 213 | # second max 214 | def secondMax(arr): 215 | max1,max2 = 0 , 0 216 | if( arr[0] > arr[1]): 217 | max1 = arr[0] 218 | max2 = arr[1] 219 | else: 220 | max1 = arr[1] 221 | max2 = arr[0] 222 | for i in arr: 223 | if(i > max1): 224 | max2 = max1 225 | max1 = i 226 | elif( i > max2 and max1 != i): 227 | max2 = i 228 | return max2 229 | 230 | 231 | #reverse string 232 | def revStr(str): 233 | newStr = '' 234 | for i in range(len(str)): 235 | newStr += str[len(str) - 1 - i] 236 | return newStr 237 | 238 | 239 | #palindrome 240 | def palindrome(str): 241 | for i in range(len(str)//2): 242 | if not str[i] == str[len(str)-1 - i]: 243 | return False 244 | return True 245 | 246 | 247 | # min max 248 | def minMax(arr): 249 | min = arr[0] 250 | max = arr[0] 251 | for i in arr: 252 | if( i > max): 253 | max = i 254 | if( i < min): 255 | min = i 256 | return min, max 257 | 258 | 259 | # missing no of a array 260 | def missingNumber(arr): 261 | n = len(arr) + 1 262 | sumOfarray = sum(arr) 263 | sumOf_N_numbers = (n * (n + 1))//2 264 | missingOne = sumOf_N_numbers - sumOfarray 265 | return missingOne 266 | 267 | 268 | print('unsorted array : ' , arr) 269 | arr = quick(arr, 0 , len(arr) - 1) 270 | print('quick sorted array : ', arr) 271 | print('fibanocci : ', fib(9)) 272 | print('second max of an array : ', secondMax(arr)) 273 | print('binary serch check : ', binary(arr , 10)) 274 | print('palindrome check : ', palindrome('abcba')) 275 | print('reverse a string : ', revStr('abcd efgh')) 276 | print('min max of a array : ',minMax(arr)) 277 | print('serch missing no of a array : ', missingNumber([1,2,4,5,6])) -------------------------------------------------------------------------------- /Database/Presentation/Presentation - DB Kuppi Full.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/Presentation/Presentation - DB Kuppi Full.pptx -------------------------------------------------------------------------------- /Database/References/Advantages of database view.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Advantages of database view.pdf -------------------------------------------------------------------------------- /Database/References/IN 1400 Tutorial EER.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/IN 1400 Tutorial EER.pdf -------------------------------------------------------------------------------- /Database/References/Indexing and Hashing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Indexing and Hashing.pdf -------------------------------------------------------------------------------- /Database/References/Views, Stored procedures.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Views, Stored procedures.pptx -------------------------------------------------------------------------------- /Database/References/Week 1- Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 1- Introduction.pdf -------------------------------------------------------------------------------- /Database/References/Week 10 - SQL 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 10 - SQL 2.pdf -------------------------------------------------------------------------------- /Database/References/Week 10- Relational Algebra.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 10- Relational Algebra.pdf -------------------------------------------------------------------------------- /Database/References/Week 11 - Indexing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 11 - Indexing.pdf -------------------------------------------------------------------------------- /Database/References/Week 2- ER (part1) V2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 2- ER (part1) V2.pdf -------------------------------------------------------------------------------- /Database/References/Week 3-4- ER (Part 2) V2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 3-4- ER (Part 2) V2.pdf -------------------------------------------------------------------------------- /Database/References/Week 5 - EER.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 5 - EER.pdf -------------------------------------------------------------------------------- /Database/References/Week 5 - ERD _General Concerns.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 5 - ERD _General Concerns.pdf -------------------------------------------------------------------------------- /Database/References/Week 6 - Relational Model.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 6 - Relational Model.pdf -------------------------------------------------------------------------------- /Database/References/Week 7- ER to Relational Mapping.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 7- ER to Relational Mapping.pdf -------------------------------------------------------------------------------- /Database/References/Week 9 - Normalization.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 9 - Normalization.pdf -------------------------------------------------------------------------------- /Database/References/Week 9 - SQL 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/Database/References/Week 9 - SQL 1.pdf -------------------------------------------------------------------------------- /Database/Scripts/MSSQLVersion/Examples(MSSQL).sql: -------------------------------------------------------------------------------- 1 | USE DBKuppi; 2 | 3 | --DROP TABLE Admin; 4 | 5 | --Creating the Table 6 | CREATE TABLE Admin( 7 | Aid int NOT NULL IDENTITY(1,1), 8 | Name varchar(40), 9 | Pid int NOT NULL, 10 | Status varchar(40) DEFAULT 'Active', 11 | CONSTRAINT PK_Admin PRIMARY KEY(Aid), 12 | CONSTRAINT FK_Admin FOREIGN KEY(Pid) REFERENCES Program(Pid) 13 | ); 14 | 15 | --Select, Update, Delete and Insert into table 16 | SELECT * FROM Admin 17 | UPDATE Admin SET Name = 'abc' WHERE Aid = 1; 18 | DELETE FROM Admin WHERE Aid =2 19 | 20 | INSERT INTO Admin VALUES('Piumi', 1, DEFAULT); 21 | INSERT INTO Admin VALUES('Chiranga', 2, DEFAULT); 22 | 23 | --Alter table 24 | ALTER TABLE Admin 25 | ALTER COLUMN Name varchar(40) NOT NULL; 26 | 27 | --Select queries 28 | SELECT * FROM Program 29 | WHERE Name = 'IT'; 30 | 31 | SELECT Stdid, Surname, GivenName 32 | FROM Student; 33 | 34 | SELECT DISTINCT GivenName FROM Student 35 | 36 | SELECT * FROM Course 37 | WHERE Name LIKE '[e,a]%' 38 | 39 | SELECT * FROM Attempt 40 | ORDER BY Mark DESC; 41 | 42 | SELECT * FROM Attempt a 43 | WHERE a.Mark > 70 44 | ORDER BY Mark; 45 | 46 | --Joins 47 | SELECT * 48 | FROM Student s 49 | INNER JOIN Attempt a 50 | ON s.Stdid = a.Stdid; 51 | 52 | SELECT * 53 | FROM Student s, Attempt a 54 | WHERE s.Stdid = a.Stdid; 55 | 56 | SELECT s.GivenName, a.Mark 57 | FROM Student s 58 | INNER JOIN Attempt a ON s.Stdid = a.Stdid 59 | INNER JOIN Course c ON a.Cid = c.Cid 60 | WHERE a.Mark>50 61 | AND c.Name = 'Calculus'; 62 | 63 | SELECT s.stdid, s.GivenName, s.Surname, a.Mark 64 | FROM Student s 65 | FUll LEFT OUTER JOIN Attempt a ON s.Stdid = a.Stdid 66 | 67 | SELECT s.stdid, s.GivenName, s.Surname, a.Mark 68 | FROM Student s 69 | FUll RIGHT OUTER JOIN Attempt a ON s.Stdid = a.Stdid 70 | 71 | --Aggregates 72 | SELECT COUNT(DISTINCT Stdid) AS Number_of_Students 73 | FROM Attempt 74 | WHERE Mark>50 75 | 76 | SELECT DISTINCT Stdid FROM Attempt WHERE Mark>50 77 | 78 | SELECT MAX(a.Mark) 79 | FROM Student s, Attempt a, Course c 80 | WHERE s.Stdid = a.Stdid 81 | AND a.Cid = c.Cid 82 | AND c.Name = 'Accounting' 83 | 84 | SELECT MIN(a.Mark) 85 | FROM Attempt a, Course c 86 | WHERE a.Cid = c.Cid 87 | AND c.Name = 'Accounting' 88 | 89 | SELECT AVG(a.Mark) 90 | FROM Attempt a, Course c 91 | WHERE a.Cid = c.Cid 92 | AND c.Name = 'Calculus' 93 | 94 | SELECT SUM(Mark) 95 | FROM Attempt 96 | 97 | 98 | -------------------------------------------------------------------------------- /Database/Scripts/MSSQLVersion/Script(MSSQL).sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE DBKuppi; 2 | 3 | USE DBKuppi; 4 | 5 | CREATE TABLE Program( 6 | Pid int NOT NULL IDENTITY(1,1), 7 | Name varchar(20) NOT NULL, 8 | CreditPoint float NOT NULL, 9 | YearCommenced date NOT NULL, 10 | CONSTRAINT PK_Program PRIMARY KEY(Pid) 11 | ); 12 | 13 | CREATE TABLE Student( 14 | Stdid int NOT NULL IDENTITY(1,1), 15 | Surname varchar(20) NOT NULL, 16 | GivenName varchar(20) NOT NULL, 17 | DoB date NOT NULL, 18 | YearEnrolled date NOT NULL, 19 | Pid int NOT NULL, 20 | CONSTRAINT PK_Student PRIMARY KEY(Stdid), 21 | CONSTRAINT FK_Student FOREIGN KEY(Pid) REFERENCES Program(Pid) 22 | ); 23 | 24 | CREATE TABLE Course( 25 | Cid int NOT NULL IDENTITY(1,1), 26 | Name varchar(50) NOT NULL, 27 | CreditPoint float NOT NULL, 28 | YearCommenced date NOT NULL, 29 | Cyear int NOT NULL, 30 | Csem int NOT NULL, 31 | Pid int NOT NULL, 32 | CONSTRAINT PK_Course PRIMARY KEY(Cid), 33 | CONSTRAINT FK_Course FOREIGN KEY(Pid) REFERENCES Program(Pid) 34 | ); 35 | 36 | CREATE TABLE Attempt( 37 | Year int NOT NULL, 38 | Sem int NOT NULL, 39 | Mark int NOT NULL, 40 | Grade char NOT NULL, 41 | Stdid int NOT NULL, 42 | Cid int NOT NULL, 43 | CONSTRAINT PK_Attempt PRIMARY KEY(Year, Sem, Stdid, Cid), 44 | CONSTRAINT FK_AttemptStudent FOREIGN KEY(Stdid) REFERENCES Student(Stdid), 45 | CONSTRAINT FK_AttemptCourse FOREIGN KEY(Cid) REFERENCES Course(Cid) 46 | ); 47 | 48 | INSERT INTO Program VALUES('IT', 50.0, '2000'); 49 | INSERT INTO Program VALUES('ITM', 50.0, '2000'); 50 | 51 | INSERT INTO Student VALUES('Perera', 'Piumi', '0001', '2016', 1); 52 | INSERT INTO Student VALUES('Wickramasighe', 'Chiranga', '0001', '2016', 1); 53 | INSERT INTO Student VALUES('De Silva', 'Lahiru', '0001', '2016', 1); 54 | INSERT INTO Student VALUES('abc', 'abc', '0001', '2015', 2); 55 | INSERT INTO Student VALUES('xyz', 'xyz', '0001', '2014', 2); 56 | INSERT INTO Student VALUES('abc', 'abc', '0001', '2017', 1); 57 | INSERT INTO Student VALUES('xyz', 'xyz', '0001', '2017', 2); 58 | INSERT INTO Student VALUES('abc', 'abc', '0001', '2018', 2); 59 | INSERT INTO Student VALUES('xyz', 'xyz', '0001', '2018', 1); 60 | INSERT INTO Student VALUES('abc', 'abc', '0001', '2014', 2); 61 | 62 | INSERT INTO Course VALUES('Mathematics', 2.5, '2000', 4, 2, 1); 63 | INSERT INTO Course VALUES('Programming', 4, '2000', 1, 2, 1); 64 | INSERT INTO Course VALUES('AI', 2.5, '2002', 3, 1, 1); 65 | INSERT INTO Course VALUES('Accounting', 2.0, '2005', 2, 1, 1); 66 | INSERT INTO Course VALUES('Database', 2.5, '2000', 1, 2, 1); 67 | INSERT INTO Course VALUES('Multimedia', 2.5, '2005', 1, 2, 2); 68 | INSERT INTO Course VALUES('Economics', 2.0, '2000', 2, 2, 2); 69 | INSERT INTO Course VALUES('EAD', 3, '2000', 3, 1, 2); 70 | INSERT INTO Course VALUES('Marketing', 2.0, '2000', 2, 2, 2); 71 | INSERT INTO Course VALUES('Calculus', 4, '2000', 2, 1, 2); 72 | 73 | 74 | INSERT INTO Attempt VALUES(4, 2, 75, 'A', 1, 1); 75 | INSERT INTO Attempt VALUES(1, 2, 85, 'A', 2, 2); 76 | INSERT INTO Attempt VALUES(3, 1, 70, 'B', 3, 3); 77 | INSERT INTO Attempt VALUES(1, 2, 20, 'F', 4, 6); 78 | INSERT INTO Attempt VALUES(2, 2, 75, 'C', 4, 6); 79 | INSERT INTO Attempt VALUES(2, 1, 60, 'B', 5, 10); 80 | INSERT INTO Attempt VALUES(2, 1, 45, 'C', 6, 4); 81 | INSERT INTO Attempt VALUES(2, 2, 95, 'A', 7, 9); 82 | INSERT INTO Attempt VALUES(2, 2, 78, 'A', 8, 9); 83 | INSERT INTO Attempt VALUES(1, 2, 23, 'F', 9, 5); 84 | INSERT INTO Attempt VALUES(2, 2, 95, 'A', 10, 9); 85 | INSERT INTO Attempt VALUES(3, 1, 78, 'A', 10, 8); 86 | INSERT INTO Attempt VALUES(2, 1, 67, 'B', 9, 4); 87 | INSERT INTO Attempt VALUES(2, 1, 95, 'A', 2, 4); 88 | INSERT INTO Attempt VALUES(2, 1, 12, 'F', 4, 10); 89 | INSERT INTO Attempt VALUES(3, 1, 23, 'F', 4, 10); 90 | INSERT INTO Attempt VALUES(2, 2, 50, 'C', 7, 7); 91 | 92 | 93 | SELECT * FROM Attempt; 94 | SELECT * FROM Course; 95 | SELECT * FROM Program; 96 | SELECT * FROM Student; 97 | 98 | /* Drop Tables 99 | 100 | DROP TABLE Attempt; 101 | DROP TABLE Course; 102 | DROP TABLE Student; 103 | DROP TABLE Program; 104 | */ -------------------------------------------------------------------------------- /Database/Scripts/MySqlVersion/Examples(MySql).sql: -------------------------------------------------------------------------------- 1 | USE DBKuppi; 2 | 3 | -- Creating the Table 4 | CREATE TABLE if not exists Admin( 5 | Aid int NOT NULL AUTO_INCREMENT, 6 | Name varchar(40), 7 | Pid int NOT NULL, 8 | Status varchar(40) DEFAULT 'Active', 9 | CONSTRAINT PK_Admin PRIMARY KEY(Aid), 10 | CONSTRAINT FK_Admin FOREIGN KEY(Pid) REFERENCES Program(Pid) 11 | ); 12 | 13 | -- Select, Update, Delete and Insert into table 14 | INSERT INTO Admin(Name,Pid,Status) VALUES('Piumi', 1, DEFAULT); 15 | INSERT INTO Admin(Name,Pid,Status) VALUES('Chiranga', 2, DEFAULT); 16 | 17 | SELECT * FROM Admin; 18 | 19 | UPDATE Admin SET Name = 'abc' WHERE Aid = 1; 20 | DELETE FROM Admin WHERE Aid =2; 21 | 22 | -- Alter table 23 | ALTER TABLE Admin 24 | MODIFY COLUMN Name varchar(40) NOT NULL; 25 | 26 | -- Select queries 27 | SELECT * FROM Program 28 | WHERE Name = 'IT'; 29 | 30 | SELECT Stdid, Surname, GivenName 31 | FROM Student; 32 | 33 | SELECT DISTINCT GivenName FROM Student; 34 | 35 | SELECT * FROM Course 36 | WHERE Name LIKE '[e,a]%'; 37 | 38 | SELECT * FROM Attempt 39 | ORDER BY Mark DESC; 40 | 41 | SELECT * FROM Attempt a 42 | WHERE a.Mark > 70 43 | ORDER BY Mark; 44 | 45 | -- Joins 46 | SELECT * 47 | FROM Student s 48 | INNER JOIN Attempt a 49 | ON s.Stdid = a.Stdid; 50 | 51 | SELECT * 52 | FROM Student s, Attempt a 53 | WHERE s.Stdid = a.Stdid; 54 | 55 | SELECT s.GivenName, a.Mark 56 | FROM Student s 57 | INNER JOIN Attempt a ON s.Stdid = a.Stdid 58 | INNER JOIN Course c ON a.Cid = c.Cid 59 | WHERE a.Mark>50 60 | AND c.Name = 'Calculus'; 61 | 62 | SELECT s.stdid, s.GivenName, s.Surname, a.Mark 63 | FROM Student s 64 | LEFT OUTER JOIN Attempt a ON s.Stdid = a.Stdid; 65 | 66 | SELECT s.stdid, s.GivenName, s.Surname, a.Mark 67 | FROM Student s 68 | RIGHT OUTER JOIN Attempt a ON s.Stdid = a.Stdid; 69 | 70 | -- Aggregates 71 | SELECT COUNT(DISTINCT Stdid) AS Number_of_Students 72 | FROM Attempt 73 | WHERE Mark>50; 74 | 75 | SELECT DISTINCT Stdid FROM Attempt WHERE Mark>50; 76 | 77 | SELECT MAX(a.Mark) 78 | FROM Student s, Attempt a, Course c 79 | WHERE s.Stdid = a.Stdid 80 | AND a.Cid = c.Cid 81 | AND c.Name = 'Accounting'; 82 | 83 | SELECT MIN(a.Mark) 84 | FROM Attempt a, Course c 85 | WHERE a.Cid = c.Cid 86 | AND c.Name = 'Accounting'; 87 | 88 | SELECT AVG(a.Mark) 89 | FROM Attempt a, Course c 90 | WHERE a.Cid = c.Cid 91 | AND c.Name = 'Calculus'; 92 | 93 | SELECT SUM(Mark) 94 | FROM Attempt; 95 | 96 | 97 | -------------------------------------------------------------------------------- /Database/Scripts/MySqlVersion/Script(MySql).sql: -------------------------------------------------------------------------------- 1 | create Database if not exists DBKuppi; 2 | 3 | USE DBKuppi; 4 | 5 | CREATE TABLE Program( 6 | Pid int NOT NULL AUTO_INCREMENT, 7 | Name varchar(20) NOT NULL, 8 | CreditPoint float NOT NULL, 9 | YearCommenced date NOT NULL, 10 | CONSTRAINT PK_Program PRIMARY KEY(Pid) 11 | ); 12 | 13 | ALTER TABLE Program AUTO_INCREMENT=1; 14 | 15 | CREATE TABLE Student( 16 | Stdid int NOT NULL AUTO_INCREMENT, 17 | Surname varchar(20) NOT NULL, 18 | GivenName varchar(20) NOT NULL, 19 | DoB date NOT NULL, 20 | YearEnrolled date NOT NULL, 21 | Pid int NOT NULL, 22 | CONSTRAINT PK_Student PRIMARY KEY(Stdid), 23 | CONSTRAINT FK_Student FOREIGN KEY(Pid) REFERENCES Program(Pid) 24 | ); 25 | 26 | ALTER TABLE Student AUTO_INCREMENT=1; 27 | 28 | CREATE TABLE Course( 29 | Cid int NOT NULL AUTO_INCREMENT, 30 | Name varchar(50) NOT NULL, 31 | CreditPoint float NOT NULL, 32 | YearCommenced date NOT NULL, 33 | Cyear int NOT NULL, 34 | Csem int NOT NULL, 35 | Pid int NOT NULL, 36 | CONSTRAINT PK_Course PRIMARY KEY(Cid), 37 | CONSTRAINT FK_Course FOREIGN KEY(Pid) REFERENCES Program(Pid) 38 | ); 39 | 40 | ALTER TABLE Course AUTO_INCREMENT=1; 41 | 42 | CREATE TABLE Attempt( 43 | Year int NOT NULL, 44 | Sem int NOT NULL, 45 | Mark int NOT NULL, 46 | Grade char NOT NULL, 47 | Stdid int NOT NULL, 48 | Cid int NOT NULL, 49 | CONSTRAINT PK_Attempt PRIMARY KEY(Year, Sem, Stdid, Cid), 50 | CONSTRAINT FK_AttemptStudent FOREIGN KEY(Stdid) REFERENCES Student(Stdid), 51 | CONSTRAINT FK_AttemptCourse FOREIGN KEY(Cid) REFERENCES Course(Cid) 52 | ); 53 | 54 | INSERT INTO Program(name,creditpoint,yearcommenced) VALUES('IT', 50.0, '2000'); 55 | INSERT INTO Program(name,creditpoint,yearcommenced) VALUES('ITM', 50.0, '2000'); 56 | 57 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('Perera', 'Piumi', '0001', '2016', 1); 58 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('Wickramasighe', 'Chiranga', '0001', '2016', 1); 59 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('De Silva', 'Lahiru', '0001', '2016', 1); 60 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('abc', 'abc', '0001', '2015', 2); 61 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('xyz', 'xyz', '0001', '2014', 2); 62 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('abc', 'abc', '0001', '2017', 1); 63 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('xyz', 'xyz', '0001', '2017', 2); 64 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('abc', 'abc', '0001', '2018', 2); 65 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('xyz', 'xyz', '0001', '2018', 1); 66 | INSERT INTO Student(surname,givenname,DoB,YearEnrolled,Pid) VALUES('abc', 'abc', '0001', '2014', 2); 67 | 68 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Mathematics', 2.5, '2000', 4, 2, 1); 69 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Programming', 4, '2000', 1, 2, 1); 70 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('AI', 2.5, '2002', 3, 1, 1); 71 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Accounting', 2.0, '2005', 2, 1, 1); 72 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Database', 2.5, '2000', 1, 2, 1); 73 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Multimedia', 2.5, '2005', 1, 2, 2); 74 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Economics', 2.0, '2000', 2, 2, 2); 75 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('EAD', 3, '2000', 3, 1, 2); 76 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Marketing', 2.0, '2000', 2, 2, 2); 77 | INSERT INTO Course(name,creditpoint,yearcommenced,Cyear,csem,pid) VALUES('Calculus', 4, '2000', 2, 1, 2); 78 | 79 | 80 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(4, 2, 75, 'A', 1, 1); 81 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(1, 2, 85, 'A', 2, 2); 82 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(3, 1, 70, 'B', 3, 3); 83 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(1, 2, 20, 'F', 4, 6); 84 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 2, 75, 'C', 4, 6); 85 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 1, 60, 'B', 5, 10); 86 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 1, 45, 'C', 6, 4); 87 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 2, 95, 'A', 7, 9); 88 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 2, 78, 'A', 8, 9); 89 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(1, 2, 23, 'F', 9, 5); 90 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 2, 95, 'A', 10, 9); 91 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(3, 1, 78, 'A', 10, 8); 92 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 1, 67, 'B', 9, 4); 93 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 1, 95, 'A', 2, 4); 94 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 1, 12, 'F', 4, 10); 95 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(3, 1, 23, 'F', 4, 10); 96 | INSERT INTO Attempt(Year,Sem,Mark,Grade,Stdid,Cid) VALUES(2, 2, 50, 'C', 7, 7); 97 | 98 | 99 | SELECT * FROM Attempt; 100 | SELECT * FROM Course; 101 | SELECT * FROM Program; 102 | SELECT * FROM Student; 103 | 104 | /* Drop Tables 105 | 106 | DROP TABLE Attempt; 107 | DROP TABLE Course; 108 | DROP TABLE Student; 109 | DROP TABLE Program; 110 | */ -------------------------------------------------------------------------------- /JavaScript/AsyncJS.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Asynchronous Js 3 | */ 4 | 5 | // 1 6 | 7 | function capitalize(word) { 8 | return word.toUpperCase(); 9 | } 10 | 11 | let capitalized = capitalize('myself'); 12 | 13 | console.log(capitalized); 14 | 15 | console.log('done') 16 | 17 | // 2 18 | 19 | function capitalize(word, done) { 20 | done(word.toUpperCase()); 21 | } 22 | 23 | capitalize('myself', (capitalized) => { 24 | console.log(capitalized); 25 | }) 26 | 27 | console.log('done'); 28 | 29 | // 3 30 | 31 | function Alpha(word, done) { 32 | done(word.toUpperCase()); 33 | } 34 | 35 | function Bravo(word) { 36 | console.log(word) 37 | } 38 | 39 | Alpha('myself', Bravo) 40 | 41 | console.log('done'); 42 | 43 | // 4 44 | 45 | // Traditional Function 46 | let func = function (a) { 47 | return a + 100; 48 | } 49 | 50 | // Arrow Function Break Down 51 | 52 | // i. Remove the word "function" and place arrow between the argument and opening body bracket 53 | func = (a) => { 54 | return a + 100; 55 | } 56 | 57 | // ii. Remove the body brackets and word "return" -- the return is implied. 58 | func = (a) => a + 100; 59 | 60 | // iii. Remove the argument parentheses 61 | func = a => a + 100; 62 | 63 | // 5 64 | 65 | function capitalize(word, done) { 66 | process.nextTick(() => { 67 | done(word.toUpperCase()); 68 | }) 69 | } 70 | 71 | capitalize('myself', (capitalized) => { 72 | console.log(capitalized); 73 | }); 74 | 75 | console.log('done'); 76 | 77 | // 6 78 | 79 | const bar = () => console.log("bar") 80 | 81 | const baz = () => console.log("baz") 82 | 83 | const foo = () => { 84 | console.log("foo") 85 | bar() 86 | baz() 87 | } 88 | 89 | foo() 90 | 91 | // 7 92 | 93 | const bar = () => console.log('bar') 94 | 95 | const baz = () => console.log('baz') 96 | 97 | const foo = () => { 98 | console.log('foo') 99 | setTimeout(bar, 0) 100 | baz() 101 | } 102 | 103 | foo() 104 | 105 | // 8 106 | 107 | function delay(seconds, callback) { 108 | setTimeout(callback, seconds * 1000); 109 | } 110 | 111 | delay(2, () => { 112 | console.log('waited 2 seconds'); 113 | }) 114 | 115 | delay(3, () => { 116 | console.log('waited another 3 seconds'); 117 | }) 118 | 119 | delay(4, () => { 120 | console.log('waited another 4 seconds'); 121 | }) 122 | 123 | // 9 124 | 125 | function delay(seconds, callback) { 126 | setTimeout(callback, seconds * 1000); 127 | } 128 | 129 | delay(2, () => { 130 | console.log('waited 2 Seconds'); 131 | delay(3, () => { 132 | console.log('waited another 3 Seconds'); 133 | delay(4, () => { 134 | console.log('waited another 4 Seconds'); 135 | }) 136 | }) 137 | }) 138 | 139 | // 10 140 | 141 | let delay = (seconds) => new Promise((resolve) => { 142 | setTimeout(() => { 143 | resolve(seconds) 144 | }, seconds * 1000); 145 | }) 146 | 147 | delay(5) 148 | .then((time) => console.log(`waited ${time} seconds`)) 149 | 150 | // 11 151 | 152 | let delay = (seconds) => new Promise((resolve) => { 153 | setTimeout(() => { 154 | resolve(seconds) 155 | }, seconds * 1000); 156 | }) 157 | 158 | delay(2) 159 | .then(time => { 160 | console.log(`waited ${time} seconds`) 161 | return time; 162 | }) 163 | .then(time => time * 6) 164 | .then(timeX6 => console.log(`time into 6 is ${timeX6}`)) 165 | 166 | // 12 167 | 168 | let delay = (seconds) => new Promise((resolve, reject) => { 169 | 170 | throw new Error('I\'m going sidewayd :( ') 171 | 172 | setTimeout(() => { 173 | resolve(seconds) 174 | }, seconds * 1000); 175 | }) 176 | 177 | delay(2) 178 | .then(time => { 179 | console.log(`waited ${time} seconds`); 180 | }) 181 | .catch(error => console.log(`Promise says \'${error.message}\'`)) 182 | 183 | 184 | // 13 185 | 186 | let delay = (seconds) => new Promise((resolve, reject) => { 187 | 188 | if (seconds < 3) { 189 | reject(new Error(`${seconds} is too short`)) 190 | } 191 | 192 | setTimeout(() => { 193 | resolve(seconds) 194 | }, seconds * 1000); 195 | }) 196 | 197 | delay(2) 198 | .then(time => { 199 | console.log(`waited ${time} seconds`); 200 | }) 201 | .catch(error => console.log(`Promise says \'${error.message}\'`)) 202 | 203 | // 14 204 | 205 | var delay = (seconds, callback) => { 206 | if (seconds > 4) { 207 | callback(new Error(`${seconds} is way too long!`)); 208 | } else { 209 | setTimeout(() => { 210 | callback(null, `The ${seconds} delay is over`); 211 | }, seconds * 1000); 212 | } 213 | } 214 | /** 215 | * It is a rule in a callback function to pass the error if exists as the first argument 216 | * and to pass everything else as a second argument 217 | * 218 | * Therefore to make this process much easier, promisify is introduced so that you can call 219 | * functions that pass usual callbacks as promises 220 | */ 221 | 222 | /** 223 | * wihtout promisify 224 | * 225 | */ 226 | delay(4, (error, message) => { 227 | if (error) { 228 | console.log(`Error ${error}`); 229 | } else { 230 | console.log(message); 231 | } 232 | }) 233 | 234 | /** 235 | * With promisify 236 | */ 237 | var { promisify } = require('util'); 238 | var promisedDelay = promisify(delay) 239 | 240 | promisedDelay(3) 241 | .then(console.log) 242 | .catch(error => console.log(`Caught error : ${error}`)); 243 | 244 | 245 | // 15 246 | 247 | function delay(seconds) { 248 | return new Promise((resolve) => { 249 | setTimeout(() => { resolve(seconds) }, seconds * 1000); 250 | }) 251 | } 252 | 253 | delay(2) 254 | .then(() => console.log('waited 2 seconds')) 255 | .then(() => delay(3)) 256 | .then(() => console.log('waited another 3 seconds')) 257 | .then(() => delay(4)) 258 | .then(() => console.log('waited another 4 seconds')) 259 | 260 | // 16 261 | 262 | function delay(seconds) { 263 | return new Promise((resolve) => { 264 | setTimeout(() => { resolve(seconds) }, seconds * 1000); 265 | }) 266 | } 267 | 268 | Promise.all([ 269 | delay(2), 270 | delay(3), 271 | delay(4) 272 | ]) 273 | .then(() => console.log('done')) 274 | .catch((error) => console.error(error)) 275 | 276 | // 17 277 | 278 | function delay(seconds) { 279 | return new Promise((resolve) => { 280 | setTimeout(() => { resolve(seconds) }, seconds * 1000); 281 | }) 282 | } 283 | 284 | Promise.race([ 285 | delay(2), 286 | delay(3), 287 | delay(4) 288 | ]) 289 | .then(() => console.log('done')) 290 | .catch((error) => console.error(error)) 291 | 292 | // 18 293 | 294 | function delay(seconds) { 295 | return new Promise((resolve) => { 296 | setTimeout(() => { resolve(seconds) }, seconds * 1000); 297 | }) 298 | } 299 | 300 | (async () => { 301 | await delay(2); 302 | console.log('waited 2 seconds'); 303 | await delay(3); 304 | console.log('waited another 3 seconds'); 305 | try { 306 | await delay(4); 307 | console.log('waited another 4 seconds'); 308 | } catch (error) { 309 | console.error(error); 310 | } 311 | })(); 312 | 313 | 314 | -------------------------------------------------------------------------------- /JavaScript/Hoisting.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Hoisting 3 | */ 4 | 5 | // 1 6 | 7 | printVariable(fish) 8 | 9 | function printVariable(name) { 10 | console.log(name) 11 | } 12 | 13 | var fish = "stingRay" 14 | 15 | // 2 16 | 17 | function printVariable(name) { 18 | console.log(name) 19 | } 20 | 21 | var fish = undefined 22 | 23 | printVariable(fish) 24 | 25 | fish = "stringRay" 26 | 27 | // 3 28 | 29 | printVariable(fish) 30 | 31 | function printVariable(name) { 32 | console.log(name) 33 | } 34 | 35 | let fish = "stingRay" 36 | 37 | // 4 38 | 39 | printVariable(fish) 40 | 41 | function printVariable(name) { 42 | console.log(name) 43 | } 44 | 45 | const fish = "stingRay" 46 | 47 | // 5 48 | 49 | multiplyAndPrint(5, 8); // Prints 40 50 | 51 | function multiplyAndPrint(a, b) { 52 | console.log(a * b); 53 | } 54 | 55 | // 6 56 | 57 | multiplyAndPrint(6, 7); // Throws 'TypeError: multiplyAndPrint is not a function' 58 | addAndPrint(5, 8); // Throws 'ReferenceError: Cannot access 'addAndPrint' before initialization' 59 | 60 | var multiplyAndPrint = function (a, b) { 61 | console.log(a * b); 62 | } 63 | 64 | let addAndPrint = (a, b) => { 65 | console.log(a + b); 66 | } 67 | 68 | // 7 69 | 70 | let student_1 = new Student("Janith", 19); // ReferenceError: Cannot access 'Student' before initialization 71 | 72 | class Student { 73 | constructor(name, id) { 74 | this.name = name; 75 | this.id = id; 76 | } 77 | } 78 | 79 | // 8 80 | 81 | let student_1 = new Student("Janith", 19); // ReferenceError: Cannot access 'Student' before initialization 82 | let teacher_1 = new Teacher("Ravindu", 95); // TypeError: Teacher is not a constructor 83 | 84 | let Student = class { 85 | constructor(name, id) { 86 | this.name = name; 87 | this.id = id; 88 | } 89 | } 90 | 91 | var Teacher = class { 92 | constructor(name, id) { 93 | this.name = name; 94 | this.id = id; 95 | } 96 | } 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /JavaScript/JIT.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Optimization and de-optimization in JIT 3 | */ 4 | 5 | let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, '9', 0, 1, 2, 3] 6 | 7 | let sum = 0 8 | 9 | array.map(item => { 10 | sum += item 11 | console.log(sum) 12 | }) -------------------------------------------------------------------------------- /JavaScript/VariablesAndScope.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Variables and Scope 3 | */ 4 | 5 | // 1 6 | 7 | let mammal = "cat" 8 | 9 | function printVar() { 10 | console.log(mammal); 11 | } 12 | 13 | printVar() 14 | 15 | // 2 16 | 17 | function printVar() { 18 | let mammal = "cat" 19 | console.log(mammal) 20 | } 21 | 22 | console.log(mammal) 23 | 24 | // 3 25 | 26 | let age = 40; 27 | 28 | if (age > 21) { 29 | var gap = age - 21; 30 | } 31 | 32 | console.log(`You are ${gap} years over drinking age`); 33 | 34 | // 4 35 | 36 | let age = 40; 37 | 38 | if (age > 21) { 39 | let gap = age - 21; 40 | } 41 | 42 | console.log(`You are ${gap} years over drinking age`); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Batch 16 2 | 3 | ### FY - Interview Sessions 4 | 5 | #### Algo 6 | 7 | - you can find all the separated algorithems in allAlgo file. 8 | - run 9 | - navigate to /Algo 10 | - ~ python allAlgo.py 11 | - run only one file 12 | 13 | - navigate to /Algo/[directory]/[filename] 14 | - ~ python [filename].py 15 | 16 | - Java algorithems are also included. 17 | 18 | #### React 19 | 20 | - React Redux examples on hooks and class components 21 | - React potential interview questions 22 | 23 | #### Database 24 | 25 | - Database presentation slides 26 | - References slides 27 | - Sql script with joins, aggregation etc. 28 | 29 | #### JavaScript 30 | 31 | - Optimization and de-optimization in JIT 32 | - Variables and Scope 33 | - Hoisting 34 | - Asynchronous Js -------------------------------------------------------------------------------- /ReactJs/React-Redux-Class-Component/react-redux.md: -------------------------------------------------------------------------------- 1 | ### React Redux Hooks Template Link 2 | 3 | - [react redux hooks](https://github.com/nir099/react-redux-class-component) 4 | -------------------------------------------------------------------------------- /ReactJs/React-Redux-Hooks/react-redux-hooks.md: -------------------------------------------------------------------------------- 1 | ### React Redux Hooks Template Link 2 | 3 | - [react redux](https://github.com/nir099/redux-with-hooks) 4 | -------------------------------------------------------------------------------- /ReactJs/potential-Interview-Questions.md: -------------------------------------------------------------------------------- 1 | ## React Js Potential Interview Questions 2 | 3 | #### What are the features of React? 4 | 5 | - JSX: JSX is a syntax extension to JavaScript. It is used with React to describe what the user interface should look like. By using JSX, we can write HTML structures in the same file that contains JavaScript code. 6 | - Components: Components are the building blocks of any React application, and a single app usually consists of multiple components. It splits the user interface into independent, reusable parts that can be processed separately. 7 | - Virtual DOM: React keeps a lightweight representation of the real DOM in the memory, and that is known as the virtual DOM. When the state of an object changes, virtual DOM changes only that object in the real DOM, rather than updating all the objects. 8 | - One-way data-binding: React’s one-way data binding keeps everything modular and fast. A unidirectional data flow means that when designing a React app, you often nest child components within parent components. 9 | - High performance: React updates only those components that have changed, rather than updating all the components at once. This results in much faster web applications. 10 | 11 | #### Hello World 12 | 13 | - Speciality in react library 14 | - Features of react than others 15 | - What is a arrow function , why we use a arrow function 16 | - Difference between react and angular 17 | - Data binding, mvc , speed , serverside and client side 18 | 19 | #### Introducing JSX 20 | 21 | - What is JSX? 22 | - Regular javascript translators for browsers (eg: babel) / (transpiler) 23 | 24 | #### Rendering Elements 25 | 26 | - Dom vs virtual dom 27 | - Why virtual dom is important in rendering 28 | 29 | #### Components and Props 30 | 31 | - Stateful and stateless component in class components 32 | - Difference between props and states 33 | - How to pass props in react 34 | - Proptypes 35 | - What is a higher-order component in React? 36 | - Prop drilling 37 | - React context api 38 | 39 | #### State and Lifecycle 40 | 41 | - How to pass a function to a child component? 42 | - How components are refreshed ( life cycle ) 43 | - How to handle componentDidUpdate without infinite loop 44 | - How are class components rendered? Please explain step wise 45 | - What are the different phases of react lifecycle 46 | - Implementation of state ( with constructor and without ) 47 | - Update a state ( asynchronous ) 48 | - how to handle a event that should hapen after state update 49 | - Why we don't update by directly assigning a value 50 | - What are the two methods to update state 51 | - React Fragments 52 | - Life cycle - mount unmount update / handling in class and hooks 53 | - Hooks? Use Effect usage render every time , render only on intial loading , render on change of state variable 54 | - useMemo - usage 55 | - useEffect - order matters / how to handle async / mounting / update / unmoumt states in useEffect 56 | 57 | #### Handling Events 58 | 59 | - What is an event in React? 60 | - What are synthetic events in React? 61 | - What is the use of this keyword? 62 | 63 | #### Conditional Rendering 64 | 65 | - Implement a code for conditional rendering 66 | - Difference between conditional rendering and component hidden 67 | 68 | #### Lists and Keys 69 | 70 | - Explain how lists work in React 71 | - Important of Keys 72 | - What is the need of using keys in a list 73 | - Is it okay to use index as a key? 74 | - Why other component does not have key attribute? 75 | 76 | #### Lifting State Up 77 | 78 | - What do you mean by state uplifting? 79 | - How can we omit props drilling? 80 | 81 | #### Redux and components of redux 82 | 83 | - Redux's intent can be summarized in three principles 84 | - Global app state is kept in a single store 85 | - The store state is read-only to the rest of the app 86 | - Reducer functions are used to update the state in response to actions 87 | - Redux uses a "one-way data flow" app structure 88 | - State describes the condition of the app at a point in time, and UI renders based on that state 89 | - When something happens in the app: 90 | - The UI dispatches an action 91 | - The store runs the reducers, and the state is updated based on what occurred 92 | - The store notifies the UI that the state has changed 93 | - The UI re-renders based on the new state 94 | - use case of Redux thunk 95 | - One of the main use cases for this middleware is for handling actions that might not be synchronous, for example, using axios to send a GET request. Redux Thunk allows us to dispatch those actions asynchronously and resolve each promise that gets returned. 96 | 97 | #### other 98 | 99 | - React routing vs conventional routing 100 | - React styling / inline , css , js object, styled component 101 | - Server Side rendering and client side rendering 102 | - Pure functions 103 | - What do you understand by refs in React? 104 | - Use cases of ref 105 | - Managing focus, text selection, or media playback. 106 | - Triggering imperative animations. 107 | - Integrating with third-party DOM libraries. 108 | - How to handle many APIs in react 109 | - How to handle API errors in one place 110 | 111 | #### Articles to Refer 112 | 113 | - [interview questions](https://www.sitepoint.com/react-interview-questions-solutions/) 114 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-kuppi", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.8", 7 | "@testing-library/react": "^11.2.2", 8 | "@testing-library/user-event": "^12.6.0", 9 | "react": "^17.0.1", 10 | "react-dom": "^17.0.1", 11 | "react-scripts": "4.0.1", 12 | "web-vitals": "^0.2.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nir099/KnowledgeBase/7fd56f175ed5d35f17fbaa48b4a7f63dd3d540a8/ReactJs/react-kuppi/public/favicon.ico -------------------------------------------------------------------------------- /ReactJs/react-kuppi/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 |Zero
; 19 | } else { 20 | returnOther
; 21 | } 22 | }; 23 | 24 | render() { 25 | return ( 26 | <> 27 |Zero
33 |Other
*/} 34 | {this.conditionalFun(0)} 35 | {/*{count}
17 | 18 | 19 | > 20 | ); 21 | }; 22 | 23 | export default Counter; 24 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/src/Fragments.js: -------------------------------------------------------------------------------- 1 | import React, { Component, Fragment } from "react"; 2 | 3 | class Fragments extends Component { 4 | state = {}; 5 | render() { 6 | return ( 7 |Please insert the name and tap enter
10 |{obj.count}
15 |{obj.name}
16 | 17 | > 18 | ); 19 | }; 20 | 21 | export default ObjectState; 22 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/src/State.js: -------------------------------------------------------------------------------- 1 | // import React, { Component } from 'react'; 2 | 3 | // const State = () => { 4 | // return ( ); 5 | // } 6 | 7 | // export default State; 8 | -------------------------------------------------------------------------------- /ReactJs/react-kuppi/src/StateHandle.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class Statehandle extends Component { 4 | constructor(props){ 5 | super(props); 6 | this.state = { 7 | person: { 8 | name: "Yashod", 9 | age: 24, 10 | email: "yashod@abc.com" 11 | }, 12 | company: "ABC" 13 | } 14 | this.increaseAge = this.increaseAge.bind(this); 15 | } 16 | 17 | increaseAge(){ 18 | this.setState((prevProps) => ({ 19 | person : { 20 | ...prevProps.person, 21 | age: prevProps.person.age + 1 22 | } 23 | })); 24 | // this.setState((prevProps) => ({ 25 | // person.age : prevProps.person.age + 1 26 | // })); 27 | // this.setState((prevProps) => ({ 28 | // person : { 29 | // age: prevProps.person.age + 1 30 | // } 31 | // })); 32 | } 33 | 34 | render() { 35 | return ( 36 | <> 37 |