Skip to content

Instantly share code, notes, and snippets.

View gphg's full-sized avatar

Garett PHG gphg

  • NKRI
View GitHub Profile
@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}))
@gphg
gphg / bukkit.yml
Last active April 28, 2022 20:55
PaperMC Poorman's Server configurations.
# Based on: https://shockbyte.com/billing/knowledgebase/154/Optimizing-bukkityml-to-Reduce-Lag.html
settings:
allow-end: true
warn-on-overload: true
permissions-file: permissions.yml
update-folder: update
plugin-profiling: false
connection-throttle: 4000
query-plugins: true
@gphg
gphg / debug.lua
Last active November 18, 2021 16:47
Based on this https://www.love2d.org/forums/viewtopic.php?f=5&t=2473 - *Trimmed* to get it working on older and/or subset API.
--local _Debug table for holding all variables
local _Debug = {
errors = {},
prints = {},
order = {}, --e for errors, p for prints
onTopFeed = {},
orderOffset = 0,
longestOffset = 0,
drawOverlay = false,