Skip to content

Instantly share code, notes, and snippets.

@jkoop
jkoop / PurifyHtml.php
Created March 8, 2024 15:03
Laravel 10: middleware: prevent HTML and Markdown attacks
<?php
namespace App\Http\Middleware;
use HTMLPurifier;
use HTMLPurifier_HTML5Config;
use Illuminate\Foundation\Http\Middleware\TransformsRequest;
/**
* Use HTMLPurifier to purify all inputs with names matching `/[-_]html\s*$/i`.
@jkoop
jkoop / PreventOverloading.php
Last active August 20, 2024 15:47
A Laravel Middleware that checks the system's current 15 minute loadavg and the number of CPUs, and if the resulting division is greater than 85%, returns 503 with an appropriate message.
<?php
// app/Http/Middleware/PreventOverloading.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
@jkoop
jkoop / autotitle.js
Last active October 14, 2024 05:32
Automatically generate and set a title for documents with a specific tag in paperless.ngx using ollama
#! bun run
/**
* The author disclaims copyright to this source code.
*/
const PAPERLESS_URL = process.env.PAPERLESS_URL ?? "";
const PAPERLESS_TOKEN = process.env.PAPERLESS_TOKEN ?? "";
const PAPERLESS_TAG_ID = process.env.PAPERLESS_TAG_ID ?? 0;
const OLLAMA_URL = process.env.OLLAMA_URL ?? "";