Skip to content

Instantly share code, notes, and snippets.

View Maxiviper117's full-sized avatar
🚧
Building

David Maxiviper117

🚧
Building
View GitHub Profile
@Maxiviper117
Maxiviper117 / Dockerfile
Created April 9, 2023 09:42
Example `dockerfile` for a Sveltekit Project
# ---- Base Node ----
FROM node:19-alpine AS base
WORKDIR /app
COPY package*.json ./
# ---- Dependencies ----
FROM base AS dependencies
RUN npm ci
# ---- Build ----
@Maxiviper117
Maxiviper117 / .prettierrc
Created April 10, 2023 08:59
Prettier config for Sveltekit project
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
"svelteAllowShorthand": false,
"svelteSortOrder": "scripts-options-markup-styles",
@Maxiviper117
Maxiviper117 / main.py
Created February 2, 2024 08:25
Delete all node_modules in a specified directory using Python
from pathlib import Path
import shutil
def delete_node_modules(directory):
deleted_any = False # Track if any node_modules directories have been deleted
for path in directory.rglob('*'): # Use rglob to find all paths
if path.name == 'node_modules' and path.is_dir():
shutil.rmtree(path)
print(f"Deleted {path}")
deleted_any = True
@Maxiviper117
Maxiviper117 / create_fastapi_directories.ps1
Last active August 5, 2024 17:39
PowerShell script to create directory structure for a FastAPI project
# Define the base directory as the app folder inside the current directory
$baseDir = Join-Path -Path (Get-Location) -ChildPath "app"
# Define the folder structure within the app directory
$folders = @(
"$baseDir/models",
"$baseDir/schemas",
"$baseDir/crud",
"$baseDir/routers",
"$baseDir/db",
@Maxiviper117
Maxiviper117 / smooth-scrolling.js
Created September 7, 2024 11:03
Smooth Scrolling JS for Any Page
document.addEventListener("DOMContentLoaded", function () {
const body = document.body;
const html = document.documentElement;
let sx = 0, sy = 0; // For scroll positions
let dx = sx, dy = sy; // For container positions
let scrollSpeed = 40; // Adjust scroll speed based on mouse wheel movement
// Set the body's height to be the height of the scrollable content
const pageHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
@Maxiviper117
Maxiviper117 / ScrollTransform.js
Created September 7, 2024 20:38
A reusable JavaScript class to apply dynamic CSS transformations (scale, rotate, translate) to elements based on vertical scroll position
/**
* ScrollTransform Class (Extended Version)
* A reusable JavaScript class to apply dynamic CSS transformations (scale, rotate, translate, opacity)
* to elements based on the vertical scroll position with various options.
*
* Usage Example:
* const scrollEffect = new ScrollTransform('.my-element', {
* scale: true, rotate: true, translateY: true, opacity: true, startPosition: 100, endPosition: 1000
* });
*
@Maxiviper117
Maxiviper117 / regex-replace.md
Created October 5, 2024 20:00
Replacing Localization Strings in Laravel in Vscode

Replacing Localization Strings in Laravel

This guide helps you replace all localization strings in the form of {{ __('...') }} with the plain text inside the __('...') function in Laravel projects.

Regular Expression for Search

  1. Pattern: Use this regular expression to match the {{ __('...') }} structure:

{{\s*__(\s*'"['"]\s*)\s*}}

@Maxiviper117
Maxiviper117 / parseSetCookie.ts
Last active October 10, 2024 17:04
A JavaScript function to parse Set-Cookie headers with multiple cookies.
function parseSetCookie(setCookieHeader: string) {
// Initialize an empty object to store the parsed cookies
const cookies = {};
// Split the `Set-Cookie` header string by ", " but only where the comma is followed by a space
// and a word character (i.e., start of a new cookie name). This avoids splitting attributes that might contain commas.
const cookieStrings = setCookieHeader.split(/,(?=\\s*\\w+=)/);
// Iterate through each individual cookie string
cookieStrings.forEach((cookieString) => {
@Maxiviper117
Maxiviper117 / expressjsv5.js
Last active October 17, 2024 09:57
Express V5 Subtle changes
import express, { Request, Response, NextFunction } from "express";
const app = express();
/**
* Middleware to parse URL-encoded data
* v5 Change: No need to set `extended` to `false` explicitly, it's now the default
*/
app.use(express.urlencoded()); // Default behavior parses simple key-value pairs in query strings
@Maxiviper117
Maxiviper117 / extract_models.php
Created October 22, 2024 12:48
Laravel extraction of model classes into consolidated file for feeding into AI
<?php
/**
* Consolidate all class definitions from app/Models into app/ConsolidatedModels.php
* Revised version with corrected class extraction to prevent duplicate 'class' keywords.
*/
// Define the directories
$modelsDir = __DIR__ . '/app/Models';
$outputFile = __DIR__ . '/app/ConsolidatedModels.php';