Skip to content

Instantly share code, notes, and snippets.

Avatar
💡
Developing

Lars Müller appgurueu

💡
Developing
View GitHub Profile
@appgurueu
appgurueu / init.lua
Created Apr 24, 2022
Fix for tile bug on Minetest 5.5
View init.lua
-- Written by appgurueu, licensed under the MIT license
local function patch_tile_texture(tex)
if not (tex:match"%[combine:" or tex:match"%[inventorycube{") then
return
end
-- Prevent Minetest 5.5 from prepending "blank.png^" for older clients which don't support [png
-- See https://github.com/minetest/minetest/pull/12210
return "(" .. tex .. ")"
end
minetest.register_on_mods_loaded(function()
@appgurueu
appgurueu / dont_do_ddos.md
Created Mar 3, 2022
Why you should not partake in the ongoing coordinated DDoSing activities
View dont_do_ddos.md

Why you should not partake in the ongoing coordinated DDoSing activities

  • It might hit the wrong targets. Do you really trust whatever tool you run and whatever list you received to only hit what you wanted to hit? DDoSing will also unnecessarily increase network load on the route from you to the target.
  • It's illegal and might come back at you. DDoSing is illegal on multiple levels. It's usually easy to prove through server logs. Your ISP might - often automatically - ban you. The targets of your attacks might "strike back" or use your attacks as a pretense to inflict even more harm to your region. You can merely hope that you will not be persecuted for your naive criminal offenses.
  • It's risky. You'll - one way or another - be running foreign code on your machine. That always comes with a risk (which can only partially be reduced through virtualization, be it through the browser environment or something like Docker). Even if no control over your machine is gained, your IP at the very least
View js_var.lua
local _G = _G
return function(implicit_declaration, stacklevel)
assert(implicit_declaration == "var" or implicit_declaration == "global" or not implicit_declaration)
stacklevel = (stacklevel or 1) + 1
local _P = getfenv(stacklevel + 1)
local _V = {}
local declarations = {}
local environment = {
_P = _P,
_V = _V,
@appgurueu
appgurueu / golike_exports.lua
Created Aug 22, 2021
Go-inspired exports based on variable capitalization
View golike_exports.lua
local parent = getfenv(1)
local private = {}
local public = {}
setfenv(1, setmetatable({}, {__newindex = function(self, key, value)
local first = key:sub(1, 1);
((first >= "A" and first <= "Z") and public or private)[key] = value
end, __index = function(self, key)
local value = private[key]
if value ~= nil then
return value
@appgurueu
appgurueu / trinary_logic.lua
Created Aug 22, 2021
Trinary logic implemented in Lua using debug.setmetatable
View trinary_logic.lua
-- 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
View infinite_loops.md

Infinite Loops

In Lua.

Lawful

Good

A classic.

View trinary_logic.lua
-- 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 Dec 19, 2020
Crosshair spread indicator code
View crosshair.lua
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
View Main.java
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 Mar 9, 2022
Shuts down the server if it lags too much ("antilag" Minetest mod init.lua)
View 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).")