Skip to content

Instantly share code, notes, and snippets.

View Maxiviper117's full-sized avatar
🎯
Focusing

David Maxiviper117

🎯
Focusing
View GitHub Profile
@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';
@Maxiviper117
Maxiviper117 / firewall.sh
Created October 30, 2024 10:35 — forked from andrasbacsai/firewall.sh
Update a Hetzner Firewall rule with your IP address
#!/bin/bash
# Script to update a firewall rule in a Hetzner Firewall with your current IP address.
# Good if you would like to restrict SSH access only for your current IP address (secure).
#################
# WARNING: This script will overwrite all rules in the firewall rules, so make sure you
# added all the required rules.
# I use a separate firewall rule just for SSH access.
#################
@Maxiviper117
Maxiviper117 / AppServiceProvider.php
Last active October 31, 2024 09:18
Laravel 11 AppServiceProvider setup for production safeguards and scheduling
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Date;
@Maxiviper117
Maxiviper117 / docker-compose.yml
Last active November 3, 2024 15:28
Docker Compose Setup for Laravel Local Development with Mailpit, MeiliSearch, MinIO, and Redis
services:
mailpit:
image: axllent/mailpit:latest
container_name: mailpit
ports:
- "8025:8025" # Web interface
- "1025:1025" # SMTP port
meilisearch:
image: getmeili/meilisearch:latest
@Maxiviper117
Maxiviper117 / tailwind.config.js
Last active November 22, 2024 08:50
Tailwind with chroma-js custom color shades
import type { Config } from 'tailwindcss';
import plugin from 'tailwindcss/plugin';
import chroma from 'chroma-js';
const domainScale = [100, 200, 300, 400, 500, 600, 700, 800, 900];
function generateShadesInverted(baseColor, steps = 9) {
const scale = chroma
.scale(['white', baseColor, 'black'])
@Maxiviper117
Maxiviper117 / tailwind4-css-color-gen.js
Last active November 25, 2024 10:06
Tailwind 4 Generate Color Shades Dynamically using chroma-js
import fs from "fs";
import chroma from "chroma-js";
// Define your custom colors
const colors = {
primary: "#1E40AF", // Blue
secondary: "#10B981", // Green
tertiary: "#9333EA", // Purple
accent: "#F59E0B", // Amber
};
@Maxiviper117
Maxiviper117 / fzf-config.zsh
Created December 22, 2024 09:09
fzf ZSH config
# ------------------------------------------------------------------------------
# FZF Configuration
# ------------------------------------------------------------------------------
# Source fzf's key bindings and completion (if installed via Homebrew or similar)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Adjust default FZF options (feel free to tweak)
export FZF_DEFAULT_OPTS="--height=70% --reverse --border"
@Maxiviper117
Maxiviper117 / settings.json
Created January 6, 2025 08:35
Vscode Github Copilot Commit message instructions
{
"github.copilot.chat.commitMessageGeneration.instructions": [
{
"text": "Generate commit messages following the Conventional Commits specification. Use the following structure strictly:\n\n<type>[optional scope]: <short description>\n\nOptional body: Include a detailed explanation of the change if necessary. Wrap text at 72 characters per line.\n\nOptional footer: Include metadata such as issue references or breaking changes. Use keywords like 'BREAKING CHANGE:' followed by an explanation, and reference issues with 'Closes #<issue_number>'.\n\nTypes must be one of the following:\n- feat: For introducing new features.\n- fix: For bug fixes.\n- docs: For documentation-only changes.\n- style: For changes that do not affect code functionality (e.g., formatting).\n- refactor: For code changes that neither fix a bug nor add a feature.\n- test: For adding or modifying tests.\n- chore: For non-code tasks such as updating dependencies.\n\nThe short description must be imperative (e.g., 'add featu