-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples added for testing #4
base: testing-pr
Are you sure you want to change the base?
Changes from all commits
2cd4fda
8d80e37
70da3e7
c40cb65
d6cc9ea
7e4534f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
require "./includes/common.php"; | ||
?> | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" > | ||
|
||
|
||
<!--jQuery library--> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
|
||
|
||
<!--Latest compiled and minified JavaScript--> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Navbar in Bootstrap</title> | ||
|
||
<link rel="stylesheet" href="css/style.css"> | ||
|
||
|
||
</head> | ||
<body> | ||
<nav class="navbar navbar-inverse navbar-fixed-top"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="index.php">Lifestyle Store</a> | ||
</div> | ||
<div class="collapse navbar-collapse" id="myNavbar"> | ||
<ul class="nav navbar-nav navbar-right"> | ||
<li><a href="signup.php"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li> | ||
<li><a href="login.php"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
|
||
<div class="container"> | ||
|
||
|
||
<div class="row_style"> | ||
|
||
<h2> | ||
Sign Up | ||
</h2> | ||
<form method="POST" action="signup_script.php"> | ||
<div class="form-group"> | ||
<input class="form-control" placeholder="Name" name="name" pattern="^[A-Za-z\s]{1,}[\.]{0,1}[A-Za-z\s]{0,}$" required> </div> | ||
|
||
<div class="form-group"> | ||
<input type="email" class="form-control" placeholder="Email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" name="email" required> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="password" class="form-control" placeholder="Password" name="password" required = "true" pattern=".{6,}"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="tel" class="form-control" name="contact" placeholder="Contact" maxlength="10" size="10" required="true" pattern="[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="text" class="form-control" name="city" placeholder="City"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="text" class="form-control" name="address" placeholder="Address"> | ||
Comment on lines
+51
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The form in abc.php lacks CSRF protection, making it vulnerable to Cross-Site Request Forgery attacks. Without a CSRF token, an attacker could trick a user into submitting this form without their knowledge, leading to unauthorized actions on their behalf.
|
||
</div> | ||
</form> | ||
<div class="btn-signup"> | ||
<button class="btn btn-primary">Submit</button> | ||
Comment on lines
+51
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The form in abc.php lacks CSRF protection, making it vulnerable to cross-site request forgery attacks. This vulnerability can allow attackers to submit unwanted actions on behalf of a logged-in user without their consent.
|
||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
<?php | ||
include './includes/footer.php'; | ||
?> | ||
</body> | ||
</html> | ||
Comment on lines
+1
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: The PHP file is located within a Python project directory, which might confuse developers and maintainers regarding its purpose and functionality.
Comment on lines
+1
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The file is mislabeled and placed in a Python directory, yet it contains PHP code. Ensure files are correctly named and placed in their respective directories according to the project's language-specific organization standards.
Comment on lines
+1
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: The PHP opening and closing tags are unnecessary when the entire file contains PHP code. It's a best practice to omit the closing tag to prevent accidental whitespace or new lines being sent to the browser, which could cause issues with headers.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from flask import Flask, render_template, request, redirect, url_for | ||
|
||
app = Flask(__name__) | ||
|
||
tasks = [] | ||
|
||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html', tasks=tasks) | ||
|
||
|
||
@app.route('/add', methods=['POST']) | ||
def add(): | ||
task = request.form.get('task') | ||
tasks.append(task) | ||
return redirect(url_for('index')) | ||
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization Issue: Directly appending tasks to a global 'tasks' list in a Flask app can lead to race conditions and inconsistent state in a multi-threaded or multi-process deployment environment. This approach does not scale and can lead to data loss or corruption.
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The current implementation of adding tasks and then redirecting to the index route can lead to scalability issues under high load, as each addition requires a full reload of the page. This can cause unnecessary load on the server due to the repeated rendering of the entire task list.
|
||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) | ||
Comment on lines
+1
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The Flask application's global variable 'tasks' is used to store tasks in a list. This approach does not scale well with a large number of concurrent requests or a large volume of tasks because it relies on a single process and does not facilitate easy distribution across multiple servers or processes.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def binary_search(arr, target): | ||
low, high = 0, len(arr) - 1 | ||
|
||
while low >= high: | ||
mid = (low - high) // 2 | ||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The condition in the while loop and the calculation of mid are incorrect for a binary search algorithm. This will lead to an infinite loop if low is greater than high. Additionally, the calculation of mid should be based on low and high values.
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization Issue: The condition in the while loop is incorrect ('while low >= high:') and the calculation of 'mid' is incorrect ('mid = (low - high) // 2'). This will cause an infinite loop or incorrect behavior in the binary search algorithm.
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance Issue: The binary search implementation contains a critical logical error in the condition of the while loop and the calculation of the mid index. The condition should be 'low <= high' instead of 'low >= high', and the calculation of mid should be '(low + high) // 2' instead of '(low - high) // 2'. This incorrect logic will prevent the binary search from functioning correctly, as it will not properly divide the array to search for the target value.
|
||
if arr[mid] == target: | ||
return mid | ||
elif arr[mid] < target: | ||
low = mid + 1 | ||
else: | ||
high = mid - 1 | ||
|
||
return -1 | ||
|
||
# Example usage | ||
sorted_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12] | ||
target_value = 12 | ||
result = binary_search(sorted_array, target_value) | ||
|
||
if result != -1: | ||
print(f"Element {target_value} found at index {result}") | ||
else: | ||
print("Element not found") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Todo List</title> | ||
</head> | ||
<body> | ||
<h1>Todo List</h1> | ||
<ul> | ||
{% for task in tasks %} | ||
<li>{{ task }}</li> | ||
{% endfor %} | ||
</ul> | ||
<form action="/add" method="post"> | ||
<label for="task">Add Task:</label> | ||
<input type="text" id="task" name="task" required> | ||
<button type="submit">Add</button> | ||
</form> | ||
<form action="/add" method="post"> | ||
<label for="task">Add Task:</label> | ||
<input type="text" id="task" name="task" required> | ||
<button type="submit">Add</button> | ||
</form> | ||
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The form action is duplicated, which might be an error. Ensure that forms are uniquely identified and necessary. Reducing redundancy can improve maintainability and reduce potential for bugs.
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: Duplicate form sections for adding a task. This redundancy might cause confusion and maintenance issues. It seems like an unintentional copy-paste error.
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The form for adding tasks is duplicated. Remove the duplicate to avoid confusion and potential errors in task submission.
Comment on lines
+20
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: The form action is duplicated, which could lead to confusion and maintenance issues. There's a repeated form for adding a task that should be consolidated into a single form or differentiated if serving different purposes.
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Node: | ||
def __init__(self, data): | ||
self.data = data | ||
self.next = None | ||
|
||
class LinkedList: | ||
def __init__(self): | ||
self.head = None | ||
|
||
def append(self, data): | ||
new_node = Node(data) | ||
if not self.head: | ||
self.head = new_node | ||
return | ||
last_node = self.head | ||
while last_node.next: | ||
last_node = last_node.next | ||
last_node.next = new_node | ||
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The append method lacks efficiency when traversing the entire list to find the last node. Consider maintaining a tail pointer to append nodes in constant time.
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization Issue: The 'append' method iterates over the entire list to find the last node, which results in O(n) time complexity for each append operation. This is inefficient, especially for long lists.
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The append method in the LinkedList implementation iterates over the entire list to find the last node, which can be inefficient for very large lists. This linear time complexity operation affects the scalability of list operations.
|
||
|
||
def display(self): | ||
current_node = self.head | ||
while current_node: | ||
print(current_node.data, end=" -> ") | ||
current_node = current_node.next | ||
print("None") | ||
|
||
# Example usage | ||
linked_list = LinkedList() | ||
linked_list.append(1) | ||
linked_list.append(2) | ||
linked_list.append(3) | ||
linked_list.display() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import heapq | ||
|
||
class TaskManager: | ||
def __init__(self): | ||
self.tasks = [] | ||
self.task_id_counter = 1 | ||
|
||
def add_task(self, priority, description): | ||
task = (priority, self.task_id_counter, description) | ||
heapq.heappush(self.tasks, task) | ||
self.task_id_counter += 1 | ||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Using a tuple for tasks introduces potential issues with readability and future modifications. Consider defining a Task class to improve code clarity and facilitate enhancements.
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The 'add_task' method does not validate the priority or description of tasks before adding them to the queue, potentially allowing the insertion of invalid or malicious data.
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The current implementation of adding tasks to a priority queue does not account for potential scalability issues with a large number of tasks. The use of a simple list structure with heapq for priority management can become inefficient as the list grows, due to the underlying operations of heapify which have O(log n) complexity for insertion.
|
||
|
||
def get_next_task(self): | ||
if self.tasks: | ||
return heapq.heappop(self.tasks) | ||
else: | ||
return None | ||
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: Returning 'None' directly from 'get_next_task' when there are no tasks. This could be improved by raising an exception for better error handling in the calling code.
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization Issue: The 'get_next_task' method returns 'None' when there are no tasks available. This approach might not be informative for debugging or logging purposes, as it does not distinguish between an empty queue and a successful operation returning 'None'.
|
||
|
||
def display_tasks(self): | ||
print("Current Tasks:") | ||
for task in self.tasks: | ||
print(f"Task ID: {task[1]}, Priority: {task[0]}, Description: {task[2]}") | ||
|
||
# Example Usage | ||
if __name__ == "__main__": | ||
task_manager = TaskManager() | ||
|
||
task_manager.add_task(2, "Implement feature A") | ||
task_manager.add_task(1, "Fix bug in module B") | ||
task_manager.add_task(3, "Write documentation") | ||
|
||
task_manager.display_tasks() | ||
|
||
next_task = task_manager.get_next_task() | ||
if next_task: | ||
print(f"Next Task: Priority {next_task[0]}, Description: {next_task[2]}") | ||
else: | ||
print("No tasks available.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class Stack: | ||
def __init__(self): | ||
self.items = [] | ||
|
||
def is_empty(self): | ||
return self.items == [] | ||
|
||
def push(self, item): | ||
self.items.append(item) | ||
|
||
def pop(self): | ||
if not self.is_empty(): | ||
return self.items.pop() | ||
else: | ||
return "Stack is empty" | ||
Comment on lines
+11
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The 'pop' method returns a custom string "Stack is empty" when trying to pop from an empty stack, which could lead to unexpected behavior or errors in the application logic, as it mixes the data types returned by this method.
Comment on lines
+11
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: The pop method's handling of an empty stack could be improved for clarity. Returning a string "Stack is empty" when attempting to pop from an empty stack mixes the concerns of data handling and user interface logic.
|
||
|
||
def peek(self): | ||
if not self.is_empty(): | ||
return self.items[-1] | ||
else: | ||
return "Stack is empty" | ||
|
||
def size(self): | ||
return len(self.items) | ||
|
||
|
||
def evaluate_postfix(expression): | ||
stack = Stack() | ||
operators = {'+': lambda x, y: x + y, '-': lambda x, y: x - y, '*': lambda x, y: x * y, '/': lambda x, y: x / y} | ||
|
||
for char in expression.split(): | ||
if char.isdigit(): | ||
stack.push(int(char)) | ||
elif char in operators: | ||
operand2 = stack.pop() | ||
operand1 = stack.pop() | ||
result = operators[char](operand1, operand2) | ||
stack.push(result) | ||
|
||
return stack.pop() | ||
Comment on lines
+27
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The method evaluate_postfix does not handle errors that may arise from invalid expressions, such as attempting to pop from an empty stack. Implement error handling to manage such cases gracefully.
Comment on lines
+27
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance Issue: The 'evaluate_postfix' function does not handle cases where there are insufficient operands for an operator, which can lead to a 'pop from empty list' error. This lack of error handling can cause the application to crash, leading to potential denial of service or other reliability issues.
Comment on lines
+27
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The evaluate_postfix function does not consider concurrency, which could lead to scalability issues when evaluating multiple expressions simultaneously in a multi-threaded or multi-process environment. The shared use of a single instance of Stack without thread-safe operations can lead to race conditions and incorrect computations.
Comment on lines
+27
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization Issue: The 'evaluate_postfix' function does not handle cases where there are not enough operands in the stack for an operation, which can lead to an error when trying to pop from an empty stack. This lack of error handling can cause the program to crash on invalid input.
|
||
|
||
|
||
if __name__ == "__main__": | ||
postfix_expression = "4 5 * +" | ||
result = evaluate_postfix(postfix_expression) | ||
print("Result of evaluating postfix expression {}: {}".format(postfix_expression, result)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Including external resources like CSS and JS directly from URLs can lead to security risks such as reliance on third-party servers and potential for man-in-the-middle attacks. Consider hosting these resources locally or using a trusted CDN with integrity checks.
Code Suggestion: