Skip to content

Instantly share code, notes, and snippets.

View gphg's full-sized avatar

Garett PHG gphg

  • NKRI
  • 18:38 (UTC +07:00)
View GitHub Profile
-- https://github.com/openresty/lua-tablepool
-- With slightly modifications.
local newtab = require "table.new"
local cleartab = require "table.clear"
local setmetatable = setmetatable
local _M = newtab(0, 2)
local max_pool_size = 200
@gphg
gphg / v9-ffmpeg.sh
Last active November 18, 2024 14:02
My attempt on writing script for ffmpeg on WEBM.
#!/bin/bash
# Usage:
# v9-ffmpeg.sh 720 input.mp4
# v9-ffmpeg.sh 720 input.mp4 output.webm
#
# Best usage for scaling down video OR just simply reencode video into WEBM.
# Change me.
OUTPUT_PREFIX=""
@gphg
gphg / main.lua
Created October 31, 2024 12:17
My "plug and play"-ish entry point Lua script for LOVE2D.
-------------------------------------------------------------------------------
--- main.lua v0.2
-------------------------------------------------------------------------------
local main = {
_VERSION = '0.2',
}
local arg, os, package, love, jit = arg, os, package, love, jit
local assert, pcall, require, tonumber, setmetatable, print =
assert, pcall, require, tonumber, setmetatable, print
@gphg
gphg / 720pify.sh
Last active August 22, 2024 06:03
Scale down any video into 720p MP4 video. Required ffmpeg.
#!/bin/bash
#
# Small and simple bash script that reencode video into 720p (any orientation).
# Required ffmpeg binary on OS's $PATH (on Windows %PATH%) or current working directory.
#
# You can run this on Windows under a POSIX subsystem (MSYS2, CygWin, Bash from Git for Windows)
#
# Usage:
# 720pify.sh ../video1.mp4 somedir/video2.mp4
#
@gphg
gphg / component-area-legacy.lua
Last active May 14, 2024 16:47
The old way to define a component (as part of ECS). This script normally saved as individual file.
---@alias entity {} # also known as character/object/thing (unique)
---@aliss component.area { width: number, height: number } # a 2d object component, also known as size
---The component constructor/giver/assembler, I don't know, I don't really know.
---@type table<entity, component.area>|fun(width?: number, height?: number): c: component
return setmetatable({}, {
-- stored as weak reference
__mode = 'kv',
---@param list table<entity, component.size>
@gphg
gphg / string.format.lua
Last active February 22, 2024 04:36
Lua function for format string by replaces %1, %2 and so on in the passed string of the passed arguments.
---Replaces %1, %2 and so on in the passed string of the passed arguments.
---@param str string # The string pattern contains %1 to %9.
---@param ... any # Any types will be passed to tostring.
---@return string str # New formated replaced string.
---@return integer count # Number of operations.
local stringformat = function(str, ...)
local tostring, select, gsub, t = tostring, select, string.gsub, {}
for i = 1, select('#', ...) do
t[tostring(i)] = tostring(select(i, ...))
end
@gphg
gphg / Scheduler.lua
Created December 4, 2023 07:48 — forked from saga/Scheduler.lua
Lua Coroutine Scheduler
pcall(require,"socket")
Scheduler = setmetatable({}, {
__call = function(class)
return setmetatable({
threads = {},
}, class)
end
})
Scheduler.__index = Scheduler
@gphg
gphg / Caddyfile
Created November 23, 2022 06:24
Dead-simple Caddy server config file.
:8080
# Points root onto remote's current working directory (as `caddy run` executed)
root * {os.Getwd}
# WebDAV access, requires custom Caddy build.
#@notget not method GET
#route @notget {
# webdav
#}
@gphg
gphg / launch.cmd
Last active November 20, 2022 03:38
launch Love2D game basically. Without fused. In different method. See versions for worse.
@ECHO off
@SET PATH=%~dp0vendor\love-11.4-win32;%PATH%
@SET PATH=%~dp0vendor\love-11.4-win64;%PATH%
@love %~dp0game.love %*
@gphg
gphg / makegifs.py
Last active December 27, 2022 18:13 — forked from Zulko/makegifs.py
My own custom of makegifs.py.
#!/usr/bin/env python
# Taken from http://zulko.github.io/blog/2015/02/01/extracting-perfectly-looping-gifs-from-videos-with-python-and-moviepy/
import os
import sys
import moviepy.editor as mp
from moviepy.video.tools.cuts import FramesMatches
# Extends FramesMatches, the code is copied from source file then modified