Skip to content

Instantly share code, notes, and snippets.

View appgurueu's full-sized avatar

Lars Müller appgurueu

View GitHub Profile
@appgurueu
appgurueu / infinite_loops.md
Last active January 29, 2023 13:21
Infinite Loops

Infinite Loops

In Lua.

Lawful

Good

A classic.

@appgurueu
appgurueu / trinary_logic.lua
Created June 11, 2021 14:06
Trinary logic
-- Set boolean metatable
debug.setmetatable(false, {
__add = function(a, b)
if b == nil then
return b + a
end
return a or b
end,
__mul = function(a, b)
if b == nil then
@appgurueu
appgurueu / crosshair.lua
Created December 19, 2020 11:53
Crosshair spread indicator code
crosshair = {}
function crosshair:set_meta(meta)
return setmetatable(self, {__index = function(self, index)
if crosshair[index] ~= nil then
return crosshair[index]
end
if meta[index] ~= nil then
return meta[index]
end
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.BiFunction;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
@appgurueu
appgurueu / init.lua
Last active March 9, 2022 00:44
Shuts down the server if it lags too much ("antilag" Minetest mod init.lua)
local min_lag = 1 -- in seconds
local min_times = 10 -- has to occur 10x
local times = 0
minetest.register_globalstep(function(lag)
if lag < min_lag then
times = 0
else
times = times + 1
if times >= min_times then
minetest.request_shutdown("Server shutting down due to high latency (lag).")
@appgurueu
appgurueu / default_bones.lua
Last active March 9, 2022 00:44
Gets default bone positions from glTF files (for Minetest)
-- helper function
local function quaternion_to_rotation(q)
local rotation = {}
local sinr_cosp = 2 * (q[4] * q[1] + q[2] * q[3])
local cosr_cosp = 1 - 2 * (q[1] * q[1] + q[2] * q[2])
rotation.x = math.atan2(sinr_cosp, cosr_cosp)
local sinp = 2 * (q[4] * q[2] - q[3] * q[1])
if sinp <= -1 then
@appgurueu
appgurueu / markdown_to_bbcode.js
Created April 7, 2020 13:02
Converts Markdown to BBCode
const md = require('mark-twain');
const parse5 = require('parse5');
tags = {
"strong": "b",
"em": "i",
"u": "u",
"code": "icode",
"h1": ["h", "b"],
"h2": ["size=150", "color=#115098"],
@appgurueu
appgurueu / init.lua
Created March 7, 2020 17:17
Minetest Waypoint Testmod
-- Use this to test waypoint capabilities
minetest.register_chatcommand(
"test_waypoints",
{
description = "tests waypoint capabilities",
func = function(name)
local player = minetest.get_player_by_name(name)
minetest.chat_send_all(
"regular: " ..
player:hud_add {
@appgurueu
appgurueu / init.lua
Last active March 9, 2022 00:53
modlib - init.lua - template
-- Table helpers
table_ext= {
tablecopy = function(t)
return table.copy(t)
end,
count = function(table)
local count = 0
for _ in pairs(table) do
@appgurueu
appgurueu / generate_bg.py
Last active October 6, 2018 08:45
Generate MT Background for Website Python Script
import PIL
import random
from PIL import Image
size=(60,40)
dirtlevel=3*16
gravellevel=5*16
dirt=Image.open("default_dirt.png")
gravel=Image.open("default_gravel.png")