Skip to content

Instantly share code, notes, and snippets.

View gphg's full-sized avatar

Garett PHG gphg

  • NKRI
  • 18:28 (UTC +07:00)
View GitHub Profile
@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
@gphg
gphg / mp42gif.sh
Last active June 5, 2022 18:56 — forked from troyane/mp42gif.sh
See script and documentation here: https://github.com/troyane/StackOverflow-pro/tree/master/mp42gif Script to convert MP4 file to GIF (via ffmpeg). It creates intermediate custom color palette out of input video file and use it for resulting GIF for better picture quality. For more info see https://superuser.com/a/556031
#!/bin/bash
#
# Script to convert MP4 video to GIF with generation of custom color palette.
#
#=== Do not touch code below
# Inner variables
input_file=""
input_fps=""
input_height=""
-- Based on this: http://lua-users.org/wiki/LuaModulesLoader
module(..., package.seeall)
local function loader(modulename)
local errmsg = ""
local modulepath = string.gsub(modulename, "%.", "/")
local dirname = modulepath:match("(.*[/\\])")
local basename = modulepath:match("^.+/(.+)$")
for path in string.gmatch(package.path, "([^;]+)") do
local filename = string.gsub(path, "%?", table.concat({dirname, basename, "/", basename}))