Compare commits
3 Commits
main
...
c++-crow-b
| Author | SHA1 | Date | |
|---|---|---|---|
| 6360b41e9a | |||
| 217adf91e9 | |||
| a7404fed3d |
9
.gitignore
vendored
@@ -1,7 +1,2 @@
|
||||
.venv
|
||||
.env
|
||||
flask_session
|
||||
__pycache__
|
||||
.vscode
|
||||
db
|
||||
app.log
|
||||
build/
|
||||
.vscode/
|
||||
6
.gitmodules
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[submodule "thirdparty/inja"]
|
||||
path = thirdparty/inja
|
||||
url = https://github.com/pantor/inja
|
||||
[submodule "thirdparty/nlohmann"]
|
||||
path = thirdparty/nlohmann
|
||||
url = https://github.com/nlohmann/json
|
||||
22
dockerfile
@@ -1,22 +0,0 @@
|
||||
FROM python:alpine
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the requirements file into the container
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install the required packages
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
RUN pip install gunicorn
|
||||
|
||||
# Copy the rest of the application code into the container
|
||||
COPY src src
|
||||
COPY templates templates
|
||||
COPY static static
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 5000
|
||||
|
||||
# run the application
|
||||
ENTRYPOINT [ "gunicorn", "-b", ":5000", "--access-logfile", "-", "--error-logfile", "-", "src.wsgi:app" ]
|
||||
15
include/errors.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef ERRORS_HPP
|
||||
#define ERRORS_HPP
|
||||
|
||||
#include <crow.h>
|
||||
#include "templating.hpp"
|
||||
|
||||
extern Templating templating;
|
||||
|
||||
struct CustomErrorHandler {
|
||||
struct context {};
|
||||
void before_handle(crow::request& req, crow::response& res, context&) {}
|
||||
void after_handle(crow::request& req, crow::response& res, context&);
|
||||
};
|
||||
|
||||
#endif
|
||||
25
include/templating.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef TEMPLATING_HPP
|
||||
#define TEMPLATING_HPP
|
||||
|
||||
#include <inja/inja.hpp>
|
||||
#include <crow.h>
|
||||
#include <string>
|
||||
|
||||
class Templating {
|
||||
public:
|
||||
explicit Templating(const std::string& template_dir);
|
||||
|
||||
crow::response render_template(const std::string& template_name, const inja::json& data);
|
||||
crow::response render_template(const std::string& template_name);
|
||||
|
||||
std::string render_template_string(const std::string& template_name, const inja::json& data);
|
||||
std::string render_template_string(const std::string& template_name);
|
||||
|
||||
private:
|
||||
inja::Environment inja_env;
|
||||
std::string template_dir; // absolute path to templates
|
||||
|
||||
std::string preprocess_template(const std::string& template_name);
|
||||
};
|
||||
|
||||
#endif
|
||||
51
makefile
Normal file
@@ -0,0 +1,51 @@
|
||||
# Directories
|
||||
INCLUDE_DIRS = include thirdparty/inja/include thirdparty/nlohmann/include
|
||||
SRC_DIR = src
|
||||
BUILD_DIR = build
|
||||
|
||||
# Compiler and linker settings
|
||||
CXX = g++
|
||||
LIBS =
|
||||
CXXFLAGS = -std=c++17 $(foreach dir,$(INCLUDE_DIRS),-I$(dir))
|
||||
|
||||
# Source and object files
|
||||
SRC = $(wildcard $(SRC_DIR)/*.cpp)
|
||||
|
||||
# Target executable
|
||||
UNAME := $(shell uname -s)
|
||||
BUILD_DIR := $(BUILD_DIR)/$(UNAME)
|
||||
OBJ_DIR := $(BUILD_DIR)/objs
|
||||
BIN = $(BUILD_DIR)/main
|
||||
|
||||
# Object files corresponding to the source files (now in obj directory)
|
||||
OBJS = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(notdir $(SRC)))))
|
||||
|
||||
# development target with debugging
|
||||
dev: CXXFLAGS += -g -Wall -Wformat
|
||||
dev: all
|
||||
|
||||
# Release target
|
||||
release: CXXFLAGS += -O3
|
||||
release: all
|
||||
|
||||
# Create directories for build output
|
||||
dirs:
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
|
||||
# Clear build directory
|
||||
clear:
|
||||
@find $(OBJ_DIR) -type f -name '*.o' -exec rm -f {} +
|
||||
|
||||
# Pattern rule for source files in src directory
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
all: dirs clear $(BIN)
|
||||
@echo Build complete
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
@@ -1,5 +0,0 @@
|
||||
psycopg2-binary
|
||||
python-dotenv
|
||||
flask-session
|
||||
requests
|
||||
flask
|
||||
5
run.sh
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ ! -f .env ] || export $(grep -v '^#' .env | xargs)
|
||||
|
||||
flask --app src.wsgi.py --debug run
|
||||
13
src/errors.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "errors.hpp"
|
||||
|
||||
|
||||
std::string render_404_template(const crow::request& req) {
|
||||
return templating.render_template_string("errors/404.html", {{"requested_url", req.url}});
|
||||
}
|
||||
|
||||
void CustomErrorHandler::after_handle(crow::request& req, crow::response& res, context&) {
|
||||
if (res.code == 404 && res.body.empty()) {
|
||||
res.set_header("Content-Type", "text/html");
|
||||
res.body = render_404_template(req);
|
||||
}
|
||||
}
|
||||
18
src/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#define CROW_STATIC_DIRECTORY "../static"
|
||||
#include "templating.hpp"
|
||||
#include "errors.hpp"
|
||||
#include <crow.h>
|
||||
|
||||
|
||||
Templating templating{"../templates"};
|
||||
|
||||
|
||||
int main() {
|
||||
crow::App<CustomErrorHandler> app;
|
||||
|
||||
CROW_ROUTE(app, "/")([]() {
|
||||
return templating.render_template("index.html");
|
||||
});
|
||||
|
||||
app.port(8080).multithreaded().run();
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
# Imports
|
||||
from flask import Blueprint, render_template, request, abort
|
||||
from os import getenv as env
|
||||
import logging, os, re
|
||||
|
||||
# Create blueprint
|
||||
bp = Blueprint(
|
||||
'dynamic_routes',
|
||||
__name__,
|
||||
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
|
||||
static_folder=env('STATIC_FOLDER', default='../static')
|
||||
)
|
||||
|
||||
# Create logger
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Get all files in folder
|
||||
def ListFiles(path):
|
||||
files = []
|
||||
for root, dirs, files_in_dir in os.walk(path):
|
||||
for file in files_in_dir:
|
||||
files.append(os.path.relpath(os.path.join(root, file), path))
|
||||
for dir in dirs:
|
||||
files.append(os.path.relpath(os.path.join(root, dir), path) + '/')
|
||||
return files
|
||||
|
||||
# Catch-all route for generic pages
|
||||
@bp.route('/<path:filename>')
|
||||
def catch_all(filename):
|
||||
try:
|
||||
return render_template(f'pages/{filename if re.match(r'^.+\.[a-zA-Z0-9]+$', filename) else filename + '.html'}')
|
||||
|
||||
except Exception as e:
|
||||
os_path = os.path.join(bp.template_folder, 'pages', filename)[3:]
|
||||
print(os_path)
|
||||
if os.path.isdir(os_path):
|
||||
if not filename.endswith('/'): filename += '/'
|
||||
return render_template('bases/directory.html', directory=filename, pages=ListFiles(os_path))
|
||||
|
||||
# If it is a file, return a 404 error
|
||||
abort(404, f"Template '{filename}' not found: {e}")
|
||||
@@ -1,39 +0,0 @@
|
||||
# Imports
|
||||
from flask import Blueprint, render_template
|
||||
from os import getenv as env
|
||||
import logging
|
||||
|
||||
# Create blueprint
|
||||
bp = Blueprint(
|
||||
'error_handlers',
|
||||
__name__,
|
||||
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
|
||||
static_folder=env('STATIC_FOLDER', default='../static')
|
||||
)
|
||||
|
||||
# Create logger
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Route for 500 error
|
||||
@bp.route('/500')
|
||||
@bp.app_errorhandler(500)
|
||||
def internal_server_error(error=None):
|
||||
if error is not None:
|
||||
log.error("Internal server error: %s", error)
|
||||
return render_template('errors/500.html'), 500
|
||||
|
||||
# Route for 404 error
|
||||
@bp.route('/404')
|
||||
@bp.app_errorhandler(404)
|
||||
def not_found(error=None):
|
||||
if error is not None:
|
||||
log.warning("Page not found: %s", error)
|
||||
return render_template('errors/404.html'), 404 if error is not None else 200
|
||||
|
||||
# Route for 400 error
|
||||
@bp.route('/400')
|
||||
@bp.app_errorhandler(400)
|
||||
def bad_request(error=None):
|
||||
if error is not None:
|
||||
log.warning("Bad request: %s", error)
|
||||
return render_template('errors/400.html', error=error), 400
|
||||
76
src/templating.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "templating.hpp"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <stdexcept>
|
||||
|
||||
Templating::Templating(const std::string& template_dir)
|
||||
: inja_env(std::filesystem::canonical(template_dir).string()),
|
||||
template_dir(std::filesystem::canonical(template_dir).string())
|
||||
{
|
||||
inja_env.set_search_included_templates_in_files(true);
|
||||
}
|
||||
|
||||
std::string Templating::preprocess_template(const std::string& template_name) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
fs::path abs_template_dir = fs::path(template_dir);
|
||||
fs::path abs_template_file = fs::canonical(abs_template_dir / template_name);
|
||||
|
||||
std::ifstream file(abs_template_file);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Failed to open template file: " + abs_template_file.string());
|
||||
}
|
||||
|
||||
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
|
||||
std::regex extends_regex(R"(\{\%\s*extends\s*(['"])(.+?)\1\s*\%\})");
|
||||
std::smatch match;
|
||||
|
||||
if (std::regex_search(content, match, extends_regex)) {
|
||||
std::string quote = match[1].str();
|
||||
std::string original_path = match[2].str();
|
||||
|
||||
if (original_path.find("/") == std::string::npos &&
|
||||
!original_path.empty() &&
|
||||
original_path.front() != '/') {
|
||||
|
||||
fs::path abs_extended_template = fs::canonical(abs_template_dir / original_path);
|
||||
fs::path rel_path = fs::relative(abs_extended_template, abs_template_file.parent_path());
|
||||
|
||||
std::string new_path = rel_path.generic_string();
|
||||
|
||||
content = std::regex_replace(content, extends_regex,
|
||||
"{% extends " + quote + new_path + quote + " %}");
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
crow::response Templating::render_template(const std::string& template_name, const inja::json& data) {
|
||||
try {
|
||||
std::string preprocessed = preprocess_template(template_name);
|
||||
inja::Template tpl = inja_env.parse(preprocessed);
|
||||
std::string rendered = inja_env.render(tpl, data);
|
||||
return crow::response(rendered);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
return crow::response(500, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
crow::response Templating::render_template(const std::string& template_name) {
|
||||
return render_template(template_name, inja::json{});
|
||||
}
|
||||
|
||||
std::string Templating::render_template_string(const std::string& template_name, const inja::json& data) {
|
||||
std::string preprocessed = preprocess_template(template_name);
|
||||
inja::Template tpl = inja_env.parse(preprocessed);
|
||||
return inja_env.render(tpl, data);
|
||||
}
|
||||
|
||||
std::string Templating::render_template_string(const std::string& template_name) {
|
||||
return render_template_string(template_name, inja::json{});
|
||||
}
|
||||
64
src/wsgi.py
@@ -1,64 +0,0 @@
|
||||
# Imports
|
||||
from flask import Flask, render_template, send_file
|
||||
from flask_session import Session
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from os import getenv as env
|
||||
import logging
|
||||
|
||||
import src.routes.error_handlers
|
||||
import src.routes.dynamic_routes
|
||||
|
||||
# Load env
|
||||
load_dotenv()
|
||||
|
||||
# Create logger
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
||||
stream_handler.setLevel(logging.INFO)
|
||||
|
||||
file_handler = logging.FileHandler(filename='app.log')
|
||||
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
||||
file_handler.setLevel(logging.DEBUG)
|
||||
|
||||
# Add handlers to the logger
|
||||
log = logging.getLogger()
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(stream_handler)
|
||||
log.addHandler(file_handler)
|
||||
log.info("Logging initialized")
|
||||
|
||||
# Create flask app
|
||||
app = Flask(
|
||||
__name__,
|
||||
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
|
||||
static_folder=env('STATIC_FOLDER', default='../static')
|
||||
)
|
||||
|
||||
# Configure sessions
|
||||
app.config["SESSION_PERMANENT"] = True
|
||||
app.config["SESSION_TYPE"] = "filesystem"
|
||||
Session(app)
|
||||
|
||||
# Load routes
|
||||
app.register_blueprint(src.routes.error_handlers.bp, url_prefix='/error')
|
||||
app.register_blueprint(src.routes.dynamic_routes.bp, url_prefix='/')
|
||||
|
||||
# Generic routes
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/favicon.ico')
|
||||
def favicon():
|
||||
return send_file('../static/content/other/favicon.ico')
|
||||
|
||||
@app.route('/robots.txt')
|
||||
def robots():
|
||||
return send_file('../static/content/other/robots.txt')
|
||||
|
||||
|
||||
# Route for sitemap.xml
|
||||
@app.route('/sitemap.xml')
|
||||
def sitemap():
|
||||
return send_file('../static/content/other/sitemap.xml')
|
||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 965 B |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 4.4 MiB |
|
Before Width: | Height: | Size: 4.9 MiB |
|
Before Width: | Height: | Size: 5.1 MiB |
@@ -3,6 +3,7 @@ https://cyber.dabamos.de/88x31/anythingbut.gif
|
||||
https://cyber.dabamos.de/88x31/bestdesktop.gif
|
||||
https://kopawz.neocities.org/buttonhoard/buttonsfldr2/diagnosedwithGAY.gif
|
||||
https://kopawz.neocities.org/indexgraphics/buttondecor/ilikecomputer.png
|
||||
https://identity-crisis.carrd.co/assets/images/gallery04/ad4f8d52.jpg?v=4e55d939
|
||||
https://anlucas.neocities.org/best_viewed_with_eyes.gif
|
||||
https://anlucas.neocities.org/html_learn_it_today.gif
|
||||
https://highway.eightyeightthirty.one/badge/5d58a8f32b007d4897db6f862a895a81674fb35f5cc3947fc66595817ca174db
|
||||
|
Before Width: | Height: | Size: 830 KiB |
@@ -308,26 +308,6 @@ a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: var(--secondary-background-color-but-slightly-transparent);
|
||||
padding: 4px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
#toaster-wave {
|
||||
position: absolute;
|
||||
left: -145px;
|
||||
top: 200px;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1240px) {
|
||||
#toaster-wave {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1000px) {
|
||||
body {
|
||||
background-color: var(--background-color);
|
||||
@@ -1,23 +1,17 @@
|
||||
.gallery {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gallery .gallery-images {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gallery .gallery-images img {
|
||||
.gallery img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.gallery h2.gallery-date {
|
||||
position: relative;
|
||||
top: 0;
|
||||
left: 0;
|
||||
.gallery-date {
|
||||
margin: 1rem 0 .25rem 0;
|
||||
font-size: 2rem;
|
||||
}
|
||||
@@ -81,8 +81,4 @@ ul#toaster-specs li {
|
||||
.flex-col {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
#toaster-wave {
|
||||
display: none;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ if (document.getElementById('spotify')) {
|
||||
// load buttons
|
||||
|
||||
function loadButtons() {
|
||||
fetch('/static/content/buttons/non_link_buttons.txt').then(response => {
|
||||
fetch('/static/content/other/buttons.txt').then(response => {
|
||||
return response.text();
|
||||
}).then(data => {
|
||||
container = document.getElementById('button-collection');
|
||||
|
||||
174
static/js/snake.js
Normal file
@@ -0,0 +1,174 @@
|
||||
const canvas = document.getElementById('snakeCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
const gridSize = 20;
|
||||
const tileSize = 100;
|
||||
const snakeSize = 60;
|
||||
const foodSize = 80;
|
||||
canvas.width = gridSize * tileSize;
|
||||
canvas.height = gridSize * tileSize;
|
||||
|
||||
let snake = [{ x: 10, y: 10 }, { x: 10, y: 11 }, { x: 10, y: 12 }];
|
||||
let direction = { x: 0, y: 0 };
|
||||
let food = { x: Math.floor(Math.random() * gridSize), y: Math.floor(Math.random() * gridSize) };
|
||||
let score = 0;
|
||||
let gameOver = false;
|
||||
|
||||
function draw() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// draw grid of checkerboard pattern
|
||||
for (let x = 0; x < gridSize; x++) {
|
||||
for (let y = 0; y < gridSize; y++) {
|
||||
ctx.fillStyle = (x + y) % 2 === 0 ?
|
||||
getComputedStyle(document.documentElement).getPropertyValue('--background-color') :
|
||||
getComputedStyle(document.documentElement).getPropertyValue('--secondary-background-color');
|
||||
ctx.fillRect(x * tileSize, y * tileSize, tileSize, tileSize);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw snake
|
||||
snake.forEach(segment => {
|
||||
let nextVec = { x: 0, y: 0 };
|
||||
// if there is a segment after the current segment
|
||||
if (snake.indexOf(segment) < snake.length - 1) {
|
||||
const nextSegment = snake[snake.indexOf(segment) + 1];
|
||||
nextVec.x = nextSegment.x - segment.x;
|
||||
nextVec.y = nextSegment.y - segment.y;
|
||||
}
|
||||
|
||||
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--primary-color');
|
||||
if (nextVec.x === 0 && nextVec.y === 0) {
|
||||
ctx.fillRect(
|
||||
segment.x * tileSize + (tileSize - snakeSize) / 2,
|
||||
segment.y * tileSize + (tileSize - snakeSize) / 2,
|
||||
snakeSize,
|
||||
snakeSize
|
||||
);
|
||||
} else if (nextVec.x > 0 || nextVec.y > 0) {
|
||||
ctx.fillRect(
|
||||
segment.x * tileSize + (tileSize - snakeSize) / 2,
|
||||
segment.y * tileSize + (tileSize - snakeSize) / 2,
|
||||
snakeSize + nextVec.x * (tileSize - snakeSize),
|
||||
snakeSize + nextVec.y * (tileSize - snakeSize)
|
||||
);
|
||||
} else {
|
||||
ctx.fillRect(
|
||||
segment.x * tileSize + (tileSize - snakeSize) / 2 + nextVec.x * (tileSize - snakeSize),
|
||||
segment.y * tileSize + (tileSize - snakeSize) / 2 + nextVec.y * (tileSize - snakeSize),
|
||||
snakeSize + Math.abs(nextVec.x) * (tileSize - snakeSize),
|
||||
snakeSize + Math.abs(nextVec.y) * (tileSize - snakeSize)
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Draw food
|
||||
ctx.fillStyle = '#ff4d4d';
|
||||
ctx.fillRect(
|
||||
food.x * tileSize + (tileSize - foodSize) / 2,
|
||||
food.y * tileSize + (tileSize - foodSize) / 2,
|
||||
foodSize,
|
||||
foodSize
|
||||
);
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (gameOver) return;
|
||||
|
||||
// Move snake
|
||||
const head = { x: snake[0].x + direction.x, y: snake[0].y + direction.y };
|
||||
|
||||
// Add new head
|
||||
snake.unshift(head);
|
||||
|
||||
// Check for food collision
|
||||
if (head.x === food.x && head.y === food.y) {
|
||||
score += 10; // Increase score
|
||||
placeFood();
|
||||
} else {
|
||||
snake.pop(); // Remove tail if no food eaten
|
||||
}
|
||||
|
||||
// Check for wall collision
|
||||
if (head.x < 0 || head.x >= gridSize || head.y < 0 || head.y >= gridSize) {
|
||||
gameOver = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for self collision
|
||||
for (let i = 1; i < snake.length; i++) {
|
||||
if (head.x === snake[i].x && head.y === snake[i].y) {
|
||||
gameOver = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function placeFood() {
|
||||
do {
|
||||
food.x = Math.floor(Math.random() * gridSize);
|
||||
food.y = Math.floor(Math.random() * gridSize);
|
||||
} while (snake.some(segment => segment.x === food.x && segment.y === food.y));
|
||||
}
|
||||
|
||||
function changeDirection(event) {
|
||||
switch (event.key) {
|
||||
case 'w':
|
||||
if (direction.y === 0) direction = { x: 0, y: -1 };
|
||||
break;
|
||||
case 's':
|
||||
if (direction.y === 0) direction = { x: 0, y: 1 };
|
||||
break;
|
||||
case 'a':
|
||||
if (direction.x === 0) direction = { x: -1, y: 0 };
|
||||
break;
|
||||
case 'd':
|
||||
if (direction.x === 0) direction = { x: 1, y: 0 };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Menu to start the game
|
||||
function menu() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--background-color');
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--text-color');
|
||||
ctx.font = '200px Arial';
|
||||
ctx.fillText('Snake Game', canvas.width / 2, canvas.height / 2);
|
||||
ctx.font = '100px Arial';
|
||||
ctx.fillText('Press W/A/S/D to move', canvas.width / 2, canvas.height / 2 + 100);
|
||||
ctx.fillText('Click to start', canvas.width / 2, canvas.height / 2 + 200);
|
||||
|
||||
canvas.addEventListener('click', startGame);
|
||||
}
|
||||
|
||||
function gameLoop() {
|
||||
if (!gameOver) {
|
||||
update();
|
||||
draw();
|
||||
setTimeout(gameLoop, 100);
|
||||
} else {
|
||||
document.removeEventListener('keydown', changeDirection);
|
||||
document.getElementById('score').value = score;
|
||||
alert(`Game Over! Your score: ${score}`);
|
||||
menu();
|
||||
}
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
snake = [{ x: 10, y: 10 }, { x: 10, y: 11 }, { x: 10, y: 12 }];
|
||||
direction = { x: 1, y: 0 };
|
||||
food = { x: Math.floor(Math.random() * gridSize), y: Math.floor(Math.random() * gridSize) };
|
||||
score = 0;
|
||||
gameOver = false;
|
||||
canvas.removeEventListener('click', startGame);
|
||||
document.addEventListener('keydown', changeDirection);
|
||||
gameLoop();
|
||||
}
|
||||
|
||||
menu();
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Alfie's basement{% endblock %}</title>
|
||||
<link rel="icon" href="/static/content/general_images/icon.webp">
|
||||
<link rel="stylesheet" href="/static/css/bases/base.css">
|
||||
<link rel="stylesheet" href="/static/css/base.css">
|
||||
<meta name="description" content="{% block description %}server backend survivor{% endblock %}">
|
||||
<meta name="keywords" content="{% block keywords %}Alfie King, Alfie, King, Alfieking, Alfieking.dev, dev, server, developer, backend, selfhost, homelab{% endblock %}">
|
||||
<meta name="author" content="Alfie King">
|
||||
@@ -13,8 +13,8 @@
|
||||
<meta name="theme-color" content="#63de90" data-react-helmet="true">
|
||||
<meta property="og:site_name" content="Alfieking.dev">
|
||||
<meta property="og:url" content="https://alfieking.dev/">
|
||||
<meta property="og:title" content="{{ self.title() }}">
|
||||
<meta property="og:description" content="{{ self.description() }}">
|
||||
<meta property="og:title" content="{% block og-title %}Home - Alfie's basement{% endblock %}">
|
||||
<meta property="og:description" content="{% block og-description %}server backend survivor{% endblock %}">
|
||||
<meta property="og:image" content="{% block og_image %}/static/content/general_images/icon.webp{% endblock %}">
|
||||
{% block head %}
|
||||
{% endblock %}
|
||||
@@ -46,28 +46,19 @@
|
||||
<section id="buttons">
|
||||
<h1>BUTTONS</h1>
|
||||
<ul>
|
||||
<li><a herf="https://hijpixel.nekoweb.org/"><img src="/static/content/buttons/hijpixel.gif" alt="hijpixel"></a></li>
|
||||
<li><a href="https://lensdeer.neocities.org/"><img src="/static/content/buttons/lensdeer.gif" alt="lensdeer"></a></li>
|
||||
<li><a href="https://emmixis.net/"><img src="/static/content/buttons/emmixis.gif" alt="emmixis"></a></li>
|
||||
<li><a href="https://dimden.dev/"><img src="https://dimden.dev/services/images/88x31.gif" alt="dimden"></a></li><!-- hotlink on purpose -->
|
||||
<li><a href="https://ne0nbandit.neocities.org/"><img src="/static/content/buttons/ne0nbandit.png" alt="ne0nbandit"></a></li>
|
||||
<li><a href="https://thinliquid.dev"><img src="/static/content/buttons/thnlqd.png" alt="thinliquid"></a></li>
|
||||
<li><a href="https://nekoweb.org/"><img src="/static/content/buttons/nekoweb.gif" alt="nekoweb"></a><!-- button by s1nez.nekoweb.org --></li>
|
||||
<li><a href="https://s1nez.nekoweb.org/"><img src="/static/content/buttons/s1nez.gif" alt="s1nez"></a></li>
|
||||
<li><a href="https://beeps.website"><img src="/static/content/buttons/beeps.gif" alt="beeps"></a></li>
|
||||
<li><a href="https://itsnotstupid.com"><img src="/static/content/buttons/insia.gif" alt="itsnotstupid"></a></li>
|
||||
<li><a href='https://blinkies.cafe'><img src='/static/content/buttons/blinkiescafe.gif' alt='blinkies.cafe | make your own blinkies!'></a></li>
|
||||
<li><a href="https://eightyeightthirty.one"><img src="/static/content/buttons/8831.png" alt="88x31"></a></li>
|
||||
<li><a href="https://neocities.org"><img src="/static/content/buttons/neocities.gif" alt="neocities"></a></li>
|
||||
<li><a href="https://tuxedodragon.art"><img src="/static/content/buttons/tuxedodragon.gif" alt="tuxedodragon"></a></li>
|
||||
<li><a href="https://dimden.dev/"><img src="https://dimden.dev/services/images/88x31.gif" alt="dimden"></a></li>
|
||||
<li><a href="https://ne0nbandit.neocities.org/"><img src="https://ne0nbandit.github.io/assets/img/btn/mine/nbbanner.png" alt="ne0nbandit"></a></li>
|
||||
<li><a href="https://thinliquid.dev"><img src="https://thinliquid.dev/thnlqd.png" alt="thinliquid"></a></li>
|
||||
<li><a href="https://nekoweb.org/"><img src="https://nekoweb.org/assets/buttons/button6.gif" alt="nekoweb"></a><!-- button by s1nez.nekoweb.org --></li>
|
||||
<li><a href="https://s1nez.nekoweb.org/"><img src="https://s1nez.nekoweb.org/BUTTON.gif" alt="s1nez"></a></li>
|
||||
<li><a href="https://beeps.website"><img src="https://beeps.website/assets/images/88x31-d.gif" alt="beeps"></a></li>
|
||||
<li><a href="https://itsnotstupid.com"><img src="https://itsnotstupid.com/pics/button1.gif" alt="itsnotstupid"></a></li>
|
||||
<li><a href='https://blinkies.cafe'><img src='https://blinkies.cafe/b/display/blinkiesCafe-badge.gif' alt='blinkies.cafe | make your own blinkies!'></a></li>
|
||||
<li><a href="https://eightyeightthirty.one"><img src="https://eightyeightthirty.one/88x31.png" alt="88x31"></a></li>
|
||||
<li><a href="https://neocities.org"><img src="https://cyber.dabamos.de/88x31/neocities-now.gif" alt="neocities"></a></li>
|
||||
<li><a href="https://tuxedodragon.art"><img src="https://tuxedodragon.art/tuxedodragon%2088x31.gif" alt="tuxedodragon"></a></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<div id='furryring'>
|
||||
<script type="text/javascript" src="https://furryring.neocities.org/onionring-variables.js"></script>
|
||||
<script type="text/javascript" src="https://furryring.neocities.org/onionring-widget.js"></script>
|
||||
</div>
|
||||
</section>
|
||||
<section>
|
||||
<pre class="vsmoltext"> |\ _,,,---,,_<br>ZZZzz /,`.-'`' -. ;-;;,_<br> |,4- ) )-,_. ,\ ( `'-'<br> '---''(_/--' `-'\_)</pre>
|
||||
</section>
|
||||
@@ -82,9 +73,6 @@
|
||||
<h2 id="typing">server backend survivor</h2>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/toaster" id="toaster-wave">
|
||||
<img src="/static/content/toaster/Toaster_v1.1.png" alt="toaster">
|
||||
</a>
|
||||
</header>
|
||||
<nav id="alt-nav">
|
||||
<ul>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{% extends "bases/base.html" %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}/{{ directory }} - Alfie's basement{% endblock %}
|
||||
{% block description %}server backend survivor{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="/static/css/bases/directory.css">
|
||||
<link rel="stylesheet" href="/static/css/directory.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{% block description %}Bad request. The server could not understand the request due to invalid syntax.{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="/static/css/errors/400.css">
|
||||
<link rel="stylesheet" href="/static/css/400.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@@ -7,7 +7,14 @@
|
||||
<section>
|
||||
<h1>404</h1>
|
||||
<p>
|
||||
It seems like the thing you are looking for does not exist or <code>rm -rf</code> itself out of exsistance.
|
||||
Hey so you know that thing you were looking for? Yeah, it doesn't exist. :P
|
||||
<br><br>
|
||||
So why not try going back to the <a href="/">homepage</a>?
|
||||
</p>
|
||||
</section>
|
||||
{% endblock %}
|
||||
<section>
|
||||
<h2>The actual error for the 2 ppl who care</h2>
|
||||
<p>
|
||||
404: {{ requested_url }} not found :3
|
||||
</p>
|
||||
</section>
|
||||
@@ -4,7 +4,7 @@
|
||||
{% block description %}An unexpected error occurred on the server.{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="/static/css/errors/500.css">
|
||||
<link rel="stylesheet" href="/static/css/500.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
{% block title %}Home - Alfie's basement{% endblock %}
|
||||
{% block description %}server backend survivor{% endblock %}
|
||||
{% block og-title %}Home - Alfie's basement{% endblock %}
|
||||
{% block og-description %}server backend survivor{% endblock %}
|
||||
|
||||
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="/static/css/index.css">
|
||||
{% endblock %}
|
||||
|
||||
{%block content %}
|
||||
{% block content %}
|
||||
<section>
|
||||
<h1>A lil bit abt me</h1>
|
||||
<p>
|
||||
Im not good with writing so dont expect much here. I was a student learning c++ and python. I've Done a few projects that i think
|
||||
Im not good with writing so dont expect much here. I am a student who is learning c++ and python. I've Done a few projects that i think
|
||||
are decent enough to show off, so I have put them on this website. I like to mess around with linux and have a few servers that I run. I've
|
||||
been running a server for a few years now, and I have learned a lot from it. I have also switched to linux on my main computer, which has been
|
||||
slightly annoying at times (mainly because one of my most played games' anticheat doesn't support on linux atm. Also, the lack of photoshop is
|
||||
@@ -104,15 +107,6 @@
|
||||
<h1>Some News</h1>
|
||||
<h6>(dont expect this to be updated often tho :P)</h6>
|
||||
<ul>
|
||||
<li>
|
||||
<h2>18-01-2026</h2>
|
||||
<p>
|
||||
:O an update! thats unheard of on this site (aleast its more often than tf2 gets updates). finding motivation to work on things has been painful
|
||||
recently, but im wokring on my mental state a bit so hopefully there will be more updates. I am writing this before i make any major changes but
|
||||
i hope to add a blog or something, or maybe a daily thoughts thing that pings my phone to get me to write something. I also need to rewrite most
|
||||
of the home page as well since its kinda out of date :P
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<h2>28-06-2025</h2>
|
||||
<p>
|
||||
@@ -120,7 +114,7 @@
|
||||
I didn't want to use a framework at first, mainly because I like the simplicity of a static site, but it allows me to use templatiing and makes
|
||||
adding new features easier and more organized. The site is also more interacive now, with a few secrets on some of the pages. I still plan on adding
|
||||
more secrets and features. I also plan on adding a blog section, that I will move this to, so that I can give updates on the site and other things
|
||||
that I find interesting.
|
||||
that I find interesting.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@@ -34,22 +34,12 @@ protogen v1.0, toaster v1.0
|
||||
<p>
|
||||
Here are some photos from the meets I have attended. I will add more as I attend more meets.
|
||||
</p>
|
||||
<h2 class="gallery-date">26th July 2025</h2>
|
||||
<div class="gallery">
|
||||
<h2 class="gallery-date">26th July 2025</h2>
|
||||
<div class="gallery-images">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_152110445.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_155134418.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_155226274.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_155434701.jpg" alt="Critters MK">
|
||||
</div>
|
||||
</div>
|
||||
<div class="gallery">
|
||||
<h2 class="gallery-date">23rd Aug 2025</h2>
|
||||
<div class="gallery-images">
|
||||
<img src="/static/content/fur_meets/23-08-2025_critters_mk/PXL_20250823_130640362.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/23-08-2025_critters_mk/PXL_20250823_130648109.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/23-08-2025_critters_mk/PXL_20250823_130659800.jpg" alt="Critters MK">
|
||||
</div>
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_152110445.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_155134418.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_155226274.jpg" alt="Critters MK">
|
||||
<img src="/static/content/fur_meets/26-07-2025_critters_mk/PXL_20250726_155434701.jpg" alt="Critters MK">
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -49,18 +49,16 @@ protogen v1.0, toaster v1.0
|
||||
<p>
|
||||
Here are some photos from the meets I have attended. I will add more as I attend more meets.
|
||||
</p>
|
||||
<h2 class="gallery-date">3rd Aug 2025</h2>
|
||||
<div class="gallery">
|
||||
<h2 class="gallery-date">3rd Aug 2025</h2>
|
||||
<div class="gallery-images">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_141943558.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_150138054.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_150249916.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_183614897.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_140629639.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_141242090.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_182023562.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_184321576.jpg" alt="Paws'N'Pistons">
|
||||
</div>
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_141943558.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_150138054.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_150249916.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_183614897.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_140629639.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_141242090.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_182023562.jpg" alt="Paws'N'Pistons">
|
||||
<img src="/static/content/fur_meets/03-08-2025_paws_n_pistons/PXL_20250803_184321576.jpg" alt="Paws'N'Pistons">
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||