Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DhanushNehru committed Apr 26, 2024
1 parent 05d55a9 commit d380348
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 152 deletions.
11 changes: 11 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: npm install && npm run build
command: npm run start


20 changes: 14 additions & 6 deletions notes.txt → NOTES.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
Python3 Code:
## Python3 Code:

Business case problem: calculating the total revenue from a list of sales transactions.

```
def calculate_total_revenue(sales):
total_revenue = 0
for item, price in sales:
total_revenue += price
return total_revenue
```

# Example usage: This would be given as inputs
### Example usage: This would be given as inputs

```
sales = [("Product A", 10), ("Product B", 20), ("Product C", 15)]
total_revenue = calculate_total_revenue(sales)
print("Total Revenue:", total_revenue)
```


Javascript Code:
## Javascript Code:

Shortest path between multiple locations on a map

```
function calculateTotalDistance(locations) {
// Helper function to calculate distance between two points (using Euclidean distance for simplicity)
function distance(point1, point2) {
Expand Down Expand Up @@ -60,8 +65,11 @@ function calculateTotalDistance(locations) {
return shortestDistance;
}
```

// Example usage: Would be passed as inputs
### Example usage: Would be passed as inputs

```
const locations = [
{ x: 0, y: 0 },
{ x: 1, y: 2 },
Expand All @@ -71,4 +79,4 @@ const locations = [
const totalDistance = calculateTotalDistance(locations);
console.log("Total Distance in meters:", totalDistance);

```
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ Contributions are welcome! Feel free to submit pull requests or open issues.

In the cloud-free development environment where you can directly start coding.

The below command will open up the index.html in a browser in gitpod
`python -m http.server 8000`

You can use Gitpod in the cloud [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/DhanushNehru/CustomCodeEditor/)

----
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 1 addition & 22 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,4 @@
to {
transform: rotate(360deg);
}
}

/**
.output pre {
background-color: #e35757;
padding: 10px;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.output pre:hover {
background-color: #9d4444;
}
**/
}
92 changes: 1 addition & 91 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,18 @@
// import { useState, useRef } from 'react'
// import Editor from "@monaco-editor/react"
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import LandingPage from './components/LandingPage';
import EditorComponent from './components/EditorComponent'; // Your refactored code
// import Documentation from './components/Documentation';
import EditorComponent from './components/EditorComponent';

import './App.css'
/**
const submitUrl = "http://13.233.194.10:2358/submissions";
const LANGUAGE_ID_FOR_JAVASCRIPT = 63;
*/

function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/editor" element={<EditorComponent />} />
{/* <Route path="/documentation" element={<Documentation />} /> */}
</Routes>
</BrowserRouter>
);
}

/**
function App() {
const [code, setCode] = useState(null); // change to "index.html"
const editorRef = useRef(null);
const [output, setOutput] = useState("");
function handleEditorDidMount(editor, monaco) {
editorRef.current = editor;
}
async function submitCode() {
const codeToSubmit = editorRef.current.getValue();
console.log(" Code to submit ",codeToSubmit )
try {
const response = await fetch(submitUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
source_code: codeToSubmit,
language_id: LANGUAGE_ID_FOR_JAVASCRIPT,
stdin: "", // Input for the code (if any)
expected_output: "", // Expected output for the code (if any)
}),
});
if (!response.ok) {
throw new Error(`Failed to create submission. Status code: ${response.status}`);
}
const data = await response.json();
const submissionId = data['token'];
console.log(`Submission created successfully. ID: ${submissionId}`);
setTimeout(() => {
fetch(`${submitUrl}/${submissionId}`)
.then(response => response.json())
.then(data => {
console.log(" DATA ", data)
console.log("Output:", data.stdout);
setOutput(data.stdout)
})
.catch(error => {
console.error("Error retrieving output:", error.message);
});
}, 2000); // Delay added to give Judge0 some time to process the submission
} catch (error) {
console.error("Error:", error.message);
setOutput("Error: " + error.message); // Display error in the output
}
}
return (
<div className="App">
<Editor
height="50vh"
width="100%"
theme="vs-dark"
onMount={handleEditorDidMount}
// path={file.name}
// defaultLanguage={file.language}
// defaultValue={file.value}
value={code} // Set initial value
onChange={(value) => setCode(value)} // Update code state on change
language="javascript" // Set default language to JavaScript
/>
<button onClick={submitCode}>
Run Code
</button>
<div className="output">
<pre><p>{output}</p></pre>
</div>
</div>
)
}
*/

export default App
21 changes: 0 additions & 21 deletions src/EmbeddedUrl.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
// import EmbeddedUrl from "./EmbeddedUrl";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
{/* <EmbeddedUrl url="https://www.google.com" /> */}
</React.StrictMode>
);

Expand Down

0 comments on commit d380348

Please sign in to comment.