-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex backup
More file actions
278 lines (264 loc) · 9.14 KB
/
Copy pathindex backup
File metadata and controls
278 lines (264 loc) · 9.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DSA Learning Hub</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.12/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.12/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.12/mode/javascript/javascript.min.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f9f9f9;
color: #333;
}
header {
background-color: #4CAF50;
color: white;
padding: 20px;
/* text-align: center; */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
header h1 {
font-size: 2.5em;
margin: 0;
margin-left: 20px;
}
header p {
font-size: 1.2em;
margin: 10px 0;
}
main {
display: flex;
}
/* Sidebar Styling */
.sidebar {
width: 250px;
background-color: #333;
color: white;
padding: 20px;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
height: 100vh;
}
.sidebar h2 {
margin: 0;
font-size: 1.5em;
margin-bottom: 20px;
}
.menu-item {
margin-bottom: 15px;
}
.menu-item > button {
background: none;
border: none;
color: white;
text-align: left;
padding: 10px;
width: 100%;
font-size: 16px;
cursor: pointer;
}
.menu-item button:hover {
background-color: #4CAF50;
}
.submenu {
margin-left: 15px;
display: none;
}
.submenu a {
display: block;
color: #f9f9f9;
text-decoration: none;
padding: 5px 0;
}
.submenu a:hover {
color: #4CAF50;
}
/* Main Content */
.content {
flex-grow: 1;
padding: 30px;
}
.output-container {
margin-top: 30px;
background: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.CodeMirror {
border: 1px solid #ddd;
height: 200px;
font-size: 16px;
}
#codeOutput {
margin-top: 20px;
background: #f4f4f4;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-family: monospace;
}
footer {
text-align: center;
padding: 15px 0;
background-color: #333;
color: white;
}
footer p {
margin: 0;
}
.headerTitle{
justify-content: space-between;
}
</style>
</head>
<body>
<header>
<div class="headerTitle">
<h1>DSA Learning Hub</h1>
<p>Master Data Structures and Algorithms Step by Step</p>
</div>
</header>
<main>
<!-- Sidebar -->
<div class="sidebar">
<!-- <h2>Menu</h2> -->
<div id="sidebarMenu">
<!-- Dynamic Menu Items will be injected here -->
</div>
</div>
<!-- Content Section -->
<div class="content">
<section>
<h2>API Endpoints</h2>
<button onclick="fetchInfo()">Fetch Info</button>
<button onclick="fetchArray()">Fetch Array</button>
<button onclick="fetchArraySum()">Fetch Sum Of Array</button>
</section>
<section class="output-container">
<h2>API Response</h2>
<div id="output">Click a button to see the response</div>
</section>
<section class="output-container">
<h2>Code Editor</h2>
<textarea id="codeEditor">// Write your code here...</textarea>
<button onclick="runCode()">Run Code</button>
<div id="codeOutput">Output will appear here...</div>
</section>
</div>
</main>
<footer>
<p>© 2024 DSA Learning Hub. All Rights Reserved.</p>
</footer>
<script>
const menuData = [
{
title: "DSA Topics",
subMenu: [
{ name: "Arrays", link: "dsa-problems" },
{ name: "Linked Lists", link: "#linkedLists" },
{ name: "Trees", link: "#trees" }
]
},
{
title: "Basic Math",
subMenu: [
{ name: "Trigonometry", link: "Trigonometry" },
{ name: "Algebra", link: "Algebra" },
{ name: "Geometry", link: "Geometry" },
{ name: "Calculus", link: "Calculus" },
{ name: "Statistics", link: "Statistics" },
{ name: "Competitive Exams", link: "CompetitiveExams" },
]
},
{
title: "Advanced Topics",
subMenu: [
{ name: "Dynamic Programming", link: "#dynamicProgramming" },
{ name: "Graphs", link: "#graphs" },
{ name: "Sorting Algorithms", link: "#sorting" }
]
},
{
title: "Examples",
subMenu: [
{ name: "Reverse a Linked List", link: "example" },
{ name: "Reverse a String", link: "ReverseString" },
// { name: "Graphs", link: "#graphs" },
// { name: "Sorting Algorithms", link: "#sorting" }
]
},
{
title: "Tutorial",
subMenu: [
{ name: "React.js Tutorial", link: "react_tutorial" },
{ name: "Node.js Tutorial", link: "node_tutorial" },
{ name: "JavaScript Tutorial", link: "JavaScript_tutorial" }
]
}
];
// Generate Sidebar
const sidebarMenu = document.getElementById("sidebarMenu");
menuData.forEach(menu => {
const menuItem = document.createElement("div");
menuItem.classList.add("menu-item");
const button = document.createElement("button");
button.textContent = menu.title;
const submenu = document.createElement("div");
submenu.classList.add("submenu");
menu.subMenu.forEach(sub => {
const link = document.createElement("a");
link.href = sub.link;
link.textContent = sub.name;
submenu.appendChild(link);
});
button.addEventListener("click", () => {
submenu.style.display = submenu.style.display === "none" || !submenu.style.display ? "block" : "none";
});
menuItem.appendChild(button);
menuItem.appendChild(submenu);
sidebarMenu.appendChild(menuItem);
});
// Fetch Functions
async function fetchInfo() {
const response = await fetch('https://dsa-07qz.onrender.com/info');
const data = await response.json();
document.getElementById('output').textContent = JSON.stringify(data, null, 2);
}
async function fetchArray() {
const response = await fetch('https://dsa-07qz.onrender.com/array/array');
const data = await response.json();
document.getElementById('output').textContent = JSON.stringify(data, null, 2);
}
async function fetchArraySum() {
const response = await fetch('https://dsa-07qz.onrender.com/array/arraySum');
const data = await response.json();
document.getElementById('output').textContent = JSON.stringify(data, null, 2);
}
// Initialize CodeMirror
document.addEventListener("DOMContentLoaded", () => {
const editor = CodeMirror.fromTextArea(document.getElementById("codeEditor"), {
mode: "javascript",
theme: "default",
lineNumbers: true,
matchBrackets: true,
autoCloseBrackets: true,
tabSize: 4,
});
window.runCode = () => {
const userCode = editor.getValue();
try {
const result = eval(userCode); // Use eval cautiously
document.getElementById("codeOutput").textContent = result;
} catch (error) {
document.getElementById("codeOutput").textContent = `Error: ${error.message}`;
}
};
});
</script>
</body>
</html>