├── PhotoEditor ├── index.php ├── rk.jpg ├── README.md ├── style.css ├── image-editor.css ├── index.html └── script.js ├── chatbot-api ├── index.php ├── bot.png ├── style.css ├── chat_tree.json ├── style2.css ├── index.html └── script.js ├── ChatList-master ├── index.php ├── rk.jpg ├── images │ ├── avatar1.png │ ├── avatar2.png │ ├── avatar3.png │ ├── avatar4.png │ ├── avatar5.png │ ├── avatar6.png │ └── avatar7.png ├── README.md ├── script.js ├── index.html ├── ChatHandler.js └── style.css ├── TravelPath ├── rk.jpg ├── README.md ├── style.css ├── index.html └── practice.js ├── js_snake ├── Assets │ ├── bg.jpg │ ├── apple.png │ └── trophy.png ├── README.md ├── snake.css ├── index.html ├── client.cpp └── snake.js ├── Sudoku Puzzle ├── Question │ ├── rk.jpg │ ├── README.md │ ├── style.css │ ├── script.js │ └── index.html ├── Solution │ ├── rk.jpg │ ├── README.md │ ├── style.css │ ├── script.js │ └── index.html └── README.md └── README.md /PhotoEditor/index.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chatbot-api/index.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ChatList-master/index.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TravelPath/rk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/TravelPath/rk.jpg -------------------------------------------------------------------------------- /PhotoEditor/rk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/PhotoEditor/rk.jpg -------------------------------------------------------------------------------- /chatbot-api/bot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/chatbot-api/bot.png -------------------------------------------------------------------------------- /ChatList-master/rk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/rk.jpg -------------------------------------------------------------------------------- /js_snake/Assets/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/js_snake/Assets/bg.jpg -------------------------------------------------------------------------------- /js_snake/Assets/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/js_snake/Assets/apple.png -------------------------------------------------------------------------------- /js_snake/Assets/trophy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/js_snake/Assets/trophy.png -------------------------------------------------------------------------------- /Sudoku Puzzle/Question/rk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/Sudoku Puzzle/Question/rk.jpg -------------------------------------------------------------------------------- /Sudoku Puzzle/Solution/rk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/Sudoku Puzzle/Solution/rk.jpg -------------------------------------------------------------------------------- /ChatList-master/images/avatar1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar1.png -------------------------------------------------------------------------------- /ChatList-master/images/avatar2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar2.png -------------------------------------------------------------------------------- /ChatList-master/images/avatar3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar3.png -------------------------------------------------------------------------------- /ChatList-master/images/avatar4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar4.png -------------------------------------------------------------------------------- /ChatList-master/images/avatar5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar5.png -------------------------------------------------------------------------------- /ChatList-master/images/avatar6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar6.png -------------------------------------------------------------------------------- /ChatList-master/images/avatar7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ravikumar7210/dsbased_jsprojects/HEAD/ChatList-master/images/avatar7.png -------------------------------------------------------------------------------- /js_snake/README.md: -------------------------------------------------------------------------------- 1 | js_snake 2 | ![Screenshot (97)](https://user-images.githubusercontent.com/39921508/124384787-89f92380-dcf0-11eb-9a7d-c45acb666712.png) 3 | -------------------------------------------------------------------------------- /ChatList-master/README.md: -------------------------------------------------------------------------------- 1 | ![Screenshot (95)](https://user-images.githubusercontent.com/39921508/124384375-82387f80-dcee-11eb-972d-2aedd294bbc7.png) 2 | # ChatList 3 | -------------------------------------------------------------------------------- /PhotoEditor/README.md: -------------------------------------------------------------------------------- 1 | photo editor snapshot ![Screenshot (99)](https://user-images.githubusercontent.com/39921508/124384413-b1e78780-dcee-11eb-8c50-6990e9871f6c.png) 2 | -------------------------------------------------------------------------------- /Sudoku Puzzle/Question/README.md: -------------------------------------------------------------------------------- 1 | question snapshot ![Screenshot (104)](https://user-images.githubusercontent.com/39921508/124384473-0b4fb680-dcef-11eb-9746-aa9a6fb897a1.png) 2 | -------------------------------------------------------------------------------- /Sudoku Puzzle/Solution/README.md: -------------------------------------------------------------------------------- 1 | solution snapshot![Screenshot (101)](https://user-images.githubusercontent.com/39921508/124384497-26bac180-dcef-11eb-9e00-8fbbf8aa0bd4.png) 2 | -------------------------------------------------------------------------------- /TravelPath/README.md: -------------------------------------------------------------------------------- 1 | travel path snapshot 2 | ![Screenshot (103)](https://user-images.githubusercontent.com/39921508/124384743-5ae2b200-dcf0-11eb-8d25-63b0a9bfb83a.png) 3 | 4 | -------------------------------------------------------------------------------- /Sudoku Puzzle/README.md: -------------------------------------------------------------------------------- 1 | question and solution of sudoku puzzle![Screenshot (107)](https://user-images.githubusercontent.com/39921508/124384699-27078c80-dcf0-11eb-85e5-517df7ba2573.png) 2 | ![Screenshot (108)](https://user-images.githubusercontent.com/39921508/124384704-2ec73100-dcf0-11eb-8494-fc50a8271393.png) 3 | -------------------------------------------------------------------------------- /js_snake/snake.css: -------------------------------------------------------------------------------- 1 | 2 | body{ 3 | background-color: black; 4 | } 5 | #mycanvas{ 6 | margin: 0; 7 | position: absolute; 8 | left: 50%; 9 | top: 50%; 10 | transform: translate(-50%,-50%); 11 | background-image: url("Assets/bg.jpg"); 12 | border:20px solid green; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /js_snake/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Javascript snake game 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /PhotoEditor/style.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | height: 100%; 4 | } 5 | 6 | .text_box { 7 | margin-top: 50px; 8 | width: 100%; 9 | display: flex; 10 | flex-wrap: wrap; 11 | align-content: center; 12 | } 13 | 14 | #container{ 15 | width: 100%; 16 | background-color: white; 17 | display: flex; 18 | margin: 0 auto; 19 | } 20 | 21 | .center_buttons { 22 | margin:auto; 23 | display:block; 24 | } 25 | -------------------------------------------------------------------------------- /chatbot-api/style.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | } 7 | 8 | #chatdiv { 9 | width: 50%; 10 | height: 100%; 11 | border: 1px solid lightgray; 12 | } 13 | 14 | #chatdiv2 { 15 | width: 50%; 16 | height: 100%; 17 | border: 1px solid lightgray; 18 | display: flex; 19 | flex-wrap: wrap; 20 | align-content: center; 21 | } 22 | 23 | #maindiv{ 24 | width: 100%; 25 | flex: 1; 26 | background-color: white; 27 | display: flex; 28 | margin: 0 auto; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /PhotoEditor/image-editor.css: -------------------------------------------------------------------------------- 1 | #imageEditor { 2 | margin:auto; 3 | padding:20px; 4 | border:1px solid #4b4b4b; 5 | -moz-border-radius:8px; 6 | -webkit-border-radius:8px; 7 | border-radius:8px; 8 | background-color:#ababab; 9 | } 10 | 11 | #editorContainer { 12 | display:block; 13 | overflow: auto; 14 | width: 800px; 15 | height: 500px; 16 | } 17 | 18 | #editor { 19 | display:block; 20 | margin: auto; 21 | } 22 | 23 | #toolbar { 24 | display:block; 25 | margin-right: 50px; 26 | } 27 | 28 | #resizer { 29 | border:2px dashed #000 30 | } 31 | 32 | #toolbar button { 33 | padding: 10px 20px 10px 20px; 34 | } -------------------------------------------------------------------------------- /TravelPath/style.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | height: 100%; 4 | } 5 | 6 | #mynetwork { 7 | width: 50%; 8 | height: 100%; 9 | border: 1px solid lightgray; 10 | } 11 | 12 | #container2 { 13 | width: 50%; 14 | height: 100%; 15 | border: 1px solid lightgray; 16 | display: flex; 17 | flex-wrap: wrap; 18 | align-content: center; 19 | } 20 | 21 | #mynetwork2{ 22 | width: 100%; 23 | height: 100%; 24 | } 25 | 26 | #container{ 27 | width: 100%; 28 | height: 70%; 29 | background-color: white; 30 | display: flex; 31 | margin: 0 auto; 32 | } 33 | 34 | #generate-graph{ 35 | margin:auto; 36 | display:block; 37 | } 38 | 39 | 40 | #solve{ 41 | margin:auto; 42 | display:block; 43 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dsbased_jsprojects 2 | snapshot of all projects![Screenshot (97)](https://user-images.githubusercontent.com/39921508/124414997-7b068580-dd71-11eb-97e3-98dadfabf8f2.png) 3 | ![Screenshot (99)](https://user-images.githubusercontent.com/39921508/124415001-7c37b280-dd71-11eb-8ae5-9cedb8eee6a9.png) 4 | ![Screenshot (103)](https://user-images.githubusercontent.com/39921508/124415002-7c37b280-dd71-11eb-9646-4d495af11528.png) 5 | ![Screenshot (107)](https://user-images.githubusercontent.com/39921508/124415004-7cd04900-dd71-11eb-9564-b0a16366313a.png) 6 | ![Screenshot (108)](https://user-images.githubusercontent.com/39921508/124415005-7d68df80-dd71-11eb-97a4-4a607ac4b10c.png) 7 | ![Screenshot (95)](https://user-images.githubusercontent.com/39921508/124415006-7d68df80-dd71-11eb-831c-9c014a8bcdfc.png) 8 | -------------------------------------------------------------------------------- /chatbot-api/chat_tree.json: -------------------------------------------------------------------------------- 1 | { 2 | "child_msg" : ["Want to hear a joke ?","What about some news ?","Wanna get motivated ?","Terminate chat"], 3 | "children" : [ 4 | { 5 | "child_msg" : ["Funny Joke","Very funny Joke","PJ :)","Terminate chat"], 6 | "children" : [ 7 | { 8 | "message" : "getJoke()", 9 | "type" : "function" 10 | }, 11 | { 12 | "message" : "Santa Banta Ha Ha Ha", 13 | "type" : "normal" 14 | }, 15 | { 16 | "message" : "Banta Santa", 17 | "type" : "normal" 18 | } 19 | ] 20 | }, 21 | { 22 | "child_msg" : ["Local News","National News","World News","Terminate chat"], 23 | "children" : [ 24 | { 25 | "message" : "getNews()", 26 | "type" : "function" 27 | }, 28 | { 29 | "message" : "India is the best", 30 | "type" : "normal" 31 | }, 32 | { 33 | "message" : "India becomes a super power", 34 | "type" : "normal" 35 | } 36 | ] 37 | }, 38 | { 39 | "message" : "You're amazing and everything you do will make a positive effect on the world" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /js_snake/client.cpp: -------------------------------------------------------------------------------- 1 | // Client side C/C++ program to demonstrate Socket programming 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #define PORT 8080 8 | 9 | int main(int argc, char const *argv[]) 10 | { 11 | int sock = 0, valread; 12 | struct sockaddr_in serv_addr; 13 | char *hello = "Hello from client"; 14 | char buffer[1024] = {0}; 15 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 16 | { 17 | printf("\n Socket creation error \n"); 18 | return -1; 19 | } 20 | 21 | serv_addr.sin_family = AF_INET; 22 | serv_addr.sin_port = htons(PORT); 23 | 24 | // Convert IPv4 and IPv6 addresses from text to binary form 25 | if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0) 26 | { 27 | printf("\nInvalid address/ Address not supported \n"); 28 | return -1; 29 | } 30 | 31 | if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) 32 | { 33 | printf("\nConnection Failed \n"); 34 | return -1; 35 | } 36 | send(sock , hello , strlen(hello) , 0 ); 37 | printf("Hello message sent\n"); 38 | valread = read( sock , buffer, 1024); 39 | printf("%s\n",buffer ); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /ChatList-master/script.js: -------------------------------------------------------------------------------- 1 | 2 | import { ChatHandler, chat_names } from './ChatHandler.js'; 3 | 4 | onload = function () { 5 | 6 | const chatlist = document.getElementById('chat-list'); 7 | const add = document.getElementById('generate-step'); 8 | const text = document.getElementById('temptext'); 9 | 10 | const templates = document.getElementsByTagName('template')[0]; 11 | const chat_item = templates.content.querySelector("li"); 12 | 13 | const chatHandler = new ChatHandler(chat_item, chatlist); 14 | let chats = []; 15 | 16 | add.onclick = function () { 17 | if(Math.random()>0.75 && chats.length > 0){ 18 | let index = Math.floor(Math.random()*chats.length); 19 | let idToDelete = chats[index]; 20 | chatHandler.deleteMsg(idToDelete); 21 | text.innerHTML = "Deleted message from "+chat_names[idToDelete] + "
" + text.innerHTML; 22 | chats.splice(index, 1); 23 | } else{ 24 | let idOfMsg = Math.floor(Math.random()*7); 25 | if(chats.includes(idOfMsg)===false){ 26 | chats.push(idOfMsg); 27 | } 28 | chatHandler.newMsg(idOfMsg); 29 | text.innerHTML = "New message from "+chat_names[idOfMsg] + "
" + text.innerHTML; 30 | } 31 | }; 32 | }; -------------------------------------------------------------------------------- /Sudoku Puzzle/Question/style.css: -------------------------------------------------------------------------------- 1 | #container{ 2 | height: auto; 3 | width: 540px; 4 | background-color: white; 5 | display: flex; 6 | flex-wrap: wrap; 7 | justify-content: space-evenly; 8 | align-content: space-evenly ; 9 | margin: 0 auto; 10 | } 11 | 12 | #generate-sudoku{ 13 | margin:auto; 14 | display:block;; 15 | } 16 | 17 | 18 | #solve{ 19 | margin:auto; 20 | display:block;; 21 | } 22 | 23 | #container div{ 24 | background-color: whitesmoke; 25 | height: 60px; 26 | width: 60px; 27 | box-sizing: border-box; 28 | font-family: sans-serif; 29 | text-align: center; 30 | vertical-align: middle; 31 | line-height: 60px; 32 | font-size: 30px; 33 | color: green; 34 | 35 | } 36 | 37 | #container div:hover{ 38 | background-color: lightskyblue; 39 | } 40 | 41 | .lsb{ 42 | border-left: black 2px solid; 43 | } 44 | 45 | .bsb{ 46 | border-bottom: black 2px solid; 47 | } 48 | 49 | .rsb{ 50 | border-right: black 2px solid; 51 | } 52 | 53 | .tsb{ 54 | border-top: black 2px solid; 55 | } 56 | 57 | 58 | .ldb{ 59 | border-left: black 0.6px dashed; 60 | } 61 | 62 | .bdb{ 63 | border-bottom: black 0.6px dashed; 64 | } 65 | 66 | .rdb{ 67 | border-right: black 0.6px dashed; 68 | } 69 | 70 | .tdb{ 71 | border-top: black 0.6px dashed; 72 | } 73 | -------------------------------------------------------------------------------- /Sudoku Puzzle/Solution/style.css: -------------------------------------------------------------------------------- 1 | #container{ 2 | height: auto; 3 | width: 540px; 4 | background-color: white; 5 | display: flex; 6 | flex-wrap: wrap; 7 | justify-content: space-evenly; 8 | align-content: space-evenly ; 9 | margin: 0 auto; 10 | } 11 | 12 | #generate-sudoku{ 13 | margin:auto; 14 | display:block;; 15 | } 16 | 17 | 18 | #solve{ 19 | margin:auto; 20 | display:block;; 21 | } 22 | 23 | #container div{ 24 | background-color: whitesmoke; 25 | height: 60px; 26 | width: 60px; 27 | box-sizing: border-box; 28 | font-family: sans-serif; 29 | text-align: center; 30 | vertical-align: middle; 31 | line-height: 60px; 32 | font-size: 30px; 33 | color: green; 34 | 35 | } 36 | 37 | #container div:hover{ 38 | background-color: lightskyblue; 39 | } 40 | 41 | .lsb{ 42 | border-left: black 2px solid; 43 | } 44 | 45 | .bsb{ 46 | border-bottom: black 2px solid; 47 | } 48 | 49 | .rsb{ 50 | border-right: black 2px solid; 51 | } 52 | 53 | .tsb{ 54 | border-top: black 2px solid; 55 | } 56 | 57 | 58 | .ldb{ 59 | border-left: black 0.6px dashed; 60 | } 61 | 62 | .bdb{ 63 | border-bottom: black 0.6px dashed; 64 | } 65 | 66 | .rdb{ 67 | border-right: black 0.6px dashed; 68 | } 69 | 70 | .tdb{ 71 | border-top: black 0.6px dashed; 72 | } 73 | -------------------------------------------------------------------------------- /TravelPath/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 25 |
26 |
27 |
28 |
29 | 30 | 31 | 32 | Red link represents bus travel time :
33 | Green link represents flight travel time :
34 | Click on solve to get Solution !! 35 |
36 | 37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /PhotoEditor/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 22 |
23 |
24 |
25 |
26 | 27 |
28 |
29 |
30 | 31 | 32 |
33 |
34 | 35 | 36 |
37 |
38 | 39 | 40 |
41 |
42 | 43 | 44 |
45 |
46 |
47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Sudoku Puzzle/Question/script.js: -------------------------------------------------------------------------------- 1 | var arr = [[], [], [], [], [], [], [], [], []] 2 | var temp = [[], [], [], [], [], [], [], [], []] 3 | 4 | for (var i = 0; i < 9; i++) { 5 | for (var j = 0; j < 9; j++) { 6 | arr[i][j] = document.getElementById(i * 9 + j); 7 | 8 | } 9 | } 10 | 11 | function initializeTemp(temp) { 12 | 13 | for (var i = 0; i < 9; i++) { 14 | for (var j = 0; j < 9; j++) { 15 | temp[i][j] = false; 16 | 17 | } 18 | } 19 | } 20 | 21 | 22 | function setTemp(board, temp) { 23 | 24 | for (var i = 0; i < 9; i++) { 25 | for (var j = 0; j < 9; j++) { 26 | if (board[i][j] != 0) { 27 | temp[i][j] = true; 28 | } 29 | 30 | } 31 | } 32 | } 33 | 34 | 35 | function setColor(temp) { 36 | 37 | for (var i = 0; i < 9; i++) { 38 | for (var j = 0; j < 9; j++) { 39 | if (temp[i][j] == true) { 40 | arr[i][j].style.color = "#DC3545"; 41 | } 42 | 43 | } 44 | } 45 | } 46 | 47 | function resetColor() { 48 | 49 | for (var i = 0; i < 9; i++) { 50 | for (var j = 0; j < 9; j++) { 51 | 52 | arr[i][j].style.color = "green"; 53 | 54 | 55 | } 56 | } 57 | } 58 | 59 | var board = [[], [], [], [], [], [], [], [], []] 60 | 61 | 62 | let button = document.getElementById('generate-sudoku') 63 | let solve = document.getElementById('solve') 64 | 65 | console.log(arr) 66 | function changeBoard(board) { 67 | for (var i = 0; i < 9; i++) { 68 | for (var j = 0; j < 9; j++) { 69 | if (board[i][j] != 0) { 70 | 71 | arr[i][j].innerText = board[i][j] 72 | } 73 | 74 | else 75 | arr[i][j].innerText = '' 76 | } 77 | } 78 | } 79 | 80 | 81 | button.onclick = function () { 82 | var xhrRequest = new XMLHttpRequest() 83 | xhrRequest.onload = function () { 84 | var response = JSON.parse(xhrRequest.response) 85 | console.log(response) 86 | initializeTemp(temp) 87 | resetColor() 88 | 89 | board = response.board 90 | setTemp(board, temp) 91 | setColor(temp) 92 | changeBoard(board) 93 | } 94 | xhrRequest.open('get', 'https://sugoku.herokuapp.com/board?difficulty=easy') 95 | //we can change the difficulty of the puzzle the allowed values of difficulty are easy, medium, hard and random 96 | xhrRequest.send() 97 | } 98 | 99 | // you can make a call to changeboard(board) function to update the state on the screen 100 | function solveSudokuHelper(board,r,c){ 101 | 102 | //base case 103 | if(r==9){ 104 | changeBoard(board); 105 | return true; 106 | } 107 | //other cases - write your code here 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | //finish your code here 119 | 120 | } 121 | 122 | function solveSudoku(board) { 123 | solveSudokuHelper(board,0,0); 124 | } 125 | 126 | 127 | solve.onclick = function () { 128 | solveSudoku(board) 129 | } -------------------------------------------------------------------------------- /chatbot-api/style2.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Lato:400,700); 2 | *, *:before, *:after { 3 | box-sizing: border-box; 4 | } 5 | 6 | .container { 7 | margin: 0 auto; 8 | width: 100%; 9 | height: 100%; 10 | background: #444753; 11 | border-radius: 5px; 12 | } 13 | 14 | .chat { 15 | height: 100%; 16 | width: 100%; 17 | background: #F2F5F8; 18 | border-top-right-radius: 5px; 19 | border-bottom-right-radius: 5px; 20 | color: #434651; 21 | } 22 | .chat .chat-header { 23 | padding: 20px; 24 | border-bottom: 2px solid white; 25 | } 26 | .chat .chat-header img { 27 | float: left; 28 | } 29 | .chat .chat-header .chat-about { 30 | float: left; 31 | padding-left: 10px; 32 | margin-top: 6px; 33 | } 34 | .chat .chat-header .chat-with { 35 | font-weight: bold; 36 | font-size: 16px; 37 | } 38 | .chat .chat-header .chat-num-messages { 39 | color: #92959E; 40 | } 41 | .chat .chat-header .fa-star { 42 | float: right; 43 | color: #D8DADF; 44 | font-size: 20px; 45 | margin-top: 12px; 46 | } 47 | .chat .chat-history { 48 | padding: 30px 30px 20px; 49 | border-bottom: 2px solid white; 50 | overflow-y: scroll; 51 | height: 400px; 52 | } 53 | .chat .chat-history .message-data { 54 | margin-bottom: 15px; 55 | } 56 | .chat .chat-history .message-data-time { 57 | color: #a8aab1; 58 | padding-left: 6px; 59 | } 60 | .chat .chat-history .message { 61 | color: white; 62 | padding: 18px 20px; 63 | line-height: 26px; 64 | font-size: 16px; 65 | border-radius: 7px; 66 | margin-bottom: 30px; 67 | width: 70%; 68 | position: relative; 69 | } 70 | .chat .chat-history .message:after { 71 | bottom: 100%; 72 | left: 7%; 73 | border: solid transparent; 74 | content: " "; 75 | height: 0; 76 | width: 0; 77 | position: absolute; 78 | pointer-events: none; 79 | border-bottom-color: #86BB71; 80 | border-width: 10px; 81 | margin-left: -10px; 82 | } 83 | .chat .chat-history .my-message { 84 | background: #86BB71; 85 | } 86 | .chat .chat-history .other-message { 87 | background: #94C2ED; 88 | } 89 | .chat .chat-history .other-message:after { 90 | border-bottom-color: #94C2ED; 91 | left: 93%; 92 | } 93 | .chat .chat-message { 94 | padding: 30px; 95 | } 96 | .chat .chat-message textarea { 97 | width: 100%; 98 | border: none; 99 | padding: 10px 20px; 100 | font: 14px/22px "Lato", Arial, sans-serif; 101 | margin-bottom: 10px; 102 | border-radius: 5px; 103 | resize: none; 104 | } 105 | .chat .chat-message .fa-file-o, .chat .chat-message .fa-file-image-o { 106 | font-size: 16px; 107 | color: gray; 108 | cursor: pointer; 109 | } 110 | .chat .chat-message button { 111 | float: right; 112 | color: #94C2ED; 113 | font-size: 16px; 114 | text-transform: uppercase; 115 | border: none; 116 | cursor: pointer; 117 | font-weight: bold; 118 | background: #F2F5F8; 119 | } 120 | .chat .chat-message button:hover { 121 | color: #75b1e8; 122 | } 123 | 124 | .online, .offline, .me { 125 | margin-right: 3px; 126 | font-size: 10px; 127 | } 128 | 129 | .online { 130 | color: #86BB71; 131 | } 132 | 133 | .offline { 134 | color: #E38968; 135 | } 136 | 137 | .me { 138 | color: #94C2ED; 139 | } 140 | 141 | .align-left { 142 | text-align: left; 143 | } 144 | 145 | .align-right { 146 | text-align: right; 147 | } 148 | 149 | .float-right { 150 | float: right; 151 | } 152 | 153 | .clearfix:after { 154 | visibility: hidden; 155 | display: block; 156 | font-size: 0; 157 | content: " "; 158 | clear: both; 159 | height: 0; 160 | } 161 | -------------------------------------------------------------------------------- /js_snake/snake.js: -------------------------------------------------------------------------------- 1 | 2 | function init(){ 3 | canvas = document.getElementById('mycanvas'); 4 | W = H = canvas.width = canvas.height = 600; 5 | pen = canvas.getContext('2d'); 6 | cs = 66; 7 | game_over = false; 8 | score = 5; 9 | 10 | 11 | //Create a Image Object for food 12 | food_img = new Image(); 13 | food_img.src = "Assets/apple.png"; 14 | 15 | trophy = new Image(); 16 | trophy.src = "Assets/trophy.png"; 17 | 18 | food = getRandomFood(); 19 | 20 | snake = { 21 | init_len:5, 22 | color:"blue", 23 | cells:[], 24 | direction:"right", 25 | 26 | 27 | createSnake:function(){ 28 | for(var i=this.init_len;i>0;i--){ 29 | this.cells.push({x:i,y:0}); 30 | } 31 | }, 32 | drawSnake:function(){ 33 | 34 | for(var i=0;i last_x || this.cells[0].y > last_y){ 85 | game_over = true; 86 | } 87 | 88 | } 89 | 90 | }; 91 | 92 | snake.createSnake(); 93 | //Add a Event Listener on the Document Object 94 | function keyPressed(e){ 95 | //Conditional Statments 96 | if(e.key=="ArrowRight"){ 97 | snake.direction = "right"; 98 | } 99 | else if(e.key=="ArrowLeft"){ 100 | snake.direction = "left"; 101 | } 102 | else if(e.key=="ArrowDown"){ 103 | snake.direction = "down"; 104 | } 105 | else{ 106 | snake.direction = "up"; 107 | } 108 | console.log(snake.direction); 109 | } 110 | 111 | 112 | document.addEventListener('keydown',keyPressed) ; 113 | 114 | } 115 | 116 | 117 | function draw(){ 118 | //console.log("In Draw"); 119 | 120 | //erase the old frame 121 | pen.clearRect(0,0,W,H); 122 | snake.drawSnake(); 123 | 124 | pen.fillStyle = food.color; 125 | pen.drawImage(food_img,food.x*cs,food.y*cs,cs,cs); 126 | 127 | pen.drawImage(trophy,18,20,cs,cs); 128 | pen.fillStyle = "blue"; 129 | pen.font = "20px Roboto" 130 | pen.fillText(score,50,50); 131 | 132 | 133 | } 134 | 135 | function update(){ 136 | //console.log("In Update"); 137 | snake.updateSnake(); 138 | } 139 | 140 | function getRandomFood(){ 141 | 142 | var foodX = Math.round(Math.random()*(W-cs)/cs); 143 | var foodY = Math.round(Math.random()*(H-cs)/cs); 144 | 145 | var food = { 146 | x:foodX, 147 | y:foodY, 148 | color:"red", 149 | } 150 | return food 151 | 152 | } 153 | 154 | function gameloop(){ 155 | if(game_over==true){ 156 | clearInterval(f); 157 | alert("Game Over"); 158 | return; 159 | } 160 | draw(); 161 | update(); 162 | } 163 | 164 | init(); 165 | 166 | var f = setInterval(gameloop,100); 167 | -------------------------------------------------------------------------------- /Sudoku Puzzle/Solution/script.js: -------------------------------------------------------------------------------- 1 | var arr = [[], [], [], [], [], [], [], [], []] 2 | var temp = [[], [], [], [], [], [], [], [], []] 3 | 4 | for (var i = 0; i < 9; i++) { 5 | for (var j = 0; j < 9; j++) { 6 | arr[i][j] = document.getElementById(i * 9 + j); 7 | 8 | } 9 | } 10 | 11 | function initializeTemp(temp) { 12 | 13 | for (var i = 0; i < 9; i++) { 14 | for (var j = 0; j < 9; j++) { 15 | temp[i][j] = false; 16 | 17 | } 18 | } 19 | } 20 | 21 | 22 | function setTemp(board, temp) { 23 | 24 | for (var i = 0; i < 9; i++) { 25 | for (var j = 0; j < 9; j++) { 26 | if (board[i][j] != 0) { 27 | temp[i][j] = true; 28 | } 29 | 30 | } 31 | } 32 | } 33 | 34 | 35 | function setColor(temp) { 36 | 37 | for (var i = 0; i < 9; i++) { 38 | for (var j = 0; j < 9; j++) { 39 | if (temp[i][j] == true) { 40 | arr[i][j].style.color = "#DC3545"; 41 | } 42 | 43 | } 44 | } 45 | } 46 | 47 | function resetColor() { 48 | 49 | for (var i = 0; i < 9; i++) { 50 | for (var j = 0; j < 9; j++) { 51 | 52 | arr[i][j].style.color = "green"; 53 | 54 | 55 | } 56 | } 57 | } 58 | 59 | var board = [[], [], [], [], [], [], [], [], []] 60 | 61 | 62 | let button = document.getElementById('generate-sudoku') 63 | let solve = document.getElementById('solve') 64 | 65 | console.log(arr) 66 | function changeBoard(board) { 67 | for (var i = 0; i < 9; i++) { 68 | for (var j = 0; j < 9; j++) { 69 | if (board[i][j] != 0) { 70 | 71 | arr[i][j].innerText = board[i][j] 72 | } 73 | 74 | else 75 | arr[i][j].innerText = '' 76 | } 77 | } 78 | } 79 | 80 | 81 | button.onclick = function () { 82 | var xhrRequest = new XMLHttpRequest() 83 | xhrRequest.onload = function () { 84 | var response = JSON.parse(xhrRequest.response) 85 | console.log(response) 86 | initializeTemp(temp) 87 | resetColor() 88 | 89 | board = response.board 90 | setTemp(board, temp) 91 | setColor(temp) 92 | changeBoard(board) 93 | } 94 | xhrRequest.open('get', 'https://sugoku.herokuapp.com/board?difficulty=easy') 95 | //we can change the difficulty of the puzzle the allowed values of difficulty are easy, medium, hard and random 96 | xhrRequest.send() 97 | } 98 | 99 | //to be completed by student, function should not return anything 100 | // you can make a call to changeboard(board) function to update the state on the screen 101 | //returns a boolean true of false 102 | 103 | function isSafe(board,r,c,no){ 104 | 105 | 106 | //not repeating in the same row or column 107 | for(var i=0;i<9;i++){ 108 | if(board[i][c]==no || board[r][i]==no){ 109 | return false; 110 | } 111 | } 112 | //subgrid 113 | var sx = r - r%3; 114 | var sy = c - c%3; 115 | 116 | for(var x=sx;x 2 | 3 | 4 | 5 | 6 | 7 | CB Chat List 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 23 |
24 |
25 |
26 |
27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 |
42 |
    43 | 44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 | Click on generate new step to get updates !! 64 | 65 |
66 |
67 | 68 |
69 |
70 | 71 |
72 | 73 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /ChatList-master/ChatHandler.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by aarnavjindal on 07/04/20. 3 | */ 4 | 5 | export { ChatHandler, chat_names} 6 | 7 | const chat_names = ["Prateek Bhaiya", "Arnav Bhaiya", "Munna Bhaiya", "Aarnav Jindal", "Shriya Chhabra", "Akul Jindal", "Abhinav Duggal"]; 8 | const chat_names_length = chat_names.length; 9 | const chat_msg = ["Why didn't he come and talk to me himse...", 10 | "Perfect, I am really glad to hear that!...", 11 | "This is what I understand you're telling me..", 12 | "I’m sorry, I don’t have the info on that.."]; 13 | const chat_msg_length = chat_msg.length; 14 | const chat_img_length = 7; 15 | 16 | class ChatHandler{ 17 | 18 | constructor(chat_template, chat_list){ 19 | this.hashmap = new Map(); 20 | this.linked_list = null; 21 | this.chat_template = chat_template; 22 | this.chat_list = chat_list; 23 | let clock = new Date(); 24 | this.hours = clock.getHours(); 25 | this.mins = clock.getMinutes(); 26 | } 27 | 28 | getTime(){ 29 | // Time Stamp creation for messages 30 | this.mins += 1; 31 | if(this.mins === 60){ 32 | this.hours += 1; 33 | this.mins = 0; 34 | } 35 | 36 | if(this.hours === 24){ 37 | this.hours = 0; 38 | } 39 | 40 | return ("0" + this.hours).slice(-2)+":"+("0" + this.mins).slice(-2); 41 | } 42 | 43 | createNode(id){ 44 | // Creating node element 45 | let node = {}; 46 | // Pointers to prev and next 47 | node['next'] = null; 48 | node['prev'] = null; 49 | // Create a copy of chat template 50 | let chat_item = this.chat_template.cloneNode(true); 51 | // Setting name, message, image to template item 52 | chat_item.querySelector('#Name').innerText = chat_names[id%chat_names_length]; 53 | chat_item.querySelector('#Message').innerText = chat_msg[id%chat_msg_length]; 54 | console.log("./images/avatar" + eval(1+(id%chat_img_length)) + ".png"); 55 | chat_item.querySelector('#Image').src = "./images/avatar" + eval(1+(id%chat_img_length)) + ".png"; 56 | node['chat_item'] = chat_item; 57 | return node; 58 | } 59 | 60 | newMsg(id){ 61 | let node = null; 62 | if((id in this.hashmap ) === false){ 63 | // If node not in linked list 64 | node = this.createNode(id); 65 | this.hashmap[id] = node; 66 | } else{ 67 | // If node in linked list 68 | node = this.getNodeFromList(id); 69 | } 70 | 71 | if(this.linked_list === null){ 72 | // Setting head of empty list 73 | this.linked_list = node; 74 | } else{ 75 | // Adding node to head of linked list 76 | node['next'] = this.linked_list; 77 | if(this.linked_list!==null) 78 | this.linked_list['prev'] = node; 79 | this.linked_list = node; 80 | } 81 | this.updateList(); 82 | } 83 | 84 | deleteMsg(id){ 85 | let node = this.getNodeFromList(id); 86 | // No use of node since it has been deleted 87 | delete this.hashmap[id]; 88 | // Clear entry from hashmap 89 | this.updateList(); 90 | } 91 | 92 | getNodeFromList(id){ 93 | let node = this.hashmap[id]; 94 | let prevNode = node['prev']; 95 | let nextNode = node['next']; 96 | 97 | // Update prev and next node pointers 98 | if(prevNode!==null) 99 | prevNode['next'] = nextNode; 100 | if(nextNode!==null) 101 | nextNode['prev'] = prevNode; 102 | 103 | // Update head of the linked list 104 | if(node===this.linked_list){ 105 | this.linked_list = nextNode; 106 | } 107 | node['next'] = null; 108 | node['prev'] = null; 109 | return node; 110 | } 111 | 112 | updateList(){ 113 | // Update the contents of the chat list 114 | let innerHTML = ''; 115 | let head = this.linked_list; 116 | while(head!==null){ 117 | let element = head['chat_item']; 118 | if(head===this.linked_list){ 119 | element.className = "ks-item ks-active"; 120 | element.querySelector('#Time').innerText = this.getTime(); 121 | } else{ 122 | element.className = "ks-item"; 123 | } 124 | innerHTML += element.outerHTML; 125 | head = head['next']; 126 | } 127 | this.chat_list.innerHTML = innerHTML; 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /chatbot-api/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 10 | 11 | 12 | 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 29 |
30 |
31 |
32 |
33 |
34 | avatar 35 | 36 |
37 |
Chat with CB Bot
38 |
Code your way to Success
39 |
40 |
41 | 42 |
43 |
    44 |
45 | 46 |
47 | 48 |
49 | 50 | 51 |     52 | 53 | 54 | 55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 | 73 | 74 | 85 | 86 |
87 |
88 | 89 | Hey there friends !
90 | This is a simple yet amazing chatbot tutorial
91 | You'll learn about JSON, Javascript promises and APIs
92 | After this tutorial you can even feed your own data to the bot and have fun with it !
93 | So let's begin interacting with the CB Bot.
94 | Send a simple hello message to begin 95 |
96 |
97 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /ChatList-master/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background:#ddd; 3 | height: 100%; 4 | } 5 | 6 | #container{ 7 | width: 100%; 8 | height: 70%; 9 | display: flex; 10 | margin: 0 auto; 11 | } 12 | 13 | .container2 { 14 | width: 50%; 15 | height: 100%; 16 | border: 1px solid lightgray; 17 | display: flex; 18 | flex-wrap: wrap; 19 | align-content: center; 20 | } 21 | 22 | .container3 { 23 | padding: 50px; 24 | display: flex; 25 | flex-wrap: wrap; 26 | align-content: center; 27 | } 28 | 29 | .ks-messenger { 30 | margin: auto; 31 | margin-top: 50px; 32 | display: -webkit-box; 33 | display: -webkit-flex; 34 | display: -ms-flexbox; 35 | display: inline-block; 36 | height: 100%; 37 | } 38 | 39 | .ks-messenger .ks-discussions { 40 | border-radius: 5px 5px 5px 5px; 41 | background: #fff; 42 | width: 340px; 43 | border-right: 1px solid #dee0e1 44 | } 45 | 46 | .ks-messenger .ks-discussions>.ks-header { 47 | display: -webkit-box; 48 | display: -webkit-flex; 49 | display: -ms-flexbox; 50 | display: flex; 51 | -webkit-box-align: center; 52 | -webkit-align-items: center; 53 | -ms-flex-align: center; 54 | align-items: center; 55 | height: 60px; 56 | border-bottom: 1px solid #dee0e1 57 | } 58 | 59 | .ks-messenger .ks-discussions>.ks-search .form-control { 60 | border: none; 61 | padding: 28px 20px 62 | } 63 | 64 | .ks-messenger .ks-discussions>.ks-search .icon-addon { 65 | color: rgba(58, 82, 155, .6) 66 | } 67 | 68 | .ks-messenger .ks-discussions>.ks-body .ks-items { 69 | list-style: none; 70 | padding: 0; 71 | margin: 0 72 | } 73 | 74 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item { 75 | border-bottom: 1px solid #dee0e1 76 | } 77 | 78 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a { 79 | display: -webkit-box; 80 | display: -webkit-flex; 81 | display: -ms-flexbox; 82 | -js-display: flex; 83 | display: flex; 84 | -webkit-box-align: center; 85 | -webkit-align-items: center; 86 | -ms-flex-align: center; 87 | align-items: center; 88 | color: #333; 89 | padding: 15px 20px 90 | } 91 | 92 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-group-amount { 93 | position: relative; 94 | top: 3px; 95 | margin-right: 12px; 96 | width: 36px; 97 | height: 36px; 98 | background-color: rgba(57, 81, 155, .1); 99 | text-align: center; 100 | line-height: 36px; 101 | -webkit-border-radius: 50%; 102 | border-radius: 50% 103 | } 104 | 105 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-group-amount>.ks-badge { 106 | position: absolute; 107 | bottom: -1px; 108 | right: -3px 109 | } 110 | 111 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-avatar { 112 | position: relative; 113 | top: 3px; 114 | margin-right: 12px 115 | } 116 | 117 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-avatar>img { 118 | width: 36px; 119 | height: 36px; 120 | -webkit-border-radius: 50%; 121 | border-radius: 50% 122 | } 123 | 124 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-avatar>.ks-badge { 125 | position: absolute; 126 | bottom: -3px; 127 | right: -3px 128 | } 129 | 130 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-body { 131 | -webkit-box-flex: 1; 132 | -webkit-flex-grow: 1; 133 | -ms-flex-positive: 1; 134 | flex-grow: 1 135 | } 136 | 137 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-body>.ks-message { 138 | font-size: 12px; 139 | color: #858585; 140 | display: -webkit-box; 141 | display: -webkit-flex; 142 | display: -ms-flexbox; 143 | -js-display: flex; 144 | display: flex 145 | } 146 | 147 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-body>.ks-message>img { 148 | position: relative; 149 | top: -2px; 150 | width: 18px; 151 | height: 18px; 152 | margin-right: 5px 153 | } 154 | 155 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-body>.ks-name { 156 | display: -webkit-box; 157 | display: -webkit-flex; 158 | display: -ms-flexbox; 159 | -js-display: flex; 160 | display: flex; 161 | margin-bottom: 4px; 162 | -webkit-box-pack: justify; 163 | -webkit-justify-content: space-between; 164 | -ms-flex-pack: justify; 165 | justify-content: space-between 166 | } 167 | 168 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item>a>.ks-body>.ks-name>.ks-datetime { 169 | text-transform: uppercase; 170 | font-size: 10px; 171 | font-weight: 400; 172 | color: #858585; 173 | position: relative; 174 | top: 3px 175 | } 176 | 177 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item.ks-active { 178 | background: rgba(247, 202, 24, .1); 179 | color: #333; 180 | position: relative 181 | } 182 | 183 | .ks-messenger .ks-discussions>.ks-body .ks-items>.ks-item.ks-active::before { 184 | content: ''; 185 | width: 4px; 186 | height: 100%; 187 | background-color: rgba(222, 187, 12, .2); 188 | display: block; 189 | position: absolute; 190 | top: 0; 191 | left: 0 192 | } -------------------------------------------------------------------------------- /chatbot-api/script.js: -------------------------------------------------------------------------------- 1 | onload = function(){ 2 | // outputs a javascript object from the parsed json 3 | 4 | var chat = { 5 | messageToSend: '', 6 | messageResponses: [ 7 | 'Why did the web developer leave the restaurant? Because of the table layout.', 8 | 'How do you comfort a JavaScript bug? You console it.', 9 | 'An SQL query enters a bar, approaches two tables and asks: "May I join you?"', 10 | 'What is the most used language in programming? Profanity.', 11 | 'What is the object-oriented way to become wealthy? Inheritance.', 12 | 'An SEO expert walks into a bar, bars, pub, tavern, public house, Irish pub, drinks, beer, alcohol' 13 | ], 14 | init: async function() { 15 | this.chatTree = new ChatTree(); 16 | await this.chatTree.init(); 17 | this.cacheDOM(); 18 | this.bindEvents(); 19 | await this.render(); 20 | }, 21 | cacheDOM: function() { 22 | this.$chatHistory = $('.chat-history'); 23 | this.$button = $('button'); 24 | this.$textarea = $('#message-to-send'); 25 | this.$chatHistoryList = this.$chatHistory.find('ul'); 26 | }, 27 | bindEvents: function() { 28 | this.$button.on('click', this.addMessage.bind(this)); 29 | this.$textarea.on('keyup', this.addMessageEnter.bind(this)); 30 | }, 31 | render: async function() { 32 | this.scrollToBottom(); 33 | if (this.messageToSend.trim() !== '') { 34 | var template = Handlebars.compile( $("#message-template").html()); 35 | var context = { 36 | messageOutput: this.messageToSend, 37 | time: this.getCurrentTime() 38 | }; 39 | 40 | this.input = this.messageToSend; 41 | this.$chatHistoryList.append(template(context)); 42 | this.scrollToBottom(); 43 | this.$textarea.val(''); 44 | 45 | // responses 46 | var templateResponse = Handlebars.compile( $("#message-response-template").html()); 47 | var contextResponse = { 48 | response: await this.chatTree.getMessage(this.input), 49 | time: this.getCurrentTime() 50 | }; 51 | 52 | setTimeout(function() { 53 | this.$chatHistoryList.append(templateResponse(contextResponse)); 54 | this.scrollToBottom(); 55 | }.bind(this), 1000); 56 | 57 | } 58 | 59 | }, 60 | 61 | addMessage: function() { 62 | this.messageToSend = this.$textarea.val(); 63 | this.render(); 64 | }, 65 | addMessageEnter: function(event) { 66 | // enter was pressed 67 | if (event.keyCode === 13) { 68 | this.addMessage(); 69 | } 70 | }, 71 | scrollToBottom: function() { 72 | this.$chatHistory.scrollTop(this.$chatHistory[0].scrollHeight); 73 | }, 74 | getCurrentTime: function() { 75 | return new Date().toLocaleTimeString(). 76 | replace(/([\d]+:[\d]{2})(:[\d]{2})(.*)/, "$1$3"); 77 | } 78 | }; 79 | 80 | chat.init(); 81 | }; 82 | 83 | class ChatTree { 84 | 85 | constructor() { 86 | } 87 | 88 | async init(){ 89 | const data = await this.reset(); 90 | this.chat_tree = data; 91 | this.firstMsg = true; 92 | console.log("inside done"); 93 | return "Chat has now been terminated. Send hi to begin chat again !"; 94 | } 95 | 96 | async reset(){ 97 | const response = await fetch("chat_tree.json"); 98 | const jsonResponse = await response.json(); 99 | return jsonResponse; 100 | } 101 | 102 | async getMessage(input){ 103 | let resp = ''; 104 | //input = new String(input.trim()); 105 | //console.log(input); 106 | if(this.firstMsg===true) { 107 | this.firstMsg = false; 108 | resp += "Hey there buddy
"; 109 | } else { 110 | 111 | if(("message" in this.chat_tree) && (input.trim()==="Reset")) { 112 | return this.init(); 113 | } 114 | 115 | if(isNaN(parseInt(input)) || parseInt(input)<=0 || parseInt(input) > this.chat_tree['children'].length+1) 116 | return 'It seems like you gave a wrong input ! Go ahead try again !'; 117 | 118 | if(parseInt(input)-1===this.chat_tree['children'].length){ 119 | this.init(); 120 | } 121 | 122 | this.chat_tree = this.chat_tree['children'][parseInt(input)-1]; 123 | } 124 | 125 | if("message" in this.chat_tree){ 126 | let data; 127 | if(this.chat_tree['type']==="function"){ 128 | // console.log(String(this.chat_tree['message']),String("getJoke()")); 129 | if(this.chat_tree['message']==="getJoke()"){ 130 | data = await eval(this.chat_tree['message']); 131 | data = data.value.joke; 132 | } else{ 133 | data = await eval(this.chat_tree['message']); 134 | data = data.articles[0].title; 135 | } 136 | } else{ 137 | data = this.chat_tree['message']; 138 | } 139 | resp += data; 140 | resp += "

Please input Reset to reset chat now"; 141 | } else { 142 | for (let i in this.chat_tree['child_msg']) { 143 | resp += String(parseInt(i) + 1) + ". " + this.chat_tree['child_msg'][parseInt(i)] + "
"; 144 | } 145 | } 146 | return resp; 147 | } 148 | } 149 | 150 | async function getJoke() { 151 | const response = await fetch('http://api.icndb.com/jokes/random'); 152 | const jsonResp = await response.json(); 153 | return jsonResp; 154 | } 155 | 156 | async function getNews() { 157 | const response = await fetch('http://newsapi.org/v2/top-headlines?country=in&pageSize=1&apiKey=a876816f98574cdfa23ffdc7d531c7bc'); 158 | const jsonResp = await response.json(); 159 | return jsonResp; 160 | } 161 | -------------------------------------------------------------------------------- /PhotoEditor/script.js: -------------------------------------------------------------------------------- 1 | 2 | onload = function () { 3 | const editor = document.getElementById("editor"); 4 | const context = editor.getContext("2d"); 5 | const toolbar = document.getElementById("toolbar"); 6 | 7 | const tools = { 8 | "upload" : function () { 9 | const upload = document.createElement('input'); 10 | upload.type = "file"; 11 | upload.click(); 12 | upload.onchange = function() { 13 | const img = new Image(); 14 | img.onload = () => { 15 | editor.width = img.width; 16 | editor.height = img.height; 17 | context.drawImage(img, 0,0); 18 | }; 19 | img.onerror = () => { 20 | console.error("The provided file couldn't be loaded as an Image media"); 21 | }; 22 | 23 | img.src = URL.createObjectURL(this.files[0]); 24 | }; 25 | }, 26 | "save" : function(){ 27 | const image = editor.toDataURL(); 28 | const link = document.createElement('a'); 29 | link.download = 'image.png'; 30 | link.href = image; 31 | link.click(); 32 | }, 33 | "flipHor" : function(){ 34 | let cols = editor.width; // Width is number of columns 35 | let rows = editor.height; // Height is number of rows 36 | let image = getRGBArray(rows, cols); 37 | 38 | for(let i=0;i=0;i--){ 68 | let row = []; 69 | for(let j=0;j=0;j--){ 85 | row.push(image[j][i]); 86 | } 87 | rimage.push(row); 88 | } 89 | setImageData(rimage, cols, rows); 90 | }, 91 | "resize" : function(){ 92 | let cols = editor.width; // Width is number of columns 93 | let rows = editor.height; // Height is number of rows 94 | let image = getRGBArray(rows, cols); 95 | 96 | let inp = prompt('Current Width : '+cols + '\n' + 'Current Height : '+rows + '\n' + 'Give the new width and height in a space separated manner').split(' '); 97 | if(inp.length!==2){ 98 | alert('Incorrect dimensions in input'); 99 | return; 100 | } 101 | let ncols = parseInt(inp[0]); 102 | let nrows = parseInt(inp[1]); 103 | if(isNaN(ncols) || isNaN(nrows)){ 104 | alert('Input is not a proper number'); 105 | return; 106 | } 107 | 108 | let hratio = rows/nrows; 109 | let wratio = cols/ncols; 110 | 111 | let nimage = []; 112 | for(let i=0;i 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 23 |

24 |
25 | 26 |
27 | 28 |
29 | 30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 |
39 | 40 |
41 |
42 | 43 |
44 | 45 |
46 | 47 |
48 |
49 | 50 |
51 | 52 |
53 | 54 |
55 |
56 | 57 |
58 | 59 |
60 | 61 |
62 | 63 |
64 | 65 |
66 | 67 |
68 | 69 |
70 | 71 |
72 | 73 |
74 |
75 | 76 |
77 | 78 |
79 | 80 |
81 |
82 | 83 |
84 | 85 |
86 | 87 |
88 |
89 | 90 |
91 | 92 |
93 | 94 |
95 | 96 |
97 | 98 |
99 | 100 |
101 | 102 |
103 | 104 |
105 | 106 |
107 |
108 | 109 |
110 | 111 |
112 | 113 |
114 |
115 | 116 |
117 | 118 |
119 | 120 |
121 |
122 | 123 |
124 | 125 |
126 | 127 |
128 | 129 |
130 | 131 |
132 | 133 |
134 | 135 |
136 | 137 |
138 | 139 |
140 |
141 | 142 |
143 | 144 |
145 | 146 |
147 |
148 | 149 |
150 | 151 |
152 | 153 |
154 |
155 | 156 |
157 | 158 |
159 | 160 |
161 | 162 |
163 | 164 |
165 | 166 |
167 |
168 | 169 |
170 | 171 |
172 |
173 | 174 |
175 | 176 |
177 | 178 |
179 |
180 | 181 |
182 | 183 |
184 | 185 |
186 |
187 | 188 |
189 | 190 |
191 | 192 |
193 | 194 |
195 | 196 |
197 | 198 |
199 | 200 |
201 | 202 |
203 | 204 |
205 |
206 | 207 |
208 | 209 |
210 | 211 |
212 |
213 | 214 |
215 | 216 |
217 | 218 |
219 |
220 | 221 |
222 | 223 |
224 | 225 |
226 | 227 |
228 | 229 |
230 | 231 |
232 | 233 |
234 | 235 |
236 | 237 |
238 |
239 | 240 |
241 | 242 |
243 | 244 |
245 |
246 | 247 |
248 | 249 |
250 | 251 |
252 |
253 | 254 |
255 | 256 |
257 | 258 |
259 | 260 |
261 | 262 |
263 | 264 |
265 | 266 |
267 | 268 |
269 | 270 |
271 |
272 | 273 |
274 | 275 |
276 | 277 |
278 |
279 | 280 |
281 | 282 |
283 | 284 |
285 |
286 | 287 |
288 | 289 |
290 | 291 |
292 | 293 |
294 | 295 |
296 | 297 |
298 | 299 |
300 | 301 |
302 | 303 |
304 |
305 | 306 |
307 | 308 |
309 | 310 |
311 |
312 | 313 |
314 | 315 |
316 | 317 |
318 |
319 | 320 |
321 | 322 | 323 |
324 |
325 |
326 |      328 | 329 |
330 | 331 | 332 | 333 | -------------------------------------------------------------------------------- /Sudoku Puzzle/Solution/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 23 |

24 |
25 | 26 |
27 | 28 |
29 | 30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 |
39 | 40 |
41 |
42 | 43 |
44 | 45 |
46 | 47 |
48 |
49 | 50 |
51 | 52 |
53 | 54 |
55 |
56 | 57 |
58 | 59 |
60 | 61 |
62 | 63 |
64 | 65 |
66 | 67 |
68 | 69 |
70 | 71 |
72 | 73 |
74 |
75 | 76 |
77 | 78 |
79 | 80 |
81 |
82 | 83 |
84 | 85 |
86 | 87 |
88 |
89 | 90 |
91 | 92 |
93 | 94 |
95 | 96 |
97 | 98 |
99 | 100 |
101 | 102 |
103 | 104 |
105 | 106 |
107 |
108 | 109 |
110 | 111 |
112 | 113 |
114 |
115 | 116 |
117 | 118 |
119 | 120 |
121 |
122 | 123 |
124 | 125 |
126 | 127 |
128 | 129 |
130 | 131 |
132 | 133 |
134 | 135 |
136 | 137 |
138 | 139 |
140 |
141 | 142 |
143 | 144 |
145 | 146 |
147 |
148 | 149 |
150 | 151 |
152 | 153 |
154 |
155 | 156 |
157 | 158 |
159 | 160 |
161 | 162 |
163 | 164 |
165 | 166 |
167 |
168 | 169 |
170 | 171 |
172 |
173 | 174 |
175 | 176 |
177 | 178 |
179 |
180 | 181 |
182 | 183 |
184 | 185 |
186 |
187 | 188 |
189 | 190 |
191 | 192 |
193 | 194 |
195 | 196 |
197 | 198 |
199 | 200 |
201 | 202 |
203 | 204 |
205 |
206 | 207 |
208 | 209 |
210 | 211 |
212 |
213 | 214 |
215 | 216 |
217 | 218 |
219 |
220 | 221 |
222 | 223 |
224 | 225 |
226 | 227 |
228 | 229 |
230 | 231 |
232 | 233 |
234 | 235 |
236 | 237 |
238 |
239 | 240 |
241 | 242 |
243 | 244 |
245 |
246 | 247 |
248 | 249 |
250 | 251 |
252 |
253 | 254 |
255 | 256 |
257 | 258 |
259 | 260 |
261 | 262 |
263 | 264 |
265 | 266 |
267 | 268 |
269 | 270 |
271 |
272 | 273 |
274 | 275 |
276 | 277 |
278 |
279 | 280 |
281 | 282 |
283 | 284 |
285 |
286 | 287 |
288 | 289 |
290 | 291 |
292 | 293 |
294 | 295 |
296 | 297 |
298 | 299 |
300 | 301 |
302 | 303 |
304 |
305 | 306 |
307 | 308 |
309 | 310 |
311 |
312 | 313 |
314 | 315 |
316 | 317 |
318 |
319 | 320 |
321 | 322 | 323 |
324 |
325 |
326 |      328 | 329 |
330 | 331 | 332 | 333 | -------------------------------------------------------------------------------- /TravelPath/practice.js: -------------------------------------------------------------------------------- 1 | onload = function () { 2 | // create a network 3 | var curr_data; 4 | var sz; 5 | var container = document.getElementById('mynetwork'); 6 | var container2 = document.getElementById('mynetwork2'); 7 | var genNew = document.getElementById('generate-graph'); 8 | var solve = document.getElementById('solve'); 9 | var temptext = document.getElementById('temptext'); 10 | var temptext2 = document.getElementById('temptext2'); 11 | // initialise graph options 12 | var options = { 13 | edges: { 14 | labelHighlightBold: true, 15 | font: { 16 | size: 20 17 | } 18 | }, 19 | nodes: { 20 | font: '12px arial red', 21 | scaling: { 22 | label: true 23 | }, 24 | shape: 'icon', 25 | icon: { 26 | face: 'FontAwesome', 27 | code: '\uf015', 28 | size: 40, 29 | color: '#991133', 30 | } 31 | } 32 | }; 33 | // initialize your network! 34 | var network = new vis.Network(container); 35 | network.setOptions(options); 36 | var network2 = new vis.Network(container2); 37 | network2.setOptions(options); 38 | 39 | function createData(){ 40 | sz = Math.floor(Math.random() * 8) + 3; 41 | const cities = ['Delhi', 'Mumbai', 'Gujarat', 'Goa', 'Kanpur', 'Jammu', 'Hyderabad', 'Bangalore', 'Gangtok', 'Meghalaya']; 42 | let nodes = []; 43 | for(let i=1;i<=sz;i++){ 44 | nodes.push({id:i, label: cities[i-1]}) 45 | } 46 | nodes = new vis.DataSet(nodes); 47 | 48 | let edges = []; 49 | for(let i=2;i<=sz;i++){ 50 | let neigh = i - Math.floor(Math.random()*Math.min(i-1,3)+1); 51 | edges.push({type: 0, from: i, to: neigh, color: 'orange',label: String(Math.floor(Math.random()*70)+31)}); 52 | } 53 | 54 | src = 1; 55 | dst = sz; 56 | 57 | for(let i=1;i<=sz/2;){ 58 | let n1 = Math.floor(Math.random()*sz)+1; 59 | let n2 = Math.floor(Math.random()*sz)+1; 60 | if(n1!=n2){ 61 | if(n1dist[mn][0]+edge[1]){ 143 | dist[edge[0]][0] = dist[mn][0]+edge[1]; 144 | dist[edge[0]][1] = mn; 145 | } 146 | } 147 | } 148 | 149 | return dist; 150 | } 151 | 152 | function solveData(sz) { 153 | let data = curr_data; 154 | let graph = []; 155 | for(let i=1;i<=sz;i++){ 156 | graph.push([]); 157 | } 158 | 159 | for(let i=0;i