Skip to content

Instantly share code, notes, and snippets.

View gphg's full-sized avatar

Garett PHG gphg

  • NKRI
  • 02:16 (UTC +07:00)
View GitHub Profile
#!/usr/bin/env python3
# /// script
# dependencies = [
# "scenedetect[opencv]",
# ]
# ///
import os
import csv
import argparse
@gphg
gphg / lite.html
Last active January 12, 2026 19:40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lite Loop (Dufs Auto-List)</title>
<style>
* { box-sizing: border-box; }
body, html {
margin: 0; padding: 0; height: 100%;
<!DOCTYPE HTML>
<html>
<!--
------------===--------===---====-----::::..:.............................................
---------====-----:-========--==------:::....................:............::::::::::::::::
--------------------=========--=------::::................................::::::::::::::::
-----------------=-===-==-----=+=-----::::..........................:::::::...............
----------==---==--------:::--=++=----:::.........................::--===-:............::.
==---=======--===------:::::--=+++=--:::.:......................::-=++++**=:..............
========--------::::::::::::--=++++=-:::.......................:-====++****-:.............
@gphg
gphg / ua_nornalization_is_stupid.md
Created December 30, 2025 08:12
Asked Gemini AI. It answers regardless how stupid it can be.

Normalizing User-Agent (UA) strings is a smart move. Raw UA strings are messy, inconsistent, and can be easily spoofed, but they provide a vital "fingerprint" layer when combined with IP and Session IDs.

For a high-traffic site like a video host, storing raw strings leads to database bloat and slow queries. Here is how to normalize them effectively for bot detection and rate limiting.


1. The Multi-Layered Normalization Approach

Don't just store one version of the UA. I recommend breaking it down into three distinct database columns to balance storage efficiency with query flexibility.

@gphg
gphg / address_sort.lua
Last active November 14, 2025 14:00
Sort by cached reference address.
-- cache definition
local cached_table_identifier = {}
-- weak table. THIS IS IMPORTANT!
-- This allow the cache string to be fred by GC as table no longer referenced.
-- Without this, you have to manually dereference the string OR memory leaking!
setmetatable(cached_table_identifier, { __mode = "k" }) -- the key (table) is weak
-- A counter just to see cache hits/misses
local cache_misses = 0
#!/bin/bash
# Exit immediately if a command exits with a non-zero status or an unset variable is used.
set -euo pipefail
# A script to convert Twitter/X status URLs to the fixupx.com direct video link format
# and initiate a download using wget.
# Function: convert_x_link
# Purpose: Takes a full Twitter/X status URL, strips tracking parameters, and
@gphg
gphg / monitor.sh
Last active November 25, 2025 16:15
POSIX-powered web page monitor. 🤏
#!/usr/bin/bash
# --- Configuration & Environment Variables ---
# Set by user via environment:
# BREAK_ON_FOUND: 1 to stop monitoring after the first alert, 0 (default) to continue.
# NOTIFICATION_MEDIA: Path to the audio file for Termux alerts.
# CUSTOM_CHECK_PATTERN: The pattern to search for in the custom failure check. Defaults to "thumbnail".
# --- Argument Handling ---
if [ "$#" -lt 2 ]; then
#!/usr/bin/env python
import os
import sys
import json
import argparse
import numpy as np
from skimage.metrics import structural_similarity as ssim
from skimage.transform import resize
from moviepy import VideoFileClip
@gphg
gphg / find_loop.py
Last active September 5, 2025 15:02
Finds a seamless loop in a video and creates a looping video or GIF.
#!/usr/bin/env python
import os
import sys
import json
import argparse
import numpy as np
from skimage.metrics import structural_similarity as ssim
from skimage.transform import resize
from moviepy import VideoFileClip
@gphg
gphg / 100mbify.sh
Last active September 15, 2025 05:26
A handy script for sharing meme videos across the internet.
#!/usr/bin/bash
# Define custom exit codes
EXIT_SUCCESS=0
EXIT_MISSING_ARGS=1
EXIT_FFPROBE_FAILED=2
EXIT_ZERO_DURATION=3
EXIT_FFMPEG_FAILED=4
EXIT_TIME_PARSING_FAILED=5
EXIT_COMMAND_NOT_FOUND=6