Skip to content

Instantly share code, notes, and snippets.

View szepeviktor's full-sized avatar
🍓
Making applications error-free

Viktor Szépe szepeviktor

🍓
Making applications error-free
View GitHub Profile
@szepeviktor
szepeviktor / glyph-width.php
Last active May 12, 2025 10:34
Estimate glyph widths for sans serif 16px font
<?php
function get_text_width(string $text): int
{
$glyph_widths = [
'A' => 10.67,
'B' => 10.67,
'C' => 11.55,
'D' => 11.55,
'E' => 10.67,
@szepeviktor
szepeviktor / QM-AJAX.patch
Created May 9, 2025 23:28
Query Monitor AJAX patch
diff --git a/dispatchers/Html.php b/dispatchers/Html.php
index dcd1b80..e33d3d7 100644
--- a/dispatchers/Html.php
+++ b/dispatchers/Html.php
@@ -319,6 +319,13 @@ class QM_Dispatcher_Html extends QM_Dispatcher {
$switched_locale = self::switch_to_locale( get_user_locale() );
+ob_start();
+$this->enqueue_assets();
@szepeviktor
szepeviktor / zip-uploads.php
Last active May 8, 2025 06:04
Archive WordPress uploads in a ZIP file on the server
<?php
function addDirToZip(string $dir, ZipArchive $zipFile, string $basePath = '')
{
$files = scandir($dir);
// Remove '.' and '..'
unset($files[0], $files[1]);
foreach ($files as $file) {
$filePath = $dir . $file;
@szepeviktor
szepeviktor / comment-tor-spam.php
Last active March 29, 2025 18:37
Mark WordPress comments from Tor exit nodes as spam
<?php
/*
* Plugin Name: Mark comments from Tor exit nodes as spam
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
*/
/** @return string|null */
function getTorExitNodes()
{
@szepeviktor
szepeviktor / composer.json
Created March 28, 2025 15:16
WHMCS Composer repository
{
"repositories": [
{
"type": "composer",
"url": "https://releases.whmcs.com/v2"
}
],
"require": {
"whmcs/whmcs": "^8.9"
}
@szepeviktor
szepeviktor / qvik.txt
Created March 27, 2025 08:28
qvik QR kód leírása - GIRO
EAM KIEGÉSZÍTŐ SZOLGÁLTATÁSOK ÚTMUTATÓ
BKR ÜZLETSZABÁLYZAT 20. SZÁMÚ MELLÉKLETE
https://www.giro.hu/storage/DDOYCCedHv8YFOdILSOSNiuL6Mfmu6sv56y2HvBU/BKR%20%C3%9CSZ_20_mell%C3%A9klet_2024_09_01.pdf
@szepeviktor
szepeviktor / Hosting.md
Created March 19, 2025 10:14
Hosting providers
@szepeviktor
szepeviktor / cpt-templates.php
Last active March 12, 2025 17:19
Programatically add custom post type template files to WordPress
<?php
/*
* Plugin Name: Add cpt templates
*/
add_filter(
'template_include',
function ($template) {
if (is_singular('cpt')) {
@szepeviktor
szepeviktor / jpeg-archive.sh
Last active March 2, 2025 23:28
Build danielgtaylor/jpeg-archive
apt-get install build-essential autoconf pkg-config nasm libtool
# Build https://github.com/mozilla/mozjpeg
cmake -G"Unix Makefiles" -DPNG_SUPPORTED=OFF -DBUILD_SHARED_LIBS=OFF .
make
make install
# Build Build danielgtaylor/jpeg-archive
# Modify source: https://github.com/danielgtaylor/jpeg-archive/pull/128
make
make install
@szepeviktor
szepeviktor / dump-product-attr.sh
Created February 26, 2025 21:53
Dump WooCommerce product attributes
#!/bin/bash
DUMP_FILE="/home/user/product-attr-debug/$(date --utc +%F).product"
TOTAL="$(wp wc product list --format=count)"
for PAGE in $(seq 1 $(( (TOTAL+99) / 100 ))); do
wp wc product list --page=${PAGE} --fields=id,attributes >>"${DUMP_FILE}"
done