Skip to content
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

Update ChessBoard.py #401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions Chess Board/ChessBoard.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,63 @@
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
from matplotlib.patches import Rectangle

dx, dy = 0.015, 0.05
# numpy.arange returns evenly spaced values within a given interval
x = np.arange(-4.0, 4.0, dx) # Corrected -04.0 to -4.0
y = np.arange(-4.0, 4.0, dy) # Corrected -04.0 to -4.0
# returns coordinate matrices from coordinate vectors
X, Y = np.meshgrid(x, y)
# Chess symbols for pieces (Unicode)
chess_pieces = {
"rook_white": "\u2656",
"rook_black": "\u265C",
"pawn_white": "\u2659",
"pawn_black": "\u265F",
}

extent = np.min(x), np.max(x), np.min(y), np.max(y)
# Initial piece positions for demonstration
initial_pieces = [
(0, 0, chess_pieces["rook_black"]),
(0, 7, chess_pieces["rook_black"]),
(7, 0, chess_pieces["rook_white"]),
(7, 7, chess_pieces["rook_white"]),
(1, 0, chess_pieces["pawn_black"]),
(1, 7, chess_pieces["pawn_black"]),
(6, 0, chess_pieces["pawn_white"]),
(6, 7, chess_pieces["pawn_white"]),
]

Z1 = np.add.outer(range(8), range(8)) % 2
# Function to draw the chessboard
def draw_chessboard(highlight_squares=None):
board_size = 8
chessboard = np.add.outer(range(board_size), range(board_size)) % 2

plt.imshow(Z1, cmap="binary_r", interpolation="nearest", extent=extent, alpha=1)
fig, ax = plt.subplots(figsize=(8, 8))
ax.imshow(chessboard, cmap="cividis", interpolation="nearest")

plt.title("Chess Board", fontweight="bold")
# Remove axes for a cleaner look
ax.set_xticks([])
ax.set_yticks([])

plt.show()
# Add grid lines to separate the squares
for i in range(board_size + 1):
ax.axhline(i - 0.5, color="black", linewidth=1, alpha=0.7)
ax.axvline(i - 0.5, color="black", linewidth=1, alpha=0.7)

# Highlight specific squares
if highlight_squares:
for (row, col) in highlight_squares:
ax.add_patch(Rectangle((col - 0.5, row - 0.5), 1, 1, color="yellow", alpha=0.4))

# Add chess pieces
for row, col, piece in initial_pieces:
ax.text(col, row, piece, fontsize=28, ha="center", va="center", color="black" if (row + col) % 2 == 0 else "white")

# Add coordinate labels
for i in range(board_size):
ax.text(-0.8, i, str(8 - i), fontsize=12, va="center") # Row labels
ax.text(i, 8 - 0.3, chr(65 + i), fontsize=12, ha="center") # Column labels

# Title
ax.set_title("Chess Board", fontweight="bold", fontsize=16)

plt.show()

# Highlight squares (optional demo)
highlight = [(0, 0), (7, 7), (3, 3)] # Example of squares to highlight
draw_chessboard(highlight_squares=highlight)
58 changes: 25 additions & 33 deletions Website Cloner/index.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>PROXY SERVER</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./util.css">
<link rel="stylesheet" type="text/css" href="./main.css">
<title>PROXY SERVER</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./util.css">
<link rel="stylesheet" type="text/css" href="./main.css">
</head>
<body>
<div class="limiter">
<div class="container-login0">
<div class="wrap-login0" style="width: 500px">
<form class="login0-form validate-form" method="post" style="width: 100%">
<div class="wrap-input0">
<input class="input0" type="text" id="link" placeholder="ENTER LINK" required>
<span class="focus-input0"></span>
<span class="symbol-input0">
<i class="fa fa-pencil" aria-hidden="true"></i>
</span>
</div>

<div class="container-login0-form-btn">
<button class="login0-form-btn" id="proxyButton" name="submitButton" type="submit" value="" onclick="proxy()">
CLONE NOW
</button>
</div>
</form>
</div>
</div>
</div>

<script>
function proxy() {
let link = document.getElementById("link").value;
document.getElementById("proxyButton").value = link;
}
</script>
<div class="limiter">
<div class="container-login0">
<div class="wrap-login0" style="width: 500px">
<form class="login0-form validate-form" method="post" action="/" style="width: 100%">
<div class="wrap-input0">
<input class="input0" type="text" id="link" name="submitButton" placeholder="ENTER LINK" required>
<span class="focus-input0"></span>
<span class="symbol-input0">
<i class="fa fa-pencil" aria-hidden="true"></i>
</span>
</div>
<div class="container-login0-form-btn">
<button class="login0-form-btn" type="submit">
CLONE NOW
</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
67 changes: 44 additions & 23 deletions Website Cloner/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,52 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.path = "index.html"
return http.server.SimpleHTTPRequestHandler.do_GET(self)
try:
return http.server.SimpleHTTPRequestHandler.do_GET(self)
except FileNotFoundError:
self.send_error(404, "File not found")

def do_POST(self):
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': self.headers['Content-Type'],
})
url = form.getvalue('submitButton')
urlN = 'https://' + str(url) +'/'
isdir = os.path.isdir(url)
if not isdir:
kwargs = {'project_name': url}
save_webpage(
url=urlN,
project_folder='./',
**kwargs
)
path = url + "/" + url + "/index.html"
content_length = int(self.headers.get('Content-Length', 0))
post_data = self.rfile.read(content_length).decode("utf-8")

# Parse the URL from the form submission
form = cgi.parse_qs(post_data)
url = form.get("submitButton", [""])[0]

if not url:
self.send_error(400, "Bad Request: URL is missing")
return

urlN = "https://" + url.strip("/")
project_folder = os.path.join('./cloned_sites', url.replace("https://", "").replace("http://", ""))

if not os.path.isdir(project_folder):
os.makedirs(project_folder, exist_ok=True)
try:
save_webpage(
url=urlN,
project_folder=project_folder,
project_name=url.replace("https://", "").replace("http://", "")
)
except Exception as e:
self.send_error(500, f"Error cloning website: {e}")
return

path = os.path.join(project_folder, "index.html")
if not os.path.isfile(path):
self.send_error(404, "Cloned page not found")
return

self.send_response(301)
self.send_header('Location', path)
self.send_header("Location", "/" + path)
self.end_headers()
return http.server.SimpleHTTPRequestHandler.do_GET(self)


PORT = 7000
s = socketserver.TCPServer(("127.0.0.1", PORT), RequestHandler)
s.serve_forever()
os.chdir(os.path.dirname(os.path.abspath(__file__)))

with socketserver.TCPServer(("127.0.0.1", PORT), RequestHandler) as s:
s.allow_reuse_address = True
print(f"Server running on http://127.0.0.1:{PORT}")
s.serve_forever()