Skip to content

Instantly share code, notes, and snippets.

View gphg's full-sized avatar

Garett PHG gphg

  • NKRI
  • 18:31 (UTC +07:00)
View GitHub Profile
@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 / .gitignore
Last active October 6, 2025 10:36
POSIX-powered web page monitor. 🤏
*.txt
*.html
#!/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
@gphg
gphg / range.lua
Last active May 14, 2025 04:55
Generated from Google Gemini conversation.
--- Calculates the lowest and highest numerical indices and the count of numerical indices in a table.
--
-- Iterates over all keys using `pairs` and finds the minimum and maximum
-- among the numerical keys. Non-numerical keys are ignored.
-- Also counts the total number of numerical keys.
-- Returns 0, 0, 0 for tables with no numerical keys (including empty tables).
--
---@param tbl table The input table.
---@return number The lowest numerical index found, or 0 if none.
---@return number The highest numerical index found, or 0 if none.

This is a conversation from a chatbot, Google Gemini. https://gemini.google.com/app (free, not signed on Google account)

I can't recall the exact question I asked, but the response is quite explanatory.

Subject is about JavaScipt DOM Event.

@gphg
gphg / to-webm.py
Last active March 10, 2025 06:52
GitHub Copilot assisted ffmpeg python script.
#!/usr/bin/python
import os
import subprocess
import sys
import time
def get_video_bitrate(input_file):
# Use ffprobe to get the video bitrate
ffprobe_command = [
'ffprobe',
@gphg
gphg / meme-text.sh
Created January 28, 2025 16:04 — forked from Mrfiregem/meme-text.sh
A bash script to add meme text to a video file using ffmpeg
#!/usr/bin/env bash
# Initialize variables to customize output
: "${FFILE:="${HOME}/.fonts/i/impact.ttf"}" # Let user choose font file
: "${FSIZE:=72}" # Let user choose font size in px
: "${BSIZE:=5}" # Let user choose stroke size in px
: "${OFFSET:='(h*0.05)'}" # Let user choose text offset in px
# TTEXT - Text to display at the top of the image
# BTEXT - Text to display at the bottom of the image
# Exit value index: